Skip to content

Commit

Permalink
Added check for initial states
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuskrause committed Aug 3, 2022
1 parent 6ae1197 commit 6379626
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
4 changes: 2 additions & 2 deletions engine/include/state/state-handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ namespace pte
void add_state(state_ref new_state, bool replacing);
void remove_state();
void process_state_changes();
int get_states_size();

bool have_state_active();
state_ref &get_active_state();
};
}
Expand Down
14 changes: 6 additions & 8 deletions engine/src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,15 @@ namespace pte

void Game::run()
{

// start a new splash state
data->state_handler.add_state(state_ref(new SplashState(this->data)), true);

std::cout << data->state_handler.get_states_size() << std::endl;
// check if the game have one state to start
// if (data->state_handler.get_states_size() != 0)
// {
// std::cerr << "No states initialized. Exiting." << std::endl;
// exit(100);
// }
//check if the game have one state to start
if (data->state_handler.have_state_active() == false)
{
std::cerr << "No states initialized. Exiting." << std::endl;
exit(100);
}

float new_time, frame_time, interpolation;
float current_time = this->clock.getElapsedTime().asSeconds();
Expand Down
13 changes: 11 additions & 2 deletions engine/src/state/state-handler.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "state/state-handler.hpp"
#include <iostream>

namespace pte
{
Expand Down Expand Up @@ -53,7 +54,15 @@ namespace pte
return this->states.top();
}

int StateHandler::get_states_size() {
return this->states.size();
bool StateHandler::have_state_active()
{
if (this->new_state == nullptr)
{
return false;
}
else
{
return true;
}
}
}

0 comments on commit 6379626

Please sign in to comment.