Setting ragdoll position without limbs going through walls, rotating entire ragdoll, using combined network messages client->server, fixed fabricators

This commit is contained in:
Regalis
2015-11-08 22:20:29 +02:00
parent 5a21d64b3a
commit cd48d12be6
31 changed files with 551 additions and 313 deletions
@@ -373,6 +373,8 @@ namespace Barotrauma
public override void ReadNetworkData(NetworkEventType type, NetBuffer message)
{
character.ClearInput(InputType.Use);
for (int i = 0; i<5; i++)
{
ushort itemId = message.ReadUInt16();
@@ -391,17 +393,11 @@ namespace Barotrauma
List<ushort> newItemIDs = new List<ushort>();
try
for (int i = 5; i < capacity; i++)
{
while (message.Position <= message.LengthBits - (sizeof(ushort) * 8))
{
newItemIDs.Add(message.ReadUInt16());
}
}
catch
{
return;
newItemIDs.Add(message.ReadUInt16());
}
for (int i = 5; i < capacity; i++)
{
@@ -73,34 +73,23 @@ namespace Barotrauma.Items.Components
}
int width = 400, height = 300;
itemList = new GUIListBox(new Rectangle(GameMain.GraphicsWidth / 2 - width / 2, GameMain.GraphicsHeight / 2 - height / 2, width, height), Color.White * 0.7f);
int width = 500, height = 300;
itemList = new GUIListBox(new Rectangle(GameMain.GraphicsWidth / 2 - width / 2, GameMain.GraphicsHeight / 2 - height / 2, width, height), GUI.Style);
itemList.OnSelected = SelectItem;
//structureList.CheckSelected = MapEntityPrefab.GetSelected;
foreach (FabricableItem fi in fabricableItems)
{
Color color = ((itemList.CountChildren % 2) == 0) ? Color.White : Color.LightGray;
//GUIFrame frame = new GUIFrame(new Rectangle(0, 0, 0, 50), Color.Transparent, itemList);
//frame.UserData = fi;
//frame.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);
//frame.Color = color;
//frame.HoverColor = Color.Gold * 0.2f;
//frame.SelectedColor = Color.Gold * 0.5f;
Color color = ((itemList.CountChildren % 2) == 0) ? Color.Transparent : Color.Black*0.3f;
GUITextBlock textBlock = new GUITextBlock(
new Rectangle(0, 0, 0, 25), fi.TargetItem.Name,
color, Color.Black,
color, Color.White,
Alignment.Left, Alignment.Left, null, itemList);
textBlock.UserData = fi;
textBlock.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);
//if (fi.TargetItem.sprite != null)
//{
// GUIImage img = new GUIImage(new Rectangle(0, 0, 40, 40), fi.TargetItem.sprite, Alignment.Left, frame);
// img.Scale = Math.Min(Math.Min(40.0f / img.SourceRect.Width, 40.0f / img.SourceRect.Height), 1.0f);
//}
textBlock.HoverColor = Color.Gold * 0.2f;
textBlock.SelectedColor = Color.Gold * 0.5f;
}
}
@@ -110,7 +99,7 @@ namespace Barotrauma.Items.Components
if (targetItem == null) return false;
int width = 200, height = 150;
selectedItemFrame = new GUIFrame(new Rectangle(GameMain.GraphicsWidth / 2 - width / 2, itemList.Rect.Bottom+20, width, height), Color.Black*0.8f);
selectedItemFrame = new GUIFrame(new Rectangle(itemList.Rect.Right - width - 20, GameMain.GraphicsHeight/2-height/2, width, height), Color.Black*0.8f);
//selectedItemFrame.Padding = GUI.style.smallPadding;
if (targetItem.TargetItem.sprite != null)
@@ -177,7 +166,7 @@ namespace Barotrauma.Items.Components
container.inventory.RemoveItem(requiredItem);
}
new Item(fabricatedItem.TargetItem, item.Position);
Item.Spawner.QueueItem(fabricatedItem.TargetItem, item.Position);
IsActive = false;
fabricatedItem = null;
@@ -199,7 +188,6 @@ namespace Barotrauma.Items.Components
}
}
itemList.Update(0.016f);
itemList.Draw(spriteBatch);
@@ -131,10 +131,14 @@ namespace Barotrauma.Items.Components
float cellDot = Vector2.Dot(cell.Center + Level.Loaded.Position, (edge.point1 + edge.point2) / 2.0f - cell.Center);
if (cellDot > 0) continue;
float facingDot = Vector2.Dot(Vector2.Normalize(edge.point1 - edge.point2), Vector2.Normalize(cell.Center + Level.Loaded.Position));
facingDot = MathHelper.Clamp(facingDot, -1.0f, 1.0f);
Vector2 point1 = (edge.point1 + Level.Loaded.Position);
Vector2 point2 = (edge.point2 + Level.Loaded.Position);
for (float x=0; x<(point1-point2).Length(); x+=Rand.Range(600.0f, 800.0f))
float length = (point1 - point2).Length();
for (float x=0; x<length; x+=Rand.Range(600.0f, 800.0f))
{
Vector2 point = point1 + Vector2.Normalize(point2 - point1) * x;
@@ -144,15 +148,18 @@ namespace Barotrauma.Items.Components
if (pointDist < prevPingRadius || pointDist > pingRadius) continue;
float step = 4.0f;
float step = 5.0f * (Math.Abs(facingDot)+1.0f);
float alpha = Rand.Range(1.5f, 2.0f);
for (float z = 0; z<radius-pointDist;z+=step)
{
var blip = new RadarBlip(
point + Rand.Vector(150.0f) - Level.Loaded.Position + Vector2.Normalize(point) * z / displayScale,
Rand.Range(0.8f, 1.0f) / (step-4.0f));
alpha);
radarBlips.Add(blip);
step += 0.5f;
alpha -= (z == 0) ? 0.5f : 0.1f;
}
}
@@ -199,7 +206,7 @@ namespace Barotrauma.Items.Components
foreach (RadarBlip radarBlip in radarBlips)
{
DrawBlip(spriteBatch, center, radarBlip.Position, Color.Green * radarBlip.FadeTimer);
DrawBlip(spriteBatch,radarBlip, center, Color.Green * radarBlip.FadeTimer, radius);
}
prevPingRadius = pingRadius;
@@ -262,17 +269,18 @@ namespace Barotrauma.Items.Components
voltage = 0.0f;
}
private void DrawBlip(SpriteBatch spriteBatch, Vector2 center, Vector2 pos, Color color)
private void DrawBlip(SpriteBatch spriteBatch, RadarBlip blip, Vector2 center, Color color, float radius)
{
pos = (pos + Level.Loaded.Position) * displayScale;
Vector2 pos = (blip.Position + Level.Loaded.Position) * displayScale;
pos.Y = -pos.Y;
//spriteBatch.Draw(radarBlipSprite, center+pos,
// new Rectangle((int)(radarBlip.SpriteIndex % 4 * 32), (int)(Math.Floor(radarBlip.SpriteIndex / 4.0f) * 32), 32, 32),
// Color.White * radarBlip.FadeTimer, 0.0f, new Vector2(16.0f, 16.0f), 0.5f, SpriteEffects.None, 0.0f);
if (pos.Length() > radius)
{
blip.FadeTimer = 0.0f;
return;
}
pos.X = MathUtils.Round(pos.X, 4);
pos.Y = MathUtils.Round(pos.Y, 2);
GUI.DrawRectangle(spriteBatch, center + pos, new Vector2(4, 2), color, true);
+10 -16
View File
@@ -297,10 +297,11 @@ namespace Barotrauma
public virtual bool FillNetworkData(NetworkEventType type, NetBuffer message, object data)
{
for (int i = 0; i<capacity; i++)
var foundItems = Array.FindAll(items, i => i != null);
message.Write((byte)foundItems.Count());
foreach (Item item in foundItems)
{
if (items[i] == null) continue;
message.Write((ushort)items[i].ID);
message.Write((ushort)item.ID);
}
return true;
@@ -309,20 +310,13 @@ namespace Barotrauma
public virtual void ReadNetworkData(NetworkEventType type, NetBuffer message)
{
List<ushort> newItemIDs = new List<ushort>();
try
{
while (message.Position <= message.LengthBits - (sizeof(ushort) * 8))
{
newItemIDs.Add(message.ReadUInt16());
}
}
catch
{
return;
}
byte count = message.ReadByte();
for (int i = 0; i<count; i++)
{
newItemIDs.Add(message.ReadUInt16());
}
for (int i = 0; i < capacity; i++)
{
if (items[i] == null) continue;
+19 -8
View File
@@ -23,9 +23,11 @@ namespace Barotrauma
class Item : MapEntity, IDamageable, IPropertyObject
{
public static List<Item> itemList = new List<Item>();
public static List<Item> ItemList = new List<Item>();
protected ItemPrefab prefab;
public static ItemSpawner Spawner = new ItemSpawner();
private List<string> tags;
public Hull CurrentHull;
@@ -308,7 +310,7 @@ namespace Barotrauma
}
InsertToList();
itemList.Add(this);
ItemList.Add(this);
}
public T GetComponent<T>()
@@ -359,7 +361,7 @@ namespace Barotrauma
{
base.Move(amount);
if (itemList != null && body != null)
if (ItemList != null && body != null)
{
amount = ConvertUnits.ToSimUnits(amount);
//Vector2 pos = new Vector2(rect.X + rect.Width / 2.0f, rect.Y - rect.Height / 2.0f);
@@ -387,7 +389,7 @@ namespace Barotrauma
/// </summary>
public static void UpdateHulls()
{
foreach (Item item in itemList) item.FindHull();
foreach (Item item in ItemList) item.FindHull();
}
public virtual Hull FindHull()
@@ -812,7 +814,7 @@ namespace Barotrauma
Vector2 displayPos = ConvertUnits.ToDisplayUnits(position);
Vector2 displayPickPos = ConvertUnits.ToDisplayUnits(pickPosition);
foreach (Item item in itemList)
foreach (Item item in ItemList)
{
if (ignoredItems!=null && ignoredItems.Contains(item)) continue;
//if (hull != item.CurrentHull && (hull==null || (item.Rect.Height<hull.Rect.Height && item.rect.Width < hull.Rect.Width))) continue;
@@ -1295,8 +1297,10 @@ namespace Barotrauma
return true;
}
public override void ReadNetworkData(NetworkEventType type, NetIncomingMessage message)
public override void ReadNetworkData(NetworkEventType type, NetIncomingMessage message, out object data)
{
data = null;
Condition = (float)message.ReadByte()/2.55f;
switch (type)
@@ -1310,11 +1314,14 @@ namespace Barotrauma
case NetworkEventType.ItemFixed:
byte requirementIndex = message.ReadByte();
data = requirementIndex;
if (requirementIndex>=FixRequirements.Count) return;
FixRequirements[requirementIndex].Fixed = true;
break;
case NetworkEventType.InventoryUpdate:
var itemContainer = GetComponent<ItemContainer>();
if (itemContainer == null || itemContainer.inventory == null) return;
itemContainer.inventory.ReadNetworkData(NetworkEventType.DropItem, message);
@@ -1322,6 +1329,9 @@ namespace Barotrauma
case NetworkEventType.ComponentUpdate:
case NetworkEventType.ImportantComponentUpdate:
int componentIndex = message.ReadByte();
data = componentIndex;
if (componentIndex < 0 || componentIndex > components.Count - 1) return;
components[componentIndex].ReadNetworkData(type, message);
break;
@@ -1331,6 +1341,7 @@ namespace Barotrauma
try
{
propertyName = message.ReadString();
data = propertyName;
}
catch
{
@@ -1380,9 +1391,9 @@ namespace Barotrauma
{
ic.Remove();
}
itemList.Remove(this);
ItemList.Remove(this);
foreach (Item it in itemList)
foreach (Item it in ItemList)
{
if (it.linkedTo.Contains(this))
{
+1 -1
View File
@@ -111,7 +111,7 @@ namespace Barotrauma
if (PlayerInput.GetMouseState.LeftButton == ButtonState.Released)
{
new Item(new Rectangle((int)placePosition.X, (int)placePosition.Y, (int)placeSize.X, (int)placeSize.Y), this);
placePosition = Vector2.Zero;
//selected = null;
return;
}
+37
View File
@@ -0,0 +1,37 @@
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Barotrauma
{
class ItemSpawner
{
private Queue<Pair<ItemPrefab, Vector2>> spawnQueue;
public ItemSpawner()
{
spawnQueue = new Queue<Pair<ItemPrefab, Vector2>>();
}
public void QueueItem(ItemPrefab itemPrefab, Vector2 position)
{
var itemInfo = new Pair<ItemPrefab, Vector2>();
itemInfo.First = itemPrefab;
itemInfo.Second = position;
spawnQueue.Enqueue(itemInfo);
}
public void Update()
{
while (spawnQueue.Count>0)
{
var itemInfo = spawnQueue.Dequeue();
new Item(itemInfo.First, itemInfo.Second);
}
}
}
}