コード例 #1
0
        private static Snapshot GenerateSessionSnapshot()
        {
            var snapshot = new Snapshot();

            snapshot.AddEntity(FpsEntityTemplates.Spawner(Coordinates.Zero));
            snapshot.AddEntity(FpsEntityTemplates.DeploymentState());
            return(snapshot);
        }
コード例 #2
0
        public void Contains_returns_true_if_entityId_exists()
        {
            var entityId = snapshot.GetNextEntityId();
            var template = GetTemplate();

            snapshot.AddEntity(entityId, template);
            Assert.IsTrue(snapshot.Contains(entityId));
        }
コード例 #3
0
        private static void GenerateDefaultSnapshot()
        {
            var snapshot = new Snapshot();

            var spawner = FpsEntityTemplates.Spawner();

            snapshot.AddEntity(spawner);

            var SimulatedPlayerCoordinatorTrigger = FpsEntityTemplates.SimulatedPlayerCoordinatorTrigger();

            snapshot.AddEntity(SimulatedPlayerCoordinatorTrigger);

            SaveSnapshot(snapshot);
        }
コード例 #4
0
        private static void CreateSpinner(Snapshot snapshot, Coordinates coords)
        {
            const string entityType = "Spinner";

            var transform = new TransformInternal.Snapshot
            {
                Location       = new Location((float)coords.X, (float)coords.Y, (float)coords.Z),
                Rotation       = new Quaternion(1, 0, 0, 0),
                TicksPerSecond = 1f / Time.fixedDeltaTime
            };

            var template = new EntityTemplate();

            template.AddComponent(new Position.Snapshot {
                Coords = coords
            }, WorkerUtils.UnityGameLogic);
            template.AddComponent(new Metadata.Snapshot {
                EntityType = entityType
            }, WorkerUtils.UnityGameLogic);
            template.AddComponent(transform, WorkerUtils.UnityGameLogic);
            template.AddComponent(new Persistence.Snapshot(), WorkerUtils.UnityGameLogic);
            template.AddComponent(new Collisions.Snapshot(), WorkerUtils.UnityGameLogic);
            template.AddComponent(new SpinnerColor.Snapshot {
                Color = Color.BLUE
            }, WorkerUtils.UnityGameLogic);
            template.AddComponent(new SpinnerRotation.Snapshot(), WorkerUtils.UnityGameLogic);

            template.SetReadAccess(WorkerUtils.UnityGameLogic, WorkerUtils.UnityClient, WorkerUtils.MobileClient);
            template.SetComponentWriteAccess(EntityAcl.ComponentId, WorkerUtils.UnityGameLogic);


            snapshot.AddEntity(template);
        }
コード例 #5
0
        private static Snapshot GenerateDefaultSnapshot()
        {
            var snapshot = new Snapshot();

            snapshot.AddEntity(FpsEntityTemplates.Spawner(Coordinates.Zero));
            return(snapshot);
        }
コード例 #6
0
        private static void AddCubeGrid(Snapshot snapshot, int cubeCount)
        {
            // Calculate grid size
            var gridLength = (int)Math.Ceiling(Math.Sqrt(cubeCount));

            if (gridLength % 2 == 1) // To make sure nothing is in (0, 0)
            {
                gridLength += 1;
            }

            var cubesToSpawn = cubeCount;

            for (var x = -gridLength + 1; x <= gridLength - 1; x += 2)
            {
                for (var z = -gridLength + 1; z <= gridLength - 1; z += 2)
                {
                    // Leave the centre empty
                    if (x == 0 && z == 0)
                    {
                        continue;
                    }

                    // Exit when we've hit our cube limit
                    if (cubesToSpawn-- <= 0)
                    {
                        return;
                    }

                    var entityTemplate = CubeTemplate.CreateCubeEntityTemplate(new Coordinates(x, 1, z));
                    snapshot.AddEntity(entityTemplate);
                }
            }
        }
