Example #1
0
    public void GenMap(int xSize, int ySize, int zSize)
    {
        cubeMap = new bool[xSize, ySize, zSize];
        float min = float.MaxValue;
        float Max = float.MinValue;

        //float[,,] floatMap = new float[xSize, ySize, zSize];

        for (int x = 0; x < xSize; x++)
        {
            for (int y = 0; y < ySize; y++)
            {
                for (int z = 0; z < zSize; z++)
                {
                    float xCoord    = (((float)x / xSize) / scale * frequncy) + offset.x;
                    float yCoord    = (((float)y / ySize) / scale * frequncy) + offset.y;
                    float zCoord    = (((float)z / zSize) / scale * frequncy) + offset.z;
                    float perlinVal = Perlin.Noise(xCoord, yCoord, zCoord);
                    //Debug.Log(perlinVal);

                    if (perlinVal < min)
                    {
                        min = perlinVal;
                    }
                    if (perlinVal > Max)
                    {
                        Max = perlinVal;
                    }
                    cubeMap[x, y, z] = perlinVal > toggleThreshold;
                }
            }
        }

        //Debug.Log("min: " + min + " Max: " + Max);
    }
Example #2
0
    private bool DetectCollisionWithStaticBlocks(bool[,,] block, int blockIndex, Vector2Int position)
    {
        Vector2Int blockSize = new Vector2Int(block.GetLength(2), block.GetLength(1));

        for (int x = 0; x < blockSize.x; x++)
        {
            for (int y = 0; y < blockSize.y; y++)
            {
                //checks if part of the blockgrid is outside of the main grid
                if (position.x + x < 0 || position.x + x >= gridSize.x || position.y + y < 0)
                {
                    //checks if that part of the blockgrid is actually part of the block
                    if (block[blockIndex, y, x])
                    {
                        if (position.y + y > 0)
                        {
                            if (grid[position.x + x, position.y + y])
                            {
                                Debug.Log("Collision");
                                return(true);
                            }
                        }
                        else
                        {
                            return(true);
                        }
                    }
                }
            }
        }
        return(false);
    }
Example #3
0
    /// <summary>
    /// 初始化方块组
    /// </summary>
    public void Init()
    {
        GroupInfos groupInfos = transform.parent.GetComponent <GroupInfos>();

        // 销毁当前方块
        foreach (Cube cube in GetComponentsInChildren <Cube>())
        {
            Destroy(cube.gameObject);
        }
        // 随机选择一个结构
        info = groupInfos.infos[Random.Range(0, groupInfos.infoSize)];
        // 构建新方块
        for (int i = 0; i < 3; i++)
        {
            for (int j = 0; j < 3; j++)
            {
                for (int k = 0; k < 3; k++)
                {
                    if (info[i, j, k])
                    {
                        GameObject cube = GameObject.Instantiate(Cubepre, transform);
                        // 相对于中心的位置生成方块
                        cube.transform.localPosition = new Vector3(k - 0.5f - 1, i - 1, j - 0.5f - 1);
                    }
                }
            }
        }
    }
Example #4
0
 public Position(int size)
 {
     this.size       = size;
     this.range      = (int)Math.Sqrt(size);
     this.numbers    = new int[size, size];
     this.impossible = new bool[size, size, size];
 }
Example #5
0
    public bool InstantiateGameObjects(bool[,,] status)
    {
        gameOjects = new GameObjectModel[field, field, field];
        if (status.Length != gameOjects.Length)
        {
            return(false);
        }

        position = new Vector3();
        for (int i = 0; i < field; i++)
        {
            position.z = 0;
            for (int j = 0; j < field; j++)
            {
                position.x = 0;
                for (int k = 0; k < field; k++)
                {
                    gameOjects[i, j, k]       = new GameObjectModel(GameObject.Instantiate(prefab, position, Quaternion.identity));
                    gameOjects[i, j, k].IsRed = status[i, j, k];
                    gameOjects[i, j, k].UpdateBollView(GameController.IsSet);
                    //gameOjects[i, j, k].SetIJKToView(i, j, k); to debug
                    position.x += 10;
                }
                position.z -= 10;
            }
            position.y -= 10;
        }
        return(true);
    }
Example #6
0
        protected bool TryGrowZ(CuboidWithMaterial cub, bool[,,] voxels, bool[,,] voxelVisited, byte[,,] voxelMaterial)
        {
            if (cub.Z2 > 15)
            {
                return(false);
            }

            for (int x = cub.X1; x < cub.X2; x++)
            {
                for (int y = cub.Y1; y < cub.Y2; y++)
                {
                    if (!voxels[x, y, cub.Z2] || voxelVisited[x, y, cub.Z2] || voxelMaterial[x, y, cub.Z2] != cub.Material)
                    {
                        return(false);
                    }
                }
            }

            for (int x = cub.X1; x < cub.X2; x++)
            {
                for (int y = cub.Y1; y < cub.Y2; y++)
                {
                    voxelVisited[x, y, cub.Z2] = true;
                }
            }

            cub.Z2++;
            return(true);
        }
