Add shouldSaveSate with ticks for checking

This commit is contained in:
Benau 2018-12-31 10:41:44 +08:00
parent 5458fcea4e
commit 7a60c4a35a
2 changed files with 7 additions and 7 deletions

View File

@ -79,7 +79,6 @@ void RewindManager::reset()
m_is_rewinding = false;
m_not_rewound_ticks.store(0);
m_overall_state_size = 0;
m_last_saved_state = -1; // forces initial state save
m_state_frequency = stk_config->getPhysicsFPS() /
NetworkConfig::get()->getStateFrequency();
@ -189,7 +188,7 @@ void RewindManager::update(int ticks_not_used)
m_not_rewound_ticks.store(ticks, std::memory_order_relaxed);
if (ticks - m_last_saved_state < m_state_frequency)
if (!shouldSaveState(ticks))
return;
// Save state, remove expired rewinder first
@ -211,7 +210,6 @@ void RewindManager::update(int ticks_not_used)
gp->sendState();
}
PROFILER_POP_CPU_MARKER();
m_last_saved_state = ticks;
} // update
// ----------------------------------------------------------------------------

View File

@ -109,9 +109,6 @@ private:
/** How much time between consecutive state saves. */
int m_state_frequency;
/** Ticks at which the last state was saved. */
int m_last_saved_state;
/** This stores the original World time in ticks during a rewind. It is
* used to detect if a client's local time need adjustment to reduce
* rewinds. */
@ -205,7 +202,12 @@ public:
// ------------------------------------------------------------------------
void addNetworkRewindInfo(RewindInfo* ri)
{ m_rewind_queue.addNetworkRewindInfo(ri); }
// ------------------------------------------------------------------------
bool shouldSaveState(int ticks)
{
int a = ticks - m_state_frequency + 1;
return ticks != 0 && a >= 0 && a % m_state_frequency == 0;
}
}; // RewindManager