Don't use the time during a rewind to determine if a client needs

to slow down.
This commit is contained in:
hiker 2017-01-27 23:45:25 +11:00
parent 7ad0a0cf69
commit cebf24f3af
4 changed files with 23 additions and 10 deletions

View File

@ -964,7 +964,7 @@ void World::update(float dt)
PROFILER_PUSH_CPU_MARKER("World::update (sub-updates)", 0x20, 0x7F, 0x00);
WorldStatus::update(dt);
RewindManager::get()->saveStates();
RewindManager::get()->update();
PROFILER_POP_CPU_MARKER();
PROFILER_PUSH_CPU_MARKER("World::update (Kart::upate)", 0x40, 0x7F, 0x00);

View File

@ -131,9 +131,6 @@ void GameProtocol::controllerAction(int kart_id, PlayerAction action,
World::getWorld()->getTime(), action, value);
} // controllerAction
#include "utils/time.hpp"
// ----------------------------------------------------------------------------
/** Called when a controller event is receiver - either on the server from
* a client, or on a client from the server. It sorts the event into the
@ -149,10 +146,15 @@ void GameProtocol::handleControllerAction(Event *event)
for (unsigned int i = 0; i < count; i++)
{
float time = data.getFloat();
if (time < World::getWorld()->getTime())
// Since this is running in a thread, it might be called during
// a rewind, i.e. with an incorrect world time. So the event
// time needs to be compared with the World time independent
// of any rewinding.
if (time < RewindManager::get()->getNotRewoundWorldTime() &&
!will_trigger_rewind )
{
will_trigger_rewind = true;
rewind_delta = time - World::getWorld()->getTime();
rewind_delta = time - RewindManager::get()->getNotRewoundWorldTime();
}
uint8_t kart_id = data.getUInt8();
assert(kart_id < World::getWorld()->getNumKarts());
@ -181,8 +183,10 @@ void GameProtocol::handleControllerAction(Event *event)
&data, false);
if (will_trigger_rewind)
{
Log::info("GameProtocol", "At %f %f requesting time adjust of %f for host %d",
Log::info("GameProtocol",
"At %f %f %f requesting time adjust of %f for host %d",
World::getWorld()->getTime(), StkTime::getRealTime(),
RewindManager::get()->getNotRewoundWorldTime(),
rewind_delta, event->getPeer()->getHostId());
// This message from a client triggered a rewind in the server.
// To avoid this, signal to the client that it should slow down.

View File

@ -73,6 +73,7 @@ RewindManager::~RewindManager()
void RewindManager::reset()
{
m_is_rewinding = false;
m_not_rewound_time = 0;
m_overall_state_size = 0;
m_state_frequency = 0.1f; // save 10 states a second
m_last_saved_state = -9999.9f; // forces initial state save
@ -157,13 +158,15 @@ void RewindManager::addNetworkState(int rewinder_index,
* rewinder to do so.
* \param dt Time step size.
*/
void RewindManager::saveStates()
void RewindManager::update()
{
if(!m_enable_rewind_manager ||
m_all_rewinder.size()==0 ||
m_is_rewinding ) return;
float time = World::getWorld()->getTime();
m_not_rewound_time = time;
// Client doesn't save state (atm), so we need to store
// time infos to get the correct dt when rewinding
@ -208,7 +211,7 @@ void RewindManager::saveStates()
World::getWorld()->getTime(), m_overall_state_size);
m_last_saved_state = time;
} // saveStates
} // update
// ----------------------------------------------------------------------------
/** Replays all events from the last event played till the specified time.

View File

@ -112,6 +112,10 @@ private:
* events later. */
float m_current_time;
/** This stores the original World time during a rewind. It is used to
* detect if a client's local time need adjustment to reduce rewinds. */
float m_not_rewound_time;
RewindManager();
~RewindManager();
@ -138,7 +142,7 @@ public:
// Non-static functtion declarations:
void reset();
void saveStates();
void update();
void rewindTo(float target_time);
void playEventsTill(float time);
void addEvent(EventRewinder *event_rewinder, BareNetworkString *buffer,
@ -176,6 +180,8 @@ public:
// ------------------------------------------------------------------------
/** Returns true if currently a rewind is happening. */
bool isRewinding() const { return m_is_rewinding; }
// ------------------------------------------------------------------------
float getNotRewoundWorldTime() const { return m_not_rewound_time; }
}; // RewindManager