Ejemplo n.º 1
0
            public override void OnComponentUpdate(ComponentUpdateOp op)
            {
                var entity = TryGetEntityFromEntityId(op.EntityId);

                if (entityManager.HasComponent <NotAuthoritative <Improbable.Gdk.Tests.ExhaustiveRepeated.Component> >(entity))
                {
                    var data = entityManager.GetComponentData <Improbable.Gdk.Tests.ExhaustiveRepeated.Component>(entity);
                    Improbable.Gdk.Tests.ExhaustiveRepeated.Serialization.ApplyUpdate(op.Update.SchemaData.Value, ref data);
                    data.DirtyBit = false;
                    entityManager.SetComponentData(entity, data);
                }

                var update = Improbable.Gdk.Tests.ExhaustiveRepeated.Serialization.DeserializeUpdate(op.Update.SchemaData.Value);

                List <Improbable.Gdk.Tests.ExhaustiveRepeated.Update> updates;

                if (entityManager.HasComponent <Improbable.Gdk.Tests.ExhaustiveRepeated.ReceivedUpdates>(entity))
                {
                    updates = entityManager.GetComponentData <Improbable.Gdk.Tests.ExhaustiveRepeated.ReceivedUpdates>(entity).Updates;
                }
                else
                {
                    var updatesComponent = new Improbable.Gdk.Tests.ExhaustiveRepeated.ReceivedUpdates
                    {
                        handle = ReferenceTypeProviders.UpdatesProvider.Allocate(World)
                    };
                    ReferenceTypeProviders.UpdatesProvider.Set(updatesComponent.handle, new List <Improbable.Gdk.Tests.ExhaustiveRepeated.Update>());
                    updates = updatesComponent.Updates;
                    entityManager.AddComponentData(entity, updatesComponent);
                }

                updates.Add(update);
            }
            public override void OnComponentUpdate(ComponentUpdateOp op)
            {
                var entity = TryGetEntityFromEntityId(op.EntityId);

                Profiler.BeginSample("ExhaustiveRepeated");
                if (entityManager.HasComponent <NotAuthoritative <Improbable.Gdk.Tests.ExhaustiveRepeated.Component> >(entity))
                {
                    var data = entityManager.GetComponentData <Improbable.Gdk.Tests.ExhaustiveRepeated.Component>(entity);
                    Improbable.Gdk.Tests.ExhaustiveRepeated.Serialization.ApplyUpdate(op.Update.SchemaData.Value, ref data);
                    data.MarkDataClean();
                    entityManager.SetComponentData(entity, data);
                }

                var update = Improbable.Gdk.Tests.ExhaustiveRepeated.Serialization.DeserializeUpdate(op.Update.SchemaData.Value);

                List <Improbable.Gdk.Tests.ExhaustiveRepeated.Update> updates;

                if (entityManager.HasComponent <Improbable.Gdk.Tests.ExhaustiveRepeated.ReceivedUpdates>(entity))
                {
                    updates = entityManager.GetComponentData <Improbable.Gdk.Tests.ExhaustiveRepeated.ReceivedUpdates>(entity).Updates;
                }
                else
                {
                    updates = Improbable.Gdk.Tests.ExhaustiveRepeated.Update.Pool.Count > 0 ? Improbable.Gdk.Tests.ExhaustiveRepeated.Update.Pool.Pop() : new List <Improbable.Gdk.Tests.ExhaustiveRepeated.Update>();
                    var updatesComponent = new Improbable.Gdk.Tests.ExhaustiveRepeated.ReceivedUpdates
                    {
                        handle = ReferenceTypeProviders.UpdatesProvider.Allocate(World)
                    };
                    ReferenceTypeProviders.UpdatesProvider.Set(updatesComponent.handle, updates);
                    entityManager.AddComponentData(entity, updatesComponent);
                }

                updates.Add(update);

                Profiler.EndSample();
            }
            public override void OnAddComponent(AddComponentOp op)
            {
                var entity = TryGetEntityFromEntityId(op.EntityId);

                Profiler.BeginSample("ExhaustiveRepeated");
                var data = Improbable.Gdk.Tests.ExhaustiveRepeated.Serialization.Deserialize(op.Data.SchemaData.Value.GetFields(), World);

                data.DirtyBit = false;
                entityManager.AddComponentData(entity, data);
                entityManager.AddComponent(entity, ComponentType.Create <NotAuthoritative <Improbable.Gdk.Tests.ExhaustiveRepeated.Component> >());

                var update = new Improbable.Gdk.Tests.ExhaustiveRepeated.Update
                {
                    Field1  = data.Field1,
                    Field2  = data.Field2,
                    Field3  = data.Field3,
                    Field4  = data.Field4,
                    Field5  = data.Field5,
                    Field6  = data.Field6,
                    Field7  = data.Field7,
                    Field8  = data.Field8,
                    Field9  = data.Field9,
                    Field10 = data.Field10,
                    Field11 = data.Field11,
                    Field12 = data.Field12,
                    Field13 = data.Field13,
                    Field14 = data.Field14,
                    Field15 = data.Field15,
                    Field16 = data.Field16,
                    Field17 = data.Field17,
                };

                var updates = new List <Improbable.Gdk.Tests.ExhaustiveRepeated.Update>
                {
                    update
                };

                var updatesComponent = new Improbable.Gdk.Tests.ExhaustiveRepeated.ReceivedUpdates
                {
                    handle = ReferenceTypeProviders.UpdatesProvider.Allocate(World)
                };

                ReferenceTypeProviders.UpdatesProvider.Set(updatesComponent.handle, updates);
                entityManager.AddComponentData(entity, updatesComponent);

                if (entityManager.HasComponent <ComponentRemoved <Improbable.Gdk.Tests.ExhaustiveRepeated.Component> >(entity))
                {
                    entityManager.RemoveComponent <ComponentRemoved <Improbable.Gdk.Tests.ExhaustiveRepeated.Component> >(entity);
                }
                else if (!entityManager.HasComponent <ComponentAdded <Improbable.Gdk.Tests.ExhaustiveRepeated.Component> >(entity))
                {
                    entityManager.AddComponent(entity, ComponentType.Create <ComponentAdded <Improbable.Gdk.Tests.ExhaustiveRepeated.Component> >());
                }
                else
                {
                    LogDispatcher.HandleLog(LogType.Error, new LogEvent(ReceivedDuplicateComponentAdded)
                                            .WithField(LoggingUtils.LoggerName, LoggerName)
                                            .WithField(LoggingUtils.EntityId, op.EntityId.Id)
                                            .WithField("Component", "Improbable.Gdk.Tests.ExhaustiveRepeated")
                                            );
                }

                Profiler.EndSample();
            }