2016-07-02 20:49:31 +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();
|
2016-06-22 12:29:39 +02:00
|
|
|
getWindow().hideCursor();
|
2014-06-06 13:18:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void LoadingState::exit()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void LoadingState::tick(float dt)
|
|
|
|
{
|
2016-08-02 13:00:05 +02:00
|
|
|
RW_UNUSED(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;
|
|
|
|
}
|
|
|
|
|
2016-06-22 12:29:39 +02:00
|
|
|
void LoadingState::handleEvent(const SDL_Event& e)
|
2014-06-06 13:18:32 +02:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|