1) Fixed time when state snapshots are taken (must be before the physics runs)
2) Added support for storing the exact time step sizes (probably only for debugging - since now we can try to have bitwise identical results when replaying). git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/rewind@13631 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
@@ -1060,8 +1060,6 @@ void Kart::eliminate()
|
||||
*/
|
||||
void Kart::update(float dt)
|
||||
{
|
||||
m_rewinder->update();
|
||||
|
||||
if ( UserConfigParams::m_graphical_effects )
|
||||
{
|
||||
// update star effect (call will do nothing if stars are not activated)
|
||||
@@ -1336,6 +1334,10 @@ void Kart::update(float dt)
|
||||
m_shadow->enableShadow();
|
||||
m_shadow_enabled = true;
|
||||
}
|
||||
|
||||
// Store current controls if there was any change from the previous state:
|
||||
m_rewinder->update();
|
||||
|
||||
} // update
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -1944,11 +1946,15 @@ void Kart::updatePhysics(float dt)
|
||||
{
|
||||
m_has_started = true;
|
||||
float f = m_kart_properties->getStartupBoost();
|
||||
m_max_speed->instantSpeedIncrease(MaxSpeed::MS_INCREASE_ZIPPER,
|
||||
0.9f*f, f,
|
||||
/*engine_force*/200.0f,
|
||||
/*duration*/5.0f,
|
||||
/*fade_out_time*/5.0f);
|
||||
|
||||
// Only give the additional engine_force if a boost was reached
|
||||
// (otherwise even with f==0, the 200 engine force would apply)
|
||||
if(f>0)
|
||||
m_max_speed->instantSpeedIncrease(MaxSpeed::MS_INCREASE_ZIPPER,
|
||||
0.9f*f, f,
|
||||
/*engine_force*/200.0f,
|
||||
/*duration*/5.0f,
|
||||
/*fade_out_time*/5.0f);
|
||||
}
|
||||
|
||||
m_bounce_back_time-=dt;
|
||||
|
||||
@@ -831,6 +831,9 @@ void World::update(float dt)
|
||||
// Clear race state so that new information can be stored
|
||||
race_state->clear();
|
||||
|
||||
RewindManager::get()->saveStates(dt);
|
||||
|
||||
|
||||
if(network_manager->getMode()!=NetworkManager::NW_CLIENT &&
|
||||
!history->dontDoPhysics())
|
||||
{
|
||||
@@ -851,8 +854,6 @@ void World::update(float dt)
|
||||
|
||||
projectile_manager->update(dt);
|
||||
|
||||
RewindManager::get()->update(dt);
|
||||
|
||||
PROFILER_POP_CPU_MARKER();
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
|
||||
#include "modes/world.hpp"
|
||||
#include "network/rewinder.hpp"
|
||||
#include "physics/physics.hpp"
|
||||
#include "race/history.hpp"
|
||||
#include "utils/log.hpp"
|
||||
|
||||
RewindManager* RewindManager::m_rewind_manager = NULL;
|
||||
@@ -53,6 +55,7 @@ RewindManager::RewindInfo::RewindInfo(Rewinder *rewinder, float time,
|
||||
{
|
||||
m_rewinder = rewinder;
|
||||
m_time = time;
|
||||
m_local_physics_time = World::getWorld()->getPhysics()->getPhysicsWorld()->getLocalTime();
|
||||
m_buffer = buffer;
|
||||
m_type = is_event ? RIT_EVENT : RIT_STATE;
|
||||
m_is_confirmed = is_confirmed;
|
||||
@@ -63,6 +66,7 @@ RewindManager::RewindInfo::RewindInfo(float time)
|
||||
{
|
||||
m_rewinder = NULL;
|
||||
m_time = time;
|
||||
m_local_physics_time = World::getWorld()->getPhysics()->getPhysicsWorld()->getLocalTime();
|
||||
m_buffer = NULL;
|
||||
m_type = RIT_TIME;
|
||||
m_is_confirmed = true;
|
||||
@@ -229,7 +233,7 @@ void RewindManager::addEvent(Rewinder *rewinder, float time, char *buffer)
|
||||
* rewinder to do so.
|
||||
* \param dt Time step size.
|
||||
*/
|
||||
void RewindManager::update(float dt)
|
||||
void RewindManager::saveStates(float dt)
|
||||
{
|
||||
if(!m_enable_rewind_manager ||
|
||||
m_all_rewinder.size()==0 ||
|
||||
@@ -265,7 +269,8 @@ void RewindManager::update(float dt)
|
||||
float(m_count_of_comparisons)/ float(m_count_of_searches) );
|
||||
|
||||
m_last_saved_state = time;
|
||||
} // update
|
||||
} // saveStates
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Rewinds to the specified time.
|
||||
* \param t Time to rewind to.
|
||||
@@ -275,6 +280,8 @@ void RewindManager::rewindTo(float rewind_time)
|
||||
assert(!m_is_rewinding);
|
||||
m_is_rewinding = true;
|
||||
|
||||
history->doReplayHistory(History::HISTORY_NONE);
|
||||
|
||||
// First find the state to which we need to rewind
|
||||
// ------------------------------------------------
|
||||
int state = findFirstIndex(rewind_time);
|
||||
@@ -311,6 +318,7 @@ void RewindManager::rewindTo(float rewind_time)
|
||||
// Rewind to the required state
|
||||
// ----------------------------
|
||||
float exact_rewind_time = m_rewind_info[state]->getTime();
|
||||
World::getWorld()->getPhysics()->getPhysicsWorld()->setLocalTime(m_rewind_info[state]->getLocalPhysicsTime());
|
||||
|
||||
// Rewind all objects (and also all state) that happen at the
|
||||
// current time.
|
||||
|
||||
@@ -108,6 +108,9 @@ private:
|
||||
/** Time when this state was taken. */
|
||||
float m_time;
|
||||
|
||||
/** The 'left over' time from the physics. */
|
||||
float m_local_physics_time;
|
||||
|
||||
/** Type of this information. */
|
||||
RewindInfoType m_type;
|
||||
|
||||
@@ -144,6 +147,9 @@ private:
|
||||
/** Returns if this state is confirmed. */
|
||||
bool isConfirmed() const { return m_is_confirmed; }
|
||||
// --------------------------------------------------------------------
|
||||
/** Returns the left-over physics time. */
|
||||
float getLocalPhysicsTime() const { return m_local_physics_time; }
|
||||
// --------------------------------------------------------------------
|
||||
/** Called when going back in time to undo any rewind information.
|
||||
* It calls either undoEvent or undoState in the rewinder. */
|
||||
void undo()
|
||||
@@ -236,7 +242,7 @@ public:
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
void reset();
|
||||
void update(float dt);
|
||||
void saveStates(float dt);
|
||||
// ------------------------------------------------------------------------
|
||||
/** Adds a Rewinder to the list of all rewinders.
|
||||
* \return true If rewinding is enabled, false otherwise.
|
||||
|
||||
@@ -38,8 +38,13 @@ public:
|
||||
|
||||
/** Resets m_localTime to 0. This allows more precise replay of
|
||||
* physics, which is important for replaying histories. */
|
||||
virtual void resetLocalTime() { m_localTime = 0; }
|
||||
|
||||
void resetLocalTime() { m_localTime = 0; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Sets the local time to a specified value. Used in rewinding. */
|
||||
void setLocalTime(float t) { m_localTime = t; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Gets the local time. */
|
||||
float getLocalTime() const { return m_localTime; }
|
||||
}; // STKDynamicsWorld
|
||||
#endif
|
||||
/* EOF */
|
||||
|
||||
Reference in New Issue
Block a user