Example #7
0
        protected bool TrySnowGrowZ(CuboidWithMaterial cub, bool[,,] voxels, bool[,] voxelVisited)
        {
            if (cub.Z2 > 15)
            {
                return(false);
            }

            for (int x = cub.X1; x < cub.X2; x++)
            {
                // Stop if
                // "Floor" is gone, already visited, or there's a voxel above
                if (!voxels[x, cub.Y1, cub.Z2] || voxelVisited[x, cub.Z2] || (cub.Y2 < 15 && voxels[x, cub.Y2, cub.Z2]))
                {
                    return(false);
                }
            }

            for (int x = cub.X1; x < cub.X2; x++)
            {
                voxelVisited[x, cub.Z2] = true;
            }

            cub.Z2++;
            return(true);
        }
Example #8
0
        protected bool TryGrowX(CuboidWithMaterial cub, bool[,,] voxels, bool[,,] voxelVisited, byte[,,] voxelMaterial)
        {
            if (cub.X2 > 15)
            {
                return(false);
            }

            for (int y = cub.Y1; y < cub.Y2; y++)
            {
                for (int z = cub.Z1; z < cub.Z2; z++)
                {
                    if (!voxels[cub.X2, y, z] || voxelVisited[cub.X2, y, z] || voxelMaterial[cub.X2, y, z] != cub.Material)
                    {
                        return(false);
                    }
                }
            }

            for (int y = cub.Y1; y < cub.Y2; y++)
            {
                for (int z = cub.Z1; z < cub.Z2; z++)
                {
                    voxelVisited[cub.X2, y, z] = true;
                }
            }

            cub.X2++;
            return(true);
        }
Example #9
0
        protected bool TryGrowY(CuboidWithMaterial cub, bool[,,] voxels, bool[,,] voxelVisited, byte[,,] voxelMaterial)
        {
            if (cub.Y2 > 15)
            {
                return(false);
            }

            for (int x = cub.X1; x < cub.X2; x++)
            {
                for (int z = cub.Z1; z < cub.Z2; z++)
                {
                    if (!voxels[x, cub.Y2, z] || voxelVisited[x, cub.Y2, z] || voxelMaterial[x, cub.Y2, z] != cub.Material)
                    {
                        return(false);
                    }
                }
            }

            for (int x = cub.X1; x < cub.X2; x++)
            {
                for (int z = cub.Z1; z < cub.Z2; z++)
                {
                    voxelVisited[x, cub.Y2, z] = true;
                }
            }

            cub.Y2++;
            return(true);
        }
Example #10
0
        protected void convertToVoxels(out bool[,,] voxels, out byte[,,] materials)
        {
            voxels    = new bool[16, 16, 16];
            materials = new byte[16, 16, 16];
            CuboidWithMaterial cwm = tmpCuboid;



            for (int i = 0; i < VoxelCuboids.Count; i++)
            {
                FromUint(VoxelCuboids[i], cwm);

                for (int dx = cwm.X1; dx < cwm.X2; dx++)
                {
                    for (int dy = cwm.Y1; dy < cwm.Y2; dy++)
                    {
                        for (int dz = cwm.Z1; dz < cwm.Z2; dz++)
                        {
                            voxels[dx, dy, dz]    = true;
                            materials[dx, dy, dz] = cwm.Material;
                        }
                    }
                }
            }
        }
Example #11
0
    void Start()
    {
        blockStates  = new bool[200, 200, 200];
        blockObjects = new GameObject[200, 200, 200];

        textureManager = GameObject.Find("Game Logic").GetComponent <TextureManager> ();
    }
Example #12
0
    private void LoadLevel()
    {
        if (GameObjectsTable != null)
        {
            ClearGameObjectsTable();
        }

        CurrentLevel    = LH.GetLevel();
        GameSize        = CurrentLevel.GameSize;
        MovesToComplete = CurrentLevel.MovesToComplete;

        // calculate width and beggining
        if (!spread)
        {
            CellGap = 0;
        }
        else
        {
            CellGap = (realWidth - (CellGap * (GameSize - 1) * 2)) / (GameSize * 2) / 1.5f;
        }

        CalculateWidthAndBeggining();

        GameRoutine = null;

        // initiate other level utilities
        GameTable        = new bool[GameSize, GameSize, GameSize];
        NextGameTable    = new bool[GameSize, GameSize, GameSize];
        GameObjectsTable = new GameObject[GameSize, GameSize, GameSize];
        TimeAlive        = new int[GameSize, GameSize, GameSize];

        // copy level table into game table
        AssignTableValues();
    }
