Compose source body physics and enable tutorial static response
This commit is contained in:
1 parent
df0263b26e
commit
35a2a66606
26 files changed
+1045
-18
No files matched your search
@@ -9,7 +9,7 @@ public enum PlayerPose { Idle, Run, Backpedal, Jump, Fall, Fly }
|
||||
|
||||
/// <summary>
|
||||
/// Walking, airborne steering and jetpack checkpoint. Recovered arithmetic is described in
|
||||
/// movement-checkpoint.md. Capsule, floor-derived pivot and 60Hz are port policies;
|
||||
/// movement-checkpoint.md. Legacy capsule, floor-derived pivot and60Hz are port policies;
|
||||
/// original collision, intro, object interactions and animation timing remain open.
|
||||
/// </summary>
|
||||
public sealed class LabSimulation
|
||||
@@ -18,6 +18,7 @@ public sealed class LabSimulation
|
||||
private readonly SceneCollision collision;
|
||||
private readonly Func<Vector3, Vector3, SupportHit?>? cameraRay;
|
||||
private readonly Func<Vector3, Vector3, SupportHit?>? ceilingRay;
|
||||
private readonly OriginalBodyPhysics? originalBody;
|
||||
private readonly Vector3 sourceStart;
|
||||
private readonly float startYaw, modelMinimumY, rootHeight, startFloor;
|
||||
private float targetYaw, extraAirAcceleration, shadowDistance, lateralContribution;
|
||||
@@ -34,6 +35,8 @@ public sealed class LabSimulation
|
||||
public string LevelCode { get; set; } = "LV1B";
|
||||
public int GadgetMode { get; set; } = -1;
|
||||
public float Energy { get; set; } = 20;
|
||||
//Source260/live15C serves both body collision and contact tests. The name
|
||||
//predates source-body integration; burst100 is not an interaction-only size.
|
||||
public float InteractionRadius { get; private set; } = 60;
|
||||
public bool JetpackEffectVisible { get; private set; }
|
||||
public float JetpackRemaining => jumpState.EffectRemaining;
|
||||
@@ -50,6 +53,8 @@ public sealed class LabSimulation
|
||||
public bool InputAfterPlayerUpdate { get; set; }
|
||||
public float Yaw { get; private set; }
|
||||
public float Speed { get; private set; }
|
||||
public float PublishedSpeed { get; private set; }
|
||||
public bool UsesOriginalBody => originalBody != null;
|
||||
public float TurnRate { get; private set; }
|
||||
public bool Grounded { get; private set; }
|
||||
public PlayerPose Pose => Noclip ? Velocity.LengthSquared() > 0 ? PlayerPose.Fly : PlayerPose.Idle
|
||||
@@ -76,11 +81,13 @@ public sealed class LabSimulation
|
||||
|
||||
public LabSimulation(SceneCollision collision, Mesh standingPose, Vector3 start, float yaw,
|
||||
Func<Vector3, Vector3, SupportHit?>? cameraRay = null,
|
||||
Func<Vector3, Vector3, SupportHit?>? ceilingRay = null)
|
||||
Func<Vector3, Vector3, SupportHit?>? ceilingRay = null,
|
||||
OriginalStaticCollision? originalCollision = null)
|
||||
{
|
||||
this.collision = collision;
|
||||
this.cameraRay = cameraRay;
|
||||
this.ceilingRay = ceilingRay;
|
||||
originalBody = originalCollision == null ? null : new OriginalBodyPhysics(originalCollision);
|
||||
sourceStart = start;
|
||||
startYaw = yaw;
|
||||
var bounds = standingPose.Bounds();
|
||||
@@ -99,10 +106,10 @@ public sealed class LabSimulation
|
||||
public void Reset()
|
||||
{
|
||||
var floor = collision.GroundHeight(sourceStart, 2500)!.Value;
|
||||
Position = new(sourceStart.X, floor + SceneCollision.Skin, sourceStart.Z);
|
||||
Position = new(sourceStart.X, floor + (UsesOriginalBody ? 0 : SceneCollision.Skin), sourceStart.Z);
|
||||
Velocity = Vector3.Zero;
|
||||
Yaw = targetYaw = startYaw;
|
||||
Speed = TurnRate = extraAirAcceleration = shadowDistance = 0;
|
||||
Speed = PublishedSpeed = TurnRate = extraAirAcceleration = shadowDistance = 0;
|
||||
lateralContribution = 0; pendingImpulse = Vector3.Zero; movementMode = 0;
|
||||
jumpState = default;
|
||||
forceFall = JetpackEffectVisible = false;
|
||||
@@ -222,7 +229,7 @@ public sealed class LabSimulation
|
||||
public void StopDebugMotion()
|
||||
{
|
||||
Velocity = pendingImpulse = Vector3.Zero;
|
||||
Speed = TurnRate = extraAirAcceleration = lateralContribution = 0;
|
||||
Speed = PublishedSpeed = TurnRate = extraAirAcceleration = lateralContribution = 0;
|
||||
jumpState = default; movementMode = 0; forceFall = JetpackEffectVisible = false;
|
||||
targetYaw = Yaw;
|
||||
}
|
||||
@@ -316,12 +323,18 @@ public sealed class LabSimulation
|
||||
else if (air.Pose is JetpackPose.Jump or JetpackPose.Fly) forceFall = false;
|
||||
if (air.StartGadget) Bursts++;
|
||||
Velocity = velocity; // Produced body state is consumed by the next physics pass.
|
||||
PublishedSpeed = Speed; //437C22..437C2D: controller608 -> body160.
|
||||
}
|
||||
|
||||
private void StepPhysics()
|
||||
{
|
||||
PhysicsSteps++;
|
||||
const float dt = FixedStepClock.Step;
|
||||
if (originalBody != null)
|
||||
{
|
||||
StepOriginalPhysics();
|
||||
return;
|
||||
}
|
||||
var wasGrounded = Grounded;
|
||||
var velocity = Velocity;
|
||||
// Keep the existing capsule/gravity adapter until C4 recovers Jimmy's
|
||||
@@ -355,6 +368,25 @@ public sealed class LabSimulation
|
||||
MaximumRise = Math.Max(MaximumRise, Position.Y - startFloor);
|
||||
}
|
||||
|
||||
private void StepOriginalPhysics()
|
||||
{
|
||||
if (DynamicRootResolver != null)
|
||||
throw new NotSupportedException("Original ordinary-body subset cannot use the provisional dynamic resolver");
|
||||
var before = Position;
|
||||
var result = originalBody!.Step(new(ActorRoot, Velocity, Vector3.UnitY * extraAirAcceleration,
|
||||
pendingImpulse, Grounded, PublishedSpeed), FixedStepClock.Step, InteractionRadius);
|
||||
Position = result.Body.Position - Vector3.UnitY * rootHeight;
|
||||
Velocity = result.Body.Velocity;
|
||||
pendingImpulse = result.Body.Impulse;
|
||||
extraAirAcceleration = result.Body.Acceleration.Y;
|
||||
Grounded = result.Body.Supported;
|
||||
if (Grounded) forceFall = false;
|
||||
if (result.Landing != null) Landings++;
|
||||
if (result.Contact is { StoredNormal.Y: > -.7f }) WallHits++;
|
||||
Travel += Vector2.Distance(new(before.X, before.Z), new(Position.X, Position.Z));
|
||||
MaximumRise = Math.Max(MaximumRise, Position.Y - startFloor);
|
||||
}
|
||||
|
||||
private void StepCamera()
|
||||
{
|
||||
const float dt = FixedStepClock.Step;
|
||||
@@ -383,5 +415,5 @@ public sealed class LabSimulation
|
||||
step is >= 80 and < 120, step is >= 60 and < 95, false, step < 180);
|
||||
|
||||
public bool SmokePassed => Steps >= 240 && Travel > 50 && MaximumRise > 20 && Jumps > 0 && Landings > 0 && Grounded;
|
||||
public string Report => $"Walk checkpoint: steps={Steps}, controller={ControllerSteps}, physics={PhysicsSteps}, effect={EffectSteps}, travel={Travel:F2}, jumps={Jumps}, landings={Landings}, max rise={MaximumRise:F2}, wall hits={WallHits}, ceiling hits={CeilingHits}, grounded={Grounded}, feet={Position}.";
|
||||
public string Report => $"Walk checkpoint: steps={Steps}, controller={ControllerSteps}, physics={PhysicsSteps}, effect={EffectSteps}, travel={Travel:F2}, jumps={Jumps}, landings={Landings}, max rise={MaximumRise:F2}, wall hits={WallHits}, ceiling hits={CeilingHits}, grounded={Grounded}, feet={Position}, body={(UsesOriginalBody ? "source ordinary" : "provisional capsule")}.";
|
||||
}
|
||||
Reference in new issue
Block a user