forked from tiltedphoques/TiltedEvolution
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDifferential.h
44 lines (34 loc) · 1.23 KB
/
Differential.h
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
#pragma once
template <class T> struct Differential
{
[[nodiscard]] static Differential Prepare(const T& aPreviousValue) noexcept;
[[nodiscard]] static Differential Make(const T& aPreviousValue, const T& aNextValue) noexcept;
void Serialize(TiltedPhoques::Buffer::Writer& aWriter) noexcept;
void Deserialize(TiltedPhoques::Buffer::Reader& aReader) noexcept;
private:
Differential() = default;
T m_previousValue{};
std::optional<T> m_nextValue{};
};
template <class T> Differential<T> Differential<T>::Prepare(const T& aPreviousValue) noexcept
{
Differential<T> diff;
diff.m_previousValue = aPreviousValue;
return diff;
}
template <class T> Differential<T> Differential<T>::Make(const T& aPreviousValue, const T& aNextValue) noexcept
{
Differential<T> diff;
diff.m_previousValue = aPreviousValue;
diff.m_nextValue = aNextValue;
return diff;
}
template <class T> void Differential<T>::Serialize(TiltedPhoques::Buffer::Writer& aWriter) noexcept
{
m_nextValue.GenerateDifferential(m_previousValue, aWriter);
}
template <class T> void Differential<T>::Deserialize(TiltedPhoques::Buffer::Reader& aReader) noexcept
{
m_nextValue = m_previousValue;
m_nextValue.ApplyDifferential(aReader);
}