diff --git a/OctoAwesome/OctoAwesome.Client/Components/ChunkRenderer.cs b/OctoAwesome/OctoAwesome.Client/Components/ChunkRenderer.cs
index 285215cb..499bef9f 100644
--- a/OctoAwesome/OctoAwesome.Client/Components/ChunkRenderer.cs
+++ b/OctoAwesome/OctoAwesome.Client/Components/ChunkRenderer.cs
@@ -18,19 +18,31 @@ internal sealed class ChunkRenderer : IDisposable
private Texture2D textures;
+ ///
+ /// Gibt an ob der aktuelle Chunk geladen wurde
+ ///
+ private bool chunkLoaded;
+
+ ///
+ /// Referenz auf den aktuellen Chunk (falls vorhanden)
+ ///
+ private IChunk chunk;
+
private VertexBuffer vb;
private IndexBuffer ib;
private int vertexCount;
private int indexCount;
private int lastReset;
- public IChunk Chunk { get; private set; }
-
- public Index3 ChunkIndex { get; private set; }
-
- public Index3 RelativeIndex { get; set; }
+ ///
+ /// Referenz auf den aktuell gerenderten Chunk
+ ///
+
- public bool InUse { get; set; }
+ ///
+ /// Adresse des aktuellen Chunks
+ ///
+ public PlanetIndex3? ChunkPosition { get; private set; }
public ChunkRenderer(GraphicsDevice graphicsDevice, Matrix projection, Texture2D textures)
{
@@ -51,28 +63,36 @@ public ChunkRenderer(GraphicsDevice graphicsDevice, Matrix projection, Texture2D
effect.FogColor = new Color(181, 224, 255).ToVector3();
effect.FogStart = SceneComponent.VIEWRANGE * OctoAwesome.Chunk.CHUNKSIZE_X * 0.5f;
effect.FogEnd = SceneComponent.VIEWRANGE * OctoAwesome.Chunk.CHUNKSIZE_X * 0.9f;
-
- InUse = false;
}
- public void SetChunk(IChunk chunk)
+ public void SetChunk(PlanetIndex3? index)
{
- ChunkIndex = chunk != null ? chunk.Index : new Index3(0, 0, 0);
- Chunk = chunk;
- RegenerateVertexBuffer();
+ ChunkPosition = index;
+ chunkLoaded = false;
+ chunk = null;
}
public bool NeedUpdate()
{
- if (!InUse || Chunk == null)
+ // Kein Chunk selektiert -> kein Update notwendig
+ if (!ChunkPosition.HasValue)
return false;
- return Chunk.ChangeCounter > lastReset;
+ // Selektierter Chunk noch nicht geladen -> Update
+ if (!chunkLoaded)
+ return true;
+
+ // Chunk vollständig geladen aber nicht vorahden -> kein Update
+ if (chunk == null)
+ return false;
+
+ // Chunk geladen und existient -> nur Update, wenn sich seit dem letzten Reset was verändert hat.
+ return chunk.ChangeCounter > lastReset;
}
public void Draw(CameraComponent camera, Index3 shift)
{
- if (!InUse || Chunk == null)
+ if (chunk == null)
return;
effect.World = Matrix.CreateTranslation(
@@ -100,7 +120,20 @@ public void Draw(CameraComponent camera, Index3 shift)
public void RegenerateVertexBuffer()
{
- if (Chunk == null)
+ if (!ChunkPosition.HasValue)
+ return;
+
+ // Chunk nachladen
+ if (!chunkLoaded)
+ {
+ chunk = ResourceManager.Instance.GetChunk(
+ ChunkPosition.Value.Planet,
+ ChunkPosition.Value.ChunkIndex);
+ chunkLoaded = true;
+ }
+
+ // Ignorieren, falls
+ if (chunk == null)
return;
List vertices = new List();
@@ -127,7 +160,7 @@ public void RegenerateVertexBuffer()
{
for (int x = 0; x < OctoAwesome.Chunk.CHUNKSIZE_X; x++)
{
- IBlock block = Chunk.GetBlock(x, y, z);
+ IBlock block = chunk.GetBlock(x, y, z);
if (block == null)
continue;
@@ -145,7 +178,7 @@ public void RegenerateVertexBuffer()
Vector2 textureSize = new Vector2(textureWidth - 0.005f, textureWidth - 0.005f);
// Top
- if (z == OctoAwesome.Chunk.CHUNKSIZE_Z - 1 || Chunk.GetBlock(new Index3(x, y, z + 1)) == null)
+ if (z == OctoAwesome.Chunk.CHUNKSIZE_Z - 1 || chunk.GetBlock(new Index3(x, y, z + 1)) == null)
{
textureOffset = new Vector2(
(((textureIndex + definition.GetTopTextureIndex(block)) % textureColumns) * textureWidth) + 0.002f,
@@ -173,7 +206,7 @@ public void RegenerateVertexBuffer()
}
// Unten
- if (z == 0 || Chunk.GetBlock(new Index3(x, y, z - 1)) == null)
+ if (z == 0 || chunk.GetBlock(new Index3(x, y, z - 1)) == null)
{
textureOffset = new Vector2(
(((textureIndex + definition.GetBottomTextureIndex(block)) % textureColumns) * textureWidth) + 0.002f,
@@ -201,7 +234,7 @@ public void RegenerateVertexBuffer()
}
// South
- if (y == OctoAwesome.Chunk.CHUNKSIZE_Y - 1 || Chunk.GetBlock(new Index3(x, y + 1, z)) == null)
+ if (y == OctoAwesome.Chunk.CHUNKSIZE_Y - 1 || chunk.GetBlock(new Index3(x, y + 1, z)) == null)
{
textureOffset = new Vector2(
(((textureIndex + definition.GetSouthTextureIndex(block)) % textureColumns) * textureWidth) + 0.002f,
@@ -230,7 +263,7 @@ public void RegenerateVertexBuffer()
}
// North
- if (y == 0 || Chunk.GetBlock(new Index3(x, y - 1, z)) == null)
+ if (y == 0 || chunk.GetBlock(new Index3(x, y - 1, z)) == null)
{
textureOffset = new Vector2(
(((textureIndex + definition.GetNorthTextureIndex(block)) % textureColumns) * textureWidth) + 0.002f,
@@ -258,7 +291,7 @@ public void RegenerateVertexBuffer()
}
// West
- if (x == 0 || Chunk.GetBlock(new Index3(x - 1, y, z)) == null)
+ if (x == 0 || chunk.GetBlock(new Index3(x - 1, y, z)) == null)
{
textureOffset = new Vector2(
(((textureIndex + definition.GetWestTextureIndex(block)) % textureColumns) * textureWidth) + 0.002f,
@@ -286,7 +319,7 @@ public void RegenerateVertexBuffer()
}
// Ost
- if (x == OctoAwesome.Chunk.CHUNKSIZE_X - 1 || Chunk.GetBlock(new Index3(x + 1, y, z)) == null)
+ if (x == OctoAwesome.Chunk.CHUNKSIZE_X - 1 || chunk.GetBlock(new Index3(x + 1, y, z)) == null)
{
textureOffset = new Vector2(
(((textureIndex + definition.GetEastTextureIndex(block)) % textureColumns) * textureWidth) + 0.002f,
@@ -350,7 +383,7 @@ public void RegenerateVertexBuffer()
if (ibOld != null)
ibOld.Dispose();
- lastReset = Chunk.ChangeCounter;
+ lastReset = chunk.ChangeCounter;
}
public void Dispose()
diff --git a/OctoAwesome/OctoAwesome.Client/Components/GamePadInput.cs b/OctoAwesome/OctoAwesome.Client/Components/GamePadInput.cs
index bdea05e2..4efd47af 100644
--- a/OctoAwesome/OctoAwesome.Client/Components/GamePadInput.cs
+++ b/OctoAwesome/OctoAwesome.Client/Components/GamePadInput.cs
@@ -59,6 +59,8 @@ public void Update()
InteractTrigger = gamePadState.Buttons.X == ButtonState.Pressed;
ApplyTrigger = gamePadState.Buttons.A == ButtonState.Pressed;
JumpTrigger = gamePadState.Buttons.Y == ButtonState.Pressed;
+ SlotLeftTrigger = gamePadState.Buttons.LeftShoulder == ButtonState.Pressed;
+ SlotRightTrigger = gamePadState.Buttons.RightShoulder == ButtonState.Pressed;
MoveX = gamePadState.ThumbSticks.Left.X;
MoveY = gamePadState.ThumbSticks.Left.Y;
HeadX = gamePadState.ThumbSticks.Right.X;
@@ -67,30 +69,10 @@ public void Update()
catch (Exception) { }
}
+ public bool[] SlotTrigger { get { return null; } }
- public bool Slot1Trigger
- {
- get { return false; }
- }
+ public bool SlotLeftTrigger { get; private set; }
- public bool Slot2Trigger
- {
- get { return false; }
- }
-
- public bool Slot3Trigger
- {
- get { return false; }
- }
-
- public bool Slot4Trigger
- {
- get { return false; }
- }
-
- public bool Slot5Trigger
- {
- get { return false; }
- }
+ public bool SlotRightTrigger { get; private set; }
}
}
diff --git a/OctoAwesome/OctoAwesome.Client/Components/HudComponent.cs b/OctoAwesome/OctoAwesome.Client/Components/HudComponent.cs
index 81ce99f0..10e83457 100644
--- a/OctoAwesome/OctoAwesome.Client/Components/HudComponent.cs
+++ b/OctoAwesome/OctoAwesome.Client/Components/HudComponent.cs
@@ -1,7 +1,9 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
+using OctoAwesome.Runtime;
using System;
using System.Collections.Generic;
+using System.IO;
using System.Linq;
using System.Text;
@@ -23,6 +25,8 @@ internal sealed class HudComponent : DrawableGameComponent
private double seconds = 0;
private double lastfps = 0f;
+ private Texture2D[] toolTextures;
+
public HudComponent(Game game, PlayerComponent player)
: base(game)
{
@@ -41,6 +45,21 @@ protected override void LoadContent()
{
font = Game.Content.Load("Hud");
pix = Game.Content.Load("Textures/pix");
+
+ toolTextures = new Texture2D[player.Tools.Length];
+ int index = 0;
+ foreach (var tool in player.Tools)
+ {
+ using (MemoryStream stream = new MemoryStream())
+ {
+ System.Drawing.Bitmap bitmap = tool.Textures.First();
+ bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
+ stream.Seek(0, SeekOrigin.Begin);
+
+ toolTextures[index++] = Texture2D.FromStream(GraphicsDevice, stream);
+ }
+ }
+
base.LoadContent();
}
@@ -85,14 +104,24 @@ public override void Draw(GameTime gameTime)
batch.DrawString(font, selection, new Vector2(5, GraphicsDevice.Viewport.Height - size.Y - 5), Color.White);
}
- if (player.Player.BlockTool != null)
+ if (player.Tools != null && player.Tools.Length > 0)
{
- string tool = "Tool: " + player.Player.BlockTool.Name;
- size = font.MeasureString(tool);
- batch.DrawString(font, tool, new Vector2(GraphicsDevice.Viewport.Width - size.X - 5, GraphicsDevice.Viewport.Height - size.Y - 5), Color.White);
+ int width = player.Tools.Length * 32 + (player.Tools.Length - 1) * 10;
+ int offset = (GraphicsDevice.Viewport.Width - width) / 2;
+ int index = 0;
+ foreach (var definition in BlockDefinitionManager.GetBlockDefinitions())
+ {
+ if (player.Player.ActiveTool == definition)
+ {
+ batch.Draw(pix, new Rectangle(offset + (index * 42) - 2, GraphicsDevice.Viewport.Height - 60 - 2, 36, 36), Color.White);
+ }
+
+ batch.Draw(toolTextures[index], new Rectangle(offset + (index * 42), GraphicsDevice.Viewport.Height - 60, 32, 32), Color.White);
+
+ index++;
+ }
}
-
int centerX = GraphicsDevice.Viewport.Width / 2;
int centerY = GraphicsDevice.Viewport.Height / 2;
diff --git a/OctoAwesome/OctoAwesome.Client/Components/InputComponent.cs b/OctoAwesome/OctoAwesome.Client/Components/InputComponent.cs
index b3df6254..f9d4502f 100644
--- a/OctoAwesome/OctoAwesome.Client/Components/InputComponent.cs
+++ b/OctoAwesome/OctoAwesome.Client/Components/InputComponent.cs
@@ -9,18 +9,20 @@ namespace OctoAwesome.Client.Components
{
internal sealed class InputComponent : GameComponent, IInputSet
{
+ private const int SlotTriggerLength = 10;
+
private bool lastInteract = false;
private bool lastJump = false;
+ private bool[] lastSlotTrigger = new bool[SlotTriggerLength];
private bool lastApply = false;
- private bool lastSlot1 = false;
- private bool lastSlot2 = false;
- private bool lastSlot3 = false;
- private bool lastSlot4 = false;
- private bool lastSlot5 = false;
+ private bool lastSlotLeftTrigger = false;
+ private bool lastSlotRightTrigger = false;
private GamePadInput gamepad;
private KeyboardInput keyboard;
private MouseInput mouse;
+ private bool[] slotTriggers = new bool[SlotTriggerLength];
+
public float MoveX { get; private set; }
public float MoveY { get; private set; }
public float HeadX { get; private set; }
@@ -29,15 +31,11 @@ internal sealed class InputComponent : GameComponent, IInputSet
public bool ApplyTrigger { get; private set; }
public bool JumpTrigger { get; private set; }
- public bool Slot1Trigger { get; private set; }
-
- public bool Slot2Trigger { get; private set; }
-
- public bool Slot3Trigger { get; private set; }
+ public bool[] SlotTrigger { get { return slotTriggers; } }
- public bool Slot4Trigger { get; private set; }
+ public bool SlotLeftTrigger { get; private set; }
- public bool Slot5Trigger { get; private set; }
+ public bool SlotRightTrigger { get; private set; }
public InputComponent(Game game)
: base(game)
@@ -53,11 +51,9 @@ public override void Update(GameTime gameTime)
bool nextInteract = false;
bool nextJump = false;
bool nextApply = false;
- bool nextSlot1 = false;
- bool nextSlot2 = false;
- bool nextSlot3 = false;
- bool nextSlot4 = false;
- bool nextSlot5 = false;
+ bool[] nextSlot = new bool[SlotTriggerLength];
+ bool nextSlotLeft = false;
+ bool nextSlotRight = false;
MoveX = 0f;
MoveY = 0f;
HeadX = 0f;
@@ -67,11 +63,11 @@ public override void Update(GameTime gameTime)
nextInteract = gamepad.InteractTrigger;
nextApply = gamepad.ApplyTrigger;
nextJump = gamepad.JumpTrigger;
- nextSlot1 = gamepad.Slot1Trigger;
- nextSlot2 = gamepad.Slot2Trigger;
- nextSlot3 = gamepad.Slot3Trigger;
- nextSlot4 = gamepad.Slot4Trigger;
- nextSlot5 = gamepad.Slot5Trigger;
+ nextSlotLeft = gamepad.SlotLeftTrigger;
+ nextSlotRight = gamepad.SlotRightTrigger;
+ if (gamepad.SlotTrigger != null)
+ for (int i = 0; i < Math.Min(gamepad.SlotTrigger.Length, SlotTriggerLength); i++)
+ nextSlot[i] = gamepad.SlotTrigger[i];
MoveX += gamepad.MoveX;
MoveY += gamepad.MoveY;
@@ -82,11 +78,12 @@ public override void Update(GameTime gameTime)
nextInteract |= keyboard.InteractTrigger;
nextApply |= keyboard.ApplyTrigger;
nextJump |= keyboard.JumpTrigger;
- nextSlot1 |= keyboard.Slot1Trigger;
- nextSlot2 |= keyboard.Slot2Trigger;
- nextSlot3 |= keyboard.Slot3Trigger;
- nextSlot4 |= keyboard.Slot4Trigger;
- nextSlot5 |= keyboard.Slot5Trigger;
+ nextSlotLeft |= keyboard.SlotLeftTrigger;
+ nextSlotRight |= keyboard.SlotRightTrigger;
+ if (keyboard.SlotTrigger != null)
+ for (int i = 0; i < Math.Min(keyboard.SlotTrigger.Length, SlotTriggerLength); i++)
+ nextSlot[i] |= keyboard.SlotTrigger[i];
+
MoveX += keyboard.MoveX;
MoveY += keyboard.MoveY;
@@ -99,12 +96,11 @@ public override void Update(GameTime gameTime)
nextInteract |= mouse.InteractTrigger;
nextApply |= mouse.ApplyTrigger;
nextJump |= mouse.JumpTrigger;
- nextSlot1 |= mouse.Slot1Trigger;
- nextSlot2 |= mouse.Slot2Trigger;
- nextSlot3 |= mouse.Slot3Trigger;
- nextSlot4 |= mouse.Slot4Trigger;
- nextSlot5 |= mouse.Slot5Trigger;
-
+ nextSlotLeft |= mouse.SlotLeftTrigger;
+ nextSlotRight |= mouse.SlotRightTrigger;
+ if (mouse.SlotTrigger != null)
+ for (int i = 0; i < Math.Min(mouse.SlotTrigger.Length, SlotTriggerLength); i++)
+ nextSlot[i] |= mouse.SlotTrigger[i];
MoveX += mouse.MoveX;
MoveY += mouse.MoveY;
@@ -134,38 +130,20 @@ public override void Update(GameTime gameTime)
JumpTrigger = false;
lastJump = nextJump;
- if (nextSlot1 && !lastSlot1)
- Slot1Trigger = true;
- else
- Slot1Trigger = false;
- lastSlot1 = nextSlot1;
+ SlotLeftTrigger = nextSlotLeft && !lastSlotLeftTrigger;
+ lastSlotLeftTrigger = nextSlotLeft;
- if (nextSlot2 && !lastSlot2)
- Slot2Trigger = true;
- else
- Slot2Trigger = false;
- lastSlot2 = nextSlot2;
+ SlotRightTrigger = nextSlotRight && !lastSlotRightTrigger;
+ lastSlotRightTrigger = nextSlotRight;
- if (nextSlot3 && !lastSlot3)
- Slot3Trigger = true;
- else
- Slot3Trigger = false;
- lastSlot3 = nextSlot3;
-
- if (nextSlot4 && !lastSlot4)
- Slot4Trigger = true;
- else
- Slot4Trigger = false;
- lastSlot4 = nextSlot4;
-
- if (nextSlot5 && !lastSlot5)
- Slot5Trigger = true;
- else
- Slot5Trigger = false;
- lastSlot5 = nextSlot5;
+ for (int i = 0; i < SlotTriggerLength; i++)
+ {
+ if (nextSlot[i] && lastSlotTrigger[i])
+ slotTriggers[i] = true;
+ else
+ slotTriggers[i] = false;
+ lastSlotTrigger[i] = nextSlot[i];
+ }
}
-
-
-
}
}
diff --git a/OctoAwesome/OctoAwesome.Client/Components/KeyboardInput.cs b/OctoAwesome/OctoAwesome.Client/Components/KeyboardInput.cs
index ebfee807..0dfde5d2 100644
--- a/OctoAwesome/OctoAwesome.Client/Components/KeyboardInput.cs
+++ b/OctoAwesome/OctoAwesome.Client/Components/KeyboardInput.cs
@@ -11,6 +11,8 @@ namespace OctoAwesome.Client.Components
///
internal sealed class KeyboardInput : IInputSet
{
+ bool[] slotTriggers = new bool[10];
+
///
/// Anteil der Seitwärtsbewegung (-1...1)
///
@@ -46,6 +48,12 @@ internal sealed class KeyboardInput : IInputSet
///
public bool JumpTrigger { get; private set; }
+ public bool[] SlotTrigger { get { return slotTriggers; } }
+
+ public bool SlotLeftTrigger { get; private set; }
+
+ public bool SlotRightTrigger { get; private set; }
+
///
/// Frame Update zur Ermittlung der Veränderungen.
///
@@ -60,11 +68,16 @@ public void Update()
InteractTrigger = keyboardState.IsKeyDown(Keys.E);
ApplyTrigger = keyboardState.IsKeyDown(Keys.Q);
JumpTrigger = keyboardState.IsKeyDown(Keys.Space);
- Slot1Trigger = keyboardState.IsKeyDown(Keys.D1);
- Slot2Trigger = keyboardState.IsKeyDown(Keys.D2);
- Slot3Trigger = keyboardState.IsKeyDown(Keys.D3);
- Slot4Trigger = keyboardState.IsKeyDown(Keys.D4);
- Slot5Trigger = keyboardState.IsKeyDown(Keys.D5);
+ slotTriggers[0] = keyboardState.IsKeyDown(Keys.D1);
+ slotTriggers[1] = keyboardState.IsKeyDown(Keys.D2);
+ slotTriggers[2] = keyboardState.IsKeyDown(Keys.D3);
+ slotTriggers[3] = keyboardState.IsKeyDown(Keys.D4);
+ slotTriggers[4] = keyboardState.IsKeyDown(Keys.D5);
+ slotTriggers[5] = keyboardState.IsKeyDown(Keys.D6);
+ slotTriggers[6] = keyboardState.IsKeyDown(Keys.D7);
+ slotTriggers[7] = keyboardState.IsKeyDown(Keys.D8);
+ slotTriggers[8] = keyboardState.IsKeyDown(Keys.D9);
+ slotTriggers[9] = keyboardState.IsKeyDown(Keys.D0);
MoveX -= (keyboardState.IsKeyDown(Keys.A) ? 1 : 0);
MoveX += (keyboardState.IsKeyDown(Keys.D) ? 1 : 0);
MoveY -= (keyboardState.IsKeyDown(Keys.S) ? 1 : 0);
@@ -74,16 +87,5 @@ public void Update()
HeadY -= (keyboardState.IsKeyDown(Keys.Up) ? 1 : 0);
HeadY += (keyboardState.IsKeyDown(Keys.Down) ? 1 : 0);
}
-
-
- public bool Slot1Trigger { get; private set; }
-
- public bool Slot2Trigger { get; private set; }
-
- public bool Slot3Trigger { get; private set; }
-
- public bool Slot4Trigger { get; private set; }
-
- public bool Slot5Trigger { get; private set; }
}
}
diff --git a/OctoAwesome/OctoAwesome.Client/Components/MouseInput.cs b/OctoAwesome/OctoAwesome.Client/Components/MouseInput.cs
index 88a42f2c..8820c719 100644
--- a/OctoAwesome/OctoAwesome.Client/Components/MouseInput.cs
+++ b/OctoAwesome/OctoAwesome.Client/Components/MouseInput.cs
@@ -17,6 +17,8 @@ internal sealed class MouseInput : IInputSet
///
private float mouseSpeed = 0.2f;
+ private int lastWheelState = 0;
+
private Game game;
private bool init = false;
@@ -56,6 +58,12 @@ internal sealed class MouseInput : IInputSet
///
public bool JumpTrigger { get; private set; }
+ public bool[] SlotTrigger { get { return null; } }
+
+ public bool SlotLeftTrigger { get; private set; }
+
+ public bool SlotRightTrigger { get; private set; }
+
///
/// Initialisierung. Benötigt eine Game-Instanz zur Ermittlung der Fenstergröße
///
@@ -87,33 +95,11 @@ public void Update()
HeadX = deltaX * mouseSpeed;
HeadY = -deltaY * mouseSpeed;
}
- init = true;
- }
+ init = true;
-
- public bool Slot1Trigger
- {
- get { return false; }
- }
-
- public bool Slot2Trigger
- {
- get { return false; }
- }
-
- public bool Slot3Trigger
- {
- get { return false; }
- }
-
- public bool Slot4Trigger
- {
- get { return false; }
- }
-
- public bool Slot5Trigger
- {
- get { return false; }
+ SlotLeftTrigger = state.ScrollWheelValue < lastWheelState;
+ SlotRightTrigger = state.ScrollWheelValue > lastWheelState;
+ lastWheelState = state.ScrollWheelValue;
}
}
}
diff --git a/OctoAwesome/OctoAwesome.Client/Components/PlayerComponent.cs b/OctoAwesome/OctoAwesome.Client/Components/PlayerComponent.cs
index be6cafdb..4660a5da 100644
--- a/OctoAwesome/OctoAwesome.Client/Components/PlayerComponent.cs
+++ b/OctoAwesome/OctoAwesome.Client/Components/PlayerComponent.cs
@@ -25,7 +25,7 @@ internal sealed class PlayerComponent : GameComponent
public OrientationFlags SelectedCorner { get; set; }
- public IBlockDefinition BlockTool { get; set; }
+ public IBlockDefinition[] Tools { get; set; }
public PlayerComponent(Game game, InputComponent input, SimulationComponent simulation)
: base(game)
@@ -34,6 +34,12 @@ public PlayerComponent(Game game, InputComponent input, SimulationComponent simu
this.input = input;
}
+ public override void Initialize()
+ {
+ base.Initialize();
+ Tools = BlockDefinitionManager.GetBlockDefinitions().ToArray();
+ }
+
public override void Update(GameTime gameTime)
{
Player.Head = new Vector2(input.HeadX, input.HeadY);
@@ -50,26 +56,41 @@ public override void Update(GameTime gameTime)
Player.Apply(SelectedBox.Value, SelectedSide);
}
- if (input.Slot1Trigger)
- {
- Player.BlockTool = BlockDefinitionManager.GetBlockDefinitions().ToArray()[1];
- }
- if (input.Slot2Trigger)
+ if (Tools != null && input.SlotTrigger != null)
{
- Player.BlockTool = BlockDefinitionManager.GetBlockDefinitions().ToArray()[2];
+ for (int i = 0; i < Math.Min(Tools.Length, input.SlotTrigger.Length); i++)
+ {
+ if (input.SlotTrigger[i])
+ Player.ActiveTool = Tools[i];
+ }
}
- if (input.Slot3Trigger)
+
+ // Index des aktiven Werkzeugs ermitteln
+ int activeTool = -1;
+ if (Tools != null && Player.ActiveTool != null)
{
- Player.BlockTool = BlockDefinitionManager.GetBlockDefinitions().ToArray()[3];
+ for (int i = 0; i < Tools.Length; i++)
+ {
+ if (Tools[i] == Player.ActiveTool)
+ {
+ activeTool = i;
+ break;
+ }
+ }
}
- if (input.Slot4Trigger)
+
+ if (activeTool > -1)
{
- Player.BlockTool = BlockDefinitionManager.GetBlockDefinitions().ToArray()[5];
+ if (input.SlotLeftTrigger)
+ activeTool--;
+
+ if (input.SlotRightTrigger)
+ activeTool++;
+
+ activeTool = (activeTool + Tools.Length) % Tools.Length;
+ Player.ActiveTool = Tools[activeTool];
}
- //if (input.Slot5Trigger)
- //{
- // Player.BlockTool = BlockDefinitionManager.GetBlockDefinitions().ToArray()[4];
- //}
+
}
}
}
diff --git a/OctoAwesome/OctoAwesome.Client/Components/SceneComponent.cs b/OctoAwesome/OctoAwesome.Client/Components/SceneComponent.cs
index d3c13819..002d1f99 100644
--- a/OctoAwesome/OctoAwesome.Client/Components/SceneComponent.cs
+++ b/OctoAwesome/OctoAwesome.Client/Components/SceneComponent.cs
@@ -28,7 +28,6 @@ internal sealed class SceneComponent : DrawableGameComponent
private Queue freeChunkRenderer = new Queue();
private List activeChunkRenderer = new List();
- private Queue highPrioUpdate = new Queue();
private List distances = new List();
private BasicEffect selectionEffect;
@@ -116,11 +115,7 @@ protected override void LoadContent()
for (int i = 0; i < chunkRenderer.Length; i++)
{
- chunkRenderer[i] = new ChunkRenderer(
- GraphicsDevice, camera.Projection, blockTextures)
- {
- InUse = false
- };
+ chunkRenderer[i] = new ChunkRenderer(GraphicsDevice, camera.Projection, blockTextures);
freeChunkRenderer.Enqueue(chunkRenderer[i]);
}
@@ -163,14 +158,6 @@ protected override void LoadContent()
public override void Update(GameTime gameTime)
{
- foreach (var renderer in chunkRenderer)
- {
- if (renderer.NeedUpdate() && !highPrioUpdate.Contains(renderer))
- highPrioUpdate.Enqueue(renderer);
- }
-
- #region Selektion
-
Index3 centerblock = player.Player.Position.GlobalBlockIndex;
Index3 renderOffset = player.Player.Position.ChunkIndex * Chunk.CHUNKSIZE;
@@ -251,7 +238,7 @@ public override void Update(GameTime gameTime)
}
player.SelectedPoint = new Vector2(
- Math.Min(1f, Math.Max(0f, player.SelectedPoint.Value.X)),
+ Math.Min(1f, Math.Max(0f, player.SelectedPoint.Value.X)),
Math.Min(1f, Math.Max(0f, player.SelectedPoint.Value.Y)));
}
else
@@ -263,8 +250,6 @@ public override void Update(GameTime gameTime)
player.SelectedCorner = OrientationFlags.None;
}
- #endregion
-
base.Update(gameTime);
}
@@ -284,11 +269,11 @@ public override void Draw(GameTime gameTime)
foreach (var renderer in chunkRenderer)
{
- if (!renderer.InUse)
+ if (!renderer.ChunkPosition.HasValue)
continue;
Index3 shift = chunkOffset.ShortestDistanceXY(
- renderer.ChunkIndex, new Index2(
+ renderer.ChunkPosition.Value.ChunkIndex, new Index2(
planet.Size.X,
planet.Size.Y));
@@ -337,11 +322,26 @@ private void FillChunkRenderer()
IPlanet planet = ResourceManager.Instance.GetPlanet(player.Player.Position.Planet);
destinationChunk.Z = Math.Max(VIEWHEIGHT, Math.Min(planet.Size.Z - VIEWHEIGHT, destinationChunk.Z));
- HandleHighPrioUpdates();
-
+ var updates = activeChunkRenderer.
+ Where(r => r.NeedUpdate()).OrderBy(r =>
+ {
+ Index3 absoluteIndex = r.ChunkPosition.Value.ChunkIndex;
+ Index3 relativeIndex = destinationChunk.ShortestDistanceXY(
+ absoluteIndex, new Index2(
+ planet.Size.X,
+ planet.Size.Y));
+ return relativeIndex.LengthSquared();
+ }).FirstOrDefault();
+
+ if (updates != null)
+ updates.RegenerateVertexBuffer();
+
+ // Restlichen Code nur ausführen wenn der Spieler den Chunk gewechselt hat
if (destinationChunk == currentChunk)
return;
+ #region Shift durchführen
+
Index3 shift = currentChunk.ShortestDistanceXY(
destinationChunk, new Index2(planet.Size.X, planet.Size.Y));
@@ -349,53 +349,47 @@ private void FillChunkRenderer()
{
ChunkRenderer renderer = activeChunkRenderer[i];
- renderer.RelativeIndex -= shift;
+ Index3 absoluteIndex = renderer.ChunkPosition.Value.ChunkIndex;
+ Index3 relativeIndex = destinationChunk.ShortestDistanceXY(
+ absoluteIndex, new Index2(
+ planet.Size.X,
+ planet.Size.Y));
- if (!renderer.InUse ||
- renderer.RelativeIndex.X < -VIEWRANGE || renderer.RelativeIndex.X > VIEWRANGE ||
- renderer.RelativeIndex.Y < -VIEWRANGE || renderer.RelativeIndex.Y > VIEWRANGE ||
- renderer.RelativeIndex.Z < -VIEWHEIGHT || renderer.RelativeIndex.Z > VIEWHEIGHT)
+ if (!renderer.ChunkPosition.HasValue ||
+ relativeIndex.X < -VIEWRANGE || relativeIndex.X > VIEWRANGE ||
+ relativeIndex.Y < -VIEWRANGE || relativeIndex.Y > VIEWRANGE ||
+ relativeIndex.Z < -VIEWHEIGHT || relativeIndex.Z > VIEWHEIGHT)
{
- renderer.InUse = false;
+ renderer.SetChunk(null);
+
freeChunkRenderer.Enqueue(renderer);
activeChunkRenderer.Remove(renderer);
}
}
+ #endregion
+
+ #region Ungenutzte Chunks auffüllen
+
foreach (var distance in distances)
{
- HandleHighPrioUpdates();
-
Index3 chunkIndex = destinationChunk + distance;
-
chunkIndex.NormalizeXY(planet.Size);
- if (!activeChunkRenderer.Any(c => c.RelativeIndex == distance))
+ PlanetIndex3 chunkPosition = new PlanetIndex3(
+ player.Player.Position.Planet, chunkIndex);
+
+ if (!activeChunkRenderer.Any(c => c.ChunkPosition == chunkPosition))
{
- IChunk chunk = ResourceManager.Instance.GetChunk(planet.Id, chunkIndex);
- if (chunk != null)
- {
- ChunkRenderer renderer = freeChunkRenderer.Dequeue();
- renderer.SetChunk(chunk);
- renderer.RelativeIndex = distance;
- renderer.InUse = true;
- activeChunkRenderer.Add(renderer);
- }
+ ChunkRenderer renderer = freeChunkRenderer.Dequeue();
+ renderer.SetChunk(chunkPosition);
+ activeChunkRenderer.Add(renderer);
}
}
- currentChunk = destinationChunk;
- }
+ #endregion
- private void HandleHighPrioUpdates()
- {
- // High Prio Interrupt
- while (highPrioUpdate.Count > 0)
- {
- var renderer = highPrioUpdate.Dequeue();
- if (activeChunkRenderer.Contains(renderer))
- renderer.RegenerateVertexBuffer();
- }
+ currentChunk = destinationChunk;
}
private void BackgroundLoop()
diff --git a/OctoAwesome/OctoAwesome.Client/TODO.txt b/OctoAwesome/OctoAwesome.Client/TODO.txt
index bdb8d812..f80f7555 100644
--- a/OctoAwesome/OctoAwesome.Client/TODO.txt
+++ b/OctoAwesome/OctoAwesome.Client/TODO.txt
@@ -1,10 +1,6 @@
Plan für die kommenden Folgen:
==============================
-1 Block-Placement
-2 Block-Definition Holz
-3 Block-Placement 2 (HUD mit Auswahl)
-4 komplexe Blöcke -> visuelle Attribute
5 Performance Optimierung VertexBuffer-Generierung
- Block-Visibility Berücksichtigen
- Flackern bei Chunkwechsel
diff --git a/OctoAwesome/OctoAwesome.Runtime/ActorHost.cs b/OctoAwesome/OctoAwesome.Runtime/ActorHost.cs
index 6fa63330..52df64d0 100644
--- a/OctoAwesome/OctoAwesome.Runtime/ActorHost.cs
+++ b/OctoAwesome/OctoAwesome.Runtime/ActorHost.cs
@@ -22,7 +22,7 @@ public class ActorHost : IPlayerController
public Player Player { get; private set; }
- public IBlockDefinition BlockTool { get; set; }
+ public IBlockDefinition ActiveTool { get; set; }
public ActorHost(Player player)
{
@@ -30,7 +30,7 @@ public ActorHost(Player player)
localChunkCache = new Cache(10, loadChunk, null);
planet = ResourceManager.Instance.GetPlanet(Player.Position.Planet);
- BlockTool = BlockDefinitionManager.GetBlockDefinitions().OfType().FirstOrDefault();
+ ActiveTool = null;
}
public void Update(GameTime frameTime)
@@ -192,7 +192,7 @@ public void Update(GameTime frameTime)
if (lastApply.HasValue)
{
- if (BlockTool != null)
+ if (ActiveTool != null)
{
Index3 add = new Index3();
switch (lastOrientation)
@@ -206,7 +206,7 @@ public void Update(GameTime frameTime)
}
ResourceManager.Instance.SetBlock(planet.Id,
- lastApply.Value + add, BlockTool.GetInstance(lastOrientation));
+ lastApply.Value + add, ActiveTool.GetInstance(lastOrientation));
lastApply = null;
}
}
diff --git a/OctoAwesome/OctoAwesome/IInputSet.cs b/OctoAwesome/OctoAwesome/IInputSet.cs
index ae6b6211..3164ad8d 100644
--- a/OctoAwesome/OctoAwesome/IInputSet.cs
+++ b/OctoAwesome/OctoAwesome/IInputSet.cs
@@ -45,14 +45,20 @@ public interface IInputSet
///
bool JumpTrigger { get; }
- bool Slot1Trigger { get; }
+ bool[] SlotTrigger { get; }
- bool Slot2Trigger { get; }
+ bool SlotLeftTrigger { get; }
+
+ bool SlotRightTrigger { get; }
+
+ //bool Slot1Trigger { get; }
+
+ //bool Slot2Trigger { get; }
- bool Slot3Trigger { get; }
+ //bool Slot3Trigger { get; }
- bool Slot4Trigger { get; }
+ //bool Slot4Trigger { get; }
- bool Slot5Trigger { get; }
+ //bool Slot5Trigger { get; }
}
}
diff --git a/OctoAwesome/OctoAwesome/PlanetIndex3.cs b/OctoAwesome/OctoAwesome/PlanetIndex3.cs
index b8ef0081..c2444061 100644
--- a/OctoAwesome/OctoAwesome/PlanetIndex3.cs
+++ b/OctoAwesome/OctoAwesome/PlanetIndex3.cs
@@ -17,6 +17,28 @@ public PlanetIndex3(int planet, Index3 chunkIndex)
ChunkIndex = chunkIndex;
}
+ public static bool operator ==(PlanetIndex3 i1, PlanetIndex3 i2)
+ {
+ return i1.Equals(i2);
+ }
+
+ public static bool operator !=(PlanetIndex3 i1, PlanetIndex3 i2)
+ {
+ return !i1.Equals(i2);
+ }
+ public override bool Equals(object obj)
+ {
+ if (!(obj is PlanetIndex3))
+ return false;
+
+ PlanetIndex3 other = (PlanetIndex3)obj;
+ return (
+ other.Planet == this.Planet &&
+ other.ChunkIndex.X == this.ChunkIndex.X &&
+ other.ChunkIndex.Y == this.ChunkIndex.Y &&
+ other.ChunkIndex.Z == this.ChunkIndex.Z);
+ }
+
public override int GetHashCode()
{
return
diff --git a/OctoAwesome/OctoAwesome/Player.cs b/OctoAwesome/OctoAwesome/Player.cs
index 771eb5c1..907c599e 100644
--- a/OctoAwesome/OctoAwesome/Player.cs
+++ b/OctoAwesome/OctoAwesome/Player.cs
@@ -31,7 +31,7 @@ public sealed class Player : Item
public Player()
{
- Position = new Coordinate(0, new Index3(16, 16, 100), Vector3.Zero);
+ Position = new Coordinate(0, new Index3(82109, 74365, 45), Vector3.Zero);
Velocity = new Vector3(0, 0, 0);
Radius = 0.75f;
Angle = 0f;