Added time step size as parameter to each protocol's synchromous update

function (which is needed for interpolation later).
This commit is contained in:
hiker 2016-03-19 10:24:44 +11:00
parent 10bb5caae3
commit d25f3cee25
27 changed files with 152 additions and 137 deletions

View File

@ -184,7 +184,7 @@ void MainLoop::run()
if (STKHost::get()->requestedShutdown())
STKHost::get()->shutdown();
else
ProtocolManager::getInstance()->update();
ProtocolManager::getInstance()->update(dt);
}
PROFILER_POP_CPU_MARKER();
@ -196,7 +196,7 @@ void MainLoop::run()
{
PROFILER_PUSH_CPU_MARKER("Protocol manager update", 0x7F, 0x00, 0x7F);
if(NetworkConfig::get()->isNetworking())
ProtocolManager::getInstance()->update();
ProtocolManager::getInstance()->update(dt);
PROFILER_POP_CPU_MARKER();
PROFILER_PUSH_CPU_MARKER("Database polling update", 0x00, 0x7F, 0x7F);

View File

@ -121,7 +121,7 @@ public:
/** \brief Called by the protocol listener, synchronously with the main
* loop. Must be re-defined.*/
virtual void update() = 0;
virtual void update(float dt) = 0;
/** \brief Called by the protocol listener as often as possible.
* Must be re-defined. */

View File

@ -321,7 +321,7 @@ bool ProtocolManager::sendEvent(Event* event)
* This function is called by the main thread (i.e. from main_loop).
* This function IS FPS-dependant.
*/
void ProtocolManager::update()
void ProtocolManager::update(float dt)
{
// before updating, notify protocols that they have received events
m_events_to_process.lock();
@ -346,7 +346,7 @@ void ProtocolManager::update()
for (unsigned int i = 0; i < m_protocols.getData().size(); i++)
{
if (m_protocols.getData()[i]->getState() == PROTOCOL_STATE_RUNNING)
m_protocols.getData()[i]->update();
m_protocols.getData()[i]->update(dt);
}
m_protocols.unlock();
} // update

View File

@ -144,7 +144,7 @@ public:
virtual void requestPause(Protocol* protocol);
virtual void requestUnpause(Protocol* protocol);
virtual void requestTerminate(Protocol* protocol);
virtual void update();
virtual void update(float dt);
virtual Protocol* getProtocol(uint32_t id);
virtual Protocol* getProtocol(ProtocolType type);
}; // class ProtocolManager

View File

@ -269,7 +269,7 @@ bool ClientLobbyRoomProtocol::notifyEventAsynchronous(Event* event)
//-----------------------------------------------------------------------------
void ClientLobbyRoomProtocol::update()
void ClientLobbyRoomProtocol::update(float dt)
{
switch (m_state)
{

View File

@ -3,6 +3,7 @@
#include "network/protocols/lobby_room_protocol.hpp"
#include "network/transport_address.hpp"
#include "utils/cpp2011.hpp"
class STKPeer;
@ -64,11 +65,11 @@ public:
void doneWithResults();
void leave();
virtual bool notifyEvent(Event* event);
virtual bool notifyEventAsynchronous(Event* event);
virtual void setup();
virtual void update();
virtual void asynchronousUpdate() {}
virtual bool notifyEvent(Event* event) OVERRIDE;
virtual bool notifyEventAsynchronous(Event* event) OVERRIDE;
virtual void setup() OVERRIDE;
virtual void update(float dt) OVERRIDE;
virtual void asynchronousUpdate() OVERRIDE {}
};

View File

@ -56,7 +56,7 @@ public:
virtual bool notifyEventAsynchronous(Event* event) OVERRIDE;
virtual void setup() OVERRIDE;
virtual void update() OVERRIDE {}
virtual void update(float dt) OVERRIDE {}
virtual void asynchronousUpdate() OVERRIDE;
virtual void callback(Protocol *protocol) OVERRIDE;
}; // class ConnectToPeer

View File

@ -63,7 +63,7 @@ public:
virtual void setup() OVERRIDE;
virtual void asynchronousUpdate() OVERRIDE;
virtual void callback(Protocol *protocol) OVERRIDE;
virtual void update() OVERRIDE {}
virtual void update(float dt) OVERRIDE {}
void setServerAddress(const TransportAddress &address);
}; // class ConnectToServer

View File