Example #13
0
        public int size;               //A size parameter so size is recorded on a per maze basis

        public Maze(int mazeSize)
        {
            size          = mazeSize;
            adjacencyList = new bool[mazeSize, mazeSize, 2];

            //Initialize all cells as connected
            for (int i = 0; i < mazeSize; i++)
            {
                for (int j = 0; j < mazeSize; j++)
                {
                    adjacencyList[i, j, 0] = true;
                    adjacencyList[i, j, 1] = true;
                }
            }

            //Remove connections to invalid cells
            for (int i = 0; i < mazeSize; i++)
            {
                adjacencyList[i, mazeSize - 1, 1] = false;
            }
            for (int j = 0; j < mazeSize; j++)
            {
                adjacencyList[mazeSize - 1, j, 0] = false;
            }
        }
Example #14
0
        void RegenMeshAndSelectionBoxes()
        {
            int layer = NextNotMatchingRecipeLayer();

            if (workitemRenderer != null)
            {
                if (layer != 16)
                {
                    workitemRenderer.RegenMesh(workItemStack, Voxels, SelectedRecipe, layer);
                }
            }

            List <Cuboidf> boxes = new List <Cuboidf>();

            bool[,,] recipeVoxels = SelectedRecipe?.Voxels;

            for (int x = 0; x < 16; x++)
            {
                for (int y = 0; y < 16; y++)
                {
                    for (int z = 0; z < 16; z++)
                    {
                        if (y == 0 || Voxels[x, y, z] || (recipeVoxels != null && y == layer && recipeVoxels[x, y, z]))
                        {
                            // Console.WriteLine("box {0} is voxel at {1},{2}", boxes.Count, x, z);
                            boxes.Add(new Cuboidf(x / 16f, y / 16f, z / 16f, x / 16f + 1 / 16f, y / 16f + 1 / 16f, z / 16f + 1 / 16f));
                        }
                    }
                }
            }

            selectionBoxes = boxes.ToArray();
        }
Example #15
0
    private void debugArray(bool[,,] a)
    {
        string dString = "";

        int x = pieceSize.x;
        int y = pieceSize.y;
        int z = pieceSize.z;

        for (int u = 0; u < x; u++)
        {
            for (int v = 0; v < y; v++)
            {
                for (int w = 0; w < z; w++)
                {
                    if (a[u, v, w] == true)
                    {
                        dString += "1 ";
                    }
                    else
                    {
                        dString += "0 ";
                    }
                }
            }
        }
    }
Example #16
0
        public void CheckIfFinished(IPlayer byPlayer)
        {
            if (MatchesRecipe() && api.World is IServerWorldAccessor)
            {
                workItemStack   = null;
                Voxels          = new bool[16, 16, 16];
                AvailableVoxels = 0;
                ItemStack outstack = SelectedRecipe.Output.ResolvedItemstack.Clone();
                selectedRecipeNumber = -1;

                if (outstack.StackSize == 1 && outstack.Class == EnumItemClass.Block)
                {
                    api.World.BlockAccessor.SetBlock(outstack.Block.BlockId, pos);
                    return;
                }

                while (outstack.StackSize > 0)
                {
                    ItemStack dropStack = outstack.Clone();
                    dropStack.StackSize = Math.Min(outstack.StackSize, outstack.Collectible.MaxStackSize);
                    outstack.StackSize -= dropStack.StackSize;

                    if (byPlayer.InventoryManager.TryGiveItemstack(dropStack))
                    {
                        api.World.PlaySoundAt(new AssetLocation("sounds/player/collect"), byPlayer);
                    }
                    else
                    {
                        api.World.SpawnItemEntity(dropStack, pos.ToVec3d().Add(0.5, 0.5, 0.5));
                    }
                }

                api.World.BlockAccessor.SetBlock(0, pos);
            }
        }
