150 lines
12 KiB
C#
150 lines
12 KiB
C#
using System.Numerics;
|
|
using System.Buffers.Binary;
|
|
using System.Text;
|
|
using GamePort.Assets;
|
|
using GamePort.Game;
|
|
using GamePort.Application;
|
|
|
|
var count=0;
|
|
void Check(bool value,string message){if(!value)throw new Exception(message);}
|
|
void Near(float actual,float expected,string message)=>Check(MathF.Abs(actual-expected)<.002f,$"{message}: {actual} != {expected}");
|
|
void Test(string name,Action action){action();count++;Console.WriteLine($"PASS {name}");}
|
|
Mesh Floor(int material=0)=>new(
|
|
[new(new(-4000,0,-4000),Vector2.Zero,Vector3.One),new(new(4000,0,-4000),Vector2.Zero,Vector3.One),
|
|
new(new(4000,0,4000),Vector2.Zero,Vector3.One),new(new(-4000,0,4000),Vector2.Zero,Vector3.One)],
|
|
[0,1,2,0,2,3]){HasCollisionMaterialIds=true,CollisionPolygons=[new(0,0,Vector3.UnitY,"floor","floor",material),new(0,1,Vector3.UnitY,"floor","floor",material)]};
|
|
LabSimulation Player(string level="VR01",Mesh? world=null)
|
|
{
|
|
world??=Floor();
|
|
return new(new SceneCollision(world),AseMesh.Load("../Original/ASE/jimstop.ase"),new(0,80,0),0,
|
|
originalCollision:OriginalStaticCollision.FromRouteScene(world,"VR01")){LevelCode=level};
|
|
}
|
|
void Until(LabSimulation player,Func<bool> done,PlayerInput input=default)
|
|
{for(var i=0;i<700&&!done();i++)player.Step(input);Check(done(),"requested phase not reached");}
|
|
|
|
Test("six copied-original radius/factor body references",()=>{
|
|
var physics=new OriginalBodyPhysics(OriginalStaticCollision.FromRouteScene(Floor(),"VR01"));
|
|
foreach(var c in new[]{
|
|
(66.4f,0f,160f,.415f,66.4000015f,0f,true),(26f,0f,160f,.415f,66.4000015f,0f,true),
|
|
(75.9f,0f,160f,.415f,75.6777802f,-13.333334f,false),(66.4f,0f,60f,1.265f,75.9000015f,0f,true),
|
|
(66.4f,300f,160f,.415f,71.1777802f,286.666656f,false),(66.4f,900f,160f,.415f,81.1777802f,886.666687f,false)})
|
|
{
|
|
var r=physics.Step(new(new(0,c.Item1,0),new(0,c.Item2,0),Vector3.Zero,Vector3.Zero),1f/60,c.Item3,c.Item4);
|
|
Near(r.Body.Position.Y,c.Item5,"root");Near(r.Body.Velocity.Y,c.Item6,"velocity");Check(r.Body.Supported==c.Item7,"support");
|
|
}
|
|
});
|
|
Test("equip and cleanup retain logical root, queued impulse and source650 maximum",()=>{
|
|
var p=Player();p.Step(new(false,false,false,false,true));var root=p.ActorRoot;var impulse=p.PendingImpulse;
|
|
p.GadgetMode=0;
|
|
Check(p.ActorRoot==root&&p.PendingImpulse==impulse&&impulse.Y==550,"equip must not recenter/reset queued impulse");
|
|
Check(p.MovementMode==2&&p.InteractionRadius==160&&p.BodyFactor==.415f&&p.MaximumSpeed==1350,"source body/controller settings");
|
|
p.GadgetMode=-1;
|
|
Check(p.ActorRoot==root&&p.PendingImpulse==impulse&&p.MovementMode==0&&p.MaximumSpeed==650&&p.BodyFactor==1.265f&&p.InteractionRadius==60,
|
|
"cleanup changes its fields without a teleport or blanket physics clear");
|
|
});
|
|
Test("mode2 persists through repeated automatic300 bounces without550/jetpack",()=>{
|
|
var p=Player();p.JetpackInventoryState=()=>1;p.GadgetMode=0;var sounds=new List<int>();p.GadgetSound+=(id,_)=>sounds.Add(id);
|
|
Until(p,()=>p.BubbleBounces>=3);
|
|
Check(p.GadgetMode==0&&p.MovementMode==2&&p.Velocity.Y==300&&p.Jumps==0&&p.Bursts==0,"automatic bounce path");
|
|
Check(p.Pose==PlayerPose.Idle&&!sounds.Contains(106),"supported STOP, released bounce has no boing");
|
|
});
|
|
Test("held supported bounce is direct900 and requests106",()=>{
|
|
var p=Player();p.GadgetMode=0;var sounds=new List<int>();p.GadgetSound+=(id,_)=>sounds.Add(id);
|
|
Until(p,()=>p.BubbleBounces>0,new(false,false,false,false,true));
|
|
Check(p.Velocity.Y==900&&sounds.SequenceEqual(new[]{106})&&p.PendingImpulse==Vector3.Zero&&p.MovementMode==2,"direct liveY/source sound");
|
|
});
|
|
Test("controlled drain, independent sprite clock and tutorial bypass",()=>{
|
|
var p=Player("LV1B");p.GadgetMode=0;p.Step(default);Near(p.Energy,20-1f/120,"ordinary controlled cost");
|
|
var root=p.BubbleRoot;var energy=p.Energy;var time=p.Bubble.Timer;var controllers=p.ControllerSteps;
|
|
p.Step(default,false,false);
|
|
Check(p.Energy==energy&&p.Bubble.Timer>time&&p.BubbleRoot==root&&p.ControllerSteps==controllers,"raw control loss does not stop effect clock or move captured sprite");
|
|
var vr=Player();vr.GadgetMode=0;for(var i=0;i<90;i++)vr.Step(default);
|
|
Check(vr.Energy==20&&vr.Bubble.Active,"VR01 exemption and expansion");
|
|
});
|
|
Test("depletion cleans once and notifies selection owner without restarting loop",()=>{
|
|
var p=Player("LV1B");p.Energy=.001f;var director=new SceneDirector(new("LV1B",[Entity("3JIM","JIM1")]),new TaskStates([]),(_,_)=>1);
|
|
var bag=new SceneInventory(new int[19]);bag.SetState(0,0,1);using var binding=new PlayerSceneBinding(director,p,bag,"JIM1");
|
|
var starts=0;var stops=0;var warnings=new List<int>();p.GadgetSound+=(_,loop)=>{if(loop)starts++;};p.BubbleSoundStopped+=()=>stops++;p.EnergySound+=warnings.Add;
|
|
bag.SelectGadget(0);binding.Step(default);
|
|
Check(p.Energy==0&&p.GadgetMode==-1&&p.MovementMode==0&&p.MaximumSpeed==650&&p.Bubble.Collapsing&&!p.Bubble.Expanding,"source depletion cleanup");
|
|
Check(starts==1&&stops==1&&bag.SelectedGadget==-1&&warnings.SequenceEqual(new[]{80,182}),"one loop and shared warning/selection ownership");
|
|
});
|
|
Test("transition flags reject re-equip until original fade finishes",()=>{
|
|
var p=Player();p.GadgetMode=0;p.GadgetMode=0;
|
|
Check(p.GadgetMode==-1&&p.Bubble.Collapsing&&!p.Bubble.Expanding,"select-again caller cleanup precedes active flag gate");
|
|
p.GadgetMode=0;Check(p.GadgetMode==-1,"collapsing owned effect blocks re-equip");
|
|
Until(p,()=>!p.Bubble.Visible);p.GadgetMode=0;
|
|
Check(p.GadgetMode==0&&p.Bubble.Expanding&&p.MaximumSpeed==1350,"hidden after strict fade allows next activation");
|
|
});
|
|
Test("Bubble fire throttles without starting the ordinary ray",()=>{
|
|
var world=Floor();var p=Player("LV1B",world);var director=new SceneDirector(new("LV1B",[Entity("3JIM","JIM1")]),new TaskStates([]),(_,_)=>1);
|
|
var bag=new SceneInventory(new int[19]);bag.SetState(0,3,1);using var ray=new SceneGadgets(director,bag,p,world);
|
|
p.GadgetMode=0;for(var i=0;i<20;i++)p.Step(new(false,false,true,false,false,Fire:true));
|
|
Check(p.Speed>0&&p.TurnRate>0&&MathF.IEEERemainder(p.Pitch,360)<0&&!ray.Ray.Visible&&!p.Shooting,"shared fire predicate is Bubble throttle, not shoot");
|
|
});
|
|
Test("lava bypass, retained entry and strict4-second debounce",()=>{
|
|
var state=new Vr01FloorState();var e=state.Visit(111,0);
|
|
Check(e.Entered&&!e.Damaged&&!state.Flashing&&state.SoundSelector==35,"Bubble entry bypass");
|
|
e=state.Visit(111,-1);Check(!e.Entered&&e.Damaged&&state.Flashing,"cleanup starts damage without replaying entry");
|
|
for(var i=0;i<16;i++)state.Step(.25f,_=>{});
|
|
Check(state.Flashing&&state.Timer==4,"exact4 still flashes");
|
|
Vector4 color=default;state.Step(MathF.Pow(2,-24),c=>color=c);
|
|
Check(!state.Flashing&&state.Timer==4&&color==Vector4.One,"unrounded comparison before float store");
|
|
state.Visit(0,-1);Check(!state.InLava&&state.SoundSelector==5,"ordinary floor resets entry and selector");
|
|
});
|
|
Test("actual VR01 floor111 retained through airborne cleanup and raw control loss",()=>{
|
|
var mesh=Mesh.LoadSceneJson("artifacts/extracted/VR01/scene.json");var collision=OriginalStaticCollision.FromRouteScene(mesh,"VR01");
|
|
Check(!collision.HasSpecialPlayerContacts&&collision.PolygonCount==80&&collision.WallPolygonCount==60,"actual static-only wall coverage");
|
|
var index=Array.FindIndex(mesh.CollisionPolygons,p=>p.MaterialId==111);var first=index*3;
|
|
var center=(mesh.Vertices[mesh.Indices[first]].Position+mesh.Vertices[mesh.Indices[first+1]].Position+mesh.Vertices[mesh.Indices[first+2]].Position)/3;
|
|
var p=Player("VR01",mesh);p.GadgetMode=0;p.RestoreReturnRoot(center+Vector3.UnitY*66.4f);
|
|
var score=0;var sounds=new List<int>();p.ScoreChanged+=delta=>score+=delta;p.GadgetSound+=(id,_)=>sounds.Add(id);
|
|
p.Step(new(false,false,false,false,true));
|
|
Check(p.Velocity.Y==900&&score==0&&sounds.Contains(39)&&!sounds.Contains(190)&&p.FloorState.InLava,"Bubble supports lava and skips damage");
|
|
p.GadgetMode=-1;p.Step(default,false,false);
|
|
Check(!p.Grounded&&score==-5&&p.FloorState.Flashing&&p.Energy==20,"retained material callback runs airborne/uncontrolled; VR energy alone exempt");
|
|
});
|
|
Test("stored material writes preserve Invisible/lava phase ownership",()=>{
|
|
var appearance=new PlayerAppearance();var inv=new InvisibleGadget();inv.AlphaRequested+=appearance.SetAlpha;inv.BlendRequested+=appearance.SetBlend;
|
|
inv.Equip(20,false);for(var i=0;i<14;i++)inv.Step(.5f,true,false,false,20,false,_=>{});inv.Step(0,true,true,false,20,false,_=>{});
|
|
Check(appearance.Color.W==.7f&&appearance.Blend==MeshBlend.Additive,"activation material request");
|
|
var lava=new Vr01FloorState();lava.Visit(111,2);lava.Step(.25f,appearance.SetColor);
|
|
Check(appearance.Color.W==1&&appearance.Blend==MeshBlend.Additive,"late direct RGBA changes alpha without changing blend bit");
|
|
for(var i=0;i<8;i++)inv.Step(.5f,true,false,false,18,false,_=>{});
|
|
Check(appearance.Color.W==1&&appearance.Blend==MeshBlend.Alpha,"indexed flash does not reapply alpha.7");
|
|
inv.Release();Check(appearance.Color==Vector4.One&&appearance.Blend==MeshBlend.Opaque,"alpha-reset clears blending");
|
|
});
|
|
Test("practice0 loads before live equip; rejected raw mode opens panel directly",()=>{
|
|
var p=Player("LV1B");var bag=new SceneInventory(new int[19]);bag.SetState(0,0,1);bag.SetState(0,2,1);bag.GadgetSelected+=i=>p.GadgetMode=GadgetScreen.EquippedMode(i);
|
|
var screen=new GadgetScreen(bag,()=>p.GadgetMode);var destination=-1;screen.PracticeRequested+=i=>destination=i;
|
|
screen.Toggle(true);screen.Point(new(520,120),"LV1B",60);screen.Activate("LV1B",60);
|
|
screen.Point(new(50,200),"LV1B",60);screen.Activate("LV1B",60);
|
|
Check(destination==0&&bag.SelectedGadget==0&&p.GadgetMode==-1&&!p.Bubble.Visible,"source practice branch precedes body/effect setup");
|
|
p.Energy=0;bag.SelectGadget(2);Check(p.GadgetMode==-1&&bag.SelectedGadget==2,"rejected Invisible display/raw split");
|
|
Check(screen.Toggle(true)&&screen.Open,"key dispatcher reads raw mode, not display index");
|
|
});
|
|
Test("camera cleanup and modern debug stop release Bubble and restore defaults",()=>{
|
|
var p=Player("LV1B");var command=Entity("3MCA","cleanup",("CameraTarget0","none"));
|
|
var director=new SceneDirector(new("LV1B",[Entity("3JIM","JIM1"),command]),new TaskStates([]),(_,_)=>1);
|
|
var bag=new SceneInventory(new int[19]);bag.SetState(0,0,1);using var binding=new PlayerSceneBinding(director,p,bag,"JIM1");
|
|
bag.SelectGadget(0);director.Trigger("cleanup");
|
|
Check(p.GadgetMode==-1&&p.MaximumSpeed==650&&p.Bubble.Collapsing&&binding.UnsupportedGadgetCleanups==0,"named-Jimmy source cleanup");
|
|
Until(p,()=>!p.Bubble.Visible);bag.SelectGadget(0);p.StopDebugMotion();
|
|
Check(p.GadgetMode==-1&&bag.SelectedGadget==-1&&p.MovementMode==0,"modern stop boundary prevents dangling movement2 gadget");
|
|
Until(p,()=>!p.Bubble.Visible);bag.SelectGadget(0);p.SetNoclip(true);
|
|
for(var i=0;i<70;i++)p.Step(default);
|
|
Check(!p.Bubble.Visible&&p.Noclip&&p.GadgetMode==-1,"owned fade advances during modern flight after cleanup");
|
|
});
|
|
Console.WriteLine($"Bubble integration:{count} groups passed; broader damage, dynamic collision and original whole-game comparison remain separate.");
|
|
|
|
GamEntity Entity(string kind,string tag,params(string Name,object Value)[] values)
|
|
{
|
|
var props=new Dictionary<string,GamProperty>(StringComparer.Ordinal);
|
|
foreach(var(name,value) in new[]{("ObjectTag",(object)tag)}.Concat(values))
|
|
{
|
|
if(value is string text)props[name]=new(name,1,Encoding.Latin1.GetBytes(text));
|
|
else{var raw=new byte[4];BinaryPrimitives.WriteInt32BigEndian(raw,(int)value);props[name]=new(name,6,raw);}
|
|
}
|
|
return new(kind,props.Count,props,[]);
|
|
}
|