forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRotation2d.NetCodeSourceGenerator.additionalfile
More file actions
110 lines (106 loc) · 5.07 KB
/
Copy pathRotation2d.NetCodeSourceGenerator.additionalfile
File metadata and controls
110 lines (106 loc) · 5.07 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
#templateid: Custom.Rotation2d
#region __GHOST_IMPORTS__
#endregion
namespace Generated
{
public struct GhostSnapshotData
{
public struct Snapshot
{
#region __GHOST_FIELD__
public int __GHOST_FIELD_NAME__W;
#endregion
}
public void PredictDelta(uint tick, ref GhostSnapshotData baseline1, ref GhostSnapshotData baseline2)
{
var predictor = new GhostDeltaPredictor(tick, this.tick, baseline1.tick, baseline2.tick);
#region __GHOST_PREDICT__
snapshot.__GHOST_FIELD_NAME__W = predictor.PredictInt(snapshot.__GHOST_FIELD_NAME__W, baseline1.__GHOST_FIELD_NAME__W, baseline2.__GHOST_FIELD_NAME__W);
#endregion
}
public void Serialize(ref Snapshot snapshot, ref Snapshot baseline, ref DataStreamWriter writer, ref StreamCompressionModel compressionModel, uint changeMask)
{
#region __GHOST_WRITE__
if ((changeMask & (1 << __GHOST_MASK_INDEX__)) != 0)
{
writer.WritePackedIntDelta(snapshot.__GHOST_FIELD_NAME__W, baseline.__GHOST_FIELD_NAME__W, compressionModel);
}
#endregion
}
public void Deserialize(ref Snapshot snapshot, ref Snapshot baseline, ref DataStreamReader reader, ref StreamCompressionModel compressionModel, uint changeMask)
{
#region __GHOST_READ__
if ((changeMask & (1 << __GHOST_MASK_INDEX__)) != 0)
{
snapshot.__GHOST_FIELD_NAME__W = reader.ReadPackedIntDelta(baseline.__GHOST_FIELD_NAME__W, compressionModel);
}
else
{
snapshot.__GHOST_FIELD_NAME__W = baseline.__GHOST_FIELD_NAME__W;
}
#endregion
}
public unsafe void CopyToSnapshot(ref Snapshot snapshot, ref IComponentData component)
{
if (true)
{
#region __GHOST_COPY_TO_SNAPSHOT__
snapshot.__GHOST_FIELD_NAME__W = (int)(component.__GHOST_FIELD_REFERENCE__.value.z > 0.0f
? component.__GHOST_FIELD_REFERENCE__.value.w * __GHOST_QUANTIZE_SCALE__
: -component.__GHOST_FIELD_REFERENCE__.value.w * __GHOST_QUANTIZE_SCALE__);
#endregion
}
}
public unsafe void CopyFromSnapshot(ref GhostDeserializerState deserializerState, ref Snapshot snapshotBefore, ref Snapshot snapshotAfter, float snapshotInterpolationFactor, ref IComponentData component)
{
if (true)
{
#region __GHOST_COPY_FROM_SNAPSHOT__
var wb = snapshotBefore.__GHOST_FIELD_NAME__W * __GHOST_DEQUANTIZE_SCALE__;
component.__GHOST_FIELD_REFERENCE__ = new quaternion(new float4(0f,0f, wb>1.0f-1e-9f?0.0f:math.sqrt(1f - wb*wb), wb));
#endregion
#region __GHOST_COPY_FROM_SNAPSHOT_INTERPOLATE__
var wb = snapshotBefore.__GHOST_FIELD_NAME__W * __GHOST_DEQUANTIZE_SCALE__;
var wa = snapshotAfter.__GHOST_FIELD_NAME__W * __GHOST_DEQUANTIZE_SCALE__;
component.__GHOST_FIELD_REFERENCE__ = math.slerp(
new quaternion(new float4(0f,0f, wb>1.0f-1e-9f?0.0f:math.sqrt(1f - wb*wb), wb)),
new quaternion(new float4(0f,0f, wa>1.0f-1e-9f?0.0f:math.sqrt(1f - wa*wa), wa)),
snapshotInterpolationFactor);
#endregion
}
}
public unsafe void RestoreFromBackup(ref IComponentData component, in IComponentData backup)
{
#region __GHOST_RESTORE_FROM_BACKUP__
component.__GHOST_FIELD_REFERENCE__ = backup.__GHOST_FIELD_REFERENCE__;
#endregion
}
public void CalculateChangeMask(ref Snapshot snapshot, ref Snapshot baseline, uint changeMask)
{
#region __GHOST_CALCULATE_CHANGE_MASK_ZERO__
changeMask = (snapshot.__GHOST_FIELD_NAME__W != baseline.__GHOST_FIELD_NAME__W) ? 1u : 0;
#endregion
#region __GHOST_CALCULATE_CHANGE_MASK__
changeMask |= (snapshot.__GHOST_FIELD_NAME__W != baseline.__GHOST_FIELD_NAME__W) ? (1u<<__GHOST_MASK_INDEX__) : 0;
#endregion
}
#if UNITY_EDITOR || NETCODE_DEBUG
private static void ReportPredictionErrors(ref IComponentData component, in IComponentData backup, ref UnsafeList<float> errors, ref int errorIndex)
{
#region __GHOST_REPORT_PREDICTION_ERROR__
errors[errorIndex] = math.max(errors[errorIndex], math.distance(component.__GHOST_FIELD_REFERENCE__.value, backup.__GHOST_FIELD_REFERENCE__.value));
++errorIndex;
#endregion
}
private static int GetPredictionErrorNames(ref FixedString512Bytes names, ref int nameCount)
{
#region __GHOST_GET_PREDICTION_ERROR_NAME__
if (nameCount != 0)
names.Append(new FixedString32Bytes(","));
names.Append(new FixedString64Bytes("Value"));
++nameCount;
#endregion
}
#endif
}
}