Removed static variables and properly initialised in setup, which
should allow this protocol to work for more than one race. Back-ported to master.
This commit is contained in:
parent
7b3fc04d26
commit
68f5259f4d
@ -10,14 +10,6 @@
|
|||||||
|
|
||||||
KartUpdateProtocol::KartUpdateProtocol() : Protocol(PROTOCOL_KART_UPDATE)
|
KartUpdateProtocol::KartUpdateProtocol() : Protocol(PROTOCOL_KART_UPDATE)
|
||||||
{
|
{
|
||||||
// Allocate arrays to store one position and rotation for each kart
|
|
||||||
// (which is the update information from the server to the client).
|
|
||||||
m_next_positions.resize(World::getWorld()->getNumKarts());
|
|
||||||
m_next_quaternions.resize(World::getWorld()->getNumKarts());
|
|
||||||
|
|
||||||
// This flag keeps track if valid data for an update is in
|
|
||||||
// the arrays
|
|
||||||
m_was_updated = false;
|
|
||||||
} // KartUpdateProtocol
|
} // KartUpdateProtocol
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@ -28,6 +20,16 @@ KartUpdateProtocol::~KartUpdateProtocol()
|
|||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
void KartUpdateProtocol::setup()
|
void KartUpdateProtocol::setup()
|
||||||
{
|
{
|
||||||
|
// Allocate arrays to store one position and rotation for each kart
|
||||||
|
// (which is the update information from the server to the client).
|
||||||
|
m_next_positions.resize(World::getWorld()->getNumKarts());
|
||||||
|
m_next_quaternions.resize(World::getWorld()->getNumKarts());
|
||||||
|
|
||||||
|
// This flag keeps track if valid data for an update is in
|
||||||
|
// the arrays
|
||||||
|
m_was_updated = false;
|
||||||
|
|
||||||
|
m_previous_time = 0;
|
||||||
} // setup
|
} // setup
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@ -73,11 +75,11 @@ void KartUpdateProtocol::update(float dt)
|
|||||||
{
|
{
|
||||||
if (!World::getWorld())
|
if (!World::getWorld())
|
||||||
return;
|
return;
|
||||||
static double time = 0;
|
|
||||||
double current_time = StkTime::getRealTime();
|
double current_time = StkTime::getRealTime();
|
||||||
if (current_time > time + 0.1) // 10 updates per second
|
if (current_time > m_previous_time + 0.1) // 10 updates per second
|
||||||
{
|
{
|
||||||
time = current_time;
|
m_previous_time = current_time;
|
||||||
if (NetworkConfig::get()->isServer())
|
if (NetworkConfig::get()->isServer())
|
||||||
{
|
{
|
||||||
World *world = World::getWorld();
|
World *world = World::getWorld();
|
||||||
|
@ -25,6 +25,10 @@ private:
|
|||||||
/** True if a new update for the kart positions was received. */
|
/** True if a new update for the kart positions was received. */
|
||||||
bool m_was_updated;
|
bool m_was_updated;
|
||||||
|
|
||||||
|
/** Time the last kart update was sent. Used to send updates with
|
||||||
|
* a fixed frequency. */
|
||||||
|
double m_previous_time;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
KartUpdateProtocol();
|
KartUpdateProtocol();
|
||||||
virtual ~KartUpdateProtocol();
|
virtual ~KartUpdateProtocol();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user