Fixed time handling to be in synch between history and rewind.

This commit is contained in:
hiker 2016-09-23 07:56:21 +10:00
parent 25a457f88f
commit 74f521980a
4 changed files with 21 additions and 30 deletions

View File

@ -35,6 +35,7 @@
#include "network/race_event_manager.hpp"
#include "network/stk_host.hpp"
#include "online/request_manager.hpp"
#include "race/history.hpp"
#include "race/race_manager.hpp"
#include "states_screens/state_manager.hpp"
#include "utils/profiler.hpp"
@ -61,6 +62,15 @@ MainLoop::~MainLoop()
*/
float MainLoop::getLimitedDt()
{
float dt = 0;
// If we are doing a replay, use the dt from the history file
if (World::getWorld() && history->replayHistory() )
{
dt = history->updateReplayAndGetDT();
return dt;
}
// In profile mode without graphics, run with a fixed dt of 1/60
if ((ProfileWorld::isProfileMode() && ProfileWorld::isNoGraphics()) ||
UserConfigParams::m_arena_ai_stats)
@ -71,7 +81,6 @@ float MainLoop::getLimitedDt()
IrrlichtDevice* device = irr_driver->getDevice();
m_prev_time = m_curr_time;
float dt; // needed outside of the while loop
while( 1 )
{
m_curr_time = device->getTimer()->getRealTime();

View File

@ -890,6 +890,11 @@ void World::updateWorld(float dt)
getPhase() == IN_GAME_MENU_PHASE )
return;
if (!history->replayHistory())
{
history->updateSaving(dt); // updating the saved state
}
try
{
update(dt);
@ -991,12 +996,6 @@ void World::update(float dt)
assert(m_magic_number == 0xB01D6543);
#endif
history->update(dt);
if (history->replayHistory())
{
dt = history->getNextDelta();
}
PROFILER_PUSH_CPU_MARKER("World::update()", 0x00, 0x7F, 0x00);
#if MEASURE_FPS

View File

@ -75,19 +75,6 @@ void History::allocateMemory(int number_of_frames)
m_all_rotations.resize(number_of_frames*num_karts);
} // allocateMemory
//-----------------------------------------------------------------------------
/** Depending on mode either saves the data for the current time step, or
* replays the data.
* /param dt Time step.
*/
void History::update(float dt)
{
if(m_replay_mode==HISTORY_NONE)
updateSaving(dt);
else
updateReplay(dt);
} // update
//-----------------------------------------------------------------------------
/** Saves the current history.
* \param dt Time step size.
@ -124,7 +111,7 @@ void History::updateSaving(float dt)
/** Sets the kart position and controls to the recorded history value.
* \param dt Time step size.
*/
void History::updateReplay(float dt)
float History::updateReplayAndGetDT()
{
m_current++;
World *world = World::getWorld();
@ -159,7 +146,8 @@ void History::updateReplay(float dt)
kart->getControls().set(m_all_controls[index]);
}
}
} // updateReplay
return m_all_deltas[m_current];
} // updateReplayAndGetDT
//-----------------------------------------------------------------------------
/** Saves the history stored in the internal data structures into a file called

View File

@ -77,26 +77,21 @@ private:
std::vector<std::string> m_kart_ident;
void allocateMemory(int number_of_frames);
void updateSaving(float dt);
void updateReplay(float dt);
public:
History ();
void startReplay ();
void initRecording ();
void update (float dt);
void Save ();
void Load ();
void updateSaving(float dt);
float updateReplayAndGetDT();
// -------------------I-----------------------------------------------------
/** Returns the identifier of the n-th kart. */
const std::string& getKartIdent(unsigned int n)
{
return m_kart_ident[n];
}
// ------------------------------------------------------------------------
/** Returns the size of the next timestep. */
float getNextDelta () const { return m_all_deltas[m_current]; }
} // getKartIdent
// ------------------------------------------------------------------------
/** Returns if a history is replayed, i.e. the history mode is not none. */
bool replayHistory () const { return m_replay_mode != HISTORY_NONE; }