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 {
while ( m_running ) {
// trigger a state change if expected
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();
......
......@@ -43,7 +43,7 @@ namespace fggl::scenes {
}
void Game::update() {
assert( m_world );
assert( m_world && "called game update, but there was no world - was activate called?" );
if ( m_input != nullptr ) {
bool escapePressed = m_input->keyboard.pressed(glfwGetKeyScancode(GLFW_KEY_ESCAPE));
......
......@@ -48,12 +48,16 @@ namespace fggl::util {
return (T *) (m_states[name].get());
}
void change(const Identifer &name) {
assertm(m_states.find(name) != m_states.end(), "state does not exist");
bool change(const Identifer &name) {
if ( m_states.find(name) == m_states.end() ) {
debug::error("attempted to change to non-existent state {}, ignoring you.", name);
return false;
}
active().deactivate();
m_active = name;
active().activate();
return true;
}
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