Use quicker ways to stop ingame protocol after finishing game
This commit is contained in:
parent
3573f64ae1
commit
7c4c7b6f63
@ -44,6 +44,7 @@
|
|||||||
#include "network/protocols/connect_to_server.hpp"
|
#include "network/protocols/connect_to_server.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/protocol_manager.hpp"
|
||||||
#include "network/race_event_manager.hpp"
|
#include "network/race_event_manager.hpp"
|
||||||
#include "network/server.hpp"
|
#include "network/server.hpp"
|
||||||
#include "network/server_config.hpp"
|
#include "network/server_config.hpp"
|
||||||
@ -1075,8 +1076,8 @@ void ClientLobby::raceFinished(Event* event)
|
|||||||
|
|
||||||
// stop race protocols
|
// stop race protocols
|
||||||
RaceEventManager::getInstance()->stop();
|
RaceEventManager::getInstance()->stop();
|
||||||
RaceEventManager::getInstance()->getProtocol()->requestTerminate();
|
ProtocolManager::lock()->findAndTerminate(PROTOCOL_GAME_EVENTS);
|
||||||
GameProtocol::lock()->requestTerminate();
|
ProtocolManager::lock()->findAndTerminate(PROTOCOL_CONTROLLER_EVENTS);
|
||||||
m_state.store(RACE_FINISHED);
|
m_state.store(RACE_FINISHED);
|
||||||
} // raceFinished
|
} // raceFinished
|
||||||
|
|
||||||
@ -1098,16 +1099,13 @@ void ClientLobby::backToLobby(Event *event)
|
|||||||
if (RaceEventManager::getInstance())
|
if (RaceEventManager::getInstance())
|
||||||
{
|
{
|
||||||
RaceEventManager::getInstance()->stop();
|
RaceEventManager::getInstance()->stop();
|
||||||
auto gep = RaceEventManager::getInstance()->getProtocol();
|
ProtocolManager::lock()->findAndTerminate(PROTOCOL_GAME_EVENTS);
|
||||||
// Game events protocol is main thread event only
|
|
||||||
if (gep)
|
|
||||||
gep->requestTerminate();
|
|
||||||
}
|
}
|
||||||
auto gp = GameProtocol::lock();
|
auto gp = GameProtocol::lock();
|
||||||
if (gp)
|
if (gp)
|
||||||
{
|
{
|
||||||
auto lock = gp->acquireWorldDeletingMutex();
|
auto lock = gp->acquireWorldDeletingMutex();
|
||||||
gp->requestTerminate();
|
ProtocolManager::lock()->findAndTerminate(PROTOCOL_CONTROLLER_EVENTS);
|
||||||
RaceResultGUI::getInstance()->backToLobby();
|
RaceResultGUI::getInstance()->backToLobby();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#include "network/game_setup.hpp"
|
#include "network/game_setup.hpp"
|
||||||
#include "network/network_config.hpp"
|
#include "network/network_config.hpp"
|
||||||
#include "network/protocols/server_lobby.hpp"
|
#include "network/protocols/server_lobby.hpp"
|
||||||
|
#include "network/protocol_manager.hpp"
|
||||||
#include "network/rewind_manager.hpp"
|
#include "network/rewind_manager.hpp"
|
||||||
#include "network/stk_host.hpp"
|
#include "network/stk_host.hpp"
|
||||||
#include "network/stk_peer.hpp"
|
#include "network/stk_peer.hpp"
|
||||||
@ -28,7 +29,6 @@
|
|||||||
*/
|
*/
|
||||||
GameEventsProtocol::GameEventsProtocol() : Protocol(PROTOCOL_GAME_EVENTS)
|
GameEventsProtocol::GameEventsProtocol() : Protocol(PROTOCOL_GAME_EVENTS)
|
||||||
{
|
{
|
||||||
m_self_terminated = false;
|
|
||||||
m_last_finished_position = 1;
|
m_last_finished_position = 1;
|
||||||
} // GameEventsProtocol
|
} // GameEventsProtocol
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ GameEventsProtocol::~GameEventsProtocol()
|
|||||||
void GameEventsProtocol::update(int ticks)
|
void GameEventsProtocol::update(int ticks)
|
||||||
{
|
{
|
||||||
if (!World::getWorld())
|
if (!World::getWorld())
|
||||||
requestTerminate();
|
ProtocolManager::lock()->findAndTerminate(PROTOCOL_GAME_EVENTS);
|
||||||
} // update
|
} // update
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@ -20,8 +20,6 @@ public:
|
|||||||
GE_CHECK_LINE = 7
|
GE_CHECK_LINE = 7
|
||||||
}; // GameEventType
|
}; // GameEventType
|
||||||
private:
|
private:
|
||||||
bool m_self_terminated;
|
|
||||||
|
|
||||||
int m_last_finished_position;
|
int m_last_finished_position;
|
||||||
|
|
||||||
void eliminatePlayer(const NetworkString &ns);
|
void eliminatePlayer(const NetworkString &ns);
|
||||||
@ -42,15 +40,6 @@ public:
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
} // notifyEventAsynchronous
|
} // notifyEventAsynchronous
|
||||||
// ------------------------------------------------------------------------
|
|
||||||
virtual void requestTerminate() OVERRIDE
|
|
||||||
{
|
|
||||||
if (m_self_terminated)
|
|
||||||
return;
|
|
||||||
m_self_terminated = true;
|
|
||||||
Protocol::requestTerminate();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}; // class GameEventsProtocol
|
}; // class GameEventsProtocol
|
||||||
|
|
||||||
|
@ -54,10 +54,9 @@ std::shared_ptr<GameProtocol> GameProtocol::createInstance()
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
/** Constructor. Allocates the buffer for events to send to the server. */
|
/** Constructor. Allocates the buffer for events to send to the server. */
|
||||||
GameProtocol::GameProtocol()
|
GameProtocol::GameProtocol()
|
||||||
: Protocol( PROTOCOL_CONTROLLER_EVENTS)
|
: Protocol(PROTOCOL_CONTROLLER_EVENTS)
|
||||||
{
|
{
|
||||||
m_data_to_send = getNetworkString();
|
m_data_to_send = getNetworkString();
|
||||||
m_self_terminated = false;
|
|
||||||
} // GameProtocol
|
} // GameProtocol
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@ -394,5 +393,5 @@ void GameProtocol::rewind(BareNetworkString *buffer)
|
|||||||
void GameProtocol::update(int ticks)
|
void GameProtocol::update(int ticks)
|
||||||
{
|
{
|
||||||
if (!World::getWorld())
|
if (!World::getWorld())
|
||||||
requestTerminate();
|
ProtocolManager::lock()->findAndTerminate(PROTOCOL_CONTROLLER_EVENTS);
|
||||||
} // update
|
} // update
|
||||||
|
@ -59,7 +59,6 @@ private:
|
|||||||
* to reduce number of rollbacks. */
|
* to reduce number of rollbacks. */
|
||||||
std::vector<int8_t> m_adjust_time;
|
std::vector<int8_t> m_adjust_time;
|
||||||
|
|
||||||
bool m_self_terminated;
|
|
||||||
// Dummy data structure to save all kart actions.
|
// Dummy data structure to save all kart actions.
|
||||||
struct Action
|
struct Action
|
||||||
{
|
{
|
||||||
@ -140,14 +139,7 @@ public:
|
|||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
std::unique_lock<std::mutex> acquireWorldDeletingMutex() const
|
std::unique_lock<std::mutex> acquireWorldDeletingMutex() const
|
||||||
{ return std::unique_lock<std::mutex>(m_world_deleting_mutex); }
|
{ return std::unique_lock<std::mutex>(m_world_deleting_mutex); }
|
||||||
// ------------------------------------------------------------------------
|
|
||||||
virtual void requestTerminate() OVERRIDE
|
|
||||||
{
|
|
||||||
if (m_self_terminated)
|
|
||||||
return;
|
|
||||||
m_self_terminated = true;
|
|
||||||
Protocol::requestTerminate();
|
|
||||||
}
|
|
||||||
}; // class GameProtocol
|
}; // class GameProtocol
|
||||||
|
|
||||||
#endif // GAME_PROTOCOL_HPP
|
#endif // GAME_PROTOCOL_HPP
|
||||||
|
Loading…
x
Reference in New Issue
Block a user