コード例 #7
0
        private static void CreateSpinner(Snapshot snapshot, Coordinates coords)
        {
            const string entityType = "Spinner";

            var transform = TransformInternal.Component.CreateSchemaComponentData(
                new Location {
                X = (float)coords.X, Y = (float)coords.Y, Z = (float)coords.Z
            },
                new Quaternion {
                W = 1, X = 0, Y = 0, Z = 0
            },
                new Velocity(0.0f, 0.0f, 0.0f),
                0,
                0.0f
                );

            var collisions      = Collisions.Component.CreateSchemaComponentData();
            var color           = SpinnerColor.Component.CreateSchemaComponentData(Color.BLUE);
            var spinnerRotation = SpinnerRotation.Component.CreateSchemaComponentData();

            var entityTemplate = EntityBuilder.Begin()
                                 .AddPosition(coords.X, coords.Y, coords.Z, WorkerUtils.UnityGameLogic)
                                 .AddMetadata(entityType, WorkerUtils.UnityGameLogic)
                                 .SetPersistence(true)
                                 .SetReadAcl(WorkerUtils.AllWorkerAttributes)
                                 .AddComponent(collisions, WorkerUtils.UnityGameLogic)
                                 .AddComponent(transform, WorkerUtils.UnityGameLogic)
                                 .AddComponent(color, WorkerUtils.UnityGameLogic)
                                 .AddComponent(spinnerRotation, WorkerUtils.UnityGameLogic)
                                 .Build();

            snapshot.AddEntity(entityTemplate);
        }
コード例 #8
0
        private static void AddDefaultUnits(Snapshot snapshot, int cubeCount, TerrainCollider ground = null)
        {
            var gridLength = (int)Math.Ceiling(Math.Sqrt(cubeCount));
            var len        = gridLength * scale;
            var templateA  = BaseUnitTemplate.CreateBaseUnitEntityTemplate(UnitSide.A, GroundCoordinates(-len * 3, 0, ground), UnitType.Stronghold);
            var templateB  = BaseUnitTemplate.CreateBaseUnitEntityTemplate(UnitSide.B, GroundCoordinates(len * 3, 0, ground), UnitType.Stronghold);

            snapshot.AddEntity(templateA);
            snapshot.AddEntity(templateB);

            var templateCa = BaseUnitTemplate.CreateBaseUnitEntityTemplate(UnitSide.A, GroundCoordinates(-len * 2, 0, ground), UnitType.Commander);
            var templateCb = BaseUnitTemplate.CreateBaseUnitEntityTemplate(UnitSide.B, GroundCoordinates(len * 2, 0, ground), UnitType.Commander);

            snapshot.AddEntity(templateCa);
            snapshot.AddEntity(templateCb);
        }
コード例 #9
0
        private static void CreateSpinner(Snapshot snapshot, Coordinates coords)
        {
            const string entityType = "Spinner";

            var transform = Generated.Improbable.Transform.Transform.Component.CreateSchemaComponentData(
                new Location {
                X = (float)coords.X, Y = (float)coords.Y, Z = (float)coords.Z
            },
                new Quaternion {
                W = 1, X = 0, Y = 0, Z = 0
            },
                0
                );

            var prefab          = Prefab.Component.CreateSchemaComponentData(entityType);
            var collisions      = Collisions.Component.CreateSchemaComponentData();
            var archetype       = ArchetypeComponent.Component.CreateSchemaComponentData(entityType);
            var color           = SpinnerColor.Component.CreateSchemaComponentData(Color.BLUE);
            var spinnerRotation = SpinnerRotation.Component.CreateSchemaComponentData();

            var entity = EntityBuilder.Begin()
                         .AddPosition(coords.X, coords.Y, coords.Z, WorkerUtils.UnityGameLogic)
                         .AddMetadata(entityType, WorkerUtils.UnityGameLogic)
                         .SetPersistence(true)
                         .SetReadAcl(UnityWorkers)
                         .AddComponent(collisions, WorkerUtils.UnityGameLogic)
                         .AddComponent(transform, WorkerUtils.UnityGameLogic)
                         .AddComponent(prefab, WorkerUtils.UnityGameLogic)
                         .AddComponent(archetype, WorkerUtils.UnityGameLogic)
                         .AddComponent(color, WorkerUtils.UnityGameLogic)
                         .AddComponent(spinnerRotation, WorkerUtils.UnityGameLogic)
                         .Build();

            snapshot.AddEntity(entity);
        }
コード例 #10
0
        private static void AddHealthPacks(Snapshot snapshot)
        {
            // Invoke our static function to create an entity template of our health pack with 100 heath.
            var healthPack = FpsEntityTemplates.HealthPickup(new Vector3f(5, 0, 0), 100);

            // Add the entity template to the snapshot.
            snapshot.AddEntity(healthPack);
        }
