Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Is my Game Architeture/Loop ok?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Irlan   Members   -  Reputation: 1838

Like
0Likes
Like

Posted 19 February 2014 - 11:26 AM

My friends, I need a advice in my design if possible.

 

Some classes are based on the book Game Engine Architeture. It's not a very large project but I'm thinking in keep the structure for use in the future. I'm going to post some questions that I think could help the others too.

 

Game.h

class Game
{
public:
bool Init();
void HandleEvent(Event* e);
void Update();

private:
Core core;
Renderer renderer;
Physics physics;
GameWorld gameWorld;

EffectDatabase effectDb;
TextureDatabase textureDb;
MaterialDatabase materialDb;
MeshDatabase meshDb;
};

Game.cpp

bool Game::Init()
{
if (!core.Init())
{
return false;
}
if (!renderer.Init())
{
return false;
}

//details ommited
return true;
}


void Game::HandleEvent(Event* e)
{
switch (e->type)
{
case EVENT_SPAWN:
{
Spawn* spawn = (Spawn*) e;
//todo
}
break;
default:
break;
}
}


void Game::Update()
{
sf::Clock clock;


float lagTime = 0.0f;
const float dt = 1.0f / 60.0f;


while (core.isActive)
{
core.HandleEvents(this);


const float frameTime = clock.restart().asSeconds();


lagTime += frameTime;
while (lagTime >= dt)
{
gameWorld.Update(dt); //update behaviours
physics.Update(dt); //check collisions

lagTime -= dt;
}

renderer.Draw(); //render mesh instances
core.Display(); //refresh window and swap buffers
}
}

The core system is just a wrapper for Windows Message and keep dispatching Windows Messages to the game.

The GameWorld holds a list of game objects.

 

I need to think in how I'm going to control the objects (add some filters, Input Controllers, etc.) because I'm using the component pattern. I'm kind of lost in that aspect. I've read Appochi's Input Mapping tutorial and I'm thinking how I can implement this into my game without extend everything from a Context.

 

I was reading some topics that states that GameStates are losing their forces and Behaviour Trees are a better way. Can I simulate a Game State using Behaviour Trees? Just to not get complicated, I should continue with my simple State Pattern?

 

I'm not fan of Design Patterns. I like to apply the ideas that they bring to us, but not completely extending interfaces and following the pattern.

For example: having a MenuState extended from a state is a bad idead. It's better to pass a Game* to a Menu member function and if a button is selected, send an Event to the Game.

 

The subsystems interconnections are disturbing me too. Should all the systems be connected with the Game World? When I spawn an GameObject, should I redirect a event to the GameWorld or just add the GameObject via gameWorld.PushGameObject(GameObject*) ?

 

Any kind of advice is welcome and may serve as a help to the others, OK?


"Information is not knowledge. The only source of knowledge is experience." - Albert Einstein

Irlan Engine: http://robsrc.wordpress.com/


Sponsor:

#2 L. Spiro   Crossbones+   -  Reputation: 14391

Like
3Likes
Like

Posted 19 February 2014 - 11:59 AM

Everything looks fine except how you handle time.  Your game will always be running slightly slower than your actual clock when using floats or doubles.  Switch to 64-bit integers and microseconds.


should I redirect a event to the GameWorld or just add the GameObject via gameWorld.PushGameObject(GameObject*) ?

Don’t abuse events. An object getting added to the scene is not an event. Just add it and be done.


I was reading some topics that states that GameStates are losing their forces and Behaviour Trees are a better way. Can I simulate a Game State using Behaviour Trees? Just to not get complicated, I should continue with my simple State Pattern?

Behavior trees are an over-engineering of the flows of game states and there is no reason to use them for such a simple thing. They will needlessly complicate your design and maintenance.


L. Spiro
It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#3 Irlan   Members   -  Reputation: 1838

Like
0Likes
Like

Posted 19 February 2014 - 12:22 PM

Everything looks fine except how you handle time.  Your game will always be running slightly slower than your actual clock when using floats or doubles.  Switch to 64-bit integers and microseconds.

 

