I'm creating my first c++ game engine project (for learning purposes) and in it I've attempted to implement an entity/component system utilizing some data oriented design principles while also not fully giving up my object oriented way of thinking. I have data only component structs:
(Example)
Position.h
struct Position
{
Vector3D position{ 0.0f, 0.0f, 0.0f };
};
which are stored in arrays within my SceneManager class:
SceneManager.h
class SceneManager
{
//Some other code....
private:
//So only systems have access to component arrays
friend class BGraphics::RenderSystem;
friend class BInput::InputSystem;
friend class BPhysics::MovementSystem;
friend class BPhysics::CollisionSystem;
friend class BAudio::AudioSystem;
//Component arrays. Each index of the arrays represents an entity.
//So positionComponents.at(1) represents entity 1's position.
Array<Position, 10> positionComponents;
Array<Velocity, 10> velocityComponents;
};
As you can see, my engine's system classes are the only ones who have access to the component arrays and so every system can process components. There are some other things involved in this setup that I don't want to get too deep into for simplicity's sake. My issues are as follows:
Each system accepts a SceneManager reference in an Update function like so:
RenderSystem::Update(SceneManager& scene)
{
//Use scene component arrays necessary for processing...
}
What I'm struggling with is right now my components seem like global variables in that every system has access to them and can change their state. Though it seems like a lot of data oriented design involves structs like these with public data for which other functions can operate on, changing their state. With that being said, is there something I'm missing with my implementation that would make my component data more encapsulated and safer? How am I suppose to think about handling data in a safe way when utilizing data oriented design? Any clarity is appreciated.