Use quicker ways to stop ingame protocol after finishing game

This commit is contained in:
Benau 2019-07-01 14:20:24 +08:00
parent 3573f64ae1
commit 7c4c7b6f63
5 changed files with 10 additions and 32 deletions

View File

@ -44,6 +44,7 @@
#include "network/protocols/connect_to_server.hpp"
#include "network/protocols/game_protocol.hpp"
#include "network/protocols/game_events_protocol.hpp"
#include "network/protocol_manager.hpp"
#include "network/race_event_manager.hpp"
#include "network/server.hpp"
#include "network/server_config.hpp"
@ -1075,8 +1076,8 @@ void ClientLobby::raceFinished(Event* event)
// stop race protocols
RaceEventManager::getInstance()->stop();
RaceEventManager::getInstance()->getProtocol()->requestTerminate();
GameProtocol::lock()->requestTerminate();
ProtocolManager::lock()->findAndTerminate(PROTOCOL_GAME_EVENTS);
ProtocolManager::lock()->findAndTerminate(PROTOCOL_CONTROLLER_EVENTS);
m_state.store(RACE_FINISHED);
} // raceFinished
@ -1098,16 +1099,13 @@ void ClientLobby::backToLobby(Event *event)
if (RaceEventManager::getInstance())
{
RaceEventManager::getInstance()->stop();
auto gep = RaceEventManager::getInstance()->getProtocol();
// Game events protocol is main thread event only
if (gep)
gep->requestTerminate();
ProtocolManager::lock()->findAndTerminate(PROTOCOL_GAME_EVENTS);
}
auto gp = GameProtocol::lock();
if (gp)
{
auto lock = gp->acquireWorldDeletingMutex();
gp->requestTerminate();
ProtocolManager::lock()->findAndTerminate(PROTOCOL_CONTROLLER_EVENTS);
RaceResultGUI::getInstance()->backToLobby();
}
else

View File

@ -9,6 +9,7 @@
#include "network/game_setup.hpp"
#include "network/network_config.hpp"
#include "network/protocols/server_lobby.hpp"
#include "network/protocol_manager.hpp"
#include "network/rewind_manager.hpp"
#include "network/stk_host.hpp"
#include "network/stk_peer.hpp"
@ -28,7 +29,6 @@
*/
GameEventsProtocol::GameEventsProtocol() : Protocol(PROTOCOL_GAME_EVENTS)
{
m_self_terminated = false;
m_last_finished_position = 1;
} // GameEventsProtocol
@ -41,7 +41,7 @@ GameEventsProtocol::~GameEventsProtocol()
void GameEventsProtocol::update(int ticks)
{
if (!World::getWorld())
requestTerminate();
ProtocolManager::lock()->findAndTerminate(PROTOCOL_GAME_EVENTS);
} // update
// ----------------------------------------------------------------------------

View File

@ -20,8 +20,6 @@ public:
GE_CHECK_LINE = 7
}; // GameEventType
private:
bool m_self_terminated;
int m_last_finished_position;
void eliminatePlayer(const NetworkString &ns);
@ -42,15 +40,6 @@ public:
{
return false;
} // notifyEventAsynchronous
// ------------------------------------------------------------------------
virtual void requestTerminate() OVERRIDE
{
if (m_self_terminated)
return;
m_self_terminated = true;
Protocol::requestTerminate();
}
}; // class GameEventsProtocol

View File

@ -54,10 +54,9 @@ std::shared_ptr<GameProtocol> GameProtocol::createInstance()
//-----------------------------------------------------------------------------
/** Constructor. Allocates the buffer for events to send to the server. */
GameProtocol::GameProtocol()
: Protocol( PROTOCOL_CONTROLLER_EVENTS)
: Protocol(PROTOCOL_CONTROLLER_EVENTS)
{
m_data_to_send = getNetworkString();
m_self_terminated = false;
} // GameProtocol
//-----------------------------------------------------------------------------
@ -394,5 +393,5 @@ void GameProtocol::rewind(BareNetworkString *buffer)
void GameProtocol::update(int ticks)
{
if (!World::getWorld())
requestTerminate();
ProtocolManager::lock()->findAndTerminate(PROTOCOL_CONTROLLER_EVENTS);
} // update

View File

@ -59,7 +59,6 @@ private:
* to reduce number of rollbacks. */
std::vector<int8_t> m_adjust_time;
bool m_self_terminated;
// Dummy data structure to save all kart actions.
struct Action
{
@ -140,14 +139,7 @@ public:
// ------------------------------------------------------------------------
std::unique_lock<std::mutex> acquireWorldDeletingMutex() const
{ 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
#endif // GAME_PROTOCOL_HPP