should I redirect a event to the GameWorld or just add the GameObject via gameWorld.PushGameObject(GameObject*) ?

Don’t abuse events. An object getting added to the scene is not an event. Just add it and be done.


I was reading some topics that states that GameStates are losing their forces and Behaviour Trees are a better way. Can I simulate a Game State using Behaviour Trees? Just to not get complicated, I should continue with my simple State Pattern?

Behavior trees are an over-engineering of the flows of game states and there is no reason to use them for such a simple thing. They will needlessly complicate your design and maintenance.


L. Spiro

 

Ok. I'll do the correction of the time.

Instead of redirecting dependencies, I'll put the dependency direct into the class that dispatch the event or instead pass a reference to a function. Is a pain in the ass keeping extending things like Game extends FrameListener or GameObject extends EventHandler.

I agree with you about Behaviour Trees. I will keep the idea of the State Pattern, but, I will minimize the dependencies and use it to control just specific things (not the game context itself).


"Information is not knowledge. The only source of knowledge is experience." - Albert Einstein

Irlan Engine: http://robsrc.wordpress.com/


#4 slayemin   Members   -  Reputation: 2913

Like
0Likes
Like

Posted 22 February 2014 - 03:45 AM

Honestly? I don't think we have enough to really go on here. Everything looks alright, but its super basic. From the software engineering side, we don't know what your data diagrams look like or know what your requirements are so we really can't tell you whether your architecture is on track or not. When I'm working on my own project architecture, I often like to get out a pen and sketch pad and draw out the architecture of my objects and their connections with each other. Then I ask myself, "Does this really make sense? Should this go here? Do I really need this? How can I simplify this?" When I have nothing left to take away and further simplifications don't seem possible, I think I've got something solid. Then I try to make my architectural diagrams and code match each other.

For your game, you might be able to get some value out of detailing out every game object into a class diagram. The architectural datastructures you need to manage and organize your game objects will become a bit more clear and apparent. 


Eric Nevala

Indie Developer | Dev blog


#5 Irlan   Members   -  Reputation: 1838

Like
0Likes
Like

Posted 23 February 2014 - 08:56 AM

Honestly? I don't think we have enough to really go on here. Everything looks alright, but its super basic. From the software engineering side, we don't know what your data diagrams look like or know what your requirements are so we really can't tell you whether your architecture is on track or not. When I'm working on my own project architecture, I often like to get out a pen and sketch pad and draw out the architecture of my objects and their connections with each other. Then I ask myself, "Does this really make sense? Should this go here? Do I really need this? How can I simplify this?" When I have nothing left to take away and further simplifications don't seem possible, I think I've got something solid. Then I try to make my architectural diagrams and code match each other.

For your game, you might be able to get some value out of detailing out every game object into a class diagram. The architectural datastructures you need to manage and organize your game objects will become a bit more clear and apparent. 

Ok.

 

I mentioned just the basic structure because the  hard part of the code is already done (Collision Detection, Rendering, Shader Management, etc.). My intention was to provide the structure of the Game Logic's POV.

 

I'll provide a high level of the game.

 

I've done a Game class that is just a container for the Game Objects. The Physics System detect a collision and dispatches to the Game Event Handler.

 

The Game class do not contain a big list of game objects. Instead, it contains separated lists of game objects, like this:

 

std::vector<GameObject*> enemies;

std::vector<GameObject*> bullets;

 

GameObject* gameObject; //player

 

When the Physics System detects a collision, the GameObjects that are attached to the Shape (Shapes are inside the Physics) class are sent too. The Game class see if the Game Objects are contained in some of these lists. If is a collision between a Enemy and a Bullet it deactivates the bullet and do something on the enemy (or its components). I could insert a filter in every game object (something like: int GameObjectType) to speed up the check, but I'm reducing dependencies here.

 

The other things like Menu, I think I'm going to use the State Pattern just to select the appropriate Menu to the game and control the menu items.


Edited by irlanrobson, 23 February 2014 - 08:57 AM.

"Information is not knowledge. The only source of knowledge is experience." - Albert Einstein

Irlan Engine: http://robsrc.wordpress.com/





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS