Merged branch new-netcode into new-netcode

This commit is contained in:
juanjp600
2016-10-08 19:14:52 -03:00
27 changed files with 550 additions and 474 deletions
+1
View File
@@ -165,6 +165,7 @@
<Compile Include="Source\Screens\BlurEffect.cs" />
<Compile Include="Source\Screens\NetLobbyVoting.cs" />
<Compile Include="Source\Screens\ServerListScreen.cs" />
<Compile Include="Source\Timing.cs" />
<Compile Include="Source\Utils\MTRandom.cs" />
<Compile Include="Source\Utils\Rand.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)
{
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.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 (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)
@@ -84,12 +97,15 @@ namespace Barotrauma
if (!character.IsUnconscious && character.Stun <= 0.0f)
{
if (character.Inventory != null && !character.LockHands &&
character.Stun >= -0.1f) character.Inventory.DrawOwn(spriteBatch, Vector2.Zero);
if (character.Inventory != null && !character.LockHands && character.Stun >= -0.1f)
{
character.Inventory.DrawOwn(spriteBatch);
}
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)
{
+30 -30
View File
@@ -197,6 +197,36 @@ namespace Barotrauma
{
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)
@@ -359,36 +389,6 @@ namespace Barotrauma
}
}
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);
//selected = child;
//if (OnSelected != null)
//{
// if (!OnSelected(selected, child.UserData)) selected = null;
//}
}
}
else if (selected.Contains(child))
{
child.State = ComponentState.Selected;
if (CheckSelected != null)
{
if (CheckSelected() != child.UserData) selected.Remove(child);
}
}
else
{
child.State = ComponentState.None;
}
child.Draw(spriteBatch);
}
+18 -19
View File
@@ -217,6 +217,24 @@ namespace Barotrauma
if (flashTimer > 0.0f) flashTimer -= deltaTime;
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)
{
caretTimer += deltaTime;
@@ -248,24 +266,6 @@ namespace Barotrauma
{
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);
if (!CaretEnabled) return;
@@ -279,7 +279,6 @@ namespace Barotrauma
new Vector2((int)caretPos.X + 2, caretPos.Y + Font.MeasureString("I").Y - 3),
textBlock.TextColor * (textBlock.TextColor.A / 255.0f));
}
}
public void ReceiveTextInput(char inputChar)
+7 -3
View File
@@ -127,9 +127,13 @@ namespace Barotrauma
}
}
spriteBatch.DrawString(GUI.LargeFont, loadText,
new Vector2(GameMain.GraphicsWidth/2.0f - GUI.LargeFont.MeasureString(loadText).X/2.0f, GameMain.GraphicsHeight*0.8f),
Color.White);
if (GUI.LargeFont!=null)
{
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();
+12 -17
View File
@@ -72,7 +72,6 @@ namespace Barotrauma
private bool hasLoaded;
private GameTime fixedTime;
private double updatesToMake;
//public static Random localRandom;
//public static Random random;
@@ -145,7 +144,7 @@ namespace Barotrauma
IsFixedTimeStep = false;
//TargetElapsedTime = new TimeSpan(0, 0, 0, 0, 55);
updatesToMake = 0.0;
Timing.Accumulator = 0.0f;
fixedTime = new GameTime();
World = new World(new Vector2(0, -9.82f));
@@ -293,12 +292,10 @@ namespace Barotrauma
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Update(GameTime gameTime)
{
double realDeltaTime = gameTime.ElapsedGameTime.TotalSeconds;
double deltaTime = 0.016;
updatesToMake += realDeltaTime;
Timing.Accumulator += gameTime.ElapsedGameTime.TotalSeconds;
PlayerInput.UpdateVariable();
while (updatesToMake > 0.0)
while (Timing.Accumulator >= Timing.Step)
{
fixedTime.IsRunningSlowly = gameTime.IsRunningSlowly;
TimeSpan addTime = new TimeSpan(0,0,0,0,16);
@@ -306,7 +303,7 @@ namespace Barotrauma
fixedTime.TotalGameTime.Add(addTime);
base.Update(fixedTime);
PlayerInput.Update(deltaTime);
PlayerInput.Update(Timing.Step);
bool paused = false;
@@ -320,32 +317,30 @@ namespace Barotrauma
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) &&
(NetworkMember == null || !NetworkMember.GameStarted);
if (!paused)
{
Screen.Selected.Update(deltaTime);
Screen.Selected.Update(Timing.Step);
}
if (NetworkMember != null)
{
NetworkMember.Update((float)deltaTime);
}
else
{
NetworkMember.Update((float)Timing.Step);
}
GUI.Update((float)deltaTime);
GUI.Update((float)Timing.Step);
}
CoroutineManager.Update((float)deltaTime, paused ? 0.0f : (float)deltaTime);
CoroutineManager.Update((float)Timing.Step, paused ? 0.0f : (float)Timing.Step);
updatesToMake -= deltaTime;
Timing.Accumulator -= Timing.Step;
}
Timing.Alpha = Timing.Accumulator / Timing.Step;
}
+115 -141
View File
@@ -277,12 +277,43 @@ namespace Barotrauma
return TryPutItem(item, new List<InvSlotType>() {placeToSlots});
}
public void DrawOwn(SpriteBatch spriteBatch, Vector2 offset)
{
string toolTip = "";
Rectangle highlightedSlot = Rectangle.Empty;
protected override void PutItem(Item item, int i, bool removeItem = true)
{
base.PutItem(item, i, removeItem);
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.ParentInventory != this)
@@ -308,7 +339,7 @@ namespace Barotrauma
//not equipped -> attempt to equip
if (IsInLimbSlot(doubleClickedItem, InvSlotType.Any))
{
TryPutItem(doubleClickedItem, doubleClickedItem.AllowedSlots.FindAll(i => i != InvSlotType.Any));
TryPutItem(doubleClickedItem, doubleClickedItem.AllowedSlots.FindAll(i => i != InvSlotType.Any));
}
//equipped -> attempt to unequip
else if (doubleClickedItem.AllowedSlots.Contains(InvSlotType.Any))
@@ -318,17 +349,77 @@ namespace Barotrauma
}
}
}
if (selectedSlot > -1)
{
UpdateSubInventory(deltaTime, selectedSlot);
}
if (character == Character.Controlled)
{
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;
}
const int rectWidth = 40, rectHeight = 40;
Rectangle slotRect = new Rectangle(0, 0, rectWidth, rectHeight);
Rectangle draggingItemSlot = slotRect;
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++)
{
slotRect.X = (int)(SlotPositions[i].X + offset.X);
slotRect.Y = (int)(SlotPositions[i].Y + offset.Y);
slotRect.X = (int)(SlotPositions[i].X + DrawOffset.X);
slotRect.Y = (int)(SlotPositions[i].Y + DrawOffset.Y);
if (i==1) //head
{
@@ -352,148 +443,31 @@ namespace Barotrauma
SpriteEffects.None, 0.1f);
}
}
base.Draw(spriteBatch);
for (int i = 0; i < capacity; i++)
if (character == Character.Controlled)
{
slotRect.X = (int)(SlotPositions[i].X + offset.X);
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 (i==n || Items[n] != Items[i]) continue;
multiSlot = true;
break;
}
}
if (multiSlot) continue;
if (Items[i] != null && slotRect.Contains(PlayerInput.MousePosition) && (selectedSlot == -1 || selectedSlot == i))
for (int i = 0; i < capacity; i++)
{
if (GameMain.DebugDraw)
if (selectedSlot != i &&
Items[i] != null && Items[i].CanUseOnSelf && character.HasSelectedItem(Items[i]))
{
toolTip = Items[i].ToString();
useOnSelfButton[i - 3].Draw(spriteBatch);
}
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)
{
DrawSubInventory(spriteBatch, highlightedSlot, selectedSlot);
}
DrawSubInventory(spriteBatch, selectedSlot);
slotRect.Width = rectWidth;
slotRect.Height = rectHeight;
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())
if (selectedSlot > -1 &&
!slots[selectedSlot].IsHighlighted &&
(draggingItem == null || draggingItem.Container != Items[selectedSlot]))
{
slotRect.X = (int)PlayerInput.MousePosition.X - slotRect.Width / 2;
slotRect.Y = (int)PlayerInput.MousePosition.Y - slotRect.Height / 2;
DrawSlot(spriteBatch, slotRect, draggingItem, false, false);
}
else
{
DropItem(draggingItem);
//draggingItem = null;
}
selectedSlot = -1;
}
}
}
@@ -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)
{
if (!drawInventory && false) return;
Inventory.Draw(spriteBatch);
}
@@ -87,7 +87,7 @@ namespace Barotrauma.Items.Components
public override void UpdateHUD(Character character)
{
GuiFrame.Update((float)Physics.step);
GuiFrame.Update((float)Timing.Step);
}
private bool ToggleActive(GUIButton button, object obj)
@@ -350,7 +350,7 @@ namespace Barotrauma.Items.Components
activateButton.Enabled = CanBeFabricated(targetItem, character);
}
GuiFrame.Update((float)Physics.step);
GuiFrame.Update((float)Timing.Step);
}
private bool CanBeFabricated(FabricableItem fabricableItem, Character user)
+1 -1
View File
@@ -366,7 +366,7 @@ namespace Barotrauma.Items.Components
break;
case "trigger_in":
item.Use((float)Physics.step, null);
item.Use((float)Timing.Step, null);
break;
}
}
+2 -2
View File
@@ -190,7 +190,7 @@ namespace Barotrauma
frame.Draw(spriteBatch);
}
public static void UpdateHud(Item item,Character character)
public static void UpdateHud(Item item, Character character)
{
if (frame == null || frame.UserData != item)
{
@@ -200,7 +200,7 @@ namespace Barotrauma
if (frame == null) return;
frame.Update((float)Physics.step);
frame.Update((float)Timing.Step);
}
}
}
+174 -106
View File
@@ -6,12 +6,43 @@ using Microsoft.Xna.Framework.Input;
using Barotrauma.Networking;
using System;
using System.Collections.Generic;
using Barotrauma.Items.Components;
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
{
public static InventorySlot draggingSlot;
public static Item draggingItem;
public static Item doubleClickedItem;
public readonly Entity Owner;
@@ -31,6 +62,8 @@ namespace Barotrauma
protected int selectedSlot = -1;
protected InventorySlot[] slots;
public Item[] Items;
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)
{
this.capacity = capacity;
@@ -116,7 +166,7 @@ namespace Barotrauma
}
}
protected void PutItem(Item item, int i, bool removeItem = true)
protected virtual void PutItem(Item item, int i, bool removeItem = true)
{
if (Owner == null) return;
@@ -141,7 +191,7 @@ namespace Barotrauma
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;
@@ -159,72 +209,90 @@ namespace Barotrauma
item.Drop(null);
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;
Rectangle highlightedSlot = Rectangle.Empty;
int spacing = 10;
int rows = (int)Math.Ceiling((double)capacity / slotsPerRow);
int startX = (int)centerPos.X - (rectWidth * slotsPerRow + spacing * (slotsPerRow - 1)) / 2;
int startY = (int)centerPos.Y - rows * (spacing + 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++)
{
slotRect.X = startX + (rectWidth + spacing) * (i % slotsPerRow);
slotRect.Y = startY + (rectHeight + spacing) * ((int)Math.Floor((double)i / slotsPerRow));
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 (slots[i].Disabled) continue;
UpdateSlot(slots[i], i, Items[i], false);
}
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);
}
else
if (draggingItem != null &&
(draggingSlot == null || (!draggingSlot.Rect.Contains(PlayerInput.MousePosition) && draggingItem.ParentInventory == this)))
{
if (!PlayerInput.LeftButtonHeld())
{
if (Owner!=null)
if (Owner != null)
{
}
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 == 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;
}
}
}
@@ -249,12 +317,21 @@ namespace Barotrauma
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)
{
@@ -263,9 +340,10 @@ namespace Barotrauma
if (draggingItem == null)
{
if (PlayerInput.LeftButtonHeld() && selectedSlot == slotIndex)
if (PlayerInput.LeftButtonHeld())
{
draggingItem = item;
draggingItem = Items[slotIndex];
draggingSlot = slot;
}
}
else if (PlayerInput.LeftButtonReleased())
@@ -278,22 +356,38 @@ namespace Barotrauma
//selectedSlot = slotIndex;
TryPutItem(draggingItem, slotIndex, true);
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];
if (item == null) return;
selectedSlot = -1;
var container = item.GetComponent<ItemContainer>();
if (container == null) return;
int itemCapacity = item == null ? 0 : item.Capacity;
if (itemCapacity == 0) return;
if (container.Inventory.slots == null) container.Inventory.CreateSlots();
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
System.Diagnostics.Debug.Assert(slotIndex >= 0 && slotIndex < Items.Length);
@@ -301,59 +395,37 @@ namespace Barotrauma
if (slotIndex < 0 || slotIndex >= Items.Length) return;
#endif
Rectangle containerRect = new Rectangle(rect.X - 5, rect.Y - (40 + 10) * itemCapacity - 5,
rect.Width + 10, rect.Height + (40 + 10) * itemCapacity + 10);
var slot = slots[slotIndex];
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;
selectedSlot = containerRect.Contains(PlayerInput.MousePosition) && !Locked ? slotIndex : -1;
GUI.DrawRectangle(spriteBatch, new Rectangle(containerRect.X, containerRect.Y, containerRect.Width, containerRect.Height - 50), Color.Black * 0.8f, true);
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, containerRect, Color.White);
Item[] containedItems = null;
if (Items[slotIndex] != null) containedItems = Items[slotIndex].ContainedItems;
string toolTip = "";
Rectangle highlightedRect = Rectangle.Empty;
if (containedItems != null)
for (int i = 0; i < itemCapacity; i++)
{
for (int i = 0; i < itemCapacity; i++)
{
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;
}
}
}
subRect.Y = subRect.Y - subRect.Height - 10;
container.Inventory.slots[i].Rect = subRect;
}
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;
GUI.DrawRectangle(spriteBatch, rect, (slot.IsHighlighted ? Color.Red * 0.4f : slot.Color), true);
if (item != null)
if (item != null && drawItem)
{
if (item.Condition < 100.0f)
{
@@ -363,21 +435,17 @@ namespace Barotrauma
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;
if (containedItems != null && containedItems.Length == 1 && containedItems[0].Condition < 100.0f)
{
GUI.DrawRectangle(spriteBatch, new Rectangle(rect.X, rect.Y, rect.Width, 8), Color.Black*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, new Rectangle(rect.X, rect.Y, rect.Width, 8), Color.Black*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, (isHighLighted ? Color.Red : Color.White) * alpha, false);
GUI.DrawRectangle(spriteBatch, rect, (slot.IsHighlighted ? Color.Red * 0.4f : slot.Color), false);
if (item == null || !drawItem) return;
+2 -2
View File
@@ -901,7 +901,7 @@ namespace Barotrauma
}
editingHUD.Draw(spriteBatch);
editingHUD.Update((float)Physics.step);
editingHUD.Update((float)Timing.Step);
if (!prefab.IsLinkable) return;
@@ -929,7 +929,7 @@ namespace Barotrauma
if (editingHUD.Rect.Height > 60)
{
editingHUD.Update((float)Physics.step);
editingHUD.Update((float)Timing.Step);
editingHUD.Draw(spriteBatch);
}
}
+1 -1
View File
@@ -148,8 +148,8 @@ namespace Barotrauma
editingHUD = CreateEditingHUD();
}
editingHUD.Update(0.016f);
editingHUD.Draw(spriteBatch);
editingHUD.Update((float)Physics.step);
if (!PlayerInput.LeftButtonClicked() || !PlayerInput.KeyDown(Keys.Space)) return;
+20 -19
View File
@@ -217,26 +217,18 @@ namespace Barotrauma
}
private Location highlightedLocation;
public void Draw(SpriteBatch spriteBatch, Rectangle rect, float scale = 1.0f)
public void Update(float deltaTime, Rectangle rect, float scale = 1.0f)
{
//GUI.DrawRectangle(spriteBatch, rect, Color.DarkBlue, true);
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);
GUI.DrawRectangle(spriteBatch, rect, Color.White);
//spriteBatch.Draw(iceTexture, offset, rect, null, null, 0f, null, Color.White, SpriteEffects.None, 0.0f);
//Vector2 scale = new Vector2((float)rect.Width/ size, (float)rect.Height/size);
float maxDist = 20.0f;
float closestDist = 0.0f;
highlightedLocation = null;
for (int i = 0; i < locations.Count;i++ )
for (int i = 0; i < locations.Count; i++)
{
Location location = locations[i];
Vector2 pos = rectCenter + (location.MapPosition+offset) * scale;
Vector2 pos = rectCenter + (location.MapPosition + offset) * scale;
if (!rect.Contains(pos)) continue;
@@ -251,21 +243,30 @@ namespace Barotrauma
foreach (LocationConnection connection in connections)
{
Color crackColor = Color.White * Math.Max(connection.Difficulty/100.0f, 0.5f);
if (highlightedLocation != currentLocation &&
connection.Locations.Contains(highlightedLocation) && connection.Locations.Contains(currentLocation))
{
crackColor = Color.Red;
if (PlayerInput.LeftButtonClicked()&&
if (PlayerInput.LeftButtonClicked() &&
selectedLocation != highlightedLocation && highlightedLocation != null)
{
selectedConnection = connection;
selectedLocation = highlightedLocation;
GameMain.LobbyScreen.SelectLocation(highlightedLocation, connection);
}
selectedLocation = highlightedLocation;
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 &&
+1 -1
View File
@@ -325,7 +325,7 @@ namespace Barotrauma
public void UpdateTransform()
{
DrawPosition = Physics.Interpolate(prevPosition, Position);
DrawPosition = Timing.Interpolate(prevPosition, Position);
}
//math/physics stuff ----------------------------------------------------
+1 -1
View File
@@ -178,7 +178,7 @@ namespace Barotrauma
editingHUD = CreateEditingHUD();
}
editingHUD.Update((float)Physics.step);
editingHUD.Update((float)Timing.Step);
editingHUD.Draw(spriteBatch);
if (!PlayerInput.LeftButtonClicked()) return;
+44 -24
View File
@@ -303,7 +303,7 @@ namespace Barotrauma.Networking
if (gameStarted)
{
inGameHUD.Update((float)Physics.step);
inGameHUD.Update((float)Timing.Step);
if (respawnManager != null) respawnManager.Update(deltaTime);
@@ -788,28 +788,31 @@ namespace Barotrauma.Networking
{
GameMain.NetLobbyScreen.StartButton.Enabled = false;
NetOutgoingMessage msg = server.CreateMessage();
msg.Write((byte)ServerPacketHeader.QUERY_STARTGAME);
msg.Write(selectedSub.Name);
msg.Write(selectedSub.MD5Hash.Hash);
msg.Write(selectedShuttle.Name);
msg.Write(selectedShuttle.MD5Hash.Hash);
connectedClients.ForEach(c => c.ReadyToStart = false);
server.SendMessage(msg, connectedClients.Select(c => c.Connection).ToList(), NetDeliveryMethod.ReliableUnordered, 0);
//give the clients a few seconds to request missing sub/shuttle files before starting the round
float waitForResponseTimer = 3.0f;
while (connectedClients.Any(c => !c.ReadyToStart) && waitForResponseTimer > 0.0f)
if (connectedClients.Any())
{
waitForResponseTimer -= CoroutineManager.UnscaledDeltaTime;
yield return CoroutineStatus.Running;
}
NetOutgoingMessage msg = server.CreateMessage();
msg.Write((byte)ServerPacketHeader.QUERY_STARTGAME);
//todo: wait until file transfers are finished/cancelled
msg.Write(selectedSub.Name);
msg.Write(selectedSub.MD5Hash.Hash);
msg.Write(selectedShuttle.Name);
msg.Write(selectedShuttle.MD5Hash.Hash);
connectedClients.ForEach(c => c.ReadyToStart = false);
server.SendMessage(msg, connectedClients.Select(c => c.Connection).ToList(), NetDeliveryMethod.ReliableUnordered, 0);
//give the clients a few seconds to request missing sub/shuttle files before starting the round
float waitForResponseTimer = 3.0f;
while (connectedClients.Any(c => !c.ReadyToStart) && waitForResponseTimer > 0.0f)
{
waitForResponseTimer -= CoroutineManager.UnscaledDeltaTime;
yield return CoroutineStatus.Running;
}
//todo: wait until file transfers are finished/cancelled
}
GameMain.ShowLoading(StartGame(selectedSub, selectedShuttle, selectedMode), false);
@@ -848,7 +851,7 @@ namespace Barotrauma.Networking
WayPoint spawnPoint = WayPoint.GetRandom(SpawnType.Human, null, selectedSub);
Vector2 spawnPosition = spawnPoint.WorldPosition;
DebugConsole.NewMessage(Convert.ToString(spawnPosition.X) + "," + Convert.ToString(spawnPosition.Y), Color.Lime);
DebugConsole.NewMessage(spawnPosition.ToString(), Color.Lime);
Character spawnedCharacter = Character.Create(Character.HumanConfigFile, spawnPosition, c.characterInfo, true, false);
spawnedCharacter.AnimController.Frozen = true;
c.Character = spawnedCharacter;
@@ -856,6 +859,15 @@ namespace Barotrauma.Networking
GameMain.GameSession.CrewManager.characters.Add(c.Character);
}
if (characterInfo!=null)
{
WayPoint spawnPoint = WayPoint.GetRandom(SpawnType.Human, null, selectedSub);
myCharacter = Character.Create(Character.HumanConfigFile, spawnPoint.WorldPosition, characterInfo, false, false);
GameMain.GameSession.CrewManager.characters.Add(myCharacter);
Character.Controlled = myCharacter;
}
SendStartMessage(roundStartSeed, Submarine.MainSub, GameMain.GameSession.gameMode.Preset, connectedClients);
//var startMessage = CreateStartMessage(roundStartSeed, Submarine.MainSub, GameMain.GameSession.gameMode.Preset);
//server.SendMessage(startMessage, connectedClients.Select(c => c.Connection).ToList(), NetDeliveryMethod.ReliableUnordered, 0);
@@ -908,12 +920,21 @@ namespace Barotrauma.Networking
var clientsWithCharacter = clients.FindAll(c => c.Character != null);
msg.Write((byte)clientsWithCharacter.Count);
int characterCount = clientsWithCharacter.Count;
if (myCharacter != null) characterCount++;
msg.Write((byte)characterCount);
foreach (Client c in clientsWithCharacter)
{
c.Character.WriteSpawnData(msg);
msg.Write(c == client);
}
if (myCharacter != null)
{
myCharacter.WriteSpawnData(msg);
msg.Write(false);
}
server.SendMessage(msg, client.Connection, NetDeliveryMethod.ReliableUnordered);
}
@@ -1291,7 +1312,6 @@ namespace Barotrauma.Networking
if (c.Character == null || !c.Character.IsDead) continue;
assignedClientCount[JobPrefab.List.IndexOf(c.Character.Info.Job.Prefab)]++;
}
//if any of the players has chosen a job that is Always Allowed, give them that job
+2 -2
View File
@@ -301,8 +301,8 @@ namespace Barotrauma.Particles
public void UpdateDrawPos()
{
drawPosition = Physics.Interpolate(prevPosition, position);
drawRotation = Physics.Interpolate(prevRotation, rotation);
drawPosition = Timing.Interpolate(prevPosition, position);
drawRotation = Timing.Interpolate(prevRotation, rotation);
prevPosition = position;
prevRotation = rotation;
+1 -28
View File
@@ -20,33 +20,6 @@ namespace Barotrauma
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 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));
}
public const float DisplayToSimRation = 100.0f;
}
}
+3 -3
View File
@@ -339,10 +339,10 @@ namespace Barotrauma
public void UpdateDrawPosition()
{
drawPosition = Physics.Interpolate(prevPosition, body.Position) - offsetFromTargetPos;
drawPosition = Timing.Interpolate(prevPosition, body.Position) - offsetFromTargetPos;
drawPosition = ConvertUnits.ToDisplayUnits(drawPosition);
drawRotation = Physics.Interpolate(prevRotation, body.Rotation);
drawRotation = Timing.Interpolate(prevRotation, body.Rotation);
if (offsetFromTargetPos == Vector2.Zero) return;
@@ -379,7 +379,7 @@ namespace Barotrauma
/// </summary>
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);
@@ -98,26 +98,15 @@ namespace Barotrauma
/// <param name="gameTime">Provides a snapshot of timing values.</param>
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);
if (physicsEnabled)
{
Physics.accumulator = Math.Min(Physics.accumulator, Physics.step * 4);
while (Physics.accumulator >= Physics.step)
{
Character.UpdateAnimAll((float)Physics.step * 1000.0f);
Character.UpdateAnimAll((float)deltaTime);
Ragdoll.UpdateAll(cam, (float)Physics.step);
Ragdoll.UpdateAll(cam, (float)deltaTime);
GameMain.World.Step((float)Physics.step);
Physics.accumulator -= Physics.step;
}
Physics.Alpha = Physics.accumulator / Physics.step;
GameMain.World.Step((float)deltaTime);
}
}
+38 -50
View File
@@ -91,9 +91,6 @@ namespace Barotrauma
/// <param name="gameTime">Provides a snapshot of timing values.</param>
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 (GameMain.GameSession != null && GameMain.GameSession.Level != null && GameMain.GameSession.Submarine != null)
@@ -109,15 +106,9 @@ namespace Barotrauma
}
#endif
Physics.accumulator = Math.Min(Physics.accumulator, Physics.step * 6);
//Physics.accumulator = Physics.step;
while (Physics.accumulator >= Physics.step)
{
if (GameMain.GameSession != null) GameMain.GameSession.Update((float)deltaTime);
if (GameMain.GameSession != null) GameMain.GameSession.Update((float)Physics.step);
//EventManager.Update(gameTime);
if (Level.Loaded != null) Level.Loaded.Update((float)Physics.step);
if (Level.Loaded != null) Level.Loaded.Update((float)deltaTime);
if (Character.Controlled != null && Character.Controlled.SelectedConstruction != null)
{
@@ -126,51 +117,50 @@ namespace Barotrauma
Character.Controlled.SelectedConstruction.UpdateHUD(Character.Controlled);
}
}
Character.UpdateAll(cam, (float)deltaTime);
BackgroundCreatureManager.Update(cam, (float)deltaTime);
BackgroundCreatureManager.Update(cam, (float)Physics.step);
GameMain.ParticleManager.Update((float)deltaTime);
GameMain.ParticleManager.Update((float)Physics.step);
StatusEffect.UpdateAll((float)deltaTime);
StatusEffect.UpdateAll((float)Physics.step);
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);
if (Character.Controlled != null && Lights.LightManager.ViewTarget != null)
{
cam.TargetPos = Lights.LightManager.ViewTarget.WorldPosition;
}
cam.MoveCamera((float)deltaTime);
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 (Submarine sub in Submarine.Loaded)
{
sub.SetPrevTransform(sub.Position);
}
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;
}
}
@@ -206,8 +196,6 @@ namespace Barotrauma
GUI.Draw((float)deltaTime, spriteBatch, cam);
if (!PlayerInput.LeftButtonHeld()) Inventory.draggingItem = null;
spriteBatch.End();
}
+6 -1
View File
@@ -355,7 +355,12 @@ namespace Barotrauma
mapZoom += PlayerInput.ScrollWheelSpeed / 1000.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)
+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));
}
}
}