Merge remote-tracking branch 'origin/master' into random_arena_item

This commit is contained in:
Benau 2016-03-19 08:58:25 +08:00
commit a42ee39240
36 changed files with 1396 additions and 1289 deletions

View File

@ -99,6 +99,8 @@ PlayerProfile::PlayerProfile(const XMLNode* node)
//------------------------------------------------------------------------------
PlayerProfile::~PlayerProfile()
{
delete m_story_mode_status;
delete m_achievements_status;
#ifdef DEBUG
m_magic_number = 0xDEADBEEF;
#endif

View File

@ -370,6 +370,9 @@ void RibbonWidget::add()
m_element->setTabOrder(id);
m_element->setTabGroup(false);
updateSelection();
if (!m_is_visible)
setVisible(false);
} // add
// ----------------------------------------------------------------------------

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

@ -107,6 +107,21 @@ void Protocol::requestTerminate()
ProtocolManager::getInstance()->requestTerminate(this);
} // requestTerminate
// ----------------------------------------------------------------------------
/** Finds a protocol with the given type and requests it to be terminated.
* If no such protocol exist, log an error message.
* \param type The protocol type to delete.
*/
void Protocol::findAndTerminateProtocol(ProtocolType type)
{
Protocol* protocol = ProtocolManager::getInstance()->getProtocol(type);
if (protocol)
protocol->requestTerminate();
else
Log::error("ClientLobbyRoomProtocol",
"No protocol %d registered.", type);
} // findAndTerminateProtocol
// ----------------------------------------------------------------------------
/** Sends a message to all peers, inserting the peer's token into the message.
* The message is composed of a 1-byte message (usually the message type)

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. */
@ -138,6 +138,7 @@ public:
void requestPause();
void requestUnpause();
void requestTerminate();
void findAndTerminateProtocol(ProtocolType type);
// ------------------------------------------------------------------------
/** \brief Called when the protocol is paused (by an other entity or by

View File

@ -315,13 +315,13 @@ bool ProtocolManager::sendEvent(Event* event)
/** \brief Updates the manager.
*
* This function processes the events queue, notifies the concerned
* protocols that they have events to process. Then ask all protocols
* to update themselves. Finally processes stored requests about
* protocols that they have events to process. Then asks all protocols
* to update themselves. Finally it processes stored requests about
* starting, stoping, pausing etc... protocols.
* This function is called by the main loop.
* 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
@ -357,7 +357,7 @@ void ProtocolManager::update()
* protocols that they have events to process. Then ask all protocols
* to update themselves. Finally processes stored requests about
* starting, stoping, pausing etc... protocols.
* This function is called in a thread.
* This function is called in a separate thread running in this instance.
* This function IS NOT FPS-dependant.
*/
void ProtocolManager::asynchronousUpdate()

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