Example #17
0
    private bool DetectCollision(bool[,,] block, int blockIndex, Vector2Int position)
    {
        Vector2Int blockSize = new Vector2Int(block.GetLength(2), block.GetLength(1));

        for (int y = 0; y < blockSize.y; y++)
        {
            for (int x = 0; x < blockSize.x; x++)
            {
                if (position.x + x < 0 || position.x + x >= columns || position.y + y < 0)
                {
                    //Debug.Log("blockindex: " + blockIndex + " x: " + x + " y: " + y);
                    if (block[blockIndex, y, x])
                    {
                        return(true);
                    }
                }
                else
                {
                    if (block[blockIndex, y, x] && grid[position.y + y, position.x + x])
                    {
                        return(true);
                    }
                }
            }
        }
        return(false);
    }
        public Life3D(int fieldWidth, int fieldHeight, int fieldDepth, Color cellColor)
        {
            if (fieldWidth < 1)
            {
                throw new ArgumentOutOfRangeException("fieldWidth", "fieldWidth must be >= 1.");
            }
            if (fieldHeight < 1)
            {
                throw new ArgumentOutOfRangeException("fieldHeight", "fieldHeight must be >= 1.");
            }
            if (fieldDepth < 1)
            {
                throw new ArgumentOutOfRangeException("fieldDepth", "fieldDepth must be >= 1.");
            }

            FieldWidth  = fieldWidth;
            FieldHeight = fieldHeight;
            FieldDepth  = fieldDepth;

            CellSize = new Vector3(
                2f / FieldWidth,
                2f / FieldHeight,
                2f / FieldDepth);

            field          = new bool[fieldWidth, fieldHeight, fieldDepth];
            this.cellColor = cellColor;
        }
Example #19
0
        static bool[,,] unmarkThisQuarter(bool[,,] markedQuarters)
        {
            RegistryKey gameKey  = Registry.CurrentUser.CreateSubKey("żabka\\startup", true);
            DateTime    dateTime = DateTime.Now;
            int         val0     = ((int)dateTime.DayOfWeek - 1) % 7;

            if (val0 == -1)
            {
                val0 = 6;
            }
            int val1 = dateTime.Hour;
            int val2 = dateTime.Minute / 15;

            markedQuarters[val0, val1, val2] = false;
            string sAllMarkedQuarters = "";

            for (int x = 0; x < 7; x++)
            {
                for (int y = 0; y < 24; y++)
                {
                    for (int z = 0; z < 4; z++)
                    {
                        if (markedQuarters[x, y, z])
                        {
                            sAllMarkedQuarters += x.ToString() + "," + y.ToString() + "," + z.ToString() + " ";
                        }
                    }
                }
            }
            gameKey.SetValue("markedQuarters", sAllMarkedQuarters);
            gameKey.Close();
            return(markedQuarters);
        }
Example #20
0
        private bool[,,] ProcessChanges3D(bool[,,] changes, bool[,,] configuration)
        {
            var xLength = configuration.GetLength(0);
            var yLength = configuration.GetLength(1);
            var zLength = configuration.GetLength(2);

            for (int x = 0; x < xLength; x++)
            {
                for (int y = 0; y < yLength; y++)
                {
                    for (int z = 0; z < zLength; z++)
                    {
                        if (changes[x, y, z] == true)
                        {
                            if (configuration[x, y, z] == true)
                            {
                                configuration[x, y, z] = false;
                            }
                            else
                            {
                                configuration[x, y, z] = true;
                            }
                        }
                    }
                }
            }

            return(configuration);
        }
Example #21
0
    public void BuildGrid(Vector3 res, bool buildObsMap)
    {
        // lock (workweLock)
        {
            scaledRes   = new Vector3();
            scaledRes.x = bounds.x / res.x;
            scaledRes.z = bounds.z / res.z;
            scaledRes.y = bounds.y / res.y;

            triDPos     = new Vector3[(int)res.x, (int)res.y, (int)res.z];
            obstacleMap = new bool[(int)res.x, (int)res.y, (int)res.z];

            for (int i = 0; i < res.y; i++)
            {
                for (int j = 0; j < res.z; j++)
                {
                    for (int k = 0; k < res.x; k++)
                    {
                        triDPos[k, i, j] = start + new Vector3(scaledRes.x * k, scaledRes.y * i, scaledRes.z * j);
                    }
                }
            }
            //if (buildObsMap)
            //{
            //    BuildObstacleMap();
            //}
        }

        // StartCoroutine(CheckGrid());
    }
    // Use this for initialization
    void Start()
    {
        cubeScale       = Vector3.one * 0.9f * pointGap;
        numPointsCenter = new Vector3(numPointsX, numPointsY, numPointsZ);
        numPointsCenter = numPointsCenter / 2.0f;
        voxels          = new bool[numPointsX, numPointsY, numPointsZ];
        int i, j, k;

        minPointRadius = Mathf.Min(numPointsCenter.x, numPointsCenter.y);
        minPointRadius = Mathf.Min(minPointRadius, numPointsCenter.y);
        for (i = 0; i < numPointsX; i++)
        {
            for (j = 0; j < numPointsY; j++)
            {
                for (k = 0; k < numPointsZ; k++)
                {
                    //if (Random.Range(0, 10) < 6) {
                    //	voxels[i, j, k] = true;
                    //}

                    voxels[i, j, k] = (new Vector3(i, j, k) - numPointsCenter).magnitude <= minPointRadius;
                }
            }
        }
    }
        public void Set_MaxY(int maxY)
        {
            Arr = new bool[A, Arr.GetLength(1), One_Min(maxY)];

            All_Change();      // to avoid illogical remnants at edges, old array cannot be trusted to be relevant
            Calc_Population();
        }
