예제 #1
0
        public int GetTerrainHeight(Vector3 position)
        {
            WorldModelHelper.GetLocalXyzFromWorldPosition(position, out int x, out int y, out int z);
            var coords = WorldModelHelper.GetChunkCoordsFromWorldPosition(position);

            return(_heights[coords][x * GeometryConsts.CHUNK_SIZE + z]);
        }
예제 #2
0
        public bool CheckVoxelOnGlobalXyz(float x, float y, float z)
        {
            var coords   = WorldModelHelper.GetChunkCoordsFromWorldXy(x, z);
            var chunkMap = GetMapByChunkCoords(coords);

            WorldModelHelper.GetLocalXyzFromWorldPosition(x, y, z, out int xOut, out int yOut, out int zOut);


            return(chunkMap[ArrayHelper.To1DMap(xOut, yOut, zOut)] != BlockTypeByte.AIR);
        }
예제 #3
0
        public void EditVoxel(Vector3 position, byte voxelType)
        {
            WorldModelHelper.GetLocalXyzFromWorldPosition(position, out int x, out int y, out int z);
            var coords = WorldModelHelper.GetChunkCoordsFromWorldPosition(position);

            var id = ArrayHelper.To1DMap(x, y, z);

            var map = _chunkMaps[coords];

            map[id] = voxelType;

            //update voxel in chunk map
            _chunkMaps[coords] = map;

            //update voxel in user player modifications map
            //so that data can persist when we clean distant chunks from memory and can be used to save / load game
            if (!_playerModifiedMaps.ContainsKey(coords))
            {
                _playerModifiedMaps[coords] = new byte[GeometryConsts.CHUNK_SIZE, GeometryConsts.CHUNK_HEIGHT, GeometryConsts.CHUNK_SIZE];
            }

            _playerModifiedMaps[coords][x, y, z] = voxelType;

            //TODO: chunks update should not be called directly from model!
            //Also get chunks list in less ugly way than this hardcoded shiat
            var updateCoords = new List <int2>();

            updateCoords.Add(coords);

            if (x <= 0)
            {
                updateCoords.Add(coords + ChunkCoord.Left);
            }
            else if (x >= GeometryConsts.CHUNK_SIZE - 1)
            {
                updateCoords.Add(coords + ChunkCoord.Right);
            }

            if (z <= 0)
            {
                updateCoords.Add(coords + ChunkCoord.Back);

                if (x <= 0)
                {
                    updateCoords.Add(coords + ChunkCoord.LeftBack);
                }
                else if (x >= GeometryConsts.CHUNK_SIZE - 1)
                {
                    updateCoords.Add(coords + ChunkCoord.RightBack);
                }
            }
            else if (z >= GeometryConsts.CHUNK_SIZE - 1)
            {
                updateCoords.Add(coords + ChunkCoord.Front);

                if (x <= 0)
                {
                    updateCoords.Add(coords + ChunkCoord.LeftFront);
                }
                else if (x >= GeometryConsts.CHUNK_SIZE - 1)
                {
                    updateCoords.Add(coords + ChunkCoord.RightFront);
                }
            }

            WorldRenderer.RenderChunks(updateCoords, updateCoords);
        }