public override bool RegenerateMesh(ChunkMesher mesher) { Mesh m = mesher.GenerateMesh(this); if (m == null && renderer == null) { return(true); } if (m != null && renderer == null) { renderer = world.CreateChunkRenderer(this); } if (m != null) { renderer.Update(m); } renderer?.SetActive(m != null); return(true); }
protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } chunkRenderer.Update(gameTime); if (!chunkRenderer.IsReady) { return; } if (IsActive) { Camera.Update(); } if (Keyboard.GetState().IsKeyDown(Keys.W)) { Camera.Move(new Vector3(0, 0, -1)); } if (Keyboard.GetState().IsKeyDown(Keys.A)) { Camera.Move(new Vector3(-1, 0, 0)); } if (Keyboard.GetState().IsKeyDown(Keys.S)) { Camera.Move(new Vector3(0, 0, 1)); } if (Keyboard.GetState().IsKeyDown(Keys.D)) { Camera.Move(new Vector3(1, 0, 0)); } if (Keyboard.GetState().IsKeyDown(Keys.Space)) { Camera.Move(new Vector3(0, 1, 0)); } if (Keyboard.GetState().IsKeyDown(Keys.LeftControl)) { Camera.Move(new Vector3(0, -1, 0)); } if (Keyboard.GetState().IsKeyDown(Keys.Up)) { Camera.Velocity *= 1.05f; } if (Keyboard.GetState().IsKeyDown(Keys.Down)) { Camera.Velocity /= 1.05f; } if (!pressed && Keyboard.GetState().IsKeyDown(Keys.Y)) { pressed = true; chunkRenderer.expandWorld(ChunkRenderer.Direction.Forward); } if (Keyboard.GetState().IsKeyUp(Keys.Y)) { pressed = false; } for (int i = 0; i < chunkRenderer.Chunks.Length; i++) { if (chunkRenderer.Chunks[i].ChunkBoundingBox.Contains(Camera.CameraPosition) == ContainmentType.Contains) { currentChunk = chunkRenderer.Chunks[i]; break; } } base.Update(gameTime); }