Files
Viano-Core/tests/clientless/test_shared_flight_landing.py
T

67 lines
3.8 KiB
Python

"""Regression: join while leader walks to takeoff; continuous safe trail handoff."""
from pathlib import Path
import subprocess,tempfile
root=Path(__file__).resolve().parents[2]
source=(root/'src/server/game/World/ClientlessFlightMgr.cpp').read_text()
a=source.index(' if(record.Following && !record.Returning)',source.index('bool ClientlessFlightMgr::Advance('))
b=source.index(' Point current =',a)
sync=source[a:b]
code=r'''
#include "ClientlessFlightPath.h"
#include <cassert>
#include <iostream>
#include <memory>
#include <string>
using namespace ClientlessFlightPath;
struct Position{float x=0,y=0,z=0;void Relocate(float a,float b,float c){x=a;y=b;z=c;}};
struct Record{std::shared_ptr<SharedTrail> Following;std::shared_ptr<SharedTrail> Published=std::make_shared<SharedTrail>();bool Returning=false;struct{Position Landing;std::string Detail;}Status;};
bool Sync(Record& record){
''' + sync + r'''
return false;
}
int main(){
Record r;r.Following=std::make_shared<SharedTrail>();r.Status.Landing.z=777;
assert(Sync(r)&&r.Status.Landing.z==777); // still preparing; no zero landing copied
r.Following->Landing={12,34,827.765625f};r.Following->LandingReady=true;
assert(!Sync(r)&&r.Status.Landing.x==12&&r.Status.Landing.y==34&&r.Status.Landing.z==827.765625f);
assert(r.Published->LandingReady&&r.Published->Landing.Z==827.765625f);
Settings cfg;auto sample=[](float,float){return Surface{827.765625f,1000,true,0};};
auto clear=[](Point const&,Point const&){return true;};
// The same shared object first exists while its leader is walking to takeoff.
SharedTrail trail;Point landing{0,0,0};std::size_t index=0;
assert(!trail.BindLanding(landing));
auto pending=FollowTrail({0,0,0},landing,cfg,trail,index,sample,clear);
assert(pending.Waiting&&!pending.Step.Valid);
// Leader completes admission later. Follower must bind this published landing,
// including after the leader record is gone/has entered the instance.
trail.Landing={-4905.67f,-4232.75f,827.765625f};trail.LandingReady=true;
Point above{trail.Landing.X,trail.Landing.Y,trail.Landing.Z+10};trail.Points={above,trail.Landing};
// Old bug: stale zero goal retains the 8-yard floor margin during touchdown.
assert(!Corridor(above,trail.Landing,landing,cfg,sample,clear,true));
assert(trail.BindLanding(landing));index=1;
auto final=FollowTrail(above,landing,cfg,trail,index,sample,clear);
assert(final.Step.Valid&&final.Step.Landing&&Distance(final.Step.Next,landing)<.01f);
// In open air the next segment is ready before reaching the prior endpoint.
SharedTrail cruise;cruise.LandingReady=true;cruise.Landing={100,0,0};
cruise.Points={{25,0,60},{50,0,60}};
auto flat=[](float,float){return Surface{0,300,true};};
index=0;auto moving=FollowTrail({15,0,60},cruise.Landing,cfg,cruise,index,flat,clear,15);
assert(moving.Step.Valid&&moving.Step.Next.X==50&&index==1);
// No shortcut through a blocked corner, and no early escape-leg shortcut.
auto obstacle=[](Point const&a,Point const&b){return !(a.X<20&&b.X>30);};
index=0;auto corner=FollowTrail({15,0,60},cruise.Landing,cfg,cruise,index,flat,obstacle,15);
assert(corner.Step.Valid&&corner.Step.Next.X==25&&index==0);
cruise.UnderOverhang={true,false};index=0;
auto escape=FollowTrail({15,0,60},cruise.Landing,cfg,cruise,index,flat,clear,15);
assert(escape.Step.Valid&&index==0);
trail.Aborted=true;assert(!trail.BindLanding(landing));
assert(!FollowTrail(above,landing,cfg,trail,index,sample,clear).Step.Valid);
std::cout<<"Shared flight: late landing publication, terminal descent, early handoff, blocked/escape corners and abort PASS\n";
}
'''
with tempfile.TemporaryDirectory() as directory:
p=Path(directory);(p/'test.cpp').write_text(code)
subprocess.run(['c++','-std=c++17','-I'+str(root/'src/server/game/World'),str(p/'test.cpp'),'-o',str(p/'test')],check=True)
subprocess.run([str(p/'test')],check=True)