Implement Grappler scalar component with original-code references
This commit is contained in:
1 parent
70cba65c1f
commit
0c913d15aa
18 files changed
+1014
-14
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/Game/GrapplerMotion.cs"/>
|
||||
<None Include="original-scalar-reference.json" CopyToOutputDirectory="PreserveNewest"/>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,59 @@
|
||||
using System.Numerics;
|
||||
using System.Text.Json;
|
||||
using GamePort.Game;
|
||||
|
||||
using var document=JsonDocument.Parse(File.ReadAllText(Path.Combine(AppContext.BaseDirectory,"original-scalar-reference.json")));
|
||||
var cases=document.RootElement.GetProperty("cases").EnumerateArray().ToArray();
|
||||
Check(cases.Length==30,"thirty copied-original observations");
|
||||
foreach(var c in cases)
|
||||
{
|
||||
var p=c.GetProperty("input").EnumerateArray().Select(x=>x.GetSingle()).ToArray();
|
||||
var observed=c.GetProperty("observed").EnumerateArray().Select(x=>x.GetSingle()).ToArray();
|
||||
var name=c.GetProperty("kind").GetString()+"/"+c.GetProperty("name").GetString();
|
||||
switch(c.GetProperty("kind").GetString())
|
||||
{
|
||||
case "attach":
|
||||
var a=GrapplerMotion.Attach(new(p[0],p[1],p[2]),new(p[3],p[4],p[5]),new(11,-222,33),p[6]);
|
||||
Near(a.Length,observed[0],name+" length");Near(a.InitialLength,observed[1],name+" first length");
|
||||
Check(a.RopeScaleZ.HasValue==(observed[3]==1),name+" scale write ownership");
|
||||
if(a.RopeScaleZ is{} scale)Near(scale,observed[2],name+" scale");
|
||||
break;
|
||||
case "held":Near(GrapplerMotion.HeldReel(p[0],p[2]),observed[0],name);break;
|
||||
case "fast":Near(GrapplerMotion.FastReel(p[0],p[1],p[2]),observed[0],name);break;
|
||||
case "swing":
|
||||
var s=GrapplerMotion.Swing(new(p[0],p[1],p[2]),p[3],p[4],p[5],p[6]);
|
||||
Near(s.X,observed[0],name+" X");Near(s.Z,observed[1],name+" Z");Near(s.Elapsed,observed[2],name+" elapsed");break;
|
||||
default:throw new Exception("Unknown native reference kind");
|
||||
}
|
||||
}
|
||||
Console.WriteLine("PASS all30 copied-original attachment/reel/damping scalar observations");
|
||||
|
||||
var first=GrapplerMotion.Attach(Vector3.Zero,new(0,300,400),new(10,-200,20));
|
||||
Check(first.Velocity==new Vector3(10,100,20)&&first.FastReelTarget==100,"source attachment velocity/reel target");
|
||||
var second=GrapplerMotion.Attach(Vector3.Zero,new(0,600,800),Vector3.Zero,first.InitialLength);
|
||||
Check(second.InitialLength==400&&second.Length==900&&second.RopeScaleZ==null,"reattach retains first rope length/scale");
|
||||
Console.WriteLine("PASS first-length retention and independent velocity/scalar publication");
|
||||
|
||||
Check(GrapplerMotion.HeldReel(251,.1f)==226&&GrapplerMotion.HeldReel(250,.1f)==250,"strict held-reel gate without final250 clamp");
|
||||
Check(GrapplerMotion.FastReel(251,250,.1f)==156&&GrapplerMotion.FastReel(250,250,.1f)==250,"strict fast-reel target without final clamp");
|
||||
var shortRope=GrapplerMotion.Swing(new(100,-100,.2f),0,0,0,349);
|
||||
var longRope=GrapplerMotion.Swing(new(100,-100,.2f),0,0,0,350);
|
||||
Check(shortRope.X==47.5f&&longRope.X==49,"350 damping boundary after50 clamp");
|
||||
var tick=GrapplerMotion.Swing(new(50,50,0),.6f,0,0,400);
|
||||
Near(tick.X,49,"one damping per callback");Near(tick.Elapsed,.4f,"remainder retained");
|
||||
Console.WriteLine("PASS strict overshoot, clamp/damping threshold and one-step timing");
|
||||
|
||||
Check(GrapplerMotion.JumpDetaches(true,false,true),"jump detaches");
|
||||
Check(!GrapplerMotion.JumpDetaches(true,true,true)&&!GrapplerMotion.JumpDetaches(false,false,true)
|
||||
&&!GrapplerMotion.JumpDetaches(true,false,false),"independent fire/jump/attached predicates");
|
||||
Console.WriteLine("PASS simultaneous fire prevents jump detach");
|
||||
|
||||
Reject(()=>GrapplerMotion.HeldReel(300,-.1f));Reject(()=>GrapplerMotion.FastReel(300,0,float.NaN));
|
||||
Reject(()=>GrapplerMotion.Attach(new(float.PositiveInfinity,0,0),Vector3.Zero,Vector3.Zero));
|
||||
Reject(()=>GrapplerMotion.Swing(new(0,0,float.NaN),.1f,0,0,400));
|
||||
Console.WriteLine("PASS nonfinite and unsupported timestep boundaries");
|
||||
Console.WriteLine("Grappler:5 scalar groups; ray/body/camera/lifetime and live VR08 integration remain separate gates.");
|
||||
|
||||
static void Check(bool ok,string message){if(!ok)throw new Exception(message);}
|
||||
static void Near(float actual,float expected,string message)=>Check(float.IsFinite(actual)&&MathF.Abs(actual-expected)<.0002f,$"{message}: {actual} != {expected}");
|
||||
static void Reject(Action action){try{action();throw new Exception("Invalid scalar state accepted");}catch(ArgumentOutOfRangeException){}}
|
||||
@@ -0,0 +1,515 @@
|
||||
{
|
||||
"source_sha256": "f5281076e1a2492f2d61f87aae3f4544b6d0f535ebe33f9fbb6f78710fe1aea8",
|
||||
"ranges": [
|
||||
{
|
||||
"kind": "attach",
|
||||
"va": "0x426be8",
|
||||
"end_va": "0x426c70",
|
||||
"file_offset": "0x26be8",
|
||||
"sha256": "afefa8d85ac6fb17d71ad2841570e88819b4159e911f037cd5e1f5edab127a7b"
|
||||
},
|
||||
{
|
||||
"kind": "held",
|
||||
"va": "0x426dac",
|
||||
"end_va": "0x426dd5",
|
||||
"file_offset": "0x26dac",
|
||||
"sha256": "b59ca8ba618e4ae7b5486e850ef97b353bc12254c03274bf41159fa70e5df4c5"
|
||||
},
|
||||
{
|
||||
"kind": "fast",
|
||||
"va": "0x429dc9",
|
||||
"end_va": "0x429df5",
|
||||
"file_offset": "0x29dc9",
|
||||
"sha256": "51e8557c6f1183ba5bb7d125ad48aba9cdcae3698ef93308e47e0cf4e83ac3aa"
|
||||
},
|
||||
{
|
||||
"kind": "swing",
|
||||
"va": "0x42a077",
|
||||
"end_va": "0x42a1a2",
|
||||
"file_offset": "0x2a077",
|
||||
"sha256": "5599448797384fa4c5be142d41e1592d0e71db9ecafe7a235d18636033699415"
|
||||
}
|
||||
],
|
||||
"scope": "Isolated scalar prefixes/suffixes; no ray, body, camera, renderer or original gameplay execution",
|
||||
"generator_sha256": "c51cc1ecefaf7a90e69a40624fd0e8cd7e01500359c4e67aee6213bb36f4a810",
|
||||
"executable_sha256": "6168b4ed3e65c094a9d28a79a9a5e2f13b499e487d631081b57c708569ad2b88",
|
||||
"log_sha256": "83814ffeb801e329126a00677f680d159dc2ab44e540843571233004f8565db5",
|
||||
"cases": [
|
||||
{
|
||||
"kind": "attach",
|
||||
"name": "first",
|
||||
"input": [
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
300.0,
|
||||
400.0,
|
||||
0.0
|
||||
],
|
||||
"observed": [
|
||||
400.0,
|
||||
400.0,
|
||||
0.666666687,
|
||||
1.0
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "attach",
|
||||
"name": "retained",
|
||||
"input": [
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
600.0,
|
||||
800.0,
|
||||
400.0
|
||||
],
|
||||
"observed": [
|
||||
900.0,
|
||||
400.0,
|
||||
12345.0,
|
||||
0.0
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "attach",
|
||||
"name": "fraction",
|
||||
"input": [
|
||||
1.25,
|
||||
-30.75,
|
||||
48.125,
|
||||
634.625,
|
||||
413.75,
|
||||
-95.125,
|
||||
0.0
|
||||
],
|
||||
"observed": [
|
||||
686.933716,
|
||||
686.933716,
|
||||
1.14488959,
|
||||
1.0
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "attach",
|
||||
"name": "short",
|
||||
"input": [
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
50.0,
|
||||
0.0,
|
||||
0.0
|
||||
],
|
||||
"observed": [
|
||||
-50.0,
|
||||
-50.0,
|
||||
-0.0833333358,
|
||||
1.0
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "attach",
|
||||
"name": "zero",
|
||||
"input": [
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0
|
||||
],
|
||||
"observed": [
|
||||
-100.0,
|
||||
-100.0,
|
||||
-0.166666672,
|
||||
1.0
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "attach",
|
||||
"name": "negative",
|
||||
"input": [
|
||||
-130.0,
|
||||
315.0,
|
||||
-490.0,
|
||||
-530.0,
|
||||
-285.0,
|
||||
310.0,
|
||||
0.0
|
||||
],
|
||||
"observed": [
|
||||
977.032959,
|
||||
977.032959,
|
||||
1.62838829,
|
||||
1.0
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "attach",
|
||||
"name": "same_first",
|
||||
"input": [
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
300.0,
|
||||
400.0,
|
||||
400.0
|
||||
],
|
||||
"observed": [
|
||||
400.0,
|
||||
400.0,
|
||||
12345.0,
|
||||
0.0
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "attach",
|
||||
"name": "negative_first",
|
||||
"input": [
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
300.0,
|
||||
400.0,
|
||||
-100.0
|
||||
],
|
||||
"observed": [
|
||||
400.0,
|
||||
-100.0,
|
||||
12345.0,
|
||||
0.0
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "held",
|
||||
"name": "above",
|
||||
"input": [
|
||||
251.0,
|
||||
0.0,
|
||||
0.100000001
|
||||
],
|
||||
"observed": [
|
||||
226.0
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "held",
|
||||
"name": "equal",
|
||||
"input": [
|
||||
250.0,
|
||||
0.0,
|
||||
0.100000001
|
||||
],
|
||||
"observed": [
|
||||
250.0
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "held",
|
||||
"name": "below",
|
||||
"input": [
|
||||
249.0,
|
||||
0.0,
|
||||
0.100000001
|
||||
],
|
||||
"observed": [
|
||||
249.0
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "held",
|
||||
"name": "negative",
|
||||
"input": [
|
||||
-100.0,
|
||||
0.0,
|
||||
0.100000001
|
||||
],
|
||||
"observed": [
|
||||
-100.0
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "held",
|
||||
"name": "long",
|
||||
"input": [
|
||||
300.0,
|
||||
0.0,
|
||||
0.600000024
|
||||
],
|
||||
"observed": [
|
||||
150.0
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "held",
|
||||
"name": "tick",
|
||||
"input": [
|
||||
950.0,
|
||||
0.0,
|
||||
0.0166666675
|
||||
],
|
||||
"observed": [
|
||||
945.833313
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "fast",
|
||||
"name": "above",
|
||||
"input": [
|
||||
251.0,
|
||||
250.0,
|
||||
0.100000001
|
||||
],
|
||||
"observed": [
|
||||
156.0
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "fast",
|
||||
"name": "equal",
|
||||
"input": [
|
||||
250.0,
|
||||
250.0,
|
||||
0.100000001
|
||||
],
|
||||
"observed": [
|
||||
250.0
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "fast",
|
||||
"name": "below",
|
||||
"input": [
|
||||
249.0,
|
||||
250.0,
|
||||
0.100000001
|
||||
],
|
||||
"observed": [
|
||||
249.0
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "fast",
|
||||
"name": "negative_target",
|
||||
"input": [
|
||||
50.0,
|
||||
-200.0,
|
||||
0.100000001
|
||||
],
|
||||
"observed": [
|
||||
-45.0
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "fast",
|
||||
"name": "long",
|
||||
"input": [
|
||||
300.0,
|
||||
0.0,
|
||||
0.600000024
|
||||
],
|
||||
"observed": [
|
||||
-270.000031
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "fast",
|
||||
"name": "tick",
|
||||
"input": [
|
||||
950.0,
|
||||
0.0,
|
||||
0.0166666675
|
||||
],
|
||||
"observed": [
|
||||
934.166687
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "swing",
|
||||
"name": "free",
|
||||
"input": [
|
||||
10.0,
|
||||
20.0,
|
||||
0.0,
|
||||
0.100000001,
|
||||
100.0,
|
||||
-200.0,
|
||||
400.0
|
||||
],
|
||||
"observed": [
|
||||
8.30000019,
|
||||
23.3999996,
|
||||
0.100000001
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "swing",
|
||||
"name": "equal",
|
||||
"input": [
|
||||
50.0,
|
||||
-50.0,
|
||||
0.0,
|
||||
0.200000003,
|
||||
0.0,
|
||||
0.0,
|
||||
400.0
|
||||
],
|
||||
"observed": [
|
||||
49.0,
|
||||
-49.0,
|
||||
0.0
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "swing",
|
||||
"name": "short",
|
||||
"input": [
|
||||
100.0,
|
||||
-100.0,
|
||||
0.200000003,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
349.0
|
||||
],
|
||||
"observed": [
|
||||
47.5,
|
||||
-47.5,
|
||||
0.0
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "swing",
|
||||
"name": "long",
|
||||
"input": [
|
||||
100.0,
|
||||
-100.0,
|
||||
0.200000003,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
350.0
|
||||
],
|
||||
"observed": [
|
||||
49.0,
|
||||
-49.0,
|
||||
0.0
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "swing",
|
||||
"name": "one_damping",
|
||||
"input": [
|
||||
50.0,
|
||||
50.0,
|
||||
0.0,
|
||||
0.600000024,
|
||||
0.0,
|
||||
0.0,
|
||||
400.0
|
||||
],
|
||||
"observed": [
|
||||
49.0,
|
||||
49.0,
|
||||
0.400000036
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "swing",
|
||||
"name": "offset",
|
||||
"input": [
|
||||
60.0,
|
||||
-55.0,
|
||||
0.189999998,
|
||||
0.0199999996,
|
||||
102.0,
|
||||
-73.0,
|
||||
349.899994
|
||||
],
|
||||
"observed": [
|
||||
47.5,
|
||||
-47.5,
|
||||
0.00999999046
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "swing",
|
||||
"name": "near_clamp",
|
||||
"input": [
|
||||
49.9999886,
|
||||
-49.9999886,
|
||||
0.189999998,
|
||||
0.0199999996,
|
||||
-9.99999975e-05,
|
||||
9.99999975e-05,
|
||||
400.0
|
||||
],
|
||||
"observed": [
|
||||
48.9999886,
|
||||
-48.9999886,
|
||||
0.00999999046
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "swing",
|
||||
"name": "tick",
|
||||
"input": [
|
||||
4.125,
|
||||
-2.75,
|
||||
0.189999998,
|
||||
0.0166666675,
|
||||
170.125,
|
||||
-333.75,
|
||||
350.0
|
||||
],
|
||||
"observed": [
|
||||
3.57011962,
|
||||
-1.76828754,
|
||||
0.00666666031
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "swing",
|
||||
"name": "below_time",
|
||||
"input": [
|
||||
8.0,
|
||||
9.0,
|
||||
0.189999998,
|
||||
0.00899999961,
|
||||
90.0,
|
||||
-65.0,
|
||||
800.0
|
||||
],
|
||||
"observed": [
|
||||
7.86229992,
|
||||
9.09945011,
|
||||
0.199000001
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "swing",
|
||||
"name": "negative_length",
|
||||
"input": [
|
||||
5.0,
|
||||
-6.0,
|
||||
0.100000001,
|
||||
0.200000003,
|
||||
-200.0,
|
||||
90.0,
|
||||
-5.0
|
||||
],
|
||||
"observed": [
|
||||
11.21,
|
||||
-8.60700035,
|
||||
0.100000009
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
"""Copied-original scalar observations, separate from body/visual/gameplay parity."""
|
||||
import json
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
ROOT=Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0,str(ROOT/'tools/binary'))
|
||||
from grappler import attach_scalars,held_reel,fast_reel,swing_scalars
|
||||
from grappler_motion import collect
|
||||
|
||||
|
||||
class GrapplerScalarReferences(unittest.TestCase):
|
||||
def test_hashed_scalar_ranges_and_reference_identity(self):
|
||||
source=collect(ROOT.parent/'Original')
|
||||
fixture=json.loads((ROOT/'tests/GamePort.GrapplerTests/original-scalar-reference.json').read_text())
|
||||
self.assertEqual(fixture['source_sha256'],source['source_sha256'])
|
||||
self.assertEqual(fixture['ranges'],source['ranges'])
|
||||
self.assertEqual(len(fixture['cases']),30)
|
||||
self.assertEqual([r['kind'] for r in source['ranges']],['attach','held','fast','swing'])
|
||||
|
||||
def test_all_thirty_native_scalar_observations(self):
|
||||
fixture=json.loads((ROOT/'tests/GamePort.GrapplerTests/original-scalar-reference.json').read_text())
|
||||
for case in fixture['cases']:
|
||||
with self.subTest(case['kind']+'/'+case['name']):
|
||||
p=case['input'];observed=case['observed']
|
||||
if case['kind']=='attach':
|
||||
a=attach_scalars(p[:3],p[3:6],initial_length=p[6])
|
||||
actual=[a.length,a.initial_length]
|
||||
self.assertEqual(a.scale_z is not None,observed[3]==1)
|
||||
if a.scale_z is not None:actual.append(a.scale_z)
|
||||
elif case['kind']=='held':actual=[held_reel(p[0],p[2])]
|
||||
elif case['kind']=='fast':actual=[fast_reel(*p)]
|
||||
else:actual=swing_scalars(*p)
|
||||
for a,b in zip(actual,observed):self.assertAlmostEqual(a,b,delta=.0002)
|
||||
|
||||
|
||||
if __name__=='__main__':unittest.main()
|
||||
Reference in new issue
Block a user