Example #24
0
            private void IterateRules(int iGen)
            {
                var nextGen = new bool[_finalDimXY, _finalDimXY, _finalDimWZ];

                // Only live cubes are from CycleCount - iGen to CycleCount + _dimInput + iGen in x and y directions and
                // from CycleCount - iGen to CycleCount + iGen in the Z direction.

                for (var iRow = CycleCount - iGen; iRow < CycleCount + _dimInput + iGen; iRow++)
                {
                    for (var iCol = CycleCount - iGen; iCol < CycleCount + _dimInput + iGen; iCol++)
                    {
                        for (var iPlane = CycleCount - iGen; iPlane <= CycleCount + iGen; iPlane++)
                        {
                            var  count = CountNeighbors(iRow, iCol, iPlane);
                            bool newVal;
                            var  oldVal = _universe3[iRow, iCol, iPlane];
                            if (oldVal)
                            {
                                newVal = (count == 2 || count == 3);
                            }
                            else
                            {
                                newVal = count == 3;
                            }

                            nextGen[iRow, iCol, iPlane] = newVal;
                        }
                    }
                }

                _universe3 = nextGen;
            }
Example #25
0
    void Start()
    {
        levelMatrix             = new bool[100, 100, 100];
        levelMatrix[50, 50, 50] = true;

        GenerateLevel(MainRooms, Corridors, SideRooms, StartRoom, MinTilesBeforeExit, MaxTilesBeforeExit, MaxTilesTotal);
    }
    static void Check(string[,] matrix, bool[, ,] used, int row, int col)
    {
        // Checking all directions
        for (int direction = 0; direction < directions.GetLength(0); direction++)
        {
            // Skip if current direction is checked
            if (used[row, col, direction])
            {
                continue;
            }

            int currentSum = 0;
            int currentRow = row;
            int currentCol = col;

            // Building current sequence
            while (IsTraversable(matrix, currentRow, currentCol) &&
                   matrix[row, col] == matrix[currentRow, currentCol])
            {
                currentSum++;
                used[currentRow, currentCol, direction] = true;
                currentRow += directions[direction, 0];
                currentCol += directions[direction, 1];
            }

            // Saving current best sequence
            if (currentSum > maxSum)
            {
                maxSum   = currentSum;
                maxValue = matrix[row, col];
            }
        }
    }
Example #27
0
    // returns the number of rows completed after placing a shape
    public int chackRowsComplete(bool [,,] grid)
    {
        int maxCount = 0;
        int counter  = 0;

        for (int i = 0; i < Grid.DEPTH; i++)
        {
            for (int j = 0; j < Grid.HEIGHT; j++)
            {
                for (int k = 0; k < Grid.WIDTH; k++)
                {
                    if (grid [k, i, j])
                    {
                        counter++;
                    }
                }
            }
            if (counter > maxCount)
            {
                maxCount = counter;
            }
            counter = 0;
        }
        return(maxCount);
    }
Example #28
0
    public DiscreteModel(InputModel inputModel, int patternSize, Coord3D outputSize, bool overlapping = true, bool periodic = true, bool addNeighbours = false, bool probabilisticModel = true)
    {
        mapOfChanges            = new bool[outputSize.X, outputSize.Y, outputSize.Z];
        neighboursMap           = new Dictionary <int, Dictionary <Coord3D, List <int> > >();
        this.periodic           = periodic;
        this.probabilisticModel = probabilisticModel;
        this.patternSize        = patternSize;
        numGen = 0;

        this.outputSize = outputSize;

        if (overlapping)
        {
            InitOverlappingModel(inputModel, patternSize, periodic);
            FindNeighbours();
        }
        else
        {
            InitSimpleModel(inputModel, patternSize, false);
            InitNeighboursMap(periodic);
            if (addNeighbours)
            {
                DetectNeighbours();
            }
        }
        InitOutputMatrix(outputSize);

        States         = new Stack <List <int> [, , ]>();
        ChosenPoints   = new List <Coord3D>();
        TotalRollbacks = 0;


        Debug.Log($"Model size: {new Vector3(inputModel.Size.X, inputModel.Size.Y, inputModel.Size.Z)}");
        Debug.Log("Model Ready!");
    }
