Further refactoring for better safety and maintainability
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
#include "SPIT_Message.h"
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <memory>
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -25,13 +26,13 @@ class SPITObjectListener;
|
||||
|
||||
class SPITObject {
|
||||
private:
|
||||
static unordered_map<string, SPITObject *> sSpitObjects;
|
||||
static unordered_map<string, SPITObject *> sSpitObjectsRemote;
|
||||
static unordered_map<string, unique_ptr<SPITObject>> sSpitObjects;
|
||||
static unordered_map<string, unique_ptr<SPITObject>> sSpitObjectsRemote;
|
||||
|
||||
public:
|
||||
static SPITObject *getSPITObject(const string &id);
|
||||
static const SPITObject &getSPITObjectRef(const string &id);
|
||||
static void addSPITObject(SPITObject &spitObject);
|
||||
static void addSPITObject(unique_ptr<SPITObject> spitObject);
|
||||
static bool removeSPITObject(const SPITObject &spitObject);
|
||||
static bool removeSPITObject(const string & spitObjectID);
|
||||
static int getSPITObjectCount() {
|
||||
@@ -39,13 +40,13 @@ class SPITObject {
|
||||
}
|
||||
static SPITObject *getSPITObject(int p_Index);
|
||||
static const SPITObject &getSPITObjectRef(int p_Index);
|
||||
static void clearSPITObjects();
|
||||
static void clearSPITObjects() { sSpitObjects.clear(); }
|
||||
static void clearUnconfirmedSPITObjects();
|
||||
static void setConfirmedFalse();
|
||||
|
||||
static SPITObject *getSPITObjectRemote(const string &id);
|
||||
static const SPITObject &getSPITObjectRemoteRef(const string &id);
|
||||
static void addSPITObjectRemote(SPITObject &spitObject);
|
||||
static void addSPITObjectRemote(unique_ptr<SPITObject> spitObject);
|
||||
static bool removeSPITObjectRemote(const SPITObject &spitObject);
|
||||
static bool removeSPITObjectRemote(const string & spitObjectID);
|
||||
static int getSPITObjectRemoteCount() {
|
||||
@@ -53,11 +54,11 @@ class SPITObject {
|
||||
}
|
||||
static SPITObject *getSPITObjectRemote(int p_Index);
|
||||
static const SPITObject &getSPITObjectRemoteRef(int p_Index);
|
||||
static void clearSPITObjectsRemote();
|
||||
static void clearSPITObjectsRemote(){ sSpitObjectsRemote.clear(); }
|
||||
|
||||
static void eventProjectClosed();
|
||||
|
||||
SPITObject();
|
||||
SPITObject(string p_ID);
|
||||
|
||||
private:
|
||||
string m_ID;
|
||||
|
||||
@@ -58,7 +58,7 @@ class SPITPlayer {
|
||||
public:
|
||||
// list the SPITPlayers
|
||||
static unordered_map<string, SPITPlayer *> s_SPITPlayers; // all actual played objects
|
||||
static SPITPlayer *getSPITPlayer(string p_PlayerID); // if a player does not exist creates a new one
|
||||
static SPITPlayer &getSPITPlayer(string p_PlayerID); // if a player does not exist creates a new one
|
||||
static void clearPlayers();
|
||||
|
||||
SPITPlayer(string p_PlayerID);
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "SPIT_Message.h"
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <memory>
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -25,32 +26,32 @@ class SPITTypeListener;
|
||||
|
||||
class SPITType {
|
||||
private:
|
||||
static unordered_map<string, SPITType *> sSpitTypes;
|
||||
static unordered_map<string, SPITType *> sSpitTypesRemote;
|
||||
static unordered_map<string, unique_ptr<SPITType>> sSpitTypes;
|
||||
static unordered_map<string, unique_ptr<SPITType>> sSpitTypesRemote;
|
||||
|
||||
public:
|
||||
static SPITType *getSPITType(const string &id);
|
||||
static const SPITType &getSPITTypeRef(const string &id);
|
||||
static void addSPITType(SPITType &spitType);
|
||||
static void addSPITType( unique_ptr<SPITType> spitType);
|
||||
static bool removeSPITType(const SPITType &spitType);
|
||||
static int getSPITTypeCount() { return sSpitTypes.size(); }
|
||||
static SPITType *getSPITType(int p_Index);
|
||||
static const SPITType &getSPITTypeRef(int p_Index);
|
||||
static void clearSPITTypes();
|
||||
static void clearSPITTypes() { sSpitTypes.clear(); }
|
||||
static void setConfirmedFalse();
|
||||
|
||||
static SPITType *getSPITTypeRemote(const string &id);
|
||||
static const SPITType &getSPITTypeRemoteRef(const string &id);
|
||||
static void addSPITTypeRemote(SPITType &spitType);
|
||||
static void addSPITTypeRemote(unique_ptr<SPITType> spitType);
|
||||
static bool removeSPITTypeRemote(const SPITType &spitType);
|
||||
static int getSPITTypeRemoteCount() { return sSpitTypesRemote.size(); }
|
||||
static SPITType *getSPITTypeRemote(int p_Index);
|
||||
static const SPITType &getSPITTypeRemoteRef(int p_Index);
|
||||
static void clearSPITTypesRemote();
|
||||
static void clearSPITTypesRemote() { sSpitTypesRemote.clear(); }
|
||||
|
||||
static void eventProjectClosed();
|
||||
|
||||
SPITType();
|
||||
SPITType(string p_ID);
|
||||
SPITType(string p_ID, string p_GroupName, string p_Name, bool p_Fixed, bool p_ProjectIndepended, long long p_DefaultDelay, long long p_DefaultDuration);
|
||||
|
||||
private:
|
||||
@@ -80,7 +81,6 @@ class SPITType {
|
||||
* true = the action is triggered on the server. The server waits for the client to play objects of this SPITType.
|
||||
*/
|
||||
bool getServerRemote() const { return m_ServerRemote; }
|
||||
|
||||
bool getProjectIndepended() const { return m_ServerProjectIndepended; }
|
||||
/**
|
||||
* This is used by the server and client to tell if the other side has registered the changes.
|
||||
|
||||
@@ -52,11 +52,8 @@ class SPIT_Client : I_SAD_Client {
|
||||
void (*onServerEvent)(ServerEvent event, const SAD_DetectedServer &p_DetectedServer){};
|
||||
void (*onConnectionStatus)(string p_ServerID, string p_ServerComputerName, string p_ServerName, int p_ServerStepTime, int p_ConnectionStatus, int p_OldConnectionStatus){};
|
||||
void (*onProjectUpdate)(ProjUpdate state, string projectId){};
|
||||
|
||||
void (*onSpitType)(ObjectEvent event, const SPITType &p_SPITType){};
|
||||
void (*onSpitTypeRemote)(ObjectEvent event, const SPITType &p_SPITType){};
|
||||
void (*onSpitObject)(ObjectEvent event, const SPITType &p_SPITType, const SPITObject &p_SPITObject){};
|
||||
void (*onSpitObjectRemote)(ObjectEvent event, const SPITType &p_SPITType, const SPITObject &p_SPITObject){};
|
||||
void (*onSpitType)(ObjectEvent event, bool isRemote, const SPITType &p_SPITType){};
|
||||
void (*onSpitObject)(ObjectEvent event, bool isRemote, const SPITType &p_SPITType, const SPITObject &p_SPITObject){};
|
||||
|
||||
void (*onPlay)(string p_PlayerID, string p_PlayerName, char p_PlayerType, bool p_PlayerIsRunning, long long p_TimeFrames){};
|
||||
void (*onPlaySpitType)(string p_PlayerID, string p_SPITTypeID, bool p_PlayerIsRunning, bool p_Started, bool p_Ended, double p_Value){};
|
||||
@@ -96,12 +93,12 @@ class SPIT_Client : I_SAD_Client {
|
||||
static constexpr char VALUEFLAG_INCREASE = 0x01;
|
||||
/**Decrease the existing value by the given value.<br>This is usefull e.g. when instead of a fader a endless wheel is used*/
|
||||
static constexpr char VALUEFLAG_DECREASE = 0x02;
|
||||
static constexpr int MAX_OVERTAKING_SPIT_MESSAGES = 10;
|
||||
|
||||
//----- SPIT_Client -----
|
||||
public:
|
||||
SPIT_Client(string name, string projName, Callbacks calls);
|
||||
virtual ~SPIT_Client();
|
||||
static int s_MAX_OVERTAKING_SPIT_MESSAGES;
|
||||
|
||||
private:
|
||||
Callbacks mCallbacks;
|
||||
@@ -120,7 +117,7 @@ class SPIT_Client : I_SAD_Client {
|
||||
|
||||
unsigned char m_MessageNumber_Send;
|
||||
int m_MessageNumber_Received;
|
||||
vector<SPIT_Message *> m_OvertakingSPIT_Messages;
|
||||
vector<unique_ptr<SPIT_Message>> m_OvertakingSPIT_Messages;
|
||||
|
||||
// Server's info filled by parseConnectAnswer
|
||||
string m_ServerID{};
|
||||
@@ -220,7 +217,7 @@ class SPIT_Client : I_SAD_Client {
|
||||
void resetMessageNumberReceived();
|
||||
void parseSPIT_Message(unique_ptr<SPIT_Message> p_SPITMessage);
|
||||
void checkParseSPIT_Message(unique_ptr<SPIT_Message> p_SPITMessage);
|
||||
void addOvertakingSPIT_Message(SPIT_Message *p_SPIT_Message);
|
||||
void addOvertakingSPIT_Message(unique_ptr<SPIT_Message> p_SPIT_Message);
|
||||
void parseConnectAnswer(SPIT_Message::ConnectAnswer *p_ConnectAnswer);
|
||||
void parseDisconnect(SPIT_Message::Disconnect *p_Disconnect);
|
||||
void parseWatchdog(SPIT_Message::Watchdog *p_Watchdog);
|
||||
|
||||
Reference in New Issue
Block a user