Implement Baseball aiming, pooled projectiles and VR07 targets
This commit is contained in:
1 parent
50fcb87d90
commit
d6ca417e9e
50 files changed
+3149
-32
No files matched your search
@@ -0,0 +1,11 @@
|
||||
<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/Assets/*.cs" />
|
||||
<Compile Include="../../src/GamePort/Game/*.cs" />
|
||||
<Compile Include="../../src/GamePort/Application/UiViewport.cs" />
|
||||
<Compile Include="../../src/GamePort/Application/BaseballVisuals.cs" />
|
||||
<Compile Include="../../src/GamePort/Application/BaseballAimOverlay.cs" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,153 @@
|
||||
using System.Numerics;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text.Json.Nodes;
|
||||
using GamePort.Application;
|
||||
using GamePort.Assets;
|
||||
using GamePort.Game;
|
||||
|
||||
var prepared=args.Length==0?"artifacts/extracted":args[0];
|
||||
var count=0;
|
||||
void Check(bool condition,string message){if(!condition)throw new Exception(message);}
|
||||
void Near(float actual,float expected,string message)=>Check(MathF.Abs(actual-expected)<.001f,$"{message}: {actual} != {expected}");
|
||||
void Test(string name,Action action){action();count++;Console.WriteLine($"PASS {name}");}
|
||||
void Invalid(Action action)
|
||||
{
|
||||
try{action();}catch(Exception e)when(e is ArgumentException or InvalidDataException){return;}
|
||||
throw new Exception("Invalid visual input accepted");
|
||||
}
|
||||
BaseballGadget Aim(float pitch,bool visible=true)
|
||||
{
|
||||
var device=new BaseballGadget();
|
||||
//Visual contract fixtures set published state directly, independently of
|
||||
//input/timing tests owned by BaseballGadget's separate test project.
|
||||
typeof(BaseballGadget).GetProperty("DisplayPitch")!.SetValue(device,pitch);
|
||||
typeof(BaseballGadget).GetProperty("AimVisible")!.SetValue(device,visible);
|
||||
return device;
|
||||
}
|
||||
Vector2 Pixels(MeshVertex vertex,uint width,uint height)=>new((vertex.Position.X+1)*width/2,(vertex.Position.Y+1)*height/2);
|
||||
|
||||
Test("twenty exact source balls append hidden alpha quads and preserve scene metadata",()=>
|
||||
{
|
||||
var source=new Mesh([new(new(1,2,3),Vector2.Zero,Vector3.One)],[0,0,0])
|
||||
{
|
||||
CollisionPolygons=[new(1,2,Vector3.UnitY,"floor")],HasCollisionMaterialIds=true,
|
||||
Textures=new(){[int.MinValue+17000]=PngImage.White}
|
||||
};
|
||||
var visual=new BaseballVisuals(source,prepared);
|
||||
Check(visual.Mesh.Vertices.Length==81&&visual.Mesh.Indices.Length==123,"append20 quads");
|
||||
Check(visual.Mesh.Draws.Length==21&&!visual.Mesh.Draws[0].ScreenSpace,"preserve implicit scene draw");
|
||||
Check(visual.Mesh.Vertices[0].Position==new Vector3(1,2,3),"original vertex retained");
|
||||
Check(ReferenceEquals(visual.Mesh.CollisionPolygons,source.CollisionPolygons)&&visual.Mesh.HasCollisionMaterialIds,"collision metadata retained");
|
||||
Check(visual.Mesh.Draws.Skip(1).All(d=>!d.Visible&&!d.ScreenSpace&&d.Blend==MeshBlend.Alpha),"hidden alpha world sprites");
|
||||
var image=visual.Mesh.Textures[visual.Mesh.Draws[^1].TextureId];
|
||||
Check(image.Width==32&&image.Height==32,"source32x32 canvas");
|
||||
Check(Convert.ToHexStringLower(SHA256.HashData(image.Rgba))=="68904b758e69139de0b01329b2a9844ecd2a466f31598c24324affaccfa2cab9","exact ball0000 pixels");
|
||||
Check(visual.Mesh.Draws[^1].TextureId!=int.MinValue+17000,"texture collision avoided");
|
||||
});
|
||||
|
||||
Test("source25-unit ball corners face camera with finite degenerate bases and full UVs",()=>
|
||||
{
|
||||
var visual=new BaseballVisuals(new([],[]),prepared);
|
||||
var ball=new BaseballProjectile();ball.Launch(new(5,10,15),Vector3.Zero,0);
|
||||
foreach(var target in new[]{Vector3.Zero,Vector3.UnitY,-Vector3.UnitY,new Vector3(2,3,4)})
|
||||
{
|
||||
visual.Update(visual.Mesh,[ball],Vector3.Zero,target);
|
||||
var v=visual.Mesh.Vertices.Take(4).ToArray();
|
||||
Check(v.All(c=>float.IsFinite(c.Position.X+c.Position.Y+c.Position.Z)),"finite basis");
|
||||
Near(Vector3.Distance(v[0].Position,v[1].Position),25,"source width");
|
||||
Near(Vector3.Distance(v[1].Position,v[2].Position),25,"source height");
|
||||
Check(Vector3.Distance(v.Aggregate(Vector3.Zero,(a,b)=>a+b.Position)/4,ball.Position)<.0001f,"source published position is center");
|
||||
Check(v.Select(c=>c.Uv).SequenceEqual(new Vector2[]{new(0,1),new(1,1),new(1,0),new(0,0)}),"full source UV");
|
||||
Check(visual.Mesh.Draws.Count(d=>d.Visible)==1,"unused19 slots remain hidden");
|
||||
}
|
||||
ball.Hide();visual.Update(visual.Mesh,[ball],Vector3.Zero,Vector3.UnitZ);
|
||||
Check(visual.Mesh.Draws.All(d=>!d.Visible),"hide removes stale draw");
|
||||
Invalid(()=>visual.Update(new([],[]),[ball],Vector3.Zero,Vector3.UnitZ));
|
||||
Invalid(()=>visual.Update(visual.Mesh,[ball],new(float.NaN),Vector3.UnitZ));
|
||||
Invalid(()=>visual.Update(visual.Mesh,Enumerable.Range(0,21).Select(_=>ball).ToArray(),Vector3.Zero,Vector3.UnitZ));
|
||||
});
|
||||
|
||||
Test("aim uses stationary original strip, prior-capture pitch and source integer truncation",()=>
|
||||
{
|
||||
var overlay=new BaseballAimOverlay(new([],[]),prepared);
|
||||
foreach(var pitch in new[]{0f,9.9f,17.5f,44.99f,45f})
|
||||
{
|
||||
overlay.Update(overlay.Mesh,Aim(pitch),640,480);
|
||||
Check(overlay.Mesh.Draws.Count(d=>d.Visible)==3,"one strip and two digits");
|
||||
var visible=overlay.Mesh.Draws.Where(d=>d.Visible).ToArray();
|
||||
var strip=visible.Single(d=>overlay.Mesh.Textures[d.TextureId].Height==210);
|
||||
var start=overlay.Mesh.Indices[strip.FirstIndex];
|
||||
Near(Pixels(overlay.Mesh.Vertices[start],640,480).X,315,"strip x stationary");
|
||||
Near(Pixels(overlay.Mesh.Vertices[start],640,480).Y,100,"strip y stationary");
|
||||
var digits=visible.Where(d=>d!=strip).OrderBy(d=>Pixels(overlay.Mesh.Vertices[overlay.Mesh.Indices[d.FirstIndex]],640,480).X).ToArray();
|
||||
for(var place=0;place<2;place++)
|
||||
{
|
||||
var point=Pixels(overlay.Mesh.Vertices[overlay.Mesh.Indices[digits[place].FirstIndex]],640,480);
|
||||
Near(point.X,286+place*16,"null TIME space has zero advance");
|
||||
Near(point.Y,(int)((45-(double)pitch)*4.3+100),"label integer y");
|
||||
var digit=place==0?(int)pitch/10:(int)pitch%10;
|
||||
Check(overlay.Mesh.Textures[digits[place].TextureId].Rgba.SequenceEqual(
|
||||
File.ReadAllBytes(Path.Combine(prepared,$"baseball/aim_{new[]{118,127,120,121,122,123,124,125,126,119}[digit]}.rgba"))),"exact selected source digit pixels");
|
||||
}
|
||||
Check(strip.Blend==MeshBlend.Alpha&&strip.ScreenSpace,"screen alpha path");
|
||||
}
|
||||
overlay.Update(overlay.Mesh,Aim(0,false),640,480);
|
||||
Check(overlay.Mesh.Draws.All(d=>!d.Visible),"unequip hides all owned aim draws");
|
||||
Invalid(()=>overlay.Update(overlay.Mesh,Aim(float.NaN),640,480));
|
||||
Invalid(()=>overlay.Update(overlay.Mesh,Aim(46),640,480));
|
||||
Invalid(()=>overlay.Update(overlay.Mesh,Aim(0),0,480));
|
||||
Invalid(()=>overlay.Update(new([],[]),Aim(0),640,480));
|
||||
});
|
||||
|
||||
Test("widescreen preserves aim pixel proportions and centered640x480 placement",()=>
|
||||
{
|
||||
var overlay=new BaseballAimOverlay(new([],[]),prepared);
|
||||
foreach(var size in new[]{(640u,480u),(1920u,1080u),(3440u,1440u),(480u,800u)})
|
||||
{
|
||||
var(w,h)=size;var scale=MathF.Min(w/640f,h/480f);
|
||||
overlay.Update(overlay.Mesh,Aim(45),w,h);
|
||||
var strip=overlay.Mesh.Draws.Single(d=>d.Visible&&overlay.Mesh.Textures[d.TextureId].Height==210);
|
||||
var start=overlay.Mesh.Indices[strip.FirstIndex];
|
||||
var a=Pixels(overlay.Mesh.Vertices[start],w,h);var b=Pixels(overlay.Mesh.Vertices[start+2],w,h);
|
||||
Near(a.X,w/2f-5*scale,"centered strip x");
|
||||
Near(a.Y,(h-480*scale)/2+100*scale,"centered strip y");
|
||||
Near(b.X-a.X,15*scale,"uniform source width");Near(b.Y-a.Y,210*scale,"uniform source height");
|
||||
}
|
||||
});
|
||||
|
||||
Test("world plus overlay updates retain each other's vertices and draws",()=>
|
||||
{
|
||||
var balls=new BaseballVisuals(new([],[]),prepared);var overlay=new BaseballAimOverlay(balls.Mesh,prepared);
|
||||
var ball=new BaseballProjectile();ball.Launch(Vector3.Zero,Vector3.Zero,0);
|
||||
balls.Update(overlay.Mesh,[ball],Vector3.Zero,Vector3.UnitZ);
|
||||
var position=overlay.Mesh.Vertices[0].Position;
|
||||
overlay.Update(overlay.Mesh,Aim(12),1920,1080);
|
||||
Check(overlay.Mesh.Vertices[0].Position==position&&overlay.Mesh.Draws[0].Visible,"overlay retains world state");
|
||||
Check(overlay.Mesh.Draws.Count(d=>d.Visible)==4,"one world and three overlay draws");
|
||||
});
|
||||
|
||||
Test("altered pixels, dimensions and manifest traversal are rejected",()=>
|
||||
{
|
||||
var directory=Path.Combine(Path.GetTempPath(),"neutron-baseball-visual-"+Guid.NewGuid());
|
||||
var output=Path.Combine(directory,"baseball");Directory.CreateDirectory(output);
|
||||
try
|
||||
{
|
||||
var source=Path.Combine(prepared,"baseball");
|
||||
foreach(var path in Directory.EnumerateFiles(source,"*.rgba"))File.Copy(path,Path.Combine(output,Path.GetFileName(path)));
|
||||
var original=File.ReadAllText(Path.Combine(source,"baseball.json"));
|
||||
var root=JsonNode.Parse(original)!;
|
||||
void Save()=>File.WriteAllText(Path.Combine(output,"baseball.json"),root.ToJsonString());
|
||||
root["textures"]![0]!["path"]="../outside.rgba";Save();
|
||||
File.Copy(Path.Combine(source,"canvas_2.rgba"),Path.Combine(directory,"outside.rgba"));
|
||||
Invalid(()=>new BaseballVisuals(new([],[]),directory));
|
||||
root=JsonNode.Parse(original)!;root["aimTextures"]![0]!["width"]=16;Save();
|
||||
Invalid(()=>new BaseballAimOverlay(new([],[]),directory));
|
||||
root=JsonNode.Parse(original)!;Save();
|
||||
File.WriteAllBytes(Path.Combine(output,"canvas_2.rgba"),new byte[4096]);
|
||||
Invalid(()=>new BaseballVisuals(new([],[]),directory));
|
||||
File.WriteAllBytes(Path.Combine(output,"aim_253.rgba"),new byte[15*210*4]);
|
||||
Invalid(()=>new BaseballAimOverlay(new([],[]),directory));
|
||||
}
|
||||
finally{Directory.Delete(directory,true);}
|
||||
});
|
||||
Console.WriteLine($"Baseball visual checks passed: {count}");
|
||||
Reference in new issue
Block a user