mirror of
https://github.com/rwengine/openrw.git
synced 2024-09-15 06:52:34 +02:00
Improve pausing behaviour with State::shouldWorldUpdate()
This commit is contained in:
parent
bc54fac53a
commit
95b6e6a676
@ -419,7 +419,7 @@ void GameRenderer::renderWorld(const ViewCamera &camera, float alpha)
|
||||
}
|
||||
|
||||
float fadeTimer = engine->gameTime - engine->state.fadeStart;
|
||||
if( fadeTimer <= engine->state.fadeTime || !engine->state.fadeOut ) {
|
||||
if( fadeTimer < engine->state.fadeTime || !engine->state.fadeOut ) {
|
||||
glUseProgram(ssRectProgram);
|
||||
glUniform2f(ssRectOffset, 0.f, 0.f);
|
||||
glUniform2f(ssRectSize, 1.f, 1.f);
|
||||
|
@ -138,6 +138,8 @@ int RWGame::run()
|
||||
|
||||
// Loop until the window is closed or we run out of state.
|
||||
while (window.isOpen() && StateManager::get().states.size()) {
|
||||
State* state = StateManager::get().states.back();
|
||||
|
||||
sf::Event event;
|
||||
while (window.pollEvent(event)) {
|
||||
switch (event.type) {
|
||||
@ -155,7 +157,7 @@ int RWGame::run()
|
||||
default: break;
|
||||
}
|
||||
|
||||
StateManager::get().states.back()->handleEvent(event);
|
||||
state->handleEvent(event);
|
||||
}
|
||||
|
||||
if(! window.isOpen() )
|
||||
@ -167,31 +169,30 @@ int RWGame::run()
|
||||
accum += timer * timescale;
|
||||
|
||||
while ( accum >= GAME_TIMESTEP ) {
|
||||
|
||||
if( ! getWorld()->isPaused() )
|
||||
{
|
||||
StateManager::get().tick(GAME_TIMESTEP);
|
||||
|
||||
tick(GAME_TIMESTEP);
|
||||
}
|
||||
|
||||
accum -= GAME_TIMESTEP;
|
||||
|
||||
// Throw away time if the accumulator reaches too high.
|
||||
if ( accum > GAME_TIMESTEP )
|
||||
if ( accum > GAME_TIMESTEP * 5.f )
|
||||
{
|
||||
accum = 0.f;
|
||||
}
|
||||
}
|
||||
|
||||
float alpha = fmod(accum, GAME_TIMESTEP) / GAME_TIMESTEP;
|
||||
if( ! state->shouldWorldUpdate() )
|
||||
{
|
||||
alpha = 1.f;
|
||||
}
|
||||
|
||||
render(alpha, timer);
|
||||
|
||||
StateManager::get().draw(renderer);
|
||||
|
||||
window.display();
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -201,12 +202,13 @@ void RWGame::tick(float dt)
|
||||
{
|
||||
// Clear out any per-tick state.
|
||||
engine->clearTickData();
|
||||
|
||||
// Process the Engine's background work.
|
||||
engine->_work->update();
|
||||
|
||||
State* state = StateManager::get().states.back();
|
||||
|
||||
static float clockAccumulator = 0.f;
|
||||
if (inFocus) {
|
||||
if (inFocus && state->shouldWorldUpdate() ) {
|
||||
engine->gameTime += dt;
|
||||
|
||||
clockAccumulator += dt;
|
||||
@ -270,7 +272,7 @@ void RWGame::tick(float dt)
|
||||
|
||||
// render() needs two cameras to smoothly interpolate between ticks.
|
||||
lastCam = nextCam;
|
||||
nextCam = StateManager::get().states.back()->getCamera();
|
||||
nextCam = state->getCamera();
|
||||
}
|
||||
|
||||
void RWGame::render(float alpha, float time)
|
||||
|
@ -9,6 +9,11 @@ const ViewCamera& State::getCamera()
|
||||
return defaultView;
|
||||
}
|
||||
|
||||
bool State::shouldWorldUpdate()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
GameWorld* State::getWorld()
|
||||
{
|
||||
return game->getWorld();
|
||||
|
@ -87,6 +87,12 @@ struct State
|
||||
|
||||
virtual const ViewCamera& getCamera();
|
||||
|
||||
/**
|
||||
* Returns false if the game world should not should
|
||||
* not update while this state is active
|
||||
*/
|
||||
virtual bool shouldWorldUpdate();
|
||||
|
||||
GameWorld* getWorld();
|
||||
sf::RenderWindow& getWindow();
|
||||
};
|
||||
|
@ -314,6 +314,11 @@ void IngameState::handleEvent(const sf::Event &event)
|
||||
State::handleEvent(event);
|
||||
}
|
||||
|
||||
bool IngameState::shouldWorldUpdate()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
const ViewCamera &IngameState::getCamera()
|
||||
{
|
||||
return _look;
|
||||
|
@ -32,6 +32,8 @@ public:
|
||||
|
||||
virtual void handleEvent(const sf::Event& event);
|
||||
|
||||
virtual bool shouldWorldUpdate();
|
||||
|
||||
const ViewCamera& getCamera();
|
||||
};
|
||||
|
||||
|
@ -40,6 +40,11 @@ void LoadingState::tick(float dt)
|
||||
}
|
||||
}
|
||||
|
||||
bool LoadingState::shouldWorldUpdate()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void LoadingState::setNextState(State* nextState)
|
||||
{
|
||||
next = nextState;
|
||||
|
@ -18,6 +18,8 @@ public:
|
||||
|
||||
void setNextState(State* nextState);
|
||||
|
||||
virtual bool shouldWorldUpdate();
|
||||
|
||||
virtual void handleEvent(const sf::Event& event);
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user