• 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
ryan mccabe

GameState as a game's conciousness

1 post in this topic

Last night I had a moment of inspiration which will either sound like utter nonsense to experienced folks or be on a right path. So I'm putting it out for review. Note that this is a purely conceptual design so far, I'm making the topic before I begin working on proper design to see if its feasible, or common sense . . . or nonsense. [i]For a summery skip the next block.[/i]

System is the root class, it has a structure composed of containers such as vectors called [b]GameState[/b].
System runs the game loop.
First 'windows messages' is checked and inputs are passed to the class [b]InputClass[/b]
[b]System [/b]runs [b]frame[/b]() in which:
[b]InputUpdat[/b]e() is called passing [b]GameState[/b] into [b]InputClass[/b]
[b]InputClass[/b] has the current frames input messages which it uses to update [b]GameState[/b]
[b]InputUpdate [/b]returns the updated [b]GameState[/b]
[b]GameLogicClass[/b] is called with [b]GameLogicUpdate([/b]) which takes [b]GameState[/b]
[b]GameLogicClass[/b] does two things: it breaks down [b]GameState[/b] to [b]AiGameState[/b] and does none entity processes with [b]GameState[/b]
[b]GameLogicClass[/b] calls [b]AiUpdate[/b]() passing [b]AiGameState[/b] to [b]AiClass[/b]
[b]AiClass[/b] breaks down [b]AiGameState[/b] to [b]EntityGameState[/b] calling [b]EntityUpdate[/b]() to pass [b]EntityGameState[/b] where there are multiple entities and thus multiple [b]EntityGameStates[/b] ([b]JoesGameState, JanesGameState[/b])
Each entity process its own [b]AiGameState[/b] subset and returns it, the returned subsets then update the superset [b]AiGameState [/b]
[b]AiGameState [/b]then updates [b]GameState [/b]inside [b]GameLogicClass [/b]after [b]AiUpdate [/b]returns it
[b]GameLogicClass [/b]returns to [b]System [/b]with an update representing the computers choices and other updates like adding to a construction timer
[b]GraphicsLogicClass [/b]then does its thing with [b]GameState[/b], particle calculations ect.
[b]FinalUpdateClass[/b] messes some more with [b]GameState [/b](placeholder class, UI ect would go here)
[b]GraphicsClass [/b]finally gets [b]GameState [/b]and renders it when it returns the game loop restarts with updated [b]GameState[/b]
To save, [b]System[/b] calls a function that writes [b]GameState[/b] to a file and before game loop begins at runtime the user can load it or start new.

My thinking behind this is the [b]GameState [/b]is like the consciousness of the game all of the classes are mental faculties. Entities get subsets of [b]GameSate[/b] because they shouldn't know everything in the game.
Also as classes breakdown [b]GameState [/b]the resulting structure is faster to update. When all of the subsets in a class are updated they can all be used to update the superset in one go. Each minor function does not have to deal with the whole [b]GameState[/b]. By using a master [b]GameState [/b]to pass to core functions I never have to worry about any class calling another except for system, everything is an independent module depending only on [b]GameSate[/b], and only affecting [b]GameState[/b]. To add physics for example I just write the class and pass it [b]GameState[/b].

Comments, suggestions, criticisms, additions are greatly appreciated. A design philosophy is what I'm after and I'm hoping Ive hit it on the head with this. If I haven't Id really benefit from knowing now while the summer semester is young.

Share this post

Link to post
Share on other sites
There is no need to provide additional encapsulation over a game state, and in fact doing so short-sightedly will likely cause need for changes down the road.

Beyond that, I agree with the ideas you have in a vague sense; but I think you're over-complicating your interface.

Here is what I usually do for my "GameMode" class (generally the same concept):

@class GameMode
Encapsulates all game-implementation specific things, and allows for vast changes in
how the game might be played or how game logic might be performed between various
states, without requiring a bunch of conditionals etc.
class GameMode
@fn Update
Handles player input, game logic and physics, and prepares for the next frame.
@param elapsedtime
Time in milliseconds between this frame and the last frame.
@param next
Next gamemode to be run. "this" to continue with this mode, "NULL" to quit.
@return true if the caller is responsible for freeing the gamemode.
virtual bool Update(uint64_t elapsedtime, GameMode*& next) = 0;
@fn Draw
Does nothing but draw the game.
@param elapsedtime
Time in milliseconds between this frame and the last frame.
@param context
The rendering context for this game -- Direct3DDevice9, GL context, SDL_Renderer, w.e you're using here.
virtual void Draw(uint64_t elapsedtime, RenderContext& context) = 0;

class GM_TitleScreen: public GameMode
/* implement the gamemode here */

int main(int argc, char** argv)
// get a rendering context
RenderContext context = SetupRendering();
// get the time of starting the game
uint64_t lasttime = GetTimeMS();
// create the title/loading screen
GameMode* game = new GM_TitleScreen(...);
// loop as long as we have a game state
// calculate elapsed time
uint64_t now = GetTimeMS();
uint64_t elapsedtime = now - lasttime;
GameMode* next = game;

// draw the game
game->Draw(elapsedtime, context);

// update the game
bool freegame = game->Update(elapsedtime, next);
// change gamemode as requested by Update
delete game;
game = next;

return 0;

It's a method I learned a few years ago and it's so simple and flexible that I still use it today. You'll see it occasionally in open-source games in one form or another, too.

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