@ -95,12 +95,6 @@ bool ControllerEventsProtocol::notifyEventAsynchronous(Event* event)
return true;
} // notifyEventAsynchronous
//-----------------------------------------------------------------------------
void ControllerEventsProtocol::update()
{
} // update
//-----------------------------------------------------------------------------
/** Called from the local kart controller when an action (like steering,
* acceleration, ...) was triggered. It compresses the current kart control

View File

@ -22,6 +22,7 @@
#include "network/protocol.hpp"
#include "input/input.hpp"
#include "utils/cpp2011.hpp"
class Controller;
class STKPeer;
@ -33,10 +34,10 @@ public:
ControllerEventsProtocol();
virtual ~ControllerEventsProtocol();
virtual bool notifyEventAsynchronous(Event* event);
virtual void update();
virtual void setup() {};
virtual void asynchronousUpdate() {}
virtual bool notifyEventAsynchronous(Event* event) OVERRIDE;
virtual void update(float dt) OVERRIDE {};
virtual void setup() OVERRIDE {};
virtual void asynchronousUpdate() OVERRIDE {}
void controllerAction(Controller* controller, PlayerAction action,
int value);

View File

@ -63,16 +63,6 @@ bool GameEventsProtocol::notifyEvent(Event* event)
return true;
} // notifyEvent
// ----------------------------------------------------------------------------
void GameEventsProtocol::setup()
{
} // setup
// ----------------------------------------------------------------------------
void GameEventsProtocol::update()
{
} // update
// ----------------------------------------------------------------------------
/** Called on the server when an item is collected.
*/

View File

@ -2,6 +2,7 @@
#define GAME_EVENTS_PROTOCOL_HPP
#include "network/protocol.hpp"
#include "utils/cpp2011.hpp"
class AbstractKart;
class Item;
@ -18,17 +19,19 @@ public:
GameEventsProtocol();
virtual ~GameEventsProtocol();
virtual bool notifyEvent(Event* event);
virtual void setup();
virtual void update();
virtual bool notifyEvent(Event* event) OVERRIDE;
void collectedItem(Item* item, AbstractKart* kart);
void collectedItem(const NetworkString &ns);
void kartFinishedRace(AbstractKart *kart, float time);
void kartFinishedRace(const NetworkString &ns);
virtual void setup() OVERRIDE {};
virtual void update(float dt) OVERRIDE {};
virtual void asynchronousUpdate() OVERRIDE{}
// ------------------------------------------------------------------------
virtual void asynchronousUpdate() {}
// ------------------------------------------------------------------------
virtual bool notifyEventAsynchronous(Event* event) { return false; }
virtual bool notifyEventAsynchronous(Event* event) OVERRIDE
{
return false;
} // notifyEventAsynchronous
}; // class GameEventsProtocol

View File

@ -21,6 +21,7 @@
#include "network/protocol.hpp"
#include "network/transport_address.hpp"
#include "utils/cpp2011.hpp"
namespace Online { class XMLRequest; }
@ -37,19 +38,19 @@ public:
GetPeerAddress(uint32_t peer_id, CallbackObject* callback_object);
virtual ~GetPeerAddress();
virtual void setup();
virtual void asynchronousUpdate();
virtual void setup() OVERRIDE;
virtual void asynchronousUpdate() OVERRIDE;
void setPeerID(uint32_t m_peer_id);
// ------------------------------------------------------------------------
/** Returns the address found. */
const TransportAddress &getAddress() const { return m_address; }
// ------------------------------------------------------------------------
virtual void update() {}
virtual void update(float dt) OVERRIDE {}
// ------------------------------------------------------------------------
virtual bool notifyEvent(Event* event) { return true; }
virtual bool notifyEvent(Event* event) OVERRIDE { return true; }
// ------------------------------------------------------------------------
virtual bool notifyEventAsynchronous(Event* event) { return true; }
virtual bool notifyEventAsynchronous(Event* event) OVERRIDE { return true; }
}; // class GetPeerAddress

View File

@ -20,6 +20,7 @@
#define GET_PUBLIC_ADDRESS_HPP
#include "network/protocol.hpp"
#include "utils/cpp2011.hpp"
#include <string>
@ -27,34 +28,39 @@ class Network;
class GetPublicAddress : public Protocol
{
public:
GetPublicAddress(CallbackObject *callback = NULL);
virtual ~GetPublicAddress() {}
private:
void createStunRequest();
std::string parseStunResponse();
virtual bool notifyEvent(Event* event) { return true; }
virtual bool notifyEventAsynchronous(Event* event) { return true; }
virtual void setup() { m_state = NOTHING_DONE; }
virtual void update() {}
virtual void asynchronousUpdate();
// Constants
static const uint32_t m_stun_magic_cookie;
static const int m_stun_server_port = 3478;
private:
void createStunRequest();
std::string parseStunResponse();
enum State
{
NOTHING_DONE,
STUN_REQUEST_SENT,
EXITING
} m_state;
// Constants
static const uint32_t m_stun_magic_cookie;
static const int m_stun_server_port = 3478;
uint8_t m_stun_tansaction_id[12];
uint32_t m_stun_server_ip;
Network* m_transaction_host;
enum State
{
NOTHING_DONE,
STUN_REQUEST_SENT,
EXITING
} m_state;
public:
GetPublicAddress(CallbackObject *callback = NULL);
virtual ~GetPublicAddress() {}
uint8_t m_stun_tansaction_id[12];
uint32_t m_stun_server_ip;
Network* m_transaction_host;
};
virtual void asynchronousUpdate() OVERRIDE;
// ------------------------------------------------------------------------
virtual void update(float dt) OVERRIDE {}
// ------------------------------------------------------------------------
virtual bool notifyEvent(Event* event) OVERRIDE { return true; }
// ------------------------------------------------------------------------
virtual bool notifyEventAsynchronous(Event* event) OVERRIDE { return true; }
// ------------------------------------------------------------------------
virtual void setup() { m_state = NOTHING_DONE; }
}; // class GetPublicAddress
#endif // GET_PUBLIC_ADDRESS_HPP

