ECS in SDL2
It starts from a school project where we're supposed to design a space shooter game based on data-oriented architecture. I decided to make an ECS for it's known for highly compatible with data oriented design techniques. Data for all entities are commonly stored together in a continuous physical memory, enabling data accessing more efficient when iterate over entities.
Often in game development, we are ought to implement some entity intuitively following traditional object-oriented-design A core idea of object oriented programming is to encapsulate data in the object. So quite often when we accessing a shared data by render system and physics system, like position, you will couple the objects together and break the encapsulation which at the end you would probably get a bunch of spaghetti spaghetti code.
Another flaw of object-oriented design is its performance in the aspecting of data accessing. Common scenario in OOD is when you iterate the enemies and try to update their position, computer will accessing the objects which contain all the data it has. It causes two problems. While in one hand, we don't want to jump around in the memory to get the data we want, also we don't need those data except the position for our use. This can be a waste of the cache we want to avoid.
One of the best advantages of ECS is we can keep data that will be iterated regularly in a continuous memory space. By doing his, we save the performance from jumping around in the memory. And we're also only looking at the data we want.
I'm really interested about ECS and enjoy a lot playing with it. At the moment I'm studying rust as a hobby language. I found Bevy engine, which is a data-driven game engine built in rust, quite appealing and now I'm trying to explore more about it. This is the major work at the moment.