• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Irlan

Is my Game Architeture/Loop ok?

4 posts in this topic

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?

0

Share this post


Link to post
Share on other sites

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).

0

Share this post


Link to post
Share on other sites

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. 

0

Share this post


Link to post
Share on other sites

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
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0