@ -31,6 +31,7 @@
#include "online/online_profile.hpp"
#include "states_screens/networking_lobby.hpp"
#include "states_screens/network_kart_selection.hpp"
#include "states_screens/race_result_gui.hpp"
#include "states_screens/state_manager.hpp"
#include "utils/log.hpp"
@ -174,7 +175,8 @@ void ClientLobbyRoomProtocol::voteLaps(uint8_t player_id, uint8_t laps,
} // voteLaps
//-----------------------------------------------------------------------------
/** Called when a client selects to exit a server.
*/
void ClientLobbyRoomProtocol::leave()
{
m_server->disconnect();
@ -183,30 +185,40 @@ void ClientLobbyRoomProtocol::leave()
ServersManager::get()->unsetJoinedServer();
} // leave
//-----------------------------------------------------------------------------
/** Called from the gui when a client clicked on 'continue' on the race result
* screen. It notifies the server that this client has exited the screen and
* is back at the lobby.
*/
void ClientLobbyRoomProtocol::doneWithResults()
{
NetworkString *done = getNetworkString(1);
done->addUInt8(LE_RACE_FINISHED_ACK);
sendToServer(done, /*reliable*/true);
delete done;
} // doneWithResults
//-----------------------------------------------------------------------------
bool ClientLobbyRoomProtocol::notifyEvent(Event* event)
{
assert(m_setup); // assert that the setup exists
if (event->getType() == EVENT_TYPE_MESSAGE)
{
NetworkString &data = event->data();
assert(data.size()); // assert that data isn't empty
uint8_t message_type = data.getUInt8();
if (message_type != LE_KART_SELECTION_UPDATE &&
message_type != LE_RACE_FINISHED )
return false; // don't treat the event
Log::info("ClientLobbyRoomProtocol", "Synchronous message of type %d",
message_type);
if (message_type == LE_KART_SELECTION_UPDATE) // kart selection update
kartSelectionUpdate(event);
else if (message_type == LE_RACE_FINISHED) // end of race
raceFinished(event);
return true;
}
switch(message_type)
{
case LE_KART_SELECTION_UPDATE: kartSelectionUpdate(event); break;
case LE_RACE_FINISHED: raceFinished(event); break;
case LE_EXIT_RESULT: exitResultScreen(event); break;
default:
return false;
break;
} // switch
return true;
} // notifyEvent
//-----------------------------------------------------------------------------
@ -257,7 +269,7 @@ bool ClientLobbyRoomProtocol::notifyEventAsynchronous(Event* event)
//-----------------------------------------------------------------------------
void ClientLobbyRoomProtocol::update()
void ClientLobbyRoomProtocol::update(float dt)
{
switch (m_state)
{
@ -302,14 +314,6 @@ void ClientLobbyRoomProtocol::update()
case SELECTING_KARTS:
break;
case PLAYING:
{
// race is now over, kill race protocols and return to connected state
if (RaceEventManager::getInstance<RaceEventManager>()->isRaceOver())
{
Log::info("ClientLobbyRoomProtocol", "Game finished.");
m_state = RACE_FINISHED;
}
}
break;
case RACE_FINISHED:
break;
@ -663,7 +667,15 @@ void ClientLobbyRoomProtocol::raceFinished(Event* event)
} // raceFinished
//-----------------------------------------------------------------------------
/** Called when the server informs the clients to exit the race result screen.
* It exits the race, and goes back to the lobby.
*/
void ClientLobbyRoomProtocol::exitResultScreen(Event *event)
{
RaceResultGUI::getInstance()->backToLobby();
} // exitResultScreen
//-----------------------------------------------------------------------------
/*! \brief Called when a player votes for a major race mode.
* \param event : Event providing the information.
*

View File

@ -3,12 +3,53 @@
#include "network/protocols/lobby_room_protocol.hpp"
#include "network/transport_address.hpp"
#include "utils/cpp2011.hpp"
class STKPeer;
class ClientLobbyRoomProtocol : public LobbyRoomProtocol
{
public:
private:
void newPlayer(Event* event);
void disconnectedPlayer(Event* event);
void connectionAccepted(Event* event); //!< Callback function on connection acceptation
void connectionRefused(Event* event); //!< Callback function on connection refusal
void kartSelectionRefused(Event* event);
void kartSelectionUpdate(Event* event);
void startGame(Event* event);
void startSelection(Event* event);
void raceFinished(Event* event);
void exitResultScreen(Event *event);
// race votes
void playerMajorVote(Event* event);
void playerRaceCountVote(Event* event);
void playerMinorVote(Event* event);
void playerTrackVote(Event* event);
void playerReversedVote(Event* event);
void playerLapsVote(Event* event);
TransportAddress m_server_address;
STKPeer* m_server;
enum STATE
{
NONE,
LINKED,
REQUESTING_CONNECTION,
CONNECTED, // means in the lobby room
KART_SELECTION, // Start kart selection, then go to next state
SELECTING_KARTS, // in the network kart selection screen
PLAYING, // racing
RACE_FINISHED, // race result shown
DONE,
EXITING
};
/** The state of the finite state machine. */
STATE m_state;
public:
ClientLobbyRoomProtocol(const TransportAddress& server_address);
virtual ~ClientLobbyRoomProtocol();
@ -21,49 +62,15 @@ class ClientLobbyRoomProtocol : public LobbyRoomProtocol
uint8_t track_nb = 0);
void voteReversed(uint8_t player_id, bool reversed, uint8_t track_nb = 0);
void voteLaps(uint8_t player_id, uint8_t laps, uint8_t track_nb = 0);
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 {}
protected:
void newPlayer(Event* event);
void disconnectedPlayer(Event* event);
void connectionAccepted(Event* event); //!< Callback function on connection acceptation
void connectionRefused(Event* event); //!< Callback function on connection refusal
void kartSelectionRefused(Event* event);
void kartSelectionUpdate(Event* event);
void startGame(Event* event);
void startSelection(Event* event);
void raceFinished(Event* event);
// race votes
void playerMajorVote(Event* event);
void playerRaceCountVote(Event* event);
void playerMinorVote(Event* event);
void playerTrackVote(Event* event);
void playerReversedVote(Event* event);
void playerLapsVote(Event* event);
TransportAddress m_server_address;
STKPeer* m_server;
enum STATE
{
NONE,
LINKED,
REQUESTING_CONNECTION,
CONNECTED, // means in the lobby room
KART_SELECTION,
SELECTING_KARTS, // in the network kart selection screen
PLAYING,
RACE_FINISHED,
DONE,
EXITING
};
STATE m_state;
};
#endif // CLIENT_LOBBY_ROOM_PROTOCOL_HPP

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,17 +28,7 @@ class Network;
class GetPublicAddress : public Protocol
{
public:
GetPublicAddress(CallbackObject *callback = NULL);
virtual ~GetPublicAddress() {}
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();
private:
private:
void createStunRequest();
std::string parseStunResponse();
@ -55,6 +46,21 @@ class GetPublicAddress : public Protocol
uint8_t m_stun_tansaction_id[12];
uint32_t m_stun_server_ip;
Network* m_transaction_host;
};
public:
GetPublicAddress(CallbackObject *callback = NULL);
virtual ~GetPublicAddress() {}
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,17 +28,7 @@ namespace Online { class XMLRequest; }
class HidePublicAddress : public Protocol
{
public:
HidePublicAddress();
virtual ~HidePublicAddress();
virtual bool notifyEvent(Event* event) { return true; }
virtual bool notifyEventAsynchronous(Event* event) { return true; }
virtual void setup();
virtual void update() {}
virtual void asynchronousUpdate();
protected:
private:
Online::XMLRequest* m_request;
enum STATE
{
@ -47,6 +38,19 @@ class HidePublicAddress : public Protocol
EXITING
};
STATE m_state;
};
public:
HidePublicAddress();
virtual ~HidePublicAddress();
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