コード例 #11
0
        private void DoInsert(IGameEntity gameEntity)
        {
            var  entityKey = gameEntity.EntityKey;
            bool hasAdd    = false;

            if (preEntityKeys.Contains(entityKey))
            {
                hasAdd = true;
            }
            else if (sendSnapshotFilter.IsIncludeEntity(gameEntity))
            {
                if (sendSnapshotFilter.IsEntitySelf(gameEntity))
                {//获取自己的备份
                    snapshot.AddEntity(gameEntity.GetSelfEntityCopy(seq));
                    hasAdd = true;
                }
                else if (!isAccountStage)
                {
                    if (isPrepareStage && gameEntity.EntityType != (int)EEntityType.Player)
                    {
                        return;
                    }
                    //获取别人的备份
                    if (gameEntity.HasPositionFilter)
                    {
                        var positionFilter = gameEntity.GetComponent <PositionFilterComponent>();
                        var position       = gameEntity.Position;
                        if (!positionFilter.Filter(position.Value, sendSnapshotFilter.Position))
                        {
                            snapshot.AddEntity(gameEntity.GetNonSelfEntityCopy(seq));
                            hasAdd = true;
                        }
                    }
                    else
                    {
                        snapshot.AddEntity(gameEntity.GetNonSelfEntityCopy(seq));
                        hasAdd = true;
                    }
                }
            }

            if (hasAdd && onInsert != null)
            {
                onInsert(gameEntity, forPre);
            }
        }
コード例 #12
0
 private static void AddPolEntities(Snapshot snapshot, int numEntities)
 {
     for (int i = 10; i < numEntities; i++)
     {
         var x         = Random.Range(-150, 150);
         var z         = Random.Range(-150, 150);
         var polEntity = Fps.FpsEntityTemplates.PolEntity(new Vector3f(x, 0, z), (uint)i % 4);
         // Add the entity template to the snapshot.
         snapshot.AddEntity(polEntity);
     }
 }
コード例 #13
0
        private static void AddWorldTimer(Snapshot snapshot, Coordinates location)
        {
            var template = new EntityTemplate();

            template.AddComponent(new Position.Snapshot(location), WorkerUtils.UnityGameLogic);
            template.AddComponent(new Metadata.Snapshot("WorldTimer"), WorkerUtils.UnityGameLogic);
            template.AddComponent(new Persistence.Snapshot(), WorkerUtils.UnityGameLogic);
            template.AddComponent(new WorldTimer.Snapshot(), WorkerUtils.UnityGameLogic);

            template.SetReadAccess(WorkerUtils.UnityGameLogic, WorkerUtils.UnityClient, WorkerUtils.MobileClient);
            template.SetComponentWriteAccess(EntityAcl.ComponentId, WorkerUtils.UnityGameLogic);
            snapshot.AddEntity(template);
        }
コード例 #14
0
        private static void AddPlayerSpawner(Snapshot snapshot)
        {
            var playerCreator = SpatialOSPlayerCreator.CreateSchemaComponentData();
            var spawner       = EntityBuilder.Begin()
                                .AddPosition(0, 0, 0, SystemConfig.UnityGameLogic)
                                .AddMetadata("PlayerCreator", SystemConfig.UnityGameLogic)
                                .SetPersistence(true)
                                .SetReadAcl(UnityWorkers)
                                .AddComponent(playerCreator, SystemConfig.UnityGameLogic)
                                .Build();

            snapshot.AddEntity(spawner);
        }
コード例 #15
0
        private static void AddPlayerSpawner(Snapshot snapshot)
        {
            var playerCreator = PlayerCreator.Component.CreateSchemaComponentData();
            var spawner       = EntityBuilder.Begin()
                                .AddPosition(0, 0, 0, WorkerUtils.UnityGameLogic)
                                .AddMetadata("PlayerCreator", WorkerUtils.UnityGameLogic)
                                .SetPersistence(true)
                                .SetReadAcl(WorkerUtils.AllWorkerAttributes)
                                .AddComponent(playerCreator, WorkerUtils.UnityGameLogic)
                                .Build();

            snapshot.AddEntity(spawner);
        }