Example #29
0
        public void CalculateMedialAxis(ref Voxel[,,] grid, ref float[,,] disField, out bool[,,] result)
        {
            int l = grid.GetLength(0);
            int m = grid.GetLength(1);
            int n = grid.GetLength(2);

            result = new bool[l, m, n];
            bool  isEle;
            float sqrtDis;

            for (int i = 0; i < l; ++i)
            {
                for (int j = 0; j < m; ++j)
                {
                    for (int k = 0; k < n; ++k)
                    {
                        isEle = true;

                        for (int x = i != 0 ? -1 : 0; x < (i != (l - 1) ? 2 : 1); ++x)
                        {
                            for (int y = j != 0 ? -1 : 0; y < (j != (m - 1) ? 2 : 1); ++y)
                            {
                                for (int z = k != 0 ? -1 : 0; z < (k != (n - 1) ? 2 : 1); ++z)
                                {
                                    sqrtDis = (float)Math.Sqrt(disField[i, j, k]) + (float)Math.Sqrt(x * x + y * y + z * z);
                                    isEle   = (sqrtDis > Math.Sqrt(disField[i + x, j + y, k + z]) || (x == 0 && y == 0 && z == 0)) ? isEle : false;
                                    //isEle = disField[i, j, k] >= disField[i + x, j + y, k + z] ? isEle : false;
                                }
                            }
                        }
                        result[i, j, k] = isEle && grid[i, j, k].set;
                    }
                }
            }
        }
Example #30
0
        protected override void GenerateTiles(ref bool[,,] _tiles)
        {
            // iterate the chldren
            for (var i = 0; i < transform.childCount; i++)
            {
                // grab the local position/scale
                var pos = transform.GetChild(i).localPosition;
                var sca = transform.GetChild(i).localScale / TileSize;

                // fix to the grid
                var x = Mathf.RoundToInt(pos.x / TileSize);
                var y = Mathf.RoundToInt(pos.y / TileSize);
                var z = Mathf.RoundToInt(pos.z / TileSize);

                // iterate the size of the transform
                for (var ix = x; ix < x + Mathf.RoundToInt(sca.x); ix++)
                {
                    for (var iy = y; iy < y + Mathf.RoundToInt(sca.y); iy++)
                    {
                        for (var iz = z; iz < z + Mathf.RoundToInt(sca.z); iz++)
                        {
                            // validate
                            if (ix < 0 || ix >= MAX_TILES_X || iy < 0 | iy >= MAX_TILES_Y || iz < 0 || iz >= MAX_TILES_Z)
                            {
                                continue;
                            }

                            // add the tile
                            _tiles[ix, iy, iz] = true;
                        }
                    }
                }
            }
        }
Example #31
0
 public MazeGen(int mazeSizeX, int mazeSizeY, int mazeSizeZ, int seed, int cellSize, int smooth)
 {
     try
     {
         myMaze = new Maze();
         myMaze.GenerateMaze(mazeSizeX, mazeSizeY, mazeSizeZ, seed, smooth);
         Voxels = myMaze.GetMaze(mazeSizeX * 2, mazeSizeY * 2, cellSize);
     }
     catch (Exception e)
     {
         // log
     }
 }
Example #32
0
File: Map.cs Project: bilwis/SH2RL
 /// <summary>
 /// This function initiates the recalculation of the sun light level.
 /// </summary>
 public void RecalcSunlight()
 {
     in_sunlight = updateSunMap();       //update the Sun map
     addSunlight(in_sunlight, sun_light);//apply it to the arrays
     prev_sun_light = sun_light;         //store the previous light level
     sun_level_changed = false;
 }
        void Stop()
        {
            m_environment.TerrainOrInteriorChanged -= OnTerrainOrInteriorChanged;

            m_visibilityArray = null;
        }
Example #34
0
 /// <summary>
 /// Creates a 3D world
 /// </summary>        
 public World(int width, int height, int depth)
 {
     worldBlocked = new Boolean[width, height, depth];
 }
Example #35
0
        public void Draw(Vector3 position, float radius, byte color)
        {
            if (myChanges == null)
            {
                myChanges = RequestBools();
                changeCount = 0;
            }

            for (int x = 0; x < data.GetLength(0); x++)
            {
                for (int y = 0; y < data.GetLength(1); y++)
                {
                    for (int z = 0; z < data.GetLength(2); z++)
                    {
                        if (Vector3.Distance(position, transform.localPosition + new Vector3(x, y, z)) < radius)
                        {
                            data[x, y, z] = color;
                            if (!myChanges[x, y, z])
                            {
                                myChanges[x, y, z] = true;
                                changeCount++;
                            }
                        }
                    }
                }
            }
        }
