osb/source/core/StarNetElementGroup.hpp

64 lines
1.9 KiB
C++
Raw Permalink Normal View History

#pragma once
2023-06-20 04:33:09 +00:00
#include "StarSet.hpp"
#include "StarNetElement.hpp"
#include "StarDataStreamDevices.hpp"
namespace Star {
// A static group of NetElements that itself is a NetElement and serializes
// changes based on the order in which elements are added. All participants
// must externally add elements of the correct type in the correct order.
class NetElementGroup : public NetElement {
public:
NetElementGroup() = default;
NetElementGroup(NetElementGroup const&) = delete;
NetElementGroup& operator=(NetElementGroup const&) = delete;
// Add an element to the group.
void addNetElement(NetElement* element, bool propagateInterpolation = true);
// Removes all previously added elements
void clearNetElements();
void initNetVersion(NetElementVersion const* version = nullptr) override;
void netStore(DataStream& ds) const override;
void netLoad(DataStream& ds) override;
void enableNetInterpolation(float extrapolationHint = 0.0f) override;
void disableNetInterpolation() override;
void tickNetInterpolation(float dt) override;
bool writeNetDelta(DataStream& ds, uint64_t fromVersion) const override;
void readNetDelta(DataStream& ds, float interpolationTime = 0.0f) override;
void blankNetDelta(float interpolationTime) override;
NetElementVersion const* netVersion() const;
bool netInterpolationEnabled() const;
float netExtrapolationHint() const;
private:
List<pair<NetElement*, bool>> m_elements;
NetElementVersion const* m_version = nullptr;
bool m_interpolationEnabled = false;
float m_extrapolationHint = 0.0f;
mutable DataStreamBuffer m_buffer;
};
inline NetElementVersion const* NetElementGroup::netVersion() const {
return m_version;
}
inline bool NetElementGroup::netInterpolationEnabled() const {
return m_interpolationEnabled;
}
inline float NetElementGroup::netExtrapolationHint() const {
return m_extrapolationHint;
}
}