refactor: Heavy refactoring of SPIT

This commit is contained in:
2025-11-11 01:01:10 +01:00
parent a18ddf2cb1
commit 3afaf3848f
26 changed files with 2166 additions and 2329 deletions
+122
View File
@@ -0,0 +1,122 @@
#pragma once
#include "spit_type.hpp"
#include "spit_message.hpp"
#include "spit_repo.hpp"
using namespace std;
namespace spit {
class SObjectListener;
class SObject {
public:
template <typename T>
struct Property {
friend SObject;
Property(bool &confirmed)
: rConfirmed(confirmed) {
}
bool set(const T& val) {
if (mValue == val)
return false;
mValue = val;
rConfirmed = false;
return true;
}
T get () const {
return mValue;
}
private:
bool & rConfirmed;
T mValue{};
};
Property<string> Name{mConfirmed};
Property<string> Remark{mConfirmed};
Property<string> ServerParams{mConfirmed};
Property<string> SPITTypeID{mConfirmed};
// Returns if the SPITType triggers an action on the Server or on the client.
// @return false = the action is triggered on the client The client waits for the server to play objects of this SPITType
// true = the action is triggered on the server. The server waits for the client to play objects of this SPITType.
Property<bool> ServerRemote{mConfirmed};
Property<bool> Fixed{mConfirmed};
Property<uint64_t> FrameStart{mConfirmed};
Property<uint64_t> FrameLength{mConfirmed};
Property<uint64_t> FrameFadeInLength{mConfirmed};
Property<uint64_t> FrameFadeOutLength{mConfirmed};
Property<char> ValueUse{mConfirmed};
Property<int> ValueFactor{mConfirmed};
Property<int> Track{mConfirmed};
Property<uint64_t> Delay{mConfirmed};
Property<uint64_t> Duration{mConfirmed};
static void clearUnconfirmedObjects(SpitRepo<SObject> &repo);
static void setConfirmedFalse(SpitRepo<SObject> &repo);
static void eventProjectClosed(SpitRepo<SObject> &repo, SpitRepo<SObject> &remoteRepo);
SObject(string iD) {
mID = iD;
}
private:
string mID;
bool mConfirmed{};
bool mCreatedByClient{};
bool mActionAssigned{};
bool mActionAssignedType{}; // Virtual construct
char mValueUse{0x01};
int mValueFactor{1000000}; // Values are given in ppm -> 1000000 = 1/1;
bool mPlayPrePosition;
uint64_t mPlayTimeInsideFrames;
int mPlayValue;
char mPlayValueFlag;
public:
string getID() const { return mID; }
/**
* This is used by the server and client to tell if the other side has registered the changes.
* @return true = other side has registered the changes.
*/
bool getConfirmed() const { return mConfirmed; }
bool getCreatedByClient() const { return mCreatedByClient; }
/**
* This is a virtual construct - ActionAssignedType is not implemented in the SPITProtocol.
* This is used when an action is associated with a SPITType.
* Then this action is done for every SObject with the SPITType.
* @return true = an action is assigned for the SPITType.
*/
bool getActionAssignedType() const { return mActionAssignedType; }
/** Returns if this SObject has an associated action or not.
* @return true = the user has asscociated an action with this SObject or
* the user has asscociated an action with the SPITType of this SObject
*/
bool getActionAssigned() const { return mActionAssigned || mActionAssignedType; }
bool getProjectIndepended(SpitRepo<SType> &repo, SpitRepo<SType> &remoteRepo) const {
SType *ptrSPITType;
if (ServerRemote.get() == false) {
ptrSPITType = repo.getEntry(SPITTypeID.get());
if (ptrSPITType == nullptr)
return true;
return ptrSPITType->ProjectIndepended.get();
} else {
ptrSPITType = remoteRepo.getEntry(SPITTypeID.get());
if (ptrSPITType == nullptr)
return true;
return ptrSPITType->ProjectIndepended.get();
}
};
bool setConfirmed(bool confirmed);
void setCreatedByClient(bool createdByClient) { mCreatedByClient = createdByClient; }
bool setActionAssignedType(bool actionAssigned);
bool setActionAssigned(bool actionAssigned);
bool setMessageOP(Message::ReportObject *message);
void fillMessageOP(Message::ReportObject &message);
void fillMessageOP(Message::RemoveObject &message);
};
}