Hi all,
I just decided to cut down my 1000 year-old inheritance tree because of too many nasty problems you probably already know of.
But I'm trying to draw all the stuff in my head before starting to make such a big architectural change. Big for me, probably not so big for you.
Ok, let's imagine I've rewritten all my classes using composition.
The way I see it, my GameObject will look like this:
class GameObject
{
Matrix transform;
Model* model;
Physics* physics;
Renderer* renderer; //Or I'll just use a static void render(GameObject&) function instead of a whole class, for starters.
}
Ok, cool. But now I need a Player object.
class Player
{
Input* input;
Animator animator; //for skeletal animation
Matrix transform;
Model* model;
Physics* physics;
Renderer* renderer; //Or I'll just use a static void render(GameObject&) function instead of a whole class, for starters.
}
Imagine 10 more different classes like this.
Final step is to render all entities using a 'for' loop.
If I was using my bad old inheritance tree, I would just do:
for( auto& object : gameObjects ) { Renderer::draw( object, viewCamera, interpolationRatio ); }
And have no problems since every monster inherits from GameObject.
But now that I have 10 classes for 10 different monsters, how do I render them at once? :huh:
1. overloading the Renderer::draw() function doesn't count
2. Stuffing every component in the world in the GameObject and using flags doesn't count. It will become too fat, I'm sure.
3. Entity-component-system is too much. I just want to make a simple game like a normal person.
Heeelp! :o
And thanks for reading. :rolleyes: