Skip to content

Instantly share code, notes, and snippets.

@Joshhua5
Created July 30, 2014 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Joshhua5/072371448382abbcee94 to your computer and use it in GitHub Desktop.
Save Joshhua5/072371448382abbcee94 to your computer and use it in GitHub Desktop.
#pragma once
#include <vector>
class GameState{
struct Function{
bool isLua;
union{
// returns void and has no arguments
void (*function_pointer)();
char* lua_function;
};
Function(){
function_pointer = nullptr;
lua_function = nullptr;
}
};
Function m_update;
Function m_render;
Function m_initialize;
Function m_return;
Function m_cleanup;
public:
bool active;
// A function called
// when the stack is being updated
void setUpdate();
// A function called when
// when the stack is being rendered
void setRender();
// A function called when
// the state is first created
void setInitialize();
// A Function called when
// set to the top of the stack
void setReturn();
// A function called
// when removed from the stack
void setCleanup();
};
class StateStack{
std::vector<GameState> m_stack;
public:
// The bool if true will stop the state below (originally on top) it in the stack from updating
// if false then it will also recieve updates.
// This allows us to not render the menu when we push on our game state,
// but all us to push ontop of that game state a GUI without stopping the game state.
void push(GameState, bool);
// The stack that is poped will have it's cleanup function called
// if one has been defined.
void pop();
// executes the stack, starting at the base
void execute();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment