diff --git a/src/karts/abstract_kart.hpp b/src/karts/abstract_kart.hpp index f7105603a..7fba6d672 100644 --- a/src/karts/abstract_kart.hpp +++ b/src/karts/abstract_kart.hpp @@ -116,9 +116,6 @@ public: // ------------------------------------------------------------------------ /** Returns all controls of this kart - const version. */ const KartControl& getControls() const { return m_controls; } - // ------------------------------------------------------------------------ - /** Sets the kart controls. Used e.g. by replaying history. */ - void setControls(const KartControl &c) { m_controls = c; } // ======================================================================== // Access to the kart properties. diff --git a/src/karts/controller/kart_control.cpp b/src/karts/controller/kart_control.cpp index 5532949c1..8075a68f2 100644 --- a/src/karts/controller/kart_control.cpp +++ b/src/karts/controller/kart_control.cpp @@ -46,14 +46,31 @@ void KartControl::rewind(BareNetworkString *buffer) } } // rewind +// ------------------------------------------------------------------------ +/** Sets this KartControl form the given value (basically a copy). This + * function uses the explicit setSteer() etc function, which means that + * rewind information will be collected. + */ +void KartControl::set(const KartControl &c) +{ + setAccel(c.getAccel()); + setBrake(c.getBrake()); + setFire(c.getFire()); + setLookBack(c.getLookBack()); + setNitro(c.getNitro()); + setRescue(c.getRescue()); + setSkidControl(c.getSkidControl()); + setSteer(c.getSteer()); +} // set + // ------------------------------------------------------------------------ /** Sets the current steering value. */ void KartControl::setSteer(float f) { float old_steer = m_steer; m_steer = f; - RewindManager *re = RewindManager::get(); - if (re->isEnabled() && !re->isRewinding() && old_steer != m_steer) + if (RewindManager::isEnabled() && !RewindManager::get()->isRewinding() && + old_steer != m_steer ) { // Save full status BareNetworkString *buffer = new BareNetworkString(getLength()); @@ -68,8 +85,8 @@ void KartControl::setAccel(float f) { float old_accel = m_accel; m_accel = f; - RewindManager *re = RewindManager::get(); - if (re->isEnabled() && !re->isRewinding() && old_accel != m_accel) + if (RewindManager::isEnabled() && !RewindManager::get()->isRewinding() && + old_accel != m_accel ) { BareNetworkString *buffer = new BareNetworkString(getLength()); copyToBuffer(buffer); @@ -81,10 +98,10 @@ void KartControl::setAccel(float f) /** Sets if the kart is braking. */ void KartControl::setBrake(bool b) { - bool old_brake = m_brake; - m_brake = b; - RewindManager *re = RewindManager::get(); - if (re->isEnabled() && !re->isRewinding() && old_brake != m_brake) + bool old_brake = m_brake; + m_brake = b; + if (RewindManager::isEnabled() && !RewindManager::get()->isRewinding() && + old_brake != m_brake ) { // Only store the buttons in this case BareNetworkString *buffer = new BareNetworkString(1); @@ -98,8 +115,8 @@ void KartControl::setNitro(bool b) { bool old_nitro = m_nitro; m_nitro = b; - RewindManager *re = RewindManager::get(); - if (re->isEnabled() && !re->isRewinding() && old_nitro != m_nitro) + if (RewindManager::isEnabled() && !RewindManager::get()->isRewinding() && + old_nitro != m_nitro ) { BareNetworkString *buffer = new BareNetworkString(1); buffer->addUInt8(getButtonsCompressed()); @@ -113,8 +130,8 @@ void KartControl::setSkidControl(SkidControl sc) { SkidControl old_skid = m_skid; m_skid = sc; - RewindManager *re = RewindManager::get(); - if (re->isEnabled() && !re->isRewinding() && old_skid != m_skid) + if (RewindManager::isEnabled() && !RewindManager::get()->isRewinding() && + old_skid != m_skid ) { BareNetworkString *buffer = new BareNetworkString(1); buffer->addUInt8(getButtonsCompressed()); @@ -128,8 +145,8 @@ void KartControl::setRescue(bool b) { bool old_rescue = m_rescue; m_rescue = b; - RewindManager *re = RewindManager::get(); - if (re->isEnabled() && !re->isRewinding() && old_rescue != m_rescue) + if (RewindManager::isEnabled() && !RewindManager::get()->isRewinding() && + old_rescue != m_rescue) { BareNetworkString *buffer = new BareNetworkString(1); buffer->addUInt8(getButtonsCompressed()); @@ -143,8 +160,8 @@ void KartControl::setFire(bool b) { bool old_fire = m_fire; m_fire = b; - RewindManager *re = RewindManager::get(); - if (re->isEnabled() && !re->isRewinding() && old_fire != m_fire) + if (RewindManager::isEnabled() && !RewindManager::get()->isRewinding() && + old_fire != m_fire ) { BareNetworkString *buffer = new BareNetworkString(1); buffer->addUInt8(getButtonsCompressed()); @@ -158,8 +175,8 @@ void KartControl::setLookBack(bool b) { bool old_look = m_look_back; m_look_back = b; - RewindManager *re = RewindManager::get(); - if (re->isEnabled() && !re->isRewinding() && old_look != m_look_back) + if (RewindManager::isEnabled() && !RewindManager::get()->isRewinding() && + old_look != m_look_back) { BareNetworkString *buffer = new BareNetworkString(1); buffer->addUInt8(getButtonsCompressed()); diff --git a/src/karts/controller/kart_control.hpp b/src/karts/controller/kart_control.hpp index 438132cd5..e4a2afec4 100644 --- a/src/karts/controller/kart_control.hpp +++ b/src/karts/controller/kart_control.hpp @@ -61,6 +61,7 @@ public: void setRescue(bool b); void setFire(bool b); void setLookBack(bool b); + void set(const KartControl &c); // ------------------------------------------------------------------------ KartControl() diff --git a/src/race/history.cpp b/src/race/history.cpp index 82f8fe79f..b3d5d479d 100644 --- a/src/race/history.cpp +++ b/src/race/history.cpp @@ -23,6 +23,7 @@ #include "io/file_manager.hpp" #include "modes/world.hpp" #include "karts/abstract_kart.hpp" +#include "network/rewind_manager.hpp" #include "physics/physics.hpp" #include "race/race_manager.hpp" #include "tracks/track.hpp" @@ -131,9 +132,17 @@ void History::updateReplay(float dt) { Log::info("History", "Replay finished"); m_current = 0; + // This is useful to use a reproducable rewind problem: + // replay it with history, for debugging only +#undef DO_REWIND_AT_END_OF_HISTORY +#ifdef DO_REWIND_AT_END_OF_HISTORY + RewindManager::get()->rewindTo(5.0f); + exit(-1); +#else // Note that for physics replay all physics parameters // need to be reset, e.g. velocity, ... world->reset(); +#endif } unsigned int num_karts = world->getNumKarts(); for(unsigned k=0; ksetControls(m_all_controls[index]); + kart->getControls().set(m_all_controls[index]); } } } // updateReplay @@ -314,6 +323,11 @@ void History::Load() sscanf(s, "delta: %f\n",&m_all_deltas[i]); } + // We need to disable the rewind manager here (otherwise setting the + // KartControl data would access the rewind manager). + bool rewind_manager_was_enabled = RewindManager::isEnabled(); + RewindManager::setEnable(false); + for(int i=0; i