diff options
author | Kae <80987908+Novaenia@users.noreply.github.com> | 2023-06-20 14:33:09 +1000 |
---|---|---|
committer | Kae <80987908+Novaenia@users.noreply.github.com> | 2023-06-20 14:33:09 +1000 |
commit | 6352e8e3196f78388b6c771073f9e03eaa612673 (patch) | |
tree | e23772f79a7fbc41bc9108951e9e136857484bf4 /source/core/StarNetElementSyncGroup.hpp | |
parent | 6741a057e5639280d85d0f88ba26f000baa58f61 (diff) |
everything everywhere
all at once
Diffstat (limited to 'source/core/StarNetElementSyncGroup.hpp')
-rw-r--r-- | source/core/StarNetElementSyncGroup.hpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/source/core/StarNetElementSyncGroup.hpp b/source/core/StarNetElementSyncGroup.hpp new file mode 100644 index 0000000..2162ebe --- /dev/null +++ b/source/core/StarNetElementSyncGroup.hpp @@ -0,0 +1,54 @@ +#ifndef STAR_NET_ELEMENT_SYNC_GROUP_HPP +#define STAR_NET_ELEMENT_SYNC_GROUP_HPP + +#include "StarNetElementGroup.hpp" + +namespace Star { + +// NetElementGroup class that works with NetElements that are not automatically +// kept up to date with working data, and users need to be notified when to +// synchronize with working data. +class NetElementSyncGroup : public NetElementGroup { +public: + void enableNetInterpolation(float extrapolationHint = 0.0f) override; + void disableNetInterpolation() override; + void tickNetInterpolation(float dt) override; + + void netStore(DataStream& ds) const override; + void netLoad(DataStream& ds) override; + + bool writeNetDelta(DataStream& ds, uint64_t fromStep) const override; + void readNetDelta(DataStream& ds, float interpolationTime = 0.0f) override; + void blankNetDelta(float interpolationTime = 0.0f) override; + +protected: + // Notifies when data needs to be pulled from NetElements, load is true if + // this is due to a netLoad call + virtual void netElementsNeedLoad(bool load); + // Notifies when data needs to be pushed to NetElements + virtual void netElementsNeedStore(); + +private: + bool m_hasRecentChanges = false; + float m_recentDeltaTime = 0.0f; + bool m_recentDeltaWasBlank = false; +}; + +// Same as a NetElementSyncGroup, except instead of protected methods, calls +// optional callback functions. +class NetElementCallbackGroup : public NetElementSyncGroup { +public: + void setNeedsLoadCallback(function<void(bool)> needsLoadCallback); + void setNeedsStoreCallback(function<void()> needsStoreCallback); + +private: + void netElementsNeedLoad(bool load) override; + void netElementsNeedStore() override; + + function<void(bool)> m_netElementsNeedLoad; + function<void()> m_netElementsNeedStore; +}; + +} + +#endif |