I'm a complete newbie so sorry if this is completely dumb. I'm working on a game engine and I opted to go with an inheritance hierarchy for my scene code I have a SceneElement
as the root class and anything that goes into a scene such as a model, camera, light source, skybox etc inherit it
class SceneElement {};
class Model : public SceneElement, public Transformable, public Renderable {};
class Camera : public SceneElement, public Transformable, public Updatable {};
class AudioSource : public SceneElement, public Transformable {};
class LightSource : public SceneElement, public Transformable {};
To me this makes sense a Model
is a SceneElement
and through the editor I can add an instance to the scene, but when it comes to actually use this code to make a game it starts to fall apart for example if I wanted to make a Player
well it doesn't really fit into this is-a relationship I mean a model might be used to visually represent the player, but I feel like that's more of a has-a relationship the player has a model and can use input to move it around.
I don't think this would count as composition, but instead of having the Player inherit from SceneElement
or some other class would it be practical to just reference the elements it needs or is mandatory that game objects fit into the engine
class Player {
void update() {
// use input module to move model around
}
private:
Model& model; // reference to some model in the scene
}
edit: another thing I realized is perhaps I could utilize mixin or interfaces? similar to how Model
inherits Renderable