Unstable 1.8.4.0

This commit is contained in:
Markus Isberg
2025-03-12 12:56:27 +00:00
parent a4c3e868e4
commit a4a3427e4e
627 changed files with 29860 additions and 10018 deletions
@@ -1,6 +1,5 @@
using Barotrauma.Networking;
using FarseerPhysics;
using Lidgren.Network;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
@@ -9,13 +8,17 @@ namespace Barotrauma
{
partial class PhysicsBody
{
private float bodyShapeTextureScale;
private Texture2D bodyShapeTexture;
public Texture2D BodyShapeTexture
{
get { return bodyShapeTexture; }
}
/// <summary>
/// Last known state the server has told us about.
/// </summary>
public PosInfo LastServerState;
/// <summary>
/// An offset used to corrections to positional errors look smoother. When a large positional correction needs to be done in multiplayer,
/// the body is immediately moved to the correct position, but the draw position is interpolated to make the correction visually smoother.
/// This value means the offset from the "actual" corrected position of the body to the "fake", interpolated draw position.
/// </summary>
public Vector2 NetworkPositionErrorOffset => drawOffset;
public void Draw(DeformableSprite deformSprite, Camera cam, Vector2 scale, Color color, bool invert = false)
{
@@ -72,85 +75,54 @@ namespace Barotrauma
if (drawOffset != Vector2.Zero)
{
Vector2 pos = ConvertUnits.ToDisplayUnits(FarseerBody.Position);
if (Submarine != null) pos += Submarine.DrawPosition;
if (Submarine != null) { pos += Submarine.DrawPosition; }
GUI.DrawLine(spriteBatch,
new Vector2(pos.X, -pos.Y),
new Vector2(DrawPosition.X, -DrawPosition.Y),
Color.Cyan, 0, 5);
Color.Purple * 0.5f, 0, 5);
}
if (bodyShapeTexture == null && IsValidShape(Radius, Height, Width))
if (IsValidShape(Radius, Height, Width))
{
DrawShape(drawPosition, DrawRotation, color);
}
if (LastServerState != null)
{
Vector2 drawPos = ConvertUnits.ToDisplayUnits(LastServerState.Position);
if (Submarine != null)
{
drawPos += Submarine.DrawPosition;
}
float rotation = LastServerState.Rotation ?? 0.0f;
DrawShape(drawPos, rotation, Color.Purple * 0.75f);
}
void DrawShape(Vector2 position, float rotation, Color color)
{
float radius = ConvertUnits.ToDisplayUnits(Radius);
float height = ConvertUnits.ToDisplayUnits(Height);
float width = ConvertUnits.ToDisplayUnits(Width);
switch (BodyShape)
{
case Shape.Rectangle:
{
float maxSize = Math.Max(ConvertUnits.ToDisplayUnits(Width), ConvertUnits.ToDisplayUnits(Height));
if (maxSize > 128.0f)
{
bodyShapeTextureScale = 128.0f / maxSize;
}
else
{
bodyShapeTextureScale = 1.0f;
}
bodyShapeTexture = GUI.CreateRectangle(
(int)ConvertUnits.ToDisplayUnits(Width * bodyShapeTextureScale),
(int)ConvertUnits.ToDisplayUnits(Height * bodyShapeTextureScale));
break;
}
GUI.DrawRectangle(spriteBatch, position.FlipY(), new Vector2(width, height), new Vector2(width, height) / 2, -rotation, color);
break;
case Shape.Capsule:
GUI.DrawCapsule(spriteBatch, position.FlipY(), height, radius, -rotation - MathHelper.PiOver2, color);
break;
case Shape.HorizontalCapsule:
{
float maxSize = Math.Max(ConvertUnits.ToDisplayUnits(Radius), ConvertUnits.ToDisplayUnits(Math.Max(Height, Width)));
if (maxSize > 128.0f)
{
bodyShapeTextureScale = 128.0f / maxSize;
}
else
{
bodyShapeTextureScale = 1.0f;
}
bodyShapeTexture = GUI.CreateCapsule(
(int)ConvertUnits.ToDisplayUnits(Radius * bodyShapeTextureScale),
(int)ConvertUnits.ToDisplayUnits(Math.Max(Height, Width) * bodyShapeTextureScale));
break;
}
GUI.DrawCapsule(spriteBatch, position.FlipY(), width, radius, -rotation, color);
break;
case Shape.Circle:
if (ConvertUnits.ToDisplayUnits(Radius) > 128.0f)
{
bodyShapeTextureScale = 128.0f / ConvertUnits.ToDisplayUnits(Radius);
}
else
{
bodyShapeTextureScale = 1.0f;
}
bodyShapeTexture = GUI.CreateCircle((int)ConvertUnits.ToDisplayUnits(Radius * bodyShapeTextureScale));
GUI.DrawDonutSection(spriteBatch, position.FlipY(), new Range<float>(radius - 0.5f, radius + 0.5f), MathHelper.TwoPi, color, 0, -rotation);
break;
default:
throw new NotImplementedException();
}
}
float rot = -DrawRotation;
if (bodyShape == Shape.HorizontalCapsule)
{
rot -= MathHelper.PiOver2;
}
if (bodyShapeTexture != null)
{
spriteBatch.Draw(
bodyShapeTexture,
new Vector2(DrawPosition.X, -DrawPosition.Y),
null,
color,
rot,
new Vector2(bodyShapeTexture.Width / 2, bodyShapeTexture.Height / 2),
1.0f / bodyShapeTextureScale, SpriteEffects.None, 0.0f);
}
}
public PosInfo ClientRead(IReadMessage msg, float sendingTime, string parentDebugName)
@@ -206,18 +178,10 @@ namespace Barotrauma
return null;
}
return lastProcessedNetworkState > sendingTime ?
null :
new PosInfo(newPosition, newRotation, newVelocity, newAngularVelocity, sendingTime);
}
if (lastProcessedNetworkState > sendingTime) { return null; }
partial void DisposeProjSpecific()
{
if (bodyShapeTexture != null)
{
bodyShapeTexture.Dispose();
bodyShapeTexture = null;
}
LastServerState = new PosInfo(newPosition, newRotation, newVelocity, newAngularVelocity, sendingTime);
return LastServerState;
}
}
}