|
|
|
|
|
by sillysaurus3
3679 days ago
|
|
They are, but in that case you'd use raw pointers. The reason this works is because of discipline. Generally, there is a FooManager class which owns Foos. The FooManager is responsible for both allocating and deallocating Foos, regardless of where they're used. And in a game, "When should something be deallocated?" usually has a clear answer: When the level loads, for example, or when you move from one part of the continuous world to another part. Then there are Subsystems (singletons) for each division of the engine: GraphicsSubsystem, InputSubsystem, etc. Between those two patterns, there aren't a lot of ways to lose track of a pointer. |
|
I think another important factor is the pseudo-realtime update loop that synchronization is tied to.
Unless there is some garbage collection between game state changes (unloading unused resources during a level, etc...), its rare that references are invalidated unexpectedly, or accessed in parallel to the cleanup step between game state changes.
eg. a global state change from RUN to CLEANUP tells the subsystems to stop using a resource, so during the CLEANUP state the subsystems can safely delete any resources they have ownership of.