Пример #1
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);
                }
            }
        }
Пример #2
0
        private void OnEntityIdsReserved(WorldCommands.ReserveEntityIds.ReceivedResponse response)
        {
            if (response.StatusCode != StatusCode.Success)
            {
                logDispatcher.HandleLog(LogType.Error,
                                        new LogEvent("ReserveEntityIds failed.").WithField("Reason", response.Message));

                return;
            }

            var location           = transformReader.Data.Location;
            var cubeEntityTemplate = CubeTemplate.CreateCubeEntityTemplate();

            cubeEntityTemplate.SetComponent(new Position.Snapshot
            {
                Coords = new Coordinates(location.X, location.Y + 2, location.Z)
            });
            cubeEntityTemplate.SetComponent(new TransformInternal.Snapshot
            {
                Location = new Location(location.X, location.Y + 2, location.Z),
                Rotation = new Quaternion(1, 0, 0, 0)
            });
            var expectedEntityId = response.FirstEntityId.Value;

            worldCommandRequestSender.SendCreateEntityCommand(
                new WorldCommands.CreateEntity.Request(cubeEntityTemplate, expectedEntityId), OnEntityCreated);
        }
Пример #3
0
        private void OnEntityIdsReserved(WorldCommands.ReserveEntityIds.ReceivedResponse response)
        {
            if (!ReferenceEquals(this, response.Context))
            {
                // This response was not for a command from this behaviour.
                return;
            }

            if (response.StatusCode != StatusCode.Success)
            {
                logDispatcher.HandleLog(LogType.Error,
                                        new LogEvent("ReserveEntityIds failed.")
                                        .WithField("Reason", response.Message));

                return;
            }

            var location           = transformReader.Data.Location;
            var cubeEntityTemplate = CubeTemplate.CreateCubeEntityTemplate();

            cubeEntityTemplate.SetComponent(new Position.Snapshot
            {
                Coords = new Coordinates(location.X, location.Y + 2, location.Z)
            });
            cubeEntityTemplate.SetComponent(new TransformInternal.Snapshot
            {
                Location = new Location(location.X, location.Y + 2, location.Z),
                Rotation = new Quaternion(1, 0, 0, 0)
            });
            var expectedEntityId = response.FirstEntityId.Value;

            worldCommandRequestSender.CreateEntity(cubeEntityTemplate, expectedEntityId, context: this);
        }
Пример #4
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);
                }
            }
        }
Пример #5
0
    public static List <bool[, ]> GenerateChunk(string key, CubeTemplate template, Neighbours chunkNeighbours)
    {
        List <bool[, ]> map;

        map = GenerateChunkFromTexture(key, template);

        /*
         * if(template.IsEmpty()){
         *      return GenerateFlatChunk(WorldManager.dimension / 2);
         * }else{
         *      map = GenerateChunkFromTexture (key, template);
         *      //map = GenerateRecursiveCellularAutomata (key, template, 1, TestChunkGenerator.randomStatic);
         * }
         */

        GetChunkType(key, chunkNeighbours);
        return(map);
    }
Пример #6
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);
                }
            }
        }
Пример #7
0
    public List <bool[, ]> GenerateCellularAutomata(string chunkKey, CubeTemplate template, int smoothIterations, int randomAddition)
    {
        List <bool[, ]> maps = new List <bool[, ]>();

        for (int y = 0; y < WorldManager.dimension * 2; y++)
        {
            maps.Add(new bool[WorldManager.dimension, WorldManager.dimension]);
        }

        if (!template.IsEmpty())
        {
            for (int x = 0; x < maps.Count; x++)
            {
                for (int y = 0; y < maps.Count; y++)
                {
                    maps[y][0, x] = template.left[x, y];
                    maps[y][maps.Count - 1, x] = template.right[x, y];

                    maps[y][x, maps.Count - 1] = template.forward[x, y];
                    maps[y][x, 0] = template.back[x, y];

                    maps[0][x, y] = template.bottom[x, y];
                    maps[maps.Count - 1][x, y] = template.top[x, y];
                }
            }

            randomAddition = (int)(randomAddition * 0.5f);
        }

        //maps = RandomFillMap(maps, chunkKey, WorldManager.dimension, randomAddition);

        for (int i = 0; i < smoothIterations; i++)
        {
            maps = SmoothMap(maps, smoothPercentage);
        }

        return(maps);
    }
        private void OnEntityIdsReserved(WorldCommands.ReserveEntityIds.ReceivedResponse response)
        {
            if (response.StatusCode != StatusCode.Success)
            {
                logDispatcher.HandleLog(LogType.Error,
                                        new LogEvent("ReserveEntityIds failed.").WithField("Reason", response.Message));

                return;
            }

            var location = gameObject.transform.position;

            location.y += 2;

            var cubeEntityTemplate = CubeTemplate.CreateCubeEntityTemplate();

            cubeEntityTemplate.SetComponent(new Position.Snapshot(location.ToCoordinates()));
            cubeEntityTemplate.SetComponent(TransformUtils.CreateTransformSnapshot(location, Quaternion.identity));

            var expectedEntityId = response.FirstEntityId.Value;

            worldCommandRequestSender.SendCreateEntityCommand(
                new WorldCommands.CreateEntity.Request(cubeEntityTemplate, expectedEntityId), OnEntityCreated);
        }
