コード例 #1
0
        public void Update()
        {
            bool changed = false;

            // SHIFT
            if (InputHelper.IsKeyDown(Keys.LeftShift) || InputHelper.IsKeyDown(Keys.RightShift))
            {
                if (InputHelper.IsNewKeyPress(Keys.Right))
                {
                    if (_RampBlockDirection == RampBlockDirection.North)
                    {
                        _RampBlockDirection = RampBlockDirection.East;
                    }
                    else if (_RampBlockDirection == RampBlockDirection.East)
                    {
                        _RampBlockDirection = RampBlockDirection.South;
                    }
                    else if (_RampBlockDirection == RampBlockDirection.South)
                    {
                        _RampBlockDirection = RampBlockDirection.West;
                    }
                    else if (_RampBlockDirection == RampBlockDirection.West)
                    {
                        _RampBlockDirection = RampBlockDirection.North;
                    }

                    changed = true;
                }

                if (InputHelper.IsNewKeyPress(Keys.Left))
                {
                    if (_RampBlockDirection == RampBlockDirection.North)
                    {
                        _RampBlockDirection = RampBlockDirection.West;
                    }
                    else if (_RampBlockDirection == RampBlockDirection.East)
                    {
                        _RampBlockDirection = RampBlockDirection.North;
                    }
                    else if (_RampBlockDirection == RampBlockDirection.South)
                    {
                        _RampBlockDirection = RampBlockDirection.East;
                    }
                    else if (_RampBlockDirection == RampBlockDirection.West)
                    {
                        _RampBlockDirection = RampBlockDirection.South;
                    }
                    changed = true;
                }
            }
            else
            {
                if (InputHelper.IsNewKeyPress(Keys.Up))
                {
                    switch (_selectedType)
                    {
                    case EditorType.Blocks:
                        _selectedType = EditorType.BottomRamps;
                        break;

                    case EditorType.BottomRamps:
                        _selectedType = EditorType.TopRamps;
                        break;

                    case EditorType.TopRamps:
                        _selectedType = EditorType.Blocks;
                        break;

                    default:
                        _previewData = new BlockVertexData();
                        break;
                    }
                    changed = true;
                }

                if (InputHelper.IsNewKeyPress(Keys.Down))
                {
                    switch (_selectedType)
                    {
                    case EditorType.Blocks:
                        _selectedType = EditorType.TopRamps;
                        break;

                    case EditorType.BottomRamps:
                        _selectedType = EditorType.Blocks;
                        break;

                    case EditorType.TopRamps:
                        _selectedType = EditorType.BottomRamps;
                        break;

                    default:
                        _previewData = new BlockVertexData();
                        break;
                    }
                    changed = true;
                }

                if (InputHelper.IsNewKeyPress(Keys.Right))
                {
                    _index++;

                    if (_index >= CountCurrentList())
                    {
                        _index = 0;
                    }
                    changed = true;
                }

                if (InputHelper.IsNewKeyPress(Keys.Left))
                {
                    _index--;

                    if (_index < 0)
                    {
                        _index = CountCurrentList() - 1;
                    }
                    changed = true;
                }
            }

            if (changed)
            {
                switch (_selectedType)
                {
                case EditorType.Blocks:
                    _activeBlockMask = _blockMasks[_index];
                    _previewData     = BlockVertexData.GetBlockMaskVertexData(_blockMasks[_index]).Copy();
                    break;

                case EditorType.BottomRamps:
                    _activeBlockMask = _bottomRampMasks[_index] | _RampBlockDirection;
                    _previewData     = RampBlockVertexData.GetBlockMaskVertexData(_bottomRampMasks[_index] | _RampBlockDirection).Copy();
                    break;

                case EditorType.TopRamps:
                    _activeBlockMask = _topRampMasks[_index] | _RampBlockDirection;
                    _previewData     = RampBlockVertexData.GetBlockMaskVertexData(_topRampMasks[_index] | _RampBlockDirection).Copy();
                    break;

                default:
                    _previewData = new BlockVertexData();
                    break;
                }
            }

            HandleHighlight();
        }
