RoboidControl-cpp/NetworkSync.h
2024-04-18 17:24:41 +02:00

78 lines
3.2 KiB
C++

#pragma once
#include "NetworkPerception.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:
/// @brief Retreive and send the roboid state
/// @param roboid The roboid for which the state is updated
virtual void NetworkUpdate(Roboid *roboid) = 0;
/// @brief Inform that the given object is no longer being tracked
/// @param obj
virtual void DestroyObject(InterestingThing *obj) = 0;
virtual void NewObject(InterestingThing *obj){};
/// @brief The id of a Pose message
static const char PoseMsg = 0x10;
static const char PoseTypeMsg = 0x11;
static const char RelativePoseMsg = 0x12;
/// @brief A bit pattern for the pose, stating that this message contains a
/// position in world coordinates
static const char Pose_Position = 0x01;
/// @brief A bit pattern for the pose, stating that this message contains an
/// orientation in world coordinates
static const char Pose_Orientation = 0x02;
/// @brief A bit pattern for the pose, stating that this messsage contains a
/// linear velocity in world coordinates
static const char Pose_LinearVelocity = 0x04;
/// @brief A bit pattern for the pose, stating that this message contains an
/// angular velocity in world coordinates
static const char Pose_AngularVelocity = 0x08;
static const char DestroyMsg = 0x20;
typedef void (*SendBuffer)(UInt8 *buffer, UInt16 bufferSize);
void SendPoseMsg(SendBuffer sendBuffer, Roboid *roboid);
void SendDestroyObject(SendBuffer sendBuffer, InterestingThing *obj);
void PublishNewObject();
void PublishTrackedObjects(SendBuffer sendBuffer, InterestingThing **objects);
virtual void SendPosition(Vector3 worldPosition){};
virtual void SendPose(Vector3 worldPosition, Quaternion worldOrientation){};
protected:
NetworkPerception *networkPerception;
void PublishTrackedObject(SendBuffer sendBuffer, InterestingThing *object);
void PublishRelativeObject(SendBuffer sendBuffer, UInt8 parentId,
InterestingThing *object);
void SendSingle100(unsigned char *data, unsigned int startIndex, float value);
void SendInt32(unsigned char *data, unsigned int startIndex, Int32 value);
void SendAngle8(unsigned char *data, unsigned int startIndex,
const float value);
// void SendAngle16(unsigned char *data, unsigned int startIndex,
// const float value);
// void SendAngle32(unsigned char *data, unsigned int startIndex,
// const float value);
void SendVector3(unsigned char *data, unsigned int startIndex,
const Vector3 v);
void SendQuaternion(unsigned char *data, const int startIndex,
const Quaternion q);
void SendPolar(unsigned char *data, unsigned char *startIndex, Polar p);
void SendSpherical(unsigned char *data, int startIndex, Spherical s);
// void SendSpherical16(unsigned char *data, int startIndex, Spherical s);
// void SendSpherical32(unsigned char *data, int startIndex, Spherical s);
void SendQuat32(unsigned char *data, int startIndex, const Quaternion q);
};
} // namespace RoboidControl
} // namespace Passer