View File

@ -20,6 +20,7 @@
#define HIDE_PUBLIC_ADDRESS_HPP
#include "network/protocol.hpp"
#include "utils/cpp2011.hpp"
#include <string>
@ -27,26 +28,29 @@ namespace Online { class XMLRequest; }
class HidePublicAddress : public Protocol
{
public:
HidePublicAddress();
virtual ~HidePublicAddress();
private:
Online::XMLRequest* m_request;
enum STATE
{
NONE,
REQUEST_PENDING,
DONE,
EXITING
};
STATE m_state;
virtual bool notifyEvent(Event* event) { return true; }
virtual bool notifyEventAsynchronous(Event* event) { return true; }
virtual void setup();
virtual void update() {}
virtual void asynchronousUpdate();
public:
HidePublicAddress();
virtual ~HidePublicAddress();
protected:
Online::XMLRequest* m_request;
enum STATE
{
NONE,
REQUEST_PENDING,
DONE,
EXITING
};
STATE m_state;
};
virtual void asynchronousUpdate() OVERRIDE;
virtual void setup() OVERRIDE;
// ------------------------------------------------------------------------
virtual bool notifyEvent(Event* event) OVERRIDE { return true; }
// ------------------------------------------------------------------------
virtual bool notifyEventAsynchronous(Event* event) OVERRIDE { return true; }
// ------------------------------------------------------------------------
virtual void update(float dt) OVERRIDE {}
}; // class HidePublicAddress
#endif // HIDE_PUBLIC_ADDRESS_HPP

View File

@ -67,7 +67,7 @@ bool KartUpdateProtocol::notifyEvent(Event* event)
* 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()
void KartUpdateProtocol::update(float dt)
{
if (!World::getWorld())
return;

View File

@ -2,7 +2,9 @@
#define KART_UPDATE_PROTOCOL_HPP
#include "network/protocol.hpp"
#include "utils/cpp2011.hpp"
#include "utils/vec3.hpp"
#include "LinearMath/btQuaternion.h"
#include <vector>
@ -27,10 +29,10 @@ public:
KartUpdateProtocol();
virtual ~KartUpdateProtocol();
virtual bool notifyEvent(Event* event);
virtual void setup();
virtual void update();
virtual void asynchronousUpdate() {};
virtual bool notifyEvent(Event* event) OVERRIDE;
virtual void setup() OVERRIDE;
virtual void update(float dt) OVERRIDE;
virtual void asynchronousUpdate() OVERRIDE {};
}; // KartUpdateProtocol

View File

@ -73,7 +73,7 @@ public:
virtual ~LobbyRoomProtocol() {}
// ------------------------------------------------------------------------
virtual void setup() = 0;
virtual void update() = 0;
virtual void update(float dt) = 0;
}; // class LobbyRoomProtocol
#endif // LOBBY_ROOM_PROTOCOL_HPP

View File

@ -3,6 +3,7 @@
#include "network/protocol.hpp"
#include "network/transport_address.hpp"
#include "utils/cpp2011.hpp"
class PingProtocol : public Protocol
{
@ -16,16 +17,19 @@ private:
/** Time of last ping. */
double m_last_ping_time;
public:
PingProtocol(const TransportAddress& ping_dst,
double delay_between_pings);
virtual ~PingProtocol();
PingProtocol(const TransportAddress& ping_dst,
double delay_between_pings);
virtual ~PingProtocol();
virtual bool notifyEvent(Event* event) { return true; }
virtual bool notifyEventAsynchronous(Event* event) { return true; }
virtual void setup();
virtual void update() {}
virtual void asynchronousUpdate();
virtual void asynchronousUpdate() OVERRIDE;
virtual void setup() OVERRIDE;
// ------------------------------------------------------------------------
virtual bool notifyEvent(Event* event) OVERRIDE { return true; }
// ------------------------------------------------------------------------
virtual bool notifyEventAsynchronous(Event* event) OVERRIDE { return true; }
// ------------------------------------------------------------------------
virtual void update(float dt) OVERRIDE {}
};
#endif // PING_PROTOCOL_HPP

