Cut 5d-2: ParticlePool + OmniLight3D[4], CameraJuiceState, Hud hit-markers & vignette, unified SimEvent drain
This commit is contained in:
parent
7f811c3011
commit
323c02cf8d
12 changed files with 2294 additions and 320 deletions
117
tests/RustToDust.Tests/CameraJuiceTests.cs
Normal file
117
tests/RustToDust.Tests/CameraJuiceTests.cs
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
using RustToDust.Client;
|
||||
using RustToDust.Core;
|
||||
using Xunit;
|
||||
|
||||
namespace RustToDust.Tests;
|
||||
|
||||
public sealed class CameraJuiceTests
|
||||
{
|
||||
[Fact]
|
||||
public void CameraJuiceState_ZeroIdleJitter_AndMonotonicDecayToExactZero()
|
||||
{
|
||||
var juice = new CameraJuiceState();
|
||||
Assert.True(juice.IsIdle);
|
||||
|
||||
for (int i = 0; i < 60; i++)
|
||||
{
|
||||
juice.Update(1f / 60f, localSpeedMps: 5f, isVtol: false);
|
||||
juice.ComputeOffsets(out Vector3 off, out float pitch, out float yaw, out float roll);
|
||||
Assert.True(juice.IsIdle);
|
||||
Assert.Equal(Vector3.Zero, off);
|
||||
Assert.Equal(0f, pitch);
|
||||
Assert.Equal(0f, yaw);
|
||||
Assert.Equal(0f, roll);
|
||||
Assert.Equal(0f, juice.FovOffsetDeg);
|
||||
}
|
||||
|
||||
// Fire local recoilless shot
|
||||
var events = new List<ISimEvent>
|
||||
{
|
||||
new ShotFiredEvent
|
||||
{
|
||||
TracerId = 1,
|
||||
IsSpectatorShooter = false,
|
||||
ShooterId = 0,
|
||||
WeaponClass = (byte)WeaponVisualClass.Explosive,
|
||||
WeaponId = "recoilless"
|
||||
}
|
||||
};
|
||||
juice.ConsumeEvents(events, localContenderId: 0, Vector3.Zero);
|
||||
Assert.False(juice.IsIdle);
|
||||
Assert.True(juice.RecoilPitchRad > 0f);
|
||||
Assert.True(juice.RecoilBackMeters > 0f);
|
||||
Assert.True(juice.Trauma > 0f);
|
||||
|
||||
juice.ComputeOffsets(out Vector3 kickOff, out float kickPitch, out _, out _);
|
||||
Assert.True(kickOff.Z > 0f);
|
||||
Assert.True(kickPitch > 0f);
|
||||
|
||||
// Decays monotonically back to exact zero
|
||||
float prevPitch = juice.RecoilPitchRad;
|
||||
for (int i = 0; i < 120; i++)
|
||||
{
|
||||
juice.Update(1f / 60f, localSpeedMps: 0f, isVtol: false);
|
||||
Assert.True(juice.RecoilPitchRad <= prevPitch);
|
||||
prevPitch = juice.RecoilPitchRad;
|
||||
}
|
||||
|
||||
Assert.True(juice.IsIdle);
|
||||
juice.ComputeOffsets(out Vector3 settledOff, out float settledPitch, out float settledYaw, out float settledRoll);
|
||||
Assert.Equal(Vector3.Zero, settledOff);
|
||||
Assert.Equal(0f, settledPitch);
|
||||
Assert.Equal(0f, settledYaw);
|
||||
Assert.Equal(0f, settledRoll);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CameraJuiceState_IgnoresRemoteShots_ClampsTrauma_AndResetsCleanly()
|
||||
{
|
||||
var juice = new CameraJuiceState();
|
||||
|
||||
// Remote contender or spectator shot must NOT kick local camera
|
||||
var remoteEvents = new List<ISimEvent>
|
||||
{
|
||||
new ShotFiredEvent
|
||||
{
|
||||
TracerId = 10,
|
||||
IsSpectatorShooter = false,
|
||||
ShooterId = 3,
|
||||
WeaponClass = (byte)WeaponVisualClass.Explosive,
|
||||
WeaponId = "recoilless"
|
||||
},
|
||||
new ShotFiredEvent
|
||||
{
|
||||
TracerId = 11,
|
||||
IsSpectatorShooter = true,
|
||||
ShooterId = 0,
|
||||
WeaponClass = (byte)WeaponVisualClass.Explosive,
|
||||
WeaponId = "recoilless"
|
||||
}
|
||||
};
|
||||
juice.ConsumeEvents(remoteEvents, localContenderId: 0, new Vector3(100f, 0f, 100f));
|
||||
Assert.True(juice.IsIdle);
|
||||
|
||||
// Clamp trauma to [0, 1]
|
||||
juice.AddTrauma(5.0f);
|
||||
Assert.Equal(1.0f, juice.Trauma);
|
||||
|
||||
// Footstep bump triggers only for local contender
|
||||
var steps = new List<FootstepPulse>
|
||||
{
|
||||
new(true, 2, 0, "bastion", 4600f, 1.2f, Vector3.Zero),
|
||||
new(true, 0, 0, "bastion", 4600f, 1.2f, Vector3.Zero)
|
||||
};
|
||||
juice.ConsumeFootsteps(steps, localContenderId: 0);
|
||||
Assert.True(juice.FootstepBumpY < 0f);
|
||||
|
||||
// Reset zeroes everything immediately
|
||||
juice.Reset();
|
||||
Assert.True(juice.IsIdle);
|
||||
Assert.Equal(0f, juice.Trauma);
|
||||
Assert.Equal(0f, juice.FootstepBumpY);
|
||||
Assert.Equal(0f, juice.FovOffsetDeg);
|
||||
}
|
||||
}
|
||||
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\..\client\WalkerFootstepTracker.cs" Link="Client\WalkerFootstepTracker.cs" />
|
||||
<Compile Include="..\..\client\CameraJuiceState.cs" Link="Client\CameraJuiceState.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
Loading…
Reference in a new issue