Skip to content
Snippets Groups Projects
Commit 464dcba7 authored by Joseph Walton-Rivers's avatar Joseph Walton-Rivers
Browse files

handle non-existant states more gracefully

parent 9b916e92
No related branches found
No related tags found
No related merge requests found
...@@ -46,7 +46,10 @@ namespace fggl { ...@@ -46,7 +46,10 @@ namespace fggl {
while ( m_running ) { while ( m_running ) {
// trigger a state change if expected // trigger a state change if expected
if ( m_expectedScene != m_states.activeID() ) { if ( m_expectedScene != m_states.activeID() ) {
m_states.change(m_expectedScene); auto result = m_states.change(m_expectedScene);
if ( !result ) {
m_expectedScene = m_states.activeID();
}
} }
auto& state = m_states.active(); auto& state = m_states.active();
......
...@@ -43,7 +43,7 @@ namespace fggl::scenes { ...@@ -43,7 +43,7 @@ namespace fggl::scenes {
} }
void Game::update() { void Game::update() {
assert( m_world ); assert( m_world && "called game update, but there was no world - was activate called?" );
if ( m_input != nullptr ) { if ( m_input != nullptr ) {
bool escapePressed = m_input->keyboard.pressed(glfwGetKeyScancode(GLFW_KEY_ESCAPE)); bool escapePressed = m_input->keyboard.pressed(glfwGetKeyScancode(GLFW_KEY_ESCAPE));
......
...@@ -48,12 +48,16 @@ namespace fggl::util { ...@@ -48,12 +48,16 @@ namespace fggl::util {
return (T *) (m_states[name].get()); return (T *) (m_states[name].get());
} }
void change(const Identifer &name) { bool change(const Identifer &name) {
assertm(m_states.find(name) != m_states.end(), "state does not exist"); if ( m_states.find(name) == m_states.end() ) {
debug::error("attempted to change to non-existent state {}, ignoring you.", name);
return false;
}
active().deactivate(); active().deactivate();
m_active = name; m_active = name;
active().activate(); active().activate();
return true;
} }
StateType &active() const { StateType &active() const {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment