Files
WoW-Hybrid-gateway/tests/spline_ground_target_test.cpp
praxisandClaude Fable 5.2 7f2139d8d0 Offline test fixtures
883 files, from working commit b1a079a.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-19 01:32:48 +02:00

104 lines
9.8 KiB
C++

#include "gateway/splines.hpp"
#include <algorithm>
#include <bit>
#include <cmath>
#include <functional>
#include <iostream>
#include <limits>
using namespace gateway;
namespace {
unsigned checks=0;
void check(bool value,const char* message){++checks;if(!value)throw Error(message);}
void reject(const std::function<void()>& call){++checks;try{call();}catch(const Error&){return;}throw Error("expected spline rejection");}
void f32(Bytes& out,float value){le(out,std::bit_cast<uint32_t>(value),4);}
Guid128 identity(uint64_t counter,uint64_t high){Bytes raw;le(raw,counter,8);le(raw,high,8);Guid128 out{};std::copy(raw.begin(),raw.end(),out.begin());return out;}
constexpr uint64_t source_target=0xF13000000600119DULL;
Guid128 player(uint64_t counter,uint16_t realm=70){return identity(counter,(uint64_t(2)<<58)|(uint64_t(realm)<<42));}
Guid128 creature(uint16_t realm=70){return identity(source_target&0xffffff,(uint64_t(8)<<58)|(uint64_t(realm)<<42)|(uint64_t(6)<<6));}
Bytes source(uint8_t face=3,uint64_t target=source_target,uint32_t flags=0x100){
Bytes raw;le(raw,4518,8);Bytes out=pack_guid(raw);
for(float v:{1.f,2.f,3.f})f32(out,v);
le(out,19,4);le(out,face,1);
if(face==3)le(out,target,8);else if(face==4)f32(out,-1);
le(out,flags,4);le(out,400,4);le(out,2,4);
for(float v:{10.f,20.f,30.f})f32(out,v);
// Source destination-relative signed quarter-unit intermediate offset (1,-2,.5).
le(out,4u|(uint32_t(2040)<<11)|(2u<<22),4);return out;
}
}
int main(){try{
auto body=source();auto value=turtle_monster_spline(body);
check(value.guid==4518 && !value.flying && !value.stop && value.face==3 && value.facing_target==source_target,"ground player target-facing source identity");
check(value.start==std::array<float,3>{1,2,3} && value.points==std::vector<std::array<float,3>>{{9,22,29.5f},{10,20,30}},"source ground geometry changed");
auto mover=player(4518),target=creature();auto wire=forever_monster_spline(value,mover,SplineFacingTarget{target,-1.f});
Reader r(wire);check(unpack_guid(r,16)==Bytes(mover.begin(),mover.end()) && r.le(4)==19,"native mover/id");
check(r.le(4)==0x400000 && r.le(1)==2 && r.le(4)==0 && r.le(4)==400 && r.le(4)==0 && r.le(1)==0,"native target face enum/timing/flags");
check(unpack_guid(r,16)==Bytes(16) && r.le(1)==255,"native transport defaults");
auto angle=r.f32();check(angle>5.28f && angle<5.29f,"native target angle not normalized");
check(unpack_guid(r,16)==Bytes(target.begin(),target.end()),"target must follow angle as packed128");
check(r.take(5)==Bytes({0,2,0,0,0}),"native uncompressed point count/options");
for(const auto& point:value.points)for(float v:point)check(r.f32()==v,"native path changed");
check(r.le(1)==0,"moving spline stop bits");for(float v:value.start)check(r.f32()==v,"native start changed");r.end();
for(size_t n=0;n<body.size();++n)reject([&]{turtle_monster_spline(std::span(body).first(n));});
auto trailing=body;trailing.push_back(0);reject([&]{turtle_monster_spline(trailing);});
reject([&]{turtle_monster_spline(source(2));});reject([&]{turtle_monster_spline(source(3,0));});
reject([&]{turtle_monster_spline(source(3,0xF11000000600119DULL));});
reject([&]{turtle_monster_spline(source(3,source_target,0x101));});
reject([&]{forever_monster_spline(value,mover);});
reject([&]{forever_monster_spline(value,mover,SplineFacingTarget{creature(71),0});});
auto wrong_target=target;wrong_target[0]^=1;reject([&]{forever_monster_spline(value,mover,SplineFacingTarget{wrong_target,0});});
wrong_target=target;wrong_target[8]^=64;reject([&]{forever_monster_spline(value,mover,SplineFacingTarget{wrong_target,0});});
reject([&]{forever_monster_spline(value,mover,SplineFacingTarget{player(4518),0});});
reject([&]{forever_monster_spline(value,mover,SplineFacingTarget{target,std::numeric_limits<float>::quiet_NaN()});});
reject([&]{forever_monster_spline(value,mover,SplineFacingTarget{target,std::numeric_limits<float>::infinity()});});
auto normal=turtle_monster_spline(source(0));check(!forever_monster_spline(normal,mover).empty(),"ordinary player ground spline rejected");
reject([&]{forever_monster_spline(normal,mover,SplineFacingTarget{target,0});});
normal.facing_target=source_target;reject([&]{forever_monster_spline(normal,mover);});
auto player_target=value;player_target.facing_target=9001;
check(!forever_monster_spline(player_target,mover,SplineFacingTarget{player(9001),0}).empty(),"bound player facing target rejected");
auto angle_source=turtle_monster_spline(source(4));
check(!forever_monster_spline(angle_source,mover).empty(),"player ground final angle rejected");
// Existing stop and smooth-flight profiles remain distinct from the new ground path.
Bytes raw;le(raw,4518,8);Bytes stop=pack_guid(raw);
for(float v:{1.f,2.f,3.f}){f32(stop,v);}le(stop,20,4);le(stop,1,1);
auto stopped=turtle_monster_spline(stop);check(stopped.stop && stopped.points.empty() && !forever_monster_spline(stopped,mover).empty(),"player stop regressed");
Bytes flight=pack_guid(raw);for(float v:{1.f,2.f,3.f})f32(flight,v);
le(flight,21,4);le(flight,0,1);le(flight,0x300,4);le(flight,4000,4);le(flight,2,4);
for(float v:{4.f,5.f,6.f,7.f,8.f,9.f})f32(flight,v);
auto flying=turtle_monster_spline(flight);auto flying_wire=forever_monster_spline(flying,mover);Reader fr(flying_wire);unpack_guid(fr,16);fr.le(4);
check(flying.flying && flying.points.back()==std::array<float,3>{7,8,9} && fr.le(4)==0x400a00,"smooth flight grammar/flags regressed");
auto npc=turtle_monster_spline(unhex("cb9d110630f10000803f0000004000004040090000000000010000e803000002000000000020410000a0410000f04104c0bf00"));
check(forever_monster_spline(npc,creature())==unhex("03e39d11800118012009000000000040000000000000e803000000000000000000ff0002000000000010410000b0410000ec41000020410000a0410000f041000000803f0000004000004040"),"existing NPC ground golden changed");
// Exact Source7036/14E5 spline710794 at2026-11-06T19:34:26.699UTC.
// Four quarter-unit decoded points coincide; original native266f91e divides
// by the zero consecutive-vertex distance. These are wire points, not padding.
auto crash_body=unhex("dbe5147c1b30f169c2f1c5496504c5f41507438ad80a000000010000db0900000700000068dcf1c5586b04c5e3450643f4f77ffff4f77ffff4f77ffff4f77ffff227c0fffa170000");
auto captured=turtle_monster_spline(crash_body);
check(captured.guid==0xf130001b7c0014e5ULL && captured.id==710794 && captured.duration==2523 && captured.points.size()==7,"captured source identity/timing/path changed");
check(captured.points[0]==captured.points[1] && captured.points[1]==captured.points[2] && captured.points[2]==captured.points[3],"captured repeated vertices missing");
auto projected=project_native_monster_spline(captured);
const std::vector<std::array<float,3>> expected{captured.points[0],captured.points[4],captured.points[5],captured.points[6]};
check(projected.points==expected && captured.points.size()==7,"native projection must preserve raw source parse");
check(projected.start==captured.start && projected.points.back()==captured.points.back() && projected.id==captured.id && projected.duration==captured.duration && projected.face==captured.face && projected.angle==captured.angle && projected.facing_target==captured.facing_target,"projection changed motion identity/destination/timing/facing");
auto captured_mover=identity(captured.guid&0xffffff,(uint64_t(8)<<58)|(uint64_t(70)<<42)|(uint64_t(7036)<<6));
auto corrected_wire=forever_monster_spline(captured,captured_mover);Reader cr(corrected_wire);
check(unpack_guid(cr,16)==Bytes(captured_mover.begin(),captured_mover.end()) && cr.le(4)==710794 && cr.le(4)==0x400000,"captured native identity/linear flags");
check(cr.le(1)==0 && cr.le(4)==0 && cr.le(4)==2523 && cr.le(4)==0 && cr.le(1)==0,"captured native duration/defaults");
check(unpack_guid(cr,16)==Bytes(16) && cr.le(1)==255 && cr.take(5)==Bytes({0,4,0,0,0}),"captured native unique point count");
for(const auto& point:expected)for(float coordinate:point)check(cr.f32()==coordinate,"captured native geometry changed");
check(cr.le(1)==0,"captured non-Stop changed into Stop");for(float coordinate:captured.start)check(cr.f32()==coordinate,"captured native start changed");cr.end();
auto edge=captured;edge.start={0,0,0};edge.points={{0,0,0},{0,0,0},{1,2,3},{1,2,3},{4,5,6},{4,5,6}};
check(project_native_monster_spline(edge).points==std::vector<std::array<float,3>>{{1,2,3},{4,5,6}},"implicit start/trailing duplicate projection");
edge.points={{1,2,3}};check(project_native_monster_spline(edge).points==edge.points && !forever_monster_spline(edge,captured_mover).empty(),"one distinct destination must remain valid");
edge.points={{0.00001f,0,0},{0,0,0},{1,2,3}};check(project_native_monster_spline(edge).points==edge.points,"near/nonconsecutive vertices must not be collapsed");
for(uint8_t face:{uint8_t(3),uint8_t(4)}) {edge.face=face;edge.angle=-1;edge.facing_target=face==3?source_target:0;auto p=project_native_monster_spline(edge);check(p.face==edge.face && p.angle==edge.angle && p.facing_target==edge.facing_target,"facing projection changed");}
edge.face=0;edge.facing_target=0;edge.points={{0,0,0},{0,0,0}};
reject([&]{project_native_monster_spline(edge);});reject([&]{forever_monster_spline(edge,captured_mover);});
check(!edge.stop && edge.points.size()==2,"all-equal non-Stop was rewritten");
auto repeated_flight=flying;repeated_flight.points={flying.start,flying.start,flying.points.back()};
check(project_native_monster_spline(repeated_flight).points==repeated_flight.points && !forever_monster_spline(repeated_flight,mover).empty(),"smooth repeated controls must remain unchanged");
auto terminal=project_native_monster_spline(stopped);check(terminal.stop && terminal.points.empty() && terminal.start==stopped.start && forever_monster_spline(terminal,mover)==forever_monster_spline(stopped,mover),"explicit Stop changed");
std::cout<<checks<<" ground-player/target-facing source and native contract checks PASS; live movement remains separate.\n";
return 0;
}catch(const std::exception& e){std::cerr<<e.what()<<'\n';return 1;}}