View File

@ -38,12 +38,14 @@ public:
RequestConnection(uint32_t server_id);
virtual ~RequestConnection();
virtual bool notifyEvent(Event* event) { return true; }
virtual bool notifyEventAsynchronous(Event* event) { return true; }
virtual void setup();
virtual void update() {}
virtual void asynchronousUpdate();
virtual void setup() OVERRIDE;
virtual void asynchronousUpdate() OVERRIDE;
// ------------------------------------------------------------------------
virtual bool notifyEvent(Event* event) OVERRIDE { return true; }
// ------------------------------------------------------------------------
virtual bool notifyEventAsynchronous(Event* event) OVERRIDE { return true; }
// ------------------------------------------------------------------------
virtual void update(float dt) OVERRIDE {}
}; // RequestConnection

View File

@ -112,7 +112,7 @@ bool ServerLobbyRoomProtocol::notifyEventAsynchronous(Event* event)
* is known, register the server and its address with the stk server so that
* client can find it.
*/
void ServerLobbyRoomProtocol::update()
void ServerLobbyRoomProtocol::update(float dt)
{
switch (m_state)
{

View File

@ -55,7 +55,7 @@ public:
virtual bool notifyEventAsynchronous(Event* event) OVERRIDE;
virtual void setup() OVERRIDE;
virtual void update() OVERRIDE;
virtual void update(float dt) OVERRIDE;
virtual void asynchronousUpdate() OVERRIDE {};
void startGame();

View File

@ -170,7 +170,7 @@ void StartGameProtocol::startRace()
} // startRace
// ----------------------------------------------------------------------------
void StartGameProtocol::update()
void StartGameProtocol::update(float dt)
{
switch(m_state)
{

View File

@ -2,6 +2,8 @@
#define START_GAME_PROTOCOL_HPP
#include "network/protocol.hpp"
#include "utils/cpp2011.hpp"
#include <map>
class GameSetup;
@ -39,10 +41,10 @@ public:
virtual ~StartGameProtocol();
virtual bool notifyEventAsynchronous(Event* event);
virtual void setup();
virtual void update();
virtual void setup() OVERRIDE;
virtual void update(float dt) OVERRIDE;
void ready();
virtual void asynchronousUpdate() {}
virtual void asynchronousUpdate() OVERRIDE {}
}; // class StartGameProtocol

View File

@ -2,6 +2,7 @@
#define STOP_SERVER_HPP
#include "network/protocol.hpp"
#include "utils/cpp2011.hpp"
namespace Online { class XMLRequest; }
@ -10,25 +11,26 @@ namespace Online { class XMLRequest; }
class StopServer : public Protocol
{
public:
StopServer();
virtual ~StopServer();
private:
Online::XMLRequest* m_request;
enum STATE
{
NONE,
REQUEST_PENDING,
DONE,
EXITING
};
STATE m_state;
public:
StopServer();
virtual ~StopServer();
virtual bool notifyEventAsynchronous(Event* event);
virtual void setup();
virtual void update() {}
virtual void asynchronousUpdate();
virtual bool notifyEventAsynchronous(Event* event) OVERRIDE;
virtual void setup() OVERRIDE;
virtual void asynchronousUpdate() OVERRIDE;
// --------------------------------------------------------------------
virtual void update(float dt) OVERRIDE {}
protected:
Online::XMLRequest* m_request;
enum STATE
{
NONE,
REQUEST_PENDING,
DONE,
EXITING
};
STATE m_state;
};
#endif // STOP_SERVER_HPP

View File

@ -2,6 +2,8 @@
#define SYNCHRONIZATION_PROTOCOL_HPP
#include "network/protocol.hpp"
#include "utils/cpp2011.hpp"
#include <vector>
#include <map>
@ -28,12 +30,13 @@ public:
SynchronizationProtocol();
virtual ~SynchronizationProtocol();
virtual bool notifyEventAsynchronous(Event* event);
virtual void setup();
virtual void update() {}
virtual void asynchronousUpdate();
virtual bool notifyEventAsynchronous(Event* event) OVERRIDE;
virtual void setup() OVERRIDE;
virtual void asynchronousUpdate() OVERRIDE;
void startCountdown(int ms_countdown);
// ------------------------------------------------------------------------
virtual void update(float dt) OVERRIDE {}
// ------------------------------------------------------------------------
int getCountdown() { return (int)(m_countdown*1000.0); }

View File

@ -305,8 +305,8 @@ void STKHost::init()
// Optional: start the network console
m_network_console = new NetworkConsole();
m_network_console->run();
} // STKHost
} // STKHost
// ----------------------------------------------------------------------------
/** Destructor. Stops the listening thread, closes the packet log file and