Files
Viano-Core/tests/clientless/test_flight_presentation.py
T
Nico f7a5899dc0 Fix ground graph re-entry and flight presentation
Bound expanded ground access probes and recover failed graph entry with checked walking searches. Unify airborne idle animation, observer updates and post-dismount movement cleanup for normal and emergency landings.

Add native registered-testbot flight controls, regression coverage and live reproduction fixtures. Record raid test setup and bound passive debugger variable printing after the observed diagnostic OOM.
2026-11-05 18:53:23 +01:00

80 lines
6.0 KiB
Python

"""Exercise production flight/hold/touchdown transitions and observer snapshots."""
from pathlib import Path
import subprocess
import tempfile
root=Path(__file__).resolve().parents[2]
s=(root/'src/server/game/World/ClientlessFlightMgr.cpp').read_text()
a=s.index('void ClientlessFlightMgr::PublishMovement(')
b=s.index('bool ClientlessFlightMgr::Follow(',a)
code=r'''
#include <cassert>
#include <cstdint>
#include <vector>
using uint32=uint32_t;using uint8=uint8_t;
constexpr uint32 MOVEMENTFLAG_FLYING=1,MOVEMENTFLAG_SWIMMING=2,MOVEMENTFLAG_FALLING=4,MOVEMENTFLAG_FALLING_FAR=8,
MOVEMENTFLAG_SPLINE_ELEVATION=16,MOVEMENTFLAG_FORWARD=32,MOVEMENTFLAG_ASCENDING=64,MOVEMENTFLAG_DESCENDING=128,
MOVEMENTFLAG_MASK_MOVING=4|8|16|32|64|128,MOVEMENTFLAG_MASK_TURNING=256,CAN_FLY=512,WATERWALKING=1024;
constexpr int UNIT_FIELD_BYTES_1=0,UNIT_BYTES_1_OFFSET_ANIM_TIER=0,SMSG_MOVE_UPDATE=42,SPELL_AURA_MOUNTED=7;
enum class AnimTier:uint8{Ground=0,Fly=3};
#define TC_LOG_INFO(...) ((void)0)
struct Guid{unsigned GetCounter()const{return 149;}};
struct Position{float x=1,y=2,z=80;void Relocate(Position const*p){*this=*p;}};
struct Info{Guid guid;Position pos;unsigned time=0,flags=0,fallTime=999;float pitch=1,splineElevation=7;
void SetFallTime(unsigned n){fallTime=n;}unsigned GetMovementFlags()const{return flags;}};
struct WorldPacket{explicit WorldPacket(int){} Info info;unsigned tier=0;bool hover=false,mounted=false;};
namespace GameTime{unsigned GetGameTimeMS(){return 123456;}}
struct Player{
Info m_movementInfo;Position position;unsigned tier=0,stops=0,swimStops=0;bool hover=false,gravity=false,levitating=false,spline=false,mounted=true;
std::vector<WorldPacket>updates;
Guid GetGUID(){return {};}Position const*GetPosition(){return &position;}
bool HasUnitMovementFlag(unsigned mask){return (m_movementInfo.flags&mask)!=0;}
void RemoveUnitMovementFlag(unsigned mask){m_movementInfo.flags&=~mask;}void AddUnitMovementFlag(unsigned mask){m_movementInfo.flags|=mask;}
bool IsHovering(){return levitating;}bool IsGravityDisabled(){return gravity;}bool IsPlayingHoverAnim(){return hover;}
unsigned GetByteValue(int,int){return tier;}void SetAnimTier(AnimTier t){tier=unsigned(t);}void SetPlayHoverAnim(bool v){hover=v;}
bool IsSplineEnabled(){return spline;}void StopMoving(){++stops;spline=false;RemoveUnitMovementFlag(MOVEMENTFLAG_FORWARD);}
void RemoveAurasByType(int){mounted=false;RemoveUnitMovementFlag(CAN_FLY);AddUnitMovementFlag(MOVEMENTFLAG_FALLING);}
void SetSwim(bool b){assert(!b);if(HasUnitMovementFlag(MOVEMENTFLAG_SWIMMING))++swimStops;RemoveUnitMovementFlag(MOVEMENTFLAG_SWIMMING);}
void WriteMovementInfo(WorldPacket&p){p.info=m_movementInfo;p.tier=tier;p.hover=hover;p.mounted=mounted;}
void SendMessageToSet(WorldPacket*p,bool){updates.push_back(*p);}
};
struct Record{bool Moving=false;unsigned Elapsed=0,HoldSyncAt=0;};
struct ClientlessFlightMgr{
void PublishMovement(Player*);bool SetAirbornePresentation(Player*,bool=false);
void HoldFollowing(Player*,Record&);void MaintainAirbornePresentation(Player*,Record&);void CompleteLanding(Player*);
};
''' + s[a:b] + r'''
int main(){ClientlessFlightMgr m;Player p;Record r;
p.m_movementInfo.flags=CAN_FLY|WATERWALKING|MOVEMENTFLAG_SWIMMING|MOVEMENTFLAG_FALLING|MOVEMENTFLAG_SPLINE_ELEVATION;
assert(m.SetAirbornePresentation(&p));assert(p.tier==3&&!p.hover&&p.HasUnitMovementFlag(MOVEMENTFLAG_FLYING));
assert(!p.HasUnitMovementFlag(MOVEMENTFLAG_SWIMMING|MOVEMENTFLAG_FALLING|MOVEMENTFLAG_SPLINE_ELEVATION));
assert(p.updates.size()==1&&p.updates.back().info.flags==(CAN_FLY|WATERWALKING|MOVEMENTFLAG_FLYING));
assert(!m.SetAirbornePresentation(&p));assert(p.updates.size()==1);
p.spline=true;r.Moving=true;p.AddUnitMovementFlag(MOVEMENTFLAG_FORWARD|MOVEMENTFLAG_ASCENDING|MOVEMENTFLAG_MASK_TURNING);
m.HoldFollowing(&p,r);assert(!r.Moving&&!p.spline&&p.stops==1&&p.hover&&p.tier==3);
assert(!p.HasUnitMovementFlag(MOVEMENTFLAG_MASK_MOVING|MOVEMENTFLAG_MASK_TURNING));
assert(p.position.x==1&&p.position.y==2&&p.position.z==80); // hover never moves or remounts
assert(p.updates.back().hover&&p.updates.back().info.pos.z==80);
auto n=p.updates.size();r.Elapsed=200;m.MaintainAirbornePresentation(&p,r);assert(p.updates.size()==n);
r.Elapsed=1000;m.MaintainAirbornePresentation(&p,r);assert(p.updates.size()==n+1);
assert(m.SetAirbornePresentation(&p));assert(!p.hover&&p.tier==3); // resume normal flight
p.AddUnitMovementFlag(MOVEMENTFLAG_SWIMMING|MOVEMENTFLAG_FALLING_FAR);m.CompleteLanding(&p);
assert(!p.mounted&&!p.hover&&p.tier==0&&p.m_movementInfo.flags==WATERWALKING&&p.swimStops==1);
assert(p.m_movementInfo.pitch==0&&p.m_movementInfo.splineElevation==0&&p.m_movementInfo.fallTime==0);
assert(!p.updates.back().mounted&&!p.updates.back().hover&&p.updates.back().tier==0&&p.updates.back().info.flags==WATERWALKING);
assert(p.position.z==80); // touchdown geometry belongs to caller; no invented landing/teleport
Player ground;Record gr;ground.m_movementInfo.flags=CAN_FLY;m.MaintainAirbornePresentation(&ground,gr);
assert(ground.tier==0&&ground.updates.empty()&&!ground.HasUnitMovementFlag(MOVEMENTFLAG_FLYING));
Player levitate;levitate.levitating=true;m.SetAirbornePresentation(&levitate);m.CompleteLanding(&levitate);assert(levitate.hover);
}
'''
# Verify both real touchdown paths and all free-flight launch types use the transitions.
assert s.count('CompleteLanding(player);')==2
for begin,end in [('AdvanceFollowing','Begin'),('AdvanceEmergency','RetryDeparture'),('Advance','Update')]:
a=s.index('bool ClientlessFlightMgr::'+begin+'(');b=s.index('bool ClientlessFlightMgr::'+end+'(',a)if end!='Update'else s.index('void ClientlessFlightMgr::Update(',a)
assert 'SetAirbornePresentation(player);'in s[a:b]
with tempfile.TemporaryDirectory()as d:
p=Path(d);(p/'test.cpp').write_text(code)
subprocess.run(['c++','-std=c++17','-fsanitize=address,undefined','-fno-omit-frame-pointer',str(p/'test.cpp'),'-o',str(p/'test')],check=True)
subprocess.run([str(p/'test')],check=True)
print('Flight presentation: moving/idle flight, bounded observer heartbeat, native dismount/fall cleanup, dry ground state and legitimate hover preservation passed')