コード例 #16
0
        private static void SaveSnapshot(IDictionary <EntityId, EntityTemplate> snapshotEntities)
        {
            var snapshotPath = Application.dataPath + SimulationSettings.DefaultRelativeSnapshotPath;

            File.Delete(snapshotPath);
            var snapshot = new Snapshot();

            foreach (var kvp in snapshotEntities)
            {
                snapshot.AddEntity(kvp.Value);
            }
            snapshot.WriteToFile(snapshotPath);
            Debug.LogFormat("Successfully generated initial world snapshot at {0}", snapshotPath);
        }
コード例 #17
0
        private static void AddSpawnController(Snapshot snapshot)
        {
            var template = new EntityTemplate();
            template.AddComponent(new Position.Snapshot(), WorkerUtils.UnityGameLogic);
            template.AddComponent(
                new Metadata.Snapshot { EntityType = "SpawnController" },
                WorkerUtils.UnityGameLogic);
            template.AddComponent(new Persistence.Snapshot(), WorkerUtils.UnityGameLogic);
            template.AddComponent(new SpawnController.Snapshot(), WorkerUtils.UnityGameLogic);

            template.SetReadAccess(WorkerUtils.AllWorkers);
            template.SetComponentWriteAccess(EntityAcl.ComponentId, WorkerUtils.UnityGameLogic);

            snapshot.AddEntity(template);
        }
コード例 #18
0
        private static void GenerateFpsSnapshot()
        {
            var localSnapshot = new Snapshot();
            var cloudSnapshot = new Snapshot();

            GenerateSnapshot(localSnapshot);
            GenerateSnapshot(cloudSnapshot);

            // The local snapshot is identical to the cloud snapshot, but also includes a simulated player coordinator
            // trigger.
            var simulatedPlayerCoordinatorTrigger = FpsEntityTemplates.SimulatedPlayerCoordinatorTrigger();
            var polController = FpsEntityTemplates.PolControllerEntity(new Improbable.Vector3f(5, 0, 0));

            cloudSnapshot.AddEntity(polController);
            cloudSnapshot.AddEntity(simulatedPlayerCoordinatorTrigger);
            AddPolEntities(cloudSnapshot, 100);

            localSnapshot.AddEntity(polController);
            AddPolEntities(localSnapshot, 100);
            localSnapshot.AddEntity(simulatedPlayerCoordinatorTrigger);

            SaveSnapshot(DefaultSnapshotPath, localSnapshot);
            SaveSnapshot(CloudSnapshotPath, cloudSnapshot);
        }
コード例 #19
0
        private static void AddCubeGrid(Snapshot snapshot, int cubeCount, TerrainCollider ground = null)
        {
            // Calculate grid size
            var gridLength = (int)Math.Ceiling(Math.Sqrt(cubeCount));

            if (gridLength % 2 == 1) // To make sure nothing is in (0, 0)
            {
                gridLength += 1;
            }

            var cubesToSpawn = cubeCount;

            for (var x = -gridLength + 1; x <= gridLength - 1; x += 2)
            {
                for (var z = -gridLength + 1; z <= gridLength - 1; z += 2)
                {
                    // Leave the centre empty
                    if (x == 0 && z == 0)
                    {
                        continue;
                    }

                    // Exit when we've hit our cube limit
                    if (cubesToSpawn-- <= 0)
                    {
                        return;
                    }

                    UnitSide side = x < 0 ? UnitSide.A : UnitSide.B;
                    int      nx;
                    if (x < 0)
                    {
                        nx = x - 3;
                    }
                    else
                    {
                        nx = x + 3;
                    }

                    double pos_x          = nx * scale;
                    double pos_z          = z * scale;
                    var    entityTemplate = BaseUnitTemplate.CreateBaseUnitEntityTemplate(side, GroundCoordinates(pos_x, pos_z, ground), UnitType.Soldier);
                    snapshot.AddEntity(entityTemplate);
                }
            }

            AddDefaultUnits(snapshot, cubeCount, ground);
        }
