Removed unnecessary events crated by KartControl, added steer_left
and steer_right values from the player controller to the state to fix steering synchronsiation problems.
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
#define HEADER_AI_BASE_CONTROLLER_HPP
|
||||
|
||||
#include "karts/controller/controller.hpp"
|
||||
#include "utils/cpp2011.hpp"
|
||||
|
||||
class AIProperties;
|
||||
class Track;
|
||||
@@ -71,6 +72,7 @@ protected:
|
||||
/** This can be called to detect if the kart is stuck (i.e. repeatedly
|
||||
* hitting part of the track). */
|
||||
bool isStuck() const { return m_stuck; }
|
||||
// ------------------------------------------------------------------------
|
||||
void determineTurnRadius(const Vec3 &end, Vec3 *center,
|
||||
float *radius) const;
|
||||
virtual void update (float delta);
|
||||
@@ -98,6 +100,10 @@ public:
|
||||
virtual bool isLocalPlayerController() const { return false; }
|
||||
virtual void action(PlayerAction action, int value) {};
|
||||
virtual void skidBonusTriggered() {};
|
||||
// ------------------------------------------------------------------------
|
||||
/** Not used for AIs. */
|
||||
virtual void saveState(BareNetworkString *buffer) const OVERRIDE {}
|
||||
virtual void rewindTo(BareNetworkString *buffer) OVERRIDE {}
|
||||
|
||||
}; // AIBaseController
|
||||
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
#include <irrString.h>
|
||||
using namespace irr;
|
||||
|
||||
class BareNetworkString;
|
||||
|
||||
/**
|
||||
* \defgroup controller Karts/controller
|
||||
* Contains kart controllers, which are either human players or AIs
|
||||
@@ -31,6 +33,7 @@ using namespace irr;
|
||||
#include "states_screens/state_manager.hpp"
|
||||
|
||||
class AbstractKart;
|
||||
class BareNetworString;
|
||||
class Item;
|
||||
class KartControl;
|
||||
class Material;
|
||||
@@ -74,6 +77,9 @@ public:
|
||||
* rubber-banding. */
|
||||
virtual bool isPlayerController () const = 0;
|
||||
virtual bool disableSlipstreamBonus() const = 0;
|
||||
virtual void saveState(BareNetworkString *buffer) const = 0;
|
||||
virtual void rewindTo(BareNetworkString *buffer) = 0;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
/** Sets the controller name for this controller. */
|
||||
virtual void setControllerName(const std::string &name)
|
||||
|
||||
@@ -58,6 +58,9 @@ public:
|
||||
virtual void action(PlayerAction action, int value) OVERRIDE;
|
||||
virtual void skidBonusTriggered() {};
|
||||
virtual void newLap(int lap) {};
|
||||
virtual void saveState(BareNetworkString *buffer) const {};
|
||||
virtual void rewindTo(BareNetworkString *buffer) {};
|
||||
|
||||
void addReplayTime(float time);
|
||||
// ------------------------------------------------------------------------
|
||||
bool isReplayEnd() const
|
||||
|
||||
@@ -38,7 +38,7 @@ void KartControl::rewind(BareNetworkString *buffer)
|
||||
if(buffer->getTotalSize()>1)
|
||||
{
|
||||
// Full state including accel and steering was saved
|
||||
setFromBuffer(buffer);
|
||||
rewindTo(buffer);
|
||||
}
|
||||
else // only a button event was stored
|
||||
{
|
||||
@@ -67,119 +67,54 @@ void KartControl::set(const KartControl &c)
|
||||
/** Sets the current steering value. */
|
||||
void KartControl::setSteer(float f)
|
||||
{
|
||||
float old_steer = m_steer;
|
||||
m_steer = f;
|
||||
if (RewindManager::isEnabled() && !RewindManager::get()->isRewinding() &&
|
||||
old_steer != m_steer )
|
||||
{
|
||||
// Save full status
|
||||
BareNetworkString *buffer = new BareNetworkString(getLength());
|
||||
copyToBuffer(buffer);
|
||||
RewindManager::get()->addEvent(this, buffer, true);
|
||||
}
|
||||
} // setSteer
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Sets the acceleration. */
|
||||
void KartControl::setAccel(float f)
|
||||
{
|
||||
float old_accel = m_accel;
|
||||
m_accel = f;
|
||||
if (RewindManager::isEnabled() && !RewindManager::get()->isRewinding() &&
|
||||
old_accel != m_accel )
|
||||
{
|
||||
BareNetworkString *buffer = new BareNetworkString(getLength());
|
||||
copyToBuffer(buffer);
|
||||
RewindManager::get()->addEvent(this, buffer, true);
|
||||
}
|
||||
} // setAccel
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Sets if the kart is braking. */
|
||||
void KartControl::setBrake(bool b)
|
||||
{
|
||||
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);
|
||||
buffer->addUInt8(getButtonsCompressed());
|
||||
RewindManager::get()->addEvent(this, buffer, true);
|
||||
}
|
||||
} // setBrake
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Sets if the kart activates nitro. */
|
||||
void KartControl::setNitro(bool b)
|
||||
{
|
||||
bool old_nitro = m_nitro;
|
||||
m_nitro = b;
|
||||
if (RewindManager::isEnabled() && !RewindManager::get()->isRewinding() &&
|
||||
old_nitro != m_nitro )
|
||||
{
|
||||
BareNetworkString *buffer = new BareNetworkString(1);
|
||||
buffer->addUInt8(getButtonsCompressed());
|
||||
RewindManager::get()->addEvent(this, buffer, true);
|
||||
}
|
||||
} // setNitro
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Sets the skid control for this kart. */
|
||||
void KartControl::setSkidControl(SkidControl sc)
|
||||
{
|
||||
SkidControl old_skid = m_skid;
|
||||
m_skid = sc;
|
||||
if (RewindManager::isEnabled() && !RewindManager::get()->isRewinding() &&
|
||||
old_skid != m_skid )
|
||||
{
|
||||
BareNetworkString *buffer = new BareNetworkString(1);
|
||||
buffer->addUInt8(getButtonsCompressed());
|
||||
RewindManager::get()->addEvent(this, buffer, true);
|
||||
}
|
||||
} // seSkidControl
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Returns if this kart wants to get rescued. */
|
||||
void KartControl::setRescue(bool b)
|
||||
{
|
||||
bool old_rescue = m_rescue;
|
||||
m_rescue = b;
|
||||
if (RewindManager::isEnabled() && !RewindManager::get()->isRewinding() &&
|
||||
old_rescue != m_rescue)
|
||||
{
|
||||
BareNetworkString *buffer = new BareNetworkString(1);
|
||||
buffer->addUInt8(getButtonsCompressed());
|
||||
RewindManager::get()->addEvent(this, buffer, true);
|
||||
}
|
||||
} // setRescue
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Sets if the kart wants to fire. */
|
||||
void KartControl::setFire(bool b)
|
||||
{
|
||||
bool old_fire = m_fire;
|
||||
m_fire = b;
|
||||
if (RewindManager::isEnabled() && !RewindManager::get()->isRewinding() &&
|
||||
old_fire != m_fire )
|
||||
{
|
||||
BareNetworkString *buffer = new BareNetworkString(1);
|
||||
buffer->addUInt8(getButtonsCompressed());
|
||||
RewindManager::get()->addEvent(this, buffer, true);
|
||||
}
|
||||
} // setFire
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Sets if the kart wants to look (and therefore also fires) backwards. */
|
||||
void KartControl::setLookBack(bool b)
|
||||
{
|
||||
bool old_look = m_look_back;
|
||||
m_look_back = b;
|
||||
if (RewindManager::isEnabled() && !RewindManager::get()->isRewinding() &&
|
||||
old_look != m_look_back)
|
||||
{
|
||||
BareNetworkString *buffer = new BareNetworkString(1);
|
||||
buffer->addUInt8(getButtonsCompressed());
|
||||
RewindManager::get()->addEvent(this, buffer, true);
|
||||
}
|
||||
} // setLookBack
|
||||
|
||||
@@ -101,7 +101,7 @@ public:
|
||||
static int getLength() { return 9; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Copies the important data from this objects into a memory buffer. */
|
||||
void copyToBuffer(BareNetworkString *buffer) const
|
||||
void saveState(BareNetworkString *buffer) const
|
||||
{
|
||||
buffer->add(m_steer);
|
||||
buffer->add(m_accel);
|
||||
@@ -110,7 +110,7 @@ public:
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** Restores this object from a previously saved memory buffer. */
|
||||
void setFromBuffer(BareNetworkString *buffer)
|
||||
void rewindTo(BareNetworkString *buffer)
|
||||
{
|
||||
m_steer = buffer->getFloat();
|
||||
m_accel = buffer->getFloat();
|
||||
|
||||
@@ -142,16 +142,17 @@ void LocalPlayerController::resetInputState()
|
||||
*/
|
||||
void LocalPlayerController::action(PlayerAction action, int value)
|
||||
{
|
||||
PlayerController::action(action, value);
|
||||
|
||||
// If this is a client, send the action to networking layer
|
||||
if (World::getWorld()->isNetworkWorld() &&
|
||||
NetworkConfig::get()->isClient() &&
|
||||
!RewindManager::get()->isRewinding() )
|
||||
{
|
||||
GameProtocol::getInstance()->controllerAction(m_kart->getWorldKartId(),
|
||||
action, value);
|
||||
action, value,
|
||||
m_steer_val_l,
|
||||
m_steer_val_r);
|
||||
}
|
||||
PlayerController::action(action, value);
|
||||
} // action
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
@@ -93,6 +93,9 @@ void PlayerController::resetInputState()
|
||||
*/
|
||||
void PlayerController::action(PlayerAction action, int value)
|
||||
{
|
||||
Log::info("action", "t %f action %d value %d val_l %d val_r %d val %d",
|
||||
World::getWorld()->getTime(), action, value,
|
||||
m_steer_val_l, m_steer_val_r, m_steer_val);
|
||||
switch (action)
|
||||
{
|
||||
case PA_STEER_LEFT:
|
||||
@@ -188,6 +191,15 @@ void PlayerController::action(PlayerAction action, int value)
|
||||
|
||||
} // action
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void PlayerController::actionFromNetwork(PlayerAction p_action, int value,
|
||||
int value_l, int value_r)
|
||||
{
|
||||
m_steer_val_l = value_l;
|
||||
m_steer_val_r = value_r;
|
||||
action(p_action, value);
|
||||
} // actionFromNetwork
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Handles steering for a player kart.
|
||||
*/
|
||||
@@ -203,6 +215,8 @@ void PlayerController::steer(float dt, int steer_val)
|
||||
steer = 0;
|
||||
}
|
||||
|
||||
Log::info("steer", "t %f dt %f steer_val %d steer %f",
|
||||
World::getWorld()->getTime(), dt, steer_val, steer);
|
||||
// Amount the steering is changed for digital devices.
|
||||
// If the steering is 'back to straight', a different steering
|
||||
// change speed is used.
|
||||
@@ -316,3 +330,18 @@ void PlayerController::handleZipper(bool play_sound)
|
||||
{
|
||||
m_kart->showZipperFire();
|
||||
} // handleZipper
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void PlayerController::saveState(BareNetworkString *buffer) const
|
||||
{
|
||||
buffer->addUInt32(m_steer_val).addUInt32(m_steer_val_l)
|
||||
.addUInt32(m_steer_val_r);
|
||||
} // copyToBuffer
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void PlayerController::rewindTo(BareNetworkString *buffer)
|
||||
{
|
||||
m_steer_val = buffer->getUInt32();
|
||||
m_steer_val_l = buffer->getUInt32();
|
||||
m_steer_val_r = buffer->getUInt32();
|
||||
} // rewindTo
|
||||
@@ -45,10 +45,14 @@ public:
|
||||
virtual ~PlayerController ();
|
||||
virtual void update (float) OVERRIDE;
|
||||
virtual void action (PlayerAction action, int value) OVERRIDE;
|
||||
virtual void actionFromNetwork(PlayerAction action, int value,
|
||||
int value_l, int value_r);
|
||||
virtual void skidBonusTriggered() OVERRIDE;
|
||||
virtual void reset () OVERRIDE;
|
||||
virtual void handleZipper(bool play_sound) OVERRIDE;
|
||||
virtual void resetInputState();
|
||||
virtual void saveState(BareNetworkString *buffer) const OVERRIDE;
|
||||
virtual void rewindTo(BareNetworkString *buffer) OVERRIDE;
|
||||
// ------------------------------------------------------------------------
|
||||
virtual void collectedItem(const Item &item, int add_info=-1,
|
||||
float previous_energy=0 ) OVERRIDE
|
||||
|
||||
@@ -1225,7 +1225,7 @@ void Kart::update(float dt)
|
||||
// is used furthermore for engine power, camera distance etc
|
||||
updateSpeed();
|
||||
|
||||
if(!history->replayHistory() && !RewindManager::get()->isRewinding())
|
||||
if(!history->replayHistory())
|
||||
m_controller->update(dt);
|
||||
|
||||
#undef DEBUG_CAMERA_SHAKE
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "items/attachment.hpp"
|
||||
#include "items/powerup.hpp"
|
||||
#include "karts/abstract_kart.hpp"
|
||||
#include "karts/controller/controller.hpp"
|
||||
#include "karts/max_speed.hpp"
|
||||
#include "karts/skidding.hpp"
|
||||
#include "modes/world.hpp"
|
||||
@@ -78,7 +79,8 @@ BareNetworkString* KartRewinder::saveState() const
|
||||
|
||||
// 2) Steering and other player controls
|
||||
// -------------------------------------
|
||||
getControls().copyToBuffer(buffer);
|
||||
getControls().saveState(buffer);
|
||||
getController()->saveState(buffer);
|
||||
|
||||
// 3) Attachment
|
||||
// -------------
|
||||
@@ -124,7 +126,8 @@ void KartRewinder::rewindToState(BareNetworkString *buffer)
|
||||
|
||||
// 2) Steering and other controls
|
||||
// ------------------------------
|
||||
getControls().setFromBuffer(buffer);
|
||||
getControls().rewindTo(buffer);
|
||||
getController()->rewindTo(buffer);
|
||||
|
||||
// 3) Attachment
|
||||
// -------------
|
||||
|
||||
@@ -65,7 +65,8 @@ void GameProtocol::update(float dt)
|
||||
{
|
||||
m_data_to_send->addFloat(a.m_time);
|
||||
m_data_to_send->addUInt8(a.m_kart_id);
|
||||
m_data_to_send->addUInt8((uint8_t)(a.m_action)).addUInt32(a.m_value);
|
||||
m_data_to_send->addUInt8((uint8_t)(a.m_action)).addUInt32(a.m_value)
|
||||
.addUInt32(a.m_value_l).addUInt32(a.m_value_r);
|
||||
} // for a in m_all_actions
|
||||
|
||||
// FIXME: for now send reliable
|
||||
@@ -102,7 +103,7 @@ bool GameProtocol::notifyEventAsynchronous(Event* event)
|
||||
* \param value New value for the given action.
|
||||
*/
|
||||
void GameProtocol::controllerAction(int kart_id, PlayerAction action,
|
||||
int value)
|
||||
int value, int val_l, int val_r)
|
||||
{
|
||||
// Store the action in the list of actions that will be sent to the
|
||||
// server next.
|
||||
@@ -111,6 +112,8 @@ void GameProtocol::controllerAction(int kart_id, PlayerAction action,
|
||||
a.m_kart_id = kart_id;
|
||||
a.m_action = action;
|
||||
a.m_value = value;
|
||||
a.m_value_l = val_l;
|
||||
a.m_value_r = val_r;
|
||||
a.m_time = World::getWorld()->getTime();
|
||||
|
||||
m_all_actions.push_back(a);
|
||||
@@ -118,7 +121,8 @@ void GameProtocol::controllerAction(int kart_id, PlayerAction action,
|
||||
// Store the event in the rewind manager, which is responsible
|
||||
// for freeing the allocated memory
|
||||
BareNetworkString *s = new BareNetworkString(4);
|
||||
s->addUInt8(kart_id).addUInt8(action).addUInt16(uint16_t(value));
|
||||
s->addUInt8(kart_id).addUInt8(action).addUInt32(value)
|
||||
.addUInt32(val_l).addUInt32(val_r);
|
||||
RewindManager::get()->addEvent(this, s, /*confirmed*/true,
|
||||
World::getWorld()->getTime() );
|
||||
|
||||
@@ -143,11 +147,14 @@ void GameProtocol::handleControllerAction(Event *event)
|
||||
assert(kart_id < World::getWorld()->getNumKarts());
|
||||
|
||||
PlayerAction action = (PlayerAction)(data.getUInt8());
|
||||
int value = data.getUInt32();
|
||||
Log::info("GameProtocol", "Action at %f: %d %d %d",
|
||||
time, kart_id, action, value);
|
||||
int value = data.getUInt32();
|
||||
int value_l = data.getUInt32();
|
||||
int value_r = data.getUInt32();
|
||||
Log::info("GameProtocol", "Action at %f: %d %d %d %d %d",
|
||||
time, kart_id, action, value, value_l, value_r);
|
||||
BareNetworkString *s = new BareNetworkString(3);
|
||||
s->addUInt8(kart_id).addUInt8(action).addUInt16(value);
|
||||
s->addUInt8(kart_id).addUInt8(action).addUInt32(value)
|
||||
.addUInt32(value_l).addUInt32(value_r);
|
||||
RewindManager::get()->addNetworkEvent(this, s, time);
|
||||
}
|
||||
|
||||
@@ -241,7 +248,12 @@ void GameProtocol::rewind(BareNetworkString *buffer)
|
||||
{
|
||||
int kart_id = buffer->getUInt8();
|
||||
PlayerAction action = PlayerAction(buffer->getUInt8());
|
||||
int value = buffer->getUInt16();
|
||||
int value = buffer->getUInt32();
|
||||
int value_l = buffer->getUInt32();
|
||||
int value_r = buffer->getUInt32();
|
||||
Controller *c = World::getWorld()->getKart(kart_id)->getController();
|
||||
c->action(action, value);
|
||||
PlayerController *pc = dynamic_cast<PlayerController*>(c);
|
||||
assert(pc);
|
||||
if(pc)
|
||||
pc->actionFromNetwork(action, value, value_l, value_r);
|
||||
} // rewind
|
||||
|
||||
@@ -52,6 +52,8 @@ private:
|
||||
int m_kart_id;
|
||||
PlayerAction m_action;
|
||||
int m_value;
|
||||
int m_value_l;
|
||||
int m_value_r;
|
||||
}; // struct Action
|
||||
|
||||
// List of all kart actions to send to the server
|
||||
@@ -67,7 +69,7 @@ public:
|
||||
virtual void update(float dt) OVERRIDE;
|
||||
|
||||
void controllerAction(int kart_id, PlayerAction action,
|
||||
int value);
|
||||
int value, int val_l, int val_r);
|
||||
void startNewState();
|
||||
void addState(BareNetworkString *buffer);
|
||||
void sendState();
|
||||
|
||||
@@ -494,19 +494,21 @@ void RewindManager::rewindTo(float rewind_time)
|
||||
{
|
||||
state->rewind();
|
||||
index++;
|
||||
//rindex--;
|
||||
if(index==m_rewind_info.end()) break;
|
||||
state = dynamic_cast<RewindInfoState*>(*index);
|
||||
}
|
||||
|
||||
// Now go forward through the list of rewind infos:
|
||||
// ------------------------------------------------
|
||||
while( world->getTime() < current_time )
|
||||
// Need to exit loop if in-game menu is open, since world clock
|
||||
// will not be increased while the game is paused
|
||||
while( world->getTime() < current_time &&
|
||||
World::getWorld()->getPhase()!=WorldStatus::IN_GAME_MENU_PHASE)
|
||||
{
|
||||
// Now handle all states and events at the current time before
|
||||
// updating the world:
|
||||
while(index !=m_rewind_info.end() &&
|
||||
(*index)->getTime()<=world->getTime()+0.001f)
|
||||
(*index)->getTime()<=world->getTime())
|
||||
{
|
||||
if((*index)->isState())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user