Example #1
0
        public static WorldDiff Clone(this WorldDiff worldDiff, Allocator label)
        {
            var clone = new WorldDiff
            {
                TypeHashes                 = new NativeArray <ulong>(worldDiff.TypeHashes, label),
                Entities                   = new NativeArray <EntityGuid>(worldDiff.Entities, label),
                EntityNames                = new NativeArray <NativeString64>(worldDiff.EntityNames, label),
                ComponentPayload           = new NativeArray <byte>(worldDiff.ComponentPayload, label),
                NewEntityCount             = worldDiff.NewEntityCount,
                DeletedEntityCount         = worldDiff.DeletedEntityCount,
                AddComponents              = new NativeArray <ComponentDiff>(worldDiff.AddComponents, label),
                RemoveComponents           = new NativeArray <ComponentDiff>(worldDiff.RemoveComponents, label),
                SetCommands                = new NativeArray <DataDiff>(worldDiff.SetCommands, label),
                EntityPatches              = new NativeArray <DiffEntityPatch>(worldDiff.EntityPatches, label),
                LinkedEntityGroupAdditions = new NativeArray <LinkedEntityGroupAddition>(worldDiff.LinkedEntityGroupAdditions, label),
                LinkedEntityGroupRemovals  = new NativeArray <LinkedEntityGroupRemoval>(worldDiff.LinkedEntityGroupRemovals, label)
            };

            if (null != worldDiff.SharedSetCommands)
            {
                clone.SharedSetCommands = new SetSharedComponentDiff[worldDiff.SharedSetCommands.Length];
                Array.Copy(worldDiff.SharedSetCommands, clone.SharedSetCommands, worldDiff.SharedSetCommands.Length);
            }

            return(clone);
        }
Example #2
0
 public void EmptyForIdenticals()
 {
     var world2 = World.Empty.SetWob(_planet);
     Assert.True(new WorldDiff(World.Empty, World.Empty).IsEmpty);
     Assert.True(new WorldDiff(world2, world2).IsEmpty);
     var diff = new WorldDiff(World.Empty, world2);
     Assert.False(diff.IsEmpty);
     Assertions.WorldsEqual(world2, World.Empty.Patch(diff));
 }
Example #3
0
        public void ComputeDiffOnly()
        {
            EntityGuid[] guids = new EntityGuid[4];
            Entity[]     ents  = new Entity[4];

            // create 4 entities
            for (int i = 0; i < 4; ++i)
            {
                guids[i] = GenerateEntityGuid(i + 1);
                ents[i]  = m_Manager.CreateEntity(typeof(EntityGuid), typeof(EcsTestData));
                m_Manager.SetComponentData(ents[i], guids[i]);
                m_Manager.SetComponentData(ents[i], new EcsTestData {
                    value = i
                });
            }

            WorldDiff diff = default;

            // Calculate initial diff
            diff = WorldDiffer.CreateDiff(m_After, m_Shadow, Allocator.TempJob);
            Assert.AreEqual(diff.NewEntityCount, 4);
            diff.Dispose();

            // These shouldn't exist in the shadow world
            foreach (var guid in guids)
            {
                Assert.AreEqual(Entity.Null, GetEntityByGuid(m_Shadow.EntityManager, guid));
            }

            // Calculate same diff again; results should be the same as above
            diff = WorldDiffer.CreateDiff(m_After, m_Shadow, Allocator.TempJob);
            Assert.AreEqual(diff.NewEntityCount, 4);

            // These still shouldn't exist in the shadow world
            foreach (var guid in guids)
            {
                Assert.AreEqual(Entity.Null, GetEntityByGuid(m_Shadow.EntityManager, guid));
            }

            // Now apply the diff to the dst world
            WorldDiffer.ApplyDiff(m_DstWorld, diff);
            diff.Dispose();

            // and now they should exist in the dst world
            for (int i = 0; i < 4; ++i)
            {
                Assert.AreEqual(ents[i], GetEntityByGuid(m_DstManager, guids[i]));
            }
        }