コード例 #20
0
        private static void AddPlayerSpawner(Snapshot snapshot, Coordinates playerSpawnerLocation)
        {
            var template = new EntityTemplate();

            template.AddComponent(new Position.Snapshot(playerSpawnerLocation), WorkerUtils.UnityGameLogic);
            template.AddComponent(new Metadata.Snapshot {
                EntityType = "PlayerCreator"
            }, WorkerUtils.UnityGameLogic);
            template.AddComponent(new Persistence.Snapshot(), WorkerUtils.UnityGameLogic);
            template.AddComponent(new PlayerCreator.Snapshot(), WorkerUtils.UnityGameLogic);

            template.SetReadAccess(WorkerUtils.UnityGameLogic, WorkerUtils.UnityClient, WorkerUtils.MobileClient);
            template.SetComponentWriteAccess(EntityAcl.ComponentId, WorkerUtils.UnityGameLogic);

            snapshot.AddEntity(template);
        }
コード例 #21
0
        private static void AddCubeGrid(Snapshot snapshot, int cubeCount)
        {
            var cubeTemplate = CubeTemplate.CreateCubeEntityTemplate();

            // Calculate grid size
            var gridLength = (int)Math.Ceiling(Math.Sqrt(cubeCount));

            if (gridLength % 2 == 1) // To make sure nothing is in (0, 0)
            {
                gridLength += 1;
            }

            var cubesToSpawn = cubeCount;

            for (var x = -gridLength + 1; x <= gridLength - 1; x += 2)
            {
                for (var z = -gridLength + 1; z <= gridLength - 1; z += 2)
                {
                    // Leave the centre empty
                    if (x == 0 && z == 0)
                    {
                        continue;
                    }

                    // Exit when we've hit our cube limit
                    if (cubesToSpawn-- <= 0)
                    {
                        return;
                    }

                    var positionSnapshot = new Position.Snapshot
                    {
                        Coords = new Coordinates(x, 1, z)
                    };
                    var transformSnapshot = new TransformInternal.Snapshot
                    {
                        Location       = new Location(x, 1, z),
                        Rotation       = new Quaternion(1, 0, 0, 0),
                        TicksPerSecond = 1f / Time.fixedDeltaTime
                    };

                    cubeTemplate.SetComponent(positionSnapshot);
                    cubeTemplate.SetComponent(transformSnapshot);
                    snapshot.AddEntity(cubeTemplate);
                }
            }
        }
コード例 #22
0
        private static void AddPlayerSpawner(Snapshot snapshot)
        {
            var serverAttribute = UnityGameLogicConnector.WorkerType;

            var template = new EntityTemplate();
            template.AddComponent(new Position.Snapshot(), serverAttribute);
            template.AddComponent(
                new Metadata.Snapshot { EntityType = "PlayerCreator" },
                serverAttribute);
            template.AddComponent(new Persistence.Snapshot(), serverAttribute);
            template.AddComponent(new PlayerCreator.Snapshot(), serverAttribute);

            template.SetReadAccess(WorkerUtils.AllWorkers);
            template.SetComponentWriteAccess(EntityAcl.ComponentId, serverAttribute);

            snapshot.AddEntity(template);
        }
コード例 #23
0
        private static void GenerateFpsSnapshot()
        {
            var localSnapshot = new Snapshot();
            var cloudSnapshot = new Snapshot();

            GenerateSnapshot(localSnapshot);
            GenerateSnapshot(cloudSnapshot);

            // The local snapshot is identical to the cloud snapshot, but also includes a simulated player coordinator
            // trigger.
            var simulatedPlayerCoordinatorTrigger = FpsEntityTemplates.SimulatedPlayerCoordinatorTrigger();

            localSnapshot.AddEntity(simulatedPlayerCoordinatorTrigger);

            SaveSnapshot(DefaultSnapshotPath, localSnapshot);
            SaveSnapshot(CloudSnapshotPath, cloudSnapshot);
        }
コード例 #24
0
        private static void AddResourceNode(Snapshot snapshot, AxialCoordinate position, ResourceType type)
        {
            var template = new EntityTemplate();

            var worldPos = HexUtils.GridToWorld(position);
            template.AddComponent(new Position.Snapshot(new Coordinates(worldPos.x, 0, worldPos.y)), WorkerUtils.UnityGameLogic);
            template.AddComponent(
                new Metadata.Snapshot { EntityType = "ResourceNode" },
                WorkerUtils.UnityGameLogic);
            template.AddComponent(new Persistence.Snapshot(), WorkerUtils.UnityGameLogic);
            template.AddComponent(new ResourceNode.Snapshot(type, 100), WorkerUtils.UnityGameLogic);
            template.AddComponent(new GridPosition.Snapshot(position.ToGridCoordinate()), WorkerUtils.UnityGameLogic);

            template.SetReadAccess(WorkerUtils.AllWorkers);
            template.SetComponentWriteAccess(EntityAcl.ComponentId, WorkerUtils.UnityGameLogic);

            snapshot.AddEntity(template);
        }
