Files
Bubberstation/code/datums/components
SkyratBot 567105d31d [MIRROR] [NO GBP]Refactors how sheets are ejected from mat container [MDB IGNORE] (#23401)
* [NO GBP]Refactors how sheets are ejected from mat container (#77945)

## About The Pull Request
As #77936 pointed out an infinite while loop occurs in the recycler.
This was caused due to my recent mat changes as follows.

When the recycler eats up an item. If it found any material inside, it
would attempt to eject any sheets formed from it over here

ed71735fb3/code/game/machinery/recycler.dm (L199)

Inside this proc i first create the sheets in `null space` why is
explained in the comment

ed71735fb3/code/datums/components/material/material_container.dm (L599-L600)

After doing logging & stuff i then would move the sheets back into its
target turf so it could get merged again

ed71735fb3/code/datums/components/material/material_container.dm (L607-L608)

Unfortunately this would trigger `COMSIG_ATOM_ENTERED` signal which the
recycler is hooked onto. The recycler would then eat the newly ejected
sheets again, which would cause more sheets to be ejected, which would
again trigger the signal `COMSIG_ATOM_ENTERED` and you have your
infinite loop.

I did this because i had no clue how to stop the stack from merging when
it got spawned and this was a poor solution, so upon examining the code
i found there is a var to specifically stops stacks from merging

ed71735fb3/code/game/objects/items/stacks/stack.dm (L81)

Yup there is specific param called `merge=TRUE` which allows you to
explicitly stop stacks from merging. I now use this var and manually
merge stacks afterwards without calling `forceMove()` so it doesn't
trigger the recycler anymore which caused the infinite loops.

## Why It's good for the game
Writing checks to see if an object came from null space is weird. It
makes the code difficult to reason with as such situations never happen.
Now it makes sense for an atom to be moved "into" null space for e.g.
when it gets deleted but for an atom to "return back from it" never
happens and you shouldn't be bothered with figuring out how that
happened.

## Changelog
🆑
refactor: sheets are merged in a better way when ejected from machines &
material related stuff
/🆑

* [NO GBP]Refactors how sheets are ejected from mat container

---------

Co-authored-by: SyncIt21 <110812394+SyncIt21@users.noreply.github.com>
2023-08-30 16:28:32 -04:00
..

Datum Component System (DCS)

Concept

Loosely adapted from /vg/. This is an entity component system for adding behaviours to datums when inheritance doesn't quite cut it. By using signals and events instead of direct inheritance, you can inject behaviours without hacky overloads. It requires a different method of thinking, but is not hard to use correctly. If a behaviour can have application across more than one thing. Make it generic, make it a component. Atom/mob/obj event? Give it a signal, and forward it's arguments with a SendSignal() call. Now every component that want's to can also know about this happening.

HackMD page for an introduction to the system as a whole.

See/Define signals and their arguments in __DEFINES\components.dm