2019-11-24
658 words
4 minutes
cpp Data Oriented Design Check out the video. This explains the AOS and SOA very well. data orientied design
The following code is a common pattern in Object oriented programming.
struct Entity{ v3 postion, v3 velocity, int flag, virtual void update() } struct Player: public Entity{ float life, float mana, void update() override; } struct Monster: public Entity{ float life, void update() override; } sturct Door: public Entity{ bool current_status, float open_target, void update(); } There are few problems with this approach:
Memory allocation. In this objected orientied approach, because we inherited Entity objects and added some fields in child object, the size of the new Object can have different sizes.