Managers
- Review of concepts so far
- CPU model
- Sequential instructions
- Fixed-cost ALU
- Random memory expensive
- Unpredictable branches expensive
- Structure of Arrays
- Object contains arrays of things
- Good for cache (access locality, avoid cache pollution)
- Good for uniform objects
- Components
- Decompose object into component objects
- Components promote code reuse between object types!
- Components allow more flexible relationships
- Components organized in dense arrays
- Good for cache, less branching
- Object is ID
- Mapping between object ID and component IDs
- Component variations
- Can have list of components per object
- make it easier to tell what you have
- Variations to map Object ID to Component ID
- map
- Log(N) lookup, not as cache friendly
- unordered_map / hash_map
- Constant time (w/ good hash), not as cache friendly
- list
- Linear (small) or binary search
- Pointers vs. handles
- Especially std::vector resize moves pointers
- If everything is dense arrays, use array index as handle instead
- More reliable for serialization
- serialization = save & restore state
- As read/write functions (often << and >> in C++)
- As function that does both depending on istream vs. ostream
- As auto-generated functions
- Great even for computational code
- Managers
- Function that operates on a component
- Doesn't care what objects hold the component
- Common to have inheritance in Managers
- Init/Shutdown (separate from constructor)
- Allows game restart w/o allocate & delete
- Can rely on construction of other components
- Unity: Construct, Awake, Start, Reset
- Update
- Call when updates need to happen
- Can be per frame, per physics update, other
- Send/Receive message
- Message = generic state tracking
- Component can post message
- Activate, ApplyDamage, ...
- Can broadcast
- Can apply locally (children, parents, nearby)
- Component can act on message
- Member function by name (Unity)
- enum input to ReceiveMessage call
- Replay message stream can replay game
- Great for debugging & repro