Allow game protocol to have 2 process instances

This commit is contained in:
Benau
2020-02-28 09:43:13 +08:00
parent 6a635e1a56
commit ca0749cf6b
2 changed files with 9 additions and 6 deletions

View File

@@ -40,7 +40,7 @@
#include "main_loop.hpp"
// ============================================================================
std::weak_ptr<GameProtocol> GameProtocol::m_game_protocol;
std::weak_ptr<GameProtocol> GameProtocol::m_game_protocol[PT_COUNT];
// ============================================================================
std::shared_ptr<GameProtocol> GameProtocol::createInstance()
{
@@ -50,7 +50,8 @@ std::shared_ptr<GameProtocol> GameProtocol::createInstance()
return NULL;
}
auto gm = std::make_shared<GameProtocol>();
m_game_protocol = gm;
ProcessType pt = STKProcess::getType();
m_game_protocol[pt] = gm;
return gm;
} // createInstance

View File

@@ -24,7 +24,7 @@
#include "input/input.hpp" // for PlayerAction
#include "utils/cpp2011.hpp"
#include "utils/singleton.hpp"
#include "utils/stk_process.hpp"
#include <cstdlib>
#include <mutex>
@@ -78,7 +78,7 @@ private:
void handleState(Event *event);
void handleAdjustTime(Event *event);
void handleItemEventConfirmation(Event *event);
static std::weak_ptr<GameProtocol> m_game_protocol;
static std::weak_ptr<GameProtocol> m_game_protocol[PT_COUNT];
NetworkItemManager* m_network_item_manager;
// Maximum value of values are only 32768
std::tuple<uint8_t, uint16_t, uint16_t, uint16_t>
@@ -128,12 +128,14 @@ public:
// ------------------------------------------------------------------------
static bool emptyInstance()
{
return m_game_protocol.expired();
ProcessType pt = STKProcess::getType();
return m_game_protocol[pt].expired();
} // emptyInstance
// ------------------------------------------------------------------------
static std::shared_ptr<GameProtocol> lock()
{
return m_game_protocol.lock();
ProcessType pt = STKProcess::getType();
return m_game_protocol[pt].lock();
} // lock
// ------------------------------------------------------------------------
/** Returns the NetworkString in which a state was saved. */