Пример #9
0
    public static List <bool[, ]> GenerateChunkFromTexture(string chunkKey, CubeTemplate template)
    {
        List <bool[, ]> maps  = new List <bool[, ]>();
        List <bool[, ]> flags = new List <bool[, ]>();

        for (int y = 0; y < WorldManager.dimension * 2; y++)
        {
            maps.Add(new bool[WorldManager.dimension, WorldManager.dimension]);
            flags.Add(new bool[WorldManager.dimension, WorldManager.dimension]);
        }

        if (!template.IsEmpty())
        {
            for (int x = 0; x < WorldManager.dimension; x++)
            {
                for (int y = 0; y < WorldManager.dimension; y++)
                {
                    if (template.left.GetLength(0) > 1)
                    {
                        maps[y][0, x]  = template.left[x, y];
                        flags[y][0, x] = true;
                    }
                    if (template.right.GetLength(0) > 1)
                    {
                        maps[y][WorldManager.dimension - 1, x]  = template.right[x, y];
                        flags[y][WorldManager.dimension - 1, x] = true;
                    }

                    if (template.forward.GetLength(0) > 1)
                    {
                        maps[y][x, WorldManager.dimension - 1]  = template.forward[x, y];
                        flags[y][x, WorldManager.dimension - 1] = true;
                    }
                    if (template.back.GetLength(0) > 1)
                    {
                        maps[y][x, 0]  = template.back[x, y];
                        flags[y][x, 0] = true;
                    }

                    if (template.bottom.GetLength(0) > 1)
                    {
                        maps[0][x, y]  = template.bottom[x, y];
                        flags[0][x, y] = true;
                    }
                    if (template.top.GetLength(0) > 1)
                    {
                        maps[WorldManager.dimension - 1][x, y]  = template.top[x, y];
                        flags[WorldManager.dimension - 1][x, y] = true;
                    }
                }
            }
        }

        string[] numbers = chunkKey.Split(',');

        Vector3 position = new Vector3(int.Parse(numbers [0]), int.Parse(numbers [1]), int.Parse(numbers [2]));

        for (int y = 0; y < maps.Count - 1; y++)
        {
            for (int x = 0; x < maps [y].GetLength(0); x++)
            {
                for (int z = 0; z < maps [y].GetLength(0); z++)
                {
                    maps [y] [x, z] = HeightMapManager.GetActiveState(x + (int)position.x * WorldManager.dimension, y + (int)position.y * WorldManager.dimension, z + (int)position.z * WorldManager.dimension);
                }
            }
        }

        return(maps);
    }
Пример #10
0
    public static List <bool[, ]> GenerateRecursiveCellularAutomata(string chunkKey, CubeTemplate template, int smoothIterations, int randomAddition)
    {
        List <bool[, ]> maps  = new List <bool[, ]>();
        List <bool[, ]> flags = new List <bool[, ]>();

        for (int y = 0; y < WorldManager.dimension * 2; y++)
        {
            maps.Add(new bool[WorldManager.dimension, WorldManager.dimension]);
            flags.Add(new bool[WorldManager.dimension, WorldManager.dimension]);
        }

        if (!template.IsEmpty())
        {
            for (int x = 0; x < WorldManager.dimension; x++)
            {
                for (int y = 0; y < WorldManager.dimension; y++)
                {
                    if (template.left.GetLength(0) > 1)
                    {
                        maps[y][0, x]  = template.left[x, y];
                        flags[y][0, x] = true;
                    }
                    if (template.right.GetLength(0) > 1)
                    {
                        maps[y][WorldManager.dimension - 1, x]  = template.right[x, y];
                        flags[y][WorldManager.dimension - 1, x] = true;
                    }

                    if (template.forward.GetLength(0) > 1)
                    {
                        maps[y][x, WorldManager.dimension - 1]  = template.forward[x, y];
                        flags[y][x, WorldManager.dimension - 1] = true;
                    }
                    if (template.back.GetLength(0) > 1)
                    {
                        maps[y][x, 0]  = template.back[x, y];
                        flags[y][x, 0] = true;
                    }

                    if (template.bottom.GetLength(0) > 1)
                    {
                        maps[0][x, y]  = template.bottom[x, y];
                        flags[0][x, y] = true;
                    }
                    if (template.top.GetLength(0) > 1)
                    {
                        maps[WorldManager.dimension - 1][x, y]  = template.top[x, y];
                        flags[WorldManager.dimension - 1][x, y] = true;
                    }
                }
            }
        }

        maps = RandomFillMap(maps, flags, chunkKey, randomAddition);

        for (int i = 0; i < 1; i++)
        {
            maps = RecursiveSmoothMap(maps, flags, 0, 0, 0, smoothPercentage);
        }

        return(maps);
    }