Merge remote-tracking branch 'refs/remotes/barotrauma/combat-mission'

Conflicts:
	Subsurface/Source/GUI/GUIListBox.cs
This commit is contained in:
juanjp600
2016-10-04 22:30:29 -03:00
29 changed files with 525 additions and 440 deletions
+1
View File
@@ -168,6 +168,7 @@
<Compile Include="Source\Screens\BlurEffect.cs" /> <Compile Include="Source\Screens\BlurEffect.cs" />
<Compile Include="Source\Screens\NetLobbyVoting.cs" /> <Compile Include="Source\Screens\NetLobbyVoting.cs" />
<Compile Include="Source\Screens\ServerListScreen.cs" /> <Compile Include="Source\Screens\ServerListScreen.cs" />
<Compile Include="Source\Timing.cs" />
<Compile Include="Source\Utils\MTRandom.cs" /> <Compile Include="Source\Utils\MTRandom.cs" />
<Compile Include="Source\Utils\Rand.cs" /> <Compile Include="Source\Utils\Rand.cs" />
<Compile Include="Source\Events\PropertyTask.cs" /> <Compile Include="Source\Events\PropertyTask.cs" />
+2 -2
View File
@@ -127,9 +127,9 @@ namespace Barotrauma
public void UpdateTransform(bool interpolate = true, bool clampPos = false) public void UpdateTransform(bool interpolate = true, bool clampPos = false)
{ {
Vector2 interpolatedPosition = interpolate ? Physics.Interpolate(prevPosition, position) : position; Vector2 interpolatedPosition = interpolate ? Timing.Interpolate(prevPosition, position) : position;
float interpolatedZoom = interpolate ? Physics.Interpolate(prevZoom, zoom) : zoom; float interpolatedZoom = interpolate ? Timing.Interpolate(prevZoom, zoom) : zoom;
worldView.X = (int)(interpolatedPosition.X - worldView.Width / 2.0); worldView.X = (int)(interpolatedPosition.X - worldView.Width / 2.0);
worldView.Y = (int)(interpolatedPosition.Y + worldView.Height / 2.0); worldView.Y = (int)(interpolatedPosition.Y + worldView.Height / 2.0);
+19 -3
View File
@@ -46,6 +46,19 @@ namespace Barotrauma
if (suicideButton != null && suicideButton.Visible) suicideButton.Update(deltaTime); if (suicideButton != null && suicideButton.Visible) suicideButton.Update(deltaTime);
if (damageOverlayTimer > 0.0f) damageOverlayTimer -= deltaTime; if (damageOverlayTimer > 0.0f) damageOverlayTimer -= deltaTime;
if (!character.IsUnconscious && character.Stun <= 0.0f)
{
if (character.Inventory != null && !character.LockHands && character.Stun >= -0.1f)
{
character.Inventory.Update(deltaTime);
}
if (character.SelectedCharacter != null && character.SelectedCharacter.Inventory != null)
{
character.SelectedCharacter.Inventory.Update(deltaTime);
}
}
} }
public static void Draw(SpriteBatch spriteBatch, Character character, Camera cam) public static void Draw(SpriteBatch spriteBatch, Character character, Camera cam)
@@ -84,12 +97,15 @@ namespace Barotrauma
if (!character.IsUnconscious && character.Stun <= 0.0f) if (!character.IsUnconscious && character.Stun <= 0.0f)
{ {
if (character.Inventory != null && !character.LockHands && if (character.Inventory != null && !character.LockHands && character.Stun >= -0.1f)
character.Stun >= -0.1f) character.Inventory.DrawOwn(spriteBatch, Vector2.Zero); {
character.Inventory.DrawOwn(spriteBatch);
}
if (character.SelectedCharacter != null && character.SelectedCharacter.Inventory != null) if (character.SelectedCharacter != null && character.SelectedCharacter.Inventory != null)
{ {
character.SelectedCharacter.Inventory.DrawOwn(spriteBatch, new Vector2(320.0f, 0.0f)); character.SelectedCharacter.Inventory.DrawOffset = new Vector2(320.0f, 0.0f);
character.SelectedCharacter.Inventory.DrawOwn(spriteBatch);
if (cprButton == null) if (cprButton == null)
{ {
+2 -2
View File
@@ -472,12 +472,12 @@ namespace Barotrauma
{ {
if (pauseMenuOpen) if (pauseMenuOpen)
{ {
pauseMenu.Update(0.016f); pauseMenu.Update(deltaTime);
} }
if (settingsMenuOpen) if (settingsMenuOpen)
{ {
GameMain.Config.SettingsFrame.Update(0.016f); GameMain.Config.SettingsFrame.Update(deltaTime);
} }
if (GUIMessageBox.MessageBoxes.Count > 0) if (GUIMessageBox.MessageBoxes.Count > 0)
+30
View File
@@ -287,6 +287,36 @@ namespace Barotrauma
{ {
scrollBar.BarScroll -= (PlayerInput.ScrollWheelSpeed / 500.0f) * BarSize; scrollBar.BarScroll -= (PlayerInput.ScrollWheelSpeed / 500.0f) * BarSize;
} }
for (int i = 0; i < children.Count; i++)
{
GUIComponent child = children[i];
if (child == frame || !child.Visible) continue;
if (enabled && child.CanBeFocused &&
(MouseOn == this || (MouseOn != null && this.IsParentOf(MouseOn))) && child.Rect.Contains(PlayerInput.MousePosition))
{
child.State = ComponentState.Hover;
if (PlayerInput.LeftButtonClicked())
{
Debug.WriteLine("clicked");
Select(i);
}
}
else if (selected.Contains(child))
{
child.State = ComponentState.Selected;
if (CheckSelected != null)
{
if (CheckSelected() != child.UserData) selected.Remove(child);
}
}
else
{
child.State = ComponentState.None;
}
}
} }
public void Select(int childIndex, bool force = false) public void Select(int childIndex, bool force = false)
+18 -19
View File
@@ -217,6 +217,24 @@ namespace Barotrauma
if (flashTimer > 0.0f) flashTimer -= deltaTime; if (flashTimer > 0.0f) flashTimer -= deltaTime;
if (!Enabled) return; if (!Enabled) return;
if (rect.Contains(PlayerInput.MousePosition) && Enabled &&
(MouseOn == null || MouseOn == this || IsParentOf(MouseOn) || MouseOn.IsParentOf(this)))
{
state = ComponentState.Hover;
if (PlayerInput.LeftButtonClicked())
{
Select();
if (OnSelected != null) OnSelected(this, Keys.None);
}
}
else
{
state = ComponentState.None;
}
textBlock.State = state;
if (CaretEnabled) if (CaretEnabled)
{ {
caretTimer += deltaTime; caretTimer += deltaTime;
@@ -248,24 +266,6 @@ namespace Barotrauma
{ {
if (!Visible) return; if (!Visible) return;
if (rect.Contains(PlayerInput.MousePosition) && Enabled &&
(MouseOn == null || MouseOn == this || IsParentOf(MouseOn) || MouseOn.IsParentOf(this)))
{
state = ComponentState.Hover;
if (PlayerInput.LeftButtonClicked())
{
Select();
if (OnSelected != null) OnSelected(this, Keys.None);
}
}
else
{
state = ComponentState.None;
}
textBlock.State = state;
DrawChildren(spriteBatch); DrawChildren(spriteBatch);
if (!CaretEnabled) return; if (!CaretEnabled) return;
@@ -279,7 +279,6 @@ namespace Barotrauma
new Vector2((int)caretPos.X + 2, caretPos.Y + Font.MeasureString("I").Y - 3), new Vector2((int)caretPos.X + 2, caretPos.Y + Font.MeasureString("I").Y - 3),
textBlock.TextColor * (textBlock.TextColor.A / 255.0f)); textBlock.TextColor * (textBlock.TextColor.A / 255.0f));
} }
} }
public void ReceiveTextInput(char inputChar) public void ReceiveTextInput(char inputChar)
+7 -3
View File
@@ -127,9 +127,13 @@ namespace Barotrauma
} }
} }
spriteBatch.DrawString(GUI.LargeFont, loadText, if (GUI.LargeFont!=null)
new Vector2(GameMain.GraphicsWidth/2.0f - GUI.LargeFont.MeasureString(loadText).X/2.0f, GameMain.GraphicsHeight*0.8f), {
Color.White); spriteBatch.DrawString(GUI.LargeFont, loadText,
new Vector2(GameMain.GraphicsWidth/2.0f - GUI.LargeFont.MeasureString(loadText).X/2.0f, GameMain.GraphicsHeight*0.8f),
Color.White);
}
} }
spriteBatch.End(); spriteBatch.End();
+25 -31
View File
@@ -72,7 +72,6 @@ namespace Barotrauma
private bool hasLoaded; private bool hasLoaded;
private GameTime fixedTime; private GameTime fixedTime;
private double updatesToMake;
//public static Random localRandom; //public static Random localRandom;
//public static Random random; //public static Random random;
@@ -142,7 +141,7 @@ namespace Barotrauma
IsFixedTimeStep = false; IsFixedTimeStep = false;
//TargetElapsedTime = new TimeSpan(0, 0, 0, 0, 55); //TargetElapsedTime = new TimeSpan(0, 0, 0, 0, 55);
updatesToMake = 0.0; Timing.Accumulator = 0.0f;
fixedTime = new GameTime(); fixedTime = new GameTime();
World = new World(new Vector2(0, -9.82f)); World = new World(new Vector2(0, -9.82f));
@@ -291,11 +290,9 @@ namespace Barotrauma
/// <param name="gameTime">Provides a snapshot of timing values.</param> /// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Update(GameTime gameTime) protected override void Update(GameTime gameTime)
{ {
double realDeltaTime = gameTime.ElapsedGameTime.TotalSeconds; Timing.Accumulator += gameTime.ElapsedGameTime.TotalSeconds;
double deltaTime = 0.016;
updatesToMake += realDeltaTime;
while (updatesToMake > 0.0) while (Timing.Accumulator >= Timing.Step)
{ {
fixedTime.IsRunningSlowly = gameTime.IsRunningSlowly; fixedTime.IsRunningSlowly = gameTime.IsRunningSlowly;
TimeSpan addTime = new TimeSpan(0, 0, 0, 0, 16); TimeSpan addTime = new TimeSpan(0, 0, 0, 0, 16);
@@ -303,39 +300,49 @@ namespace Barotrauma
fixedTime.TotalGameTime.Add(addTime); fixedTime.TotalGameTime.Add(addTime);
base.Update(fixedTime); base.Update(fixedTime);
PlayerInput.Update(deltaTime); PlayerInput.Update(Timing.Step);
bool paused = false; bool paused = false;
if (hasLoaded && !titleScreenOpen) if (titleScreenOpen)
{
if (TitleScreen.LoadState >= 100.0f &&
(!waitForKeyHit || PlayerInput.GetKeyboardState.GetPressedKeys().Length>0 || PlayerInput.LeftButtonClicked()))
{
titleScreenOpen = false;
}
}
else if (hasLoaded)
{ {
SoundPlayer.Update(); SoundPlayer.Update();
if (PlayerInput.KeyHit(Keys.Escape)) GUI.TogglePauseMenu(); if (PlayerInput.KeyHit(Keys.Escape)) GUI.TogglePauseMenu();
DebugConsole.Update(this, (float)deltaTime); DebugConsole.Update(this, (float)Timing.Step);
paused = (DebugConsole.IsOpen || GUI.PauseMenuOpen || GUI.SettingsMenuOpen) && paused = (DebugConsole.IsOpen || GUI.PauseMenuOpen || GUI.SettingsMenuOpen) &&
(NetworkMember == null || !NetworkMember.GameStarted); (NetworkMember == null || !NetworkMember.GameStarted);
if (!paused) Screen.Selected.Update(deltaTime); if (!paused)
{
Screen.Selected.Update(Timing.Step);
}
if (NetworkMember != null) if (NetworkMember != null)
{ {
NetworkMember.Update((float)deltaTime); NetworkMember.Update((float)Timing.Step);
}
else
{
NetworkEvent.Events.Clear();
} }
GUI.Update((float)deltaTime); GUI.Update((float)Timing.Step);
} }
CoroutineManager.Update((float)deltaTime, paused ? 0.0f : (float)deltaTime);
updatesToMake -= deltaTime; CoroutineManager.Update((float)Timing.Step, paused ? 0.0f : (float)Timing.Step);
Timing.Accumulator -= Timing.Step;
} }
Timing.Alpha = Timing.Accumulator / Timing.Step;
} }
@@ -344,8 +351,6 @@ namespace Barotrauma
/// </summary> /// </summary>
protected override void Draw(GameTime gameTime) protected override void Draw(GameTime gameTime)
{ {
//renderTimer.Restart();
double deltaTime = gameTime.ElapsedGameTime.TotalSeconds; double deltaTime = gameTime.ElapsedGameTime.TotalSeconds;
FrameCounter.Update(deltaTime); FrameCounter.Update(deltaTime);
@@ -353,22 +358,11 @@ namespace Barotrauma
if (titleScreenOpen) if (titleScreenOpen)
{ {
TitleScreen.Draw(spriteBatch, GraphicsDevice, (float)deltaTime); TitleScreen.Draw(spriteBatch, GraphicsDevice, (float)deltaTime);
if (TitleScreen.LoadState>=100.0f &&
(!waitForKeyHit || PlayerInput.GetKeyboardState.GetPressedKeys().Length>0 || PlayerInput.LeftButtonClicked()))
{
titleScreenOpen = false;
}
} }
else if (hasLoaded) else if (hasLoaded)
{ {
Screen.Selected.Draw(deltaTime, GraphicsDevice, spriteBatch); Screen.Selected.Draw(deltaTime, GraphicsDevice, spriteBatch);
} }
//double elapsed = sw.Elapsed.TotalSeconds;
//if (elapsed < Physics.step)
//{
// System.Threading.Thread.Sleep((int)((Physics.step - elapsed) * 1000.0));
//}
} }
static bool waitForKeyHit = true; static bool waitForKeyHit = true;
+2 -6
View File
@@ -317,19 +317,15 @@ namespace Barotrauma
if (gameMode != null) gameMode.Update(deltaTime); if (gameMode != null) gameMode.Update(deltaTime);
if (Mission != null) Mission.Update(deltaTime); if (Mission != null) Mission.Update(deltaTime);
if (infoFrame != null) infoFrame.Update(deltaTime);
} }
public void Draw(SpriteBatch spriteBatch) public void Draw(SpriteBatch spriteBatch)
{ {
//guiRoot.Draw(spriteBatch);
infoButton.Draw(spriteBatch); infoButton.Draw(spriteBatch);
if (gameMode != null) gameMode.Draw(spriteBatch); if (gameMode != null) gameMode.Draw(spriteBatch);
if (infoFrame != null) if (infoFrame != null) infoFrame.Draw(spriteBatch);
{
infoFrame.Update(0.016f);
infoFrame.Draw(spriteBatch);
}
} }
public void Save(string filePath) public void Save(string filePath)
+112 -139
View File
@@ -279,10 +279,41 @@ namespace Barotrauma
return TryPutItem(item, new List<InvSlotType>() {placeToSlots}, createNetworkEvent); return TryPutItem(item, new List<InvSlotType>() {placeToSlots}, createNetworkEvent);
} }
public void DrawOwn(SpriteBatch spriteBatch, Vector2 offset) protected override void PutItem(Item item, int i, bool createNetworkEvent, bool removeItem = true)
{ {
string toolTip = ""; base.PutItem(item, i, createNetworkEvent, removeItem);
Rectangle highlightedSlot = Rectangle.Empty; CreateSlots();
}
public override void RemoveItem(Item item)
{
base.RemoveItem(item);
CreateSlots();
}
protected override void CreateSlots()
{
slots = new InventorySlot[capacity];
int rectWidth = 40, rectHeight = 40;
Rectangle slotRect = new Rectangle(0, 0, rectWidth, rectHeight);
for (int i = 0; i < capacity; i++)
{
slotRect.X = (int)(SlotPositions[i].X + DrawOffset.X);
slotRect.Y = (int)(SlotPositions[i].Y + DrawOffset.Y);
slots[i] = new InventorySlot(slotRect);
slots[i].Color = limbSlots[i] == InvSlotType.Any ? Color.White * 0.2f : Color.White * 0.4f;
}
MergeSlots();
}
public override void Update(float deltaTime)
{
base.Update(deltaTime);
if (doubleClickedItem != null) if (doubleClickedItem != null)
{ {
@@ -320,16 +351,76 @@ namespace Barotrauma
} }
} }
doubleClickedItem = null; if (selectedSlot > -1)
{
UpdateSubInventory(deltaTime, selectedSlot);
}
const int rectWidth = 40, rectHeight = 40; if (character == Character.Controlled)
Rectangle slotRect = new Rectangle(0, 0, rectWidth, rectHeight); {
Rectangle draggingItemSlot = slotRect; for (int i = 0; i < capacity; i++)
{
if (selectedSlot != i &&
Items[i] != null && Items[i].CanUseOnSelf && character.HasSelectedItem(Items[i]))
{
//-3 because selected items are in slots 3 and 4 (hands)
useOnSelfButton[i - 3].Update(deltaTime);
}
}
}
//cancel dragging if too far away from the container of the dragged item
if (draggingItem != null)
{
var rootContainer = draggingItem.GetRootContainer();
var rootInventory = draggingItem.ParentInventory;
if (rootContainer != null)
{
rootInventory = rootContainer.ParentInventory != null ?
rootContainer.ParentInventory : rootContainer.GetComponent<Items.Components.ItemContainer>().Inventory;
}
if (rootInventory != null &&
rootInventory.Owner != Character.Controlled &&
rootInventory.Owner != Character.Controlled.SelectedConstruction &&
rootInventory.Owner != Character.Controlled.SelectedCharacter)
{
draggingItem = null;
}
}
doubleClickedItem = null;
}
private void MergeSlots()
{
for (int i = 0; i < capacity-1; i++)
{
if (slots[i].Disabled || Items[i] == null) continue;
for (int n = i+1; n < capacity; n++)
{
if (Items[n] == Items[i])
{
slots[i].Rect = Rectangle.Union(slots[i].Rect, slots[n].Rect);
slots[n].Disabled = true;
}
}
}
}
public void DrawOwn(SpriteBatch spriteBatch)
{
if (slots == null) CreateSlots();
Rectangle slotRect = new Rectangle(0, 0, 40, 40);
for (int i = 0; i < capacity; i++) for (int i = 0; i < capacity; i++)
{ {
slotRect.X = (int)(SlotPositions[i].X + offset.X); slotRect.X = (int)(SlotPositions[i].X + DrawOffset.X);
slotRect.Y = (int)(SlotPositions[i].Y + offset.Y); slotRect.Y = (int)(SlotPositions[i].Y + DrawOffset.Y);
if (i==1) //head if (i==1) //head
{ {
@@ -354,147 +445,29 @@ namespace Barotrauma
} }
} }
for (int i = 0; i < capacity; i++) base.Draw(spriteBatch);
if (character == Character.Controlled)
{ {
slotRect.X = (int)(SlotPositions[i].X + offset.X); for (int i = 0; i < capacity; i++)
slotRect.Y = (int)(SlotPositions[i].Y + offset.Y);
bool multiSlot = false;
//skip if the item is in multiple slots
if (Items[i]!=null)
{ {
for (int n = 0; n < capacity; n++ ) if (selectedSlot != i &&
Items[i] != null && Items[i].CanUseOnSelf && character.HasSelectedItem(Items[i]))
{ {
if (i==n || Items[n] != Items[i]) continue; useOnSelfButton[i - 3].Draw(spriteBatch);
multiSlot = true;
break;
} }
} }
if (multiSlot) continue;
if (Items[i] != null && slotRect.Contains(PlayerInput.MousePosition) && (selectedSlot == -1 || selectedSlot == i))
{
if (GameMain.DebugDraw)
{
toolTip = Items[i].ToString();
}
else
{
toolTip = string.IsNullOrEmpty(Items[i].Description) ? Items[i].Name : Items[i].Name + '\n' + Items[i].Description;
}
highlightedSlot = slotRect;
}
if (selectedSlot == i) highlightedSlot = slotRect;
UpdateSlot(spriteBatch, slotRect, i, Items[i], false, i>5 ? 0.2f : 0.4f);
if (draggingItem!=null && draggingItem == Items[i]) draggingItemSlot = slotRect;
}
for (int i = 0; i < capacity; i++)
{
bool multiSlot = false;
//check if the item is in multiple slots
if (Items[i] != null)
{
slotRect.X = (int)(SlotPositions[i].X + offset.X);
slotRect.Y = (int)(SlotPositions[i].Y + offset.Y);
slotRect.Width = 40;
slotRect.Height = 40;
for (int n = 0; n < capacity; n++)
{
if (Items[n] != Items[i]) continue;
if (!multiSlot && i > n) break;
if (i!=n)
{
multiSlot = true;
slotRect = Rectangle.Union(
new Rectangle((int)(SlotPositions[n].X+offset.X), (int)(SlotPositions[n].Y+offset.Y), rectWidth, rectHeight), slotRect);
}
}
}
if (multiSlot)
{
if (Items[i] != null && slotRect.Contains(PlayerInput.MousePosition) && (selectedSlot==-1 || selectedSlot==i))
{
toolTip = string.IsNullOrEmpty(Items[i].Description) ? Items[i].Name : Items[i].Name + '\n' + Items[i].Description;
highlightedSlot = slotRect;
}
if (selectedSlot == i) highlightedSlot = slotRect;
UpdateSlot(spriteBatch, slotRect, i, Items[i], i > 4);
}
if (character==Character.Controlled && selectedSlot != i &&
Items[i] != null && Items[i].CanUseOnSelf && character.HasSelectedItem(Items[i]))
{
useOnSelfButton[i - 3].Update(0.016f);
useOnSelfButton[i - 3].Draw(spriteBatch);
}
} }
if (selectedSlot > -1) if (selectedSlot > -1)
{ {
DrawSubInventory(spriteBatch, highlightedSlot, selectedSlot); DrawSubInventory(spriteBatch, selectedSlot);
}
slotRect.Width = rectWidth; if (selectedSlot > -1 &&
slotRect.Height = rectHeight; !slots[selectedSlot].IsHighlighted &&
(draggingItem == null || draggingItem.Container != Items[selectedSlot]))
if (!string.IsNullOrWhiteSpace(toolTip))
{
DrawToolTip(spriteBatch, toolTip, highlightedSlot);
}
if (draggingItem == null) return;
var rootContainer = draggingItem.GetRootContainer();
var rootInventory = draggingItem.ParentInventory;
if (rootContainer != null)
{
rootInventory = rootContainer.ParentInventory != null ?
rootContainer.ParentInventory : rootContainer.GetComponent<Items.Components.ItemContainer>().Inventory;
}
if (rootInventory != null &&
rootInventory.Owner != Character.Controlled &&
rootInventory.Owner != Character.Controlled.SelectedConstruction &&
rootInventory.Owner != Character.Controlled.SelectedCharacter)
{
draggingItem = null;
return;
}
if (!draggingItemSlot.Contains(PlayerInput.MousePosition))
{
if (PlayerInput.LeftButtonHeld())
{ {
slotRect.X = (int)PlayerInput.MousePosition.X - slotRect.Width / 2; selectedSlot = -1;
slotRect.Y = (int)PlayerInput.MousePosition.Y - slotRect.Height / 2;
DrawSlot(spriteBatch, slotRect, draggingItem, false, false);
}
else
{
DropItem(draggingItem);
new NetworkEvent(NetworkEventType.DropItem, draggingItem.ID, true);
//draggingItem = null;
} }
} }
} }
@@ -214,10 +214,13 @@ namespace Barotrauma.Items.Components
} }
} }
public override void UpdateHUD(Character character)
{
Inventory.Update((float)Timing.Step);
}
public override void DrawHUD(SpriteBatch spriteBatch, Character character) public override void DrawHUD(SpriteBatch spriteBatch, Character character)
{ {
if (!drawInventory && false) return;
Inventory.Draw(spriteBatch); Inventory.Draw(spriteBatch);
} }
@@ -87,7 +87,7 @@ namespace Barotrauma.Items.Components
public override void UpdateHUD(Character character) public override void UpdateHUD(Character character)
{ {
GuiFrame.Update((float)Physics.step); GuiFrame.Update((float)Timing.Step);
} }
private bool ToggleActive(GUIButton button, object obj) private bool ToggleActive(GUIButton button, object obj)
@@ -350,7 +350,7 @@ namespace Barotrauma.Items.Components
activateButton.Enabled = CanBeFabricated(targetItem, character); activateButton.Enabled = CanBeFabricated(targetItem, character);
} }
GuiFrame.Update((float)Physics.step); GuiFrame.Update((float)Timing.Step);
} }
private bool CanBeFabricated(FabricableItem fabricableItem, Character user) private bool CanBeFabricated(FabricableItem fabricableItem, Character user)
+1 -1
View File
@@ -366,7 +366,7 @@ namespace Barotrauma.Items.Components
break; break;
case "trigger_in": case "trigger_in":
item.Use((float)Physics.step, null); item.Use((float)Timing.Step, null);
break; break;
} }
} }
+1 -1
View File
@@ -202,7 +202,7 @@ namespace Barotrauma
if (frame == null) return; if (frame == null) return;
frame.Update((float)Physics.step); frame.Update((float)Timing.Step);
} }
} }
} }
+171 -103
View File
@@ -6,12 +6,43 @@ using Microsoft.Xna.Framework.Input;
using Barotrauma.Networking; using Barotrauma.Networking;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Barotrauma.Items.Components;
namespace Barotrauma namespace Barotrauma
{ {
class InventorySlot
{
public Rectangle Rect;
public GUIComponent.ComponentState State;
public bool Disabled;
public bool IsHighlighted
{
get
{
return State == GUIComponent.ComponentState.Hover;
}
}
public Color Color;
public InventorySlot(Rectangle rect)
{
Rect = rect;
State = GUIComponent.ComponentState.None;
Color = Color.White * 0.4f;
}
}
class Inventory class Inventory
{ {
public static InventorySlot draggingSlot;
public static Item draggingItem; public static Item draggingItem;
public static Item doubleClickedItem; public static Item doubleClickedItem;
public readonly Entity Owner; public readonly Entity Owner;
@@ -31,6 +62,8 @@ namespace Barotrauma
protected int selectedSlot = -1; protected int selectedSlot = -1;
protected InventorySlot[] slots;
public Item[] Items; public Item[] Items;
public bool Locked; public bool Locked;
@@ -46,6 +79,23 @@ namespace Barotrauma
} }
} }
private Vector2 drawOffset;
public Vector2 DrawOffset
{
get
{
return drawOffset;
}
set
{
if (value == drawOffset) return;
drawOffset = value;
CreateSlots();
}
}
public Inventory(Entity owner, int capacity, Vector2? centerPos = null, int slotsPerRow=5) public Inventory(Entity owner, int capacity, Vector2? centerPos = null, int slotsPerRow=5)
{ {
this.capacity = capacity; this.capacity = capacity;
@@ -116,7 +166,7 @@ namespace Barotrauma
} }
} }
protected void PutItem(Item item, int i, bool createNetworkEvent, bool removeItem = true) protected virtual void PutItem(Item item, int i, bool createNetworkEvent, bool removeItem = true)
{ {
if (Owner == null) return; if (Owner == null) return;
@@ -143,7 +193,7 @@ namespace Barotrauma
return Items.FirstOrDefault(i => i != null && (i.Name == itemName || i.HasTag(itemName))); return Items.FirstOrDefault(i => i != null && (i.Name == itemName || i.HasTag(itemName)));
} }
public void RemoveItem(Item item) public virtual void RemoveItem(Item item)
{ {
if (item == null) return; if (item == null) return;
@@ -161,19 +211,12 @@ namespace Barotrauma
item.Drop(null, false); item.Drop(null, false);
return; return;
} }
//public void DropItem(int i)
//{
// items[i].Drop();
// items[i] = null;
//}
public virtual void Draw(SpriteBatch spriteBatch) protected virtual void CreateSlots()
{ {
string toolTip = ""; slots = new InventorySlot[capacity];
int rectWidth = 40, rectHeight = 40; int rectWidth = 40, rectHeight = 40;
Rectangle highlightedSlot = Rectangle.Empty;
int spacing = 10; int spacing = 10;
int rows = (int)Math.Ceiling((double)capacity / slotsPerRow); int rows = (int)Math.Ceiling((double)capacity / slotsPerRow);
@@ -182,51 +225,76 @@ namespace Barotrauma
int startY = (int)centerPos.Y - rows * (spacing + rectHeight); int startY = (int)centerPos.Y - rows * (spacing + rectHeight);
Rectangle slotRect = new Rectangle(startX, startY, rectWidth, rectHeight); Rectangle slotRect = new Rectangle(startX, startY, rectWidth, rectHeight);
Rectangle draggingItemSlot = slotRect; for (int i = 0; i < capacity; i++)
{
slotRect.X = startX + (rectWidth + spacing) * (i % slotsPerRow) + (int)DrawOffset.X;
slotRect.Y = startY + (rectHeight + spacing) * ((int)Math.Floor((double)i / slotsPerRow)) + (int)DrawOffset.Y;
selectedSlot = -1; slots[i] = new InventorySlot(slotRect);
}
}
public virtual void Update(float deltaTime)
{
if (slots == null) CreateSlots();
for (int i = 0; i < capacity; i++) for (int i = 0; i < capacity; i++)
{ {
slotRect.X = startX + (rectWidth + spacing) * (i % slotsPerRow); if (slots[i].Disabled) continue;
slotRect.Y = startY + (rectHeight + spacing) * ((int)Math.Floor((double)i / slotsPerRow)); UpdateSlot(slots[i], i, Items[i], false);
if (draggingItem == Items[i]) draggingItemSlot = slotRect;
UpdateSlot(spriteBatch, slotRect, i, Items[i], false);
if (slotRect.Contains(PlayerInput.MousePosition) && Items[i] != null)
{
highlightedSlot = slotRect;
toolTip = GameMain.DebugDraw ? Items[i].ToString() : Items[i].Name;
}
} }
if (draggingItem != null && !draggingItemSlot.Contains(PlayerInput.MousePosition) && draggingItem.Container == this.Owner)
{
if (PlayerInput.LeftButtonHeld())
{
slotRect.X = (int)PlayerInput.MousePosition.X - slotRect.Width / 2;
slotRect.Y = (int)PlayerInput.MousePosition.Y - slotRect.Height / 2;
//GUI.DrawRectangle(spriteBatch, rect, Color.White, true);
//draggingItem.sprite.Draw(spriteBatch, new Vector2(rect.X + rect.Width / 2, rect.Y + rect.Height / 2), Color.White);
DrawSlot(spriteBatch, slotRect, draggingItem, false, false); if (draggingItem != null && !draggingSlot.Rect.Contains(PlayerInput.MousePosition) && draggingItem.ParentInventory == this)
} {
else if (!PlayerInput.LeftButtonHeld())
{ {
if (Owner!=null) if (Owner != null)
{ {
new NetworkEvent(NetworkEventType.InventoryUpdate, Owner.ID, true); new NetworkEvent(NetworkEventType.InventoryUpdate, Owner.ID, true);
} }
DropItem(draggingItem); DropItem(draggingItem);
//draggingItem = null;
} }
} }
if (!string.IsNullOrWhiteSpace(toolTip)) }
public virtual void Draw(SpriteBatch spriteBatch)
{
string toolTip = "";
if (slots == null) CreateSlots();
for (int i = 0; i < capacity; i++)
{ {
DrawToolTip(spriteBatch, toolTip, highlightedSlot); if (slots[i].Disabled) continue;
//don't draw the slot if dragged an item out of it
bool drawItem = draggingItem == null || draggingItem != Items[i] || slots[i].IsHighlighted;
DrawSlot(spriteBatch, slots[i], Items[i], drawItem);
}
if (draggingItem != null &&
!draggingSlot.Rect.Contains(PlayerInput.MousePosition) &&
draggingItem.ParentInventory == this)
{
Rectangle dragRect = new Rectangle(
(int)PlayerInput.MousePosition.X - 10,
(int)PlayerInput.MousePosition.Y - 10,
40, 40);
DrawSlot(spriteBatch, new InventorySlot(dragRect), draggingItem);
}
for (int i = 0; i < capacity; i++)
{
if (slots[i].IsHighlighted && !slots[i].Disabled)
{
DrawToolTip(spriteBatch, toolTip, slots[i].Rect);
break;
}
} }
} }
@@ -251,12 +319,21 @@ namespace Barotrauma
1.0f, SpriteEffects.None, 0.0f); 1.0f, SpriteEffects.None, 0.0f);
} }
protected void UpdateSlot(SpriteBatch spriteBatch, Rectangle rect, int slotIndex, Item item, bool isSubSlot, float alpha = 0.4f, bool drawItem=true) protected void UpdateSlot(InventorySlot slot, int slotIndex, Item item, bool isSubSlot)
{ {
bool mouseOn = rect.Contains(PlayerInput.MousePosition) && !Locked; bool mouseOn = slot.Rect.Contains(PlayerInput.MousePosition) && !Locked;
if (mouseOn) slot.State = GUIComponent.ComponentState.None;
if (!(this is CharacterInventory) && !mouseOn && selectedSlot==slotIndex)
{ {
selectedSlot = -1;
}
if (mouseOn &&
(draggingItem!=null || selectedSlot==slotIndex || selectedSlot==-1))
{
slot.State = GUIComponent.ComponentState.Hover;
if (!isSubSlot && selectedSlot == -1) if (!isSubSlot && selectedSlot == -1)
{ {
@@ -265,9 +342,10 @@ namespace Barotrauma
if (draggingItem == null) if (draggingItem == null)
{ {
if (PlayerInput.LeftButtonHeld() && selectedSlot == slotIndex) if (PlayerInput.LeftButtonHeld())
{ {
draggingItem = item; draggingItem = Items[slotIndex];
draggingSlot = slot;
} }
} }
else if (PlayerInput.LeftButtonReleased()) else if (PlayerInput.LeftButtonReleased())
@@ -280,22 +358,38 @@ namespace Barotrauma
//selectedSlot = slotIndex; //selectedSlot = slotIndex;
TryPutItem(draggingItem, slotIndex, true, true); TryPutItem(draggingItem, slotIndex, true, true);
draggingItem = null; draggingItem = null;
draggingSlot = null;
} }
} }
DrawSlot(spriteBatch, rect, (draggingItem == item && !mouseOn) ? null : item, mouseOn && selectedSlot == slotIndex, isSubSlot, alpha, drawItem);
} }
public void DrawSubInventory(SpriteBatch spriteBatch, Rectangle rect, int slotIndex) public void UpdateSubInventory(float deltaTime, int slotIndex)
{ {
var item = Items[slotIndex]; var item = Items[slotIndex];
if (item == null) return;
selectedSlot = -1; var container = item.GetComponent<ItemContainer>();
if (container == null) return;
int itemCapacity = item == null ? 0 : item.Capacity; if (container.Inventory.slots == null) container.Inventory.CreateSlots();
if (itemCapacity == 0) return;
slots[slotIndex].State = GUIComponent.ComponentState.Hover;
container.Inventory.Update(deltaTime);
}
public void DrawSubInventory(SpriteBatch spriteBatch, int slotIndex)
{
var item = Items[slotIndex];
if (item == null) return;
var container = item.GetComponent<ItemContainer>();
if (container == null) return;
if (container.Inventory.slots == null) container.Inventory.CreateSlots();
int itemCapacity = container.Capacity;
#if DEBUG #if DEBUG
System.Diagnostics.Debug.Assert(slotIndex >= 0 && slotIndex < Items.Length); System.Diagnostics.Debug.Assert(slotIndex >= 0 && slotIndex < Items.Length);
@@ -303,59 +397,37 @@ namespace Barotrauma
if (slotIndex < 0 || slotIndex >= Items.Length) return; if (slotIndex < 0 || slotIndex >= Items.Length) return;
#endif #endif
Rectangle containerRect = new Rectangle(rect.X - 5, rect.Y - (40 + 10) * itemCapacity - 5, var slot = slots[slotIndex];
rect.Width + 10, rect.Height + (40 + 10) * itemCapacity + 10); Rectangle containerRect = new Rectangle(slot.Rect.X - 5, slot.Rect.Y - (40 + 10) * itemCapacity - 5,
slot.Rect.Width + 10, slot.Rect.Height + (40 + 10) * itemCapacity + 10);
Rectangle subRect = rect; Rectangle subRect = slot.Rect;
subRect.Height = 40; subRect.Height = 40;
selectedSlot = containerRect.Contains(PlayerInput.MousePosition) && !Locked ? slotIndex : -1; GUI.DrawRectangle(spriteBatch, new Rectangle(containerRect.X, containerRect.Y, containerRect.Width, containerRect.Height - slot.Rect.Height - 5), Color.Black * 0.8f, true);
GUI.DrawRectangle(spriteBatch, new Rectangle(containerRect.X, containerRect.Y, containerRect.Width, containerRect.Height - 50), Color.Black * 0.8f, true);
GUI.DrawRectangle(spriteBatch, containerRect, Color.White); GUI.DrawRectangle(spriteBatch, containerRect, Color.White);
Item[] containedItems = null; for (int i = 0; i < itemCapacity; i++)
if (Items[slotIndex] != null) containedItems = Items[slotIndex].ContainedItems;
string toolTip = "";
Rectangle highlightedRect = Rectangle.Empty;
if (containedItems != null)
{ {
for (int i = 0; i < itemCapacity; i++) subRect.Y = subRect.Y - subRect.Height - 10;
{ container.Inventory.slots[i].Rect = subRect;
subRect.Y = subRect.Y - subRect.Height - 10;
highlightedRect = subRect;
UpdateSlot(spriteBatch, subRect, selectedSlot, i < containedItems.Length ? containedItems[i] : null, true);
if (i >= containedItems.Length || containedItems[i] == null) continue;
if (highlightedRect.Contains(PlayerInput.MousePosition))
{
if (GameMain.DebugDraw)
{
toolTip = containedItems[i].ToString();
}
else
{
toolTip = string.IsNullOrEmpty(containedItems[i].Description) ?
containedItems[i].Name :
containedItems[i].Name + '\n' + containedItems[i].Description;
}
}
}
} }
if (!string.IsNullOrWhiteSpace(toolTip)) DrawToolTip(spriteBatch, toolTip, highlightedRect); container.Inventory.Draw(spriteBatch);
if (!containerRect.Contains(PlayerInput.MousePosition))
{
if (draggingItem == null || draggingItem.Container != item) selectedSlot = -1;
}
} }
protected void DrawSlot(SpriteBatch spriteBatch, Rectangle rect, Item item, bool isHighLighted, bool isSubSlot, float alpha=0.4f, bool drawItem=true) protected void DrawSlot(SpriteBatch spriteBatch, InventorySlot slot, Item item, bool drawItem=true)
{ {
GUI.DrawRectangle(spriteBatch, rect, (isHighLighted ? Color.Red : Color.White) * alpha*0.75f, true); Rectangle rect = slot.Rect;
if (item != null) GUI.DrawRectangle(spriteBatch, rect, (slot.IsHighlighted ? Color.Red * 0.4f : slot.Color), true);
if (item != null && drawItem)
{ {
if (item.Condition < 100.0f) if (item.Condition < 100.0f)
{ {
@@ -365,21 +437,17 @@ namespace Barotrauma
Color.Lerp(Color.Red, Color.Green, item.Condition / 100.0f)*0.8f, true); Color.Lerp(Color.Red, Color.Green, item.Condition / 100.0f)*0.8f, true);
} }
if (!isHighLighted) var containedItems = item.ContainedItems;
if (containedItems != null && containedItems.Length == 1 && containedItems[0].Condition < 100.0f)
{ {
var containedItems = item.ContainedItems; GUI.DrawRectangle(spriteBatch, new Rectangle(rect.X, rect.Y, rect.Width, 8), Color.Black*0.8f, true);
if (containedItems != null && containedItems.Length == 1 && containedItems[0].Condition < 100.0f) GUI.DrawRectangle(spriteBatch,
{ new Rectangle(rect.X, rect.Y, (int)(rect.Width * containedItems[0].Condition / 100.0f), 8),
GUI.DrawRectangle(spriteBatch, new Rectangle(rect.X, rect.Y, rect.Width, 8), Color.Black*0.8f, true); Color.Lerp(Color.Red, Color.Green, containedItems[0].Condition / 100.0f)*0.8f, true);
GUI.DrawRectangle(spriteBatch,
new Rectangle(rect.X, rect.Y, (int)(rect.Width * containedItems[0].Condition / 100.0f), 8),
Color.Lerp(Color.Red, Color.Green, containedItems[0].Condition / 100.0f)*0.8f, true);
}
} }
} }
GUI.DrawRectangle(spriteBatch, rect, (slot.IsHighlighted ? Color.Red * 0.4f : slot.Color), false);
GUI.DrawRectangle(spriteBatch, rect, (isHighLighted ? Color.Red : Color.White) * alpha, false);
if (item == null || !drawItem) return; if (item == null || !drawItem) return;
+2 -2
View File
@@ -923,7 +923,7 @@ namespace Barotrauma
} }
editingHUD.Draw(spriteBatch); editingHUD.Draw(spriteBatch);
editingHUD.Update((float)Physics.step); editingHUD.Update((float)Timing.Step);
if (!prefab.IsLinkable) return; if (!prefab.IsLinkable) return;
@@ -951,7 +951,7 @@ namespace Barotrauma
if (editingHUD.Rect.Height > 60) if (editingHUD.Rect.Height > 60)
{ {
editingHUD.Update((float)Physics.step); editingHUD.Update((float)Timing.Step);
editingHUD.Draw(spriteBatch); editingHUD.Draw(spriteBatch);
} }
} }
+1 -1
View File
@@ -156,8 +156,8 @@ namespace Barotrauma
editingHUD = CreateEditingHUD(); editingHUD = CreateEditingHUD();
} }
editingHUD.Update(0.016f);
editingHUD.Draw(spriteBatch); editingHUD.Draw(spriteBatch);
editingHUD.Update((float)Physics.step);
if (!PlayerInput.LeftButtonClicked() || !PlayerInput.KeyDown(Keys.Space)) return; if (!PlayerInput.LeftButtonClicked() || !PlayerInput.KeyDown(Keys.Space)) return;
+17 -10
View File
@@ -254,20 +254,18 @@ namespace Barotrauma
currentLocation.Discovered = true; currentLocation.Discovered = true;
} }
public void Draw(SpriteBatch spriteBatch, Rectangle rect, float scale = 1.0f) public void Update(float deltaTime, Rectangle rect, float scale = 1.0f)
{ {
Vector2 rectCenter = new Vector2(rect.Center.X, rect.Center.Y); Vector2 rectCenter = new Vector2(rect.Center.X, rect.Center.Y);
Vector2 offset = -currentLocation.MapPosition; Vector2 offset = -currentLocation.MapPosition;
iceTexture.DrawTiled(spriteBatch, new Vector2(rect.X, rect.Y), new Vector2(rect.Width, rect.Height), Vector2.Zero, Color.White*0.8f);
float maxDist = 20.0f; float maxDist = 20.0f;
float closestDist = 0.0f; float closestDist = 0.0f;
highlightedLocation = null; highlightedLocation = null;
for (int i = 0; i < locations.Count;i++ ) for (int i = 0; i < locations.Count; i++)
{ {
Location location = locations[i]; Location location = locations[i];
Vector2 pos = rectCenter + (location.MapPosition+offset) * scale; Vector2 pos = rectCenter + (location.MapPosition + offset) * scale;
if (!rect.Contains(pos)) continue; if (!rect.Contains(pos)) continue;
@@ -281,14 +279,10 @@ namespace Barotrauma
foreach (LocationConnection connection in connections) foreach (LocationConnection connection in connections)
{ {
Color crackColor = Color.White * Math.Max(connection.Difficulty/100.0f, 1.5f);
if (highlightedLocation != currentLocation && if (highlightedLocation != currentLocation &&
connection.Locations.Contains(highlightedLocation) && connection.Locations.Contains(currentLocation)) connection.Locations.Contains(highlightedLocation) && connection.Locations.Contains(currentLocation))
{ {
crackColor = Color.Red; if (PlayerInput.LeftButtonClicked() &&
if (PlayerInput.LeftButtonClicked()&&
selectedLocation != highlightedLocation && highlightedLocation != null) selectedLocation != highlightedLocation && highlightedLocation != null)
{ {
selectedConnection = connection; selectedConnection = connection;
@@ -296,6 +290,19 @@ namespace Barotrauma
GameMain.LobbyScreen.SelectLocation(highlightedLocation, connection); GameMain.LobbyScreen.SelectLocation(highlightedLocation, connection);
} }
} }
}
}
public void Draw(SpriteBatch spriteBatch, Rectangle rect, float scale = 1.0f)
{
Vector2 rectCenter = new Vector2(rect.Center.X, rect.Center.Y);
Vector2 offset = -currentLocation.MapPosition;
iceTexture.DrawTiled(spriteBatch, new Vector2(rect.X, rect.Y), new Vector2(rect.Width, rect.Height), Vector2.Zero, Color.White*0.8f);
foreach (LocationConnection connection in connections)
{
Color crackColor = Color.White * Math.Max(connection.Difficulty/100.0f, 1.5f);
if (selectedLocation != currentLocation && if (selectedLocation != currentLocation &&
(connection.Locations.Contains(selectedLocation) && connection.Locations.Contains(currentLocation))) (connection.Locations.Contains(selectedLocation) && connection.Locations.Contains(currentLocation)))
+1 -1
View File
@@ -323,7 +323,7 @@ namespace Barotrauma
public void UpdateTransform() public void UpdateTransform()
{ {
DrawPosition = Physics.Interpolate(prevPosition, Position); DrawPosition = Timing.Interpolate(prevPosition, Position);
} }
//math/physics stuff ---------------------------------------------------- //math/physics stuff ----------------------------------------------------
+1 -1
View File
@@ -178,7 +178,7 @@ namespace Barotrauma
editingHUD = CreateEditingHUD(); editingHUD = CreateEditingHUD();
} }
editingHUD.Update((float)Physics.step); editingHUD.Update((float)Timing.Step);
editingHUD.Draw(spriteBatch); editingHUD.Draw(spriteBatch);
if (!PlayerInput.LeftButtonClicked()) return; if (!PlayerInput.LeftButtonClicked()) return;
+2 -3
View File
@@ -284,6 +284,8 @@ namespace Barotrauma.Networking
{ {
if (ShowNetStats) netStats.Update(deltaTime); if (ShowNetStats) netStats.Update(deltaTime);
if (settingsFrame != null) settingsFrame.Update(deltaTime); if (settingsFrame != null) settingsFrame.Update(deltaTime);
if (log.LogFrame != null) log.LogFrame.Update(deltaTime);
if (!started) return; if (!started) return;
@@ -302,8 +304,6 @@ namespace Barotrauma.Networking
if (gameStarted) if (gameStarted)
{ {
//inGameHUD.Update((float)Physics.step);
if (respawnManager != null) respawnManager.Update(deltaTime); if (respawnManager != null) respawnManager.Update(deltaTime);
bool isCrewDead = bool isCrewDead =
@@ -1336,7 +1336,6 @@ namespace Barotrauma.Networking
} }
else if (log.LogFrame!=null) else if (log.LogFrame!=null)
{ {
log.LogFrame.Update(0.016f);
log.LogFrame.Draw(spriteBatch); log.LogFrame.Draw(spriteBatch);
} }
+2 -2
View File
@@ -301,8 +301,8 @@ namespace Barotrauma.Particles
public void UpdateDrawPos() public void UpdateDrawPos()
{ {
drawPosition = Physics.Interpolate(prevPosition, position); drawPosition = Timing.Interpolate(prevPosition, position);
drawRotation = Physics.Interpolate(prevRotation, rotation); drawRotation = Timing.Interpolate(prevRotation, rotation);
prevPosition = position; prevPosition = position;
prevRotation = rotation; prevRotation = rotation;
-27
View File
@@ -20,33 +20,6 @@ namespace Barotrauma
public static float DisplayToRealWorldRatio = 1.0f / 80.0f; public static float DisplayToRealWorldRatio = 1.0f / 80.0f;
public static double accumulator;
public static double step = 1.0/60.0;
public const float DisplayToSimRation = 100.0f; public const float DisplayToSimRation = 100.0f;
public static double Alpha
{
get { return alpha; }
set { alpha = Math.Min(Math.Max(value, 0.0), 1.0); }
}
public static double Interpolate(double previous, double current)
{
return current * alpha + previous * (1.0 - alpha);
}
public static float Interpolate(float previous, float current)
{
return current * (float)alpha + previous * (1.0f - (float)alpha);
}
public static Vector2 Interpolate(Vector2 previous, Vector2 current)
{
return new Vector2(
Interpolate(previous.X, current.X),
Interpolate(previous.Y, current.Y));
}
} }
} }
+3 -3
View File
@@ -330,10 +330,10 @@ namespace Barotrauma
public void UpdateDrawPosition() public void UpdateDrawPosition()
{ {
drawPosition = Physics.Interpolate(prevPosition, body.Position) - offsetFromTargetPos; drawPosition = Timing.Interpolate(prevPosition, body.Position) - offsetFromTargetPos;
drawPosition = ConvertUnits.ToDisplayUnits(drawPosition); drawPosition = ConvertUnits.ToDisplayUnits(drawPosition);
drawRotation = Physics.Interpolate(prevRotation, body.Rotation); drawRotation = Timing.Interpolate(prevRotation, body.Rotation);
if (offsetFromTargetPos == Vector2.Zero) return; if (offsetFromTargetPos == Vector2.Zero) return;
@@ -370,7 +370,7 @@ namespace Barotrauma
/// </summary> /// </summary>
public void SmoothRotate(float targetRotation, float force = 10.0f) public void SmoothRotate(float targetRotation, float force = 10.0f)
{ {
float nextAngle = body.Rotation + body.AngularVelocity * (float)Physics.step; float nextAngle = body.Rotation + body.AngularVelocity * (float)Timing.Step;
float angle = MathUtils.GetShortestAngle(nextAngle, targetRotation); float angle = MathUtils.GetShortestAngle(nextAngle, targetRotation);
@@ -98,26 +98,15 @@ namespace Barotrauma
/// <param name="gameTime">Provides a snapshot of timing values.</param> /// <param name="gameTime">Provides a snapshot of timing values.</param>
public override void Update(double deltaTime) public override void Update(double deltaTime)
{ {
Physics.accumulator += deltaTime;
//cam.Zoom += Math.Sign(PlayerInput.GetMouseState.ScrollWheelValue - PlayerInput.GetOldMouseState.ScrollWheelValue)*0.1f;
cam.MoveCamera((float)deltaTime); cam.MoveCamera((float)deltaTime);
if (physicsEnabled) if (physicsEnabled)
{ {
Physics.accumulator = Math.Min(Physics.accumulator, Physics.step * 4); Character.UpdateAnimAll((float)deltaTime);
while (Physics.accumulator >= Physics.step)
{
Character.UpdateAnimAll((float)Physics.step * 1000.0f);
Ragdoll.UpdateAll(cam, (float)Physics.step); Ragdoll.UpdateAll(cam, (float)deltaTime);
GameMain.World.Step((float)Physics.step); GameMain.World.Step((float)deltaTime);
Physics.accumulator -= Physics.step;
}
Physics.Alpha = Physics.accumulator / Physics.step;
} }
} }
+37 -49
View File
@@ -91,9 +91,6 @@ namespace Barotrauma
/// <param name="gameTime">Provides a snapshot of timing values.</param> /// <param name="gameTime">Provides a snapshot of timing values.</param>
public override void Update(double deltaTime) public override void Update(double deltaTime)
{ {
//the accumulator code is based on this article:
//http://gafferongames.com/game-physics/fix-your-timestep/
Physics.accumulator += deltaTime;
#if DEBUG #if DEBUG
if (GameMain.GameSession != null && GameMain.GameSession.Level != null && GameMain.GameSession.Submarine != null) if (GameMain.GameSession != null && GameMain.GameSession.Level != null && GameMain.GameSession.Submarine != null)
@@ -112,8 +109,6 @@ namespace Barotrauma
if (Level.Loaded != null) Level.Loaded.Update((float)deltaTime); if (Level.Loaded != null) Level.Loaded.Update((float)deltaTime);
Character.UpdateAll(cam, (float)deltaTime);
if (Character.Controlled != null && Character.Controlled.SelectedConstruction != null) if (Character.Controlled != null && Character.Controlled.SelectedConstruction != null)
{ {
if (Character.Controlled.SelectedConstruction == Character.Controlled.ClosestItem) if (Character.Controlled.SelectedConstruction == Character.Controlled.ClosestItem)
@@ -121,54 +116,49 @@ namespace Barotrauma
Character.Controlled.SelectedConstruction.UpdateHUD(Character.Controlled); Character.Controlled.SelectedConstruction.UpdateHUD(Character.Controlled);
} }
} }
Character.UpdateAll(cam, (float)deltaTime);
Physics.accumulator = Math.Min(Physics.accumulator, Physics.step * 6); BackgroundCreatureManager.Update(cam, (float)deltaTime);
//Physics.accumulator = Physics.step;
while (Physics.accumulator >= Physics.step) GameMain.ParticleManager.Update((float)deltaTime);
StatusEffect.UpdateAll((float)deltaTime);
if (Character.Controlled != null && Lights.LightManager.ViewTarget != null)
{ {
BackgroundCreatureManager.Update(cam, (float)Physics.step); cam.TargetPos = Lights.LightManager.ViewTarget.WorldPosition;
}
cam.MoveCamera((float)deltaTime);
GameMain.ParticleManager.Update((float)Physics.step); foreach (Submarine sub in Submarine.Loaded)
{
StatusEffect.UpdateAll((float)Physics.step); sub.SetPrevTransform(sub.Position);
if (Character.Controlled != null && Lights.LightManager.ViewTarget != null)
{
cam.TargetPos = Lights.LightManager.ViewTarget.WorldPosition;
//Lights.LightManager.ViewPos = Character.Controlled.WorldPosition;
}
cam.MoveCamera((float)Physics.step);
foreach (Submarine sub in Submarine.Loaded)
{
sub.SetPrevTransform(sub.Position);
}
foreach (PhysicsBody pb in PhysicsBody.list)
{
pb.SetPrevTransform(pb.SimPosition, pb.Rotation);
}
MapEntity.UpdateAll(cam, (float)Physics.step);
Character.UpdateAnimAll((float)Physics.step);
Ragdoll.UpdateAll(cam, (float)Physics.step);
foreach (Submarine sub in Submarine.Loaded)
{
sub.Update((float)Physics.step);
}
GameMain.World.Step((float)Physics.step);
//Level.AfterWorldStep();
Physics.accumulator -= Physics.step;
} }
foreach (PhysicsBody pb in PhysicsBody.list)
{
pb.SetPrevTransform(pb.SimPosition, pb.Rotation);
}
Physics.Alpha = Physics.accumulator / Physics.step; MapEntity.UpdateAll(cam, (float)deltaTime);
Character.UpdateAnimAll((float)deltaTime);
Ragdoll.UpdateAll(cam, (float)deltaTime);
foreach (Submarine sub in Submarine.Loaded)
{
sub.Update((float)deltaTime);
}
GameMain.World.Step((float)deltaTime);
if (!PlayerInput.LeftButtonHeld())
{
Inventory.draggingSlot = null;
Inventory.draggingItem = null;
}
} }
@@ -207,8 +197,6 @@ namespace Barotrauma
GUI.Draw((float)deltaTime, spriteBatch, cam); GUI.Draw((float)deltaTime, spriteBatch, cam);
if (!PlayerInput.LeftButtonHeld()) Inventory.draggingItem = null;
spriteBatch.End(); spriteBatch.End();
} }
+6 -1
View File
@@ -350,7 +350,12 @@ namespace Barotrauma
mapZoom += PlayerInput.ScrollWheelSpeed / 1000.0f; mapZoom += PlayerInput.ScrollWheelSpeed / 1000.0f;
mapZoom = MathHelper.Clamp(mapZoom, 1.0f, 4.0f); mapZoom = MathHelper.Clamp(mapZoom, 1.0f, 4.0f);
//shiftPanel.Update((float)deltaTime);
GameMain.GameSession.Map.Update((float)deltaTime, new Rectangle(
bottomPanel[selectedRightPanel].Rect.X + 20,
bottomPanel[selectedRightPanel].Rect.Y + 20,
bottomPanel[selectedRightPanel].Rect.Width - 310,
bottomPanel[selectedRightPanel].Rect.Height - 40), mapZoom);
} }
public override void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch) public override void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch)
+40
View File
@@ -0,0 +1,40 @@
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Barotrauma
{
static class Timing
{
private static double alpha;
public static double Accumulator;
public static double Step = 1.0 / 60.0;
public static double Alpha
{
get { return alpha; }
set { alpha = Math.Min(Math.Max(value, 0.0), 1.0); }
}
public static double Interpolate(double previous, double current)
{
return current * alpha + previous * (1.0 - alpha);
}
public static float Interpolate(float previous, float current)
{
return current * (float)alpha + previous * (1.0f - (float)alpha);
}
public static Vector2 Interpolate(Vector2 previous, Vector2 current)
{
return new Vector2(
Interpolate(previous.X, current.X),
Interpolate(previous.Y, current.Y));
}
}
}