コード例 #25
0
        private static void CreateSpinner(Snapshot snapshot, Coordinates coords)
        {
            const string entityType = "Spinner";

            var transform = TransformUtils.CreateTransformSnapshot(coords, Quaternion.identity);

            var template = new EntityTemplate();

            template.AddComponent(new Position.Snapshot(coords), WorkerUtils.UnityGameLogic);
            template.AddComponent(new Metadata.Snapshot(entityType), WorkerUtils.UnityGameLogic);
            template.AddComponent(transform, WorkerUtils.UnityGameLogic);
            template.AddComponent(new Persistence.Snapshot(), WorkerUtils.UnityGameLogic);
            template.AddComponent(new Collisions.Snapshot(), WorkerUtils.UnityGameLogic);
            template.AddComponent(new SpinnerColor.Snapshot(Color.BLUE), WorkerUtils.UnityGameLogic);
            template.AddComponent(new SpinnerRotation.Snapshot(), WorkerUtils.UnityGameLogic);

            template.SetReadAccess(WorkerUtils.UnityGameLogic, WorkerUtils.UnityClient, WorkerUtils.MobileClient);
            template.SetComponentWriteAccess(EntityAcl.ComponentId, WorkerUtils.UnityGameLogic);

            snapshot.AddEntity(template);
        }
コード例 #26
0
        private static void AddCubeGrid(Snapshot snapshot, int cubeCount)
        {
            var cubeTemplate = CubeTemplate.CreateCubeEntityTemplate();

            // Calculate grid size
            var gridLength = (int)Math.Ceiling(Math.Sqrt(cubeCount));

            if (gridLength % 2 == 1) // To make sure nothing is in (0, 0)
            {
                gridLength += 1;
            }

            var cubesToSpawn = cubeCount;

            for (var x = -gridLength + 1; x <= gridLength - 1; x += 2)
            {
                for (var z = -gridLength + 1; z <= gridLength - 1; z += 2)
                {
                    // Leave the centre empty
                    if (x == 0 && z == 0)
                    {
                        continue;
                    }

                    // Exit when we've hit our cube limit
                    if (cubesToSpawn-- <= 0)
                    {
                        return;
                    }

                    var location          = new Vector3(x, 1, z);
                    var positionSnapshot  = new Position.Snapshot(location.ToCoordinates());
                    var transformSnapshot = TransformUtils.CreateTransformSnapshot(location, Quaternion.identity);

                    cubeTemplate.SetComponent(positionSnapshot);
                    cubeTemplate.SetComponent(transformSnapshot);
                    snapshot.AddEntity(cubeTemplate);
                }
            }
        }
コード例 #27
0
        private static void AddPlayerSpawner(Snapshot snapshot, Coordinates playerSpawnerLocation)
        {
            var template = new EntityTemplate();

            template.AddComponent(new Position.Snapshot(playerSpawnerLocation), WorkerUtils.UnityGameLogic);
            template.AddComponent(new Metadata.Snapshot {
                EntityType = "PlayerCreator"
            }, WorkerUtils.UnityGameLogic);
            template.AddComponent(new Persistence.Snapshot(), WorkerUtils.UnityGameLogic);
            template.AddComponent(new PlayerCreator.Snapshot(), WorkerUtils.UnityGameLogic);
            template.AddComponent(new WorldTimer.Snapshot(), WorkerUtils.UnityGameLogic);

            var query    = InterestQuery.Query(Constraint.RelativeCylinder(500));
            var interest = InterestTemplate.Create()
                           .AddQueries <Position.Component>(query);

            template.AddComponent(interest.ToSnapshot(), WorkerUtils.UnityGameLogic);

            template.SetReadAccess(WorkerUtils.UnityGameLogic, WorkerUtils.UnityClient, WorkerUtils.MobileClient);
            template.SetComponentWriteAccess(EntityAcl.ComponentId, WorkerUtils.UnityGameLogic);
            snapshot.AddEntity(template);
        }
