I am in the process of writing an entity component model game engine, and I wanted to ask about the best way to lay out the code. I have run into an issue that I know will quickly cause me to run into more problems, down the road. In short, I currently have a render component, that I attach to the entity class. The problem is, I need the render component to signal the render engine, and add itself to it.
I thought about creating a singleton for the render system, but I quickly realized that was a bad road, and sooner or later, I would be creating singletons for just about everything (Ex, physics for the physics component). What I am currently thinking of doing is creating the base engine class as my only singleton. The engine class is responsible for initializing all of the systems available, such as the graphics and file systems, storing references to them, calling the game loops update method, and keeping track of all the entities in the game. If I did that, then my components or any other part of the code could easily reference the important systems they need to deal with via a simple Engine.MySystem
. In the case of my render component, Engine.Graphics3D.addModel()
.
I am wondering is if this is an acceptable way of doing things, or not. If not, what would be better? I could, in theory, pass a reference to the GFX system to the render component, but that seems like a really bad idea. I feel like this is a nice middle ground between the two options.