Example #36
0
        public void LoadChunk(BinaryReader reader)
        {
            byte current = 0;
            byte count = 0;

            for (int x = 0; x < data.GetLength(0); x++)
            {
                for (int y = 0; y < data.GetLength(1); y++)
                {
                    for (int z = 0; z < data.GetLength(2); z++)
                    {
                        if (count == 0)
                        {
                            count = reader.ReadByte();
                            current = reader.ReadByte();
                            if (current >= MarchingCubes.Builder.colorMap.Length)
                            {
                                Debug.LogError("Malformed data from server: " + current, this);
                                current = 0;

                                //var ms = (MemoryStream)reader.BaseStream;
                                //ms.Position = ms.Length;
                                return;
                            }

                            if (count == 0)
                            {
                                Debug.LogError("Count is zero at: " + x + "," + y + "," + z);
                            }
                        }

                        count--;
                        if (current == 0)
                        {
                            continue;
                        }

                        if (data[x, y, z] == 0 || myChanges == null || !myChanges[x, y, z])
                        {
                            data[x, y, z] = current;
                        }

                        if (myChanges != null && myChanges[x, y, z] && data[x, y, z] == current)
                        {
                            myChanges[x, y, z] = false;
                            changeCount--;
                        }
                    }
                }
            }

            if (myChanges != null && changeCount <= 0)
            {
                boolPool.Push(myChanges);
                myChanges = null;
            }
        }
Example #37
0
 public void ResetShadows()
 {
     light = null;
     lightheight = null;
     lightheight = new InfiniteHeightCache();
     chunklighted = null;
     UpdateHeightCache();
     loaded = true;
     light = new InfiniteMapCache();
     chunklighted = new bool[map.MapSizeX / chunksize, map.MapSizeY / chunksize, map.MapSizeZ / chunksize];
 }
Example #38
0
        public bool[,,] Analyze(IProgressListener progress)
        {
            int width = Model.Width;
            int height = Model.Height;
            int depth = Model.Depth;
            exterior = new bool[width, height, depth];

            queue = new Queue<IntVector3>();
            var model = this.Model;

            // Start the scan from the boundary
            for (int x = 0; x < width; ++x)
            {
                for (int y = 0; y < height; ++y)
                {
                    Traverse(x, y, 0);
                    Traverse(x, y, depth - 1);
                }
            }
            for (int x = 0; x < width; ++x)
            {
                for (int z = 0; z < depth; ++z)
                {
                    Traverse(x, 0, z);
                    Traverse(x, height - 1, z);
                }
            }
            for (int y = 0; y < height; ++y)
            {
                for (int z = 0; z < depth; ++z)
                {
                    Traverse(0, y, z);
                    Traverse(width - 1, y, z);
                }
            }

            int numProcessed = 0;

            while (queue.Count > 0)
            {
                var p = queue.Dequeue();
                if (p.X > 0)
                {
                    Traverse(p.X - 1, p.Y, p.Z);
                }
                if (p.X < width - 1)
                {
                    Traverse(p.X + 1, p.Y, p.Z);
                }
                if (p.Y > 0)
                {
                    Traverse(p.X, p.Y - 1, p.Z);
                }
                if (p.Y < height - 1)
                {
                    Traverse(p.X, p.Y + 1, p.Z);
                }
                if (p.Z > 0)
                {
                    Traverse(p.X, p.Y, p.Z - 1);
                }
                if (p.Z < depth - 1)
                {
                    Traverse(p.X, p.Y, p.Z + 1);
                }

                ++numProcessed;

                // this might move the progress bar in a funny way but
                // we can't do better since we don't know how many exterior voxels are there yet
                progress?.Report((double)numProcessed / (numProcessed + queue.Count));
            }

            var ret = exterior;
            exterior = null;
            return ret;
        }