Example #4
0
        async void Check(object stateInfo)
        {
            try {
                var world = await VrcApi.GetWorld(WorldId);

                var worldInstances = new List <WorldInstance>();
                foreach (var instance in world.Instances)
                {
                    // worldInstances.Add(await VrcApi.GetWorldInstance(WorldId, instance.Id));
                }
                Callback(WorldDiff.GetDiff(world, worldInstances));
            } catch (Exception e) {
                ErrorCallback(e);
            }
        }
Example #5
0
        private IEnumerable <Scene> GetScenesForCreatedEntities(WorldDiff diff)
        {
            var sharedSetCommands = diff.SharedSetCommands;

            for (var packedEntityIndex = 0; packedEntityIndex < diff.NewEntityCount; packedEntityIndex++)
            {
                var sceneGuid       = new SceneGuid();
                var sceneInstanceId = new SceneInstanceId();

                for (var i = 0; i < sharedSetCommands.Length; i++)
                {
                    var cmd = sharedSetCommands[i];

                    if (cmd.EntityIndex != packedEntityIndex)
                    {
                        continue;
                    }

                    var stableTypeHash = diff.TypeHashes[cmd.TypeHashIndex];

                    if (stableTypeHash == TypeManager.GetTypeInfo <SceneGuid>().StableTypeHash)
                    {
                        sceneGuid = (SceneGuid)cmd.BoxedSharedValue;
                    }

                    if (stableTypeHash == TypeManager.GetTypeInfo <SceneInstanceId>().StableTypeHash)
                    {
                        sceneInstanceId = (SceneInstanceId)cmd.BoxedSharedValue;
                    }
                }

                if (sceneGuid.Guid != Guid.Empty)
                {
                    yield return(new Scene(sceneGuid, sceneInstanceId));
                }
            }
        }
Example #6
0
 public static uint Size(this WorldDiff worldDiff)
 {
     return(worldDiff.HasChanges ? (uint)Marshal.SizeOf(worldDiff) : 0);
 }
Example #7
0
 public bool SendWorldPatch(Guid clientID, WorldDiff diff)
 {
     SetShadow(clientID, w => w.Patch(diff));
     _world.Set(w => w.Patch(diff));
     return true;
 }
Example #8
0
 public WorldDiff ReceiveWorldPatch(Guid clientID)
 {
     WorldDiff diff = null;
     SetShadow(clientID, shadow => shadow.Patch(diff = new WorldDiff(shadow, _world)));
     return diff;
 }
Example #9
0
 private void SyncWithServer()
 {
     Thread.Sleep(TimeSpan.FromSeconds(ServerSyncInterval));
     var diffOut = new WorldDiff(_worldShadow, Globals.World);
     _worldShadow = _worldShadow.Patch(diffOut);
     if (!diffOut.IsEmpty) _visualizationUpdates.Enqueue(diffOut);
     _service.SendWorldPatch(_clientID, diffOut);
     var diffIn = _service.ReceiveWorldPatch(_clientID);
     if (!diffIn.IsEmpty) _visualizationUpdates.Enqueue(diffIn);
     _worldShadow = _worldShadow.Patch(diffIn);
     Globals.World.Set(w => w.Patch(diffIn));
     if (_mission == null)
         _mission = new Mission
         {
             AssignMessage = "Go and find The Planet!\nThere'll be no reward.",
             AssignVolume = new Sphere(Globals.World.Value.Wobs.Values.OfType<Station>().First().Pos, 50),
             CompleteMessage = "You found the correct planet,\nnice!",
             CompleteVolume = new Sphere(Globals.World.Value.Wobs.Values.OfType<Planet>().First().Pos, 80),
         };
 }
Example #10
0
 internal Changes(WorldDiff worldDiff, WorldDiff inverseWorldDiff)
 {
     m_WorldDiff        = worldDiff;
     m_InverseWorldDiff = inverseWorldDiff;
 }
Example #11
0
 private void AssertDiffAndPatch(World world1, World world2, Action<WorldDiff> assertDiff)
 {
     var diff = new WorldDiff(world1, world2);
     assertDiff(diff);
     Assertions.WorldsEqual(world2, world1.Patch(diff));
 }