So i have been struggling with this for many years and haven't seen a solution that provides the right complexity (implementation/extension) and performance when it comes to managing the objects in a game scene. As far as i have seen there are 3 main approaches:
OOD / Components:
-Base Object (Actor), derive from this to make your new types: Character, NPC, Orc, Weapon…
-Derived type adds components (Composition over inheritance): MeshRendererComp, DialogueComp, PlayerInputComp etc.
-Objects are stored in a map or linked list? and iterated over in a Scene with Tick called etc.
Pros:
-Easy too implement/Think about
-Easy too access components with simple pointers
Cons:
-Memory is not contiguous
-Cache issues
-Raw pointers dangerous
Component-Entity Architecture:
-GameObject Class is a container for components
-Components added dynamically at runtime/removed usually via a Map on the GameObject
-Objects are stored in a map or linked list
Pro:
-Easy To implement
-Flexible, objects can be composed out of any components even at runtime.
Cons:
-Terrible memory layout, components are scattered, worse than OOD?
-Accessing components is now an indirection via a map look up.
-Cache misses worse than OOD.
Entity Component System (Sparse Set):
-GameObject is now just an EntityID, no data
-Components stored in component pools (Densly packed) and accessed via a Map(EntityID→Index)
-Systems contain logic and operate on components
-Pro:
-Components are grouped into contiguous pools
-Entities can be copied easily.
-ID's/Handles can resolve dangling and allow memory relocation
Cons:
-Everything is now an indirection.
-Each system will NOT loop over linear memory as it needs too “fetch” via potentially multiple levels of indirection the components that it desires to operate on?
-Harder too think about from a gameplay programming perspective
-Seems like its forced to be global everywhere i.e g_World→GetComponent<Transform>(entityID)
Can anyone shed light on which approach they find the most useful in terms of actually getting stuff done and having acceptable performance overhead?
Thanks.