Example #39
0
    void generate(Vector3 voxel)
    {
        int cubes = 0;
        float vx = voxel.x;
        float vy = voxel.y;
        float vz = voxel.z;
        grid = fillGrid (voxel);

        string targetName = "voxel " + vx + "," + vy + "," + vz;

        GameObject target = GameObject.Find (targetName);

        if (target) {
            target.transform.Find ("geometry").gameObject.SetActive (true);
            print ("Reactivating voxel " + voxelName(voxel));
            return;
        }

        print ("instantiating new voxel " + voxelName (voxel));
        GameObject node = new GameObject (targetName);
        node.transform.parent = root;

        GameObject geometry = new GameObject ("geometry");
        geometry.transform.parent = node.transform;
        geometry.AddComponent<MeshFilter> ();
        MeshRenderer mr = geometry.AddComponent<MeshRenderer> ();
        geometry.AddComponent<MeshCollider> ();

        for (int x = 1; x < gridSize +1; x++) {
            for (int y = 1; y < gridSize +1; y++) {
                for (int z = 1; z < gridSize +1; z++) {
                    if (checkPositionEdges (x, y, z)) {
                        cubes++;

                        Transform child = Instantiate (box, new Vector3 ((x + vx * gridSize) * 2, (y + vy * gridSize) * 2, (z + + vz * gridSize) * 2), Quaternion.identity) as Transform;
                        child.parent = geometry.transform;

                        child.gameObject.isStatic = true;
                    }
                }
            }
        }

        MeshFilter[] meshFilters = geometry.GetComponentsInChildren<MeshFilter> ();
        CombineInstance[] combine = new CombineInstance[meshFilters.Length];
        int i = 0;
        while (i < meshFilters.Length) {
            combine [i].mesh = meshFilters [i].sharedMesh;
            combine [i].transform = meshFilters [i].transform.localToWorldMatrix;
            meshFilters [i].gameObject.active = false;
            i++;
        }
        Mesh m = geometry.transform.GetComponent<MeshFilter> ().mesh = new Mesh ();
        geometry.transform.GetComponent<MeshCollider> ().sharedMesh = m;

        Material mat = Resources.Load ("rock", typeof(Material)) as Material;
        mr.material = mat;

        geometry.transform.GetComponent<MeshFilter> ().mesh.CombineMeshes (combine);
        geometry.transform.gameObject.active = true;
    }
        public void InitiateAnimation(Common.LEDAnimations animation, DispatcherTimer timer)
        {
            CurrentAnimation = animation;

            switch (CurrentAnimation)
            {
                case Common.LEDAnimations.RED_LED_ANIMATION:
                    CurrentAnimationArray = RED_LED_ANIMATION;
                    CurrentAnimationMaxFrames = 8;
                    CurrentAnimationFrame = 0;
                    timer.Interval = TimeSpan.FromMilliseconds(200);
                    break;
                case Common.LEDAnimations.GREEN_LED_ANIMATION:
                    CurrentAnimationArray = GREEN_LED_ANIMATION;
                    CurrentAnimationMaxFrames = 8;
                    CurrentAnimationFrame = 0;
                    timer.Interval = TimeSpan.FromMilliseconds(200);
                    break;
                case Common.LEDAnimations.YELLOW_LED_ANIMATION:
                    CurrentAnimationArray = YELLOW_LED_ANIMATION;
                    CurrentAnimationMaxFrames = 8;
                    CurrentAnimationFrame = 0;
                    timer.Interval = TimeSpan.FromMilliseconds(200);
                    break;
                case Common.LEDAnimations.BLUE_LED_ANIMATION:
                    CurrentAnimationArray = BLUE_LED_ANIMATION;
                    CurrentAnimationMaxFrames = 8;
                    CurrentAnimationFrame = 0;
                    timer.Interval = TimeSpan.FromMilliseconds(200);
                    break;
                case Common.LEDAnimations.GAME_START_LED_ANIMATION:
                    CurrentAnimationArray = GAME_START_LED_ANIMATION;
                         CurrentAnimationMaxFrames = 6;
                    CurrentAnimationFrame = 0;
                    timer.Interval = TimeSpan.FromMilliseconds(500);
                    break;
                case Common.LEDAnimations.GAME_OVER_LED_ANIMATION:
                    CurrentAnimationArray = GAME_OVER_LED_ANIMATION;
                    CurrentAnimationMaxFrames = 7;
                    CurrentAnimationFrame = 0;
                    timer.Interval = TimeSpan.FromMilliseconds(500);
                    break;
                case Common.LEDAnimations.FILL:
                    CurrentAnimationArray = FILL_LED_ANIMATION;
                    CurrentAnimationMaxFrames = 18;
                    CurrentAnimationFrame = 0;
                    timer.Interval = TimeSpan.FromMilliseconds(175);
                    break;
                case Common.LEDAnimations.CLEAR:
                    CurrentAnimationArray = CLEAR_LED_ANIMATION;
                    CurrentAnimationMaxFrames = 1;
                    CurrentAnimationFrame = 0;
                    timer.Interval = TimeSpan.FromMilliseconds(175);
                    break;
                default:
                    break;
            }
        }
Example #41
0
 public void ResetShadows()
 {
     light = null;
     lightheight = null;
     lightheight = new InfiniteHeightCache();
     chunklighted = null;
     UpdateHeightCache();
     loaded = true;
 }