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
@@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup><OutputType>Exe</OutputType><TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings><Nullable>enable</Nullable>
|
||||
<EnableDefaultCompileItems>false</EnableDefaultCompileItems></PropertyGroup>
|
||||
<ItemGroup><Compile Include="Program.cs" />
|
||||
<Compile Include="../../src/GamePort/Assets/*.cs" />
|
||||
<Compile Include="../../src/GamePort/Game/*.cs" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,123 @@
|
||||
using System.Numerics;
|
||||
using GamePort.Game;
|
||||
using GamePort.Assets;
|
||||
|
||||
void Check(bool value, string message) { if (!value) throw new Exception(message); }
|
||||
void Near(Vector3 actual, Vector3 expected, string message) =>
|
||||
Check(Vector3.Distance(actual,expected)<.002f,$"{message}: {actual} != {expected}");
|
||||
var floor=new CameraRayPolygon(new(new(-1000,0,-1000),new(1000,0,-1000),new(0,0,1000)),Vector3.UnitY);
|
||||
var physics=new OriginalBodyPhysics(new([floor]));
|
||||
OrdinaryBodyState Initial() => new(new(0,75.9f,0),Vector3.Zero,Vector3.Zero,Vector3.Zero);
|
||||
// References observed from copied479D20/support, body-probe/wine.log.
|
||||
var cases=new (string Name,OrdinaryBodyState Input,Vector3 Position,Vector3 Velocity,float AngularY,bool Supported,float? LandingY,bool Geometry)[] {
|
||||
("floor_support",Initial(),new(0,75.9000015f,0),Vector3.Zero,0,true,-13.333334f,true),
|
||||
("spawn_settle",Initial() with {Position=new(0,26,0)},new(0,75.9000015f,0),Vector3.Zero,0,true,-13.333334f,true),
|
||||
("pending_jump",Initial() with {Supported=true,Impulse=new(0,550,0),Acceleration=new(0,-264,0)},new(0,84.7711105f,0),new(0,532.266663f,0),0,false,null,true),
|
||||
("fall_above_floor",Initial() with {Position=new(0,100,0),Velocity=new(0,-200,0)},new(0,96.4444427f,0),new(0,-213.333328f,0),0,false,null,true),
|
||||
("fall_land",Initial() with {Position=new(0,76,0),Velocity=new(0,-200,0)},new(0,75.9000015f,0),Vector3.Zero,0,true,-213.333328f,true),
|
||||
("ground_friction",Initial() with {Velocity=new(100,0,50),AngularVelocity=new(0,12,0)},new(1.66666675f,75.9000015f,.833333373f),new(98.6666641f,0,49.3333321f),11.8400002f,true,-13.333334f,true),
|
||||
("published_speed",Initial() with {Velocity=new(100,0,50),AngularVelocity=new(0,12,0),PublishedSpeed=100},new(1.66666675f,75.9000015f,.833333373f),new(100,0,50),12,true,-13.333334f,true),
|
||||
("stationary_angular",Initial() with {AngularVelocity=new(0,12,0)},new(0,75.9000015f,0),Vector3.Zero,12,true,-13.333334f,true),
|
||||
("small_motion",Initial() with {Velocity=new(.125f,0,0)},new(.00208333344f,75.9000015f,0),Vector3.Zero,0,true,-13.333334f,true),
|
||||
("geometry_disabled",Initial() with {Velocity=new(0,200,0),Acceleration=new(0,-264,0)},new(0,75.9000015f,0),Vector3.Zero,0,true,null,false)
|
||||
};
|
||||
foreach(var test in cases)
|
||||
{
|
||||
var result=physics.Step(test.Input,1f/60,geometryEnabled:test.Geometry);
|
||||
Near(result.Body.Position,test.Position,$"{test.Name} root");
|
||||
Near(result.Body.Velocity,test.Velocity,$"{test.Name} velocity");
|
||||
Near(result.Body.AngularVelocity,new(0,test.AngularY,0),$"{test.Name} angular velocity");
|
||||
Near(result.Body.Impulse,Vector3.Zero,$"{test.Name} consumes impulse");
|
||||
var expectedAcceleration=test.Geometry ? test.Supported ? Vector3.Zero : test.Input.Acceleration : new Vector3(0,800,0);
|
||||
Near(result.Body.Acceleration,expectedAcceleration,$"{test.Name} acceleration");
|
||||
Check(result.Body.Supported==test.Supported && result.Landing.HasValue==test.LandingY.HasValue,$"{test.Name} support/landing");
|
||||
if(test.LandingY is {} vy)
|
||||
{
|
||||
var observation=result.Landing!.Value;
|
||||
Check(!observation.Supported && MathF.Abs(observation.Velocity.Y-vy)<.002f,$"{test.Name} callback sees old velocity/support");
|
||||
Check(observation.Acceleration.Y==0 && observation.Position==result.Body.Position,$"{test.Name} callback sees new root/acceleration");
|
||||
}
|
||||
Console.WriteLine($"PASS original ordinary-body reference {test.Name}");
|
||||
}
|
||||
var resting=physics.Step(Initial() with {Supported=true},1f/60);
|
||||
Check(resting.Body.Supported && resting.Landing==null,"already supported must not emit landing37C again");
|
||||
Console.WriteLine("PASS prior support suppresses repeated landing callback");
|
||||
var empty=new OriginalBodyPhysics(new([]));
|
||||
var rotation=empty.Step(Initial() with {AngularVelocity=new(0,.1f,0)},.5f);
|
||||
Near(rotation.Body.Rotation,new(0,.05f,0),"rotation is integrated before small angular motion is suppressed");
|
||||
Check(rotation.Body.AngularVelocity==Vector3.Zero,"small angular suppression");
|
||||
var moving=empty.Step(Initial() with {Velocity=new(.125f,0,0),PublishedSpeed=1},1f/60,geometryEnabled:false);
|
||||
Check(moving.Body.Velocity.X!=0,"nonzero published speed suppresses friction and small linear cutoff");
|
||||
Console.WriteLine("PASS angular integration and independent published speed cutoff");
|
||||
try { new OriginalBodyPhysics(new([floor with {StoredNormal=Vector3.UnitZ,MaterialId=61}]));
|
||||
throw new Exception("unsupported special contacts accepted"); }
|
||||
catch(NotSupportedException) { }
|
||||
Console.WriteLine("PASS unsupported special-contact scene rejected");
|
||||
var falling=empty.Step(Initial(),1f/60);
|
||||
var rising=empty.Step(Initial() with {Impulse=new(0,550,0)},1f/60);
|
||||
Check(falling.CollisionPasses==0 && rising.CollisionPasses==1,
|
||||
"falling vertical motion is added after horizontal dispatcher; rising motion is dispatched whole");
|
||||
Console.WriteLine("PASS positive-Y versus horizontal-first split");
|
||||
var ceiling=new CameraRayPolygon(new(new(-100,100,-100),new(100,100,100),new(100,100,-100)), -Vector3.UnitY);
|
||||
var roof=new OriginalBodyPhysics(new([ceiling]));
|
||||
var roofHit=roof.Step(new(new(0,80,0),new(0,920,0),new(0,100,0),Vector3.Zero),1f/60,10,1);
|
||||
Near(roofHit.Body.Position,new(0,90,0),"ceiling candidate published after terminal callback370");
|
||||
Check(roofHit.Contact==ceiling && roofHit.Body.Velocity.Y==0 && roofHit.Body.Acceleration.Y==0,
|
||||
"370 clears positive vertical velocity and acceleration without landing");
|
||||
Check(!roofHit.Body.Supported && roofHit.Landing==null,"ceiling does not invent floor support");
|
||||
Console.WriteLine("PASS composed ceiling370 and support ownership");
|
||||
var wide=physics.Step(Initial(),1f/60,100);
|
||||
Near(wide.Body.Position,new(0,126.5f,0),"live radius100 changes support offset as well as collision");
|
||||
var unclamped=empty.Step(Initial() with {Velocity=new(100,0,0)},.5f,friction:4,geometryEnabled:false);
|
||||
Near(unclamped.Body.Velocity,new(-100,0,0),"source friction multiplier is not clamped");
|
||||
Console.WriteLine("PASS radius-dependent support and unclamped friction");
|
||||
var original=Path.GetFullPath(args.Length==1?args[0]:"../Original");
|
||||
var world=Mesh.LoadSceneJson("artifacts/extracted/VR04/scene.json");
|
||||
var level=GamLevel.Load(AssetPath.Resolve(original,"gam/VR04.gam"));
|
||||
var start=level.FindStart()!;
|
||||
var standing=AseMesh.Load(AssetPath.Resolve(original,"ASE/jimstop.ase"));
|
||||
var geometry=OriginalCameraRay.FromRouteScene(world,"VR04");
|
||||
LabSimulation Simulation(bool retained=false) => new(new(world),standing,start.Position,start.Rotation.Y,
|
||||
(a,b)=>geometry.Trace(a,b),(a,b)=>geometry.TraceGeometry(a,b),OriginalStaticCollision.FromRouteScene(world,"VR04"))
|
||||
{LevelCode="VR04",InputAfterPlayerUpdate=retained};
|
||||
var player=Simulation();
|
||||
Check(player.UsesOriginalBody && player.PublishedSpeed==0,"tutorial explicitly selects source body");
|
||||
for(var i=0;i<120;i++)player.Step(default);
|
||||
Check(player.Grounded && player.Landings==0,"steady source support must not chatter");
|
||||
var sole=standing.Vertices.Min(v=>Vector3.Transform(v.Position,player.Model).Y);
|
||||
Check(MathF.Abs(sole-player.Position.Y)<.001f,"modern sole/root render bridge remains explicit and stable");
|
||||
var rootBefore=player.ActorRoot;
|
||||
player.Step(new(false,false,false,false,true));
|
||||
Check(player.PendingImpulse.Y==550 && player.Grounded,"controller queues takeoff after body");
|
||||
player.Step(default,false);
|
||||
Check(player.PendingImpulse==Vector3.Zero && !player.Grounded && player.ActorRoot.Y>rootBefore.Y
|
||||
&& player.ControllerSteps==121 && player.PhysicsSteps==122,"body consumes jump without control ownership");
|
||||
Console.WriteLine("PASS tutorial root/visual bridge and control-independent pending jump");
|
||||
player=Simulation();
|
||||
for(var i=0;i<8;i++)player.Step(new(true,false,false,false,false));
|
||||
var published=player.PublishedSpeed;
|
||||
Check(published>0 && published==player.Speed,"controlled tail publishes controller speed");
|
||||
player.PrepareForScript();
|
||||
Check(player.Speed==0 && player.PublishedSpeed==published,"preparation preserves previously published speed160");
|
||||
player.Step(default,false);
|
||||
Check(player.PublishedSpeed==published,"raw control gate prevents new publication");
|
||||
player.Step(default);
|
||||
Check(player.PublishedSpeed==player.Speed,"resumed controlled tail publishes again");
|
||||
Console.WriteLine("PASS tutorial published speed/preparation/control boundaries");
|
||||
player=Simulation(true);
|
||||
Check(player.ApplyRetainedLevelState(new("LV1B",3,1,.6f,4)),"retained tutorial scalar state accepted");
|
||||
Check(player.PublishedSpeed==0 && player.Velocity==Vector3.Zero,"scene Init resets published body/controller motion");
|
||||
for(var i=0;i<300;i++)player.Step(LabSimulation.JetpackSmokeInput(i));
|
||||
Check(player.Bursts>0 && player.Travel>50 && player.MaximumRise>100 && player.Energy==20,
|
||||
"retained input ordering keeps powered steering and VR04 energy exemption");
|
||||
Check(player.Grounded && player.Landings>0,"source tutorial powered flight returns to support");
|
||||
Console.WriteLine("PASS retained tutorial jetpack/steering/landing phases");
|
||||
player=Simulation();
|
||||
player.SetNoclip(true);
|
||||
player.Step(new(false,false,false,false,false,Rise:true));
|
||||
var physicsSteps=player.PhysicsSteps;
|
||||
player.SetNoclip(false);
|
||||
player.Step(default,false);
|
||||
Check(player.PhysicsSteps==physicsSteps+1 && player.PublishedSpeed==0,"modern noclip exits into source body with cleared motion");
|
||||
Console.WriteLine("PASS tutorial noclip returns to source body");
|
||||
Console.WriteLine("Ordinary body:20 groups passed; dynamic actors and special Player contacts remain separate.");
|
||||
@@ -9,6 +9,10 @@
|
||||
<Compile Include="../../src/GamePort/Game/TaskActivation.cs"/>
|
||||
<Compile Include="../../src/GamePort/Game/TaskStates.cs"/>
|
||||
<Compile Include="../../src/GamePort/Game/LabSimulation.cs"/>
|
||||
<Compile Include="../../src/GamePort/Game/OriginalBodyPhysics.cs"/>
|
||||
<Compile Include="../../src/GamePort/Game/OriginalStaticCollision.cs"/>
|
||||
<Compile Include="../../src/GamePort/Game/OriginalSphereResponse.cs"/>
|
||||
<Compile Include="../../src/GamePort/Game/OriginalCameraRay.cs"/>
|
||||
<Compile Include="../../src/GamePort/Game/PlayerLevelState.cs"/>
|
||||
<Compile Include="../../src/GamePort/Game/AirSteering.cs"/>
|
||||
<Compile Include="../../src/GamePort/Game/JetpackBurst.cs"/>
|
||||
|
||||
@@ -13,6 +13,10 @@
|
||||
<Compile Include="../../src/GamePort/Game/TaskStates.cs"/>
|
||||
<Compile Include="../../src/GamePort/Game/TaskActivation.cs"/>
|
||||
<Compile Include="../../src/GamePort/Game/LabSimulation.cs"/>
|
||||
<Compile Include="../../src/GamePort/Game/OriginalBodyPhysics.cs"/>
|
||||
<Compile Include="../../src/GamePort/Game/OriginalStaticCollision.cs"/>
|
||||
<Compile Include="../../src/GamePort/Game/OriginalSphereResponse.cs"/>
|
||||
<Compile Include="../../src/GamePort/Game/OriginalCameraRay.cs"/>
|
||||
<Compile Include="../../src/GamePort/Game/PlayerLevelState.cs"/>
|
||||
<Compile Include="../../src/GamePort/Game/AirSteering.cs"/>
|
||||
<Compile Include="../../src/GamePort/Game/JetpackBurst.cs"/>
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(ROOT/'tools/binary'))
|
||||
from body_composition_contract import can_publish, collect, phase_order
|
||||
|
||||
|
||||
class BodyCompositionContractTests(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.report = collect(ROOT.parent/'Original')
|
||||
|
||||
def test_original_body_identity_and_decisive_sites(self):
|
||||
self.assertEqual(self.report['body']['file_offset'], '0x79d20')
|
||||
sites = {site['name']: site for site in self.report['sites']}
|
||||
self.assertEqual(sites['clamp_candidate_y']['bytes'], 'd9442420d81d086a4d00')
|
||||
self.assertEqual(sites['delta_y_nonpositive_branch']['bytes'], 'f6c441753d')
|
||||
self.assertEqual(sites['root_compare_w']['file_offset'], '0x7a176')
|
||||
self.assertEqual(len(sites), 81)
|
||||
|
||||
def test_disabled_integration_still_clears_support(self):
|
||||
self.assertEqual(phase_order(integration_enabled=False),
|
||||
['read_previous_support', 'clear_current_support', 'integration_gate'])
|
||||
self.assertEqual(phase_order(support_enabled=False, integration_enabled=False),
|
||||
['read_previous_support', 'integration_gate'])
|
||||
|
||||
def test_rotation_impulse_acceleration_gravity_and_suppression_order(self):
|
||||
order = phase_order(upward=True)
|
||||
names = ('rotate', 'impulse_add', 'impulse_clear', 'acceleration_add', 'gravity_add',
|
||||
'velocity_to_delta', 'full_dispatch', 'support47b890',
|
||||
'published_speed_zero_friction', 'angular_suppression',
|
||||
'published_speed_zero_linear_suppression')
|
||||
self.assertEqual(sorted(order.index(name) for name in names), [order.index(name) for name in names])
|
||||
|
||||
def test_nonpositive_vertical_motion_is_added_after_horizontal_response(self):
|
||||
down = phase_order(upward=False)
|
||||
up = phase_order(upward=True)
|
||||
self.assertLess(down.index('horizontal_dispatch'), down.index('add_fall_y'))
|
||||
self.assertLess(down.index('add_fall_y'), down.index('compare_previous_live_root_vec4'))
|
||||
self.assertNotIn('add_fall_y', up)
|
||||
self.assertNotIn('horizontal_dispatch', up)
|
||||
|
||||
def test_collision_world_and_global_geometry_are_separate_gates(self):
|
||||
collision_off = phase_order(collision_enabled=False)
|
||||
world_off = phase_order(world_enabled=False)
|
||||
geometry_off = phase_order(geometry_enabled=False)
|
||||
self.assertNotIn('support47b890', collision_off)
|
||||
self.assertNotIn('published_speed_zero_friction', collision_off)
|
||||
self.assertIn('translate31c', collision_off)
|
||||
self.assertNotIn('translate31c', phase_order(collision_enabled=False, translation_locked=True))
|
||||
self.assertIn('support47b890', world_off)
|
||||
self.assertIn('published_speed_zero_friction', world_off)
|
||||
self.assertNotIn('reset_static_context', world_off)
|
||||
self.assertIn('reset_static_context', geometry_off)
|
||||
self.assertIn('geometry_off_support_anchor_acceleration_velocity', geometry_off)
|
||||
|
||||
def test_publication_compares_fresh_previous_and_live_root_vec4(self):
|
||||
root = (1.0, 2.0, 3.0, 1.0)
|
||||
self.assertTrue(can_publish(root, root))
|
||||
for component in range(4):
|
||||
changed = list(root)
|
||||
changed[component] += 1
|
||||
self.assertFalse(can_publish(root, changed))
|
||||
with self.assertRaises(ValueError):
|
||||
can_publish(root[:3], root[:3])
|
||||
|
||||
def test_burst_and_support_share_live_radius_and_factor(self):
|
||||
targets = {entry['slot']: entry['target'] for entry in self.report['tables']}
|
||||
self.assertEqual(targets['0x110'], '0x471240')
|
||||
self.assertEqual(targets['0x260'], '0x471b30')
|
||||
self.assertEqual(targets['0x264'], '0x471b40')
|
||||
self.assertEqual(targets['0x250'], '0x471af0')
|
||||
self.assertEqual(targets['0x254'], '0x471b00')
|
||||
self.assertAlmostEqual(self.report['constants']['factor'], 1.265, places=6)
|
||||
|
||||
def test_init_restores_authored_speed_separately_from_controller_publication(self):
|
||||
targets = {entry['slot']: entry['target'] for entry in self.report['tables']}
|
||||
self.assertEqual(targets['0x114'], '0x471260')
|
||||
self.assertEqual(targets['0x118'], '0x471270')
|
||||
self.assertEqual(targets['0x268'], '0x471b50')
|
||||
self.assertEqual(targets['0x26c'], '0x471b60')
|
||||
sites = {site['name']: site for site in self.report['sites']}
|
||||
self.assertEqual(sites['init_authored_speed114']['file_offset'], '0x706cf')
|
||||
self.assertEqual(sites['init_publish_speed26c']['file_offset'], '0x706db')
|
||||
self.assertIn('894138', sites['authored_speed_setter118_to_live26c']['bytes'])
|
||||
self.assertNotIn('894138', sites['published_speed_setter26c']['bytes'])
|
||||
self.assertEqual(self.report['constants']['constructor_authored_speed'], 0)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user