38f1ddb...178a853: v0.8.9.1, removed content folder

This commit is contained in:
Joonas Rikkonen
2019-03-18 19:46:58 +02:00
parent 38f1ddb6fe
commit 6c0679c297
1054 changed files with 151673 additions and 144931 deletions
+173 -40
View File
@@ -8,9 +8,39 @@ namespace Barotrauma
{
public static bool FollowSub = true;
const float DefaultZoom = 1.0f;
const float ZoomSmoothness = 8.0f;
const float MoveSmoothness = 8.0f;
private float defaultZoom = 1.3f;
public float DefaultZoom
{
get { return defaultZoom; }
set { defaultZoom = MathHelper.Clamp(value, 0.5f, 2.0f); }
}
private float zoomSmoothness = 8.0f;
public float ZoomSmoothness
{
get { return zoomSmoothness; }
set { zoomSmoothness = Math.Max(value, 0.01f); }
}
private float moveSmoothness = 8.0f;
public float MoveSmoothness
{
get { return moveSmoothness; }
set { moveSmoothness = Math.Max(value, 0.01f); }
}
private float minZoom = 0.1f;
public float MinZoom
{
get { return minZoom;}
set { minZoom = MathHelper.Clamp(value, 0.01f, 10.0f); }
}
private float maxZoom = 2.0f;
public float MaxZoom
{
get { return maxZoom; }
set { maxZoom = MathHelper.Clamp(value, 1.0f, 10.0f); }
}
private float zoom;
@@ -20,26 +50,36 @@ namespace Barotrauma
private Vector2 position;
private float rotation;
private float angularVelocity;
private float angularDamping;
private float angularSpring;
private Vector2 prevPosition;
private float prevZoom;
public float Shake;
private Vector2 shakePosition;
private Vector2 shakeTargetPosition;
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;
public float Zoom
{
get { return zoom; }
set
{
zoom = Math.Max(value, GameMain.DebugDraw ? 0.01f : 0.1f);
zoom = MathHelper.Clamp(value, GameMain.DebugDraw ? 0.01f : MinZoom, MaxZoom);
Vector2 center = WorldViewCenter;
float newWidth = resolution.X / zoom;
@@ -58,7 +98,21 @@ namespace Barotrauma
public float Rotation
{
get { return rotation; }
set { rotation = value; }
set
{
if (!MathUtils.IsValid(value)) return;
rotation = value;
}
}
public float AngularVelocity
{
get { return angularVelocity; }
set
{
if (!MathUtils.IsValid(value)) return;
angularVelocity = value;
}
}
public float OffsetAmount
@@ -99,18 +153,12 @@ namespace Barotrauma
public Camera()
{
zoom = prevZoom = 1.0f;
zoom = prevZoom = targetZoom = 1.0f;
rotation = 0.0f;
position = Vector2.Zero;
worldView = new Rectangle(0,0,
GameMain.GraphicsWidth,
GameMain.GraphicsHeight);
resolution = new Point(GameMain.GraphicsWidth, GameMain.GraphicsHeight);
viewMatrix =
Matrix.CreateTranslation(new Vector3(GameMain.GraphicsWidth / 2.0f, GameMain.GraphicsHeight / 2.0f, 0));
CreateMatrices();
GameMain.Instance.OnResolutionChanged += () => { CreateMatrices(); };
UpdateTransform(false);
}
@@ -125,7 +173,15 @@ namespace Barotrauma
public void Translate(Vector2 amount)
{
position += amount;
}
private void CreateMatrices()
{
resolution = new Point(GameMain.GraphicsWidth, GameMain.GraphicsHeight);
worldView = new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight);
viewMatrix = Matrix.CreateTranslation(new Vector3(GameMain.GraphicsWidth / 2.0f, GameMain.GraphicsHeight / 2.0f, 0));
globalZoomScale = new Vector2(resolution.X, resolution.Y).Length() / new Vector2(1920, 1080).Length();
}
public void UpdateTransform(bool interpolate = true)
@@ -140,16 +196,25 @@ namespace Barotrauma
transform = Matrix.CreateTranslation(
new Vector3(-interpolatedPosition.X, interpolatedPosition.Y, 0)) *
Matrix.CreateScale(new Vector3(interpolatedZoom, interpolatedZoom, 1)) *
viewMatrix;
Matrix.CreateRotationZ(rotation) * viewMatrix;
shaderTransform = Matrix.CreateTranslation(
new Vector3(
-interpolatedPosition.X - resolution.X / interpolatedZoom / 2.0f,
-interpolatedPosition.Y - resolution.Y / interpolatedZoom / 2.0f, 0)) *
Matrix.CreateScale(new Vector3(interpolatedZoom, interpolatedZoom, 1)) *
viewMatrix;
viewMatrix * Matrix.CreateRotationZ(-rotation);
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));
}
Sound.CameraPos = new Vector3(WorldViewCenter.X, WorldViewCenter.Y, 0.0f);
if (!interpolate)
{
@@ -158,27 +223,38 @@ namespace Barotrauma
}
}
private Vector2 previousOffset;
/// <summary>
/// Resets to false each time the MoveCamera method is called.
/// </summary>
public bool Freeze { get; set; }
public void MoveCamera(float deltaTime, bool allowMove = true, bool allowZoom = true)
{
{
prevPosition = position;
prevZoom = zoom;
float moveSpeed = 20.0f/zoom;
float moveSpeed = 20.0f / zoom;
Vector2 moveCam = Vector2.Zero;
if (targetPos == Vector2.Zero)
{
if (allowMove && GUIComponent.KeyboardDispatcher.Subscriber == null)
Vector2 moveInput = Vector2.Zero;
if (allowMove && GUI.KeyboardDispatcher.Subscriber == null)
{
if (PlayerInput.KeyDown(Keys.LeftShift)) moveSpeed *= 2.0f;
if (PlayerInput.KeyDown(Keys.LeftControl)) moveSpeed *= 0.5f;
if (GameMain.Config.KeyBind(InputType.Left).IsDown()) moveCam.X -= moveSpeed;
if (GameMain.Config.KeyBind(InputType.Right).IsDown()) moveCam.X += moveSpeed;
if (GameMain.Config.KeyBind(InputType.Down).IsDown()) moveCam.Y -= moveSpeed;
if (GameMain.Config.KeyBind(InputType.Up).IsDown()) moveCam.Y += moveSpeed;
if (GameMain.Config.KeyBind(InputType.Left).IsDown()) moveInput.X -= 1.0f;
if (GameMain.Config.KeyBind(InputType.Right).IsDown()) moveInput.X += 1.0f;
if (GameMain.Config.KeyBind(InputType.Down).IsDown()) moveInput.Y -= 1.0f;
if (GameMain.Config.KeyBind(InputType.Up).IsDown()) moveInput.Y += 1.0f;
}
velocity = Vector2.Lerp(velocity, moveInput, deltaTime * 10.0f);
moveCam = velocity * moveSpeed * deltaTime * 60.0f;
if (Screen.Selected == GameMain.GameScreen && FollowSub)
{
var closestSub = Submarine.FindClosest(WorldViewCenter);
@@ -188,45 +264,102 @@ namespace Barotrauma
}
}
moveCam = moveCam * deltaTime * 60.0f;
if (allowZoom)
{
Vector2 mouseInWorld = ScreenToWorld(PlayerInput.MousePosition);
Vector2 diffViewCenter;
diffViewCenter = ((mouseInWorld - Position) * Zoom);
Zoom = MathHelper.Clamp(zoom + (PlayerInput.ScrollWheelSpeed / 1000.0f) * zoom, GameMain.DebugDraw ? 0.01f : 0.1f, 2.0f);
targetZoom = MathHelper.Clamp(
targetZoom + (PlayerInput.ScrollWheelSpeed / 1000.0f) * zoom,
GameMain.DebugDraw ? MinZoom * 0.1f : MinZoom,
MaxZoom);
Zoom = MathHelper.Lerp(Zoom, targetZoom, deltaTime * 10.0f);
if (!PlayerInput.KeyDown(Keys.F)) Position = mouseInWorld - (diffViewCenter / Zoom);
}
}
else
else if (allowMove)
{
Vector2 mousePos = PlayerInput.MousePosition;
Vector2 offset = mousePos - new Vector2(resolution.X / 2.0f, resolution.Y / 2.0f);
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;
// 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)
{
Freeze = true;
}
if (CharacterHealth.OpenHealthWindow != null)
{
offset *= 0;
Freeze = false;
}
if (Freeze)
{
offset = previousOffset;
}
else
{
previousOffset = offset;
}
//how much to zoom out (zoom completely out when offset is 1000)
float zoomOutAmount = Math.Min(offset.Length() / 1000.0f, 1.0f);
//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;
if (offset.Length() > 1.0f) offset.Normalize();
//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, (float)Math.Sqrt(zoomOutAmount));
offset = offset * offsetAmount;
float newZoom = Math.Min(DefaultZoom - Math.Min(offset.Length() / resolution.Y, 1.0f),1.0f);
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;
moveCam = diff / MoveSmoothness;
}
rotation += angularVelocity * deltaTime;
angularVelocity *= (1.0f - angularDamping);
angularVelocity += -rotation * angularSpring;
shakeTargetPosition = Rand.Vector(Shake);
shakePosition = Vector2.Lerp(shakePosition, shakeTargetPosition, 0.5f);
Shake = MathHelper.Lerp(Shake, 0.0f, deltaTime * 2.0f);
angularDamping = 0.05f;
angularSpring = 0.2f;
if (Shake < 0.01f)
{
shakePosition = Vector2.Zero;
shakeTimer = 0.0f;
}
else
{
shakeTimer += deltaTime * 5.0f;
Vector2 noisePos = new Vector2((float)PerlinNoise.CalculatePerlin(shakeTimer, shakeTimer, 0) - 0.5f, (float)PerlinNoise.CalculatePerlin(shakeTimer, shakeTimer, 0.5f) - 0.5f);
shakePosition = noisePos * Shake * 2.0f;
Shake = MathHelper.Lerp(Shake, 0.0f, deltaTime * 2.0f);
}
Translate(moveCam + shakePosition);
Freeze = false;
}
public void StopMovement()
{
targetZoom = zoom;
velocity = Vector2.Zero;
angularVelocity = 0.0f;
rotation = 0.0f;
}
public Vector2 Position
{
get { return position; }
@@ -239,7 +372,7 @@ namespace Barotrauma
position = value;
}
}
public Vector2 ScreenToWorld(Vector2 coords)
{
Vector2 worldCoords = Vector2.Transform(coords, Matrix.Invert(transform));