Fixed timestep for some GUI & input code

Fixed timestep only applied to the physics simulation, but input and GUI updates were not being handled properly, so here's some progress into fixing them.
This commit is contained in:
juanjp600
2016-09-18 11:03:52 -03:00
parent 179c0424d7
commit 33641ead3e
14 changed files with 153 additions and 50 deletions

View File

@@ -469,6 +469,8 @@ namespace Barotrauma.Items.Components
//}
public virtual void DrawHUD(SpriteBatch spriteBatch, Character character) { }
public virtual void UpdateHUD(Character character) { }
/// <returns>true if the operation was completed</returns>
public virtual bool AIOperate(float deltaTime, Character character, AIObjectiveOperateItem objective)

View File

@@ -82,10 +82,14 @@ namespace Barotrauma.Items.Components
public override void DrawHUD(SpriteBatch spriteBatch, Character character)
{
GuiFrame.Update((float)Physics.step);
GuiFrame.Draw(spriteBatch);
}
public override void UpdateHUD(Character character)
{
GuiFrame.Update((float)Physics.step);
}
private bool ToggleActive(GUIButton button, object obj)
{
SetActive(!IsActive);

View File

@@ -338,6 +338,11 @@ namespace Barotrauma.Items.Components
}
public override void DrawHUD(SpriteBatch spriteBatch, Character character)
{
GuiFrame.Draw(spriteBatch);
}
public override void UpdateHUD(Character character)
{
FabricableItem targetItem = itemList.SelectedData as FabricableItem;
if (targetItem != null)
@@ -346,7 +351,6 @@ namespace Barotrauma.Items.Components
}
GuiFrame.Update((float)Physics.step);
GuiFrame.Draw(spriteBatch);
}
private bool CanBeFabricated(FabricableItem fabricableItem, Character user)

View File

@@ -156,13 +156,17 @@ namespace Barotrauma.Items.Components
int x = GuiFrame.Rect.X;
int y = GuiFrame.Rect.Y;
GuiFrame.Update(1.0f / 60.0f);
GuiFrame.Draw(spriteBatch);
spriteBatch.DrawString(GUI.Font, "Pumping speed: " + (int)flowPercentage + " %", new Vector2(x + 40, y + 85), Color.White);
}
public override void UpdateHUD(Character character)
{
GuiFrame.Update(1.0f / 60.0f);
}
public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item sender, float power=0.0f)
{
base.ReceiveSignal(stepsTaken, signal, connection, sender, power);

View File

@@ -102,8 +102,6 @@ namespace Barotrauma.Items.Components
public override void DrawHUD(SpriteBatch spriteBatch, Character character)
{
GuiFrame.Update(1.0f / 60.0f);
GuiFrame.Draw(spriteBatch);
if (voltage < minVoltage && powerConsumption > 0.0f) return;
@@ -112,6 +110,11 @@ namespace Barotrauma.Items.Components
DrawRadar(spriteBatch, new Rectangle((int)GuiFrame.Center.X - radius, (int)GuiFrame.Center.Y - radius, radius * 2, radius * 2));
}
public override void UpdateHUD(Character character)
{
GuiFrame.Update(1.0f / 60.0f);
}
private void DrawRadar(SpriteBatch spriteBatch, Rectangle rect)
{
Vector2 center = new Vector2(rect.X + rect.Width*0.5f, rect.Center.Y);

View File

@@ -438,7 +438,6 @@ namespace Barotrauma.Items.Components
int x = GuiFrame.Rect.X;
int y = GuiFrame.Rect.Y;
GuiFrame.Update(1.0f / 60.0f);
GuiFrame.Draw(spriteBatch);
float xOffset = (graphTimer / (float)updateGraphInterval);
@@ -481,6 +480,11 @@ namespace Barotrauma.Items.Components
//y = y - 260;
}
public override void UpdateHUD(Character character)
{
GuiFrame.Update(1.0f / 60.0f);
}
private bool ToggleAutoTemp(GUITickBox tickBox)
{
unsentChanges = true;

View File

@@ -161,7 +161,6 @@ namespace Barotrauma.Items.Components
int x = GuiFrame.Rect.X;
int y = GuiFrame.Rect.Y;
GuiFrame.Update(1.0f / 60.0f);
GuiFrame.Draw(spriteBatch);
if (voltage < minVoltage && powerConsumption > 0.0f) return;
@@ -210,6 +209,11 @@ namespace Barotrauma.Items.Components
}
}
public override void UpdateHUD(Character character)
{
GuiFrame.Update(1.0f / 60.0f);
}
private void UpdateAutoPilot(float deltaTime)
{
if (posToMaintain != null)