diff --git a/Subsurface/Characters/HumanoidAnimController.cs b/Subsurface/Characters/HumanoidAnimController.cs index 2ca0847f3..8946a8163 100644 --- a/Subsurface/Characters/HumanoidAnimController.cs +++ b/Subsurface/Characters/HumanoidAnimController.cs @@ -32,7 +32,7 @@ namespace Subsurface { case Physics.CollisionStairs: Structure structure = fixture.Body.UserData as Structure; - if (stairs == null && (!inWater || TargetMovement.Y>0.0f) && structure!=null) + if (stairs == null && !inWater && structure!=null) { if (LowestLimb.SimPosition.Y 20.0f) return; } - Limb leftFoot = GetLimb(LimbType.LeftFoot); - Limb rightFoot = GetLimb(LimbType.RightFoot); Limb torso = GetLimb(LimbType.Torso); Limb leftHand = GetLimb(LimbType.LeftHand); Limb rightHand = GetLimb(LimbType.RightHand); + Limb leftFoot = GetLimb(LimbType.LeftFoot); + Limb rightFoot = GetLimb(LimbType.RightFoot); + Limb leftLeg = GetLimb(LimbType.LeftLeg); + Limb rightLeg = GetLimb(LimbType.RightLeg); float rotation = MathHelper.WrapAngle(torso.Rotation); rotation = MathHelper.ToDegrees(rotation); @@ -397,9 +404,9 @@ namespace Subsurface if (TargetMovement.X == 0.0f) { head.body.ApplyForce(head.Mass * new Vector2(-Dir * 5.1f, -5.0f)); - torso.body.ApplyForce(torso.Mass *new Vector2(-Dir*5.1f, -15.0f)); - leftFoot.body.ApplyForce(leftFoot.Mass *new Vector2(0.0f, -80.0f)); - rightFoot.body.ApplyForce(rightFoot.Mass *new Vector2(0.0f, -80.0f)); + torso.body.ApplyForce(torso.Mass * new Vector2(-Dir * 5.1f, -15.0f)); + leftFoot.body.ApplyForce(leftFoot.Mass * new Vector2(0.0f, -80.0f)); + rightFoot.body.ApplyForce(rightFoot.Mass * new Vector2(0.0f, -80.0f)); } else { @@ -432,12 +439,19 @@ namespace Subsurface MoveLimb(leftFoot, footPos + transformedFootPos, 2.5f); MoveLimb(rightFoot, footPos - transformedFootPos, 2.5f); - Vector2 feetExtendForce = new Vector2( - (float)-Math.Sin(torso.body.Rotation), - (float)Math.Cos(torso.body.Rotation)); + float legCorrection = MathUtils.GetShortestAngle(leftLeg.Rotation, torso.body.Rotation); - leftFoot.body.ApplyForce(feetExtendForce); - rightFoot.body.ApplyForce(feetExtendForce); + leftLeg.body.ApplyTorque(legCorrection); + + legCorrection = MathUtils.GetShortestAngle(rightLeg.Rotation, torso.body.Rotation); + + rightLeg.body.ApplyTorque(legCorrection); + //Vector2 feetExtendForce = new Vector2( + // (float)-Math.Sin(torso.body.Rotation), + // (float)Math.Cos(torso.body.Rotation)); + + //leftFoot.body.ApplyForce(feetExtendForce); + //rightFoot.body.ApplyForce(feetExtendForce); leftFoot.body.ApplyTorque(leftFoot.body.Mass * -Dir); rightFoot.body.ApplyTorque(rightFoot.body.Mass * -Dir); diff --git a/Subsurface/Characters/Limb.cs b/Subsurface/Characters/Limb.cs index 9f0ed97b3..a17e19bb7 100644 --- a/Subsurface/Characters/Limb.cs +++ b/Subsurface/Characters/Limb.cs @@ -187,7 +187,16 @@ namespace Subsurface if (element.Attribute("type") != null) { - type = (LimbType)Enum.Parse(typeof(LimbType), element.Attribute("type").Value, true); + try + { + type = (LimbType)Enum.Parse(typeof(LimbType), element.Attribute("type").Value, true); + } + catch + { + type = LimbType.None; + DebugConsole.ThrowError("Error in "+element+"! ''"+element.Attribute("type").Value+"'' is not a valid limb type"); + } + Vector2 jointPos = ToolBox.GetAttributeVector2(element, "pullpos", Vector2.Zero); diff --git a/Subsurface/Content/Items/Engine/engine.xml b/Subsurface/Content/Items/Engine/engine.xml index 4f804353d..4a7a2aa76 100644 --- a/Subsurface/Content/Items/Engine/engine.xml +++ b/Subsurface/Content/Items/Engine/engine.xml @@ -7,14 +7,16 @@ pickdistance="150"> - - + + + + - + - + + + + + + + diff --git a/Subsurface/Content/Items/MiniMap/item.xml b/Subsurface/Content/Items/MiniMap/item.xml index 91be063eb..82e32f95c 100644 --- a/Subsurface/Content/Items/MiniMap/item.xml +++ b/Subsurface/Content/Items/MiniMap/item.xml @@ -6,7 +6,9 @@ - + + + diff --git a/Subsurface/Content/Items/Reactor/reactor.xml b/Subsurface/Content/Items/Reactor/reactor.xml index d794b8eee..51f98f343 100644 --- a/Subsurface/Content/Items/Reactor/reactor.xml +++ b/Subsurface/Content/Items/Reactor/reactor.xml @@ -9,6 +9,7 @@ + diff --git a/Subsurface/Content/Items/poweritems.xml b/Subsurface/Content/Items/poweritems.xml index 0718b56ea..907bc87f1 100644 --- a/Subsurface/Content/Items/poweritems.xml +++ b/Subsurface/Content/Items/poweritems.xml @@ -8,12 +8,15 @@ - + + + - - + + + @@ -23,8 +26,10 @@ pickdistance="150"> - - + + + + diff --git a/Subsurface/GUI/GUI.cs b/Subsurface/GUI/GUI.cs index 3f80d1b19..5c6ad18fd 100644 --- a/Subsurface/GUI/GUI.cs +++ b/Subsurface/GUI/GUI.cs @@ -264,15 +264,15 @@ namespace Subsurface public static void Draw(float deltaTime, SpriteBatch spriteBatch, Camera cam) { - spriteBatch.DrawString(font, - "FPS: " + (int)Game1.frameCounter.AverageFramesPerSecond - + " - render: " + Game1.renderTimeElapsed, - new Vector2(10, 10), Color.White); + //spriteBatch.DrawString(font, + // "FPS: " + (int)Game1.frameCounter.AverageFramesPerSecond + // + " - render: " + Game1.renderTimeElapsed, + // new Vector2(10, 10), Color.White); - spriteBatch.DrawString(font, - "Physics: " + Game1.world.UpdateTime - + " - bodies: " + Game1.world.BodyList.Count, - new Vector2(10, 30), Color.White); + //spriteBatch.DrawString(font, + // "Physics: " + Game1.world.UpdateTime + // + " - bodies: " + Game1.world.BodyList.Count, + // new Vector2(10, 30), Color.White); if (Character.Controlled != null && cam!=null) Character.Controlled.DrawHud(spriteBatch, cam); diff --git a/Subsurface/GUI/GUIComponent.cs b/Subsurface/GUI/GUIComponent.cs index a2fbf255c..966d97f2b 100644 --- a/Subsurface/GUI/GUIComponent.cs +++ b/Subsurface/GUI/GUIComponent.cs @@ -39,6 +39,11 @@ namespace Subsurface { get { return parent; } } + + public Vector2 Center + { + get { return new Vector2(rect.Center.X, rect.Center.Y); } + } public Rectangle Rect { @@ -192,43 +197,44 @@ namespace Subsurface } } - protected virtual void UpdateDimensions(GUIComponent parent) + protected virtual void UpdateDimensions(GUIComponent parent = null) { - if (parent!=null) + Rectangle parentRect = (parent==null) ? new Rectangle(0,0,Game1.GraphicsWidth, Game1.GraphicsHeight) : parent.rect; + + Vector4 padding = (parent == null) ? Vector4.Zero : parent.padding; + + if (rect.Width == 0) rect.Width = parentRect.Width - rect.X + - (int)padding.X - (int)padding.Z; + + if (rect.Height == 0) rect.Height = parentRect.Height - rect.Y + - (int)padding.Y - (int)padding.W; + + if (alignment.HasFlag(Alignment.CenterX)) { - if (rect.Width == 0) rect.Width = parent.Rect.Width - rect.X - - (int)parent.Padding.X - (int)parent.Padding.Z; - - if (rect.Height == 0) rect.Height = parent.Rect.Height - rect.Y - - (int)parent.Padding.Y - (int)parent.Padding.W; - - if (alignment.HasFlag(Alignment.CenterX)) - { - rect.X += parent.Rect.X + (int)parent.Rect.Width/2 - (int)rect.Width/2; - } - else if (alignment.HasFlag(Alignment.Right)) - { - rect.X += parent.Rect.X + (int)parent.Rect.Width - (int)parent.Padding.Z - (int)rect.Width; - } - else - { - rect.X += parent.Rect.X + (int)parent.Padding.X; - } - - if (alignment.HasFlag(Alignment.CenterY)) - { - rect.Y += parent.Rect.Y + (int)parent.Rect.Height / 2 - (int)rect.Height / 2; - } - else if (alignment.HasFlag(Alignment.Bottom)) - { - rect.Y += parent.Rect.Y + (int)parent.Rect.Height - (int)parent.Padding.W - (int)rect.Height; - } - else - { - rect.Y += parent.Rect.Y + (int)parent.Padding.Y; - } - + rect.X += parentRect.X + (int)parentRect.Width/2 - (int)rect.Width/2; } + else if (alignment.HasFlag(Alignment.Right)) + { + rect.X += parentRect.X + (int)parentRect.Width - (int)padding.Z - (int)rect.Width; + } + else + { + rect.X += parentRect.X + (int)padding.X; + } + + if (alignment.HasFlag(Alignment.CenterY)) + { + rect.Y += parentRect.Y + (int)parentRect.Height / 2 - (int)rect.Height / 2; + } + else if (alignment.HasFlag(Alignment.Bottom)) + { + rect.Y += parentRect.Y + (int)parentRect.Height - (int)padding.W - (int)rect.Height; + } + else + { + rect.Y += parentRect.Y + (int)padding.Y; + } + } public virtual void DrawChildren(SpriteBatch spriteBatch) diff --git a/Subsurface/GUI/GUIFrame.cs b/Subsurface/GUI/GUIFrame.cs index ecfee361d..06d726c25 100644 --- a/Subsurface/GUI/GUIFrame.cs +++ b/Subsurface/GUI/GUIFrame.cs @@ -23,8 +23,15 @@ namespace Subsurface this.alignment = alignment; this.color = color; - if (parent!=null) + + if (parent != null) + { parent.AddChild(this); + } + else + { + UpdateDimensions(); + } } public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch) diff --git a/Subsurface/Game1.cs b/Subsurface/Game1.cs index 847a4062d..7f1d87d91 100644 --- a/Subsurface/Game1.cs +++ b/Subsurface/Game1.cs @@ -49,7 +49,7 @@ namespace Subsurface public static Random random; //private Stopwatch renderTimer; - public static int renderTimeElapsed; + //public static int renderTimeElapsed; public Camera Cam diff --git a/Subsurface/Items/Components/Door.cs b/Subsurface/Items/Components/Door.cs index 459cba8cd..2be769c5e 100644 --- a/Subsurface/Items/Components/Door.cs +++ b/Subsurface/Items/Components/Door.cs @@ -310,7 +310,7 @@ namespace Subsurface.Items.Components if (convexHull2 != null) convexHull2.Remove(); } - public override void ReceiveSignal(string signal, Connection connection, Item sender) + public override void ReceiveSignal(string signal, Connection connection, Item sender, float power=0.0f) { if (connection.name=="toggle") { diff --git a/Subsurface/Items/Components/Holdable.cs b/Subsurface/Items/Components/Holdable/Holdable.cs similarity index 100% rename from Subsurface/Items/Components/Holdable.cs rename to Subsurface/Items/Components/Holdable/Holdable.cs diff --git a/Subsurface/Items/Components/Pickable.cs b/Subsurface/Items/Components/Holdable/Pickable.cs similarity index 100% rename from Subsurface/Items/Components/Pickable.cs rename to Subsurface/Items/Components/Holdable/Pickable.cs diff --git a/Subsurface/Items/Components/RangedWeapon.cs b/Subsurface/Items/Components/Holdable/RangedWeapon.cs similarity index 95% rename from Subsurface/Items/Components/RangedWeapon.cs rename to Subsurface/Items/Components/Holdable/RangedWeapon.cs index 5affe69de..dfc0ec150 100644 --- a/Subsurface/Items/Components/RangedWeapon.cs +++ b/Subsurface/Items/Components/Holdable/RangedWeapon.cs @@ -35,8 +35,8 @@ namespace Subsurface.Items.Components public RangedWeapon(Item item, XElement element) : base(item, element) { - barrelPos = ToolBox.GetAttributeVector2(element, "barrelpos", Vector2.Zero); - barrelPos = ConvertUnits.ToSimUnits(barrelPos); + //barrelPos = ToolBox.GetAttributeVector2(element, "barrelpos", Vector2.Zero); + //barrelPos = ConvertUnits.ToSimUnits(barrelPos); } public override void Update(float deltaTime, Camera cam) diff --git a/Subsurface/Items/Components/RepairTool.cs b/Subsurface/Items/Components/Holdable/RepairTool.cs similarity index 100% rename from Subsurface/Items/Components/RepairTool.cs rename to Subsurface/Items/Components/Holdable/RepairTool.cs diff --git a/Subsurface/Items/Components/Throwable.cs b/Subsurface/Items/Components/Holdable/Throwable.cs similarity index 100% rename from Subsurface/Items/Components/Throwable.cs rename to Subsurface/Items/Components/Holdable/Throwable.cs diff --git a/Subsurface/Items/Components/ItemComponent.cs b/Subsurface/Items/Components/ItemComponent.cs index 5e7763ff8..58c5b5dcf 100644 --- a/Subsurface/Items/Components/ItemComponent.cs +++ b/Subsurface/Items/Components/ItemComponent.cs @@ -54,6 +54,8 @@ namespace Subsurface private List sounds; + private GUIFrame guiFrame; + public readonly Dictionary properties; public Dictionary ObjectProperties { @@ -96,6 +98,19 @@ namespace Subsurface get { return name; } } + protected GUIFrame GuiFrame + { + get + { + if (guiFrame==null) + { + DebugConsole.ThrowError("Error: the component "+name+" in "+item.Name+" doesn't have a guiFrame"); + guiFrame = new GUIFrame(new Rectangle(0, 0, 100, 100), Color.Black); + } + return guiFrame; + } + } + [HasDefaultValue("", false)] public string Msg { @@ -153,6 +168,32 @@ namespace Subsurface case "statuseffect": statusEffects.Add(StatusEffect.Load(subElement)); break; + case "guiframe": + Vector4 rect = ToolBox.GetAttributeVector4(subElement, "rect", Vector4.One); + rect.X *= Game1.GraphicsWidth; + rect.Y *= Game1.GraphicsHeight; + rect.Z *= Game1.GraphicsWidth; + rect.W *= Game1.GraphicsHeight; + + Vector4 color = ToolBox.GetAttributeVector4(subElement, "color", Vector4.One); + + Alignment alignment = Alignment.Center; + try + { + alignment = (Alignment)Enum.Parse(typeof(Alignment), + ToolBox.GetAttributeString(subElement, "alignment", "Center"), true); + } + catch + { + DebugConsole.ThrowError("Error in " + element + "! ''" + element.Attribute("type").Value + "'' is not a valid alignment"); + } + + guiFrame = new GUIFrame( + new Rectangle((int)rect.X, (int)rect.Y, (int)rect.Z, (int)rect.W), + new Color(color.X, color.Y, color.Z), alignment); + guiFrame.Alpha = color.W; + + break; case "sound": string filePath = ToolBox.GetAttributeString(subElement, "file", ""); if (filePath=="") continue; @@ -284,7 +325,7 @@ namespace Subsurface return false; } - public virtual void ReceiveSignal(string signal, Connection connection, Item sender) { } + public virtual void ReceiveSignal(string signal, Connection connection, Item sender, float power = 0.0f) { } public virtual bool Combine(Item item) { diff --git a/Subsurface/Items/Components/Controller.cs b/Subsurface/Items/Components/Machines/Controller.cs similarity index 100% rename from Subsurface/Items/Components/Controller.cs rename to Subsurface/Items/Components/Machines/Controller.cs diff --git a/Subsurface/Items/Components/Engine.cs b/Subsurface/Items/Components/Machines/Engine.cs similarity index 75% rename from Subsurface/Items/Components/Engine.cs rename to Subsurface/Items/Components/Machines/Engine.cs index 4db0fa5bc..3c7b1e94c 100644 --- a/Subsurface/Items/Components/Engine.cs +++ b/Subsurface/Items/Components/Machines/Engine.cs @@ -71,17 +71,18 @@ namespace Subsurface.Items.Components public override void DrawHUD(SpriteBatch spriteBatch, Character character) { //isActive = true; + GuiFrame.Draw(spriteBatch); + + //int width = 300, height = 300; + //int x = Game1.GraphicsWidth / 2 - width / 2; + //int y = Game1.GraphicsHeight / 2 - height / 2 - 50; - int width = 300, height = 300; - int x = Game1.GraphicsWidth / 2 - width / 2; - int y = Game1.GraphicsHeight / 2 - height / 2 - 50; + //GUI.DrawRectangle(spriteBatch, new Rectangle(x, y, width, height), Color.Black, true); - GUI.DrawRectangle(spriteBatch, new Rectangle(x, y, width, height), Color.Black, true); + spriteBatch.DrawString(GUI.font, "Force: " + (int)targetForce + " %", new Vector2(GuiFrame.Rect.X + 30, GuiFrame.Rect.Y + 30), Color.White); - spriteBatch.DrawString(GUI.font, "Force: " + (int)targetForce+" %", new Vector2(x + 30, y + 30), Color.White); - - if (GUI.DrawButton(spriteBatch, new Rectangle(x + 280, y + 30, 40, 40), "+", true)) targetForce += 1.0f; - if (GUI.DrawButton(spriteBatch, new Rectangle(x + 280, y + 80, 40, 40), "-", true)) targetForce -= 1.0f; + if (GUI.DrawButton(spriteBatch, new Rectangle(GuiFrame.Rect.X + 280, GuiFrame.Rect.Y + 30, 40, 40), "+", true)) targetForce += 1.0f; + if (GUI.DrawButton(spriteBatch, new Rectangle(GuiFrame.Rect.X + 280, GuiFrame.Rect.Y + 80, 40, 40), "-", true)) targetForce -= 1.0f; item.NewComponentEvent(this, true); } @@ -91,9 +92,9 @@ namespace Subsurface.Items.Components force = MathHelper.Lerp(force, 0.0f, 0.1f); } - public override void ReceiveSignal(string signal, Connection connection, Item sender) + public override void ReceiveSignal(string signal, Connection connection, Item sender, float power=0.0f) { - base.ReceiveSignal(signal, connection, sender); + base.ReceiveSignal(signal, connection, sender, power); if (connection.name == "set_force") { diff --git a/Subsurface/Items/Components/Fabricator.cs b/Subsurface/Items/Components/Machines/Fabricator.cs similarity index 100% rename from Subsurface/Items/Components/Fabricator.cs rename to Subsurface/Items/Components/Machines/Fabricator.cs diff --git a/Subsurface/Items/Components/MiniMap.cs b/Subsurface/Items/Components/Machines/MiniMap.cs similarity index 89% rename from Subsurface/Items/Components/MiniMap.cs rename to Subsurface/Items/Components/Machines/MiniMap.cs index 1f501484d..cbc32393a 100644 --- a/Subsurface/Items/Components/MiniMap.cs +++ b/Subsurface/Items/Components/Machines/MiniMap.cs @@ -32,12 +32,13 @@ namespace Subsurface.Items.Components public override void DrawHUD(SpriteBatch spriteBatch, Character character) { - int width = 500, height = 400; - int x = Game1.GraphicsWidth / 2 - width / 2; - int y = Game1.GraphicsHeight / 2 - height / 2; + int width = GuiFrame.Rect.Width, height = GuiFrame.Rect.Height; + int x = GuiFrame.Rect.X; + int y = GuiFrame.Rect.Y; + GuiFrame.Draw(spriteBatch); - GUI.DrawRectangle(spriteBatch, new Rectangle(x,y,width,height), Color.Black, true); + //GUI.DrawRectangle(spriteBatch, new Rectangle(x,y,width,height), Color.Black, true); Rectangle miniMap = new Rectangle(x + 20, y + 40, width - 40, height - 60); diff --git a/Subsurface/Items/Components/OxygenGenerator.cs b/Subsurface/Items/Components/Machines/OxygenGenerator.cs similarity index 100% rename from Subsurface/Items/Components/OxygenGenerator.cs rename to Subsurface/Items/Components/Machines/OxygenGenerator.cs diff --git a/Subsurface/Items/Components/Pump.cs b/Subsurface/Items/Components/Machines/Pump.cs similarity index 95% rename from Subsurface/Items/Components/Pump.cs rename to Subsurface/Items/Components/Machines/Pump.cs index 302a78c80..26b3db691 100644 --- a/Subsurface/Items/Components/Pump.cs +++ b/Subsurface/Items/Components/Machines/Pump.cs @@ -133,9 +133,11 @@ namespace Subsurface.Items.Components // } //} - public override void ReceiveSignal(string signal, Connection connection, Item sender) + public override void ReceiveSignal(string signal, Connection connection, Item sender, float power=0.0f) { - base.ReceiveSignal(signal, connection, sender); + base.ReceiveSignal(signal, connection, sender, power); + + isActive = true; if (connection.name == "toggle") { @@ -150,7 +152,7 @@ namespace Subsurface.Items.Components float tempSpeed; if (float.TryParse(signal, NumberStyles.Float, CultureInfo.InvariantCulture, out tempSpeed)) { - flowPercentage = MathHelper.Clamp(flowPercentage, -100.0f, 100.0f); + flowPercentage = MathHelper.Clamp(tempSpeed, -100.0f, 100.0f); } } diff --git a/Subsurface/Items/Components/Machines/Radar.cs b/Subsurface/Items/Components/Machines/Radar.cs new file mode 100644 index 000000000..e38f65e58 --- /dev/null +++ b/Subsurface/Items/Components/Machines/Radar.cs @@ -0,0 +1,86 @@ +using FarseerPhysics; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Xml.Linq; + +namespace Subsurface.Items.Components +{ + class Radar : ItemComponent + { + float range; + + float angle; + + //RenderTarget2D renderTarget; + + [HasDefaultValue(0.0f, false)] + public float Range + { + get { return ConvertUnits.ToDisplayUnits(range); } + set { range = ConvertUnits.ToSimUnits(value); } + } + + public Radar(Item item, XElement element) + : base(item, element) + { + //renderTarget = new RenderTarget2D(Game1.CurrGraphicsDevice, GuiFrame.Rect.Width, GuiFrame.Rect.Height); + } + + public override void Update(float deltaTime, Camera cam) + { + base.Update(deltaTime, cam); + + angle = (angle + deltaTime) % MathHelper.TwoPi; + } + + public override void DrawHUD(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, Character character) + { + int width = GuiFrame.Rect.Width, height = GuiFrame.Rect.Height; + int x = GuiFrame.Rect.X; + int y = GuiFrame.Rect.Y; + + GuiFrame.Draw(spriteBatch); + + if (GUI.DrawButton(spriteBatch, new Rectangle(x+20, y+20, 200, 30), "Activate Radar")) isActive = !isActive; + + Vector2 lineEnd = GuiFrame.Center; + lineEnd += new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle))*Math.Min(width,height)/2.0f; + GUI.DrawLine(spriteBatch, GuiFrame.Center, lineEnd, Color.Green); + + if (!isActive) return; + + float scale = 0.01f; + + List edges = Level.Loaded.GetCellEdges(-Level.Loaded.position, 5); + Vector2 offset = Vector2.Zero; //Level.Loaded.position; + //offset.Y = -offset.Y; + + for (int i = 0; i < edges.Count; i++) + { + GUI.DrawLine(spriteBatch, + GuiFrame.Center + (edges[i][0] - offset) * scale, + GuiFrame.Center + (edges[i][1] - offset) * scale, Color.Green); + } + + scale = ConvertUnits.ToDisplayUnits(scale); + for (int i = 0; i< Submarine.Loaded.HullVertices.Count; i++) + { + Vector2 start =Submarine.Loaded.HullVertices[i] * scale; + start.Y = -start.Y; + Vector2 end = Submarine.Loaded.HullVertices[(i+1)%Submarine.Loaded.HullVertices.Count] * scale; + end.Y = -end.Y; + + GUI.DrawLine(spriteBatch, GuiFrame.Center + start,GuiFrame.Center + end, Color.Green); + } + } + + private void UpdateRendertarget() + { + + } + } +} diff --git a/Subsurface/Items/Components/Reactor.cs b/Subsurface/Items/Components/Machines/Reactor.cs similarity index 98% rename from Subsurface/Items/Components/Reactor.cs rename to Subsurface/Items/Components/Machines/Reactor.cs index 433926992..2a34e610f 100644 --- a/Subsurface/Items/Components/Reactor.cs +++ b/Subsurface/Items/Components/Machines/Reactor.cs @@ -300,9 +300,11 @@ namespace Subsurface.Items.Components { isActive = true; - int width = 500, height = 420; - int x = Game1.GraphicsWidth / 2 - width / 2; - int y = Game1.GraphicsHeight / 2 - height / 2 - 50; + int width = GuiFrame.Rect.Width, height = GuiFrame.Rect.Height; + int x = GuiFrame.Rect.X; + int y = GuiFrame.Rect.Y; + + GuiFrame.Draw(spriteBatch); float xOffset = (graphTimer / (float)updateGraphInterval); diff --git a/Subsurface/Items/Components/Steering.cs b/Subsurface/Items/Components/Machines/Steering.cs similarity index 70% rename from Subsurface/Items/Components/Steering.cs rename to Subsurface/Items/Components/Machines/Steering.cs index 43367febe..95b3d9721 100644 --- a/Subsurface/Items/Components/Steering.cs +++ b/Subsurface/Items/Components/Machines/Steering.cs @@ -23,24 +23,22 @@ namespace Subsurface.Items.Components { base.Update(deltaTime, cam); - item.SendSignal(targetVelocity.X.ToString(), "velocity_x_out", item); - item.SendSignal(targetVelocity.Y.ToString(), "velocity_y_out", item); + item.SendSignal(targetVelocity.X.ToString(), "velocity_x_out"); + item.SendSignal((-targetVelocity.Y).ToString(), "velocity_y_out"); } public override void DrawHUD(SpriteBatch spriteBatch, Character character) { - //isActive = true; + int width = GuiFrame.Rect.Width, height = GuiFrame.Rect.Height; + int x = GuiFrame.Rect.X; + int y = GuiFrame.Rect.Y; - int width = 300, height = 300; - int x = Game1.GraphicsWidth / 2 - width / 2; - int y = Game1.GraphicsHeight / 2 - height / 2 - 50; + GuiFrame.Draw(spriteBatch); - GUI.DrawRectangle(spriteBatch, new Rectangle(x, y, width, height), Color.Black, true); - - Rectangle velRect = new Rectangle(x+20, y+20, 100, 100); + Rectangle velRect = new Rectangle(x + 20, y + 20, width - 40, height - 40); GUI.DrawRectangle(spriteBatch, velRect, Color.White, false); - GUI.DrawLine(spriteBatch, + GUI.DrawLine(spriteBatch, new Vector2(velRect.Center.X,velRect.Center.Y), new Vector2(velRect.Center.X + currVelocity.X, velRect.Center.Y - currVelocity.Y), Color.Gray); @@ -65,20 +63,27 @@ namespace Subsurface.Items.Components } } - //spriteBatch.DrawString(GUI.font, "Force: " + (int)force + " %", new Vector2(x + 30, y + 30), Color.White); - - //if (GUI.DrawButton(spriteBatch, new Rectangle(x + 280, y + 30, 40, 40), "+", true)) targetForce += 1.0f; - //if (GUI.DrawButton(spriteBatch, new Rectangle(x + 280, y + 80, 40, 40), "-", true)) targetForce -= 1.0f; - item.NewComponentEvent(this, true); } - public override void ReceiveSignal(string signal, Connection connection, Item sender) + public override void ReceiveSignal(string signal, Connection connection, Item sender, float power=0.0f) { if (connection.name == "velocity_in") { currVelocity = ToolBox.ParseToVector2(signal, false); } } + + public override void FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetOutgoingMessage message) + { + message.Write(targetVelocity.X); + message.Write(targetVelocity.Y); + } + + public override void ReadNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetIncomingMessage message) + { + targetVelocity.X = message.ReadFloat(); + targetVelocity.Y = message.ReadFloat(); + } } } diff --git a/Subsurface/Items/Components/Vent.cs b/Subsurface/Items/Components/Machines/Vent.cs similarity index 100% rename from Subsurface/Items/Components/Vent.cs rename to Subsurface/Items/Components/Machines/Vent.cs diff --git a/Subsurface/Items/Components/PowerContainer.cs b/Subsurface/Items/Components/Power/PowerContainer.cs similarity index 100% rename from Subsurface/Items/Components/PowerContainer.cs rename to Subsurface/Items/Components/Power/PowerContainer.cs diff --git a/Subsurface/Items/Components/PowerTransfer.cs b/Subsurface/Items/Components/Power/PowerTransfer.cs similarity index 87% rename from Subsurface/Items/Components/PowerTransfer.cs rename to Subsurface/Items/Components/Power/PowerTransfer.cs index f8691148f..e8990bc83 100644 --- a/Subsurface/Items/Components/PowerTransfer.cs +++ b/Subsurface/Items/Components/Power/PowerTransfer.cs @@ -49,9 +49,8 @@ namespace Subsurface.Items.Components { pt.powerLoad += (fullLoad - pt.powerLoad) / inertia; pt.currPowerConsumption += (-fullPower - pt.currPowerConsumption) / inertia; - pt.Item.SendSignal( - (fullPower / Math.Max(fullLoad,1.0f)).ToString(CultureInfo.InvariantCulture), - "power_out"); + pt.Item.SendSignal("", + "power", fullPower / Math.Max(fullLoad, 1.0f)); } else @@ -126,9 +125,11 @@ namespace Subsurface.Items.Components public override void DrawHUD(SpriteBatch spriteBatch, Character character) { - int width = 300, height = 200; - int x = Game1.GraphicsWidth / 2 - width / 2; - int y = Game1.GraphicsHeight / 2 - height / 2; + int width = GuiFrame.Rect.Width, height = GuiFrame.Rect.Height; + int x = GuiFrame.Rect.X; + int y = GuiFrame.Rect.Y; + + GuiFrame.Draw(spriteBatch); GUI.DrawRectangle(spriteBatch, new Rectangle(x, y, width, height), Color.Black, true); @@ -136,5 +137,15 @@ namespace Subsurface.Items.Components spriteBatch.DrawString(GUI.font, "Load: " + (int)powerLoad, new Vector2(x + 30, y + 100), Color.White); } + public override void ReceiveSignal(string signal, Connection connection, Item sender, float power) + { + base.ReceiveSignal(signal, connection, sender, power); + + if (connection.name=="signal") + { + connection.SendSignal(signal, item, 0.0f); + } + } + } } diff --git a/Subsurface/Items/Components/Powered.cs b/Subsurface/Items/Components/Power/Powered.cs similarity index 89% rename from Subsurface/Items/Components/Powered.cs rename to Subsurface/Items/Components/Power/Powered.cs index 1546f95a0..219b683f2 100644 --- a/Subsurface/Items/Components/Powered.cs +++ b/Subsurface/Items/Components/Power/Powered.cs @@ -59,15 +59,9 @@ namespace Subsurface.Items.Components set { voltage = Math.Max(0.0f, value); } } - public override void ReceiveSignal(string signal, Connection connection, Item sender) + public override void ReceiveSignal(string signal, Connection connection, Item sender, float power) { - if (connection.name=="power_in") - { - if (!float.TryParse(signal, NumberStyles.Any, CultureInfo.InvariantCulture, out voltage)) - { - voltage = 0.0f; - } - } + if (connection.name=="power_in") voltage = power; } public override void Update(float deltaTime, Camera cam) diff --git a/Subsurface/Items/Components/Signal/AndComponent.cs b/Subsurface/Items/Components/Signal/AndComponent.cs index 97bdc4385..085a4b896 100644 --- a/Subsurface/Items/Components/Signal/AndComponent.cs +++ b/Subsurface/Items/Components/Signal/AndComponent.cs @@ -53,7 +53,7 @@ namespace Subsurface.Items.Components } } - public override void ReceiveSignal(string signal, Connection connection, Item sender) + public override void ReceiveSignal(string signal, Connection connection, Item sender, float power=0.0f) { switch (connection.name) { diff --git a/Subsurface/Items/Components/Signal/Connection.cs b/Subsurface/Items/Components/Signal/Connection.cs index e7b6ef802..40685a15d 100644 --- a/Subsurface/Items/Components/Signal/Connection.cs +++ b/Subsurface/Items/Components/Signal/Connection.cs @@ -135,7 +135,7 @@ namespace Subsurface.Items.Components // return false; //} - public void SendSignal(string signal, Item sender) + public void SendSignal(string signal, Item sender, float power) { for (int i = 0; i(); if (panel == null) return; @@ -650,7 +649,7 @@ namespace Subsurface { if (c.name != connectionName) continue; - c.SendSignal(signal, this); + c.SendSignal(signal, this, power); } } diff --git a/Subsurface/Map/Level.cs b/Subsurface/Map/Level.cs index fd655d3af..a73ed17ef 100644 --- a/Subsurface/Map/Level.cs +++ b/Subsurface/Map/Level.cs @@ -181,10 +181,33 @@ namespace Subsurface cells.Remove(cell); } - //GenerateBodies(cells, pathCells); + for (int x = 0; x < cellGrid.GetLength(0); x++ ) + { + for (int y = 0; y < cellGrid.GetLength(1); y++ ) + { + cellGrid[x, y].Clear(); + } + } + + foreach (VoronoiCell cell in cells) + { + cellGrid[(int)Math.Floor(cell.Center.X / gridCellWidth), (int)Math.Floor(cell.Center.Y / gridCellWidth)].Add(cell); + } GeneratePolygons(cells, pathCells); + foreach (VoronoiCell cell in cells) + { + foreach (GraphEdge edge in cell.edges) + { + edge.cell1 = null; + edge.cell2 = null; + edge.site1 = null; + edge.site2 = null; + } + + } + Debug.WriteLine("Generatelevel: " + sw2.ElapsedMilliseconds + " ms"); sw2.Restart(); @@ -452,6 +475,8 @@ namespace Subsurface VoronoiCell adjacentCell = ge.AdjacentCell(cell); if (!emptyCells.Contains(adjacentCell)) continue; + ge.isSolid = true; + if (!bodyPoints.Contains(ge.point1)) bodyPoints.Add(ge.point1); if (!bodyPoints.Contains(ge.point2)) bodyPoints.Add(ge.point2); } @@ -624,39 +649,101 @@ namespace Subsurface // } //} - int gridPosX = (int)Math.Floor(-observerPosition.X / gridCellWidth); - int gridPosY = (int)Math.Floor(-observerPosition.Y / gridCellWidth); - int searchOffset = 2; + //int gridPosX = (int)Math.Floor(-observerPosition.X / gridCellWidth); + //int gridPosY = (int)Math.Floor(-observerPosition.Y / gridCellWidth); + //int searchOffset = 2; - int startX = Math.Max(gridPosX - searchOffset, 0); - int endX = Math.Min(gridPosX + searchOffset, cellGrid.GetLength(0) - 1); + //int startX = Math.Max(gridPosX - searchOffset, 0); + //int endX = Math.Min(gridPosX + searchOffset, cellGrid.GetLength(0) - 1); - int startY = Math.Max(gridPosY - searchOffset, 0); - int endY = Math.Min(gridPosY + searchOffset, cellGrid.GetLength(1) - 1); + //int startY = Math.Max(gridPosY - searchOffset, 0); + //int endY = Math.Min(gridPosY + searchOffset, cellGrid.GetLength(1) - 1); + + //for (int x = startX; x < endX; x++) + //{ + // for (int y = startY; y < endY; y++) + // { + // GUI.DrawRectangle(spriteBatch, + // new Rectangle(x * gridCellWidth + (int)position.X, borders.Y - borders.Height + y * gridCellWidth - (int)position.Y, gridCellWidth, gridCellWidth), + // Color.Cyan); + // } + //} + + List edges = GetCellEdges(-observerPosition); + + for (int i = 0; i < edges.Count; i++ ) + { + GUI.DrawLine(spriteBatch, edges[i][0], edges[i][1], Color.Green); + } + + //foreach (VoronoiCell cell in cells) + //{ + // for (int i = 0; i < cell.edges.Count; i++) + // { + // Vector2 start = cell.edges[i].point1 + position; + // start.Y = -start.Y; + + // Vector2 end = cell.edges[i].point2 + position; + // end.Y = -end.Y; + + // GUI.DrawLine(spriteBatch, start, end, (cell.body != null && cell.body.Enabled) ? Color.Green : Color.Red); + // } + //} + } + + public List GetCellEdges(Vector2 refPos, int searchDepth = 2, bool onlySolid = true) + { + + int gridPosX = (int)Math.Floor(refPos.X / gridCellWidth); + int gridPosY = (int)Math.Floor(refPos.Y / gridCellWidth); + + int startX = Math.Max(gridPosX - searchDepth, 0); + int endX = Math.Min(gridPosX + searchDepth, cellGrid.GetLength(0) - 1); + + int startY = Math.Max(gridPosY - searchDepth, 0); + int endY = Math.Min(gridPosY + searchDepth, cellGrid.GetLength(1) - 1); + + + List edges = new List(); for (int x = startX; x < endX; x++) { for (int y = startY; y < endY; y++) { - GUI.DrawRectangle(spriteBatch, - new Rectangle(x * gridCellWidth + (int)position.X, borders.Y - borders.Height + y * gridCellWidth - (int)position.Y, gridCellWidth, gridCellWidth), - Color.Cyan); + foreach (VoronoiCell cell in cellGrid[x,y]) + { + for (int i = 0; i < cell.edges.Count; i++) + { + if (onlySolid && !cell.edges[i].isSolid) continue; + Vector2 start = cell.edges[i].point1 + position; + start.Y = -start.Y; + + Vector2 end = cell.edges[i].point2 + position; + end.Y = -end.Y; + + edges.Add(new Vector2[] { start, end }); + //GUI.DrawLine(spriteBatch, start, end, (cell.body != null && cell.body.Enabled) ? Color.Green : Color.Red); + } + } } } - foreach (VoronoiCell cell in cells) - { - for (int i = 0; i HullVertices + { + get; + private set; + } + public Md5Hash Hash { get @@ -401,9 +407,7 @@ namespace Subsurface ApplyForce(-Vector2.Normalize(speed)*drag); } //hullBodies[0].body.LinearVelocity = -hullBodies[0].body.Position; - - - + hullBody.SetTransform(Vector2.Zero , 0.0f); if (collidingCell == null) @@ -697,6 +701,9 @@ namespace Subsurface } List convexHull = GenerateConvexHull(); + + HullVertices = convexHull; + for (int i = 0; i < convexHull.Count; i++) { convexHull[i] = ConvertUnits.ToSimUnits(convexHull[i]); @@ -718,7 +725,7 @@ namespace Subsurface var triangulatedVertices = Triangulate.ConvexPartition(_shapevertices, TriangulationAlgorithm.Bayazit); - Body hullBody = BodyFactory.CreateCompoundPolygon(Game1.world, triangulatedVertices, 5.0f); + hullBody = BodyFactory.CreateCompoundPolygon(Game1.world, triangulatedVertices, 5.0f); hullBody.BodyType = BodyType.Dynamic; hullBody.CollisionCategories = Physics.CollisionMisc; diff --git a/Subsurface/Map/VoronoiElements.cs b/Subsurface/Map/VoronoiElements.cs index e850c4053..b56c81d2d 100644 --- a/Subsurface/Map/VoronoiElements.cs +++ b/Subsurface/Map/VoronoiElements.cs @@ -143,6 +143,8 @@ namespace Voronoi2 public Site site1, site2; public VoronoiCell cell1, cell2; + public bool isSolid; + public VoronoiCell AdjacentCell(VoronoiCell cell) { if (cell1==cell) diff --git a/Subsurface/Subsurface.csproj b/Subsurface/Subsurface.csproj index c66b513c0..69cb96cab 100644 --- a/Subsurface/Subsurface.csproj +++ b/Subsurface/Subsurface.csproj @@ -78,10 +78,11 @@ - - - - + + + + + @@ -89,8 +90,8 @@ - - + + @@ -108,18 +109,18 @@ - + - - - - - - - - - + + + + + + + + + @@ -159,7 +160,7 @@ - + diff --git a/Subsurface/ToolBox.cs b/Subsurface/ToolBox.cs index b7a3e93d9..a97317a92 100644 --- a/Subsurface/ToolBox.cs +++ b/Subsurface/ToolBox.cs @@ -189,7 +189,7 @@ namespace Subsurface if (components.Length!=2) { if (!errorMessages) return vector; - DebugConsole.ThrowError("Failed to parse the string "+stringVector2+" to Vector2"); + DebugConsole.ThrowError("Failed to parse the string ''"+stringVector2+"'' to Vector2"); return vector; } @@ -212,7 +212,7 @@ namespace Subsurface if (components.Length < 3) { - DebugConsole.ThrowError("Failed to parse the string " + stringVector4 + " to Vector4"); + DebugConsole.ThrowError("Failed to parse the string ''" + stringVector4 + "'' to Vector4"); return vector; } diff --git a/Subsurface_Solution.v12.suo b/Subsurface_Solution.v12.suo index fb3481370..221e16c3d 100644 Binary files a/Subsurface_Solution.v12.suo and b/Subsurface_Solution.v12.suo differ