About the Game Logic Class

Started by
22 comments, last by Irlan Robson 9 years, 10 months ago

Every actor in the game, be it a character or otherwise, is managed by the scene manager.
I mean what I said in the last post: Your Game class example has a member called “std::vector characters”. It’s pseudocode so I don’t know what the vector actually contains, but I would assume it is an array of Actor * (why would Character inherit from Behavior instead of Actor? A Character is an Actor).

To be clear: a Character is a form of actor and should inherit from Actor.

SceneManager should have std::vector<Actor *> m_vActors, which is an array of all characters/actors in the scene.

L. Spiro

That's what I do. The single responsability of my scene is to manage actors. It manages a array of actor. I was thinking that inheriting from an Actor was a bad idea (using composition over inhertance), but if my Character is an Actor, it'll make the scene a lot more easier to manage.

Advertisement

Every actor in the game, be it a character or otherwise, is managed by the scene manager.
I mean what I said in the last post: Your Game class example has a member called “std::vector characters”. It’s pseudocode so I don’t know what the vector actually contains, but I would assume it is an array of Actor * (why would Character inherit from Behavior instead of Actor? A Character is an Actor).

To be clear: a Character is a form of actor and should inherit from Actor.

SceneManager should have std::vector<Actor *> m_vActors, which is an array of all characters/actors in the scene.

L. Spiro


class Character : public Actor
{
public:     virtual void Update(const Time& _time)
     {
          isActive = maxLives < 0;
     }private:     int maxLives;};

class Scene
{
public:
     void Update(const Time& _time)
     {
          for each actor, update him!
          update camera!
     }
private:
     Camera *m_pActiveCamera;
     std::vector<Actor *> m_vActors;};

class Game
{
public:

private:
     Character *pCharacter; // main character
     //(...)
};

There is a bunch of things that I won't post, but I think you got it.

Now I need a way of handling the pCharacter pointer in the game class when gets removed of the scene without using smart pointers.

You could simply use a message / notification system to alert subscribers that their state is now invalid. This could be something as simple as o


MessageSystem->NotifySubscribers<CharacterDestroyedMessage>();

However, it does seem to me that the AI behaviour should be a component of an entity, rather than a standalone system from the entity system. If this is the case, then removing any behaviour components should remove the entity from the system. It doesn't seem sensible to store a pointer to the "Main" character, as that is subjective to the point of development, and will force you to produce code that is inflexible to future design change.

You could simply use a message / notification system to alert subscribers that their state is now invalid. This could be something as simple as o


MessageSystem->NotifySubscribers<CharacterDestroyedMessage>();

However, it does seem to me that the AI behaviour should be a component of an entity, rather than a standalone system from the entity system. If this is the case, then removing any behaviour components should remove the entity from the system. It doesn't seem sensible to store a pointer to the "Main" character, as that is subjective to the point of development, and will force you to produce code that is inflexible to future design change.

I'm not using any kind of Event/Message/Notification/Signal System in my in-house game engine. This should be avoided as much as possible in this type of applications.

This topic is closed to new replies.

Advertisement