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

Commit d1d114e

Browse files
authored
UTY-1067: Add enum to test schema (#624)
1 parent 2211cdc commit d1d114e

24 files changed

+1095
-31
lines changed

test-project/Assets/.Schema/improbable/gdk/tests/exhaustive_test.schema

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ package improbable.gdk.tests;
22

33
type SomeType {}
44

5-
// Non-Blittable Components.
5+
enum SomeEnum {
6+
FIRST_VALUE = 0;
7+
SECOND_VALUE = 1;
8+
}
69

710
component ExhaustiveSingular {
811
id = 197715;
@@ -23,6 +26,7 @@ component ExhaustiveSingular {
2326
sfixed64 field15 = 15;
2427
EntityId field16 = 16;
2528
SomeType field17 = 17;
29+
SomeEnum field18 = 18;
2630
}
2731

2832
component ExhaustiveOptional {
@@ -44,6 +48,7 @@ component ExhaustiveOptional {
4448
option<sfixed64> field15 = 15;
4549
option<EntityId> field16 = 16;
4650
option<SomeType> field17 = 17;
51+
option<SomeEnum> field18 = 18;
4752
}
4853

4954
component ExhaustiveRepeated {
@@ -65,6 +70,7 @@ component ExhaustiveRepeated {
6570
list<sfixed64> field15 = 15;
6671
list<EntityId> field16 = 16;
6772
list<SomeType> field17 = 17;
73+
list<SomeEnum> field18 = 18;
6874
}
6975

7076
component ExhaustiveMapValue {
@@ -86,6 +92,7 @@ component ExhaustiveMapValue {
8692
map<string, sfixed64> field15 = 15;
8793
map<string, EntityId> field16 = 16;
8894
map<string, SomeType> field17 = 17;
95+
map<string, SomeEnum> field18 = 18;
8996
}
9097

9198
component ExhaustiveMapKey {
@@ -107,6 +114,7 @@ component ExhaustiveMapKey {
107114
map<sfixed64, string> field15 = 15;
108115
map<EntityId, string> field16 = 16;
109116
map<SomeType, string> field17 = 17;
117+
map<SomeEnum, string> field18 = 18;
110118
}
111119

112120
// Blittable subset
@@ -127,4 +135,5 @@ component ExhaustiveBlittableSingular {
127135
sfixed64 field15 = 15;
128136
EntityId field16 = 16;
129137
SomeType field17 = 17;
138+
SomeEnum field18 = 18;
130139
}

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

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ public struct Component : IComponentData, ISpatialComponentData, ISnapshottable<
2222
// Each byte tracks 8 component properties.
2323
private byte dirtyBits0;
2424
private byte dirtyBits1;
25+
private byte dirtyBits2;
2526

2627
public bool IsDataDirty()
2728
{
2829
var isDataDirty = false;
2930
isDataDirty |= (dirtyBits0 != 0x0);
3031
isDataDirty |= (dirtyBits1 != 0x0);
32+
isDataDirty |= (dirtyBits2 != 0x0);
3133
return isDataDirty;
3234
}
3335

@@ -45,9 +47,9 @@ component MyComponent
4547
*/
4648
public bool IsDataDirty(int propertyIndex)
4749
{
48-
if (propertyIndex < 0 || propertyIndex >= 15)
50+
if (propertyIndex < 0 || propertyIndex >= 16)
4951
{
50-
throw new ArgumentException("\"propertyIndex\" argument out of range. Valid range is [0, 14]. " +
52+
throw new ArgumentException("\"propertyIndex\" argument out of range. Valid range is [0, 15]. " +
5153
"Unless you are using custom component replication code, this is most likely caused by a code generation bug. " +
5254
"Please contact SpatialOS support if you encounter this issue.");
5355
}
@@ -60,6 +62,8 @@ public bool IsDataDirty(int propertyIndex)
6062
return (dirtyBits0 & (0x1 << propertyIndex % 8)) != 0x0;
6163
case 1:
6264
return (dirtyBits1 & (0x1 << propertyIndex % 8)) != 0x0;
65+
case 2:
66+
return (dirtyBits2 & (0x1 << propertyIndex % 8)) != 0x0;
6367
}
6468

6569
return false;
@@ -69,9 +73,9 @@ public bool IsDataDirty(int propertyIndex)
6973
// This method throws an InvalidOperationException in case your component doesn't contain properties.
7074
public void MarkDataDirty(int propertyIndex)
7175
{
72-
if (propertyIndex < 0 || propertyIndex >= 15)
76+
if (propertyIndex < 0 || propertyIndex >= 16)
7377
{
74-
throw new ArgumentException("\"propertyIndex\" argument out of range. Valid range is [0, 14]. " +
78+
throw new ArgumentException("\"propertyIndex\" argument out of range. Valid range is [0, 15]. " +
7579
"Unless you are using custom component replication code, this is most likely caused by a code generation bug. " +
7680
"Please contact SpatialOS support if you encounter this issue.");
7781
}
@@ -86,13 +90,17 @@ public void MarkDataDirty(int propertyIndex)
8690
case 1:
8791
dirtyBits1 |= (byte) (0x1 << propertyIndex % 8);
8892
break;
93+
case 2:
94+
dirtyBits2 |= (byte) (0x1 << propertyIndex % 8);
95+
break;
8996
}
9097
}
9198

9299
public void MarkDataClean()
93100
{
94101
dirtyBits0 = 0x0;
95102
dirtyBits1 = 0x0;
103+
dirtyBits2 = 0x0;
96104
}
97105

98106
public Snapshot ToComponentSnapshot(global::Unity.Entities.World world)
@@ -287,6 +295,18 @@ public long Field15
287295
}
288296
}
289297

298+
private global::Improbable.Gdk.Tests.SomeEnum field18;
299+
300+
public global::Improbable.Gdk.Tests.SomeEnum Field18
301+
{
302+
get => field18;
303+
set
304+
{
305+
MarkDataDirty(15);
306+
this.field18 = value;
307+
}
308+
}
309+
290310
public static global::Improbable.Worker.CInterop.ComponentData CreateSchemaComponentData(
291311
BlittableBool field1,
292312
float field2,
@@ -302,7 +322,8 @@ public long Field15
302322
int field14,
303323
long field15,
304324
global::Improbable.Gdk.Core.EntityId field16,
305-
global::Improbable.Gdk.Tests.SomeType field17
325+
global::Improbable.Gdk.Tests.SomeType field17,
326+
global::Improbable.Gdk.Tests.SomeEnum field18
306327
)
307328
{
308329
var schemaComponentData = new global::Improbable.Worker.CInterop.SchemaComponentData(197720);
@@ -352,6 +373,9 @@ public long Field15
352373
{
353374
global::Improbable.Gdk.Tests.SomeType.Serialization.Serialize(field17, obj.AddObject(17));
354375
}
376+
{
377+
obj.AddEnum(18, (uint) field18);
378+
}
355379
return new global::Improbable.Worker.CInterop.ComponentData(schemaComponentData);
356380
}
357381
}
@@ -375,6 +399,7 @@ public struct Snapshot : ISpatialComponentSnapshot
375399
public long Field15;
376400
public global::Improbable.Gdk.Core.EntityId Field16;
377401
public global::Improbable.Gdk.Tests.SomeType Field17;
402+
public global::Improbable.Gdk.Tests.SomeEnum Field18;
378403
}
379404

380405
public static class Serialization
@@ -426,6 +451,9 @@ public static void SerializeComponent(Improbable.Gdk.Tests.ExhaustiveBlittableSi
426451
{
427452
global::Improbable.Gdk.Tests.SomeType.Serialization.Serialize(component.Field17, obj.AddObject(17));
428453
}
454+
{
455+
obj.AddEnum(18, (uint) component.Field18);
456+
}
429457
}
430458

431459
public static void SerializeUpdate(Improbable.Gdk.Tests.ExhaustiveBlittableSingular.Component component, global::Improbable.Worker.CInterop.SchemaComponentUpdate updateObj)
@@ -536,6 +564,13 @@ public static void SerializeUpdate(Improbable.Gdk.Tests.ExhaustiveBlittableSingu
536564
}
537565

538566
}
567+
{
568+
if (component.IsDataDirty(15))
569+
{
570+
obj.AddEnum(18, (uint) component.Field18);
571+
}
572+
573+
}
539574
}
540575

541576
public static Improbable.Gdk.Tests.ExhaustiveBlittableSingular.Component Deserialize(global::Improbable.Worker.CInterop.SchemaObject obj, global::Unity.Entities.World world)
@@ -587,6 +622,9 @@ public static Improbable.Gdk.Tests.ExhaustiveBlittableSingular.Component Deseria
587622
{
588623
component.Field17 = global::Improbable.Gdk.Tests.SomeType.Serialization.Deserialize(obj.GetObject(17));
589624
}
625+
{
626+
component.Field18 = (global::Improbable.Gdk.Tests.SomeEnum) obj.GetEnum(18);
627+
}
590628
return component;
591629
}
592630

