Exemple #1
0
        public void UpdateCurrentCursor(ChunkManager chunkManager, World world)
        {
            CurrentCursor = CollisionHelper.GetCurrentSelection(new Ray(Position, LookAt), chunkManager);

            if (chunkManager.TryGetVoxel(Position.Round(), out var voxel) &&
                voxel.BlockType == VoxelDefinition.Water.Type)
            {
                IsInWater = true;
            }
            else
            {
                IsInWater = false;
            }
        }
Exemple #2
0
        private string BuildLeftText(ChunkManager chunkManager, Camera camera, Game game)
        {
            var targetInfo = camera.CurrentCursor == null
                ? "No target"
                : $"{camera.CurrentCursor.AbsoluteVoxelIndex} (BlockType: {camera.CurrentCursor.Voxel.BlockType}, Light: {camera.CurrentCursor.Voxel.CompositeLight})";

            var targetTargetInfo = "No target target";

            if (camera.CurrentCursor != null)
            {
                if (chunkManager.TryGetVoxel(camera.CurrentCursor.AbsoluteVoxelIndex + camera.CurrentCursor.Direction, out var targetTarget))
                {
                    if (chunkManager.TryGetVoxelAddress(
                            camera.CurrentCursor.AbsoluteVoxelIndex + camera.CurrentCursor.Direction, out var address))
                    {
                        targetTargetInfo =
                            $"BlockType: {targetTarget.BlockType}, Sun: {targetTarget.Sunlight}, Light: {targetTarget.EmittedLight}" +
                            $"Chunk: {address.Chunk.ChunkIndex.X}, {address.Chunk.ChunkIndex.Y}, " +
                            $"Voxel: {address.RelativeVoxelIndex.X}, {address.RelativeVoxelIndex.Y}, {address.RelativeVoxelIndex.Z}";
                    }
                    else
                    {
                        throw new Exception("that should not happen i guess");
                    }
                }
            }

            return //$"Finalized chunks {chunkManager.FinalizedChunks:N0}\r\n" +
                   //$"Rendered chunks {chunkManager.RenderedChunks:N0}\r\n" +
                   //$"Queued chunks {chunkManager.QueuedChunks:N0}\r\n" +
                   //$"Total visible faces {chunkManager.TotalVisibleFaces:N0}\r\n" +
                   //$"Total visible voxels {chunkManager.TotalVisibleVoxels:N0}\r\n" +
                   ($"Time: {game.World.Time:N2}\r\n" +
                    $"Current position {camera.Position.ToNonRetardedString()}\r\n" +
                    $"Orientation {camera.LookAt.ToNonRetardedString()}\r\n" +
                    $"Current target {targetInfo}\r\n" +
                    $"Target target: {targetTargetInfo}\r\n" +
                    $"Back-face culling [F1]: {(Game.IsBackFaceCullingEnabled ? "On" : "Off")}\r\n" +
                    $"View frustum culling [F2]: {(Game.IsViewFrustumCullingEnabled ? "On" : "Off")}\r\n" +
                    $"Show chunk boxes [F3]: {(Game.ShowChunkBoundingBoxes ? "On" : "Off")}\r\n");
        }
Exemple #3
0
        private void HandleDefaultInputs(ChunkManager chunkManager)
        {
            if (_lastMouseState == null)
            {
                return;
            }

            const int leftClickIndex  = 0;
            const int rightClickIndex = 1;

            if (!_currentKeyboardState.IsPressed(Key.Escape) && _lastKeyboardState.IsPressed(Key.Escape))
            {
                IsPaused = !IsPaused;
            }

            if (!_currentKeyboardState.IsPressed(Key.F1) && _lastKeyboardState.IsPressed(Key.F1))
            {
                Game.RenderSolid = !Game.RenderSolid;
            }

            if (!_currentKeyboardState.IsPressed(Key.F2) && _lastKeyboardState.IsPressed(Key.F2))
            {
                Game.RenderWater = !Game.RenderWater;
            }

            if (!_currentKeyboardState.IsPressed(Key.F3) && _lastKeyboardState.IsPressed(Key.F3))
            {
                Game.RenderSprites = !Game.RenderSprites;
            }

            if (!_currentKeyboardState.IsPressed(Key.F4) && _lastKeyboardState.IsPressed(Key.F4))
            {
                Game.RenderBoxes = !Game.RenderBoxes;
            }

            if (!_currentKeyboardState.IsPressed(Key.F5) && _lastKeyboardState.IsPressed(Key.F5))
            {
                Game.ShowChunkBoundingBoxes = !Game.ShowChunkBoundingBoxes;
            }

            if (!_currentKeyboardState.IsPressed(Key.F6) && _lastKeyboardState.IsPressed(Key.F6))
            {
                Game.RenderSky = !Game.RenderSky;
            }

            if (!_currentKeyboardState.IsPressed(Key.F7) && _lastKeyboardState.IsPressed(Key.F7))
            {
                Game.ShowPipelineVisualization = !Game.ShowPipelineVisualization;
            }

            if (!_currentKeyboardState.IsPressed(Key.F12) && _lastKeyboardState.IsPressed(Key.F12))
            {
                Game.Debug = !Game.Debug;
            }

            var delta = _currentMouseState.Z / 120;

            if (delta != 0)
            {
                _voxelDefinitionIndexInHand += delta;
                if (_voxelDefinitionIndexInHand < 0)
                {
                    _voxelDefinitionIndexInHand = VoxelDefinition.RegisteredDefinitions.Count - 1;
                }
                else
                {
                    _voxelDefinitionIndexInHand %= VoxelDefinition.RegisteredDefinitions.Count;
                }

                VoxelInHand = VoxelDefinition.DefinitionByType[VoxelDefinition.RegisteredDefinitions[_voxelDefinitionIndexInHand]];
            }

            if (DateTime.Now - _lastModification > BuildCooldown)
            {
                if (_currentMouseState.Buttons[leftClickIndex])
                {
                    if (CurrentCursor != null)
                    {
                        _lastModification = DateTime.Now;
                        chunkManager.SetBlock(CurrentCursor.AbsoluteVoxelIndex, 0);
                    }
                }

                if (_currentMouseState.Buttons[rightClickIndex])
                {
                    if (CurrentCursor != null)
                    {
                        chunkManager.TryGetVoxel(CurrentCursor.AbsoluteVoxelIndex, out var directTargetVoxel);
                        var targetBlock = directTargetVoxel.GetDefinition().IsSprite
                            ? CurrentCursor.AbsoluteVoxelIndex
                            : CurrentCursor.AbsoluteVoxelIndex + CurrentCursor.Direction;

                        var hasPositionConflict = false;
                        var min = (WorldSettings.PlayerMin + Position).Round();
                        var max = (WorldSettings.PlayerMax + Position).Round();
                        for (var i = min.X; i <= max.X && !hasPositionConflict; i++)
                        {
                            for (var j = min.Y; j <= max.Y && !hasPositionConflict; j++)
                            {
                                for (var k = min.Z; k <= max.Z && !hasPositionConflict; k++)
                                {
                                    hasPositionConflict = targetBlock == new Int3(i, j, k);
                                }
                            }
                        }

                        if (!hasPositionConflict)
                        {
                            _lastModification = DateTime.Now;
                            chunkManager.SetBlock(targetBlock, VoxelInHand.Type);
                        }
                    }
                }
            }
        }