Skip to content
This repository was archived by the owner on Jan 18, 2022. It is now read-only.

Commit 758c128

Browse files
authored
Add ISnapshottable interface to generated components (#617)
* add the interface interface changes * add implementation impl changes * add generated code generated code * add changelog entry * adjustments to templates * more generated code
1 parent aae388d commit 758c128

File tree

17 files changed

+1915
-961
lines changed

17 files changed

+1915
-961
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- Added a reference to Blank Starter Project in the README.
99
- Added Frames Per Second (FPS) and Unity heap usage as metrics sent by `MetricSendSystem.cs`.
1010
- Added a warning message to the top of schema files copied into the `from_gdk_packages` directory.
11+
- Added an `ISnapshottable<T>` interface to all generated components. This allows you to convert a component to a snapshot.
1112

1213
### Changed
1314

test-project/Assets/Generated/Source/improbable/gdk/tests/ExhaustiveBlittableSingular.cs

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public partial class ExhaustiveBlittableSingular
1414
{
1515
public const uint ComponentId = 197720;
1616

17-
public struct Component : IComponentData, ISpatialComponentData
17+
public struct Component : IComponentData, ISpatialComponentData, ISnapshottable<Snapshot>
1818
{
1919
public uint ComponentId => 197720;
2020

@@ -95,6 +95,18 @@ public void MarkDataClean()
9595
dirtyBits1 = 0x0;
9696
}
9797

98+
public Snapshot ToComponentSnapshot(global::Unity.Entities.World world)
99+
{
100+
var componentDataSchema = new ComponentData(new SchemaComponentData(197720));
101+
Serialization.SerializeComponent(this, componentDataSchema.SchemaData.Value.GetFields(), world);
102+
var snapshot = Serialization.DeserializeSnapshot(componentDataSchema.SchemaData.Value.GetFields(), world);
103+
104+
componentDataSchema.SchemaData?.Dispose();
105+
componentDataSchema.SchemaData = null;
106+
107+
return snapshot;
108+
}
109+
98110
private BlittableBool field1;
99111

100112
public BlittableBool Field1
@@ -367,6 +379,55 @@ public struct Snapshot : ISpatialComponentSnapshot
367379

368380
public static class Serialization
369381
{
382+
public static void SerializeComponent(Improbable.Gdk.Tests.ExhaustiveBlittableSingular.Component component, global::Improbable.Worker.Core.SchemaObject obj, global::Unity.Entities.World world)
383+
{
384+
{
385+
obj.AddBool(1, component.Field1);
386+
}
387+
{
388+
obj.AddFloat(2, component.Field2);
389+
}
390+
{
391+
obj.AddInt32(4, component.Field4);
392+
}
393+
{
394+
obj.AddInt64(5, component.Field5);
395+
}
396+
{
397+
obj.AddDouble(6, component.Field6);
398+
}
399+
{
400+
obj.AddUint32(8, component.Field8);
401+
}
402+
{
403+
obj.AddUint64(9, component.Field9);
404+
}
405+
{
406+
obj.AddSint32(10, component.Field10);
407+
}
408+
{
409+
obj.AddSint64(11, component.Field11);
410+
}
411+
{
412+
obj.AddFixed32(12, component.Field12);
413+
}
414+
{
415+
obj.AddFixed64(13, component.Field13);
416+
}
417+
{
418+
obj.AddSfixed32(14, component.Field14);
419+
}
420+
{
421+
obj.AddSfixed64(15, component.Field15);
422+
}
423+
{
424+
obj.AddEntityId(16, component.Field16);
425+
}
426+
{
427+
global::Improbable.Gdk.Tests.SomeType.Serialization.Serialize(component.Field17, obj.AddObject(17));
428+
}
429+
}
430+
370431
public static void SerializeUpdate(Improbable.Gdk.Tests.ExhaustiveBlittableSingular.Component component, global::Improbable.Worker.Core.SchemaComponentUpdate updateObj)
371432
{
372433
var obj = updateObj.GetFields();

0 commit comments

Comments
 (0)