@@ -714,6 +752,14 @@ public static Improbable.Gdk.Tests.ExhaustiveBlittableSingular.Update Deserializ
714752
update.Field17 = new global::Improbable.Gdk.Core.Option<global::Improbable.Gdk.Tests.SomeType>(value);
715753
}
716754

755+
}
756+
{
757+
if (obj.GetEnumCount(18) == 1)
758+
{
759+
var value = (global::Improbable.Gdk.Tests.SomeEnum) obj.GetEnum(18);
760+
update.Field18 = new global::Improbable.Gdk.Core.Option<global::Improbable.Gdk.Tests.SomeEnum>(value);
761+
}
762+
717763
}
718764
return update;
719765
}
@@ -782,6 +828,10 @@ public static Improbable.Gdk.Tests.ExhaustiveBlittableSingular.Snapshot Deserial
782828
component.Field17 = global::Improbable.Gdk.Tests.SomeType.Serialization.Deserialize(obj.GetObject(17));
783829
}
784830

831+
{
832+
component.Field18 = (global::Improbable.Gdk.Tests.SomeEnum) obj.GetEnum(18);
833+
}
834+
785835
return component;
786836
}
787837

@@ -909,6 +959,14 @@ public static void ApplyUpdate(global::Improbable.Worker.CInterop.SchemaComponen
909959
}
910960

