Files

77 lines
5.3 KiB
C#

using System.Numerics;
using System.Text.Json;
using GamePort.Assets;
using GamePort.Game;
static class QueryReferences
{
public static void Run()
{
using var doc=JsonDocument.Parse(File.ReadAllText(Path.Combine(AppContext.BaseDirectory,"original-query-reference.json")));
var cases=doc.RootElement.GetProperty("cases").EnumerateArray().ToArray();Check(cases.Length==42,"42 query/constraint/contact cases");
foreach(var c in cases)
{
var p=c.GetProperty("input").EnumerateArray().Select(x=>x.GetSingle()).ToArray();
var o=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 "aim":
var a=GrapplerGeometry.Aim(Vector3.Zero,new(0,2400,2400),p[0]!=0?new Vector3(0,p[1],0):null,
new(p[2]!=1,p[2]!=2,p[2]!=3,(int)p[3]),p[4]!=0,p[5]!=0,p[6],p[7]);
Check(a.EndsActiveInput==(o[0]!=0)&&a.CursorVisible==(o[1]==0),name+" caller/visibility");
if(a.CursorVisible)Near(a.CursorPosition,new(o[3],o[4],o[5]),name+" cursor");
Near(a.Length,o[6],name+" length");break;
case "constraint":
var constraint=GrapplerGeometry.Constrain(new(p[0],p[1],p[2]),new(p[3],p[4],p[5]),new(p[6],p[7],0),p[8],p[9]);
Near(constraint.Offset,new(o[0],o[1],o[2]),name+" offset");
Near(constraint.DesiredRoot,new(o[3],o[4],o[5]),name+" root");break;
case "impact":
var impact=GrapplerGeometry.Contact(new(p[0],p[1],.75f));
Check(impact.Swing==new GrapplerSwing(o[0],o[1],.75f)&&impact.Detach==(o[2]!=0)
&&o[2]==o[3],name+" post-base clear/detach/latch");break;
default:throw new Exception("Unknown original query reference");
}
}
Console.WriteLine("PASS42 copied-original aim/constraint/post-base contact observations");
var blocked=GrapplerGeometry.Aim(Vector3.Zero,new(0,2400,2400),new(0,700,0),new(true,true,true,60),true,false,300,.1f);
Check(blocked.EndsActiveInput&&!blocked.CursorVisible&&blocked.Length==275,"blocked aim reels then skips later primary attachment");
var near=GrapplerGeometry.Aim(Vector3.Zero,new(0,2400,2400),new(0,449,0),new(true,true,true,0),true,false,300,.1f);
Check(near.EndsActiveInput&&near.Length==300,"close aim skips primary without blocked-material reel");
Console.WriteLine("PASS enclosing input gate distinguishes close/blocked aim from attachment helper acceptance");
CameraRayPolygon Wall(int shape,float z,int material)=>new(new(new(-100,-100,z),new(200,0,z),new(-100,100,z),shape,0),-Vector3.UnitZ,"wall","wall",material);
var query=new OriginalCameraRay([Wall(1,300,170),Wall(2,200,0)]);
var selected=query.TraceSelectedGeometry(Vector3.Zero,new(0,0,450));
Check(selected is{Polygon.MaterialId:170,Hit.ShapeId:1},"selected metadata follows first source hit, not nearer/allowed polygon");
query.Enabled=false;
Check(query.Trace(Vector3.Zero,new(0,0,450))==null&&query.TraceSelectedGeometry(Vector3.Zero,new(0,0,450))==selected,
"gameplay ray remains active when camera debug query is disabled");
Console.WriteLine("PASS first-hit material snapshot and camera-debug separation");
var world=Mesh.LoadSceneJson("artifacts/extracted/VR08/scene.json");
var level=GamLevel.Load("../Original/gam/VR08.gam");var root=level.FindStart()!.Position;var ray=new GrapplerRay(world,level.Code);
Check(ray.Endpoint(root,Vector3.Zero)==root+new Vector3(0,2400,2400),"aim uses actual root, not swing pivot+116");
int hits=0;
foreach(float yaw in new[]{0,90,180,270})
{
var rotation=new Vector3(0,yaw,0);var hit=ray.Trace(root,rotation);if(hit is not{} h)continue;
hits++;Check(h.Polygon.MaterialId is 0 or 2 or 3 or 4,"actual VR08 material context");
var aim=ray.Aim(root,rotation,true,false,0,1f/60);
Check(aim.CursorVisible||aim.EndsActiveInput,"actual ray reaches valid or close-surface gate");
}
Check(hits>0,"actual VR08 geometry produces authored-start aiming hits");
Console.WriteLine($"PASS actual VR08 root/Euler ray/filter/material integration ({hits} cardinal hits)");
Reject(()=>GrapplerGeometry.Constrain(Vector3.Zero,new(0,116,0),default,100,.1f));
Reject(()=>new GrapplerRay(world,"LV1B"));
Reject(()=>new GrapplerRay(world with{HasCollisionMaterialIds=false},"VR08"));
Console.WriteLine("PASS explicit zero-normalization and unsupported scene/profile boundaries");
}
static void Check(bool ok,string message){if(!ok)throw new Exception(message);}
static void Near(float a,float b,string name)=>Check(float.IsFinite(a)&&MathF.Abs(a-b)<.004f,$"{name}: {a} != {b}");
static void Near(Vector3 a,Vector3 b,string name){Near(a.X,b.X,name+" X");Near(a.Y,b.Y,name+" Y");Near(a.Z,b.Z,name+" Z");}
static void Reject(Action action){try{action();throw new Exception("Unsupported boundary accepted");}catch(NotSupportedException){}}
}