Removed KartUpdate protocol (which breakes online play).
This commit is contained in:
parent
4d065f67e6
commit
04d1d4817a
@ -1,5 +1,5 @@
|
|||||||
# Modify this file to change the last-modified date when you add/remove a file.
|
# Modify this file to change the last-modified date when you add/remove a file.
|
||||||
# This will then trigger a new cmake run automatically.
|
# This will then trigger a new cmake run automatically.
|
||||||
file(GLOB_RECURSE STK_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.hpp")
|
file(GLOB_RECURSE STK_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.hpp")
|
||||||
file(GLOB_RECURSE STK_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.cpp")
|
file(GLOB_RECURSE STK_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.cpp")
|
||||||
file(GLOB_RECURSE STK_SHADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "data/shaders/*")
|
file(GLOB_RECURSE STK_SHADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "data/shaders/*")
|
||||||
|
@ -1,147 +0,0 @@
|
|||||||
#include "network/protocols/kart_update_protocol.hpp"
|
|
||||||
|
|
||||||
#include "karts/abstract_kart.hpp"
|
|
||||||
#include "karts/controller/controller.hpp"
|
|
||||||
#include "modes/world.hpp"
|
|
||||||
#include "network/event.hpp"
|
|
||||||
#include "network/network_config.hpp"
|
|
||||||
#include "network/protocol_manager.hpp"
|
|
||||||
#include "utils/time.hpp"
|
|
||||||
|
|
||||||
KartUpdateProtocol::KartUpdateProtocol() : Protocol(PROTOCOL_KART_UPDATE)
|
|
||||||
{
|
|
||||||
} // KartUpdateProtocol
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
KartUpdateProtocol::~KartUpdateProtocol()
|
|
||||||
{
|
|
||||||
} // ~KartUpdateProtocol
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
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
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
/** Store the update events in the queue. Since the events are handled in the
|
|
||||||
* synchronous notify function, there is no lock necessary to
|
|
||||||
*/
|
|
||||||
bool KartUpdateProtocol::notifyEvent(Event* event)
|
|
||||||
{
|
|
||||||
// It might be possible that we still receive messages after
|
|
||||||
// the game was exited, so make sure we still have a world.
|
|
||||||
if (event->getType() != EVENT_TYPE_MESSAGE || !World::getWorld())
|
|
||||||
return true;
|
|
||||||
NetworkString &ns = event->data();
|
|
||||||
if (ns.size() < 33)
|
|
||||||
{
|
|
||||||
Log::info("KartUpdateProtocol", "Message too short.");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
float time = ns.getFloat();
|
|
||||||
while(ns.size() >= 29)
|
|
||||||
{
|
|
||||||
uint8_t kart_id = ns.getUInt8();
|
|
||||||
Vec3 xyz = ns.getVec3();
|
|
||||||
btQuaternion quat = ns.getQuat();
|
|
||||||
m_next_positions [kart_id] = xyz;
|
|
||||||
m_next_quaternions[kart_id] = quat;
|
|
||||||
} // while ns.size()>29
|
|
||||||
|
|
||||||
// Set the flag that a new update was received
|
|
||||||
m_was_updated = true;
|
|
||||||
return true;
|
|
||||||
} // notifyEvent
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
/** Sends regular update events from the server to all clients and from the
|
|
||||||
* clients to the server (FIXME - is that actually necessary??)
|
|
||||||
* Then it applies all update events that have been received in notifyEvent.
|
|
||||||
* This two-part implementation means that if the server should send two
|
|
||||||
* or more updates before this client handles them, only the last one will
|
|
||||||
* actually be handled (i.e. outdated kart position updates are discarded).
|
|
||||||
*/
|
|
||||||
void KartUpdateProtocol::update(float dt)
|
|
||||||
{
|
|
||||||
if (!World::getWorld())
|
|
||||||
return;
|
|
||||||
|
|
||||||
double current_time = StkTime::getRealTime();
|
|
||||||
if (current_time > m_previous_time + 0.1) // 10 updates per second
|
|
||||||
{
|
|
||||||
m_previous_time = current_time;
|
|
||||||
if (NetworkConfig::get()->isServer())
|
|
||||||
{
|
|
||||||
World *world = World::getWorld();
|
|
||||||
NetworkString *ns = getNetworkString(4+world->getNumKarts()*29);
|
|
||||||
ns->setSynchronous(true);
|
|
||||||
ns->addFloat( world->getTime() );
|
|
||||||
for (unsigned int i = 0; i < world->getNumKarts(); i++)
|
|
||||||
{
|
|
||||||
AbstractKart* kart = world->getKart(i);
|
|
||||||
Vec3 xyz = kart->getXYZ();
|
|
||||||
ns->addUInt8( kart->getWorldKartId());
|
|
||||||
ns->add(xyz).add(kart->getRotation());
|
|
||||||
Log::verbose("KartUpdateProtocol",
|
|
||||||
"Sending %d's positions %f %f %f",
|
|
||||||
kart->getWorldKartId(), xyz[0], xyz[1], xyz[2]);
|
|
||||||
}
|
|
||||||
sendMessageToPeersChangingToken(ns, /*reliable*/false);
|
|
||||||
delete ns;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
NetworkString *ns =
|
|
||||||
getNetworkString(4+29*race_manager->getNumLocalPlayers());
|
|
||||||
ns->setSynchronous(true);
|
|
||||||
ns->addFloat(World::getWorld()->getTime());
|
|
||||||
for(unsigned int i=0; i<race_manager->getNumLocalPlayers(); i++)
|
|
||||||
{
|
|
||||||
AbstractKart *kart = World::getWorld()->getLocalPlayerKart(i);
|
|
||||||
const Vec3 &xyz = kart->getXYZ();
|
|
||||||
ns->addUInt8(kart->getWorldKartId());
|
|
||||||
ns->add(xyz).add(kart->getRotation());
|
|
||||||
Log::verbose("KartUpdateProtocol",
|
|
||||||
"Sending %d's positions %f %f %f",
|
|
||||||
kart->getWorldKartId(), xyz[0], xyz[1], xyz[2]);
|
|
||||||
}
|
|
||||||
sendToServer(ns, /*reliable*/false);
|
|
||||||
delete ns;
|
|
||||||
} // if server
|
|
||||||
} // if (current_time > time + 0.1)
|
|
||||||
|
|
||||||
|
|
||||||
// Now handle all update events that have been received.
|
|
||||||
// There is no lock necessary, since receiving new positions is done in
|
|
||||||
// notifyEvent, which is called from the same thread that calls this
|
|
||||||
// function.
|
|
||||||
if(m_was_updated)
|
|
||||||
{
|
|
||||||
for (unsigned id = 0; id < m_next_positions.size(); id++)
|
|
||||||
{
|
|
||||||
AbstractKart *kart = World::getWorld()->getKart(id);
|
|
||||||
if (!kart->getController()->isLocalPlayerController())
|
|
||||||
{
|
|
||||||
btTransform transform = kart->getBody()
|
|
||||||
->getInterpolationWorldTransform();
|
|
||||||
transform.setOrigin(m_next_positions[id]);
|
|
||||||
transform.setRotation(m_next_quaternions[id]);
|
|
||||||
kart->getBody()->setCenterOfMassTransform(transform);
|
|
||||||
Log::verbose("KartUpdateProtocol", "Update kart %i pos",
|
|
||||||
id);
|
|
||||||
} // if not local player
|
|
||||||
} // for id < num_karts
|
|
||||||
m_was_updated = false; // mark that all updates were applied
|
|
||||||
} // if m_was_updated
|
|
||||||
} // update
|
|
||||||
|
|
@ -1,43 +0,0 @@
|
|||||||
#ifndef KART_UPDATE_PROTOCOL_HPP
|
|
||||||
#define KART_UPDATE_PROTOCOL_HPP
|
|
||||||
|
|
||||||
#include "network/protocol.hpp"
|
|
||||||
#include "utils/cpp2011.hpp"
|
|
||||||
#include "utils/vec3.hpp"
|
|
||||||
|
|
||||||
#include "LinearMath/btQuaternion.h"
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include "pthread.h"
|
|
||||||
|
|
||||||
class AbstractKart;
|
|
||||||
|
|
||||||
class KartUpdateProtocol : public Protocol
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
|
|
||||||
/** Stores the last updated position for a kart. */
|
|
||||||
std::vector<Vec3> m_next_positions;
|
|
||||||
|
|
||||||
/** Stores the last updated rotation for a kart. */
|
|
||||||
std::vector<btQuaternion> m_next_quaternions;
|
|
||||||
|
|
||||||
/** True if a new update for the kart positions was received. */
|
|
||||||
bool m_was_updated;
|
|
||||||
|
|
||||||
/** Time the last kart update was sent. Used to send updates with
|
|
||||||
* a fixed frequency. */
|
|
||||||
double m_previous_time;
|
|
||||||
|
|
||||||
public:
|
|
||||||
KartUpdateProtocol();
|
|
||||||
virtual ~KartUpdateProtocol();
|
|
||||||
|
|
||||||
virtual bool notifyEvent(Event* event) OVERRIDE;
|
|
||||||
virtual void setup() OVERRIDE;
|
|
||||||
virtual void update(float dt) OVERRIDE;
|
|
||||||
virtual void asynchronousUpdate() OVERRIDE {};
|
|
||||||
|
|
||||||
}; // KartUpdateProtocol
|
|
||||||
|
|
||||||
#endif // KART_UPDATE_PROTOCOL_HPP
|
|
@ -26,7 +26,6 @@
|
|||||||
#include "network/protocol_manager.hpp"
|
#include "network/protocol_manager.hpp"
|
||||||
#include "network/protocols/game_protocol.hpp"
|
#include "network/protocols/game_protocol.hpp"
|
||||||
#include "network/protocols/game_events_protocol.hpp"
|
#include "network/protocols/game_events_protocol.hpp"
|
||||||
#include "network/protocols/kart_update_protocol.hpp"
|
|
||||||
#include "network/protocols/latency_protocol.hpp"
|
#include "network/protocols/latency_protocol.hpp"
|
||||||
#include "network/race_event_manager.hpp"
|
#include "network/race_event_manager.hpp"
|
||||||
#include "network/stk_host.hpp"
|
#include "network/stk_host.hpp"
|
||||||
@ -124,7 +123,6 @@ void LobbyProtocol::loadWorld()
|
|||||||
// Load the actual world.
|
// Load the actual world.
|
||||||
m_game_setup->getRaceConfig()->loadWorld();
|
m_game_setup->getRaceConfig()->loadWorld();
|
||||||
World::getWorld()->setNetworkWorld(true);
|
World::getWorld()->setNetworkWorld(true);
|
||||||
(new KartUpdateProtocol())->requestStart();
|
|
||||||
GameProtocol::getInstance()->requestStart();
|
GameProtocol::getInstance()->requestStart();
|
||||||
(new GameEventsProtocol())->requestStart();
|
(new GameEventsProtocol())->requestStart();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user