예제 #1
0
        private void RecacheChunks()
        {
            this._player.CurrentChunk = this.GetChunk((int) _player.Position.X, (int) _player.Position.Z);

            for (int z = -CacheRange; z <= CacheRange; z++)
            {
                for (int x = -CacheRange; x <= CacheRange; x++)
                {
                    if (this._chunkStorage.ContainsKey(this._player.CurrentChunk.RelativePosition.X + x, this._player.CurrentChunk.RelativePosition.Z + z))
                        continue;

                    var chunk = new Chunk(new Vector2Int(this._player.CurrentChunk.RelativePosition.X + x, this._player.CurrentChunk.RelativePosition.Z + z));
                    this._chunkStorage[chunk.RelativePosition.X, chunk.RelativePosition.Z] = chunk;
                }
            }

            var southWestEdge = new Vector2Int(this._player.CurrentChunk.RelativePosition.X - ViewRange, this._player.CurrentChunk.RelativePosition.Z - ViewRange);
            var northEastEdge = new Vector2Int(this._player.CurrentChunk.RelativePosition.X + ViewRange, this._player.CurrentChunk.RelativePosition.Z + ViewRange);

            BoundingBox = new BoundingBox(
                    new Vector3(southWestEdge.X*Chunk.WidthInBlocks, 0, southWestEdge.Z*Chunk.LenghtInBlocks),
                    new Vector3((northEastEdge.X + 1)*Chunk.WidthInBlocks, Chunk.HeightInBlocks,
                                (northEastEdge.Z + 1)*Chunk.LenghtInBlocks));
        }
예제 #2
0
파일: Player.cs 프로젝트: knocte/voxeliq
 public void SpawnPlayer(Vector2Int relativePosition)
 {
     this.RelativePosition = relativePosition;
     this.Position = new Vector3(relativePosition.X*Chunk.WidthInBlocks, 150,
                                 relativePosition.Z*Chunk.LenghtInBlocks);
     this._world.SpawnPlayer(relativePosition);
 }
예제 #3
0
파일: World.cs 프로젝트: nerdshark/voxeliq
        public void SpawnPlayer(Vector2Int relativePosition)
        {
            //Profiler.Start("terrain-generation");
            for (int z = -ChunkCache.CacheRange; z <= ChunkCache.CacheRange; z++)
            {
                for (int x = -ChunkCache.CacheRange; x <= ChunkCache.CacheRange; x++)
                {
                    var chunk = new Chunk(new Vector2Int(relativePosition.X + x, relativePosition.Z + z));
                    this.Chunks[chunk.RelativePosition.X, chunk.RelativePosition.Z] = chunk;

                    if (chunk.RelativePosition == relativePosition) this._player.CurrentChunk = chunk;
                }
            }

            this.Chunks.SouthWestEdge = new Vector2Int(relativePosition.X - ChunkCache.ViewRange,
                                                       relativePosition.Z - ChunkCache.ViewRange);
            this.Chunks.NorthEastEdge = new Vector2Int(relativePosition.X + ChunkCache.ViewRange,
                                                       relativePosition.Z + ChunkCache.ViewRange);

            ChunkCache.BoundingBox =
                new BoundingBox(
                    new Vector3(this.Chunks.SouthWestEdge.X*Chunk.WidthInBlocks, 0, this.Chunks.SouthWestEdge.Z*Chunk.LenghtInBlocks),
                    new Vector3((this.Chunks.NorthEastEdge.X + 1)*Chunk.WidthInBlocks, Chunk.HeightInBlocks, (this.Chunks.NorthEastEdge.Z + 1)*Chunk.LenghtInBlocks));
        }
예제 #4
0
파일: Chunk.cs 프로젝트: nerdshark/voxeliq
        /// <summary>
        /// Creates a new chunk instance.
        /// </summary>
        /// <param name="relativePosition">The relative position of the chunk.</param>
        public Chunk(Vector2Int relativePosition)
        {
            this.ChunkState = ChunkState.AwaitingGenerate; // set initial state to awaiting generation.
            this.RelativePosition = relativePosition; // set the relative position.

            // calculate the real world position.
            this.WorldPosition = new Vector2Int(this.RelativePosition.X*WidthInBlocks,
                                                this.RelativePosition.Z*LenghtInBlocks);

            // calculate bounding-box.
            this.BoundingBox = new BoundingBox(new Vector3(WorldPosition.X, 0, WorldPosition.Z),
                                               new Vector3(this.WorldPosition.X + WidthInBlocks, HeightInBlocks,
                                                           this.WorldPosition.Z + LenghtInBlocks));

            // create vertex & index lists.
            this.VertexList = new List<BlockVertex>();
            this.IndexList = new List<short>();
        }