911961
}
962+
{
963+
if (obj.GetEnumCount(18) == 1)
964+
{
965+
var value = (global::Improbable.Gdk.Tests.SomeEnum) obj.GetEnum(18);
966+
component.Field18 = value;
967+
}
968+
969+
}
912970
}
913971
}
914972

@@ -931,6 +989,7 @@ public struct Update : ISpatialComponentUpdate
931989
public Option<long> Field15;
932990
public Option<global::Improbable.Gdk.Core.EntityId> Field16;
933991
public Option<global::Improbable.Gdk.Tests.SomeType> Field17;
992+
public Option<global::Improbable.Gdk.Tests.SomeEnum> Field18;
934993
}
935994

936995
public struct ReceivedUpdates : IComponentData

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public interface Reader : IReader<Improbable.Gdk.Tests.ExhaustiveBlittableSingul
4646
event Action<long> Field15Updated;
4747
event Action<global::Improbable.Gdk.Core.EntityId> Field16Updated;
4848
event Action<global::Improbable.Gdk.Tests.SomeType> Field17Updated;
49+
event Action<global::Improbable.Gdk.Tests.SomeEnum> Field18Updated;
4950
}
5051

5152
[InjectableId(InjectableType.ReaderWriter, 197720)]
@@ -424,6 +425,30 @@ public event Action<long> Field15Updated
424425
}
425426
}
426427

428+
private readonly List<Action<global::Improbable.Gdk.Tests.SomeEnum>> field18Delegates = new List<Action<global::Improbable.Gdk.Tests.SomeEnum>>();
429+
430+
public event Action<global::Improbable.Gdk.Tests.SomeEnum> Field18Updated
431+
{
432+
add
433+
{
434+
if (!IsValid())
435+
{
436+
return;
437+
}
438+
439+
field18Delegates.Add(value);
440+
}
441+
remove
442+
{
443+
if (!IsValid())
444+
{
445+
return;
446+
}
447+
448+
field18Delegates.Remove(value);
449+
}
450+
}
451+
427452
protected override void TriggerFieldCallbacks(Improbable.Gdk.Tests.ExhaustiveBlittableSingular.Update update)
428453
{
429454
DispatchWithErrorHandling(update.Field1, field1Delegates);
@@ -441,6 +466,7 @@ protected override void TriggerFieldCallbacks(Improbable.Gdk.Tests.ExhaustiveBli
441466
DispatchWithErrorHandling(update.Field15, field15Delegates);
442467
DispatchWithErrorHandling(update.Field16, field16Delegates);
443468
DispatchWithErrorHandling(update.Field17, field17Delegates);
469+
DispatchWithErrorHandling(update.Field18, field18Delegates);
444470
}
445471

446472
protected override void ApplyUpdate(Improbable.Gdk.Tests.ExhaustiveBlittableSingular.Update update, ref Improbable.Gdk.Tests.ExhaustiveBlittableSingular.Component data)
@@ -505,6 +531,10 @@ protected override void ApplyUpdate(Improbable.Gdk.Tests.ExhaustiveBlittableSing
505531
{
506532
data.Field17 = update.Field17.Value;
507533
}
534+
if (update.Field18.HasValue)
535+
{
536+
data.Field18 = update.Field18.Value;
537+
}
508538
}
509539
}
510540
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public override void OnAddComponent(AddComponentOp op)
6666
Field15 = data.Field15,
6767
Field16 = data.Field16,
6868
Field17 = data.Field17,
69+
Field18 = data.Field18,
6970
};
7071

7172
var updates = new List<Improbable.Gdk.Tests.ExhaustiveBlittableSingular.Update>

0 commit comments

Comments
 (0)