RoboidControl-cpp/NetworkSync.h
2024-12-17 12:09:30 +01:00

68 lines
2.0 KiB
C++

#pragma once
#include "ControlCore/Participant.h"
#include "Perception.h"
#include "Roboid.h"
#include "Types.h"
namespace Passer {
namespace RoboidControl {
/// @brief Interface for synchronizaing state between clients across a network
class NetworkSync : public Participant {
public:
NetworkSync() {};
NetworkSync(Roboid *roboid);
unsigned char networkId = 0;
/// @brief Retreive and send the roboid state
/// @param roboid The roboid for which the state is updated
virtual void NetworkUpdate(Roboid *roboid) = 0;
void SendThingInfo(Thing *thing, bool recurse = false);
void SendThing(Thing *thing);
void SendName(Thing *roboid);
void SendModel(Thing *thing);
void SendCustom(Thing *thing);
/// @brief Inform that the given object is no longer being tracked
/// @param obj
void SendDestroy(Thing *thing);
typedef void (*Buffer)(UInt8 *buffer, UInt16 bufferSize);
void ReceiveMessage(Roboid *roboid, unsigned char bytecount);
void PublishState(Roboid *roboid);
void PublishPerception(Roboid *roboid);
void PublishTrackedObjects(Roboid *roboid, InterestingThing **objects);
virtual void SendPosition(Spherical16 worldPosition) {};
virtual void SendPose(Spherical16 worldPosition,
SwingTwist16 worldOrientation) {};
void SendPose(Thing *thing, bool force = 0, bool recurse = true);
virtual void SendText(const char *s);
void SendInt(const int x);
virtual void Download(const char *url) {};
protected:
Roboid *roboid;
virtual void ProcessNetworkIdMsg(Passer::Control::NetworkIdMsg msg) override;
virtual void ProcessInvestigateMsg(InvestigateMsg msg) override;
virtual void ProcessThingMsg(ThingMsg msg) override;
virtual void ProcessPoseMsg(PoseMsg msg) override;
virtual void ProcessCustomMsg(CustomMsg msg) override;
void ReceiveNetworkId();
void ReceiveCustom(unsigned char packetSize);
void PublishTrackedObject(Roboid *roboid, InterestingThing *object);
void PublishClient();
};
} // namespace RoboidControl
} // namespace Passer