blob: 30dafe803d04359155cdb5cd852c78f9ff802601 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
#pragma once
#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, NetCompatibilityRules rules = {}) const override;
void netLoad(DataStream& ds, NetCompatibilityRules rules) override;
bool writeNetDelta(DataStream& ds, uint64_t fromVersion, NetCompatibilityRules rules = {}) const override;
void readNetDelta(DataStream& ds, float interpolationTime = 0.0f, NetCompatibilityRules rules = {}) 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;
};
}
|