70 lines
4.1 KiB
C#
70 lines
4.1 KiB
C#
using System.Numerics;
|
|
using System.Text.Json;
|
|
using GamePort.Game;
|
|
using var document=JsonDocument.Parse(File.ReadAllText(Path.Combine(AppContext.BaseDirectory,"original-ground-reference.json")));
|
|
int inputs=0,applies=0;
|
|
foreach(var c in document.RootElement.GetProperty("cases").EnumerateArray())
|
|
{
|
|
var p=c.GetProperty("input").EnumerateArray().Select(v=>v.GetSingle()).ToArray();
|
|
var o=c.GetProperty("observed").EnumerateArray().Select(v=>v.GetSingle()).ToArray();string name=c.GetProperty("name").GetString()!;
|
|
if(c.GetProperty("kind").GetString()=="INPUT")
|
|
{
|
|
var r=JimmyGroundMotion.Input(new(p[0],0,p[6],p[7]!=0),p[5],new(p[1]!=0,p[2]!=0,p[3]!=0,p[4]!=0,false));
|
|
Near(r.State.Speed,o[0],name+" scalar");Near(r.Lateral,o[1],name+" side");Near(r.State.TargetYaw,o[2],name+" heading");
|
|
Check(r.State.AutoTurning==(o[3]!=0),name+" latch");inputs++;
|
|
}
|
|
else
|
|
{
|
|
var r=JimmyGroundMotion.Apply(p[0],new(p[1],p[2],p[3]),new(p[4],p[5],p[6]),p[7],p[8],p[9]!=0,p[10]!=0,p[11]);
|
|
Near(r.Velocity.X,o[0],name+" X");Near(r.Velocity.Y,o[1],name+" Y");Near(r.Velocity.Z,o[2],name+" Z");Near(r.Rotation.Y,o[3],name+" yaw");applies++;
|
|
}
|
|
}
|
|
Check(inputs==17&&applies==8,"complete25 native observations");Console.WriteLine("PASS17 original ground-input observations and8 ground-apply observations");
|
|
var active=JimmyGroundMotion.Input(new(100,130),90,new(true,false,false,false,false));Check(active.State.TargetYaw==90,"active forward stops previous destination-yaw drift");
|
|
var idle=JimmyGroundMotion.Input(new(100,130),90,default);Check(idle.State.TargetYaw==130,"idle retains prior destination yaw");
|
|
var fire=JimmyGroundMotion.Input(new(100,90),90,new(false,true,false,false,false,Fire:true),blockBackward:true);
|
|
Check(fire.State.Speed==65&&!fire.HeadingUpdated,"source parent fire acceptance gate suppresses backward");
|
|
Console.WriteLine("PASS heading publication and caller-owned backward/fire gate");
|
|
using var landing = JsonDocument.Parse(File.ReadAllText(Path.Combine(AppContext.BaseDirectory,"original-landing-rotation-reference.json")));
|
|
int trajectories = 0;
|
|
foreach (var c in landing.RootElement.GetProperty("cases").EnumerateArray())
|
|
{
|
|
var initial = c.GetProperty("before");
|
|
var current = Euler(initial,"current");
|
|
var target = Euler(initial,"target");
|
|
var dirty = initial.GetProperty("dirty").GetInt32()!=0;
|
|
var input = new PlayerInput(c.GetProperty("up").GetInt32()!=0,false,c.GetProperty("left").GetInt32()!=0,false,false);
|
|
var state = new JimmyGroundState(0,target.Y);
|
|
for (var tick=0;tick<300;tick++)
|
|
{
|
|
var ground = JimmyGroundMotion.Input(state,current.Y,input);
|
|
state = ground.State;
|
|
if (ground.HeadingUpdated) { target=new(0,state.TargetYaw,0);dirty=true; }
|
|
if (tick==0) Compare("after_input");
|
|
var prior = current;
|
|
current = JimmyOrientation.Step(current,target,1f/60,dirty:dirty);
|
|
if (dirty) dirty=prior!=target;
|
|
if (tick==0) Compare("after_facing");
|
|
}
|
|
Compare("after_300");
|
|
trajectories++;
|
|
|
|
void Compare(string stage)
|
|
{
|
|
var expected=c.GetProperty(stage);
|
|
var e=Euler(expected,"current");var t=Euler(expected,"target");
|
|
Near(current.X,e.X,stage+" pitch");Near(current.Y,e.Y,stage+" yaw");Near(current.Z,e.Z,stage+" roll");
|
|
Near(target.X,t.X,stage+" target pitch");Near(target.Y,t.Y,stage+" target yaw");Near(target.Z,t.Z,stage+" target roll");
|
|
Check(dirty==(expected.GetProperty("dirty").GetInt32()!=0),stage+" dirty");
|
|
}
|
|
}
|
|
Check(trajectories==7,"complete seven original grounded-input/facing trajectories");
|
|
Console.WriteLine("PASS7 original grounded-input/facing trajectories: neutral destination retention, dirty ownership and active steering leveling");
|
|
static Vector3 Euler(JsonElement state,string key)
|
|
{
|
|
var values=state.GetProperty(key).EnumerateArray().Select(v=>v.GetSingle()).ToArray();
|
|
return new(values[0],values[1],values[2]);
|
|
}
|
|
static void Check(bool condition,string name){if(!condition)throw new Exception(name);}
|
|
static void Near(float value,float expected,string name)=>Check(float.IsFinite(value)&&Math.Abs(value-expected)<.02f,$"{name}: {value} != {expected}");
|