105 lines
5.2 KiB
C#
105 lines
5.2 KiB
C#
// Diagnostic composition of the existing port. No original code execution or
|
|
// production state-policy change; snapshots expose the first returning writer.
|
|
using System.Buffers.Binary;
|
|
using System.Numerics;
|
|
using System.Text;
|
|
using System.Text.Json;
|
|
using GamePort.Assets;
|
|
using GamePort.Game;
|
|
|
|
var originals = Path.GetFullPath(args.Length > 0 ? args[0] : "../Original");
|
|
var output = Path.GetFullPath(args.Length > 1 ? args[1] : "artifacts/jimmy-cutscene-return/port-trace/observations.json");
|
|
var level = GamLevel.Load(AssetPath.Resolve(originals,"gam/level1b.gam"));
|
|
var save = OriginalSave.Load(AssetPath.Resolve(originals,"NewGame.tsk"));
|
|
var cases = new List<object>();
|
|
foreach (var camera in new[]{"CAM", "CarlMCA"})
|
|
foreach (var inputAfterPlayer in new[]{false,true})
|
|
foreach (var left in new[]{false,true})
|
|
foreach (var finish in new[]{"natural","skip","default"})
|
|
foreach (var heldDuringScene in new[]{false,true})
|
|
{
|
|
var scene = camera == "CarlMCA"
|
|
? new SceneDirector(level,new TaskStates(save.Tasks),(_,_)=>2)
|
|
: new SceneDirector(new("LV1B", [Entity("3JIM","JIM1"),
|
|
Entity("3CAM","camera",("PlayerControlled","NULL"),("CameraTarget","JIM1"),
|
|
("SoundDatabase","voice"),("SoundIndex",1),("NextTrigger","default"))]),new TaskStates([]),(_,_)=>2);
|
|
var body=FlatBody();
|
|
body.InputAfterPlayerUpdate=inputAfterPlayer;
|
|
using var binding=new PlayerSceneBinding(scene,body,new SceneInventory(new int[19]),"JIM1");
|
|
var rows=new List<object>();
|
|
var phase="entry";
|
|
var tick=0;
|
|
var recordInput=false;
|
|
body.InputActions+=_=>{if(recordInput)Snapshot("input-published");};
|
|
var jumpInput=new PlayerInput(true,false,left,!left,true);
|
|
for(var i=0;i<8;i++)binding.Step(jumpInput);
|
|
if(body.Grounded || !body.FacingDirty || body.TurnRate==0)
|
|
throw new InvalidOperationException("Trace did not establish a banked jump");
|
|
Snapshot("before-trigger");
|
|
scene.Trigger(camera=="CarlMCA"?"neutron1a":"camera");
|
|
Snapshot("after-trigger");
|
|
phase="locked";
|
|
if(finish=="natural")
|
|
{
|
|
for(tick=0;tick<5000 && (!scene.Controlled || scene.Playing);tick++)
|
|
{
|
|
binding.Step(heldDuringScene?jumpInput:default);
|
|
scene.Step(FixedStepClock.Step);
|
|
if(tick==0 || tick==59 || scene.Controlled)Snapshot("after-step");
|
|
}
|
|
if(tick==5000)throw new InvalidOperationException("Natural camera chain did not complete");
|
|
}
|
|
else
|
|
{
|
|
for(tick=0;tick<180;tick++)binding.Step(heldDuringScene?jumpInput:default);
|
|
Snapshot("before-finish");
|
|
if(finish=="skip")scene.Skip();else scene.Trigger("default");
|
|
}
|
|
Snapshot("after-finish");
|
|
if(!body.Grounded || !scene.Controlled)
|
|
throw new InvalidOperationException("Trace must return idle after grounding during the camera");
|
|
phase="neutral-resumption";
|
|
recordInput=true;
|
|
for(tick=1;tick<=300;tick++)
|
|
{
|
|
if(tick>3)recordInput=false;
|
|
binding.Step(default);
|
|
if(tick<=3 || tick==30 || tick==300)Snapshot("after-step");
|
|
}
|
|
cases.Add(new {camera,inputAfterPlayer,left,finish,heldDuringScene,rows,
|
|
finalCurrent=Vector(body.Rotation),finalTarget=Vector(body.FacingTarget)});
|
|
|
|
void Snapshot(string boundary)=>rows.Add(new {phase,tick,boundary,
|
|
current=Vector(body.Rotation),target=Vector(body.FacingTarget),dirty=body.FacingDirty,
|
|
mode=body.CaptureLevelState(-1)!.MovementMode,turn=body.TurnRate,speed=body.Speed,
|
|
grounded=body.Grounded,control=scene.AuthoredControlledTag,script=scene.CurrentTag,
|
|
playing=scene.Playing,controller=body.ControllerSteps,physics=body.PhysicsSteps,
|
|
root=Vector(body.ActorRoot)});
|
|
}
|
|
Directory.CreateDirectory(Path.GetDirectoryName(output)!);
|
|
File.WriteAllText(output,JsonSerializer.Serialize(new {
|
|
scope="Existing-port managed diagnostic; synthetic flat-floor body, actual original Carl GAM chain or synthetic CAM and 2-second sound clock. No original execution, GPU or gameplay modification.",
|
|
cases},new JsonSerializerOptions{WriteIndented=true}));
|
|
Console.WriteLine($"Recorded {cases.Count} port-only handoff cases: {output}");
|
|
|
|
static float[] Vector(Vector3 v)=>[v.X,v.Y,v.Z];
|
|
static LabSimulation FlatBody()
|
|
{
|
|
var points=new[]{new Vector3(-10000,0,-10000),new(-10000,0,10000),new(10000,0,10000),new(10000,0,-10000)};
|
|
var floor=new Mesh(points.Select(p=>new MeshVertex(p,Vector2.Zero,Vector3.One)).ToArray(),[0,1,2,0,2,3]);
|
|
var standing=new Mesh([new(new(-20,-20,-20),Vector2.Zero,Vector3.One),new(new(20,80,20),Vector2.Zero,Vector3.One)],[]);
|
|
return new(new SceneCollision(floor),standing,new(0,25,0),0);
|
|
}
|
|
static GamEntity Entity(string kind,string tag,params (string Name,object Value)[] values)
|
|
{
|
|
var properties=new Dictionary<string,GamProperty>();
|
|
foreach(var(name,value) in values.Prepend(("ObjectTag",(object)tag)))
|
|
{
|
|
uint type;byte[] raw;
|
|
if(value is string text){type=1;raw=Encoding.Latin1.GetBytes(text);}
|
|
else{raw=new byte[4];type=value is float?3u:6u;BinaryPrimitives.WriteInt32BigEndian(raw,value is float f?BitConverter.SingleToInt32Bits(f):(int)value);}
|
|
properties[name]=new(name,type,raw);
|
|
}
|
|
return new(kind,0,properties,new byte[4]);
|
|
}
|