v0.13.0.11

This commit is contained in:
Joonas Rikkonen
2021-04-22 17:33:08 +03:00
parent 0697d7fc64
commit 8bb31f2893
391 changed files with 17271 additions and 5949 deletions
@@ -37,7 +37,7 @@ namespace Barotrauma
public float MinZoom
{
get { return minZoom;}
set { minZoom = MathHelper.Clamp(value, 0.01f, 10.0f); }
set { minZoom = MathHelper.Clamp(value, 0.001f, 10.0f); }
}
private float maxZoom = 2.0f;
@@ -51,8 +51,6 @@ namespace Barotrauma
private float zoom;
private float offsetAmount;
private Matrix transform, shaderTransform, viewMatrix;
private Vector2 position;
private float rotation;
@@ -67,16 +65,9 @@ namespace Barotrauma
public float Shake;
private Vector2 shakePosition;
private float shakeTimer;
//the area of the world inside the camera view
private Rectangle worldView;
private float globalZoomScale = 1.0f;
private Point resolution;
private Vector2 targetPos;
//used to smooth out the movement when in freecam
private float targetZoom;
private Vector2 velocity;
@@ -89,10 +80,10 @@ namespace Barotrauma
zoom = MathHelper.Clamp(value, GameMain.DebugDraw ? 0.01f : MinZoom, MaxZoom);
Vector2 center = WorldViewCenter;
float newWidth = resolution.X / zoom;
float newHeight = resolution.Y / zoom;
float newWidth = Resolution.X / zoom;
float newHeight = Resolution.Y / zoom;
worldView = new Rectangle(
WorldView = new Rectangle(
(int)(center.X - newWidth / 2.0f),
(int)(center.Y + newHeight / 2.0f),
(int)newWidth,
@@ -122,29 +113,20 @@ namespace Barotrauma
}
}
public float OffsetAmount
{
get { return offsetAmount; }
set { offsetAmount = value; }
}
public float OffsetAmount { get; set; }
public Point Resolution
{
get { return resolution; }
}
public Point Resolution { get; private set; }
public Rectangle WorldView
{
get { return worldView; }
}
//the area of the world inside the camera view
public Rectangle WorldView { get; private set; }
public Vector2 WorldViewCenter
{
get
{
return new Vector2(
worldView.X + worldView.Width / 2.0f,
worldView.Y - worldView.Height / 2.0f);
WorldView.X + WorldView.Width / 2.0f,
WorldView.Y - WorldView.Height / 2.0f);
}
}
@@ -171,12 +153,13 @@ namespace Barotrauma
UpdateTransform(false);
}
public Vector2 TargetPos
~Camera()
{
get { return targetPos; }
set { targetPos = value; }
GameMain.Instance.ResolutionChanged -= CreateMatrices;
}
public Vector2 TargetPos { get; set; }
public Vector2 GetPosition()
{
return position;
@@ -204,21 +187,29 @@ namespace Barotrauma
public void SetResolution(Point res)
{
resolution = res;
Resolution = res;
worldView = new Rectangle(0, 0, res.X, res.Y);
WorldView = new Rectangle(0, 0, res.X, res.Y);
viewMatrix = Matrix.CreateTranslation(new Vector3(res.X / 2.0f, res.Y / 2.0f, 0));
globalZoomScale = (float)Math.Pow(new Vector2(GUI.UIWidth, resolution.Y).Length() / GUI.ReferenceResolution.Length(), 2);
float newGlobalZoomScale = (float)new Vector2(GUI.UIWidth, Resolution.Y).Length() / GUI.ReferenceResolution.Length();
if (globalZoomScale > 0.0f)
{
Zoom *= newGlobalZoomScale / globalZoomScale;
targetZoom *= newGlobalZoomScale / globalZoomScale;
prevZoom *= newGlobalZoomScale / globalZoomScale;
}
globalZoomScale = newGlobalZoomScale;
}
public void UpdateTransform(bool interpolate = true)
public void UpdateTransform(bool interpolate = true, bool updateListener = true)
{
Vector2 interpolatedPosition = interpolate ? Timing.Interpolate(prevPosition, position) : position;
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);
WorldView = new Rectangle((int)(interpolatedPosition.X - WorldView.Width / 2.0),
(int)(interpolatedPosition.Y + WorldView.Height / 2.0),
WorldView.Width, WorldView.Height);
transform = Matrix.CreateTranslation(
new Vector3(-interpolatedPosition.X, interpolatedPosition.Y, 0)) *
@@ -227,19 +218,22 @@ namespace Barotrauma
shaderTransform = Matrix.CreateTranslation(
new Vector3(
-interpolatedPosition.X - resolution.X / interpolatedZoom / 2.0f,
-interpolatedPosition.Y - resolution.Y / interpolatedZoom / 2.0f, 0)) *
-interpolatedPosition.X - Resolution.X / interpolatedZoom / 2.0f,
-interpolatedPosition.Y - Resolution.Y / interpolatedZoom / 2.0f, 0)) *
Matrix.CreateScale(new Vector3(interpolatedZoom, interpolatedZoom, 1)) *
viewMatrix * Matrix.CreateRotationZ(-rotation);
if (Character.Controlled == null)
if (updateListener)
{
GameMain.SoundManager.ListenerPosition = new Vector3(WorldViewCenter.X, WorldViewCenter.Y, -(100.0f / zoom));
}
else
{
GameMain.SoundManager.ListenerPosition = new Vector3(Character.Controlled.WorldPosition.X, Character.Controlled.WorldPosition.Y, -(100.0f / zoom));
if (Character.Controlled == null)
{
GameMain.SoundManager.ListenerPosition = new Vector3(WorldViewCenter.X, WorldViewCenter.Y, -(100.0f / zoom));
}
else
{
GameMain.SoundManager.ListenerPosition = new Vector3(Character.Controlled.WorldPosition.X, Character.Controlled.WorldPosition.Y, -(100.0f / zoom));
}
}
@@ -257,7 +251,7 @@ namespace Barotrauma
/// </summary>
public bool Freeze { get; set; }
public void MoveCamera(float deltaTime, bool allowMove = true, bool allowZoom = true)
public void MoveCamera(float deltaTime, bool allowMove = true, bool allowZoom = true, bool? followSub = null)
{
prevPosition = position;
prevZoom = zoom;
@@ -265,7 +259,7 @@ namespace Barotrauma
float moveSpeed = 20.0f / zoom;
Vector2 moveCam = Vector2.Zero;
if (targetPos == Vector2.Zero)
if (TargetPos == Vector2.Zero)
{
Vector2 moveInput = Vector2.Zero;
if (allowMove && !Freeze)
@@ -284,7 +278,7 @@ namespace Barotrauma
velocity = Vector2.Lerp(velocity, moveInput, deltaTime * 10.0f);
moveCam = velocity * moveSpeed * deltaTime * FreeCamMoveSpeed * 60.0f;
if (Screen.Selected == GameMain.GameScreen && FollowSub)
if (Screen.Selected == GameMain.GameScreen && (followSub ?? FollowSub))
{
var closestSub = Submarine.FindClosest(WorldViewCenter);
if (closestSub != null)
@@ -294,7 +288,7 @@ namespace Barotrauma
}
}
if (allowZoom && GUI.MouseOn == null)
if (allowZoom)
{
Vector2 mouseInWorld = ScreenToWorld(PlayerInput.MousePosition);
Vector2 diffViewCenter;
@@ -318,14 +312,15 @@ namespace Barotrauma
else if (allowMove)
{
Vector2 mousePos = PlayerInput.MousePosition;
Vector2 offset = mousePos - resolution.ToVector2() / 2;
offset.X = offset.X / (resolution.X * 0.4f);
offset.Y = -offset.Y / (resolution.Y * 0.3f);
Vector2 offset = mousePos - Resolution.ToVector2() / 2;
offset.X = offset.X / (Resolution.X * 0.4f);
offset.Y = -offset.Y / (Resolution.Y * 0.3f);
if (offset.LengthSquared() > 1.0f) offset.Normalize();
offset *= offsetAmount;
float offsetUnscaledLen = offset.Length();
offset *= OffsetAmount;
// Freeze the camera movement by default, when the cursor is on top of an ui element.
// Setting a positive value to the OffsetAmount, will override this behaviour.
if (GUI.MouseOn != null && offsetAmount > 0)
if (GUI.MouseOn != null && OffsetAmount > 0)
{
Freeze = true;
}
@@ -336,7 +331,7 @@ namespace Barotrauma
}
if (Freeze)
{
offset = previousOffset;
if (offset.LengthSquared() > 0.001f) { offset = previousOffset; }
}
else
{
@@ -344,24 +339,19 @@ namespace Barotrauma
}
//how much to zoom out (zoom completely out when offset is 1000)
float zoomOutAmount = GetZoomAmount(offset);
//zoom amount when resolution is not taken into account
float unscaledZoom = MathHelper.Lerp(DefaultZoom, MinZoom, zoomOutAmount);
//zoom with resolution taken into account (zoom further out on smaller resolutions)
float scaledZoom = unscaledZoom * globalZoomScale;
//an ad-hoc way of allowing the players to have roughly the same maximum view distance regardless of the resolution,
//while still keeping the zoom around 1.0 when not looking further away (because otherwise we'd always be downsampling
//on lower resolutions, which doesn't look that good)
float newZoom = MathHelper.Lerp(unscaledZoom, scaledZoom,
(GameMain.Config == null || GameMain.Config.EnableMouseLook) ? (float)Math.Sqrt(zoomOutAmount) : 0.3f);
float zoomOutAmount = GetZoomAmount(offset);
//scaled zoom amount
float scaledZoom = MathHelper.Lerp(DefaultZoom, MinZoom, zoomOutAmount) * globalZoomScale;
//zoom in further if zoomOutAmount is low and resolution is lower than reference
float newZoom = scaledZoom * (MathHelper.Lerp(0.3f * (1f - Math.Min(globalZoomScale, 1f)), 0f,
(GameMain.Config == null || GameMain.Config.EnableMouseLook) ? (float)Math.Sqrt(offsetUnscaledLen) : 0.3f) + 1f);
Zoom += (newZoom - zoom) / ZoomSmoothness;
//force targetzoom to the current zoom value, so the camera stays at the same zoom when switching to freecam
targetZoom = Zoom;
Vector2 diff = (targetPos + offset) - position;
Vector2 diff = (TargetPos + offset) - position;
moveCam = diff / MoveSmoothness;
}