-
-
Save Joshhua5/072371448382abbcee94 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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