273 lines
29 KiB
C++
273 lines
29 KiB
C++
#include "eter_effect/FlyingManager.h"
|
||
#include "eter_render/ActorInstance.h"
|
||
#include "eter_render/Gr2ModelRenderer.h"
|
||
#include "eter_base/Random.h"
|
||
#include "eter_render/RaceData.h"
|
||
#include "eter_render/MapObjectManager.h"
|
||
#include "eter_net/NetworkActorManager.h"
|
||
#include <cmath>
|
||
#include <iostream>
|
||
#include <memory>
|
||
#include <stdexcept>
|
||
#include <filesystem>
|
||
#include <fstream>
|
||
#include <chrono>
|
||
using namespace ava2;
|
||
static void check(bool valid,const char* message){if(!valid)throw std::runtime_error(message);}
|
||
static bool near(float a,float b){return std::abs(a-b)<0.001f;}
|
||
static uint32_t ShakeClock(){return 1000;}
|
||
static uint32_t ShakeValue(){return 6;}
|
||
int main(){
|
||
namespace fs=std::filesystem;
|
||
const auto path=fs::temp_directory_path()/("ava2-flight-"+std::to_string(std::chrono::steady_clock::now().time_since_epoch().count())+".msf");
|
||
try {
|
||
{std::ofstream(path)<<"InitialVelocity 10\nRange 1000\nHomingStartTime 0.5\nHomingMaxAngle 15\nHomingFlag 1\nPierceCount 2\nMaintainParallelFlag 1\nHitOnBackground 1\nHitOnAnotherMonster 1\nSpreadingFlag 1\nGravity -7\nAcceleration 1 2 3\n";}
|
||
FlyingData loaded;check(loaded.LoadScriptFile(path.string()) && loaded.pierce_count==2 && loaded.maintain_parallel && loaded.spreading && loaded.hit_on_background && loaded.hit_on_another_monster
|
||
&& loaded.homing_start_time==0.5f && loaded.initial_velocity==10 && loaded.gravity==-7,"MSF flight parameters");fs::remove(path);
|
||
auto data=std::make_shared<FlyingData>();data->initial_velocity=100;data->bomb_range=1;data->range=10000;
|
||
float start[3]={},target[3]={100,0,0};int hits=0,ranges=0;
|
||
FlyingInstance swept(data,start,target);swept.SetHitCallback([&](const float*){++hits;});
|
||
check(!swept.Update(2,2) && hits==1,"swept target skipped by high-speed flight");
|
||
check(!swept.Update(2,4) && hits==1,"terminated flight callback duplicated");
|
||
|
||
// Launch along X, move the object to a tangent afterwards.
|
||
bool live=true;float moving[3]={100,0,0};
|
||
auto resolver=[&](float* out){if(!live)return false;std::copy(moving,moving+3,out);return true;};
|
||
FlyingInstance strict(data,start,target,resolver);moving[1]=1;
|
||
check(strict.Update(2,2),"strict bomb-range boundary accepted");moving[1]=0;
|
||
data->range=99;FlyingInstance range(data,start,target);range.SetRangeCallback([&]{++ranges;});range.SetHitCallback([&](const float*){++hits;});
|
||
check(!range.Update(1,1) && ranges==1 && hits==1,"range exhaustion reported as target hit");
|
||
data->range=100;FlyingInstance equalRange(data,start,target);check(!equalRange.Update(1,1),"zero remaining range prevented valid hit");
|
||
data->range=10000;data->initial_velocity=1;float far[3]={1000,0,0};
|
||
FlyingInstance slow(data,start,far);int timeoutHits=0;slow.SetHitCallback([&](const float*){++timeoutHits;});
|
||
check(slow.Update(6,6) && near(slow.GetPosition()[0],6) && timeoutHits==0,"five-second timeout/fake velocity remains");
|
||
data->initial_velocity=100;data->gravity=-10;
|
||
FlyingInstance gravity(data,start,far);check(gravity.Update(1,1) && near(gravity.GetPosition()[1],-10) && near(gravity.GetPosition()[2],0),"native gravity axis/units/order");
|
||
data->gravity=0;data->acceleration[2]=5;FlyingInstance acceleration(data,start,far);
|
||
check(acceleration.Update(1,1) && near(acceleration.GetPosition()[2],5),"initial roll and target arc not applied to acceleration");data->acceleration[2]=0;
|
||
data->homing_flag=true;data->homing_start_time=0.5f;data->homing_max_angle=15;
|
||
moving[0]=1000;moving[1]=0;moving[2]=0;
|
||
FlyingInstance homing(data,start,moving,resolver);moving[0]=0;moving[2]=1000;
|
||
check(homing.Update(0.5f,0.5f) && near(homing.GetPosition()[0],50) && near(homing.GetPosition()[2],0),"homing start boundary not strict");
|
||
check(homing.Update(0.5f,1) && near(homing.GetPosition()[0],50+50*std::cos(3.14159265358979323846f/6))
|
||
&& near(homing.GetPosition()[2],25),"homing quaternion angle limit/speed preservation");
|
||
// Static positions do not home, even when the script has homing enabled.
|
||
FlyingInstance position(data,start,far);check(position.Update(1,1) && near(position.GetPosition()[0],100),"static flight changed direction");
|
||
data->homing_start_time=0;data->homing_max_angle=181;
|
||
moving[0]=1000;moving[2]=0;FlyingInstance unrestricted(data,start,moving,resolver);moving[0]=0;moving[2]=1000;
|
||
check(unrestricted.Update(0.1f,0.1f) && near(unrestricted.GetPosition()[0],0) && near(unrestricted.GetPosition()[2],10),"unlimited homing does not follow moving actor");
|
||
moving[0]=100;moving[2]=0;data->homing_flag=false;data->pierce_count=1;
|
||
FlyingInstance piercing(data,start,moving,resolver);int objectHits=0;piercing.SetTargetHitCallback([&]{++objectHits;});
|
||
check(piercing.Update(1,1) && objectHits==1 && piercing.Update(0,1) && objectHits==1,"piercing primary hit not one-shot");
|
||
data->pierce_count=0;moving[0]=300;FlyingInstance tracking(data,start,moving,resolver);moving[0]=100;
|
||
tracking.SetTargetHitCallback([&]{++objectHits;});check(!tracking.Update(1,1) && objectHits==2,"non-homing flight used stale target point");
|
||
moving[0]=100;FlyingInstance cleared(data,start,moving,resolver);live=false;moving[0]=1000;
|
||
cleared.SetTargetHitCallback([&]{++objectHits;});check(!cleared.Update(1,1) && objectHits==2,"deleted object did not become last position");
|
||
// Independent fixed-seed source trajectory: three Park–Miller draws and
|
||
// native Z -> negative-Y -> initial roll -> target arc composition.
|
||
data->spreading=true;float spreadTarget[3]={0,0,1000};eter::srandom(1);
|
||
FlyingInstance spread(data,start,spreadTarget);check(spread.Update(1,1),"spread flight terminated");
|
||
check(near(spread.GetPosition()[0],-78.86724f) && near(spread.GetPosition()[1],-2.778796f)
|
||
&& near(spread.GetPosition()[2],61.41853f),"source spreading direction/composition");
|
||
check(eter::random()==984943658u,"spreading RNG consumed wrong draw count");
|
||
data->acceleration[1]=-100;eter::srandom(1);FlyingInstance spreadAcceleration(data,start,spreadTarget);
|
||
check(spreadAcceleration.Update(1,1) && near(spreadAcceleration.GetPosition()[0],-157.73448f)
|
||
&& near(spreadAcceleration.GetPosition()[1],-5.557592f) && near(spreadAcceleration.GetPosition()[2],122.83706f),"spread acceleration not rotated with velocity");
|
||
data->acceleration[1]=0;data->spreading=false;eter::srandom(1);FlyingInstance noSpread(data,start,spreadTarget);
|
||
check(eter::random()==16807u,"disabled spreading consumed RNG");
|
||
// Extra actors use BODY spheres, not DEFENDING, enemy filters or health.
|
||
{std::ofstream(path)<<"Group AttachingData\n{\nGroup AttachingData00\n{\nCollisionType 1\nGroup SphereData00\n{\nRadius 5\nPosition 0 0 0\n}\n}\n}\n";}
|
||
auto* bodyRace=RaceManager::Instance().CreateRace(50002);check(bodyRace->LoadRaceData(path.string()),"BODY fixture");
|
||
check(bodyRace->GetBodySpheres().size()==1 && bodyRace->GetDefendingSpheres().empty() && bodyRace->GetDefendingRadius()==0,"BODY misclassified as DEFENDING");
|
||
auto& actors=NetworkActorManager::Instance();actors.Clear();
|
||
auto addBody=[&](uint32_t vid,float x,float z){SNetworkActorData actor{};actor.m_dwVID=vid;actor.m_dwRace=50002;actor.m_bType=6;actors.AppendActor(actor);auto instance=actors.GetActorInstance(vid);instance->SetPosition(x,20,z);return instance;};
|
||
auto owner=addBody(1,0,0),other=addBody(2,50,0);other->Die();
|
||
owner->SetShakeSourcesForTest(ShakeClock,ShakeValue);owner->OnShootDamage();owner->Update(0);
|
||
const auto bodyUnshaken=owner->GetBodyCollisionSpheres();float shakenCenter[3];owner->GetFlyTargetCenter(shakenCenter);
|
||
check(bodyUnshaken.size()==1 && bodyUnshaken[0].position[0]==0 && bodyUnshaken[0].position[1]==20 && bodyUnshaken[0].position[2]==0
|
||
&& shakenCenter[0]==6 && shakenCenter[2]==-6,"shake changed BODY geometry or missing graphic target offset");
|
||
owner->SetShakeSourcesForTest(nullptr,nullptr);
|
||
float sceneStart[3]={0,20,0},sceneTarget[3]={1000,20,0};
|
||
std::vector<uint32_t> extraHits;int backgroundHits=0;
|
||
FlyCollisionCallbacks callbacks;callbacks.owner=owner->GetFlyCollisionIdentity();callbacks.onAnotherTarget=[&](uint32_t vid){extraHits.push_back(vid);};callbacks.onBackground=[&]{++backgroundHits;};
|
||
data->hit_on_another_monster=true;data->pierce_count=1;
|
||
FlyingInstance extra(data,sceneStart,sceneTarget);extra.SetCollisionCallbacks(callbacks);
|
||
check(extra.Update(1,1) && extraHits==std::vector<uint32_t>{2},"owner filter/dead friendly BODY collision");
|
||
other->SetPosition(100,20,0);check(extra.Update(0,1) && extraHits.size()==1,"piercing duplicate object callback");
|
||
// Previously-hit first candidate masks another, matching source hit-set ordering.
|
||
addBody(3,100,0);check(extra.Update(0,1) && extraHits.size()==1,"already-hit candidate incorrectly skipped before query");actors.RemoveActor(3);
|
||
auto oldOther=other;actors.RemoveActor(2);other=addBody(2,100,0);
|
||
check(!extra.Update(0,1) && extraHits==std::vector<uint32_t>({2,2}),"same VID replacement inherited collision hit set");
|
||
extraHits.clear();data->pierce_count=0;other->SetPosition(50,20,-50);other->SetSpeed(100);other->SetMoveTarget(50,50);other->Update(1);
|
||
FlyingInstance crossing(data,sceneStart,sceneTarget);crossing.SetCollisionCallbacks(callbacks);
|
||
check(!crossing.Update(1,1) && extraHits==std::vector<uint32_t>{2},"moving BODY sphere sweep missed crossing");
|
||
other->SetPosition(50,35,0);other->Update(0.01f);extraHits.clear();
|
||
FlyingInstance tangentBody(data,sceneStart,sceneTarget);tangentBody.SetCollisionCallbacks(callbacks);
|
||
check(!tangentBody.Update(1,1) && extraHits==std::vector<uint32_t>{2},"BODY inclusive radius boundary");
|
||
actors.RemoveActor(2);extraHits.clear();FlyingInstance ownerOnly(data,sceneStart,sceneTarget);ownerOnly.SetCollisionCallbacks(callbacks);
|
||
check(ownerOnly.Update(1,1) && extraHits.empty(),"owner hit itself");
|
||
// Primary hit returns before actor/background checks; range exhaustion returns first.
|
||
other=addBody(2,50,0);data->pierce_count=1;data->hit_on_background=true;
|
||
struct Ground:TerrainHeightSource {float height=100;float GetHeightAtWorld(float,float)const override{return height;}bool HasAttrMap()const override{return false;}bool IsAttrOn(float,float,uint8_t)const override{return false;}} ground;
|
||
float primary[3]={100,20,0};FlyingInstance primaryFirst(data,sceneStart,primary,[](float* out){out[0]=100;out[1]=20;out[2]=0;return true;});primaryFirst.SetCollisionCallbacks(callbacks);
|
||
check(primaryFirst.Update(1,1,&ground) && backgroundHits==0 && extraHits.empty(),"primary piercing priority changed");
|
||
data->range=99;FlyingInstance exhausted(data,sceneStart,sceneTarget);exhausted.SetCollisionCallbacks(callbacks);
|
||
check(!exhausted.Update(1,1,&ground) && backgroundHits==0 && extraHits.empty(),"range collision priority changed");data->range=10000;
|
||
data->pierce_count=0;FlyingInstance actorFirst(data,sceneStart,sceneTarget);actorFirst.SetCollisionCallbacks(callbacks);
|
||
check(!actorFirst.Update(1,1,&ground) && extraHits==std::vector<uint32_t>{2} && backgroundHits==0,"actor/background priority changed");
|
||
data->hit_on_another_monster=false;FlyingInstance buried(data,sceneStart,sceneTarget);buried.SetCollisionCallbacks(callbacks);
|
||
check(!buried.Update(1,1,&ground) && backgroundHits==1,"below-ground impact not dispatched");ground.height=20;
|
||
FlyingInstance groundEqual(data,sceneStart,sceneTarget);groundEqual.SetCollisionCallbacks(callbacks);
|
||
check(groundEqual.Update(1,1,&ground) && backgroundHits==1,"ground equality exploded");
|
||
FlyingInstance compositeGround(data,sceneStart,sceneTarget);compositeGround.SetCollisionCallbacks(callbacks);
|
||
check(!compositeGround.Update(1,1,&ground,nullptr,[](float,float){return 100.0f;}) && backgroundHits==2,"composite map height override ignored");
|
||
data->hit_on_background=false;ground.height=100;FlyingInstance noBackground(data,sceneStart,sceneTarget);noBackground.SetCollisionCallbacks(callbacks);
|
||
check(noBackground.Update(1,1,&ground) && backgroundHits==2,"disabled background flag ignored");
|
||
// A 3D box proxy must not behave as a ground cylinder; original OBB tests endpoints.
|
||
OrientedBoundingBox box;box.centerX=50;box.centerY=20;box.halfExtents[0]=5;box.halfExtents[1]=5;box.halfExtents[2]=10;
|
||
const float above[3]={50,100,0},onBoundary[3]={56,20,0};check(!box.IntersectsSphere3D(above,1) && box.IntersectsSphere3D(onBoundary,1),"OBB 3D height/inclusive radius");
|
||
box.yawRad=3.14159265358979323846f/2;const float rotated[3]={60,20,0};check(box.IntersectsSphere3D(rotated,1),"OBB yaw ignored");
|
||
actors.Clear();fs::remove(path);
|
||
// Four parsed attachments produce four independently positioned ribbons.
|
||
{std::ofstream script(path);script<<"InitialVelocity 100\nRange 10000\nRollAngle 90\nAngularVelocity 0 0 90\n";
|
||
for(int type=1;type<=4;++type)script<<"Group AttachData\n{\nType 1\nFlyType "<<type<<"\nTailFlag 1\nTailColor 4294967295d\nTailLength 5\nTailSize 2\nRoll 90\nDistance 10\nPeriod 1\nAmplitude 20\n}\n";}
|
||
auto visualData=std::make_shared<FlyingData>();check(visualData->LoadScriptFile(path.string()) && visualData->attachments.size()==4
|
||
&& visualData->attach.fly_type==1 && visualData->attachments[3].amplitude==20 && visualData->angular_velocity[2]==90,"multi attachment script parsing");
|
||
const auto effectPath=fs::path(path.string()+".mse");
|
||
{std::ofstream(effectPath)<<"Group Particle { List TimeEventPosition { 0 MOVING_TYPE_DIRECT 0 0 0 } Group EmitterProperty { MaxEmissionCount 1 CycleLength 1 CycleLoopEnable 1 List TimeEventEmissionCountPerSecond { 0 20 } List TimeEventLifeTime { 0 20 } } Group ParticleProperty { BillboardType 1 AttachEnable 1 List TextureFiles { flight.dds } } }";}
|
||
for(auto& definition:visualData->attachments)definition.attach_file=effectPath.string();
|
||
auto& effects=EffectManager::Instance();effects.DeleteAllInstances();const auto unrelated=effects.CreateEffect(effectPath.string());check(unrelated!=0,"attachment effect fixture");
|
||
{
|
||
FlyingInstance visual(visualData,start,spreadTarget);check(effects.GetActiveInstanceCount()==5,"only one attachment created");
|
||
check(visual.Update(0.25f,0.25f),"visual flight died");float identity[16]={};for(int k=0;k<16;k+=5)identity[k]=1;
|
||
float tailProjection[16]={};tailProjection[0]=tailProjection[5]=0.001f;tailProjection[10]=0.0005f;tailProjection[14]=0.5f;tailProjection[15]=1;
|
||
std::vector<Render3DDraw> ribbons;visual.BuildDrawCommands(identity,tailProjection,0.25f,ribbons);check(ribbons.size()==4,"independent attachment tails missing");
|
||
const float amounts[]={0,10,20,20*std::exp(-0.25f)*0.25f};
|
||
for(int index=0;index<4;++index) {
|
||
const auto& positions=ribbons[index].positions;check(positions.size()>=9,"attachment ribbon geometry absent");
|
||
const float x=(positions[3]+positions[6])*0.5f,z=(positions[5]+positions[8])*0.5f;
|
||
check(near(x,-amounts[index]*std::cos(3.14159265358979323846f/8))
|
||
&& near(z,25+amounts[index]*std::sin(3.14159265358979323846f/8)),"LINE/MULTI/SINE/EXP offset or angular composition");
|
||
}
|
||
effects.Update(0.05f);const float camera[3]={0,0,100};std::vector<Render3DDraw> particles;effects.BuildDrawCommands(identity,identity,camera,particles);
|
||
check(particles.size()==5,"multi attachment effect draws missing");
|
||
for(int index=0;index<4;++index) {
|
||
const float expectedX=-amounts[index]*std::cos(3.14159265358979323846f/8),expectedZ=25+amounts[index]*std::sin(3.14159265358979323846f/8);
|
||
bool found=false;for(const auto& particle:particles) {
|
||
if(particle.positions.size()<12)continue;float x=0,z=0;
|
||
for(int vertex=0;vertex<4;++vertex){x+=particle.positions[vertex*3]/4;z+=particle.positions[vertex*3+2]/4;}
|
||
if(near(x,expectedX) && near(z,expectedZ))found=true;
|
||
}
|
||
check(found,"attachment global matrix did not reach particle drawing");
|
||
}
|
||
}
|
||
check(effects.GetActiveInstanceCount()==1 && effects.IsAliveEffect(unrelated),"attachment destruction leaked/deleted unrelated effect");
|
||
visualData->range=1;
|
||
{
|
||
FlyingInstance expiringVisual(visualData,start,spreadTarget);check(effects.GetActiveInstanceCount()==5,"expiring attachments not created");
|
||
check(!expiringVisual.Update(0.25f,0.25f) && effects.GetActiveInstanceCount()==1,"range termination did not clear owned attachments");
|
||
float identity[16]={};for(int k=0;k<16;k+=5)identity[k]=1;std::vector<Render3DDraw> clearedTails;
|
||
expiringVisual.BuildDrawCommands(identity,identity,0.25f,clearedTails);check(clearedTails.empty(),"terminated tails retained geometry");
|
||
}
|
||
effects.DeleteAllInstances();fs::remove(effectPath);fs::remove(path);
|
||
// Original tail is a six-vertex pointed strip, not a four-vertex ribbon.
|
||
float traceView[16]={},traceProjection[16]={};for(int k=0;k<16;k+=5)traceView[k]=traceProjection[k]=1;traceView[14]=10;traceProjection[0]=traceProjection[5]=0.001f;traceProjection[10]=0.0005f;traceProjection[14]=0.5f;
|
||
FlyTrace trace;trace.Create(0x80402010,1,2,false);trace.UpdateNewPosition(0,0,0,0);trace.UpdateNewPosition(10,0,0,0.5f);
|
||
std::vector<Render3DDraw> traceDraws;trace.BuildDrawCommands(traceView,traceProjection,0.5f,traceDraws);
|
||
check(traceDraws.size()==1 && traceDraws[0].positions.size()==18 && traceDraws[0].indices.size()==12,"source pointed tail topology");
|
||
const float expectedTrace[]={12,0,0,10,-2,0,10,2,0,0,-1,0,0,1,0,-1,0,0};
|
||
for(int k=0;k<18;++k)check(near(traceDraws[0].positions[k],expectedTrace[k]),"source camera-eye basis or width decay");
|
||
for(auto color:traceDraws[0].diffuse)check(color==0x80402010,"tail faded original constant alpha");
|
||
check(traceDraws[0].alpha_test && traceDraws[0].alpha_ref==0 && traceDraws[0].blend_mode==1,"tail alpha/additive states");
|
||
trace.Create(0xFFFFFFFF,1,2,true);trace.UpdateNewPosition(0,0,0,0);trace.UpdateNewPosition(10,0,0,0.5f);traceDraws.clear();
|
||
trace.BuildDrawCommands(traceView,traceProjection,0.5f,traceDraws);check(near(traceDraws[0].positions[9+1],-2),"rect tail width decayed");
|
||
trace.UpdateNewPosition(20,0,0,1);traceDraws.clear();trace.BuildDrawCommands(traceView,traceProjection,1,traceDraws);
|
||
check(traceDraws[0].positions.size()==36,"tail expiry equality removed oldest sample");
|
||
trace.UpdateNewPosition(30,0,0,1.001f);traceDraws.clear();trace.BuildDrawCommands(traceView,traceProjection,1.001f,traceDraws);
|
||
check(traceDraws[0].positions.size()==36,"tail strict expiry did not remove only oldest sample");
|
||
trace.Create(0xFFFFFFFF,0.005f,0.05f,false);trace.UpdateNewPosition(0,0,0,0);trace.UpdateNewPosition(10,0,0,0.002f);traceDraws.clear();
|
||
trace.BuildDrawCommands(traceView,traceProjection,0.002f,traceDraws);check(near(traceDraws[0].positions[0],10.05f),"small valid tail parameters replaced with defaults");
|
||
trace.Create(0xFFFFFFFF,0,2,false);trace.UpdateNewPosition(0,0,0,0);trace.UpdateNewPosition(10,0,0,0);traceDraws.clear();
|
||
trace.BuildDrawCommands(traceView,traceProjection,0,traceDraws);check(traceDraws.empty(),"zero-length tail generated invalid geometry");
|
||
trace.Create(0xFFFFFFFF,10,1,true);trace.UpdateNewPosition(0,0,0,0);trace.UpdateNewPosition(10,0,10,1);trace.UpdateNewPosition(20,0,15,2);traceDraws.clear();
|
||
trace.BuildDrawCommands(traceView,traceProjection,2,traceDraws);
|
||
check(traceDraws[0].positions.size()==36 && near((traceDraws[0].positions[5]+traceDraws[0].positions[8])*0.5f,10),"source depth sorting changed");
|
||
// Six normalized D3D clip planes: external tangency is OUTSIDE.
|
||
float clipView[16]={},clipProjection[16]={};for(int k=0;k<16;k+=5)clipView[k]=clipProjection[k]=1;
|
||
auto visible=[&](float x,float y,float z){FlyTrace clip;clip.Create(0xFFFFFFFF,10,100,true);clip.UpdateNewPosition(x,y,z-0.1f,0);clip.UpdateNewPosition(x,y,z+0.1f,1);std::vector<Render3DDraw> draws;clip.BuildDrawCommands(clipView,clipProjection,1,draws);return !draws.empty();};
|
||
check(visible(0,0,0.5f) && !visible(2,0,0.5f) && !visible(-2,0,0.5f)
|
||
&& !visible(0,2,0.5f) && !visible(0,-2,0.5f) && !visible(0,0,-1) && !visible(0,0,2),"six-plane tail clipping");
|
||
// Exact binary values avoid rounding the tangent comparison.
|
||
auto boundaryVisible=[&](float x){FlyTrace clip;clip.Create(0xFFFFFFFF,10,100,true);clip.UpdateNewPosition(x,0,0.25f,0);clip.UpdateNewPosition(x,0,0.75f,1);std::vector<Render3DDraw> draws;clip.BuildDrawCommands(clipView,clipProjection,1,draws);return !draws.empty();};
|
||
check(!boundaryVisible(1.25f) && boundaryVisible(1.249f),"frustum tangent/partial boundary");
|
||
// Width 100 must not enlarge the source's segment sphere.
|
||
check(!boundaryVisible(2),"tail width incorrectly enlarged culling sphere");
|
||
FlyTrace mixed; mixed.Create(0xFFFFFFFF,10,1,true);mixed.UpdateNewPosition(0,0,0.5f,0);mixed.UpdateNewPosition(0.5f,0,0.5f,1);mixed.UpdateNewPosition(4,0,0.5f,2);mixed.UpdateNewPosition(5,0,0.5f,3);
|
||
traceDraws.clear();mixed.BuildDrawCommands(clipView,clipProjection,3,traceDraws);check(traceDraws.size()==1 && traceDraws[0].positions.size()==12*3,"per-segment clipping/visible strip retained");
|
||
clipView[12]=-2;check(!visible(4,0,0.5f),"outside sphere accepted");
|
||
FlyTrace translated;translated.Create(0xFFFFFFFF,10,1,true);translated.UpdateNewPosition(2,0,0.4f,0);translated.UpdateNewPosition(2,0,0.6f,1);traceDraws.clear();translated.BuildDrawCommands(clipView,clipProjection,1,traceDraws);
|
||
check(!traceDraws.empty(),"view/projection matrix product order");
|
||
// Current client's standard perspective: near=1, far=100, 90-degree FOV.
|
||
for(int k=0;k<16;++k)clipView[k]=(k%5==0)?1.0f:0.0f;
|
||
std::fill(clipProjection,clipProjection+16,0);clipProjection[0]=clipProjection[5]=1;clipProjection[10]=100.0f/99;clipProjection[11]=1;clipProjection[14]=-100.0f/99;
|
||
check(visible(0.5f,0.3f,5) && !visible(0,0,0.5f) && !visible(0,0,200) && !visible(10,0,5),"perspective tail planes/coarse sphere");
|
||
// Original screen stores degree FOV but coarse sphere uses tan(degrees/2).
|
||
// At 20*pi degrees its coarse sphere excludes a plane-visible far corner.
|
||
const float historicalFov=20*3.14159265358979323846f;
|
||
clipProjection[0]=clipProjection[5]=1/std::tan(historicalFov*3.14159265358979323846f/360);
|
||
check(!visible(50,0,99),"source FOV unit mismatch in coarse sphere not preserved");
|
||
// UpdateGame snapshot survives render-time camera/projection changes.
|
||
Gr2SceneRenderer scene(32,32);scene.SetCameraLookAt(0,0,0,0,0,1,0,1,0);
|
||
scene.SetPerspective(90,1,1,100);scene.BuildViewFrustum();
|
||
FlyTrace cached;cached.Create(0xFFFFFFFF,10,0.1f,true);cached.UpdateNewPosition(0,0,5,0);cached.UpdateNewPosition(0,0,5.2f,1);
|
||
scene.SetCameraLookAt(100,0,0,100,0,1,0,1,0);scene.SetOrtho3D(2,2,0,10);
|
||
traceDraws.clear();cached.BuildDrawCommands(scene.GetViewMatrix(),scene.GetProjMatrix(),1,traceDraws,scene.GetCachedViewFrustum());
|
||
check(!traceDraws.empty(),"render-time setters invalidated UpdateGame frustum");
|
||
scene.BuildViewFrustum();traceDraws.clear();cached.BuildDrawCommands(scene.GetViewMatrix(),scene.GetProjMatrix(),1,traceDraws,scene.GetCachedViewFrustum());
|
||
check(traceDraws.empty(),"next UpdateGame did not refresh cached camera");
|
||
// Ortho planes retain the last perspective's coarse sphere, including degree FOV.
|
||
scene.SetCameraLookAt(0,0,0,0,0,1,0,1,0);scene.SetPerspective(historicalFov,1,1,100);scene.SetOrtho3D(200,200,0,100);scene.BuildViewFrustum();
|
||
check(scene.GetCachedViewFrustum()->Outside({50,0,99},0.1f),"ortho lost saved perspective coarse sphere");
|
||
check(!scene.GetCachedViewFrustum()->Outside({0,0,50},0.1f),"ortho coarse sphere rejects centre");
|
||
float offAxis[16];std::copy_n(scene.GetProjMatrix(),16,offAxis);offAxis[12]=0.2f;scene.SetProjectionMatrix(offAxis);scene.BuildViewFrustum();
|
||
check(scene.GetCachedViewFrustum()->Outside({50,0,99},0.1f),"custom projection lost coarse sphere metadata");
|
||
scene.SetOrtho2D(200,100,10);check(near(scene.GetProjMatrix()[12],-1) && near(scene.GetProjMatrix()[13],1) && near(scene.GetProjMatrix()[5],-0.02f),"ortho2d off-centre mapping");
|
||
// Source restores LESS but inherits ZENABLE/ZWRITE from the enclosing pass.
|
||
scene.SetDepthState({false,false});traceDraws.clear();cached.BuildDrawCommands(traceView,traceProjection,1,traceDraws,nullptr,scene.GetDepthState());
|
||
check(!traceDraws.empty() && !traceDraws[0].z_enable && !traceDraws[0].z_write && traceDraws[0].depth_less,"inherited tail depth states");
|
||
scene.SetDepthState({true,true});traceDraws.clear();cached.BuildDrawCommands(traceView,traceProjection,1,traceDraws,nullptr,scene.GetDepthState());
|
||
check(traceDraws[0].z_enable && traceDraws[0].z_write && traceDraws[0].depth_less,"default tail depth write forced off");
|
||
HardwareBatch le{},lt{};lt.depthLess=true;check(PipelineKey(le)!=PipelineKey(lt),"GPU pipeline key merges LESS and LESSEQUAL");
|
||
// Render equal-depth fragments: LESS must reject; additive writes still update depth.
|
||
scene.SetCameraLookAt(0,0,0,0,0,1,0,1,0);scene.SetOrtho3D(2,2,0,1);
|
||
auto* surface=SDL_CreateSurface(32,32,SDL_PIXELFORMAT_ARGB8888);check(surface!=nullptr,"depth surface allocation");
|
||
Render3DDraw triangle;triangle.positions={-0.8f,-0.8f,0.5f,0.8f,-0.8f,0.5f,0,0.8f,0.5f};triangle.indices={0,1,2};triangle.diffuse={0xFFFF0000,0xFFFF0000,0xFFFF0000};triangle.lighting=false;triangle.fog=false;triangle.cull_mode=1;
|
||
for(int k=0;k<16;k+=5)triangle.world[k]=1;
|
||
scene.Clear(0,1);SDL_FillSurfaceRect(surface,nullptr,0);scene.RenderDraw(surface,triangle);
|
||
const size_t pixel=16*32+16;const auto before=static_cast<uint32_t*>(surface->pixels)[pixel];check(scene.GetDepthBuffer()[pixel]<1,"depth triangle produced no fragments");
|
||
triangle.diffuse={0xFF00FF00,0xFF00FF00,0xFF00FF00};triangle.alpha_blend=true;triangle.blend_mode=1;triangle.depth_less=true;
|
||
scene.RenderDraw(surface,triangle);check(static_cast<uint32_t*>(surface->pixels)[pixel]==before,"LESS accepted equal-depth fragment");
|
||
triangle.depth_less=false;scene.RenderDraw(surface,triangle);check(static_cast<uint32_t*>(surface->pixels)[pixel]!=before,"LESSEQUAL rejected equal depth");
|
||
scene.Clear(0,1);triangle.depth_less=true;scene.RenderDraw(surface,triangle);check(scene.GetDepthBuffer()[pixel]<1,"additive depth-write state ignored");
|
||
scene.Clear(0,1);triangle.z_write=false;scene.RenderDraw(surface,triangle);check(scene.GetDepthBuffer()[pixel]==1,"disabled additive depth-write changed depth");
|
||
triangle.z_write=true;triangle.alpha_test=true;triangle.alpha_ref=84;triangle.diffuse={0x54FFFFFF,0x54FFFFFF,0x54FFFFFF};
|
||
scene.Clear(0,1);scene.RenderDraw(surface,triangle);check(scene.GetDepthBuffer()[pixel]==1,"software alpha accepted equal reference");
|
||
triangle.diffuse={0x55FFFFFF,0x55FFFFFF,0x55FFFFFF};scene.RenderDraw(surface,triangle);check(scene.GetDepthBuffer()[pixel]<1,"software alpha rejected greater reference");
|
||
scene.Clear(0,1);triangle.alpha_ref=0;triangle.diffuse={0x01FFFFFF,0x01FFFFFF,0x01FFFFFF};scene.RenderDraw(surface,triangle);check(scene.GetDepthBuffer()[pixel]<1,"zero alpha reference replaced by fallback threshold");
|
||
scene.Clear(0,1);triangle.diffuse={0x00FFFFFF,0x00FFFFFF,0x00FFFFFF};scene.RenderDraw(surface,triangle);check(scene.GetDepthBuffer()[pixel]==1,"fully transparent fragment wrote depth");
|
||
scene.Clear(0,1);triangle.alpha_ref=84;triangle.diffuse={0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF};triangle.material_diffuse[3]=0.25f;scene.RenderDraw(surface,triangle);
|
||
check(scene.GetDepthBuffer()[pixel]==1,"alpha tested before material modulation");
|
||
SDL_DestroySurface(surface);
|
||
trace.Clear();check(trace.IsEmpty(),"tail clear retained history");
|
||
// Actor resolver weak identity must reject deletion and same-VID replacement.
|
||
auto actor=std::make_unique<ActorInstance>();actor->SetVID(7);actor->SetPosition(20,30,40);ActorInstance* registered=actor.get();
|
||
ActorInstance::SetActorResolver([&](uint32_t vid){return vid==7?registered:nullptr;});
|
||
auto captured=actor->CaptureFlyTargetResolver();float center[3];check(captured(center) && center[0]==20 && center[2]==40,"actor target capture");
|
||
actor->SetPosition(25,30,45);check(captured(center) && center[0]==25 && center[2]==45,"actor target not live");
|
||
auto replacement=std::make_unique<ActorInstance>();replacement->SetVID(7);registered=replacement.get();
|
||
check(!captured(center),"VID reuse inherited old flight while old actor retained");actor.reset();check(!captured(center),"deleted actor resolver dereferenced");
|
||
registered=nullptr;ActorInstance::SetActorResolver({});
|
||
std::cout<<"AVA2 flying target lifecycle passed\n";return 0;
|
||
}catch(const std::exception& e){fs::remove(path);fs::remove(path.string()+".mse");ActorInstance::SetActorResolver({});std::cerr<<e.what()<<'\n';return 1;}
|
||
}
|