Sync daemon authority migration
This commit is contained in:
parent
030b4b5d74
commit
39a0dc8737
295 changed files with 25121 additions and 7360 deletions
|
|
@ -7,15 +7,17 @@ using System.Collections;
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using CultMath;
|
||||
using UniRx;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
using quaternion = Unity.Mathematics.quaternion;
|
||||
using static CultMath.math;
|
||||
using cfloat2 = CultMath.float2;
|
||||
using cfloat3 = CultMath.float3;
|
||||
using cquaternion = CultMath.quaternion;
|
||||
|
||||
public class Ship : Entity
|
||||
{
|
||||
public Entity HomeEntity;
|
||||
public float2 MovementDirection;
|
||||
public cfloat2 MovementDirection;
|
||||
public bool IsPlayerShip;
|
||||
|
||||
private HashSet<EquippedItem> _thrusterItems;
|
||||
|
|
@ -32,10 +34,10 @@ public class Ship : Entity
|
|||
private bool _exitingWormhole = false;
|
||||
private bool _enteringWormhole = false;
|
||||
private float _wormholeAnimationProgress;
|
||||
private float2 _wormholeEntryPosition;
|
||||
private float2 _wormholeEntryDirection;
|
||||
private float2 _wormholePosition;
|
||||
private float2 _wormholeExitVelocity;
|
||||
private cfloat2 _wormholeEntryPosition;
|
||||
private cfloat2 _wormholeEntryDirection;
|
||||
private cfloat2 _wormholePosition;
|
||||
private cfloat2 _wormholeExitVelocity;
|
||||
|
||||
public bool WormholeAnimationInProgress => _enteringWormhole || _exitingWormhole;
|
||||
public float ForwardThrust { get; private set; }
|
||||
|
|
@ -49,35 +51,40 @@ public class Ship : Entity
|
|||
public float RightStrafeTotalTorque { get; private set; }
|
||||
private List<Thruster> RightStrafeTorqueThrusters = new List<Thruster>();
|
||||
|
||||
public float TurnTime(float2 direction)
|
||||
public float TurnTime(cfloat2 direction)
|
||||
{
|
||||
var angleDiff = Direction.Angle(normalize(direction));
|
||||
var clockwise = dot(direction, Direction.Rotate(ItemRotation.Clockwise)) > 0;
|
||||
var cultDirection = normalize(direction);
|
||||
var shipDirection = CultDirection;
|
||||
var angleDiff = AetheriaMath.AngleDegrees(shipDirection, cultDirection);
|
||||
var clockwise = dot(cultDirection, AetheriaMath.Rotate(shipDirection, ItemRotation.Clockwise)) > 0;
|
||||
return angleDiff / ((clockwise ? ClockwiseTorque : CounterClockwiseTorque) / Mass);
|
||||
}
|
||||
|
||||
public event Action OnExitedWormhole;
|
||||
public event Action OnEnteredWormhole;
|
||||
|
||||
public quaternion Rotation { get; private set; }
|
||||
public cquaternion Rotation { get; private set; }
|
||||
|
||||
public void ExitWormhole(float2 wormholePosition, float2 exitVelocity)
|
||||
private static cquaternion LookRotation(cfloat3 forward, cfloat3 up) =>
|
||||
cquaternion.LookRotation(forward, up);
|
||||
|
||||
public void ExitWormhole(cfloat2 wormholePosition, cfloat2 exitVelocity)
|
||||
{
|
||||
_exitingWormhole = true;
|
||||
_wormholeAnimationProgress = 0;
|
||||
_wormholePosition = wormholePosition;
|
||||
_wormholeExitVelocity = exitVelocity;
|
||||
Direction = normalize(exitVelocity);
|
||||
CultDirection = normalize(_wormholeExitVelocity);
|
||||
}
|
||||
|
||||
public void EnterWormhole(float2 wormholePosition)
|
||||
public void EnterWormhole(cfloat2 wormholePosition)
|
||||
{
|
||||
Target.Value = null;
|
||||
_wormholeAnimationProgress = 0;
|
||||
_enteringWormhole = true;
|
||||
_wormholeEntryPosition = Position.xz;
|
||||
_wormholeEntryDirection = normalize(_wormholeEntryPosition-wormholePosition);
|
||||
_wormholeEntryPosition = CultPositionXZ;
|
||||
_wormholePosition = wormholePosition;
|
||||
_wormholeEntryDirection = normalize(_wormholeEntryPosition - _wormholePosition);
|
||||
}
|
||||
|
||||
public override void Activate()
|
||||
|
|
@ -245,33 +252,35 @@ public class Ship : Entity
|
|||
{
|
||||
RecalculateThrust();
|
||||
foreach (var thruster in _allThrusters) thruster.Axis = 0;
|
||||
var movementDirection = MovementDirection;
|
||||
var rightThrusterTorqueCompensation = abs(RightStrafeTotalTorque) / RightStrafeTorqueThrusters.Count;
|
||||
foreach (var thruster in _rightThrusters)
|
||||
{
|
||||
var thrust = 0f;
|
||||
thrust += MovementDirection.x;
|
||||
thrust += movementDirection.x;
|
||||
if (RightStrafeTorqueThrusters.Contains(thruster))
|
||||
thrust -= MovementDirection.x * (rightThrusterTorqueCompensation / (abs(thruster.Torque) * thruster.Thrust));
|
||||
thrust -= movementDirection.x * (rightThrusterTorqueCompensation / (abs(thruster.Torque) * thruster.Thrust));
|
||||
thruster.Axis = thrust;
|
||||
}
|
||||
var leftThrusterTorqueCompensation = abs(LeftStrafeTotalTorque) / LeftStrafeTorqueThrusters.Count;
|
||||
foreach (var thruster in _leftThrusters)
|
||||
{
|
||||
var thrust = 0f;
|
||||
thrust += -MovementDirection.x;
|
||||
thrust += -movementDirection.x;
|
||||
if (LeftStrafeTorqueThrusters.Contains(thruster))
|
||||
thrust += MovementDirection.x * (leftThrusterTorqueCompensation / (abs(thruster.Torque) * thruster.Thrust));
|
||||
thrust += movementDirection.x * (leftThrusterTorqueCompensation / (abs(thruster.Torque) * thruster.Thrust));
|
||||
thruster.Axis = thrust;
|
||||
}
|
||||
foreach (var thruster in _forwardThrusters) thruster.Axis += MovementDirection.y;
|
||||
foreach (var thruster in _reverseThrusters) thruster.Axis += -MovementDirection.y;
|
||||
foreach (var thruster in _forwardThrusters) thruster.Axis += movementDirection.y;
|
||||
foreach (var thruster in _reverseThrusters) thruster.Axis += -movementDirection.y;
|
||||
|
||||
var look = normalize(LookDirection.xz);
|
||||
var deltaRot = dot(look, normalize(Direction).Rotate(ItemRotation.Clockwise));
|
||||
var look = normalize(CultLookDirectionXZ);
|
||||
var shipDirection = normalize(CultDirection);
|
||||
var deltaRot = dot(look, AetheriaMath.Rotate(shipDirection, ItemRotation.Clockwise));
|
||||
if (abs(deltaRot) < .01f)
|
||||
{
|
||||
deltaRot = 0;
|
||||
Direction = lerp(Direction, look, min(delta, 1));
|
||||
CultDirection = lerp(shipDirection, look, min(delta, 1));
|
||||
}
|
||||
deltaRot = pow(abs(deltaRot), .5f) * sign(deltaRot);
|
||||
|
||||
|
|
@ -279,58 +288,60 @@ public class Ship : Entity
|
|||
foreach (var thruster in _counterClockwiseThrusters) thruster.Axis += -deltaRot;
|
||||
|
||||
foreach (var drive in _aetherDrives)
|
||||
drive.Axis = float3(MovementDirection.y, MovementDirection.x, deltaRot);
|
||||
drive.Axis = new cfloat3(movementDirection.y, movementDirection.x, deltaRot);
|
||||
}
|
||||
|
||||
var velocityMagnitude = length(Velocity);
|
||||
var velocity = CultVelocity;
|
||||
var velocityMagnitude = length(velocity);
|
||||
if(velocityMagnitude > .01f)
|
||||
Velocity = normalize(Velocity) * AetheriaMath.Decay(velocityMagnitude, (float)(ItemManager.GetRuntimeItem(Hull)?.HullDrag ?? 0), delta);
|
||||
CultVelocity = normalize(velocity) * AetheriaMath.Decay(velocityMagnitude, (float)(ItemManager.GetRuntimeItem(Hull)?.HullDrag ?? 0), delta);
|
||||
|
||||
Position.xz += Velocity * delta;
|
||||
CultPositionXZ += CultVelocity * delta;
|
||||
|
||||
var normal = Zone.GetNormal(Position.xz);
|
||||
var force = new float2(normal.x, normal.z);
|
||||
var normal = Zone.GetNormal(CultPositionXZ);
|
||||
var force = new cfloat2(normal.x, normal.z);
|
||||
var forceMagnitude = lengthsq(force);
|
||||
if (forceMagnitude > .001f)
|
||||
{
|
||||
var fa = 1 / (1 - forceMagnitude) - 1;
|
||||
Velocity += normalize(force) * Zone.Settings.GravityStrength * fa;
|
||||
CultVelocity += normalize(force) * Zone.Settings.GravityStrength * fa;
|
||||
}
|
||||
var shipRight = Direction.Rotate(ItemRotation.Clockwise);
|
||||
var forward = cross(float3(shipRight.x, 0, shipRight.y), normal);
|
||||
Rotation = quaternion.LookRotation(forward, normal);
|
||||
var shipRight = AetheriaMath.Rotate(CultDirection, ItemRotation.Clockwise);
|
||||
var forward = cross(new cfloat3(shipRight.x, 0, shipRight.y), normal);
|
||||
Rotation = LookRotation(forward, normal);
|
||||
|
||||
base.Update(delta);
|
||||
|
||||
if (_exitingWormhole)
|
||||
{
|
||||
var inverseDirection = new cfloat3(-CultDirection.x, 0, -CultDirection.y);
|
||||
_wormholeAnimationProgress += delta / ItemManager.GameplaySettings.WormholeAnimationDuration;
|
||||
if(_wormholeAnimationProgress < 1)
|
||||
{
|
||||
if (_wormholeAnimationProgress < ItemManager.GameplaySettings.WormholeExitCurveStart)
|
||||
{
|
||||
Position.xz = _wormholePosition;
|
||||
Rotation = quaternion.LookRotation(float3(0, 1, 0), float3(-Direction.x, 0, -Direction.y));
|
||||
CultPositionXZ = _wormholePosition;
|
||||
Rotation = LookRotation(new cfloat3(0, 1, 0), inverseDirection);
|
||||
}
|
||||
else
|
||||
{
|
||||
var exitLerp = (_wormholeAnimationProgress - ItemManager.GameplaySettings.WormholeExitCurveStart) /
|
||||
(1 - ItemManager.GameplaySettings.WormholeExitCurveStart);
|
||||
exitLerp = AetheriaMath.Smootherstep(exitLerp); // Square the interpolation variable to produce curve with zero slope at start
|
||||
Position.xz = _wormholePosition + normalize(_wormholeExitVelocity) * exitLerp * ItemManager.GameplaySettings.WormholeExitRadius;
|
||||
Rotation = quaternion.LookRotation(
|
||||
lerp(float3(0, 1, 0), forward, exitLerp),
|
||||
lerp(float3(-Direction.x, 0, -Direction.y), normal, exitLerp));
|
||||
CultPositionXZ = _wormholePosition + normalize(_wormholeExitVelocity) * exitLerp * ItemManager.GameplaySettings.WormholeExitRadius;
|
||||
Rotation = LookRotation(
|
||||
lerp(new cfloat3(0, 1, 0), forward, exitLerp),
|
||||
lerp(inverseDirection, normal, exitLerp));
|
||||
}
|
||||
|
||||
Position.y = Position.y - lerp(ItemManager.GameplaySettings.WormholeDepth, 0, _wormholeAnimationProgress);
|
||||
CultPositionY -= lerp(ItemManager.GameplaySettings.WormholeDepth, 0, _wormholeAnimationProgress);
|
||||
}
|
||||
else
|
||||
{
|
||||
_exitingWormhole = false;
|
||||
OnExitedWormhole?.Invoke();
|
||||
OnExitedWormhole = null;
|
||||
Velocity = _wormholeExitVelocity;
|
||||
CultVelocity = _wormholeExitVelocity;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -343,19 +354,19 @@ public class Ship : Entity
|
|||
{
|
||||
var enterLerp = _wormholeAnimationProgress / (1 - ItemManager.GameplaySettings.WormholeExitCurveStart);
|
||||
enterLerp = AetheriaMath.Smootherstep(enterLerp); // Square the interpolation variable to produce curve with zero slope at vertical
|
||||
Position.xz = lerp(_wormholeEntryPosition, _wormholePosition, enterLerp);
|
||||
Rotation = quaternion.LookRotation(
|
||||
lerp(forward, float3(0, -1, 0), enterLerp),
|
||||
lerp(normal, float3(-_wormholeEntryDirection.x, 0, -_wormholeEntryDirection.y), enterLerp));
|
||||
CultPositionXZ = lerp(_wormholeEntryPosition, _wormholePosition, enterLerp);
|
||||
Rotation = LookRotation(
|
||||
lerp(forward, new cfloat3(0, -1, 0), enterLerp),
|
||||
lerp(normal, new cfloat3(-_wormholeEntryDirection.x, 0, -_wormholeEntryDirection.y), enterLerp));
|
||||
}
|
||||
else
|
||||
{
|
||||
Position.xz = _wormholePosition;
|
||||
Rotation = quaternion.LookRotation(float3(0, -1, 0),
|
||||
float3(-_wormholeEntryDirection.x, 0, -_wormholeEntryDirection.y));
|
||||
CultPositionXZ = _wormholePosition;
|
||||
Rotation = LookRotation(new cfloat3(0, -1, 0),
|
||||
new cfloat3(-_wormholeEntryDirection.x, 0, -_wormholeEntryDirection.y));
|
||||
}
|
||||
|
||||
Position.y = Position.y - lerp(0, ItemManager.GameplaySettings.WormholeDepth, _wormholeAnimationProgress);
|
||||
CultPositionY -= lerp(0, ItemManager.GameplaySettings.WormholeDepth, _wormholeAnimationProgress);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue