adding a protocol to update positions over network during a race

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/hilnius@13259 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hilnius 2013-07-16 14:45:48 +00:00
parent 9e712c87b7
commit 3be0d70ce0
8 changed files with 32 additions and 4 deletions

View File

@ -152,6 +152,7 @@ src/network/protocols/connect_to_server.cpp
src/network/protocols/get_peer_address.cpp
src/network/protocols/get_public_address.cpp
src/network/protocols/hide_public_address.cpp
src/network/protocols/kart_update_protocol.cpp
src/network/protocols/lobby_room_protocol.cpp
src/network/protocols/ping_protocol.cpp
src/network/protocols/quick_join_protocol.cpp
@ -429,6 +430,7 @@ src/network/protocols/connect_to_server.hpp
src/network/protocols/get_peer_address.hpp
src/network/protocols/get_public_address.hpp
src/network/protocols/hide_public_address.hpp
src/network/protocols/kart_update_protocol.hpp
src/network/protocols/lobby_room_protocol.hpp
src/network/protocols/ping_protocol.hpp
src/network/protocols/quick_join_protocol.hpp

View File

@ -35,6 +35,7 @@
#include "karts/skidding.hpp"
#include "karts/rescue_animation.hpp"
#include "modes/world.hpp"
#include "network/network_world.hpp"
#include "race/history.hpp"
#include "states_screens/race_gui_base.hpp"
#include "utils/constants.hpp"
@ -218,6 +219,10 @@ void PlayerController::action(PlayerAction action, int value)
default:
break;
}
if (NetworkWorld::getInstance()->isRunning())
{
NetworkWorld::getInstance()->controllerAction(this, action, value);
}
} // action

View File

@ -31,13 +31,14 @@ using namespace irr;
#include "physics/user_pointer.hpp"
#include "utils/no_copy.hpp"
#include "utils/vec3.hpp"
#include "network/types.hpp"
class Material;
/**
* \ingroup karts
*/
class Moveable: public NoCopy
class Moveable: public NoCopy, public CallbackObject
{
private:
btVector3 m_velocityLC; /**<Velocity in kart coordinates. */

View File

@ -273,6 +273,9 @@ public:
assert(kartId >= 0 && kartId < int(m_karts.size()));
return m_karts[kartId]; }
// ------------------------------------------------------------------------
/** Returns all karts. */
KartList getKarts() const { return m_karts; }
// ------------------------------------------------------------------------
/** Returns the number of currently active (i.e.non-elikminated) karts. */
unsigned int getCurrentNumKarts() const { return (int)m_karts.size() -
m_eliminated_karts; }

View File

@ -4,6 +4,8 @@
#include "network/protocols/synchronization_protocol.hpp"
#include "modes/world.hpp"
#include "karts/controller/controller.hpp"
NetworkWorld::NetworkWorld()
{
m_running = false;
@ -24,9 +26,11 @@ void NetworkWorld::update(float dt)
{
return;
}
else
{
}
}
World::getWorld()->updateWorld(dt);
}
void NetworkWorld::controllerAction(Controller* controller, PlayerAction action, int value)
{
}

View File

@ -2,6 +2,13 @@
#define NETWORK_WORLD_HPP
#include "network/singleton.hpp"
#include "input/input.hpp"
#include <map>
class Controller;
//class InputEventProtocol;
class KartUpdateProtocol;
class AbstractKart;
/*! \brief Manages the world updates during an online game
* This function's update is to be called instead of the normal World update
@ -16,9 +23,12 @@ class NetworkWorld : public Singleton<NetworkWorld>
void stop() { m_running = false; }
bool isRunning() { return m_running; }
void controllerAction(Controller* controller, PlayerAction action, int value);
protected:
bool m_running;
float m_race_time;
//std::map<Controller*, InputEventProtocol*> m_events_map;
private:
NetworkWorld();

View File

@ -36,6 +36,7 @@ enum PROTOCOL_TYPE
PROTOCOL_LOBBY_ROOM = 2, //!< Protocol that is used during the lobby room phase.
PROTOCOL_START_GAME = 3, //!< Protocol used when starting the game.
PROTOCOL_SYNCHRONIZATION = 4,//!<Protocol used to synchronize clocks.
PROTOCOL_KART_UPDATE = 5, //!< Protocol to update karts position, rotation etc...
PROTOCOL_SILENT = 0xffff //!< Used for protocols that do not subscribe to any network event.
};

View File

@ -1,6 +1,7 @@
#include "network/protocols/synchronization_protocol.hpp"
#include "network/network_manager.hpp"
#include "network/protocols/kart_update_protocol.hpp"
#include "utils/time.hpp"
//-----------------------------------------------------------------------------
@ -125,6 +126,7 @@ void SynchronizationProtocol::asynchronousUpdate()
if (m_countdown < 0.0)
{
Log::info("SynchronizationProtocol", "Countdown finished. Starting now.");
m_listener->requestStart(new KartUpdateProtocol());
m_listener->requestTerminate(this);
return;
}