About the Game Logic Class

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

class AIActor is a bag of behaviours.

I disagree. An AI can have at one time only one state/behavior.
There does not need to be a notification to the game state class that an actor has been deleted and so its behavior must be deleted.
Firstly, this can be achieved more easily via the simple use of smart pointers, but secondly it shouldn’t be done at all. The pool of behaviors doesn’t need to be released until the game state is over.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

Advertisement

class AIActor is a bag of behaviours.

I disagree. An AI can have at one time only one state/behavior.
There does not need to be a notification to the game state class that an actor has been deleted and so its behavior must be deleted.
Firstly, this can be achieved more easily via the simple use of smart pointers, but secondly it shouldn’t be done at all. The pool of behaviors doesn’t need to be released until the game state is over.


L. Spiro

That's what I do.

The Scene (for instance) is initialized inside the Gameplay (A GameState) class.

Gameplay::Init()->Scene->Load()

Gameplay::Destroy()->Scene->ClearActors()

I'm not using a actor/behaviour pool yet. sad.png

Actors should be created and deleted on-the-fly as they are to come to exist in the game scene and when they are removed from it respectively.
Keeping around dead actors is nothing but overhead, if not in CPU usage then in memory, but typically both.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

Actors should be created and deleted on-the-fly as they are to come to exist in the game scene and when they are removed from it respectively.
Keeping around dead actors is nothing but overhead, if not in CPU usage then in memory, but typically both.


L. Spiro

I know, I always use new/delete and I'm not talking about memory allocation because I have a lot of experience with it.

What I'm saying is the Scene create and delete (manages) all actors.

The problem is: if my Game class have a pointer to an Actor (the player) and the Scene delete all of them, the pointer will be a dangling pointer.

Your game state doesn’t have pointers to actors. It accesses them through the scene manager(s).

(Do not make scene managers static, singletons, or otherwise “only one”. The game state class can make as many scene managers as it wants (even if most of the time there will be only one). Very useful for multi-perspective games. It was a pain in the ass when I had to make a golfing game with only one scene manager where the 3D golf world was overlayed by a 3D silhouette of a golfer in a totally different perspective and environment—a totally different setup from split-screen where there would still be only one scene but 2 cameras.)


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

Your game state doesn’t have pointers to actors. It accesses them through the scene manager(s).

(Do not make scene managers static, singletons, or otherwise “only one”. The game state class can make as many scene managers as it wants (even if most of the time there will be only one). Very useful for multi-perspective games. It was a pain in the ass when I had to make a golfing game with only one scene manager where the 3D golf world was overlayed by a 3D silhouette of a golfer in a totally different perspective and environment—a totally different setup from split-screen where there would still be only one scene but 2 cameras.)


L. Spiro

So, my Scene has a pointer to a main Actor?

If so when updating my Scene, I'll calculate the Camera (worldMatrix) values based on that Actor?

Why do you mean?

The only global that have is the main function, but I don't think I can make a Object. laugh.png

So, my Scene has a pointer to a main Actor?

No.
Currently your Game class has std::vector characters. This belongs in the scene manager.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

So, my Scene has a pointer to a main Actor?

No.
Currently your Game class has std::vector characters. This belongs in the scene manager.


L. Spiro

My scene has actors and characters or by character you mean an actor?

My scene just need to know about an actor isn't?

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

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

This topic is closed to new replies.

Advertisement