diff options
Diffstat (limited to 'source/core/StarNetElementGroup.hpp')
-rw-r--r-- | source/core/StarNetElementGroup.hpp | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/source/core/StarNetElementGroup.hpp b/source/core/StarNetElementGroup.hpp new file mode 100644 index 0000000..d583818 --- /dev/null +++ b/source/core/StarNetElementGroup.hpp @@ -0,0 +1,66 @@ +#ifndef STAR_NET_ELEMENT_GROUP_HPP +#define STAR_NET_ELEMENT_GROUP_HPP + +#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; +} + +} + +#endif |