コード例 #28
0
    private static void AddPlayerSpawner(Snapshot snapshot)
    {
        var serverAttribute = UnityGameLogicConnector.WorkerType;

        var template = new EntityTemplate();

        template.AddComponent(new Position.Snapshot(), serverAttribute);
        template.AddComponent(new Metadata.Snapshot("PlayerCreator"), serverAttribute);
        template.AddComponent(new Persistence.Snapshot(), serverAttribute);
        template.AddComponent(new PlayerCreator.Snapshot(), serverAttribute);

        var query    = InterestQuery.Query(Constraint.RelativeCylinder(500));
        var interest = InterestTemplate.Create()
                       .AddQueries <Position.Component>(query);

        template.AddComponent(interest.ToSnapshot(), serverAttribute);

        template.SetReadAccess(
            UnityClientConnector.WorkerType,
            UnityGameLogicConnector.WorkerType);
        template.SetComponentWriteAccess(EntityAcl.ComponentId, serverAttribute);

        snapshot.AddEntity(template);
    }
コード例 #29
0
 private static void GenerateSnapshot(Snapshot snapshot)
 {
     snapshot.AddEntity(FpsEntityTemplates.Spawner(Coordinates.Zero));
 }
コード例 #30
0
ファイル: CincoServer.cs プロジェクト: strager/Cinco
        private Snapshot GetSnapshot(bool fullSnapshot)
        {
            Snapshot snapshot = new Snapshot();

            lock (entityLock)
            {
                foreach (NetworkEntity entity in entities.Values)
                {
                    switch (entity.ChangedState)
                    {
                        case ChangedState.Changed:
                            snapshot.AddEntity (entity, true);
                            break;

                        case ChangedState.None:
                            if (!fullSnapshot)
                                snapshot.AddEntity (entity, false);

                            break;
                    }
                }
            }

            return snapshot;
        }
コード例 #31
0
        private static void AddCubeGrid(Snapshot snapshot, int cubeCount)
        {
            // Calculate grid size
            var gridLength = (int)Math.Ceiling(Math.Sqrt(cubeCount));

            if (gridLength % 2 == 1) // To make sure nothing is in (0, 0)
            {
                gridLength += 1;
            }

            var          cubesToSpawn = cubeCount;
            const string entityType   = "Cube";

            for (var x = -gridLength + 1; x <= gridLength - 1; x += 2)
            {
                for (var z = -gridLength + 1; z <= gridLength - 1; z += 2)
                {
                    // Leave the centre empty
                    if (x == 0 && z == 0)
                    {
                        continue;
                    }

                    // Exit when we've hit our cube limit
                    if (cubesToSpawn-- <= 0)
                    {
                        return;
                    }

                    var transform = Generated.Improbable.Transform.Transform.Component.CreateSchemaComponentData(
                        new Location {
                        X = x, Y = 1, Z = z
                    },
                        new Quaternion {
                        W = 1, X = 0, Y = 0, Z = 0
                    },
                        0
                        );

                    var cubeColor          = CubeColor.Component.CreateSchemaComponentData();
                    var cubeTargetVelocity = CubeTargetVelocity.Component.CreateSchemaComponentData(new Vector3f {
                        X = -2.0f
                    });
                    var prefab             = Prefab.Component.CreateSchemaComponentData(entityType);
                    var launchable         = Launchable.Component.CreateSchemaComponentData(new EntityId(0));
                    var archetypeComponent = ArchetypeComponent.Component.CreateSchemaComponentData(entityType);

                    var entity = EntityBuilder.Begin()
                                 .AddPosition(x, 0, z, WorkerUtils.UnityGameLogic)
                                 .AddMetadata(entityType, WorkerUtils.UnityGameLogic)
                                 .SetPersistence(true)
                                 .SetReadAcl(UnityWorkers)
                                 .AddComponent(transform, WorkerUtils.UnityGameLogic)
                                 .AddComponent(cubeColor, WorkerUtils.UnityGameLogic)
                                 .AddComponent(cubeTargetVelocity, WorkerUtils.UnityGameLogic)
                                 .AddComponent(prefab, WorkerUtils.UnityGameLogic)
                                 .AddComponent(archetypeComponent, WorkerUtils.UnityGameLogic)
                                 .AddComponent(launchable, WorkerUtils.UnityGameLogic)
                                 .Build();

                    snapshot.AddEntity(entity);
                }
            }
        }