I'm trying to implement some kind of "game engine" just for me ", and the plot of the problem is as follows:
Suppose I have an abstract interface for a rendered object, for example. IRenderable.
And it is declared as follows:
interface IRenderable {
virtual void Render(Backend& backend) = 0;
};
What I'm doing now is something like declaring different classes, such as
class Ball : public IRenderable {
virtual void Render(Backend& backend) {
}
};
And then everything looks good. I can easily do something like std::vector<IRenderable*> items, click elements like in it new Ball(), and then make a call that looks likeforeach (IRenderable* in items) { item->Render(backend); }
Well, I think this is a "polymorphic" way, but what if I want to have different types of objects in my game and the ability to manipulate their state, where each object can be controlled through its own interface?
I could do something like
struct GameState {
Ball ball;
Bonus bonus;
};
, ball.Move(...) bonus.Activate(...), Move(...) Ball Activate(...) - Bonus.
foreach IRenderable* , , .
ball.Render(backend);
bonus.Render(backend);
, ( Render ..
downcasting dynamic_cast - typeid, , , , "" .
, : - () , , - , IRenderable* ( Render ), ?
, - , , :)
!