-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTowerNetworkObject.cs
More file actions
141 lines (116 loc) · 3.97 KB
/
TowerNetworkObject.cs
File metadata and controls
141 lines (116 loc) · 3.97 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
using BeardedManStudios.Forge.Networking.Frame;
using BeardedManStudios.Forge.Networking.Unity;
using System;
using UnityEngine;
namespace BeardedManStudios.Forge.Networking.Generated
{
[GeneratedInterpol("{\"inter\":[0]")]
public partial class TowerNetworkObject : NetworkObject
{
public const int IDENTITY = 16;
private byte[] _dirtyFields = new byte[1];
#pragma warning disable 0067
public event FieldChangedEvent fieldAltered;
#pragma warning restore 0067
[ForgeGeneratedField]
private float _captureGauge;
public event FieldEvent<float> captureGaugeChanged;
public InterpolateFloat captureGaugeInterpolation = new InterpolateFloat() { LerpT = 0f, Enabled = false };
public float captureGauge
{
get { return _captureGauge; }
set
{
// Don't do anything if the value is the same
if (_captureGauge == value)
return;
// Mark the field as dirty for the network to transmit
_dirtyFields[0] |= 0x1;
_captureGauge = value;
hasDirtyFields = true;
}
}
public void SetcaptureGaugeDirty()
{
_dirtyFields[0] |= 0x1;
hasDirtyFields = true;
}
private void RunChange_captureGauge(ulong timestep)
{
if (captureGaugeChanged != null) captureGaugeChanged(_captureGauge, timestep);
if (fieldAltered != null) fieldAltered("captureGauge", _captureGauge, timestep);
}
protected override void OwnershipChanged()
{
base.OwnershipChanged();
SnapInterpolations();
}
public void SnapInterpolations()
{
captureGaugeInterpolation.current = captureGaugeInterpolation.target;
}
public override int UniqueIdentity { get { return IDENTITY; } }
protected override BMSByte WritePayload(BMSByte data)
{
UnityObjectMapper.Instance.MapBytes(data, _captureGauge);
return data;
}
protected override void ReadPayload(BMSByte payload, ulong timestep)
{
_captureGauge = UnityObjectMapper.Instance.Map<float>(payload);
captureGaugeInterpolation.current = _captureGauge;
captureGaugeInterpolation.target = _captureGauge;
RunChange_captureGauge(timestep);
}
protected override BMSByte SerializeDirtyFields()
{
dirtyFieldsData.Clear();
dirtyFieldsData.Append(_dirtyFields);
if ((0x1 & _dirtyFields[0]) != 0)
UnityObjectMapper.Instance.MapBytes(dirtyFieldsData, _captureGauge);
// Reset all the dirty fields
for (int i = 0; i < _dirtyFields.Length; i++)
_dirtyFields[i] = 0;
return dirtyFieldsData;
}
protected override void ReadDirtyFields(BMSByte data, ulong timestep)
{
if (readDirtyFlags == null)
Initialize();
Buffer.BlockCopy(data.byteArr, data.StartIndex(), readDirtyFlags, 0, readDirtyFlags.Length);
data.MoveStartIndex(readDirtyFlags.Length);
if ((0x1 & readDirtyFlags[0]) != 0)
{
if (captureGaugeInterpolation.Enabled)
{
captureGaugeInterpolation.target = UnityObjectMapper.Instance.Map<float>(data);
captureGaugeInterpolation.Timestep = timestep;
}
else
{
_captureGauge = UnityObjectMapper.Instance.Map<float>(data);
RunChange_captureGauge(timestep);
}
}
}
public override void InterpolateUpdate()
{
if (IsOwner)
return;
if (captureGaugeInterpolation.Enabled && !captureGaugeInterpolation.current.UnityNear(captureGaugeInterpolation.target, 0.0015f))
{
_captureGauge = (float)captureGaugeInterpolation.Interpolate();
//RunChange_captureGauge(captureGaugeInterpolation.Timestep);
}
}
private void Initialize()
{
if (readDirtyFlags == null)
readDirtyFlags = new byte[1];
}
public TowerNetworkObject() : base() { Initialize(); }
public TowerNetworkObject(NetWorker networker, INetworkBehavior networkBehavior = null, int createCode = 0, byte[] metadata = null) : base(networker, networkBehavior, createCode, metadata) { Initialize(); }
public TowerNetworkObject(NetWorker networker, uint serverId, FrameStream frame) : base(networker, serverId, frame) { Initialize(); }
// DO NOT TOUCH, THIS GETS GENERATED PLEASE EXTEND THIS CLASS IF YOU WISH TO HAVE CUSTOM CODE ADDITIONS
}
}