コード例 #2
0
        public void UpdateDrawModule()
        {
            DebugLog.Log("Updating RenderChunk: (" + ParentRenderSegment.Position.X + ", " + _heightOffset + ", " + ParentRenderSegment.Position.Y + ");");
            for (int x = 0; x < Blocks.GetLength(0); x++)
            {
                for (int y = 0; y < Blocks.GetLength(1); y++)
                {
                    for (int z = 0; z < Blocks.GetLength(2); z++)
                    {
                        if (Blocks[x, y, z] != BlockHelper.BlockMasks.Air && Blocks[x, y, z] != BlockHelper.BlockMasks.AirBlocked)
                        {
                            BlockVertexData currentVertextData = new BlockVertexData();
                            Vector3         blockLocation      = new Vector3(x, y, z) + _locationOffset;
                            if (BlockHelper.IsBlock(Blocks[x, y, z]))
                            {
                                currentVertextData = BlockVertexData.GetCopyOfBlockMasBlockVertexData(Blocks[x, y, z]);
                            }
                            else if (BlockHelper.IsRampBlock(Blocks[x, y, z]))
                            {
                                currentVertextData = RampBlockVertexData.GetBlockMaskVertexData(Blocks[x, y, z]);
                            }

                            currentVertextData.TranslateToWorldLocation(blockLocation);

                            // Following checks all the face blocking cubes around the current location to see if we'll add the vertices to the buffer or not.
                            if (!BlockHelper.DoesBlockMaskAObscureMaskBFace(ParentRenderSegment.ParentSegmentManager.GetBlockMaskAt(new SegmentLocation(blockLocation + WorldDirection.Up)), Blocks[x, y, z], WorldDirection.Up))
                            {
                                _blockDrawModule.AddData(currentVertextData.UpVertices.ToList(),
                                                         currentVertextData.UpIndices.ToList());
                            }
                            if (!BlockHelper.DoesBlockMaskAObscureMaskBFace(ParentRenderSegment.ParentSegmentManager.GetBlockMaskAt(new SegmentLocation(blockLocation + WorldDirection.Down)), Blocks[x, y, z], WorldDirection.Down))
                            {
                                _blockDrawModule.AddData(currentVertextData.DownVertices.ToList(),
                                                         currentVertextData.DownIndices.ToList());
                            }
                            if (!BlockHelper.DoesBlockMaskAObscureMaskBFace(ParentRenderSegment.ParentSegmentManager.GetBlockMaskAt(new SegmentLocation(blockLocation + WorldDirection.North)), Blocks[x, y, z], WorldDirection.North))
                            {
                                _blockDrawModule.AddData(currentVertextData.NorthVertices.ToList(),
                                                         currentVertextData.NorthIndices.ToList());
                            }
                            if (!BlockHelper.DoesBlockMaskAObscureMaskBFace(ParentRenderSegment.ParentSegmentManager.GetBlockMaskAt(new SegmentLocation(blockLocation + WorldDirection.East)), Blocks[x, y, z], WorldDirection.East))
                            {
                                // add east vertices/indices, but don't forget to translate to world location...
                                _blockDrawModule.AddData(currentVertextData.EastVertices.ToList(),
                                                         currentVertextData.EastIndices.ToList());
                            }
                            if (!BlockHelper.DoesBlockMaskAObscureMaskBFace(ParentRenderSegment.ParentSegmentManager.GetBlockMaskAt(new SegmentLocation(blockLocation + WorldDirection.South)), Blocks[x, y, z], WorldDirection.South))
                            {
                                // add east vertices/indices, but don't forget to translate to world location...
                                _blockDrawModule.AddData(currentVertextData.SouthVertices.ToList(),
                                                         currentVertextData.SouthIndices.ToList());
                            }
                            if (!BlockHelper.DoesBlockMaskAObscureMaskBFace(ParentRenderSegment.ParentSegmentManager.GetBlockMaskAt(new SegmentLocation(blockLocation + WorldDirection.West)), Blocks[x, y, z], WorldDirection.West))
                            {
                                // add east vertices/indices, but don't forget to translate to world location...
                                _blockDrawModule.AddData(currentVertextData.WestVertices.ToList(),
                                                         currentVertextData.WestIndices.ToList());
                            }
                        }
                    }
                }
            }
            _blockDrawModule.PrepareToDraw();

            Dirty = false;
        }