@ -36,24 +36,26 @@ public:
/** Lists all lobby events (LE). */
enum
{
LE_CONNECTION_REQUESTED = 1,
LE_REQUEST_BEGIN,
LE_NEW_PLAYER_CONNECTED,
LE_KART_SELECTION,
LE_PLAYER_DISCONNECTED,
LE_KART_SELECTION_UPDATE,
LE_START_RACE,
LE_START_SELECTION,
LE_RACE_FINISHED,
LE_CONNECTION_REFUSED,
LE_CONNECTION_ACCEPTED,
LE_KART_SELECTION_REFUSED,
LE_VOTE_MAJOR,
LE_VOTE_RACE_COUNT,
LE_VOTE_MINOR,
LE_VOTE_TRACK,
LE_VOTE_REVERSE,
LE_VOTE_LAPS,
LE_CONNECTION_REQUESTED = 1, // a connection to the server
LE_CONNECTION_REFUSED, // Connection to server refused
LE_CONNECTION_ACCEPTED, // Connection to server accepted
LE_KART_SELECTION_UPDATE, // inform client about kart selected
LE_REQUEST_BEGIN, // begin of kart selection
LE_KART_SELECTION_REFUSED, // Client not auth. to start selection
LE_NEW_PLAYER_CONNECTED, // inform client about new player
LE_KART_SELECTION, // Player selected kart
LE_PLAYER_DISCONNECTED, // Client disconnected
LE_START_RACE, // start race
LE_START_SELECTION, // inform client to start selection
LE_RACE_FINISHED, // race has finished, display result
LE_RACE_FINISHED_ACK, // client went back to lobby
LE_EXIT_RESULT, // Force clients to exit race result screen
LE_VOTE_MAJOR, // vote of major race mode
LE_VOTE_MINOR, // vote for minor race mode
LE_VOTE_RACE_COUNT, // vote for number of tracks
LE_VOTE_TRACK, // vote for a track
LE_VOTE_REVERSE, // vote if race in reverse
LE_VOTE_LAPS, // vote number of laps
};
protected:
@ -71,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
{
@ -20,12 +21,15 @@ public:
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

@ -33,6 +33,7 @@
#include "network/stk_peer.hpp"
#include "online/online_profile.hpp"
#include "online/request_manager.hpp"
#include "states_screens/race_result_gui.hpp"
#include "utils/log.hpp"
#include "utils/random_generator.hpp"
#include "utils/time.hpp"
@ -67,7 +68,6 @@ void ServerLobbyRoomProtocol::setup()
m_state = NetworkConfig::get()->isLAN() ? ACCEPTING_CLIENTS
: NONE;
m_selection_enabled = false;
m_in_race = false;
m_current_protocol = NULL;
Log::info("ServerLobbyRoomProtocol", "Starting the protocol.");
} // setup
@ -96,6 +96,7 @@ bool ServerLobbyRoomProtocol::notifyEventAsynchronous(Event* event)
case LE_VOTE_TRACK: playerTrackVote(event); break;
case LE_VOTE_REVERSE: playerReversedVote(event); break;
case LE_VOTE_LAPS: playerLapsVote(event); break;
case LE_RACE_FINISHED_ACK: playerFinishedResult(event); break;
} // switch
} // if (event->getType() == EVENT_TYPE_MESSAGE)
@ -111,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)
{
@ -142,16 +143,38 @@ void ServerLobbyRoomProtocol::update()
// Only poll the STK server if this is a WAN server.
if(NetworkConfig::get()->isWAN())
checkIncomingConnectionRequests();
if (m_in_race && World::getWorld() &&
break;
}
case SELECTING:
break; // Nothing to do, this is event based
case RACING:
if (World::getWorld() &&
RaceEventManager::getInstance<RaceEventManager>()->isRunning())
{
checkRaceFinished();
}
break;
case RESULT_DISPLAY:
if(StkTime::getRealTime() > m_timeout)
{
// Send a notification to all clients to exit
// the race result screen
NetworkString *exit_result_screen = getNetworkString(1);
exit_result_screen->setSynchronous(true);
exit_result_screen->addUInt8(LE_EXIT_RESULT);
sendMessageToPeersChangingToken(exit_result_screen,
/*reliable*/true);
delete exit_result_screen;
m_state = ACCEPTING_CLIENTS;
RaceResultGUI::getInstance()->backToLobby();
// notify the network world that it is stopped
RaceEventManager::getInstance()->stop();
// stop race protocols
findAndTerminateProtocol(PROTOCOL_CONTROLLER_EVENTS);
findAndTerminateProtocol(PROTOCOL_KART_UPDATE);
findAndTerminateProtocol(PROTOCOL_GAME_EVENTS);
}
case SELECTING_KARTS:
break; // Nothing to do, this is event based
break;
case DONE:
m_state = EXITING;
requestTerminate();
@ -227,7 +250,7 @@ void ServerLobbyRoomProtocol::startGame()
delete ns;
Protocol *p = new StartGameProtocol(m_setup);
p->requestStart();
m_in_race = true;
m_state = RACING;
} // startGame
//-----------------------------------------------------------------------------
@ -252,7 +275,7 @@ void ServerLobbyRoomProtocol::startSelection(const Event *event)
m_selection_enabled = true;
m_state = SELECTING_KARTS;
m_state = SELECTING;
} // startSelection
//-----------------------------------------------------------------------------
@ -304,27 +327,35 @@ void ServerLobbyRoomProtocol::checkIncomingConnectionRequests()
} // checkIncomingConnectionRequests
//-----------------------------------------------------------------------------
void ServerLobbyRoomProtocol::checkRaceFinished()
/** Checks if the race is finished, and if so informs the clients and switches
* to state RESULT_DISPLAY, during which the race result gui is shown and all
* clients can click on 'continue'.
*/
void ServerLobbyRoomProtocol::checkRaceFinished()
{
assert(RaceEventManager::getInstance()->isRunning());
assert(World::getWorld());
// if race is over, give the final score to everybody
if (RaceEventManager::getInstance()->isRaceOver())
{
if(!RaceEventManager::getInstance()->isRaceOver()) return;
m_player_ready_counter = 0;
// Set the delay before the server forces all clients to exit the race
// result screen and go back to the lobby
m_timeout = (float)(StkTime::getRealTime()+15.0f);
m_state = RESULT_DISPLAY;
// calculate karts ranks :
int num_players = race_manager->getNumberOfKarts();
int num_karts = race_manager->getNumberOfKarts();
std::vector<int> karts_results;
std::vector<float> karts_times;
for (int j = 0; j < num_players; j++)
for (int j = 0; j < num_karts; j++)
{
float kart_time = race_manager->getKartRaceTime(j);
for (unsigned int i = 0; i < karts_times.size(); i++)
{
if (kart_time < karts_times[i])
{
karts_times.insert(karts_times.begin()+i, kart_time);
karts_results.insert(karts_results.begin()+i, j);
karts_times.insert(karts_times.begin() + i, kart_time);
karts_results.insert(karts_results.begin() + i, j);
break;
}
}
@ -332,7 +363,7 @@ void ServerLobbyRoomProtocol::checkRaceFinished()
const std::vector<STKPeer*> &peers = STKHost::get()->getPeers();
NetworkString *total = getNetworkString(1+karts_results.size());
NetworkString *total = getNetworkString(1 + karts_results.size());
total->setSynchronous(true);
total->addUInt8(LE_RACE_FINISHED);
for (unsigned int i = 0; i < karts_results.size(); i++)
@ -344,39 +375,7 @@ void ServerLobbyRoomProtocol::checkRaceFinished()
sendMessageToPeersChangingToken(total, /*reliable*/ true);
delete total;
Log::info("ServerLobbyRoomProtocol", "End of game message sent");
m_in_race = false;
// stop race protocols
Protocol* protocol = ProtocolManager::getInstance()
->getProtocol(PROTOCOL_CONTROLLER_EVENTS);
if (protocol)
protocol->requestTerminate();
else
Log::error("ClientLobbyRoomProtocol",
"No controller events protocol registered.");
protocol = ProtocolManager::getInstance()
->getProtocol(PROTOCOL_KART_UPDATE);
if (protocol)
protocol->requestTerminate();
else
Log::error("ClientLobbyRoomProtocol",
"No kart update protocol registered.");
protocol = ProtocolManager::getInstance()
->getProtocol(PROTOCOL_GAME_EVENTS);
if (protocol)
protocol->requestTerminate();
else
Log::error("ClientLobbyRoomProtocol",
"No game events protocol registered.");
// notify the network world that it is stopped
RaceEventManager::getInstance()->stop();
// exit the race now
race_manager->exitRace();
race_manager->setAIKartOverride("");
}
} // checkRaceFinished
//-----------------------------------------------------------------------------
@ -522,7 +521,7 @@ void ServerLobbyRoomProtocol::connectionRequested(Event* event)
*/
void ServerLobbyRoomProtocol::kartSelectionRequested(Event* event)
{
if(m_state!=SELECTING_KARTS)
if(m_state!=SELECTING)
{
Log::warn("Server", "Received kart selection while in state %d.",
m_state);
@ -751,3 +750,19 @@ void ServerLobbyRoomProtocol::playerLapsVote(Event* event)
} // playerLapsVote
//-----------------------------------------------------------------------------
/** Called when a client clicks on 'ok' on the race result screen.
* If all players have clicked on 'ok', go back to the lobby.
*/
void ServerLobbyRoomProtocol::playerFinishedResult(Event *event)
{
m_player_ready_counter++;
if(m_player_ready_counter == STKHost::get()->getPeerCount())
{
// We can't trigger the world/race exit here, since this is called
// from the protocol manager thread. So instead we force the timeout
// to get triggered (which is done from the main thread):
m_timeout = 0;
}
} // playerFinishedResult
//-----------------------------------------------------------------------------

View File

@ -13,10 +13,12 @@ private:
enum
{
NONE,
GETTING_PUBLIC_ADDRESS,
ACCEPTING_CLIENTS,
SELECTING_KARTS,
DONE,
GETTING_PUBLIC_ADDRESS, // Waiting to receive its public ip address
ACCEPTING_CLIENTS, // In lobby, accepting clients
SELECTING, // kart, track, ... selection started
RACING, // racing
RESULT_DISPLAY, // Show result screen
DONE, // shutting down server
EXITING
} m_state;
@ -25,7 +27,12 @@ private:
Protocol *m_current_protocol;
bool m_selection_enabled;
bool m_in_race;
/** Counts how many players are ready to go on. */
int m_player_ready_counter;
/** Timeout counter for showing the result screen. */
float m_timeout;
// connection management
void clientDisconnected(Event* event);
@ -39,6 +46,7 @@ private:
void playerTrackVote(Event* event);
void playerReversedVote(Event* event);
void playerLapsVote(Event* event);
void playerFinishedResult(Event *event);
void registerServer();
public:
@ -47,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,16 +11,7 @@ namespace Online { class XMLRequest; }
class StopServer : public Protocol
{
public:
StopServer();
virtual ~StopServer();
virtual bool notifyEventAsynchronous(Event* event);
virtual void setup();
virtual void update() {}
virtual void asynchronousUpdate();
protected:
private:
Online::XMLRequest* m_request;
enum STATE
{
@ -29,6 +21,16 @@ class StopServer : public Protocol
EXITING
};
STATE m_state;
public:
StopServer();
virtual ~StopServer();
virtual bool notifyEventAsynchronous(Event* event) OVERRIDE;
virtual void setup() OVERRIDE;
virtual void asynchronousUpdate() OVERRIDE;
// --------------------------------------------------------------------
virtual void update(float dt) OVERRIDE {}
};
#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

@ -148,7 +148,7 @@ void CreateServerScreen::onUpdate(float delta)
// Otherwise wait till we get an answer from the server:
// -----------------------------------------------------
if(!STKHost::get()->isRegistered())
if(!STKHost::get()->isRegistered() && !NetworkConfig::get()->isLAN())
{
m_info_widget->setDefaultColor();
m_info_widget->setText(StringUtils::loadingDots(_("Creating server")),

View File

@ -125,6 +125,7 @@ void NetworkingLobby::init()
m_server_game_mode->setText(mode, false);
}
if(!NetworkConfig::get()->isServer())
m_start_button->setVisible(STKHost::get()->isAuthorisedToControl());
// For now create the active player and bind it to the right
@ -138,8 +139,11 @@ void NetworkingLobby::init()
void NetworkingLobby::onUpdate(float delta)
{
// FIXME Network looby should be closed when stkhost is shut down
if(NetworkConfig::get()->isClient())
{
m_start_button->setVisible(STKHost::existHost() &&
STKHost::get()->isAuthorisedToControl());
}
} // onUpdate
// ----------------------------------------------------------------------------

View File

@ -81,6 +81,15 @@ void OnlineProfileBase::loadedFromFile()
void OnlineProfileBase::beforeAddingWidget()
{
m_visiting_profile = ProfileManager::get()->getVisitingProfile();
} // beforeAddingWidget
// -----------------------------------------------------------------------------
/** Called when entering this menu (before widgets are added).
*/
void OnlineProfileBase::init()
{
Screen::init();
if (m_profile_tabs)
{
if (!m_visiting_profile || !m_visiting_profile->isCurrentUser())
@ -95,14 +104,6 @@ void OnlineProfileBase::beforeAddingWidget()
m_profile_tabs->setVisible(false);
}
} // if m_profile_tabhs
} // beforeAddingWidget
// -----------------------------------------------------------------------------
/** Called when entering this menu (before widgets are added).
*/
void OnlineProfileBase::init()
{
Screen::init();
if (m_profile_tabs)
{

View File

@ -137,6 +137,11 @@ void OnlineProfileServers::doQuickPlay()
// select first one
const Server *server = ServersManager::get()->getQuickPlay();
if(!server)
{
Log::error("OnlineProfileServers", "Can not find quick play server.");
return;
}
// do a join request
XMLRequest *join_request = new RequestConnection::ServerJoinRequest();

File diff suppressed because it is too large Load Diff

View File

@ -213,6 +213,7 @@ public:
Input::InputType type, int playerId) OVERRIDE;
void eventCallback(GUIEngine::Widget* widget, const std::string& name,
const int playerID) OVERRIDE;
void backToLobby();
friend class GUIEngine::ScreenSingleton<RaceResultGUI>;