diff --git a/OctoAwesome/OctoAwesome.Basics/ComplexPlanet.cs b/OctoAwesome/OctoAwesome.Basics/ComplexPlanet.cs
index b6490081..30c0218d 100644
--- a/OctoAwesome/OctoAwesome.Basics/ComplexPlanet.cs
+++ b/OctoAwesome/OctoAwesome.Basics/ComplexPlanet.cs
@@ -20,12 +20,11 @@ public class ComplexPlanet : Planet
/// ID des Planeten
/// ID des Universums
/// Größe des Planeten in Zweierpotenzen Chunks
- /// Instanz des Map-Generators
/// Seed des Zufallsgenerators
- public ComplexPlanet(int id, Guid universe, Index3 size, IMapGenerator generator, int seed)
- : base(id, universe, size, seed)
+ public ComplexPlanet(int id, Guid universe, Index3 size, int seed) : base(id, universe, size, seed)
{
- Initalize();
+ BiomeGenerator = new SurfaceBiomeGenerator(this, 40);
+ ClimateMap = new Climate.ComplexClimateMap(this);
}
public ComplexPlanet() : base()
@@ -36,11 +35,6 @@ public ComplexPlanet() : base()
public override void Deserialize(Stream stream)
{
base.Deserialize(stream);
- Initalize();
- }
-
- private void Initalize()
- {
BiomeGenerator = new SurfaceBiomeGenerator(this, 40);
ClimateMap = new Climate.ComplexClimateMap(this);
}
diff --git a/OctoAwesome/OctoAwesome.Basics/ComplexPlanetGenerator.cs b/OctoAwesome/OctoAwesome.Basics/ComplexPlanetGenerator.cs
index e5ac808f..a563615a 100644
--- a/OctoAwesome/OctoAwesome.Basics/ComplexPlanetGenerator.cs
+++ b/OctoAwesome/OctoAwesome.Basics/ComplexPlanetGenerator.cs
@@ -11,7 +11,7 @@ public class ComplexPlanetGenerator : IMapGenerator
public IPlanet GeneratePlanet(Guid universe, int id, int seed)
{
Index3 size = new Index3(12, 12, 3);
- ComplexPlanet planet = new ComplexPlanet(id, universe, size, this, seed)
+ ComplexPlanet planet = new ComplexPlanet(id, universe, size, seed)
{
Generator = this
};
diff --git a/OctoAwesome/OctoAwesome.Basics/Controls/InventoryControl.cs b/OctoAwesome/OctoAwesome.Basics/Controls/InventoryControl.cs
new file mode 100644
index 00000000..eae3f7cf
--- /dev/null
+++ b/OctoAwesome/OctoAwesome.Basics/Controls/InventoryControl.cs
@@ -0,0 +1,124 @@
+using engenious;
+using engenious.Graphics;
+using MonoGameUi;
+using OctoAwesome.Basics.EntityComponents;
+using OctoAwesome.Entities;
+using System;
+using System.Collections.Generic;
+
+namespace OctoAwesome.Basics.Controls
+{
+ internal sealed class InventoryControl : Panel
+ {
+ private const int COLUMNS = 8;
+
+ ///
+ /// Gibt den aktuell selektierten Slot an.
+ ///
+ public InventorySlot HoveredSlot { get; private set; }
+
+ private InventoryComponent inventory;
+ private Label volumeLabel;
+ private Label massLabel;
+ private Label nameLabel;
+
+ public InventoryControl(BaseScreenComponent manager, IUserInterfaceExtensionManager interfacemanager,
+ InventoryComponent inventory) : base(manager)
+ {
+ this.inventory = inventory;
+
+ Texture2D panelBackground = interfacemanager.LoadTextures(manager.GetType(), "panel");
+ Margin = new Border(0, 0, 0, 0);
+ HorizontalAlignment = HorizontalAlignment.Stretch;
+ VerticalAlignment = VerticalAlignment.Stretch;
+
+ Grid parentgrid = new Grid(manager);
+ parentgrid.Columns.Add(new ColumnDefinition() { ResizeMode = ResizeMode.Parts, Width = 1, });
+ parentgrid.Rows.Add(new RowDefinition() { ResizeMode = ResizeMode.Parts, Height = 1, });
+ parentgrid.Rows.Add(new RowDefinition() { ResizeMode = ResizeMode.Fixed, Height = 100, });
+ Controls.Add(parentgrid);
+
+ Panel panel = new Panel(manager)
+ {
+ HorizontalAlignment = HorizontalAlignment.Stretch,
+ VerticalAlignment = VerticalAlignment.Stretch,
+ Background = NineTileBrush.FromSingleTexture(panelBackground, 30, 30)
+ };
+ parentgrid.AddControl(panel, 0, 0);
+
+ ScrollContainer scroll = new ScrollContainer(manager)
+ {
+ Margin = Border.All(0, 5, 5, 5),
+ HorizontalAlignment = HorizontalAlignment.Stretch,
+ VerticalAlignment = VerticalAlignment.Stretch,
+ };
+ panel.Controls.Add(scroll);
+
+ StackPanel infoPanel = new StackPanel(manager)
+ {
+ Margin = new Border(0, 10, 0, 0),
+ HorizontalAlignment = HorizontalAlignment.Stretch,
+ VerticalAlignment = VerticalAlignment.Stretch,
+ Background = NineTileBrush.FromSingleTexture(panelBackground, 30, 30),
+ };
+
+ nameLabel = new Label(manager);
+ infoPanel.Controls.Add(nameLabel);
+ massLabel = new Label(manager);
+ infoPanel.Controls.Add(massLabel);
+ volumeLabel = new Label(manager);
+ infoPanel.Controls.Add(volumeLabel);
+ parentgrid.AddControl(infoPanel, 0, 1);
+
+ Grid grid = new Grid(manager)
+ {
+ HorizontalAlignment = HorizontalAlignment.Stretch,
+ };
+ for (int i = 0; i < COLUMNS; i++)
+ grid.Columns.Add(new ColumnDefinition() { ResizeMode = ResizeMode.Parts, Width = 1 });
+
+ int rows = (int) System.Math.Ceiling((float) inventory.Inventory.Count / COLUMNS);
+ for (int i = 0; i < rows; i++)
+ grid.Rows.Add(new RowDefinition() { ResizeMode = ResizeMode.Fixed, Height = 50 });
+
+ int column = 0;
+ int row = 0;
+ foreach (var item in inventory.Inventory)
+ {
+ Texture2D texture = interfacemanager.LoadTextures(item.Definition.GetType(), item.Definition.Icon);
+
+ var image = new Image(manager) { Texture = texture, Width = 42, Height = 42, VerticalAlignment = VerticalAlignment.Center };
+ image.MouseEnter += (s, e) => { HoveredSlot = item; };
+ image.MouseLeave += (s, e) => { HoveredSlot = null; };
+ image.StartDrag += (e) =>
+ {
+ e.Handled = true;
+ e.Icon = texture;
+ e.Content = item;
+ e.Sender = image;
+ };
+ var label = new Label(manager) { Text = item.Amount.ToString(), HorizontalAlignment = HorizontalAlignment.Right, VerticalTextAlignment = VerticalAlignment.Bottom, Background = new BorderBrush(Color.White) };
+ grid.AddControl(image, column, row);
+ grid.AddControl(label, column, row);
+
+ column++;
+ if (column >= COLUMNS)
+ {
+ row++;
+ column = 0;
+ }
+ }
+ scroll.Content = grid;
+ }
+ protected override void OnUpdate(GameTime gameTime)
+ {
+ nameLabel.Text = HoveredSlot?.Definition.Name ?? "";
+ massLabel.Text = volumeLabel.Text = HoveredSlot?.Amount.ToString() ?? "";
+ }
+ public override string ToString()
+ {
+ // TODO: resx -> Languages.OctoBasics.Inventory or what ever...
+ return "Inventar";
+ }
+ }
+}
diff --git a/OctoAwesome/OctoAwesome.Basics/Controls/ToolbarControl.cs b/OctoAwesome/OctoAwesome.Basics/Controls/ToolbarControl.cs
new file mode 100644
index 00000000..03cb306f
--- /dev/null
+++ b/OctoAwesome/OctoAwesome.Basics/Controls/ToolbarControl.cs
@@ -0,0 +1,183 @@
+using MonoGameUi;
+using System.Collections.Generic;
+using engenious;
+using engenious.Graphics;
+using OctoAwesome.Entities;
+using System;
+using OctoAwesome.Basics.EntityComponents;
+
+namespace OctoAwesome.Basics.Controls
+{
+ internal class ToolbarControl : Panel
+ {
+ private Button[] buttons;
+
+ private Image[] images;
+
+ private Brush buttonBackgroud;
+
+ private Brush activeBackground;
+
+ private ToolBarComponent toolbar;
+
+ private Label activeToolLabel;
+
+ private Dictionary toolTextures;
+
+ public ToolbarControl(BaseScreenComponent screenManager, IUserInterfaceExtensionManager manager, ToolBarComponent bar) :
+ base(screenManager)
+ {
+ HorizontalAlignment = HorizontalAlignment.Stretch;
+ VerticalAlignment = VerticalAlignment.Bottom;
+ Height = 100;
+ toolbar = bar;
+ buttonBackgroud = new BorderBrush(Color.Black);
+ activeBackground = new BorderBrush(Color.Red);
+ buttons = new Button[toolbar.Tools.Length];
+ images = new Image[toolbar.Tools.Length];
+
+ toolTextures = new Dictionary();
+
+ foreach (var item in bar.Service.DefinitionManager.GetDefinitions())
+ {
+ Texture2D texture = manager.LoadTextures(item.GetType(), item.Icon);
+ toolTextures.Add(item.GetType().FullName, texture);
+ }
+
+ Grid grid = new Grid(screenManager)
+ {
+ Margin = new Border(0, 0, 0, 0),
+ HorizontalAlignment = HorizontalAlignment.Center,
+ VerticalAlignment = VerticalAlignment.Bottom
+ };
+ Controls.Add(grid);
+
+ grid.Rows.Add(new RowDefinition() { ResizeMode = ResizeMode.Auto, Height = 1 });
+ grid.Rows.Add(new RowDefinition() { ResizeMode = ResizeMode.Fixed, Height = 50 });
+
+ for (int i = 0; i < toolbar.Tools.Length; i++)
+ {
+ grid.Columns.Add(new ColumnDefinition() { ResizeMode = ResizeMode.Fixed, Width = 50 });
+ }
+
+ activeToolLabel = new Label(screenManager);
+ activeToolLabel.VerticalAlignment = VerticalAlignment.Top;
+ activeToolLabel.HorizontalAlignment = HorizontalAlignment.Center;
+ activeToolLabel.Background = new BorderBrush(Color.Black * 0.3f);
+ activeToolLabel.TextColor = Color.White;
+ grid.AddControl(activeToolLabel, 0, 0, 10);
+
+ for (int i = 0; i < toolbar.Tools.Length; i++)
+ {
+ buttons[i] = new Button(screenManager)
+ {
+ HorizontalAlignment = HorizontalAlignment.Stretch,
+ VerticalAlignment = VerticalAlignment.Stretch,
+ Background = buttonBackgroud,
+ HoveredBackground = null,
+ PressedBackground = null,
+ };
+ buttons[i].Content = images[i] = new Image(screenManager)
+ {
+ Width = 42,
+ Height = 42,
+ };
+ grid.AddControl(buttons[i], i, 1);
+ }
+ }
+ protected override void OnUpdate(GameTime gameTime)
+ {
+ if (!Visible || !Enabled)
+ return;
+ if(!(toolbar.Entity is IControllable con) || con.Controller == null)
+ return;
+ #region Toolbar Update
+
+ if (toolbar.Tools != null && toolbar.Tools.Length > 0)
+ {
+ if (toolbar.ActiveTool == null) toolbar.ActiveTool = toolbar.Tools[0];
+ for (int i = 0; i < Math.Min(toolbar.Tools.Length, con.Controller.SlotInput.Length); i++)
+ {
+ if (con.Controller.SlotInput[i]) toolbar.ActiveTool = toolbar.Tools[i];
+ con.Controller.SlotInput[i] = false;
+ }
+ }
+
+ //Index des aktiven Werkzeugs ermitteln
+ int activeTool = -1;
+ List toolIndices = new List();
+ for (int i = 0; i < toolbar.Tools.Length; i++)
+ {
+
+ if (toolbar.ActiveTool != null && toolbar.ActiveTool.Amount <= 0)
+ toolbar.RemoveSlot(toolbar.ActiveTool);
+
+ if (toolbar.Tools[i] != null)
+ toolIndices.Add(i);
+
+ if (toolbar.Tools[i] == toolbar.ActiveTool)
+ activeTool = toolIndices.Count - 1;
+ }
+
+ if (con.Controller.SlotLeftInput)
+ {
+ if (activeTool > -1)
+ activeTool--;
+ else if (toolIndices.Count > 0)
+ activeTool = toolIndices[toolIndices.Count - 1];
+ }
+ con.Controller.SlotLeftInput = false;
+
+ if (con.Controller.SlotRightInput)
+ {
+ if (activeTool > -1)
+ activeTool++;
+ else if (toolIndices.Count > 0)
+ activeTool = toolIndices[0];
+ }
+ con.Controller.SlotRightInput = false;
+
+ if (activeTool > -1)
+ {
+ activeTool = (activeTool + toolIndices.Count) % toolIndices.Count;
+ toolbar.ActiveTool = toolbar.Tools[toolIndices[activeTool]];
+ }
+ #endregion
+
+ // Aktualisierung des aktiven Buttons
+ for (int i = 0; i < toolbar.Tools.Length; i++)
+ {
+ if (toolbar.Tools != null &&
+ toolbar.Tools.Length > i &&
+ toolbar.Tools[i] != null &&
+ toolbar.Tools[i].Definition != null)
+ {
+ images[i].Texture = toolTextures[toolbar.Tools[i].Definition.GetType().FullName];
+ if (toolbar.ActiveTool == toolbar.Tools[i])
+ buttons[i].Background = activeBackground;
+ else
+ buttons[i].Background = buttonBackgroud;
+ }
+ else
+ {
+ images[i].Texture = null;
+ buttons[i].Background = buttonBackgroud;
+ }
+ }
+
+ //Aktualisierung des ActiveTool Labels
+ activeToolLabel.Text = toolbar.ActiveTool != null ?
+ string.Format("{0} ({1})", toolbar.ActiveTool.Definition.Name, toolbar.ActiveTool.Amount) :
+ string.Empty;
+
+ activeToolLabel.Visible = !(activeToolLabel.Text == string.Empty);
+
+ base.OnUpdate(gameTime);
+ }
+ public override string ToString()
+ {
+ // TODO: resx -> Languages.OctoBasics.Tool or what ever...
+ return "Werkzeuge";
+ }
+ }
+}
diff --git a/OctoAwesome/OctoAwesome.Basics/Controls/ToolbarInventoryControl.cs b/OctoAwesome/OctoAwesome.Basics/Controls/ToolbarInventoryControl.cs
new file mode 100644
index 00000000..38dd12d4
--- /dev/null
+++ b/OctoAwesome/OctoAwesome.Basics/Controls/ToolbarInventoryControl.cs
@@ -0,0 +1,155 @@
+using engenious;
+using engenious.Graphics;
+using engenious.Input;
+using MonoGameUi;
+using OctoAwesome.Basics.EntityComponents;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OctoAwesome.Basics.Controls
+{
+ class ToolbarInventoryControl : Panel
+ {
+ private Dictionary toolTextures = new Dictionary();
+
+ private Image[] images;
+
+ private Brush backgroundBrush;
+
+ private Brush hoverBrush;
+
+ private ToolBarComponent bar;
+
+ public ToolbarInventoryControl(BaseScreenComponent screenmanager, IUserInterfaceExtensionManager manager,
+ ToolBarComponent bar) : base(screenmanager)
+ {
+ Texture2D panelBackground = manager.LoadTextures(manager.GetType(), "panel");
+ Background = NineTileBrush.FromSingleTexture(panelBackground, 30, 30);
+ Margin = new Border(0, 0, 0, 0);
+ HorizontalAlignment = HorizontalAlignment.Stretch;
+ VerticalAlignment = VerticalAlignment.Stretch;
+
+ this.bar = bar;
+ backgroundBrush = new BorderBrush(Color.Black);
+ hoverBrush = new BorderBrush(Color.Brown);
+
+ foreach (var item in bar.Service.DefinitionManager.GetDefinitions())
+ {
+ Texture2D texture = manager.LoadTextures(item.GetType(), item.Icon);
+ toolTextures.Add(item.GetType().FullName, texture);
+ }
+
+ Grid toolbar = new Grid(ScreenManager)
+ {
+ HorizontalAlignment = HorizontalAlignment.Stretch,
+ VerticalAlignment = VerticalAlignment.Center,
+ };
+ Controls.Add(toolbar);
+
+ toolbar.Columns.Add(new ColumnDefinition() { ResizeMode = ResizeMode.Parts, Width = 1 });
+
+ for (int i = 0; i < bar.Tools.Length; i++)
+ toolbar.Rows.Add(new RowDefinition() { ResizeMode = ResizeMode.Fixed, Height = 50 });
+
+ images = new Image[bar.Tools.Length];
+ for (int i = 0; i < images.Length; i++)
+ {
+ Image image = images[i] = new Image(screenmanager)
+ {
+ Width = 42,
+ Height = 42,
+ Background = backgroundBrush,
+ HorizontalAlignment = HorizontalAlignment.Center,
+ Tag = i,
+ Padding = Border.All(2),
+ };
+
+ image.StartDrag += (e) =>
+ {
+ InventorySlot slot = bar.Tools[(int) image.Tag];
+ if (slot != null)
+ {
+ e.Handled = true;
+ e.Icon = toolTextures[slot.Definition.GetType().FullName];
+ e.Content = slot;
+ e.Sender = toolbar;
+ }
+ };
+
+ image.DropEnter += (e) => { image.Background = hoverBrush; };
+ image.DropLeave += (e) => { image.Background = backgroundBrush; };
+ image.EndDrop += (e) =>
+ {
+ e.Handled = true;
+
+ //TODO: wieder hinzufügen, oder anders lösen
+ if (e.Sender is Grid) // && ShiftPressed
+ {
+ // Swap
+ int targetIndex = (int) image.Tag;
+ InventorySlot targetSlot = bar.Tools[targetIndex];
+
+ InventorySlot sourceSlot = e.Content as InventorySlot;
+ int sourceIndex = bar.GetSlotIndex(sourceSlot);
+
+ bar.SetTool(sourceSlot, targetIndex);
+ bar.SetTool(targetSlot, sourceIndex);
+ }
+ else
+ {
+ // Inventory Drop
+ InventorySlot slot = e.Content as InventorySlot;
+ bar.SetTool(slot, (int) image.Tag);
+ }
+ };
+
+ toolbar.AddControl(image, 0, i);
+ }
+ }
+ protected override void OnUpdate(GameTime gameTime)
+ {
+ //Aktualisierung des aktiven Buttons
+ for (int i = 0; i < bar.Tools.Length; i++)
+ {
+ if (bar.Tools != null &&
+ bar.Tools.Length > i &&
+ bar.Tools[i] != null &&
+ bar.Tools[i].Definition != null)
+ {
+ images[i].Texture = toolTextures[bar.Tools[i].Definition.GetType().FullName];
+ }
+ else
+ {
+ images[i].Texture = null;
+ }
+ }
+ }
+ protected override void OnEndDrop(DragEventArgs args)
+ {
+ if (args.Content is InventorySlot slot)
+ {
+ args.Handled = true;
+ bar.RemoveSlot(slot);
+ }
+ }
+ //protected override void OnKeyDown(KeyEventArgs args)
+ //{
+ // // TODO: lösung finden
+ // //Tool neu zuweisen
+ // //if ((int) args.Key >= (int) Keys.D0 && (int) args.Key <= (int) Keys.D9)
+ // //{
+ // // int offset = (int) args.Key - (int) Keys.D0;
+ // // player.Toolbar.SetTool(inventory.HoveredSlot, offset);
+ // // args.Handled = true;
+ // //}
+ //}
+ public override string ToString()
+ {
+ // TODO: resx
+ return "Werkzeuge";
+ }
+ }
+}
diff --git a/OctoAwesome/OctoAwesome.Basics/Definitions/Blocks/BirchWoodBlockDefinition.cs b/OctoAwesome/OctoAwesome.Basics/Definitions/Blocks/BirchWoodBlockDefinition.cs
index 71450244..57b897e9 100644
--- a/OctoAwesome/OctoAwesome.Basics/Definitions/Blocks/BirchWoodBlockDefinition.cs
+++ b/OctoAwesome/OctoAwesome.Basics/Definitions/Blocks/BirchWoodBlockDefinition.cs
@@ -27,14 +27,7 @@ public override PhysicalProperties GetProperties(ILocalChunkCache manager, int x
Granularity = 0.9f,
Hardness = 0.1f
};
-
- public override void Hit(IBlockDefinition block, PhysicalProperties itemProperties)
- {
- throw new NotImplementedException();
- }
-
- public override int GetTextureIndex(Wall wall, ILocalChunkCache manager,
- int x, int y, int z)
+ public override int GetTextureIndex(Wall wall, ILocalChunkCache manager, int x, int y, int z)
{
OrientationFlags orientation = (OrientationFlags)manager.GetBlockMeta(x, y, z);
@@ -98,10 +91,9 @@ public override int GetTextureIndex(Wall wall, ILocalChunkCache manager,
// Assert here
return -1;
}
-
public override int GetTextureRotation(Wall wall, ILocalChunkCache manager, int x, int y, int z)
{
- OrientationFlags orientation = (OrientationFlags)manager.GetBlockMeta(x, y, z);
+ OrientationFlags orientation = (OrientationFlags) manager.GetBlockMeta(x, y, z);
switch (wall)
{
case Wall.Top:
@@ -138,5 +130,9 @@ public override int GetTextureRotation(Wall wall, ILocalChunkCache manager, int
return base.GetTextureRotation(wall, manager, x, y, z); //should never ever happen
}
}
+ public override void Hit(IBlockDefinition block, PhysicalProperties itemProperties)
+ {
+ throw new NotImplementedException();
+ }
}
}
diff --git a/OctoAwesome/OctoAwesome.Basics/Entities/WauziEntity.cs b/OctoAwesome/OctoAwesome.Basics/Entities/WauziEntity.cs
index 818f58ad..3ccf6928 100644
--- a/OctoAwesome/OctoAwesome.Basics/Entities/WauziEntity.cs
+++ b/OctoAwesome/OctoAwesome.Basics/Entities/WauziEntity.cs
@@ -1,59 +1,75 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using engenious;
-using OctoAwesome.Basics.EntityComponents;
-using OctoAwesome.EntityComponents;
-
+using engenious;
+using OctoAwesome.Entities;
namespace OctoAwesome.Basics.Entities
{
- public class WauziEntity : UpdateableEntity
+ public class WauziEntity : Entity, IControllable, OctoAwesome.Entities.IDrawable
{
- public int JumpTime { get; set; }
-
- public WauziEntity() : base()
+ class WauziTestController : IEntityController
{
+ public float Tilt { get; set; }
+ public float Yaw { get; set; }
+ public Vector3 Direction { get; set; }
+ public Index3? SelectedBlock { get; set; }
+ public Vector2? SelectedPoint { get; set; }
+
+ public OrientationFlags SelectedSide => OrientationFlags.None;
+ public OrientationFlags SelectedEdge => OrientationFlags.None;
+ public OrientationFlags SelectedCorner => OrientationFlags.None;
+
+ public bool InteractInput { get; set; }
+ public bool ApplyInput { get; set; }
+ public bool JumpInput { get; set; }
+
+ public bool[] SlotInput{ get; } = new bool[10];
+
+ public bool SlotLeftInput { get; set; }
+ public bool SlotRightInput { get; set; }
+
+ public WauziTestController()
+ {
+ }
}
+ public IEntityController Controller => currentcontroller;
+ public bool DrawUpdate => true;
+ // TODO: Auslagern in die Definition
+ public string Name => "Wauzi";
+ public string ModelName => "dog";
+ public string TextureName => "texdog";
+ public float BaseRotationZ => -90f;
+
+ public float Height => 1;
+ public float Radius => 1;
+ private IEntityController currentcontroller;
+ private float jumptime;
+ public WauziEntity() : base(true)
+ {
+ currentcontroller = new WauziTestController();
+ SetPosition(new Coordinate(0, new Index3(0, 0, 200), new Vector3(0, 0, 0)), 0, false);
+ }
protected override void OnInitialize(IResourceManager manager)
{
Cache = new LocalChunkCache(manager.GlobalChunkCache, true, 2, 1);
}
-
public override void Update(GameTime gameTime)
- {
- BodyPowerComponent body = Components.GetComponent();
- ControllableComponent controller = Components.GetComponent();
- controller.MoveInput = new Vector2(0.5f, 0.5f) ;
-
- if (JumpTime <= 0)
+ {
+ if (currentcontroller != null && jumptime <= 0)
{
- controller.JumpInput = true;
- JumpTime = 10000;
+ currentcontroller.JumpInput = true;
+ jumptime = 10000;
}
else
{
- JumpTime -= gameTime.ElapsedGameTime.Milliseconds;
- }
-
- if (controller.JumpActive)
- {
- controller.JumpInput = false;
+ jumptime -= gameTime.ElapsedGameTime.Milliseconds;
}
}
-
- public override void RegisterDefault()
+ public void Register(IEntityController controller)
{
- Components.AddComponent(new PositionComponent() { Position = new Coordinate(0, new Index3(0, 0, 200), new Vector3(0, 0, 0)) });
- Components.AddComponent(new GravityComponent());
- Components.AddComponent(new BodyComponent() { Mass = 50f, Height = 2f, Radius = 1.5f });
- Components.AddComponent(new BodyPowerComponent() { Power = 600f, JumpTime = 120 });
- Components.AddComponent(new MoveableComponent());
- Components.AddComponent(new BoxCollisionComponent());
- Components.AddComponent(new ControllableComponent());
- Components.AddComponent(new RenderComponent() { Name = "Wauzi", ModelName = "dog", TextureName = "texdog", BaseZRotation = -90 }, true);
+ this.currentcontroller = controller;
+ }
+ public void Reset()
+ {
+
}
}
}
diff --git a/OctoAwesome/OctoAwesome/EntityComponents/BodyComponent.cs b/OctoAwesome/OctoAwesome.Basics/EntityComponents/BodyComponent.cs
similarity index 90%
rename from OctoAwesome/OctoAwesome/EntityComponents/BodyComponent.cs
rename to OctoAwesome/OctoAwesome.Basics/EntityComponents/BodyComponent.cs
index dc939209..49e7f119 100644
--- a/OctoAwesome/OctoAwesome/EntityComponents/BodyComponent.cs
+++ b/OctoAwesome/OctoAwesome.Basics/EntityComponents/BodyComponent.cs
@@ -1,9 +1,5 @@
-using System;
-using System.Collections.Generic;
+using OctoAwesome.Entities;
using System.IO;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace OctoAwesome.EntityComponents
{
diff --git a/OctoAwesome/OctoAwesome.Basics/EntityComponents/BodyPowerComponent.cs b/OctoAwesome/OctoAwesome.Basics/EntityComponents/BodyPowerComponent.cs
index 58d8d90e..fb033417 100644
--- a/OctoAwesome/OctoAwesome.Basics/EntityComponents/BodyPowerComponent.cs
+++ b/OctoAwesome/OctoAwesome.Basics/EntityComponents/BodyPowerComponent.cs
@@ -1,9 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+using System.IO;
namespace OctoAwesome.Basics.EntityComponents
{
diff --git a/OctoAwesome/OctoAwesome.Basics/EntityComponents/BoxCollisionComponent.cs b/OctoAwesome/OctoAwesome.Basics/EntityComponents/BoxCollisionComponent.cs
index 992b0274..5502f325 100644
--- a/OctoAwesome/OctoAwesome.Basics/EntityComponents/BoxCollisionComponent.cs
+++ b/OctoAwesome/OctoAwesome.Basics/EntityComponents/BoxCollisionComponent.cs
@@ -1,4 +1,7 @@
-using System;
+using engenious;
+using OctoAwesome.Entities;
+using OctoAwesome.EntityComponents;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -8,5 +11,109 @@ namespace OctoAwesome.Basics.EntityComponents
{
public sealed class BoxCollisionComponent : CollisionComponent
{
+
+ private void CheckBoxCollision(GameTime gameTime, Entity e, MoveableComponent movecomp, PositionComponent poscomp)
+ {
+ BodyComponent bc = new BodyComponent();
+ if (e.Components.ContainsComponent())
+ bc = e.Components.GetComponent();
+
+
+ Coordinate position = poscomp.Position;
+
+ Vector3 move = movecomp.PositionMove;
+
+ //Blocks finden die eine Kollision verursachen könnten
+ int minx = (int) Math.Floor(Math.Min(
+ position.BlockPosition.X - bc.Radius,
+ position.BlockPosition.X - bc.Radius + movecomp.PositionMove.X));
+ int maxx = (int) Math.Ceiling(Math.Max(
+ position.BlockPosition.X + bc.Radius,
+ position.BlockPosition.X + bc.Radius + movecomp.PositionMove.X));
+ int miny = (int) Math.Floor(Math.Min(
+ position.BlockPosition.Y - bc.Radius,
+ position.BlockPosition.Y - bc.Radius + movecomp.PositionMove.Y));
+ int maxy = (int) Math.Ceiling(Math.Max(
+ position.BlockPosition.Y + bc.Radius,
+ position.BlockPosition.Y + bc.Radius + movecomp.PositionMove.Y));
+ int minz = (int) Math.Floor(Math.Min(
+ position.BlockPosition.Z,
+ position.BlockPosition.Z + movecomp.PositionMove.Z));
+ int maxz = (int) Math.Ceiling(Math.Max(
+ position.BlockPosition.Z + bc.Height,
+ position.BlockPosition.Z + bc.Height + movecomp.PositionMove.Z));
+
+ //Beteiligte Flächen des Spielers
+ var playerplanes = CollisionPlane.GetPlayerCollisionPlanes(bc.Radius, bc.Height, movecomp.Velocity, poscomp.Position);
+
+ bool abort = false;
+
+ for (int z = minz; z <= maxz && !abort; z++)
+ {
+ for (int y = miny; y <= maxy && !abort; y++)
+ {
+ for (int x = minx; x <= maxx && !abort; x++)
+ {
+ move = movecomp.Velocity * (float) gameTime.ElapsedGameTime.TotalSeconds;
+
+ Index3 pos = new Index3(x, y, z);
+ Index3 blockPos = pos + position.GlobalBlockIndex;
+ ushort block = e.Cache.GetBlock(blockPos);
+ if (block == 0)
+ continue;
+
+
+
+ var blockplane = CollisionPlane.GetBlockCollisionPlanes(pos, movecomp.Velocity);
+
+ var planes = from pp in playerplanes
+ from bp in blockplane
+ where CollisionPlane.Intersect(bp, pp)
+ let distance = CollisionPlane.GetDistance(bp, pp)
+ where CollisionPlane.CheckDistance(distance, move)
+ select new { BlockPlane = bp, PlayerPlane = pp, Distance = distance };
+
+ foreach (var plane in planes)
+ {
+
+ var subvelocity = (plane.Distance / (float) gameTime.ElapsedGameTime.TotalSeconds);
+ var diff = movecomp.Velocity - subvelocity;
+
+ float vx;
+ float vy;
+ float vz;
+
+ if (plane.BlockPlane.normal.X != 0 && (movecomp.Velocity.X > 0 && diff.X >= 0 && subvelocity.X >= 0 || movecomp.Velocity.X < 0 && diff.X <= 0 && subvelocity.X <= 0))
+ vx = subvelocity.X;
+ else
+ vx = movecomp.Velocity.X;
+
+ if (plane.BlockPlane.normal.Y != 0 && (movecomp.Velocity.Y > 0 && diff.Y >= 0 && subvelocity.Y >= 0 || movecomp.Velocity.Y < 0 && diff.Y <= 0 && subvelocity.Y <= 0))
+ vy = subvelocity.Y;
+ else
+ vy = movecomp.Velocity.Y;
+
+ if (plane.BlockPlane.normal.Z != 0 && (movecomp.Velocity.Z > 0 && diff.Z >= 0 && subvelocity.Z >= 0 || movecomp.Velocity.Z < 0 && diff.Z <= 0 && subvelocity.Z <= 0))
+ vz = subvelocity.Z;
+ else
+ vz = movecomp.Velocity.Z;
+
+ movecomp.Velocity = new Vector3(vx, vy, vz);
+
+ if (vx == 0 && vy == 0 && vz == 0)
+ {
+ abort = true;
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ // TODO: Was ist für den Fall Gravitation = 0 oder im Scheitelpunkt des Sprungs?
+ //movecomp.OnGround = Player.Velocity.Z == 0f;
+
+ movecomp.PositionMove = movecomp.Velocity * (float) gameTime.ElapsedGameTime.TotalSeconds;
+ }
}
}
diff --git a/OctoAwesome/OctoAwesome.Basics/EntityComponents/CollisionComponent.cs b/OctoAwesome/OctoAwesome.Basics/EntityComponents/CollisionComponent.cs
index 2c3c9aef..07ba04da 100644
--- a/OctoAwesome/OctoAwesome.Basics/EntityComponents/CollisionComponent.cs
+++ b/OctoAwesome/OctoAwesome.Basics/EntityComponents/CollisionComponent.cs
@@ -1,4 +1,5 @@
-using System;
+using OctoAwesome.Entities;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
diff --git a/OctoAwesome/OctoAwesome/EntityComponents/ControllableComponent.cs b/OctoAwesome/OctoAwesome.Basics/EntityComponents/ControllableComponent.cs
similarity index 80%
rename from OctoAwesome/OctoAwesome/EntityComponents/ControllableComponent.cs
rename to OctoAwesome/OctoAwesome.Basics/EntityComponents/ControllableComponent.cs
index e47c47d1..ed9e868c 100644
--- a/OctoAwesome/OctoAwesome/EntityComponents/ControllableComponent.cs
+++ b/OctoAwesome/OctoAwesome.Basics/EntityComponents/ControllableComponent.cs
@@ -1,20 +1,16 @@
using engenious;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+using OctoAwesome.Entities;
namespace OctoAwesome.EntityComponents
{
public class ControllableComponent : EntityComponent
{
- public bool JumpInput { get; set; }
- public Vector2 MoveInput { get; set; }
public bool JumpActive { get; set; }
public int JumpTime { get; set; }
+ public Vector2 MoveInput { get; set; }
+ public bool JumpInput { get; set; }
public Index3? InteractBlock { get; set; }
public Index3? ApplyBlock { get; set; }
public OrientationFlags ApplySide { get; set; }
diff --git a/OctoAwesome/OctoAwesome.Basics/EntityComponents/ForceComponent.cs b/OctoAwesome/OctoAwesome.Basics/EntityComponents/ForceComponent.cs
index a692aa0b..880e678f 100644
--- a/OctoAwesome/OctoAwesome.Basics/EntityComponents/ForceComponent.cs
+++ b/OctoAwesome/OctoAwesome.Basics/EntityComponents/ForceComponent.cs
@@ -1,4 +1,5 @@
using engenious;
+using OctoAwesome.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
diff --git a/OctoAwesome/OctoAwesome.Basics/EntityComponents/GroundPhysicComponent.cs b/OctoAwesome/OctoAwesome.Basics/EntityComponents/GroundPhysicComponent.cs
new file mode 100644
index 00000000..3881b88b
--- /dev/null
+++ b/OctoAwesome/OctoAwesome.Basics/EntityComponents/GroundPhysicComponent.cs
@@ -0,0 +1,111 @@
+using engenious;
+using engenious.Helper;
+using OctoAwesome.CodeExtensions;
+using OctoAwesome.Entities;
+using System;
+namespace OctoAwesome.Basics.EntityComponents
+{
+ class GroundPhysicComponent : EntityComponent
+ {
+ public float Mass { get; }
+ public float Radius { get; }
+ public float Height { get; }
+ public float Trust { get; }
+
+ bool onGround;
+ float azimuth;
+ Vector3 inputforce;
+ Vector3 externalForce;
+ Vector3 acceleration;
+ Vector3 velocity;
+ Vector3 deltaPosition;
+
+ public GroundPhysicComponent(Entity entity, IGameService service, float mass, float trust, float radius, float height) :
+ base(entity, service, true)
+ {
+ if (entity == null) throw new ArgumentNullException(nameof(entity));
+ Mass = mass;
+ Trust = trust;
+ Radius = radius;
+ Height = height;
+ IPlanet planet = entity.Cache.GetPlanet(entity.Position.Planet);
+ entity.Position.NormalizeChunkIndexXY(planet.Size);
+ entity.Cache.SetCenter(planet, new Index2(entity.Position.ChunkIndex));
+ }
+ public override void Update(GameTime gameTime)
+ {
+ IEntityController controller = (Entity as IControllable)?.Controller;
+ if (controller != null)
+ CalcInput(gameTime, controller);
+ else inputforce = Vector3.Zero;
+ CalcMotion(gameTime);
+ velocity = Service.WorldCollision(gameTime, Entity, Radius, Height, deltaPosition, velocity);
+ // TODO: Was ist für den Fall Gravitation = 0 oder im Scheitelpunkt des Sprungs?
+ // Gravitation sollte eigentlich nicht sein.
+ onGround = velocity.Z == 0;
+ if (velocity.IsEmtpy()) deltaPosition = Vector3.Zero;
+ else
+ {
+ deltaPosition = velocity * (float) gameTime.ElapsedGameTime.TotalSeconds;
+ Entity.Move(deltaPosition, azimuth);
+ }
+ }
+ private void CalcInput(GameTime gameTime, IEntityController controller)
+ {
+ inputforce = controller.Direction * Trust;
+ if (controller.JumpInput)
+ {
+ controller.JumpInput = false;
+ velocity += new Vector3(0, 0, 5);
+ }
+ }
+ private void CalcMotion(GameTime gameTime)
+ {
+ externalForce = Vector3.Zero;
+ float gravity = Entity.Cache.Planet.Gravity;
+ if (gravity == 0) gravity = 9.81f;
+ float gravityforce = -Mass * gravity;
+
+ Index3 blockPos = new Index3(0, 0, -1) + Entity.Position.GlobalBlockIndex;
+ ushort groundblock = Entity.Cache.GetBlock(blockPos);
+ float fluidC = 0;
+ float stictionC = 0;
+ float airCoefficent = 5;
+ if (groundblock != 0 && onGround)
+ {
+ //TODO: friction of underground
+ //IBlockDefinition definition = definitionManager.GetDefinitionByIndex(groundblock) as IBlockDefinition;
+ //if (definition != null)
+ //{
+ //}
+ fluidC = 25;
+ if (inputforce.IsEmtpy()) fluidC *= 10f;
+ }
+ float xresforce = 0;
+ float yresforce = 0;
+ if (onGround)
+ {
+ if(velocity.IsEmtpy())
+ {
+ // TODO: haftreibung
+ //stiction
+ //float stiction = Math.Abs(scoefficeint * gravityforce);
+ //if (stiction < externalForce.X)
+ // xresforce = defaultTrust.X - Math.Sign(direction.X) * stiction;
+ //if (stiction < externalForce.Y)
+ // yresforce = defaultTrust.Y - Math.Sign(direction.Y) * stiction;
+ }
+ else externalForce += new Vector3(velocity.X * -fluidC, velocity.Y * -fluidC, 0); //fluid or sliding friction
+ }
+ // air friction
+ externalForce += velocity * - airCoefficent + new Vector3(xresforce, yresforce, gravityforce);
+
+ acceleration = (inputforce + externalForce) / Mass;
+ velocity += acceleration * (float) gameTime.ElapsedGameTime.TotalSeconds;
+
+ if (velocity.X != 0 && velocity.Y != 0)
+ azimuth = MathHelper.WrapAngle((float) Math.Atan2(velocity.Y, velocity.X));
+ deltaPosition = velocity * (float) gameTime.ElapsedGameTime.TotalSeconds;
+ }
+ }
+}
diff --git a/OctoAwesome/OctoAwesome/EntityComponents/HeadComponent.cs b/OctoAwesome/OctoAwesome.Basics/EntityComponents/HeadComponent.cs
similarity index 91%
rename from OctoAwesome/OctoAwesome/EntityComponents/HeadComponent.cs
rename to OctoAwesome/OctoAwesome.Basics/EntityComponents/HeadComponent.cs
index 55cd73dd..4841b199 100644
--- a/OctoAwesome/OctoAwesome/EntityComponents/HeadComponent.cs
+++ b/OctoAwesome/OctoAwesome.Basics/EntityComponents/HeadComponent.cs
@@ -1,10 +1,6 @@
using engenious;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
using System.IO;
+using OctoAwesome.Entities;
namespace OctoAwesome.EntityComponents
{
diff --git a/OctoAwesome/OctoAwesome/EntityComponents/InventoryComponent.cs b/OctoAwesome/OctoAwesome.Basics/EntityComponents/InventoryComponent.cs
similarity index 82%
rename from OctoAwesome/OctoAwesome/EntityComponents/InventoryComponent.cs
rename to OctoAwesome/OctoAwesome.Basics/EntityComponents/InventoryComponent.cs
index 58e03739..f7eeced8 100644
--- a/OctoAwesome/OctoAwesome/EntityComponents/InventoryComponent.cs
+++ b/OctoAwesome/OctoAwesome.Basics/EntityComponents/InventoryComponent.cs
@@ -1,24 +1,24 @@
-using System;
+using engenious;
+using engenious.Graphics;
+using MonoGameUi;
+using OctoAwesome.Basics.Controls;
+using OctoAwesome.Entities;
using System.Collections.Generic;
using System.IO;
using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-namespace OctoAwesome.EntityComponents
+namespace OctoAwesome.Basics.EntityComponents
{
- public class InventoryComponent : EntityComponent
+ public class InventoryComponent : EntityComponent, IUserInterfaceExtension, IInventory
{
///
/// Das Inventar der Entity
///
public List Inventory { get; set; }
-
- public InventoryComponent()
+ public InventoryComponent(Entity entity, IGameService service) : base(entity, service, false)
{
Inventory = new List();
}
-
public override void Deserialize(BinaryReader reader, IDefinitionManager definitionManager)
{
base.Deserialize(reader, definitionManager);
@@ -42,7 +42,6 @@ public override void Deserialize(BinaryReader reader, IDefinitionManager definit
Inventory.Add(slot);
}
}
-
public override void Serialize(BinaryWriter writer, IDefinitionManager definitionManager)
{
base.Serialize(writer, definitionManager);
@@ -54,7 +53,6 @@ public override void Serialize(BinaryWriter writer, IDefinitionManager definitio
writer.Write(slot.Amount);
}
}
-
///
/// Fügt ein Element des angegebenen Definitionstyps hinzu.
///
@@ -76,7 +74,6 @@ public void AddUnit(IInventoryableDefinition definition)
}
slot.Amount += definition.VolumePerUnit;
}
-
///
/// Entfernt eine Einheit vom angegebenen Slot.
///
@@ -90,11 +87,17 @@ public bool RemoveUnit(InventorySlot slot)
if (slot.Amount >= definition.VolumePerUnit) // Wir können noch einen Block setzen
{
slot.Amount -= definition.VolumePerUnit;
- if (slot.Amount <= 0)
- Inventory.Remove(slot);
+ if (slot.Amount <= 0) Inventory.Remove(slot);
return true;
}
return false;
}
+ public override void Update(GameTime gameTime)
+ {
+ }
+ public void Register(IUserInterfaceExtensionManager manager)
+ {
+ manager.RegisterOnInventoryScreen(typeof(InventoryControl), this);
+ }
}
}
diff --git a/OctoAwesome/OctoAwesome.Basics/EntityComponents/MassComponent.cs b/OctoAwesome/OctoAwesome.Basics/EntityComponents/MassComponent.cs
index beca668c..468f450f 100644
--- a/OctoAwesome/OctoAwesome.Basics/EntityComponents/MassComponent.cs
+++ b/OctoAwesome/OctoAwesome.Basics/EntityComponents/MassComponent.cs
@@ -1,4 +1,5 @@
-using System;
+using OctoAwesome.Entities;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
diff --git a/OctoAwesome/OctoAwesome.Basics/EntityComponents/MoveableComponent.cs b/OctoAwesome/OctoAwesome.Basics/EntityComponents/MoveableComponent.cs
index 62f74f56..db8b0d7e 100644
--- a/OctoAwesome/OctoAwesome.Basics/EntityComponents/MoveableComponent.cs
+++ b/OctoAwesome/OctoAwesome.Basics/EntityComponents/MoveableComponent.cs
@@ -1,9 +1,5 @@
using engenious;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+using OctoAwesome.Entities;
namespace OctoAwesome.Basics.EntityComponents
{
diff --git a/OctoAwesome/OctoAwesome/EntityComponents/PositionComponent.cs b/OctoAwesome/OctoAwesome.Basics/EntityComponents/PositionComponent.cs
similarity index 84%
rename from OctoAwesome/OctoAwesome/EntityComponents/PositionComponent.cs
rename to OctoAwesome/OctoAwesome.Basics/EntityComponents/PositionComponent.cs
index 3984e4ca..20b123b1 100644
--- a/OctoAwesome/OctoAwesome/EntityComponents/PositionComponent.cs
+++ b/OctoAwesome/OctoAwesome.Basics/EntityComponents/PositionComponent.cs
@@ -1,10 +1,6 @@
using engenious;
-using System;
-using System.Collections.Generic;
+using OctoAwesome.Entities;
using System.IO;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace OctoAwesome.EntityComponents
{
@@ -43,7 +39,9 @@ public override void Deserialize(BinaryReader reader, IDefinitionManager definit
float posY = reader.ReadSingle();
float posZ = reader.ReadSingle();
- Position = new Coordinate(planet, new Index3(blockX, blockY, blockZ), new Vector3(posX, posY, posZ));
+ Position = new Coordinate(reader.ReadInt32(),
+ new Index3(reader.ReadInt32(), reader.ReadInt32(), reader.ReadInt32()),
+ new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()));
}
}
}
diff --git a/OctoAwesome/OctoAwesome.Basics/EntityComponents/PowerComponent.cs b/OctoAwesome/OctoAwesome.Basics/EntityComponents/PowerComponent.cs
index 066ec00a..24b90886 100644
--- a/OctoAwesome/OctoAwesome.Basics/EntityComponents/PowerComponent.cs
+++ b/OctoAwesome/OctoAwesome.Basics/EntityComponents/PowerComponent.cs
@@ -5,6 +5,7 @@
using System.Text;
using System.Threading.Tasks;
using System.IO;
+using OctoAwesome.Entities;
namespace OctoAwesome.Basics.EntityComponents
{
diff --git a/OctoAwesome/OctoAwesome/EntityComponents/RenderComponent.cs b/OctoAwesome/OctoAwesome.Basics/EntityComponents/RenderComponent.cs
similarity index 71%
rename from OctoAwesome/OctoAwesome/EntityComponents/RenderComponent.cs
rename to OctoAwesome/OctoAwesome.Basics/EntityComponents/RenderComponent.cs
index c39efecd..3d979dc9 100644
--- a/OctoAwesome/OctoAwesome/EntityComponents/RenderComponent.cs
+++ b/OctoAwesome/OctoAwesome.Basics/EntityComponents/RenderComponent.cs
@@ -1,8 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+using OctoAwesome.Entities;
namespace OctoAwesome.EntityComponents
{
diff --git a/OctoAwesome/OctoAwesome/EntityComponents/ToolBarComponent.cs b/OctoAwesome/OctoAwesome.Basics/EntityComponents/ToolBarComponent.cs
similarity index 54%
rename from OctoAwesome/OctoAwesome/EntityComponents/ToolBarComponent.cs
rename to OctoAwesome/OctoAwesome.Basics/EntityComponents/ToolBarComponent.cs
index fd5a1c6a..3cd8bf0e 100644
--- a/OctoAwesome/OctoAwesome/EntityComponents/ToolBarComponent.cs
+++ b/OctoAwesome/OctoAwesome.Basics/EntityComponents/ToolBarComponent.cs
@@ -1,40 +1,37 @@
using System;
using System.Collections.Generic;
-using System.IO;
using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace OctoAwesome.EntityComponents
+using engenious;
+using engenious.Graphics;
+using MonoGameUi;
+using OctoAwesome.Basics.Controls;
+using OctoAwesome.Entities;
+namespace OctoAwesome.Basics.EntityComponents
{
///
- /// EntityComponent, die eine Werkzeug-Toolbar für den Apieler bereitstellt.
+ /// EntityComponent, die eine Werkzeug-Toolbar für den Spieler bereitstellt.
///
- public class ToolBarComponent : EntityComponent
+ public class ToolBarComponent : EntityComponent, IUserInterfaceExtension
{
///
- /// Gibt die Anzahl Tools in der Toolbar an.
+ /// Gibt die Anzahl der Tools in der Toolbar an.
///
public const int TOOLCOUNT = 10;
-
///
/// Auflistung der Werkzeuge die der Spieler in seiner Toolbar hat.
///
- public InventorySlot[] Tools { get; set; }
-
+ public InventorySlot[] Tools { get; }
///
/// Derzeit aktives Werkzeug des Spielers
///
public InventorySlot ActiveTool { get; set; }
-
///
/// Erzeugte eine neue ToolBarComponent
///
- public ToolBarComponent()
+ public ToolBarComponent(Entity entity, IGameService service) : base(entity, service, true)
{
Tools = new InventorySlot[TOOLCOUNT];
}
-
///
/// Entfernt einen InventorySlot aus der Toolbar
///
@@ -49,7 +46,6 @@ public void RemoveSlot(InventorySlot slot)
if (ActiveTool == slot)
ActiveTool = null;
}
-
///
/// Setzt einen InventorySlot an eine Stelle in der Toolbar und löscht ggf. vorher den Slot aus alten Positionen.
///
@@ -61,7 +57,6 @@ public void SetTool(InventorySlot slot, int index)
Tools[index] = slot;
}
-
///
/// Gibt den Index eines InventorySlots in der Toolbar zurück.
///
@@ -75,7 +70,6 @@ public int GetSlotIndex(InventorySlot slot)
return -1;
}
-
///
/// Fügt einen neuen InventorySlot an der ersten freien Stelle hinzu.
///
@@ -91,5 +85,40 @@ public void AddNewSlot(InventorySlot slot)
}
}
}
+ public override void Update(GameTime gameTime)
+ {
+ IEntityController controller = (Entity as IControllable)?.Controller;
+ if (controller == null) return;
+ else if(controller.InteractInput)
+ {
+ if (Entity.Components.TryGetComponent(out InventoryComponent inventory))
+ {
+ Service.TakeBlock(controller, Entity.Cache, inventory);
+ }
+ else if (Service.TakeBlock(controller, Entity.Cache, out IInventoryableDefinition item))
+ {
+ // TODO: und jetzt ?
+ }
+ }
+ else if(controller.ApplyInput)
+ {
+ if (Entity.Components.TryGetComponent(out InventoryComponent inventory))
+ Service.InteractBlock(Entity.Position, 0, 0, controller, Entity.Cache, ActiveTool, inventory);
+ }
+ }
+ public void Register(IUserInterfaceExtensionManager manager)
+ {
+ manager.RegisterOnGameScreen(typeof(ToolbarControl), this);
+ manager.RegisterOnInventoryScreen(typeof(ToolbarInventoryControl), this);
+ }
+ private void UpdateToolbar(InventoryComponent inventory)
+ {
+ foreach (InventorySlot slot in inventory.Inventory)
+ {
+ if (Tools.Any(s => s != null && s.Definition.Name == slot.Definition.Name))
+ continue;
+ else AddNewSlot(slot);
+ }
+ }
}
}
diff --git a/OctoAwesome/OctoAwesome.Basics/Extension.cs b/OctoAwesome/OctoAwesome.Basics/Extension.cs
index 56174caa..07b2299b 100644
--- a/OctoAwesome/OctoAwesome.Basics/Extension.cs
+++ b/OctoAwesome/OctoAwesome.Basics/Extension.cs
@@ -1,12 +1,9 @@
-using OctoAwesome.Basics.Definitions.Blocks;
-using OctoAwesome.Basics.Entities;
-using OctoAwesome.Basics.EntityComponents;
-using OctoAwesome.Basics.SimulationComponents;
-using OctoAwesome.EntityComponents;
+using OctoAwesome.Basics.Entities;
using System.Reflection;
using System.Linq;
using System;
-using engenious;
+using OctoAwesome.Entities;
+using OctoAwesome.Basics.EntityComponents;
namespace OctoAwesome.Basics
{
@@ -18,41 +15,38 @@ public sealed class Extension : IExtension
public void Register(IExtensionLoader extensionLoader)
{
-
foreach (var t in Assembly.GetExecutingAssembly().GetTypes().Where(
t => !t.IsAbstract && typeof(IDefinition).IsAssignableFrom(t)))
{
- extensionLoader.RegisterDefinition((IDefinition)Activator.CreateInstance(t));
+ extensionLoader.RegisterDefinition((IDefinition) Activator.CreateInstance(t));
}
-
extensionLoader.RegisterMapGenerator(new ComplexPlanetGenerator());
-
extensionLoader.RegisterMapPopulator(new TreePopulator());
- extensionLoader.RegisterMapPopulator(new WauziPopulator());
-
+ //extensionLoader.RegisterMapPopulator(new WauziPopulator());
extensionLoader.RegisterEntity();
extensionLoader.RegisterDefaultEntityExtender();
-
- extensionLoader.RegisterEntityExtender((p) =>
+ extensionLoader.RegisterEntityExtender((player, service) =>
+ {
+ player.Components.AddComponent(new GroundPhysicComponent(player, service, 60f, 400f, 0.8f, 3.5f));
+ InventoryComponent inventory = new InventoryComponent(player, service);
+ player.Components.AddComponent(inventory); // -> sinvoll
+ player.Components.AddComponent(new ToolBarComponent(player, service)); // -> sinvoll
+ });
+ extensionLoader.RegisterEntityExtender((p, service) =>
{
- p.Components.AddComponent(new GravityComponent());
- p.Components.AddComponent(new PositionComponent() { Position = new Coordinate(0, new Index3(0, 0, 200), new Vector3(0, 0, 0)) });
- p.Components.AddComponent(new BodyComponent() { Mass = 50f, Height = 3.5f, Radius = 0.75f });
- p.Components.AddComponent(new BodyPowerComponent() { Power = 600f, JumpTime = 120 });
- p.Components.AddComponent(new MoveableComponent());
- p.Components.AddComponent(new BoxCollisionComponent());
- p.Components.AddComponent(new EntityCollisionComponent());
+ p.Components.AddComponent(new GroundPhysicComponent(p, service, 30f, 300f, 1.2f, 1.6f));
});
extensionLoader.RegisterSimulationExtender((s) =>
{
- s.Components.AddComponent(new WattMoverComponent());
- s.Components.AddComponent(new NewtonGravitatorComponent());
- s.Components.AddComponent(new ForceAggregatorComponent());
- s.Components.AddComponent(new PowerAggregatorComponent());
- s.Components.AddComponent(new AccelerationComponent());
- s.Components.AddComponent(new MoveComponent());
- s.Components.AddComponent(new BlockInteractionComponent(s));
+ //s.Components.AddComponent(new GroundPhysicComponent(s.ResourceManager.DefinitionManager));
+ //s.Components.AddComponent(new WattMoverComponent());
+ //s.Components.AddComponent(new NewtonGravitatorComponent());
+ //s.Components.AddComponent(new ForceAggregatorComponent());
+ //s.Components.AddComponent(new PowerAggregatorComponent());
+ //s.Components.AddComponent(new AccelerationComponent());
+ //s.Components.AddComponent(new MoveComponent());
+ //s.Components.AddComponent(new BlockInteractionComponent(s));
//TODO: unschön
});
}
diff --git a/OctoAwesome/OctoAwesome.Basics/OctoAwesome.Basics.csproj b/OctoAwesome/OctoAwesome.Basics/OctoAwesome.Basics.csproj
index 943f3bac..0b6fd99e 100644
--- a/OctoAwesome/OctoAwesome.Basics/OctoAwesome.Basics.csproj
+++ b/OctoAwesome/OctoAwesome.Basics/OctoAwesome.Basics.csproj
@@ -46,6 +46,10 @@
..\packages\engenious.0.1.11\lib\net40\engenious.dll
+
+ False
+ ..\libs\MonoGameUi.dll
+
..\packages\engenious.0.1.11\lib\net40\NVorbis.dll
True
@@ -59,6 +63,9 @@
..\packages\engenious.0.1.11\lib\net40\System.Numerics.Vectors.dll
+
+ ..\packages\System.ValueTuple.4.4.0\lib\net461\System.ValueTuple.dll
+
@@ -67,19 +74,19 @@
-
+
+
+
+
+
+
-
-
-
-
-
@@ -90,10 +97,6 @@
-
-
-
-
@@ -135,14 +138,6 @@
-
-
-
-
-
-
-
-
diff --git a/OctoAwesome/OctoAwesome.Basics/SimulationComponents/AccelerationComponent.cs b/OctoAwesome/OctoAwesome.Basics/SimulationComponents/AccelerationComponent.cs
index 47765256..125099bc 100644
--- a/OctoAwesome/OctoAwesome.Basics/SimulationComponents/AccelerationComponent.cs
+++ b/OctoAwesome/OctoAwesome.Basics/SimulationComponents/AccelerationComponent.cs
@@ -3,12 +3,13 @@
using System.Linq;
using engenious;
using OctoAwesome.Basics.EntityComponents;
+using OctoAwesome.Entities;
using OctoAwesome.EntityComponents;
namespace OctoAwesome.Basics.SimulationComponents
{
[EntityFilter(typeof(MoveableComponent), typeof(BodyComponent))]
- public sealed class AccelerationComponent : SimulationComponent
+ public sealed class AccelerationComponent : OSimulationComponent
{
private List acceleratedEntities = new List();
@@ -17,20 +18,20 @@ public override void Update(GameTime gameTime)
foreach (var entity in acceleratedEntities)
{
// Convert external Forces to Powers
- Vector3 power = ((entity.Move.ExternalForces * entity.Move.ExternalForces) / (2 * entity.Body.Mass)) *
- (float)gameTime.ElapsedGameTime.TotalSeconds;
+ Vector3 power = ((entity.Move.ExternalForces * entity.Move.ExternalForces) / (2 * entity.Body.Mass)) *
+ (float) gameTime.ElapsedGameTime.TotalSeconds;
// Take care of direction
power *= new Vector3(
- Math.Sign(entity.Move.ExternalForces.X),
- Math.Sign(entity.Move.ExternalForces.Y),
+ Math.Sign(entity.Move.ExternalForces.X),
+ Math.Sign(entity.Move.ExternalForces.Y),
Math.Sign(entity.Move.ExternalForces.Z));
// Add external Power
power += entity.Move.ExternalPowers;
// Friction Power
- power -= new Vector3(60F,60f,0.1f) * entity.Move.Velocity;
+ power -= new Vector3(60F, 60f, 0.1f) * entity.Move.Velocity;
//DEBUGGING
var a1 = 2.0f / entity.Body.Mass;
@@ -38,23 +39,22 @@ public override void Update(GameTime gameTime)
var a2 = a1 * power;
var c = new Vector3(a1 * power.X, a1 * power.Y, a1 * power.Z);
- var a3 = a2 * (float)gameTime.ElapsedGameTime.TotalSeconds;
-
+ var a3 = a2 * (float) gameTime.ElapsedGameTime.TotalSeconds;
+
//DEBUGGING
// Calculate Velocity change
- Vector3 velocityChange = ((2.0f / entity.Body.Mass) * power) *
- (float)gameTime.ElapsedGameTime.TotalSeconds;
+ Vector3 velocityChange = ((2.0f / entity.Body.Mass) * power) * (float) gameTime.ElapsedGameTime.TotalSeconds;
// Take care of direction
entity.Move.Velocity += new Vector3(
- (float)(velocityChange.X < 0 ? -Math.Sqrt(-velocityChange.X) : Math.Sqrt(velocityChange.X)),
- (float)(velocityChange.Y < 0 ? -Math.Sqrt(-velocityChange.Y) : Math.Sqrt(velocityChange.Y)),
- (float)(velocityChange.Z < 0 ? -Math.Sqrt(-velocityChange.Z) : Math.Sqrt(velocityChange.Z)));
+ (float) (velocityChange.X < 0 ? -Math.Sqrt(-velocityChange.X) : Math.Sqrt(velocityChange.X)),
+ (float) (velocityChange.Y < 0 ? -Math.Sqrt(-velocityChange.Y) : Math.Sqrt(velocityChange.Y)),
+ (float) (velocityChange.Z < 0 ? -Math.Sqrt(-velocityChange.Z) : Math.Sqrt(velocityChange.Z)));
// Calculate Move Vector for the upcoming frame
- entity.Move.PositionMove = entity.Move.Velocity * (float)gameTime.ElapsedGameTime.TotalSeconds;
+ entity.Move.PositionMove = entity.Move.Velocity * (float) gameTime.ElapsedGameTime.TotalSeconds;
}
}
diff --git a/OctoAwesome/OctoAwesome.Basics/SimulationComponents/BlockInteractionComponent.cs b/OctoAwesome/OctoAwesome.Basics/SimulationComponents/BlockInteractionComponent.cs
index 5b4af618..78e1cc2c 100644
--- a/OctoAwesome/OctoAwesome.Basics/SimulationComponents/BlockInteractionComponent.cs
+++ b/OctoAwesome/OctoAwesome.Basics/SimulationComponents/BlockInteractionComponent.cs
@@ -5,11 +5,12 @@
using System.Text;
using System.Threading.Tasks;
using engenious;
+using OctoAwesome.Entities;
namespace OctoAwesome.Basics.SimulationComponents
{
[EntityFilter(typeof(ControllableComponent), typeof(InventoryComponent))]
- public class BlockInteractionComponent : SimulationComponent
+ public class BlockInteractionComponent : OSimulationComponent
{
private Simulation simulation;
@@ -28,29 +29,31 @@ protected override void RemoveEntity(Entity entity)
}
- protected override void UpdateEntity(GameTime gameTime, Entity entity, ControllableComponent controller, InventoryComponent inventory)
+ protected override void UpdateEntity(GameTime gameTime, Entity entity, ControllableComponent controller,
+ InventoryComponent inventory)
{
var toolbar = entity.Components.GetComponent();
+ // take block
if (controller.InteractBlock.HasValue)
{
- ushort lastBlock = entity.Cache.GetBlock(controller.InteractBlock.Value);
- entity.Cache.SetBlock(controller.InteractBlock.Value, 0);
+ ushort lastBlock = entity.Cache.GetBlock(controller.InteractBlock.Value, true);
+ //entity.Cache.SetBlock(controller.InteractBlock.Value, 0);
if (lastBlock != 0)
{
var blockDefinition = simulation.ResourceManager.DefinitionManager.GetDefinitionByIndex(lastBlock);
- if (blockDefinition is IInventoryableDefinition invDef)
- inventory.AddUnit(invDef);
+ if (blockDefinition is IInventoryableDefinition invDef) inventory.AddUnit(invDef);
}
controller.InteractBlock = null;
}
+ // set or interact with tool
if (toolbar != null && controller.ApplyBlock.HasValue)
{
if (toolbar.ActiveTool != null)
{
- Index3 add = new Index3();
+ Index3 add;
switch (controller.ApplySide)
{
case OrientationFlags.SideWest: add = new Index3(-1, 0, 0); break;
@@ -59,12 +62,11 @@ protected override void UpdateEntity(GameTime gameTime, Entity entity, Controlla
case OrientationFlags.SideNorth: add = new Index3(0, 1, 0); break;
case OrientationFlags.SideBottom: add = new Index3(0, 0, -1); break;
case OrientationFlags.SideTop: add = new Index3(0, 0, 1); break;
+ default: add = new Index3(); break;
}
- if (toolbar.ActiveTool.Definition is IBlockDefinition)
+ if (toolbar.ActiveTool.Definition is IBlockDefinition definition)
{
- IBlockDefinition definition = toolbar.ActiveTool.Definition as IBlockDefinition;
-
Index3 idx = controller.ApplyBlock.Value + add;
var boxes = definition.GetCollisionBoxes(entity.Cache, idx.X, idx.Y, idx.Z);
@@ -102,8 +104,7 @@ protected override void UpdateEntity(GameTime gameTime, Entity entity, Controlla
if (inventory.RemoveUnit(toolbar.ActiveTool))
{
entity.Cache.SetBlock(idx, simulation.ResourceManager.DefinitionManager.GetDefinitionIndex(definition));
- if (toolbar.ActiveTool.Amount <= 0)
- toolbar.RemoveSlot(toolbar.ActiveTool);
+ if (toolbar.ActiveTool.Amount <= 0) toolbar.RemoveSlot(toolbar.ActiveTool);
}
}
}
diff --git a/OctoAwesome/OctoAwesome.Basics/SimulationComponents/CollisionComponent.cs b/OctoAwesome/OctoAwesome.Basics/SimulationComponents/CollisionComponent.cs
index c93c232a..c223fdbe 100644
--- a/OctoAwesome/OctoAwesome.Basics/SimulationComponents/CollisionComponent.cs
+++ b/OctoAwesome/OctoAwesome.Basics/SimulationComponents/CollisionComponent.cs
@@ -4,10 +4,11 @@
using System.Text;
using System.Threading.Tasks;
using engenious;
+using OctoAwesome.Entities;
namespace OctoAwesome.Basics.SimulationComponents
{
- public sealed class CollisionComponent : SimulationComponent
+ public sealed class CollisionComponent : OSimulationComponent
{
protected override bool AddEntity(Entity entity)
{
diff --git a/OctoAwesome/OctoAwesome.Basics/SimulationComponents/ForceAggregatorComponent.cs b/OctoAwesome/OctoAwesome.Basics/SimulationComponents/ForceAggregatorComponent.cs
index 19d6f1f3..70de3ab7 100644
--- a/OctoAwesome/OctoAwesome.Basics/SimulationComponents/ForceAggregatorComponent.cs
+++ b/OctoAwesome/OctoAwesome.Basics/SimulationComponents/ForceAggregatorComponent.cs
@@ -2,11 +2,12 @@
using System.Linq;
using engenious;
using OctoAwesome.Basics.EntityComponents;
+using OctoAwesome.Entities;
namespace OctoAwesome.Basics.SimulationComponents
{
[EntityFilter(typeof(ForceComponent), typeof(MoveableComponent))]
- public sealed class ForceAggregatorComponent : SimulationComponent
+ public sealed class ForceAggregatorComponent : OSimulationComponent
{
private List forcedEntities = new List();
diff --git a/OctoAwesome/OctoAwesome.Basics/SimulationComponents/MoveComponent.cs b/OctoAwesome/OctoAwesome.Basics/SimulationComponents/MoveComponent.cs
index 66ddc187..a0e1ca00 100644
--- a/OctoAwesome/OctoAwesome.Basics/SimulationComponents/MoveComponent.cs
+++ b/OctoAwesome/OctoAwesome.Basics/SimulationComponents/MoveComponent.cs
@@ -4,17 +4,18 @@
using System.Linq;
using OctoAwesome.EntityComponents;
using engenious.Helper;
+using OctoAwesome.Entities;
namespace OctoAwesome.Basics.SimulationComponents
{
[EntityFilter(typeof(MoveableComponent), typeof(PositionComponent))]
- public sealed class MoveComponent : SimulationComponent
+ public sealed class MoveComponent : OSimulationComponent
{
protected override bool AddEntity(Entity entity)
{
var poscomp = entity.Components.GetComponent();
- var planet = entity.Cache.LoadPlanet(poscomp.Position.Planet);
+ var planet = entity.Cache.GetPlanet(poscomp.Position.Planet);
poscomp.Position.NormalizeChunkIndexXY(planet.Size);
entity.Cache.SetCenter(planet, new Index2(poscomp.Position.ChunkIndex));
return true;
@@ -41,8 +42,8 @@ protected override void UpdateEntity(GameTime gameTime,Entity e, MoveableCompone
var newposition = poscomp.Position + movecomp.PositionMove;
newposition.NormalizeChunkIndexXY(e.Cache.Planet.Size);
var result = e.Cache.SetCenter(e.Cache.Planet, new Index2(poscomp.Position.ChunkIndex));
- if (result)
- poscomp.Position = newposition;
+ if (result) poscomp.Position = newposition;
+
//Direction
if (movecomp.PositionMove.LengthSquared != 0)
@@ -52,7 +53,7 @@ protected override void UpdateEntity(GameTime gameTime,Entity e, MoveableCompone
}
}
- private void CheckBoxCollision(GameTime gameTime,Entity e,MoveableComponent movecomp,PositionComponent poscomp)
+ private void CheckBoxCollision(GameTime gameTime, Entity e, MoveableComponent movecomp, PositionComponent poscomp)
{
BodyComponent bc = new BodyComponent();
if (e.Components.ContainsComponent())
@@ -64,27 +65,27 @@ private void CheckBoxCollision(GameTime gameTime,Entity e,MoveableComponent move
Vector3 move = movecomp.PositionMove;
//Blocks finden die eine Kollision verursachen könnten
- int minx = (int)Math.Floor(Math.Min(
+ int minx = (int) Math.Floor(Math.Min(
position.BlockPosition.X - bc.Radius,
- position.BlockPosition.X - bc.Radius + movecomp.PositionMove.X));
- int maxx = (int)Math.Ceiling(Math.Max(
+ position.BlockPosition.X - bc.Radius + movecomp.PositionMove.X));
+ int maxx = (int) Math.Ceiling(Math.Max(
position.BlockPosition.X + bc.Radius,
position.BlockPosition.X + bc.Radius + movecomp.PositionMove.X));
- int miny = (int)Math.Floor(Math.Min(
+ int miny = (int) Math.Floor(Math.Min(
position.BlockPosition.Y - bc.Radius,
position.BlockPosition.Y - bc.Radius + movecomp.PositionMove.Y));
- int maxy = (int)Math.Ceiling(Math.Max(
+ int maxy = (int) Math.Ceiling(Math.Max(
position.BlockPosition.Y + bc.Radius,
position.BlockPosition.Y + bc.Radius + movecomp.PositionMove.Y));
- int minz = (int)Math.Floor(Math.Min(
+ int minz = (int) Math.Floor(Math.Min(
position.BlockPosition.Z,
position.BlockPosition.Z + movecomp.PositionMove.Z));
- int maxz = (int)Math.Ceiling(Math.Max(
+ int maxz = (int) Math.Ceiling(Math.Max(
position.BlockPosition.Z + bc.Height,
position.BlockPosition.Z + bc.Height + movecomp.PositionMove.Z));
//Beteiligte Flächen des Spielers
- var playerplanes = CollisionPlane.GetPlayerCollisionPlanes(bc, movecomp, poscomp).ToList();
+ var playerplanes = CollisionPlane.GetPlayerCollisionPlanes(bc.Radius, bc.Height, movecomp.Velocity, poscomp.Position);
bool abort = false;
@@ -94,7 +95,7 @@ private void CheckBoxCollision(GameTime gameTime,Entity e,MoveableComponent move
{
for (int x = minx; x <= maxx && !abort; x++)
{
- move = movecomp.Velocity * (float)gameTime.ElapsedGameTime.TotalSeconds;
+ move = movecomp.Velocity * (float) gameTime.ElapsedGameTime.TotalSeconds;
Index3 pos = new Index3(x, y, z);
Index3 blockPos = pos + position.GlobalBlockIndex;
@@ -116,7 +117,7 @@ where CollisionPlane.CheckDistance(distance, move)
foreach (var plane in planes)
{
- var subvelocity = (plane.Distance / (float)gameTime.ElapsedGameTime.TotalSeconds);
+ var subvelocity = (plane.Distance / (float) gameTime.ElapsedGameTime.TotalSeconds);
var diff = movecomp.Velocity - subvelocity;
float vx;
@@ -153,7 +154,7 @@ where CollisionPlane.CheckDistance(distance, move)
// TODO: Was ist für den Fall Gravitation = 0 oder im Scheitelpunkt des Sprungs?
//movecomp.OnGround = Player.Velocity.Z == 0f;
- movecomp.PositionMove = movecomp.Velocity * (float)gameTime.ElapsedGameTime.TotalSeconds;
+ movecomp.PositionMove = movecomp.Velocity * (float) gameTime.ElapsedGameTime.TotalSeconds;
}
}
}
diff --git a/OctoAwesome/OctoAwesome.Basics/SimulationComponents/NewtonGravitatorComponent.cs b/OctoAwesome/OctoAwesome.Basics/SimulationComponents/NewtonGravitatorComponent.cs
index 935df6be..fe53f525 100644
--- a/OctoAwesome/OctoAwesome.Basics/SimulationComponents/NewtonGravitatorComponent.cs
+++ b/OctoAwesome/OctoAwesome.Basics/SimulationComponents/NewtonGravitatorComponent.cs
@@ -6,11 +6,12 @@
using System.Threading.Tasks;
using engenious;
using OctoAwesome.EntityComponents;
+using OctoAwesome.Entities;
namespace OctoAwesome.Basics.SimulationComponents
{
[EntityFilter(typeof(GravityComponent),typeof(BodyComponent))]
- public class NewtonGravitatorComponent : SimulationComponent
+ public class NewtonGravitatorComponent : OSimulationComponent
{
class GravityEntity
{
diff --git a/OctoAwesome/OctoAwesome.Basics/SimulationComponents/PhysicEngineComponent.cs b/OctoAwesome/OctoAwesome.Basics/SimulationComponents/PhysicEngineComponent.cs
new file mode 100644
index 00000000..41176780
--- /dev/null
+++ b/OctoAwesome/OctoAwesome.Basics/SimulationComponents/PhysicEngineComponent.cs
@@ -0,0 +1,25 @@
+using System;
+using System.Linq;
+using engenious;
+using engenious.Helper;
+using OctoAwesome.Entities;
+using System.Collections.Generic;
+using OctoAwesome.CodeExtensions;
+namespace OctoAwesome.Basics.SimulationComponents
+{
+ class PhysicEngineComponent : SimulationComponent
+ {
+ public PhysicEngineComponent(IDefinitionManager manager)
+ {
+ }
+ public override void Register(Entity entity)
+ {
+ }
+ public override void Remove(Entity entity)
+ {
+ }
+ public override void Update(GameTime gameTime)
+ {
+ }
+ }
+}
diff --git a/OctoAwesome/OctoAwesome.Basics/SimulationComponents/PowerAggregatorComponent.cs b/OctoAwesome/OctoAwesome.Basics/SimulationComponents/PowerAggregatorComponent.cs
index 064d52a3..68fadeb8 100644
--- a/OctoAwesome/OctoAwesome.Basics/SimulationComponents/PowerAggregatorComponent.cs
+++ b/OctoAwesome/OctoAwesome.Basics/SimulationComponents/PowerAggregatorComponent.cs
@@ -5,11 +5,12 @@
using System.Threading.Tasks;
using engenious;
using OctoAwesome.Basics.EntityComponents;
+using OctoAwesome.Entities;
namespace OctoAwesome.Basics.SimulationComponents
{
[EntityFilter(typeof(PowerComponent), typeof(MoveableComponent))]
- public sealed class PowerAggregatorComponent : SimulationComponent
+ public sealed class PowerAggregatorComponent : OSimulationComponent
{
private List poweredEntities = new List();
diff --git a/OctoAwesome/OctoAwesome.Basics/SimulationComponents/WattMoverComponent.cs b/OctoAwesome/OctoAwesome.Basics/SimulationComponents/WattMoverComponent.cs
index 74b862d3..b5bd5470 100644
--- a/OctoAwesome/OctoAwesome.Basics/SimulationComponents/WattMoverComponent.cs
+++ b/OctoAwesome/OctoAwesome.Basics/SimulationComponents/WattMoverComponent.cs
@@ -7,11 +7,12 @@
using System.Threading.Tasks;
using engenious;
using engenious.Helper;
+using OctoAwesome.Entities;
namespace OctoAwesome.Basics.SimulationComponents
{
[EntityFilter(typeof(ControllableComponent), typeof(BodyPowerComponent))]
- public class WattMoverComponent : SimulationComponent
+ public class WattMoverComponent : OSimulationComponent
{
protected override bool AddEntity(Entity entity)
{
@@ -32,7 +33,7 @@ protected override void UpdateEntity(GameTime gameTime, Entity e, ControllableCo
float lookX = (float)Math.Cos(head.Angle);
float lookY = -(float)Math.Sin(head.Angle);
- var velocitydirection = new Vector3(lookX, lookY, 0) * controller.MoveInput.Y;
+ var velocitydirection = new Vector3(lookX, lookY, 0) * controller.MoveInput.Y;
float stafeX = (float)Math.Cos(head.Angle + MathHelper.PiOver2);
float stafeY = -(float)Math.Sin(head.Angle + MathHelper.PiOver2);
@@ -43,7 +44,7 @@ protected override void UpdateEntity(GameTime gameTime, Entity e, ControllableCo
}
else
{
- powercomp.Direction = new Vector3(controller.MoveInput.X,controller.MoveInput.Y);
+ powercomp.Direction = new Vector3(controller.MoveInput.X, controller.MoveInput.Y);
}
//Jump
diff --git a/OctoAwesome/OctoAwesome.Basics/WauziPopulator.cs b/OctoAwesome/OctoAwesome.Basics/WauziPopulator.cs
index ffcfba6f..bf63ce78 100644
--- a/OctoAwesome/OctoAwesome.Basics/WauziPopulator.cs
+++ b/OctoAwesome/OctoAwesome.Basics/WauziPopulator.cs
@@ -1,14 +1,10 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
using engenious;
using OctoAwesome.Basics.Entities;
-using OctoAwesome.EntityComponents;
namespace OctoAwesome.Basics
{
+ // TODO: populator system überarbeiten?
public class WauziPopulator : IMapPopulator
{
@@ -34,8 +30,12 @@ public void Populate(IResourceManager resourcemanager, IPlanet planet, IChunkCol
var x = r.Next(0, Chunk.CHUNKSIZE_X/2);
var y = r.Next(0, Chunk.CHUNKSIZE_Y/2);
- PositionComponent position = new PositionComponent() { Position = new Coordinate(0, new Index3(x+column00.Index.X*Chunk.CHUNKSIZE_X, y + column00.Index.Y * Chunk.CHUNKSIZE_Y, 200), new Vector3(0, 0, 0)) };
- wauzi.Components.AddComponent(position);
+ // TODO: der code wird immer redundanter :D
+
+ wauzi.SetPosition(new Coordinate(0, new Index3(x + column00.Index.X * Chunk.CHUNKSIZE_X, y + column00.Index.Y * Chunk.CHUNKSIZE_Y, 200), new Vector3(0, 0, 0)));
+ // TODO: warum wird das wauzi nicht direkt auf dem planeten gespritz...
+ // und findet dann seinen weg über die postion zum chunck ?
+ // oder noch besser in die simulation
column00.Entities.Add(wauzi);
}
diff --git a/OctoAwesome/OctoAwesome.Basics/packages.config b/OctoAwesome/OctoAwesome.Basics/packages.config
index ac2023de..1bd314fd 100644
--- a/OctoAwesome/OctoAwesome.Basics/packages.config
+++ b/OctoAwesome/OctoAwesome.Basics/packages.config
@@ -1,4 +1,5 @@

+
\ No newline at end of file
diff --git a/OctoAwesome/OctoAwesome.Client/Components/CameraComponent.cs b/OctoAwesome/OctoAwesome.Client/Components/CameraComponent.cs
index 27ad9dab..3f7c35a9 100644
--- a/OctoAwesome/OctoAwesome.Client/Components/CameraComponent.cs
+++ b/OctoAwesome/OctoAwesome.Client/Components/CameraComponent.cs
@@ -1,7 +1,6 @@
using System;
using engenious;
using engenious.Helper;
-using OctoAwesome.EntityComponents;
namespace OctoAwesome.Client.Components
{
@@ -36,44 +35,32 @@ public override void Update(GameTime gameTime)
if (player == null || player.CurrentEntity == null)
return;
+
+ Coordinate position = player.CurrentEntity.Position;
- Entity entity = player.CurrentEntity;
- HeadComponent head = player.CurrentEntityHead;
- PositionComponent position = player.Position;
+ CameraChunk = position.ChunkIndex;
- CameraChunk = position.Position.ChunkIndex;
+ CameraPosition = position.LocalPosition + player.HeadOffset;
- CameraPosition = position.Position.LocalPosition + head.Offset;
- CameraUpVector = new Vector3(0, 0, 1f);
+ float height = (float)Math.Sin(player.Tilt);
+ float distance = (float)Math.Cos(player.Tilt);
- float height = (float)Math.Sin(head.Tilt);
- float distance = (float)Math.Cos(head.Tilt);
+ float lookX = (float)Math.Cos(player.Yaw) * distance;
+ float lookY = -(float)Math.Sin(player.Yaw) * distance;
- float lookX = (float)Math.Cos(head.Angle) * distance;
- float lookY = -(float)Math.Sin(head.Angle) * distance;
-
- float strafeX = (float)Math.Cos(head.Angle + MathHelper.PiOver2);
- float strafeY = -(float)Math.Sin(head.Angle + MathHelper.PiOver2);
+ float strafeX = (float)Math.Cos(player.Yaw + MathHelper.PiOver2);
+ float strafeY = -(float)Math.Sin(player.Yaw + MathHelper.PiOver2);
CameraUpVector = Vector3.Cross(new Vector3(strafeX, strafeY, 0), new Vector3(lookX, lookY, height));
- View = Matrix.CreateLookAt(
- CameraPosition,
- new Vector3(
- CameraPosition.X + lookX,
- CameraPosition.Y + lookY,
- CameraPosition.Z + height),
+ View = Matrix.CreateLookAt(CameraPosition,
+ new Vector3(CameraPosition.X + lookX, CameraPosition.Y + lookY, CameraPosition.Z + height),
CameraUpVector);
MinimapView = Matrix.CreateLookAt(
new Vector3(CameraPosition.X, CameraPosition.Y, 100),
- new Vector3(
- position.Position.LocalPosition.X,
- position.Position.LocalPosition.Y,
- 0f),
- new Vector3(
- (float)Math.Cos(head.Angle),
- (float)Math.Sin(-head.Angle), 0f));
+ new Vector3(position.LocalPosition.X, position.LocalPosition.Y, 0f),
+ new Vector3((float)Math.Cos(player.Yaw), (float)Math.Sin(-player.Yaw), 0f));
float centerX = GraphicsDevice.Viewport.Width / 2;
float centerY = GraphicsDevice.Viewport.Height / 2;
diff --git a/OctoAwesome/OctoAwesome.Client/Components/EntityComponent.cs b/OctoAwesome/OctoAwesome.Client/Components/EntityComponent.cs
index 5c1e6d00..0e2d053c 100644
--- a/OctoAwesome/OctoAwesome.Client/Components/EntityComponent.cs
+++ b/OctoAwesome/OctoAwesome.Client/Components/EntityComponent.cs
@@ -1,17 +1,16 @@
using engenious;
using engenious.Graphics;
using engenious.Helper;
-using OctoAwesome.EntityComponents;
-using System;
+using OctoAwesome.Entities;
using System.Collections.Generic;
using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace OctoAwesome.Client.Components
{
internal sealed class EntityComponent : GameComponent
{
+ public SimulationComponent Simulation { get; private set; }
+ public IEnumerable Entities { get { return entities; } }
private struct ModelInfo
{
public bool render;
@@ -20,25 +19,20 @@ private struct ModelInfo
}
private GraphicsDevice graphicsDevice;
private BasicEffect effect;
- public SimulationComponent Simulation { get; private set; }
-
-
private Dictionary models = new Dictionary();
-
-
- public List Entities { get; set; }
-
- public EntityComponent(OctoGame game, SimulationComponent simulation) : base(game)
+ private List entities;
+ public EntityComponent(Game game, SimulationComponent simulation) : base(game)
{
Simulation = simulation;
- Entities = new List();
+ entities = new List();
graphicsDevice = game.GraphicsDevice;
effect = new BasicEffect(graphicsDevice);
}
public void Draw(Matrix view, Matrix projection, Index3 chunkOffset, Index2 planetSize)
{
+ if (entities.Count() == 0) return;
effect.Projection = projection;
effect.View = view;
effect.TextureEnabled = true;
@@ -47,47 +41,34 @@ public void Draw(Matrix view, Matrix projection, Index3 chunkOffset, Index2 plan
{
pass.Apply();
- foreach (var entity in Entities)
+ foreach (var entity in entities)
{
- if (!entity.Components.ContainsComponent())
- {
- continue;
- }
-
- var rendercomp = entity.Components.GetComponent();
+ var drawable = entity as Entities.IDrawable;
+ if (!drawable.DrawUpdate) continue;
- ModelInfo modelinfo;
-
- if (!models.TryGetValue(rendercomp.Name,out modelinfo))
+ if (!models.TryGetValue(drawable.Name, out ModelInfo modelinfo))
{
modelinfo = new ModelInfo()
{
+ model = Game.Content.Load(drawable.ModelName),
+ texture = Game.Content.Load(drawable.TextureName),
render = true,
- model = Game.Content.Load(rendercomp.ModelName),
- texture = Game.Content.Load(rendercomp.TextureName),
- };
+ };
}
- if (!modelinfo.render)
- continue;
-
- var positioncomp = entity.Components.GetComponent();
- var position = positioncomp.Position;
- var body = entity.Components.GetComponent();
+ if (!modelinfo.render) continue;
+
+ Coordinate position = entity.Position;
- HeadComponent head = new HeadComponent();
- if (entity.Components.ContainsComponent())
- head = entity.Components.GetComponent();
-
- Index3 shift = chunkOffset.ShortestDistanceXY(
- position.ChunkIndex, planetSize);
-
- var rotation = MathHelper.WrapAngle(positioncomp.Direction + MathHelper.ToRadians(rendercomp.BaseZRotation));
+ Index3 shift = chunkOffset.ShortestDistanceXY(position.ChunkIndex, planetSize);
+ var rotation = MathHelper.WrapAngle(drawable.Azimuth + MathHelper.ToRadians(drawable.BaseRotationZ));
Matrix world = Matrix.CreateTranslation(
shift.X * Chunk.CHUNKSIZE_X + position.LocalPosition.X,
shift.Y * Chunk.CHUNKSIZE_Y + position.LocalPosition.Y,
- shift.Z * Chunk.CHUNKSIZE_Z + position.LocalPosition.Z) * Matrix.CreateScaling(body.Radius * 2, body.Radius * 2, body.Height)*Matrix.CreateRotationZ(rotation);
+ shift.Z * Chunk.CHUNKSIZE_Z + position.LocalPosition.Z) *
+ Matrix.CreateScaling(drawable.Radius, drawable.Radius, drawable.Height) *
+ Matrix.CreateRotationZ(rotation);
effect.World = world;
modelinfo.model.Transform = world;
modelinfo.model.Draw(effect, modelinfo.texture);
@@ -97,15 +78,12 @@ public void Draw(Matrix view, Matrix projection, Index3 chunkOffset, Index2 plan
public override void Update(GameTime gameTime)
{
- if (Simulation.Simulation == null)
- return;
-
var simulation = Simulation.Simulation;
- if (!(simulation.State == SimulationState.Running || simulation.State == SimulationState.Paused))
+ if (simulation == null || !(simulation.State == SimulationState.Running || simulation.State == SimulationState.Paused))
return;
- Entities = simulation.Entities.Where(i => i.Components.ContainsComponent()).ToList();
+ entities = simulation.Entities.Where(i => i is Entities.IDrawable).ToList();
//base.Update(gameTime);
}
diff --git a/OctoAwesome/OctoAwesome.Client/Components/PlayerComponent.cs b/OctoAwesome/OctoAwesome.Client/Components/PlayerComponent.cs
index 0e4b77cb..a18ea249 100644
--- a/OctoAwesome/OctoAwesome.Client/Components/PlayerComponent.cs
+++ b/OctoAwesome/OctoAwesome.Client/Components/PlayerComponent.cs
@@ -1,24 +1,21 @@
-using OctoAwesome.Runtime;
-using System;
+using System;
using System.Collections.Generic;
-using System.Linq;
-using System.Text;
using engenious;
-using OctoAwesome.EntityComponents;
-
+using engenious.Graphics;
+using engenious.Helper;
+using MonoGameUi;
+using OctoAwesome.Entities;
namespace OctoAwesome.Client.Components
{
- internal sealed class PlayerComponent : GameComponent
+ internal sealed class PlayerComponent : GameComponent, IEntityController, IUserInterfaceExtensionManager
{
- private new OctoGame Game;
-
- private IResourceManager resourceManager;
+ #region IEntityController Interface
- #region External Input
+ public bool[] SlotInput { get; private set; } = new bool[10];
- public Vector2 HeadInput { get; set; }
+ public bool SlotLeftInput { get; set; }
- public Vector2 MoveInput { get; set; }
+ public bool SlotRightInput { get; set; }
public bool InteractInput { get; set; }
@@ -26,179 +23,163 @@ internal sealed class PlayerComponent : GameComponent
public bool JumpInput { get; set; }
- public bool FlymodeInput { get; set; }
-
- public bool[] SlotInput { get; private set; } = new bool[10];
+ public float Tilt { get; set; }
- public bool SlotLeftInput { get; set; }
+ public float Yaw { get; set; }
+
+ public Vector3 Direction { get; set; }
- public bool SlotRightInput { get; set; }
+ public Index3? SelectedBlock { get; set; }
- #endregion
+ public Vector2? SelectedPoint { get; set; }
- public Entity CurrentEntity { get; private set; }
+ public OrientationFlags SelectedSide { get; set; }
- public HeadComponent CurrentEntityHead { get; private set; }
+ public OrientationFlags SelectedEdge { get; set; }
- public ControllableComponent CurrentController { get; private set; }
+ public OrientationFlags SelectedCorner { get; set; }
+
+ #endregion
- public InventoryComponent Inventory { get; private set; }
+ #region External Inputs
+ public Vector2 HeadInput { get; set; }
- public ToolBarComponent Toolbar { get; private set; }
+ public Vector2 MoveInput { get; set; }
- public PositionComponent Position { get; private set; }
+ public bool FlymodeInput { get; set; }
+ #endregion
- // public ActorHost ActorHost { get; private set; }
+ public Vector3 HeadOffset { get; private set; }
+ public Entity CurrentEntity { get; private set; }
- public Index3? SelectedBox { get; set; }
+ public IEnumerable> GameScreenExtension { get { return gamescreenextension.Values; } }
- public Vector2? SelectedPoint { get; set; }
+ public IEnumerable> InventoryScreenExtension { get { return inventoryscreenextension.Values; } }
- public OrientationFlags SelectedSide { get; set; }
+ private new OctoGame Game;
- public OrientationFlags SelectedEdge { get; set; }
+ private IResourceManager resourceManager;
- public OrientationFlags SelectedCorner { get; set; }
+ private Dictionary> gamescreenextension;
+ private Dictionary> inventoryscreenextension;
- public PlayerComponent(OctoGame game, IResourceManager resourceManager)
- : base(game)
+ public PlayerComponent(OctoGame game, IResourceManager resourceManager) : base(game)
{
this.resourceManager = resourceManager;
Game = game;
+ gamescreenextension = new Dictionary>();
+ inventoryscreenextension = new Dictionary>();
}
public void SetEntity(Entity entity)
{
CurrentEntity = entity;
-
-
-
- if (CurrentEntity == null)
+ if (CurrentEntity != null && CurrentEntity is IControllable current)
+ current.Reset();
+ if (entity is IControllable controllable)
+ controllable.Register(this);
+ if (CurrentEntity is Entities.IDrawable draw)
+ HeadOffset = new Vector3(0, 0, draw.Height - 0.3f);
+ else HeadOffset = new Vector3(0, 0, 3.2f);
+
+ if (CurrentEntity != null)
{
- CurrentEntityHead = null;
+ foreach(Entities.EntityComponent comp in entity.Components)
+ {
+ if (comp is IUserInterfaceExtension extension)
+ extension.Register(this);
+ }
}
else
{
- // Map other Components
-
- CurrentController = entity.Components.GetComponent();
-
- CurrentEntityHead = CurrentEntity.Components.GetComponent();
- if (CurrentEntityHead == null) CurrentEntityHead = new HeadComponent();
-
- Inventory = CurrentEntity.Components.GetComponent();
- if (Inventory == null) Inventory = new InventoryComponent();
-
- Toolbar = CurrentEntity.Components.GetComponent();
- if (Toolbar == null) Toolbar = new ToolBarComponent();
-
- Position = CurrentEntity.Components.GetComponent();
- if (Position == null) Position = new PositionComponent() { Position = new Coordinate(0, new Index3(0, 0, 0), new Vector3(0, 0, 0)) };
+ gamescreenextension.Clear();
+ inventoryscreenextension.Clear();
}
}
public override void Update(GameTime gameTime)
{
- if (!Enabled)
- return;
-
- if (CurrentEntity == null)
+ if (!Enabled || CurrentEntity == null)
return;
- CurrentEntityHead.Angle += (float)gameTime.ElapsedGameTime.TotalSeconds * HeadInput.X;
- CurrentEntityHead.Tilt += (float)gameTime.ElapsedGameTime.TotalSeconds * HeadInput.Y;
- CurrentEntityHead.Tilt = Math.Min(1.5f, Math.Max(-1.5f, CurrentEntityHead.Tilt));
- HeadInput = Vector2.Zero;
-
- CurrentController.MoveInput = MoveInput;
- MoveInput = Vector2.Zero;
+ Yaw += (float) gameTime.ElapsedGameTime.TotalSeconds * HeadInput.X;
+ Tilt = Math.Min(1.5f, Math.Max(-1.5f, Tilt + (float) gameTime.ElapsedGameTime.TotalSeconds * HeadInput.Y));
- CurrentController.JumpInput = JumpInput;
- JumpInput = false;
+ // calculation of motion direction
+ float lookX = (float) Math.Cos(Yaw);
+ float lookY = -(float) Math.Sin(Yaw);
+ Direction = new Vector3(lookX, lookY, 0) * MoveInput.Y;
- if (InteractInput && SelectedBox.HasValue)
- CurrentController.InteractBlock = SelectedBox.Value;
- InteractInput = false;
-
- if (ApplyInput && SelectedBox.HasValue)
- {
- CurrentController.ApplyBlock = SelectedBox.Value;
- CurrentController.ApplySide = SelectedSide;
- }
+ float stafeX = (float) Math.Cos(Yaw + MathHelper.PiOver2);
+ float stafeY = -(float) Math.Sin(Yaw + MathHelper.PiOver2);
+ Direction += new Vector3(stafeX, stafeY, 0) * MoveInput.X;
- ApplyInput = false;
+ MoveInput = Vector2.Zero;
+ HeadInput = Vector2.Zero;
+ //TODO: was ist damit
//if (FlymodeInput)
// ActorHost.Player.FlyMode = !ActorHost.Player.FlyMode;
//FlymodeInput = false;
+ }
- if (Toolbar.Tools != null && Toolbar.Tools.Length > 0)
- {
- if (Toolbar.ActiveTool == null) Toolbar.ActiveTool = Toolbar.Tools[0];
- for (int i = 0; i < Math.Min(Toolbar.Tools.Length, SlotInput.Length); i++)
- {
- if (SlotInput[i])
- Toolbar.ActiveTool = Toolbar.Tools[i];
- SlotInput[i] = false;
- }
- }
+ ///
+ /// DEBUG METHODE: NICHT FÃœR VERWENDUNG IM SPIEL!
+ ///
+ [Obsolete("Is Empty right now... TODO: implementieren")]
+ internal void AllBlocksDebug()
+ {
+ //var inventory = CurrentEntity.Components.GetComponent();
+ //if (inventory == null)
+ // return;
- //Index des aktiven Werkzeugs ermitteln
- int activeTool = -1;
- List toolIndices = new List();
- if (Toolbar.Tools != null)
- {
- for (int i = 0; i < Toolbar.Tools.Length; i++)
- {
- if (Toolbar.Tools[i] != null)
- toolIndices.Add(i);
+ //var blockDefinitions = resourceManager.DefinitionManager.GetBlockDefinitions();
+ //foreach (var blockDefinition in blockDefinitions)
+ // inventory.AddUnit(blockDefinition);
- if (Toolbar.Tools[i] == Toolbar.ActiveTool)
- activeTool = toolIndices.Count - 1;
- }
+ //var itemDefinitions = resourceManager.DefinitionManager.GetItemDefinitions();
+ //foreach (var itemDefinition in itemDefinitions)
+ // inventory.AddUnit(itemDefinition);
+ }
+ #region IUserinterfaceManager
+ public bool RegisterOnGameScreen(Type controltype, params object[] args)
+ {
+ if (!gamescreenextension.TryGetValue(controltype, out Func extension))
+ {
+ gamescreenextension.Add(controltype, () => InternalCreate(controltype, args));
+ return true;
}
-
- if (SlotLeftInput)
+ return false;
+ }
+ public bool RegisterOnInventoryScreen(Type controltype, params object[] args)
+ {
+ if (!inventoryscreenextension.TryGetValue(controltype, out Func extension))
{
- if (activeTool > -1)
- activeTool--;
- else if (toolIndices.Count > 0)
- activeTool = toolIndices[toolIndices.Count - 1];
+ inventoryscreenextension.Add(controltype, () => InternalCreate(controltype, args));
+ return true;
}
- SlotLeftInput = false;
-
- if (SlotRightInput)
+ return false;
+ }
+ public Texture2D LoadTextures(Type type, string key)
+ {
+ return Game.Assets.LoadTexture(type, key);
+ }
+ private Control InternalCreate(Type controltype, object[] args)
+ {
+ object[] constructorargs = new object[2 + args.Length];
+ constructorargs[0] = Game.Screen;
+ constructorargs[1] = this;
+ Array.Copy(args, 0, constructorargs, 2, args.Length);
+ try
{
- if (activeTool > -1)
- activeTool++;
- else if (toolIndices.Count > 0)
- activeTool = toolIndices[0];
+ return (Control) Activator.CreateInstance(controltype, constructorargs);
}
- SlotRightInput = false;
-
- if (activeTool > -1)
+ catch(Exception exception)
{
- activeTool = (activeTool + toolIndices.Count) % toolIndices.Count;
- Toolbar.ActiveTool = Toolbar.Tools[toolIndices[activeTool]];
+ //TODO: Loggen
+ return null;
}
}
-
- ///
- /// DEBUG METHODE: NICHT FÃœR VERWENDUNG IM SPIEL!
- ///
- internal void AllBlocksDebug()
- {
- var inventory = CurrentEntity.Components.GetComponent();
- if (inventory == null)
- return;
-
- var blockDefinitions = resourceManager.DefinitionManager.GetBlockDefinitions();
- foreach (var blockDefinition in blockDefinitions)
- inventory.AddUnit(blockDefinition);
-
- var itemDefinitions = resourceManager.DefinitionManager.GetItemDefinitions();
- foreach (var itemDefinition in itemDefinitions)
- inventory.AddUnit(itemDefinition);
- }
+ #endregion
}
}
diff --git a/OctoAwesome/OctoAwesome.Client/Controls/CompassControl.cs b/OctoAwesome/OctoAwesome.Client/Controls/CompassControl.cs
index 8d501b9c..f143ac44 100644
--- a/OctoAwesome/OctoAwesome.Client/Controls/CompassControl.cs
+++ b/OctoAwesome/OctoAwesome.Client/Controls/CompassControl.cs
@@ -31,7 +31,7 @@ protected override void OnDrawContent(SpriteBatch batch, Rectangle contentArea,
if (Player == null || Player.CurrentEntity == null || !assets.Ready)
return;
- float compassValue = Player.CurrentEntityHead.Angle / (float)(2 * Math.PI);
+ float compassValue = Player.Yaw / (float)(2 * Math.PI);
compassValue %= 1f;
if (compassValue < 0)
compassValue += 1f;
diff --git a/OctoAwesome/OctoAwesome.Client/Controls/DebugControl.cs b/OctoAwesome/OctoAwesome.Client/Controls/DebugControl.cs
index 6cfb5713..a80d5b1d 100644
--- a/OctoAwesome/OctoAwesome.Client/Controls/DebugControl.cs
+++ b/OctoAwesome/OctoAwesome.Client/Controls/DebugControl.cs
@@ -1,8 +1,5 @@
using MonoGameUi;
-using System.Collections.Generic;
-using OctoAwesome.Runtime;
using OctoAwesome.Client.Components;
-using System;
using engenious;
using engenious.Graphics;
using System.Linq;
@@ -29,8 +26,7 @@ internal class DebugControl : Panel
StackPanel leftView, rightView;
Label devText, position, rotation, fps, box, controlInfo, loadedChunks, loadedTextures, activeTool, toolCount, loadedInfo, flyInfo, temperatureInfo, precipitationInfo;
- public DebugControl(ScreenComponent screenManager)
- : base(screenManager)
+ public DebugControl(ScreenComponent screenManager) : base(screenManager)
{
framebuffer = new float[buffersize];
Player = screenManager.Player;
@@ -153,14 +149,14 @@ protected override void OnDrawContent(SpriteBatch batch, Rectangle contentArea,
controlInfo.Text = Languages.OctoClient.ActiveControls + ": " + ScreenManager.ActiveScreen.Controls.Count;
//Draw Position
- string pos = "pos: " + Player.Position.Position.ToString();
+ string pos = "pos: " + Player.CurrentEntity.Position.ToString();
position.Text = pos;
//Draw Rotation
- float grad = (Player.CurrentEntityHead.Angle / MathHelper.TwoPi) * 360;
+ float grad = (Player.Yaw / MathHelper.TwoPi) * 360;
string rot = "rot: " +
- (((Player.CurrentEntityHead.Angle / MathHelper.TwoPi) * 360) % 360).ToString("0.00") + " / " +
- ((Player.CurrentEntityHead.Tilt / MathHelper.TwoPi) * 360).ToString("0.00");
+ (((Player.Yaw / MathHelper.TwoPi) * 360) % 360).ToString("0.00") + " / " +
+ ((Player.Tilt / MathHelper.TwoPi) * 360).ToString("0.00");
rotation.Text = rot;
//Draw Fps
@@ -193,18 +189,18 @@ protected override void OnDrawContent(SpriteBatch batch, Rectangle contentArea,
//if (Player.ActorHost.Player.FlyMode) flyInfo.Text = Languages.OctoClient.FlymodeEnabled;
//else flyInfo.Text = "";
- IPlanet planet = manager.Game.ResourceManager.GetPlanet(Player.Position.Position.Planet);
+ IPlanet planet = manager.Game.ResourceManager.GetPlanet(Player.CurrentEntity.Position.Planet);
// Temperature Info
- temperatureInfo.Text = Languages.OctoClient.Temperature + ": " + planet.ClimateMap.GetTemperature(Player.Position.Position.GlobalBlockIndex);
+ temperatureInfo.Text = Languages.OctoClient.Temperature + ": " + planet.ClimateMap.GetTemperature(Player.CurrentEntity.Position.GlobalBlockIndex);
// Precipitation Info
- precipitationInfo.Text = "Precipitation: " + planet.ClimateMap.GetPrecipitation(Player.Position.Position.GlobalBlockIndex);
+ precipitationInfo.Text = "Precipitation: " + planet.ClimateMap.GetPrecipitation(Player.CurrentEntity.Position.GlobalBlockIndex);
//Draw Box Information
- if (Player.SelectedBox.HasValue)
+ if (Player.SelectedBlock.HasValue)
{
string selection = "box: " +
- Player.SelectedBox.Value.ToString() + " on " +
+ Player.SelectedBlock.Value.ToString() + " on " +
Player.SelectedSide.ToString() + " (" +
Player.SelectedPoint.Value.X.ToString("0.00") + "/" +
Player.SelectedPoint.Value.Y.ToString("0.00") + ") -> " +
diff --git a/OctoAwesome/OctoAwesome.Client/Controls/InventoryControl.cs b/OctoAwesome/OctoAwesome.Client/Controls/InventoryControl.cs
deleted file mode 100644
index c1c8184e..00000000
--- a/OctoAwesome/OctoAwesome.Client/Controls/InventoryControl.cs
+++ /dev/null
@@ -1,72 +0,0 @@
-using engenious;
-using engenious.Graphics;
-using MonoGameUi;
-using OctoAwesome.Client.Components;
-
-namespace OctoAwesome.Client.Controls
-{
- internal sealed class InventoryControl : Panel
- {
- private const int COLUMNS = 8;
-
- ///
- /// Gibt den aktuell selektierten Slot an.
- ///
- public InventorySlot HoveredSlot { get; private set; }
-
- public InventoryControl(ScreenComponent manager, int columns = COLUMNS) : base(manager)
- {
-
-
- ScrollContainer scroll = new ScrollContainer(manager)
- {
- Margin = new Border(0, 0, 0, 0),
- HorizontalAlignment = HorizontalAlignment.Stretch,
- VerticalAlignment = VerticalAlignment.Stretch,
- };
- Controls.Add(scroll);
-
- Grid grid = new Grid(manager)
- {
- HorizontalAlignment = HorizontalAlignment.Stretch,
- };
- for (int i = 0; i < columns; i++)
- grid.Columns.Add(new ColumnDefinition() { ResizeMode = ResizeMode.Parts, Width = 1 });
- int rows = (int)System.Math.Ceiling((float)manager.Game.Player.Inventory.Inventory.Count / columns);
- for (int i = 0; i < rows; i++)
- grid.Rows.Add(new RowDefinition() { ResizeMode = ResizeMode.Fixed, Height = 50 });
-
- int column = 0;
- int row = 0;
- foreach (var item in manager.Game.Player.Inventory.Inventory)
- {
- Texture2D texture = manager.Game.Assets.LoadTexture(item.Definition.GetType(), item.Definition.Icon);
-
- var image = new Image(manager) { Texture = texture, Width = 42, Height = 42, VerticalAlignment = VerticalAlignment.Center };
- image.MouseEnter += (s, e) => { HoveredSlot = item; };
- image.MouseLeave += (s, e) => { HoveredSlot = null; };
- image.StartDrag += (e) =>
- {
- e.Handled = true;
- e.Icon = texture;
- e.Content = item;
- e.Sender = image;
- };
- var label = new Label(manager) { Text = item.Amount.ToString(), HorizontalAlignment = HorizontalAlignment.Right, VerticalTextAlignment = VerticalAlignment.Bottom, Background = new BorderBrush(Color.White) };
- grid.AddControl(image, column, row);
- grid.AddControl(label, column, row);
-
- column++;
- if (column >= columns)
- {
- row++;
- column = 0;
- }
- }
-
- scroll.Content = grid;
-
-
- }
- }
-}
diff --git a/OctoAwesome/OctoAwesome.Client/Controls/SceneControl.cs b/OctoAwesome/OctoAwesome.Client/Controls/SceneControl.cs
index 7edb3073..06d9c8d0 100644
--- a/OctoAwesome/OctoAwesome.Client/Controls/SceneControl.cs
+++ b/OctoAwesome/OctoAwesome.Client/Controls/SceneControl.cs
@@ -105,11 +105,10 @@ public SceneControl(ScreenComponent manager, string style = "") :
layer++;
}
}
-
+
planet = Manager.Game.ResourceManager.GetPlanet(0);
// TODO: evtl. Cache-Size (Dimensions) VIEWRANGE + 1
-
int range = ((int)Math.Pow(2, VIEWRANGE) - 2) / 2;
localChunkCache = new LocalChunkCache(Manager.Game.ResourceManager.GlobalChunkCache,false, VIEWRANGE, range);
@@ -238,8 +237,8 @@ protected override void OnUpdate(GameTime gameTime)
sunPosition += (float)gameTime.ElapsedGameTime.TotalMinutes * MathHelper.TwoPi;
- Index3 centerblock = player.Position.Position.GlobalBlockIndex;
- Index3 renderOffset = player.Position.Position.ChunkIndex * Chunk.CHUNKSIZE;
+ Index3 centerblock = player.CurrentEntity.Position.GlobalBlockIndex;
+ Index3 renderOffset = player.CurrentEntity.Position.ChunkIndex * Chunk.CHUNKSIZE;
Index3? selected = null;
Axis? selectedAxis = null;
@@ -276,7 +275,7 @@ protected override void OnUpdate(GameTime gameTime)
if (selected.HasValue)
{
- player.SelectedBox = selected;
+ player.SelectedBlock = selected;
switch (selectedAxis)
{
case Axis.X: player.SelectedSide = (camera.PickRay.Direction.X > 0 ? OrientationFlags.SideWest : OrientationFlags.SideEast); break;
@@ -325,14 +324,14 @@ protected override void OnUpdate(GameTime gameTime)
}
else
{
- player.SelectedBox = null;
+ player.SelectedBlock = null;
player.SelectedPoint = null;
player.SelectedSide = OrientationFlags.None;
player.SelectedEdge = OrientationFlags.None;
player.SelectedCorner = OrientationFlags.None;
}
- Index2 destinationChunk = new Index2(player.Position.Position.ChunkIndex);
+ Index2 destinationChunk = new Index2(player.CurrentEntity.Position.ChunkIndex);
// Nur ausführen wenn der Spieler den Chunk gewechselt hat
if (destinationChunk != currentChunk)
@@ -359,8 +358,8 @@ protected override void OnPreDraw(GameTime gameTime)
float octoDaysPerEarthDay = 360f;
float inclinationVariance = MathHelper.Pi / 3f;
- float playerPosX = ((float)player.Position.Position.GlobalPosition.X / (planet.Size.X * Chunk.CHUNKSIZE_X)) * MathHelper.TwoPi;
- float playerPosY = ((float)player.Position.Position.GlobalPosition.Y / (planet.Size.Y * Chunk.CHUNKSIZE_Y)) * MathHelper.TwoPi;
+ float playerPosX = ((float)player.CurrentEntity.Position.GlobalPosition.X / (planet.Size.X * Chunk.CHUNKSIZE_X)) * MathHelper.TwoPi;
+ float playerPosY = ((float)player.CurrentEntity.Position.GlobalPosition.Y / (planet.Size.Y * Chunk.CHUNKSIZE_Y)) * MathHelper.TwoPi;
TimeSpan diff = DateTime.UtcNow - new DateTime(1888, 8, 8);
@@ -424,7 +423,7 @@ protected override void OnPreDraw(GameTime gameTime)
// GraphicsDevice.RasterizerState = RasterizerState.CullNone;
sunEffect.Texture = sunTexture;
Matrix billboard = Matrix.Invert(camera.View);
- billboard.Translation = player.Position.Position.LocalPosition + (sunDirection * -10);
+ billboard.Translation = player.CurrentEntity.Position.LocalPosition + (sunDirection * -10);
sunEffect.World = billboard;
sunEffect.View = camera.View;
sunEffect.Projection = camera.Projection;
@@ -462,20 +461,20 @@ protected override void OnPreDraw(GameTime gameTime)
entities.Draw(camera.View, camera.Projection,chunkOffset,new Index2(planet.Size.X,planet.Size.Z));
- if (player.SelectedBox.HasValue)
+ if (player.SelectedBlock.HasValue)
{
// Index3 offset = player.ActorHost.Position.ChunkIndex * Chunk.CHUNKSIZE;
Index3 offset = camera.CameraChunk * Chunk.CHUNKSIZE;
Index3 planetSize = planet.Size * Chunk.CHUNKSIZE;
Index3 relativePosition = new Index3(
- Index2.ShortestDistanceOnAxis(offset.X, player.SelectedBox.Value.X, planetSize.X),
- Index2.ShortestDistanceOnAxis(offset.Y, player.SelectedBox.Value.Y, planetSize.Y),
- player.SelectedBox.Value.Z - offset.Z);
+ Index2.ShortestDistanceOnAxis(offset.X, player.SelectedBlock.Value.X, planetSize.X),
+ Index2.ShortestDistanceOnAxis(offset.Y, player.SelectedBlock.Value.Y, planetSize.Y),
+ player.SelectedBlock.Value.Z - offset.Z);
Vector3 selectedBoxPosition = new Vector3(
- player.SelectedBox.Value.X - (chunkOffset.X * Chunk.CHUNKSIZE_X),
- player.SelectedBox.Value.Y - (chunkOffset.Y * Chunk.CHUNKSIZE_Y),
- player.SelectedBox.Value.Z - (chunkOffset.Z * Chunk.CHUNKSIZE_Z));
+ player.SelectedBlock.Value.X - (chunkOffset.X * Chunk.CHUNKSIZE_X),
+ player.SelectedBlock.Value.Y - (chunkOffset.Y * Chunk.CHUNKSIZE_Y),
+ player.SelectedBlock.Value.Z - (chunkOffset.Z * Chunk.CHUNKSIZE_Z));
// selectionEffect.World = Matrix.CreateTranslation(selectedBoxPosition);
selectionEffect.World = Matrix.CreateTranslation(relativePosition);
selectionEffect.View = camera.View;
@@ -499,14 +498,13 @@ private void FillChunkRenderer()
if (player.CurrentEntity == null)
return;
- Index2 destinationChunk = new Index2(player.Position.Position.ChunkIndex);
+ Index2 destinationChunk = new Index2(player.CurrentEntity.Position.ChunkIndex);
// Nur ausführen wenn der Spieler den Chunk gewechselt hat
if (destinationChunk != currentChunk)
{
- localChunkCache.SetCenter(
- planet,
- new Index2(player.Position.Position.ChunkIndex),
+ localChunkCache.SetCenter( planet,
+ new Index2(player.CurrentEntity.Position.ChunkIndex),
b => {
if (b)
{
@@ -534,7 +532,7 @@ private void FillChunkRenderer()
}
}
- Index3 comparationIndex = player.Position.Position.ChunkIndex;
+ Index3 comparationIndex = player.CurrentEntity.Position.ChunkIndex;
orderedChunkRenderer.Sort((x, y) =>
{
if (!x.ChunkPosition.HasValue) return 1;
diff --git a/OctoAwesome/OctoAwesome.Client/Controls/ToolbarControl.cs b/OctoAwesome/OctoAwesome.Client/Controls/ToolbarControl.cs
deleted file mode 100644
index 7268cc5c..00000000
--- a/OctoAwesome/OctoAwesome.Client/Controls/ToolbarControl.cs
+++ /dev/null
@@ -1,127 +0,0 @@
-using MonoGameUi;
-using OctoAwesome.Client.Components;
-using OctoAwesome.Runtime;
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Text;
-using engenious;
-using engenious.Graphics;
-using OctoAwesome.EntityComponents;
-
-namespace OctoAwesome.Client.Controls
-{
- internal class ToolbarControl : Panel
- {
- private Dictionary toolTextures;
-
- private Button[] buttons = new Button[ToolBarComponent.TOOLCOUNT];
-
- private Image[] images = new Image[ToolBarComponent.TOOLCOUNT];
-
- private Brush buttonBackgroud;
-
- private Brush activeBackground;
-
- public PlayerComponent Player { get; set; }
-
- public Label activeToolLabel;
-
- public ToolbarControl(ScreenComponent screenManager)
- : base(screenManager)
- {
- Player = screenManager.Player;
- toolTextures = new Dictionary();
-
- buttonBackgroud = new BorderBrush(Color.Black);
- activeBackground = new BorderBrush(Color.Red);
-
- foreach (var item in screenManager.Game.DefinitionManager.GetDefinitions())
- {
- Texture2D texture = screenManager.Game.Assets.LoadTexture(item.GetType(), item.Icon);
- toolTextures.Add(item.GetType().FullName, texture);
- }
-
- Grid grid = new Grid(screenManager)
- {
- Margin = new Border(0, 0, 0, 0),
- HorizontalAlignment = HorizontalAlignment.Center,
- VerticalAlignment = VerticalAlignment.Bottom
- };
- Controls.Add(grid);
-
- grid.Rows.Add(new RowDefinition() { ResizeMode = ResizeMode.Auto, Height = 1 });
- grid.Rows.Add(new RowDefinition() { ResizeMode = ResizeMode.Fixed, Height = 50 });
-
- for (int i = 0; i < ToolBarComponent.TOOLCOUNT; i++)
- {
- grid.Columns.Add(new ColumnDefinition() { ResizeMode = ResizeMode.Fixed, Width = 50 });
- }
-
- activeToolLabel = new Label(screenManager);
- activeToolLabel.VerticalAlignment = VerticalAlignment.Top;
- activeToolLabel.HorizontalAlignment = HorizontalAlignment.Center;
- activeToolLabel.Background = new BorderBrush(Color.Black * 0.3f);
- activeToolLabel.TextColor = Color.White;
- grid.AddControl(activeToolLabel, 0, 0, ToolBarComponent.TOOLCOUNT);
-
- for (int i = 0; i < ToolBarComponent.TOOLCOUNT; i++)
- {
- buttons[i] = new Button(screenManager)
- {
- HorizontalAlignment = HorizontalAlignment.Stretch,
- VerticalAlignment = VerticalAlignment.Stretch,
- Background = buttonBackgroud,
- HoveredBackground = null,
- PressedBackground = null,
- };
- buttons[i].Content = images[i] = new Image(screenManager)
- {
- Width = 42,
- Height = 42,
- };
- grid.AddControl(buttons[i], i, 1);
- }
- }
-
- protected override void OnUpdate(GameTime gameTime)
- {
- if (!Visible || !Enabled)
- return;
-
- if (Player.CurrentEntity == null) return;
-
- // Aktualisierung des aktiven Buttons
- for (int i = 0; i < ToolBarComponent.TOOLCOUNT; i++)
- {
- if (Player.Toolbar.Tools != null &&
- Player.Toolbar.Tools.Length > i &&
- Player.Toolbar.Tools[i] != null &&
- Player.Toolbar.Tools[i].Definition != null)
- {
- images[i].Texture = toolTextures[Player.Toolbar.Tools[i].Definition.GetType().FullName];
-
- if (Player.Toolbar.ActiveTool == Player.Toolbar.Tools[i])
- buttons[i].Background = activeBackground;
- else
- buttons[i].Background = buttonBackgroud;
- }
- else
- {
- images[i].Texture = null;
- buttons[i].Background = buttonBackgroud;
- }
- }
-
- // Aktualisierung des ActiveTool Labels
- activeToolLabel.Text = Player.Toolbar.ActiveTool != null ?
- string.Format("{0} ({1})", Player.Toolbar.ActiveTool.Definition.Name, Player.Toolbar.ActiveTool.Amount) :
- string.Empty;
-
- activeToolLabel.Visible = !(activeToolLabel.Text == string.Empty);
-
- base.OnUpdate(gameTime);
- }
- }
-}
diff --git a/OctoAwesome/OctoAwesome.Client/OctoAwesome.Client.csproj b/OctoAwesome/OctoAwesome.Client/OctoAwesome.Client.csproj
index c1ee17c6..5c6216f1 100644
--- a/OctoAwesome/OctoAwesome.Client/OctoAwesome.Client.csproj
+++ b/OctoAwesome/OctoAwesome.Client/OctoAwesome.Client.csproj
@@ -62,13 +62,11 @@
-
-
True
@@ -104,15 +102,23 @@
-
- False
- ..\libs\engenious.dll
+
+ ..\packages\engenious.0.1.11\lib\net40\engenious.dll
..\libs\MonoGameUi.dll
+
+ ..\packages\engenious.0.1.11\lib\net40\NVorbis.dll
+
+
+ ..\packages\engenious.0.1.11\lib\net40\OpenTK.dll
+
+
+ ..\packages\engenious.0.1.11\lib\net40\System.Numerics.Vectors.dll
+
@@ -177,6 +183,7 @@
+
@@ -196,6 +203,13 @@
+
+
+
+ Dieses Projekt verweist auf mindestens ein NuGet-Paket, das auf diesem Computer fehlt. Verwenden Sie die Wiederherstellung von NuGet-Paketen, um die fehlenden Dateien herunterzuladen. Weitere Informationen finden Sie unter "http://go.microsoft.com/fwlink/?LinkID=322105". Die fehlende Datei ist "{0}".
+
+
+
cut and passted from here
+ //}
+ if (entity.Position.ChunkIndex.X != column.Index.X || entity.Position.ChunkIndex.Y != column.Index.Y)
+ {
+ yield return new FailEntityChunkArgs()
+ {
+ Entity = entity,
+ CurrentChunk = new Index2(column.Index),
+ CurrentPlanet = column.Planet,
+ TargetChunk = new Index2(entity.Position.ChunkIndex),
+ TargetPlanet = entity.Position.Planet,
+ };
+ }
+ }
+ }
+ }
+}
diff --git a/OctoAwesome/OctoAwesome/Entities/IControllable.cs b/OctoAwesome/OctoAwesome/Entities/IControllable.cs
new file mode 100644
index 00000000..3d1cc289
--- /dev/null
+++ b/OctoAwesome/OctoAwesome/Entities/IControllable.cs
@@ -0,0 +1,29 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OctoAwesome.Entities
+{
+ public interface IControllable
+ {
+ ///
+ /// Position in the world
+ ///
+ Coordinate Position { get; }
+ ///
+ /// Controller
+ ///
+ IEntityController Controller { get; }
+ ///
+ /// Register a controller
+ ///
+ /// Controller to register
+ void Register(IEntityController controller);
+ ///
+ /// Reset the controller
+ ///
+ void Reset();
+ }
+}
diff --git a/OctoAwesome/OctoAwesome/Entities/IDrawable.cs b/OctoAwesome/OctoAwesome/Entities/IDrawable.cs
new file mode 100644
index 00000000..75372ed7
--- /dev/null
+++ b/OctoAwesome/OctoAwesome/Entities/IDrawable.cs
@@ -0,0 +1,57 @@
+using System;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Collections.Generic;
+using engenious.Graphics;
+using engenious;
+namespace OctoAwesome.Entities
+{
+ ///
+ /// Interface for drawable elements
+ ///
+ public interface IDrawable
+ {
+ #region Temporary
+ ///
+ /// Name
+ ///
+ string Name { get; }
+ ///
+ /// Modelname
+ ///
+ string ModelName { get; }
+ ///
+ /// Texturename
+ ///
+ string TextureName { get; }
+ ///
+ /// Base rotation of Z axis
+ ///
+ float BaseRotationZ { get; }
+ #endregion
+
+ ///
+ /// Indicates if the element need draw updates
+ ///
+ bool DrawUpdate { get; }
+ ///
+ /// Horizontal angle
+ ///
+ float Azimuth { get; }
+ ///
+ /// Height of the element
+ ///
+ float Height { get; }
+ ///
+ /// body radius of the element
+ ///
+ float Radius { get; }
+ ///
+ /// position of the element
+ ///
+ Coordinate Position { get; }
+ //void Initialize(IGraphicsDevice device);
+ //void Draw(IGraphicsDevice graphicsDevice, GameTime gameTime);
+ }
+}
diff --git a/OctoAwesome/OctoAwesome/Entities/IEntityController.cs b/OctoAwesome/OctoAwesome/Entities/IEntityController.cs
new file mode 100644
index 00000000..508d3602
--- /dev/null
+++ b/OctoAwesome/OctoAwesome/Entities/IEntityController.cs
@@ -0,0 +1,68 @@
+using engenious;
+
+namespace OctoAwesome.Entities
+{
+ ///
+ /// Interface for controlling an entity
+ ///
+ public interface IEntityController
+ {
+ // TODO: more ui inputs and data from the user.
+ ///
+ /// Pressed numbers on Keyboard (0 to 9)
+ ///
+ bool[] SlotInput { get; }
+ ///
+ /// Indicates that Slots have to be shifted left
+ ///
+ bool SlotLeftInput { get; set; }
+ ///
+ /// Indicates that Slots have to be shifted right
+ ///
+ bool SlotRightInput { get; set; }
+ ///
+ /// Input for interaction
+ ///
+ bool InteractInput { get; set; }
+ ///
+ /// Input for apply
+ ///
+ bool ApplyInput { get; set; }
+ ///
+ /// input for Jump
+ ///
+ bool JumpInput { get; set; }
+ ///
+ /// Tilt (Neigung des Kopfes)
+ ///
+ float Tilt { get; }
+ ///
+ /// Yaw (Horizontale Drehung)
+ ///
+ float Yaw { get; }
+ ///
+ /// Direction of Motion
+ ///
+ Vector3 Direction { get; }
+ ///
+ /// Index of Block to interact
+ ///
+ Index3? SelectedBlock { get; }
+ ///
+ /// Selected point of the block
+ ///
+ Vector2? SelectedPoint { get; }
+ ///
+ /// Selected side of the block
+ ///
+ OrientationFlags SelectedSide { get; }
+ ///
+ /// Selected edge o the block
+ ///
+ OrientationFlags SelectedEdge { get; }
+ ///
+ /// Selected corner of the block
+ ///
+ OrientationFlags SelectedCorner { get; }
+ }
+}
diff --git a/OctoAwesome/OctoAwesome/Entities/IEntityDefinition.cs b/OctoAwesome/OctoAwesome/Entities/IEntityDefinition.cs
new file mode 100644
index 00000000..78b7275a
--- /dev/null
+++ b/OctoAwesome/OctoAwesome/Entities/IEntityDefinition.cs
@@ -0,0 +1,31 @@
+using engenious;
+
+namespace OctoAwesome.Entities
+{
+ ///
+ /// defines an
+ ///
+ public interface IEntityDefinition : IDefinition
+ {
+ ///
+ /// Modelname of
+ ///
+ string ModelName { get; }
+ ///
+ /// Texturename of
+ ///
+ string TextureName { get; }
+ ///
+ /// BaseZRotation of
+ ///
+ float BaseRotationZ { get; }
+ ///
+ /// Mass of
+ ///
+ float Mass { get; }
+ ///
+ /// Body of
+ ///
+ Vector3 Body { get; }
+ }
+}
diff --git a/OctoAwesome/OctoAwesome/Entities/IEntityList.cs b/OctoAwesome/OctoAwesome/Entities/IEntityList.cs
new file mode 100644
index 00000000..35af3b21
--- /dev/null
+++ b/OctoAwesome/OctoAwesome/Entities/IEntityList.cs
@@ -0,0 +1,46 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OctoAwesome.Entities
+{
+ ///
+ /// Interface for
+ ///
+ public interface IEntityList : ICollection
+ {
+ ///
+ /// Checks if an leaves a ?
+ ///
+ ///
+ IEnumerable FailChunkEntity();
+ }
+ ///
+ /// .
+ ///
+ public class FailEntityChunkArgs
+ {
+ ///
+ /// Position of Chuck.
+ ///
+ public Index2 CurrentChunk { get; set; }
+ ///
+ /// Chunk Plante.
+ ///
+ public int CurrentPlanet { get; set; }
+ ///
+ /// Target Chunk
+ ///
+ public Index2 TargetChunk { get; set; }
+ ///
+ /// Target Planet
+ ///
+ public int TargetPlanet { get; set; }
+ ///
+ /// Entity
+ ///
+ public Entity Entity { get; set; }
+ }
+}
diff --git a/OctoAwesome/OctoAwesome/Entities/IInteractable.cs b/OctoAwesome/OctoAwesome/Entities/IInteractable.cs
new file mode 100644
index 00000000..c0d7e2e2
--- /dev/null
+++ b/OctoAwesome/OctoAwesome/Entities/IInteractable.cs
@@ -0,0 +1,11 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+namespace OctoAwesome.Entities
+{
+ public interface IInteractable
+ {
+ }
+}
diff --git a/OctoAwesome/OctoAwesome/Entity.cs b/OctoAwesome/OctoAwesome/Entity.cs
deleted file mode 100644
index 0e9bb08d..00000000
--- a/OctoAwesome/OctoAwesome/Entity.cs
+++ /dev/null
@@ -1,92 +0,0 @@
-using engenious;
-using OctoAwesome.EntityComponents;
-using System;
-using System.IO;
-
-namespace OctoAwesome
-{
- ///
- /// Basisklasse für alle selbständigen Wesen
- ///
- public abstract class Entity
- {
- ///
- /// Contains all Components.
- ///
- public ComponentList Components { get; private set; }
-
- ///
- /// Temp Id
- ///
- public int Id { get; internal set; }
-
- ///
- /// Reference to the active Simulation.
- ///
- public Simulation Simulation { get; internal set; }
-
- ///
- /// LocalChunkCache für die Entity
- ///
- public ILocalChunkCache Cache { get; protected set; }
-
- ///
- /// Entity die regelmäßig eine Updateevent bekommt
- ///
- public Entity()
- {
- Components = new ComponentList(
- ValidateAddComponent, ValidateRemoveComponent,OnAddComponent,OnRemoveComponent);
- }
-
- private void OnRemoveComponent(EntityComponent component)
- {
-
- }
-
- private void OnAddComponent(EntityComponent component)
- => component.SetEntity(this);
-
- private void ValidateAddComponent(EntityComponent component)
- {
- if (Simulation != null)
- throw new NotSupportedException("Can't add components during simulation");
- }
-
- private void ValidateRemoveComponent(EntityComponent component)
- {
- if (Simulation != null)
- throw new NotSupportedException("Can't remove components during simulation");
- }
-
- public void Initialize(IResourceManager mananger)
- {
- OnInitialize(mananger);
- }
-
- protected virtual void OnInitialize(IResourceManager manager)
- {
- }
-
- ///
- /// Serialisiert die Entität mit dem angegebenen BinaryWriter.
- ///
- /// Der BinaryWriter, mit dem geschrieben wird.
- /// Der aktuell verwendete .
- public virtual void Serialize(BinaryWriter writer, IDefinitionManager definitionManager)
- => Components.Serialize(writer, definitionManager);
-
- ///
- /// Deserialisiert die Entität aus dem angegebenen BinaryReader.
- ///
- /// Der BinaryWriter, mit dem gelesen wird.
- /// Der aktuell verwendete .
- public virtual void Deserialize(BinaryReader reader, IDefinitionManager definitionManager)
- => Components.Deserialize(reader, definitionManager);
-
- public virtual void RegisterDefault()
- {
-
- }
- }
-}
diff --git a/OctoAwesome/OctoAwesome/EntityComponent.cs b/OctoAwesome/OctoAwesome/EntityComponent.cs
deleted file mode 100644
index fe0ae575..00000000
--- a/OctoAwesome/OctoAwesome/EntityComponent.cs
+++ /dev/null
@@ -1,29 +0,0 @@
-using System;
-
-namespace OctoAwesome
-{
- ///
- /// Base Class for all Entity Components.
- ///
- public abstract class EntityComponent : Component
- {
- ///
- /// Reference to the Entity.
- ///
- public Entity Entity { get; private set; }
-
- public void SetEntity(Entity entity)
- {
- if (Entity != null)
- throw new NotSupportedException("Can not change the Entity");
-
- Entity = entity;
- OnSetEntity();
- }
-
- protected virtual void OnSetEntity()
- {
-
- }
- }
-}
diff --git a/OctoAwesome/OctoAwesome/EntityList.cs b/OctoAwesome/OctoAwesome/EntityList.cs
deleted file mode 100644
index d53f86ec..00000000
--- a/OctoAwesome/OctoAwesome/EntityList.cs
+++ /dev/null
@@ -1,71 +0,0 @@
-using OctoAwesome.EntityComponents;
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace OctoAwesome
-{
- public class EntityList : IEntityList
- {
- private List entities;
- private IChunkColumn column;
-
- public EntityList(IChunkColumn column)
- {
- entities = new List();
- this.column = column;
- }
-
- public int Count => entities.Count;
-
- public bool IsReadOnly => false;
-
- public void Add(Entity item)
- {
- entities.Add(item);
- column.ChangeCounter++;
- }
-
- public void Clear() => entities.Clear();
-
- public bool Contains(Entity item) => entities.Contains(item);
-
- public void CopyTo(Entity[] array, int arrayIndex) => entities.CopyTo(array, arrayIndex);
-
- public IEnumerator GetEnumerator() => entities.GetEnumerator();
-
- public bool Remove(Entity item)
- {
- column.ChangeCounter++;
- return entities.Remove(item);
- }
-
- IEnumerator IEnumerable.GetEnumerator() => entities.GetEnumerator();
-
- public IEnumerable FailChunkEntity()
- {
- foreach (var entity in entities)
- {
- if (entity.Components.ContainsComponent())
- {
- var position = entity.Components.GetComponent();
-
- if (position.Position.ChunkIndex.X != column.Index.X || position.Position.ChunkIndex.Y != column.Index.Y)
- {
- yield return new FailEntityChunkArgs()
- {
- Entity = entity,
- CurrentChunk = new Index2(column.Index),
- CurrentPlanet = column.Planet,
- TargetChunk = new Index2(position.Position.ChunkIndex),
- TargetPlanet = position.Position.Planet,
- };
- }
- }
- }
- }
- }
-}
diff --git a/OctoAwesome/OctoAwesome/Extension.cs b/OctoAwesome/OctoAwesome/Extension.cs
deleted file mode 100644
index 293d8d10..00000000
--- a/OctoAwesome/OctoAwesome/Extension.cs
+++ /dev/null
@@ -1,30 +0,0 @@
-using engenious;
-using OctoAwesome.EntityComponents;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace OctoAwesome
-{
- //TODO:Eventuell auslagern
-
- public sealed class Extension : IExtension
- {
- public string Description => "OctoAwesome";
-
- public string Name => "OctoAwesome";
-
- public void Register(IExtensionLoader extensionLoader)
- {
- extensionLoader.RegisterEntityExtender((p) =>
- {
- p.Components.AddComponent(new ControllableComponent());
- p.Components.AddComponent(new HeadComponent() { Offset = new Vector3(0, 0, 3.2f) });
- p.Components.AddComponent(new InventoryComponent());
- p.Components.AddComponent(new ToolBarComponent());
- });
- }
- }
-}
diff --git a/OctoAwesome/OctoAwesome/GlobalChunkCache.cs b/OctoAwesome/OctoAwesome/GlobalChunkCache.cs
index d94b6979..e25ed816 100644
--- a/OctoAwesome/OctoAwesome/GlobalChunkCache.cs
+++ b/OctoAwesome/OctoAwesome/GlobalChunkCache.cs
@@ -267,8 +267,7 @@ private void BackgroundCleanup()
///
/// ID des Planeten
/// Planet
- public IPlanet GetPlanet(int id)
- => loadPlanetDelagte(id);
+ public IPlanet GetPlanet(int id) => loadPlanetDelagte(id);
public void BeforeSimulationUpdate(Simulation simulation)
{
diff --git a/OctoAwesome/OctoAwesome/IChunk.cs b/OctoAwesome/OctoAwesome/IChunk.cs
index 02655859..1eea2ef8 100644
--- a/OctoAwesome/OctoAwesome/IChunk.cs
+++ b/OctoAwesome/OctoAwesome/IChunk.cs
@@ -40,6 +40,24 @@ public interface IChunk
///
int ChangeCounter { get; set; }
+ ///
+ /// Liefet den Block an der angegebenen Koordinate zurück.
+ ///
+ /// Koordinate des Blocks innerhalb des Chunkgs
+ /// Entfernt den Block.
+ /// Die Block-ID an der angegebenen Koordinate
+ ushort GetBlock(Index3 index, bool removeblock);
+
+ ///
+ /// Liefet den Block an der angegebenen Koordinate zurück.
+ ///
+ /// X-Anteil der Koordinate des Blocks
+ /// Y-Anteil der Koordinate des Blocks
+ /// Z-Anteil der Koordinate des Blocks
+ /// Entfernt den Block.
+ /// Block-ID der angegebenen Koordinate
+ ushort GetBlock(int x, int y, int z, bool removeblock);
+
///
/// Liefet den Block an der angegebenen Koordinate zurück.
///
diff --git a/OctoAwesome/OctoAwesome/IChunkColumn.cs b/OctoAwesome/OctoAwesome/IChunkColumn.cs
index c8200159..b9bf7574 100644
--- a/OctoAwesome/OctoAwesome/IChunkColumn.cs
+++ b/OctoAwesome/OctoAwesome/IChunkColumn.cs
@@ -1,7 +1,7 @@
using System.Collections.Generic;
using System;
using System.IO;
-
+using OctoAwesome.Entities;
namespace OctoAwesome
{
///
@@ -24,6 +24,9 @@ public interface IChunkColumn
///
Index2 Index { get; }
+ ///
+ /// Gibt die anzahl der Änderungen an die an dieser Instance vorgenommen wurden.
+ ///
int ChangeCounter { get; set; }
///
@@ -57,6 +60,9 @@ public interface IChunkColumn
/// Block-ID der angegebenen Koordinate
ushort GetBlock(int x, int y, int z);
+ ///
+ /// Wird ausgelöst wenn sich die IChunkColumn ändert.
+ ///
event Action Changed;
///
@@ -95,6 +101,8 @@ public interface IChunkColumn
/// (Optional) Metainformationen für den Block
void SetBlockMeta(int x, int y, int z, int meta);
+ // TODO: überlegen ob der Block die Ressourcen wissen muss.
+ // Die Ressourcen könnten auch erst ermittelt werden wenn der Block verarbeitet wurde.
///
/// Liefert alle Ressourcen im Block an der angegebenen Koordinate zurück.
///
@@ -104,6 +112,8 @@ public interface IChunkColumn
/// Ein Array aller Ressourcen des Blocks
ushort[] GetBlockResources(int x, int y, int z);
+ // TODO: überlegen ob der Block die Ressourcen wissen muss.
+ // Die Ressourcen könnten auch erst ermittelt werden wenn der Block verarbeitet wurde.
///
/// Ändert die Ressourcen des Blocks an der angegebenen Koordinate
///
diff --git a/OctoAwesome/OctoAwesome/IEntityList.cs b/OctoAwesome/OctoAwesome/IEntityList.cs
deleted file mode 100644
index 9f0aecc9..00000000
--- a/OctoAwesome/OctoAwesome/IEntityList.cs
+++ /dev/null
@@ -1,24 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace OctoAwesome
-{
- public interface IEntityList : ICollection
- {
- IEnumerable FailChunkEntity();
- }
-
- public class FailEntityChunkArgs
- {
- public Index2 CurrentChunk { get; set; }
- public int CurrentPlanet { get; set; }
-
- public Index2 TargetChunk { get; set; }
- public int TargetPlanet { get; set; }
-
- public Entity Entity { get; set; }
- }
-}
diff --git a/OctoAwesome/OctoAwesome/IExtensionLoader.cs b/OctoAwesome/OctoAwesome/IExtensionLoader.cs
index bb965a88..6ae82222 100644
--- a/OctoAwesome/OctoAwesome/IExtensionLoader.cs
+++ b/OctoAwesome/OctoAwesome/IExtensionLoader.cs
@@ -1,6 +1,6 @@
-using System;
+using OctoAwesome.Entities;
+using System;
using System.Collections.Generic;
-
namespace OctoAwesome
{
///
@@ -53,7 +53,7 @@ public interface IExtensionLoader
///
/// Entity Type
/// Extender Delegate
- void RegisterEntityExtender(Action extenderDelegate) where T : Entity;
+ void RegisterEntityExtender(Action extenderDelegate) where T : Entity;
///
/// Adds the Default Extender for the given Entity Type.
@@ -78,8 +78,17 @@ public interface IExtensionLoader
/// Map Generator Type
void RemoveMapGenerator(T item) where T : IMapGenerator;
+ ///
+ /// Adds an new .
+ ///
+ /// Populator to register
void RegisterMapPopulator(IMapPopulator populator);
+ ///
+ /// Removes an existing
+ ///
+ /// Type of Populator
+ /// Pupulator whit type T
void RemoveMapPopulator(T item) where T : IMapPopulator;
}
}
diff --git a/OctoAwesome/OctoAwesome/IExtensionResolver.cs b/OctoAwesome/OctoAwesome/IExtensionResolver.cs
index a0c90663..29da7324 100644
--- a/OctoAwesome/OctoAwesome/IExtensionResolver.cs
+++ b/OctoAwesome/OctoAwesome/IExtensionResolver.cs
@@ -1,4 +1,5 @@
-using System.Collections.Generic;
+using OctoAwesome.Entities;
+using System.Collections.Generic;
namespace OctoAwesome
{
diff --git a/OctoAwesome/OctoAwesome/IGameService.cs b/OctoAwesome/OctoAwesome/IGameService.cs
new file mode 100644
index 00000000..daaf453a
--- /dev/null
+++ b/OctoAwesome/OctoAwesome/IGameService.cs
@@ -0,0 +1,57 @@
+using engenious;
+using OctoAwesome.Entities;
+
+namespace OctoAwesome
+{
+ ///
+ /// Diese Berechnungen sollten nicht der Extension überlassen werden.
+ ///
+ public interface IGameService
+ {
+ ///
+ /// DefinitionManager
+ ///
+ IDefinitionManager DefinitionManager { get; }
+ ///
+ /// Take a Block from the World.
+ ///
+ /// of the
+ /// of the
+ /// of the
+ /// true if the block was successully taken
+ bool TakeBlock(IEntityController controller, ILocalChunkCache cache, out IInventoryableDefinition block);
+ ///
+ /// Take a Block from the World and add it to the invetory.
+ ///
+ /// of the
+ /// of the
+ /// Inventory to store the item
+ /// true if the block was successully taken
+ bool TakeBlock(IEntityController controller, ILocalChunkCache cache, IInventory inventory);
+ ///
+ /// Set a block or interact with a Tool.
+ ///
+ /// of the
+ /// of the
+ /// of the
+ /// Used
+ /// of the
+ /// Height of the
+ /// Radius of the
+ /// true if the interaction was successful
+ bool InteractBlock(Coordinate position, float radius, float height, IEntityController controller,
+ ILocalChunkCache cache, InventorySlot slot, IInventory inventory);
+ ///
+ /// Calculates the collison between an and the world.
+ ///
+ /// Simulation time
+ /// Entity
+ /// radius of the
+ /// height of the
+ /// Calculated delta position for this cycle
+ /// claculated velocity for this cycle
+ /// the velocity of the after collision checks
+ Vector3 WorldCollision(GameTime gameTime, Entity entity, float radius, float height, Vector3 deltaPosition, Vector3 velocity);
+
+ }
+}
diff --git a/OctoAwesome/OctoAwesome/IInventory.cs b/OctoAwesome/OctoAwesome/IInventory.cs
new file mode 100644
index 00000000..57104d78
--- /dev/null
+++ b/OctoAwesome/OctoAwesome/IInventory.cs
@@ -0,0 +1,26 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OctoAwesome
+{
+ ///
+ /// Interface for storage of game elements
+ ///
+ public interface IInventory
+ {
+ ///
+ /// Fügt ein Element des angegebenen Definitionstyps hinzu.
+ ///
+ /// Die Definition.
+ void AddUnit(IInventoryableDefinition definition);
+ ///
+ /// Entfernt eine Einheit vom angegebenen Slot.
+ ///
+ /// Der Slot, aus dem entfernt werden soll.
+ /// Gibt an, ob das entfernen der Einheit aus dem Inventar funktioniert hat. False, z.B. wenn nicht genügend Volumen (weniger als VolumePerUnit) übrig ist-
+ bool RemoveUnit(InventorySlot slot);
+ }
+}
diff --git a/OctoAwesome/OctoAwesome/ILocalChunkCache.cs b/OctoAwesome/OctoAwesome/ILocalChunkCache.cs
index 18344426..6c934270 100644
--- a/OctoAwesome/OctoAwesome/ILocalChunkCache.cs
+++ b/OctoAwesome/OctoAwesome/ILocalChunkCache.cs
@@ -36,7 +36,7 @@ public interface ILocalChunkCache
/// Instanz des Chunks
IChunk GetChunk(int x, int y, int z);
- IPlanet LoadPlanet(int id);
+ IPlanet GetPlanet(int id);
///
/// Setzt den Zentrums-Chunk für diesen lokalen Cache.
@@ -51,6 +51,24 @@ public interface ILocalChunkCache
///
void Flush();
+ ///
+ /// Liefert den Block an der angegebenen Block-Koodinate zurück.
+ ///
+ /// Block Index
+ /// Die Block-ID an der angegebenen Koordinate
+ /// Entfernt den Block.
+ ushort GetBlock(Index3 index, bool removeblock);
+
+ ///
+ /// Liefert den Block an der angegebenen Block-Koodinate zurück.
+ ///
+ /// X-Anteil der Koordinate des Blocks innerhalb des Chunks
+ /// Y-Anteil der Koordinate des Blocks innerhalb des Chunks
+ /// Z-Anteil der Koordinate des Blocks innerhalb des Chunks
+ /// Entfernt den Block.
+ /// Die Block-ID an der angegebenen Koordinate
+ ushort GetBlock(int x, int y, int z, bool removeblock);
+
///
/// Liefert den Block an der angegebenen Block-Koodinate zurück.
///
@@ -73,7 +91,8 @@ public interface ILocalChunkCache
///
/// Block-Koordinate
/// Die neue Block-ID.
- void SetBlock(Index3 index, ushort block);
+ /// Die neuen Blockmetadatan
+ void SetBlock(Index3 index, ushort block, int meta = 0);
///
/// Ãœberschreibt den Block an der angegebenen Koordinate.
@@ -82,7 +101,8 @@ public interface ILocalChunkCache
/// Y-Anteil der Koordinate des Blocks innerhalb des Chunks
/// Z-Anteil der Koordinate des Blocks innerhalb des Chunks
/// Die neue Block-ID.
- void SetBlock(int x, int y, int z, ushort block);
+ /// Die neuen Blockmetadatan
+ void SetBlock(int x, int y, int z, ushort block, int meta = 0);
///
/// Gibt die Metadaten des Blocks an der angegebenen Koordinate zurück.
diff --git a/OctoAwesome/OctoAwesome/IMapPopulator.cs b/OctoAwesome/OctoAwesome/IMapPopulator.cs
index 7e2ce119..f9d952f6 100644
--- a/OctoAwesome/OctoAwesome/IMapPopulator.cs
+++ b/OctoAwesome/OctoAwesome/IMapPopulator.cs
@@ -10,6 +10,7 @@ public interface IMapPopulator
///
int Order { get; }
+ //TODO: Kommentieren xD
///
/// Versieht einen Chunk mit Items
///
diff --git a/OctoAwesome/OctoAwesome/IPlanet.cs b/OctoAwesome/OctoAwesome/IPlanet.cs
index 46eef0ed..5be2c3d8 100644
--- a/OctoAwesome/OctoAwesome/IPlanet.cs
+++ b/OctoAwesome/OctoAwesome/IPlanet.cs
@@ -28,6 +28,11 @@ public interface IPlanet
///
Index3 Size { get; }
+ ///
+ /// Gravitation des Planeten.
+ ///
+ float Gravity { get; }
+
///
/// Die Klimakarte des Planeten
///
diff --git a/OctoAwesome/OctoAwesome/IResourceManager.cs b/OctoAwesome/OctoAwesome/IResourceManager.cs
index 58148040..fc7b2499 100644
--- a/OctoAwesome/OctoAwesome/IResourceManager.cs
+++ b/OctoAwesome/OctoAwesome/IResourceManager.cs
@@ -1,3 +1,4 @@
+using OctoAwesome.Entities;
using System;
namespace OctoAwesome
@@ -7,8 +8,10 @@ namespace OctoAwesome
///
public interface IResourceManager
{
+ ///
+ /// Manager for Object definitions.
+ ///
IDefinitionManager DefinitionManager { get; }
-
///
/// Erzuegt ein neues Universum.
///
@@ -16,66 +19,59 @@ public interface IResourceManager
/// Weltgenerator-Seed für das neue Universum.
/// Die Guid des neuen Universums.
Guid NewUniverse(string name, int seed);
-
///
/// Lädt das Universum für die angegebene GUID.
///
/// Die Guid des Universums.
void LoadUniverse(Guid universeId);
-
///
/// Das aktuell geladene Universum.
///
IUniverse CurrentUniverse { get; }
-
///
/// Entlädt das aktuelle Universum.
///
void UnloadUniverse();
-
///
/// Gibt alle Universen zurück, die geladen werden können.
///
/// Die Liste der Universen.
IUniverse[] ListUniverses();
-
///
/// Löscht ein Universum.
///
/// Die Guid des Universums.
void DeleteUniverse(Guid id);
-
///
/// Lädt einen Player.
///
/// Der Name des Players.
///
Player LoadPlayer(string playername);
-
///
/// Speichert einen Player.
///
/// Der Player.
void SavePlayer(Player player);
-
///
/// Entlädt das aktuelle Universum
///
/// Das gewünschte Universum, falls es existiert
IUniverse GetUniverse();
-
///
/// Gibt den Planeten mit der angegebenen ID zurück
///
/// Die Planteten-ID des gewünschten Planeten
/// Der gewünschte Planet, falls er existiert
IPlanet GetPlanet(int planetId);
-
///
/// Cache der für alle Chunks verwaltet und diese an lokale Caches weiter gibt.
///
IGlobalChunkCache GlobalChunkCache { get; }
-
+ ///
+ /// Save an
+ ///
+ ///
void SaveEntity(Entity entity);
}
}
\ No newline at end of file
diff --git a/OctoAwesome/OctoAwesome/ISerializable.cs b/OctoAwesome/OctoAwesome/ISerializable.cs
new file mode 100644
index 00000000..dc3f8924
--- /dev/null
+++ b/OctoAwesome/OctoAwesome/ISerializable.cs
@@ -0,0 +1,22 @@
+using System.IO;
+namespace OctoAwesome
+{
+ ///
+ /// Interface for Serializable classes.
+ ///
+ public interface ISerializable
+ {
+ ///
+ /// Serialisiert die Entität mit dem angegebenen BinaryWriter.
+ ///
+ /// Der BinaryWriter, mit dem geschrieben wird.
+ /// Der aktuell verwendete .
+ void Serialize(BinaryWriter writer, IDefinitionManager definitionManager);
+ ///
+ /// Deserialisiert die Entität aus dem angegebenen BinaryReader.
+ ///
+ /// Der BinaryWriter, mit dem gelesen wird.
+ /// Der aktuell verwendete .
+ void Deserialize(BinaryReader reader, IDefinitionManager definitionManager);
+ }
+}
diff --git a/OctoAwesome/OctoAwesome/IUserInterfaceExtension.cs b/OctoAwesome/OctoAwesome/IUserInterfaceExtension.cs
new file mode 100644
index 00000000..41f1c358
--- /dev/null
+++ b/OctoAwesome/OctoAwesome/IUserInterfaceExtension.cs
@@ -0,0 +1,16 @@
+using OctoAwesome.Entities;
+
+namespace OctoAwesome
+{
+ ///
+ /// Interface for UI dependend
+ ///
+ public interface IUserInterfaceExtension
+ {
+ ///
+ /// Register the extending UI.
+ ///
+ /// UI-Manager
+ void Register(IUserInterfaceExtensionManager manager);
+ }
+}
diff --git a/OctoAwesome/OctoAwesome/IUserInterfaceExtensionManager.cs b/OctoAwesome/OctoAwesome/IUserInterfaceExtensionManager.cs
new file mode 100644
index 00000000..859148cc
--- /dev/null
+++ b/OctoAwesome/OctoAwesome/IUserInterfaceExtensionManager.cs
@@ -0,0 +1,37 @@
+using engenious.Graphics;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OctoAwesome
+{
+ ///
+ /// UserInterfaceManager
+ ///
+ public interface IUserInterfaceExtensionManager
+ {
+ ///
+ /// Register an to Gamescreen
+ ///
+ /// Type of the Control
+ /// contructor parameter
+ ///
+ bool RegisterOnGameScreen(Type controltype, params object[] args);
+ ///
+ /// Register an to InvertoryScreen
+ ///
+ /// Type of the Control
+ /// contructor parameter
+ ///
+ bool RegisterOnInventoryScreen(Type controltype, params object[] args);
+ ///
+ /// Load Textures for UI
+ ///
+ /// Texture type
+ /// Texture key
+ ///
+ Texture2D LoadTextures(Type type, string key);
+ }
+}
diff --git a/OctoAwesome/OctoAwesome/LocalChunkCache.cs b/OctoAwesome/OctoAwesome/LocalChunkCache.cs
index 432a0a87..a33c88cc 100644
--- a/OctoAwesome/OctoAwesome/LocalChunkCache.cs
+++ b/OctoAwesome/OctoAwesome/LocalChunkCache.cs
@@ -15,9 +15,13 @@ public class LocalChunkCache : ILocalChunkCache
/// Aktueller Planet auf dem sich der Cache bezieht.
///
public IPlanet Planet { get; private set; }
-
+ ///
+ /// Indicates that the LocalChunkCache is Passive (not loading Chunks)
+ ///
public bool IsPassive { get; private set; }
-
+ ///
+ /// The Center Chucnkcolumn of the LocalCach
+ ///
public Index2 CenterPosition { get; set; }
///
@@ -59,6 +63,7 @@ public class LocalChunkCache : ILocalChunkCache
/// Referenz auf global Chunk Cache
/// Größe des Caches in Zweierpotenzen
/// Gibt die Range in alle Richtungen an.
+ /// Indicats that the Cache is passive (no active load)
public LocalChunkCache(IGlobalChunkCache globalCache, bool passive, int dimensions, int range)
{
IsPassive = passive;
@@ -150,8 +155,7 @@ private void InternalSetCenter(CancellationToken token, IPlanet planet, Index2 i
}
foreach (var chunkColumnIndex in requiredChunkColumns
- .OrderBy(c => index.ShortestDistanceXY(c, new Index2(planet.Size))
- .LengthSquared()))
+ .OrderBy(c => index.ShortestDistanceXY(c, new Index2(planet.Size)).LengthSquared()))
{
int localX = chunkColumnIndex.X & mask;
int localY = chunkColumnIndex.Y & mask;
@@ -240,6 +244,14 @@ public IChunk GetChunk(int x, int y, int z)
return null;
}
+ ///
+ /// Liefert den Block an der angegebenen Block-Koodinate zurück.
+ ///
+ /// Block Index
+ /// The block will be removed
+ /// Die Block-ID an der angegebenen Koordinate
+ public ushort GetBlock(Index3 index, bool removeblock)
+ => GetBlock(index.X, index.Y, index.Z, removeblock);
///
/// Liefert den Block an der angegebenen Block-Koodinate zurück.
///
@@ -247,7 +259,19 @@ public IChunk GetChunk(int x, int y, int z)
/// Die Block-ID an der angegebenen Koordinate
public ushort GetBlock(Index3 index)
=> GetBlock(index.X, index.Y, index.Z);
-
+ ///
+ /// Liefert den Block an der angegebenen Block-Koodinate zurück.
+ ///
+ /// X-Anteil der Koordinate des Blocks
+ /// Y-Anteil der Koordinate des Blocks
+ /// Z-Anteil der Koordinate des Blocks
+ /// The block will be removed
+ /// Die Block-ID an der angegebenen Koordinate
+ public ushort GetBlock(int x, int y, int z, bool removeblock)
+ {
+ IChunk chunk = GetChunk(x >> Chunk.LimitX, y >> Chunk.LimitY, z >> Chunk.LimitZ);
+ return chunk?.GetBlock(x, y, z, removeblock) ?? 0;
+ }
///
/// Liefert den Block an der angegebenen Block-Koodinate zurück.
///
@@ -258,11 +282,7 @@ public ushort GetBlock(Index3 index)
public ushort GetBlock(int x, int y, int z)
{
IChunk chunk = GetChunk(x >> Chunk.LimitX, y >> Chunk.LimitY, z >> Chunk.LimitZ);
-
- if (chunk != null)
- return chunk.GetBlock(x, y, z);
-
- return 0;
+ return chunk?.GetBlock(x, y, z) ?? 0;
}
///
@@ -270,8 +290,9 @@ public ushort GetBlock(int x, int y, int z)
///
/// Block-Koordinate
/// Die neue Block-ID.
- public void SetBlock(Index3 index, ushort block)
- => SetBlock(index.X, index.Y, index.Z, block);
+ /// Die neuen Metadatan
+ public void SetBlock(Index3 index, ushort block, int meta = 0)
+ => SetBlock(index.X, index.Y, index.Z, block, meta);
///
/// Ãœberschreibt den Block an der angegebenen Koordinate.
@@ -280,12 +301,11 @@ public void SetBlock(Index3 index, ushort block)
/// Y-Anteil der Koordinate des Blocks innerhalb des Chunks
/// Z-Anteil der Koordinate des Blocks innerhalb des Chunks
/// Die neue Block-ID
- public void SetBlock(int x, int y, int z, ushort block)
+ /// Die neuen Metadatan
+ public void SetBlock(int x, int y, int z, ushort block, int meta = 0)
{
IChunk chunk = GetChunk(x >> Chunk.LimitX, y >> Chunk.LimitY, z >> Chunk.LimitZ);
-
- if (chunk != null)
- chunk.SetBlock(x, y, z, block);
+ chunk?.SetBlock(x, y, z, block, meta);
}
///
@@ -359,10 +379,13 @@ public void Flush()
/// Die X-Koordinate
/// Die Y-Koordinate
/// Der Abgeflachte index
- private int FlatIndex(int x, int y)
- => (((y & (mask)) << limit) | ((x & (mask))));
+ private int FlatIndex(int x, int y) => (((y & (mask)) << limit) | ((x & (mask))));
- public IPlanet LoadPlanet(int id)
- => globalCache.GetPlanet(id);
+ ///
+ /// Get the from .
+ ///
+ /// Id of the planet.
+ ///
+ public IPlanet GetPlanet(int id) => globalCache.GetPlanet(id);
}
}
diff --git a/OctoAwesome/OctoAwesome/MapPopulator.cs b/OctoAwesome/OctoAwesome/MapPopulator.cs
index dca4131f..f2129d14 100644
--- a/OctoAwesome/OctoAwesome/MapPopulator.cs
+++ b/OctoAwesome/OctoAwesome/MapPopulator.cs
@@ -10,6 +10,10 @@ public abstract class MapPopulator : IMapPopulator
///
public int Order { get; protected set; }
+ // TODO: initialisieren? -> bessere skalierung der population
+ // enviromente parameter können besser einbezogen werden (plante ist zu kalt für lebewesen etc...)
+ //public abstract void Initialize(IPlanet plante, IDefinitionManager definitions);
+
///
/// Versieht einen Chunk mit Items
///
diff --git a/OctoAwesome/OctoAwesome/OctoAwesome.csproj b/OctoAwesome/OctoAwesome/OctoAwesome.csproj
index 30f630e0..1fef95ec 100644
--- a/OctoAwesome/OctoAwesome/OctoAwesome.csproj
+++ b/OctoAwesome/OctoAwesome/OctoAwesome.csproj
@@ -43,13 +43,21 @@
false
-
- False
- ..\libs\engenious.dll
+
+ ..\packages\engenious.0.1.11\lib\net40\engenious.dll
+
+
+ ..\packages\engenious.0.1.11\lib\net40\NVorbis.dll
+
+
+ ..\packages\engenious.0.1.11\lib\net40\OpenTK.dll
+
+ ..\packages\engenious.0.1.11\lib\net40\System.Numerics.Vectors.dll
+
@@ -64,28 +72,31 @@
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
+
+
@@ -102,11 +113,13 @@
-
+
+
+
@@ -121,9 +134,18 @@
-
+
+
+
+
+
+
+ Dieses Projekt verweist auf mindestens ein NuGet-Paket, das auf diesem Computer fehlt. Verwenden Sie die Wiederherstellung von NuGet-Paketen, um die fehlenden Dateien herunterzuladen. Weitere Informationen finden Sie unter "http://go.microsoft.com/fwlink/?LinkID=322105". Die fehlende Datei ist "{0}".
+
+
+