Allow game protocols self-terminated if world is gone
This commit is contained in:
parent
0ce185e42c
commit
e344a94946
@ -123,8 +123,8 @@ public:
|
|||||||
void sendMessageToPeersInServer(NetworkString *message,
|
void sendMessageToPeersInServer(NetworkString *message,
|
||||||
bool reliable = true);
|
bool reliable = true);
|
||||||
void sendToServer(NetworkString *message, bool reliable = true);
|
void sendToServer(NetworkString *message, bool reliable = true);
|
||||||
void requestStart();
|
virtual void requestStart();
|
||||||
void requestTerminate();
|
virtual void requestTerminate();
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
/** \brief Notify a protocol matching the Event type of that event.
|
/** \brief Notify a protocol matching the Event type of that event.
|
||||||
* \param event : Pointer to the event.
|
* \param event : Pointer to the event.
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
*/
|
*/
|
||||||
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
|
||||||
|
|
||||||
@ -36,6 +37,13 @@ GameEventsProtocol::~GameEventsProtocol()
|
|||||||
{
|
{
|
||||||
} // ~GameEventsProtocol
|
} // ~GameEventsProtocol
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
void GameEventsProtocol::update(int ticks)
|
||||||
|
{
|
||||||
|
if (!World::getWorld())
|
||||||
|
requestTerminate();
|
||||||
|
} // update
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
bool GameEventsProtocol::notifyEvent(Event* event)
|
bool GameEventsProtocol::notifyEvent(Event* event)
|
||||||
{
|
{
|
||||||
|
@ -20,6 +20,8 @@ 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);
|
||||||
@ -33,13 +35,21 @@ public:
|
|||||||
void kartFinishedRace(const NetworkString &ns);
|
void kartFinishedRace(const NetworkString &ns);
|
||||||
void sendStartupBoost(uint8_t kart_id);
|
void sendStartupBoost(uint8_t kart_id);
|
||||||
virtual void setup() OVERRIDE {}
|
virtual void setup() OVERRIDE {}
|
||||||
virtual void update(int ticks) OVERRIDE {}
|
virtual void update(int ticks) OVERRIDE;
|
||||||
virtual void asynchronousUpdate() OVERRIDE {}
|
virtual void asynchronousUpdate() OVERRIDE {}
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
virtual bool notifyEventAsynchronous(Event* event) OVERRIDE
|
virtual bool notifyEventAsynchronous(Event* event) OVERRIDE
|
||||||
{
|
{
|
||||||
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
|
||||||
|
@ -57,7 +57,7 @@ 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
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@ -389,3 +389,10 @@ void GameProtocol::rewind(BareNetworkString *buffer)
|
|||||||
std::get<3>(a));
|
std::get<3>(a));
|
||||||
}
|
}
|
||||||
} // rewind
|
} // rewind
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
void GameProtocol::update(int ticks)
|
||||||
|
{
|
||||||
|
if (!World::getWorld())
|
||||||
|
requestTerminate();
|
||||||
|
} // update
|
||||||
|
@ -59,6 +59,7 @@ 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
|
||||||
{
|
{
|
||||||
@ -105,7 +106,7 @@ public:
|
|||||||
virtual ~GameProtocol();
|
virtual ~GameProtocol();
|
||||||
|
|
||||||
virtual bool notifyEventAsynchronous(Event* event) OVERRIDE;
|
virtual bool notifyEventAsynchronous(Event* event) OVERRIDE;
|
||||||
virtual void update(int ticks) OVERRIDE {}
|
virtual void update(int ticks) OVERRIDE;
|
||||||
void sendActions();
|
void sendActions();
|
||||||
void controllerAction(int kart_id, PlayerAction action,
|
void controllerAction(int kart_id, PlayerAction action,
|
||||||
int value, int val_l, int val_r);
|
int value, int val_l, int val_r);
|
||||||
@ -139,7 +140,14 @@ 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…
Reference in New Issue
Block a user