2014-06-06 13:18:32 +02:00
|
|
|
#include "loadingstate.hpp"
|
2014-09-16 20:22:43 +02:00
|
|
|
#include "RWGame.hpp"
|
2015-04-05 03:12:54 +02:00
|
|
|
#include <render/OpenGLRenderer.hpp>
|
2014-06-06 13:18:32 +02:00
|
|
|
|
2014-09-16 20:22:43 +02:00
|
|
|
LoadingState::LoadingState(RWGame* game)
|
2015-04-03 02:26:20 +02:00
|
|
|
: State(game), next(nullptr)
|
2014-06-06 13:18:32 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void LoadingState::enter()
|
|
|
|
{
|
2015-05-03 06:22:03 +02:00
|
|
|
// Load Item definitions
|
|
|
|
for( auto& def : game->getGameData()->ideLocations )
|
|
|
|
{
|
|
|
|
game->getGameData()->loadObjects(def.second);
|
2014-06-06 13:18:32 +02:00
|
|
|
}
|
|
|
|
|
2015-05-03 06:22:03 +02:00
|
|
|
game->newGame();
|
2014-06-06 13:18:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void LoadingState::exit()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void LoadingState::tick(float dt)
|
|
|
|
{
|
2015-04-03 02:26:20 +02:00
|
|
|
// If background work is completed, switch to the next state
|
2014-06-06 13:18:32 +02:00
|
|
|
if( getWorld()->_work->isEmpty() ) {
|
2015-04-03 02:26:20 +02:00
|
|
|
StateManager::get().exec(next);
|
2014-06-06 13:18:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-03 16:38:24 +02:00
|
|
|
bool LoadingState::shouldWorldUpdate()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-04-03 02:26:20 +02:00
|
|
|
void LoadingState::setNextState(State* nextState)
|
|
|
|
{
|
|
|
|
next = nextState;
|
|
|
|
}
|
|
|
|
|
2014-06-06 13:18:32 +02:00
|
|
|
void LoadingState::handleEvent(const sf::Event &e)
|
|
|
|
{
|
|
|
|
State::handleEvent(e);
|
|
|
|
}
|
|
|
|
|
2015-02-07 23:55:06 +01:00
|
|
|
void LoadingState::draw(GameRenderer* r)
|
2014-06-06 13:18:32 +02:00
|
|
|
{
|
|
|
|
// Display some manner of loading screen.
|
2015-02-07 23:55:06 +01:00
|
|
|
TextRenderer::TextInfo ti;
|
|
|
|
ti.text = "Loading...";
|
2015-04-05 03:12:54 +02:00
|
|
|
auto size = r->getRenderer()->getViewport();
|
|
|
|
ti.size = 25.f;
|
|
|
|
ti.screenPosition = glm::vec2( 50.f, size.y - ti.size - 50.f );
|
2015-02-07 23:55:06 +01:00
|
|
|
ti.font = 2;
|
2016-05-07 19:29:08 +02:00
|
|
|
ti.baseColour = glm::u8vec3(255);
|
2015-02-07 23:55:06 +01:00
|
|
|
r->text.renderText(ti);
|
2014-06-06 13:18:32 +02:00
|
|
|
}
|