Align AVA2 Windows behavior and improve mobile touch interactions
This commit is contained in:
@@ -171,6 +171,23 @@ void TestComboStateMachine(const char* model) {
|
||||
fast.Update(0.1f);
|
||||
assert(Near(fast.GetAttackingElapsedTime(), 0.15f, 1e-3f));
|
||||
|
||||
// SetAttackSpeed stores zero but does not retime the already bound attack.
|
||||
fast.SetAttackSpeed(0);
|
||||
fast.Update(0.1f);
|
||||
assert(Near(fast.GetAttackingElapsedTime(), 0.30f, 1e-3f));
|
||||
assert(fast.RunComboAttack(0, RaceData::NAME_COMBO_ATTACK_1));
|
||||
fast.Update(0.1f);
|
||||
assert(Near(fast.GetAttackingElapsedTime(), 0));
|
||||
assert(!fast.IsMotionFinished());
|
||||
fast.SetAttackSpeed(2);
|
||||
fast.Update(0.1f);
|
||||
assert(Near(fast.GetAttackingElapsedTime(), 0));
|
||||
assert(fast.RunComboAttack(0, RaceData::NAME_COMBO_ATTACK_1));
|
||||
fast.Update(0.1f);
|
||||
assert(Near(fast.GetAttackingElapsedTime(), 0.2f, 1e-3f));
|
||||
fast.SetAttackSpeed(-1);
|
||||
assert(Near(fast.GetAttackSpeed(), 2));
|
||||
|
||||
// Without SetReportAttacks nothing is queued (remote actors).
|
||||
ava2::ActorInstance remote;
|
||||
assert(remote.SetRace(0) && remote.SetModel(model));
|
||||
|
||||
@@ -1382,7 +1382,8 @@ int main(int argc, char** argv) {
|
||||
trace.UpdateNewPosition(25.0f, 110.0f, 15.0f, 0.10f);
|
||||
assert(!trace.IsEmpty() && "FlyTrace must contain positions");
|
||||
std::vector<ava2::Render3DDraw> traceDraws;
|
||||
trace.BuildDrawCommands(dummyView, dummyProj, 0.12f, traceDraws);
|
||||
float traceProjection[16]={};traceProjection[0]=traceProjection[5]=0.001f;traceProjection[10]=0.0005f;traceProjection[14]=0.5f;traceProjection[15]=1;
|
||||
trace.BuildDrawCommands(dummyView,traceProjection,0.12f,traceDraws);
|
||||
assert(!traceDraws.empty() && "FlyTrace must generate ribbon quad draw commands");
|
||||
assert(traceDraws[0].blend_mode == 1 && "FlyTrace must use Additive blend mode");
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "python_background.h"
|
||||
#include "python_gameplay_modules.h"
|
||||
#include "python_runtime.h"
|
||||
#include "python_app.h"
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <filesystem>
|
||||
@@ -177,6 +178,78 @@ int main(int argc, char** argv) {
|
||||
"assert bg.GetCurrentMapName() == ''\n"
|
||||
);
|
||||
|
||||
std::cout << "[TEST] Map height scale, visibility, streaming and water parity..." << std::endl;
|
||||
// MapOutdoorLoad::LoadSetting -> AreaTerrain scaled raw heights and water vertices.
|
||||
spit(root/"map/scaled_map/setting.txt","ScriptType MapSetting\nMapSize 4 1\nBasePosition 50000 60000\nHeightScale 2\nTerrainVisible 0\nTextureSet textureset/scaled.txt\n");
|
||||
spit(root/"textureset/scaled.txt","Start Texture004\n\"scaled.dds\"\n2\n3\n0\n0\n1\n0\n0\nEnd Texture004\n");
|
||||
std::string water(7+128*128+8,char(0xff));
|
||||
auto word=[&](size_t offset,uint16_t value) {water[offset]=char(value);water[offset+1]=char(value>>8);};
|
||||
word(0,5426);word(2,128);word(4,128);water[6]=2;
|
||||
water[7+128+1]=0;water[7+128+2]=1; // Odd row/column cell; second layer is -1 (no water).
|
||||
const size_t waterHeightOffset=7+128*128;
|
||||
for(int byte=0;byte<4;++byte)water[waterHeightOffset+byte]=char(uint32_t(1000)>>(8*byte));
|
||||
for(int block=0;block<4;++block) {
|
||||
char name[16];std::snprintf(name,sizeof(name),"%03d000",block);
|
||||
std::vector<uint16_t> scaledRaw(131*131,uint16_t(200+block*100));
|
||||
spit(root/"map/scaled_map"/name/"height.raw",std::string(reinterpret_cast<const char*>(scaledRaw.data()),scaledRaw.size()*2));
|
||||
spit(root/"map/scaled_map"/name/"water.wtr",water);
|
||||
}
|
||||
auto& background=CPythonBackground::Instance();
|
||||
for(int part=0;part<CPythonBackground::PART_NUM;++part)background.SetVisiblePart(part,false);
|
||||
background.SetVisiblePart(CPythonBackground::PART_TERRAIN,true);
|
||||
require(background.LoadMap("scaled_map"),"scaled map load");
|
||||
require(background.GetHeight(100,100)==400 && background.GetTerrain()->GetHeightScale()==2,"map HeightScale ignored");
|
||||
require(background.GetTerrain()->GetCellScale()==200,"original fixed CellScale changed");
|
||||
std::vector<Render3DDraw> draws;background.BuildDrawCommands(nullptr,nullptr,nullptr,draws);
|
||||
require(draws.empty() && background.IsVisiblePart(CPythonBackground::PART_TERRAIN),"map TerrainVisible must independently suppress draws");
|
||||
auto* firstTerrain=background.GetTerrain();background.Update(3*25600+100,100,0);
|
||||
require(background.GetTerrain()==firstTerrain && background.GetHeight(3*25600+100,100)==1000,"streamed blocks lost HeightScale or replaced active terrain");
|
||||
auto* loadedWater=background.GetWater();require(loadedWater && loadedWater->GetWaterLevel()==2000,"water scale/bias diverged from original");
|
||||
require(loadedWater->GetWaterFaceCount()==2,"invalid -1 water layer counted");
|
||||
auto waterDraw=loadedWater->BuildDrawCommand(0);
|
||||
require(waterDraw.positions.size()==12 && waterDraw.indices.size()==6,"odd water cell skipped or expanded across dry cells");
|
||||
require(waterDraw.positions[0]==2*25600+200 && waterDraw.positions[1]==2000 && waterDraw.positions[2]==200,"water uses bordered terrain origin or fixed height offset");
|
||||
background.SetVisiblePart(CPythonBackground::PART_WATER,true);
|
||||
draws.clear();background.BuildDrawCommands(nullptr,nullptr,nullptr,draws);
|
||||
require(draws.size()==2,"TerrainVisible disabled water or emitted hidden terrain");
|
||||
// Missing optional settings in existing minimal fixtures must reset to defaults, not leak.
|
||||
spit(root/"map/reset_map/setting.txt","ScriptType MapSetting\nMapSize 1 1\n");
|
||||
std::vector<uint16_t> resetRaw(131*131,200);
|
||||
spit(root/"map/reset_map/000000/height.raw",std::string(reinterpret_cast<const char*>(resetRaw.data()),resetRaw.size()*2));
|
||||
require(background.LoadMap("reset_map"),"default map load");
|
||||
require(background.GetHeight(100,100)==100 && background.GetOutdoorMap()->baseX==0 && background.GetTerrain()->GetTextureSet().empty(),"map settings/textures inherited");
|
||||
draws.clear();background.BuildDrawCommands(nullptr,nullptr,nullptr,draws);
|
||||
require(!draws.empty(),"default TerrainVisible not restored");
|
||||
background.SetVisiblePart(CPythonBackground::PART_TERRAIN,false);draws.clear();
|
||||
background.BuildDrawCommands(nullptr,nullptr,nullptr,draws);require(draws.empty(),"runtime terrain visibility ignored");
|
||||
background.SetVisiblePart(CPythonBackground::PART_TERRAIN,true);
|
||||
// A valid camera whose entire map is beyond its draw distance must not trigger an uncullable full-map fallback.
|
||||
const float view[16]={1,0,0,0,0,1,0,0,0,0,1,0,0,0,1000000,1};
|
||||
const float proj[16]={1,0,0,0,0,1,0,0,0,0,1,1,0,0,-1,0};
|
||||
const float eye[3]={0,0,-1000000};
|
||||
std::vector<Render3DDrawRef> refs;draws.clear();background.BuildDrawCommands(view,proj,eye,draws,&refs);
|
||||
require(draws.empty() && refs.empty(),"culled terrain reappeared through full-map fallback");
|
||||
spit(root/"map/reset_map/setting.txt","ScriptType MapSetting\nMapSize 1 1\nHeightScale 1.25\n");
|
||||
require(background.LoadMap("reset_map",100000,0),"fallback terrain load");
|
||||
require(background.GetHeight(100,100)==250,"fallback terrain ignored scale");
|
||||
spit(root/"map/reset_map/setting.txt","ScriptType MapSetting\nMapSize 1 1\nHeightScale nan\n");
|
||||
require(!background.LoadMap("reset_map") && !background.IsMapReady(),"non-finite terrain heights accepted");
|
||||
background.Destroy();
|
||||
require(background.LoadMap("test_bg_map"),"forest clock map load");
|
||||
SpeedTreeForest reference;
|
||||
reference.CreateInstance(0,0,300,191919,0,1,"clock");
|
||||
background.GetForest()->CreateInstance(0,0,300,191919,0,1,"clock");
|
||||
const float treeView[16]={1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1};
|
||||
const float treeProj[16]={1,0,0,0,0,1,0,0,0,0,1,1,0,0,-1,0};
|
||||
for(float elapsed:{0.125f,0.375f,0.0f}) {
|
||||
SetGameFrameDelta(elapsed);background.Update(0,0,0);reference.UpdateSystem(GetGameFrameDelta());
|
||||
auto expected=reference.BuildDrawCommands(treeView,treeProj,0,50,0);
|
||||
auto actual=background.GetForest()->BuildDrawCommands(treeView,treeProj,0,50,0);
|
||||
require(!actual.empty() && actual.size()==expected.size(),"forest clock draw fixture");
|
||||
for(size_t i=0;i<actual.size();++i)require(actual[i].positions==expected[i].positions,"background wind uses fixed 0.033 instead of frame delta");
|
||||
}
|
||||
SetGameFrameDelta(0.033f);background.Destroy();
|
||||
|
||||
std::cout << "[TEST] Running block 4 (app camera bindings)..." << std::endl;
|
||||
python.execute(
|
||||
"import app\n"
|
||||
|
||||
@@ -77,9 +77,9 @@ void TestSafeBoxCpp() {
|
||||
std::cout << "[Test 2] Testing CPythonSafeBox storeroom..." << std::endl;
|
||||
auto& sb = CPythonSafeBox::Instance();
|
||||
|
||||
// Open 3 pages (3 * 45 = 135 slots)
|
||||
// Windows OpenSafeBox takes rows: three rows * five columns, not three pages.
|
||||
sb.OpenSafeBox(3);
|
||||
assert(sb.GetCurrentSafeBoxSize() == 135);
|
||||
assert(sb.GetCurrentSafeBoxSize() == 15);
|
||||
|
||||
sb.SetMoney(9876543);
|
||||
assert(sb.GetMoney() == 9876543);
|
||||
@@ -106,8 +106,8 @@ void TestSafeBoxCpp() {
|
||||
assert(sb.GetSlotItemID(5, &queriedVnum) && queriedVnum == 0);
|
||||
|
||||
// Mall
|
||||
sb.OpenMall(2); // 2 * 45 = 90 slots
|
||||
assert(sb.GetMallSize() == 90);
|
||||
sb.OpenMall(2); // Two rows * five columns.
|
||||
assert(sb.GetMallSize() == 10);
|
||||
|
||||
TItemData mallItem;
|
||||
mallItem.vnum = 70005; // Teleportation Ring
|
||||
|
||||
@@ -0,0 +1,265 @@
|
||||
#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");
|
||||
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;}
|
||||
}
|
||||
@@ -63,6 +63,19 @@ int main() {
|
||||
color=center({near,masked});assert(color[2]>245&&color[0]<5);
|
||||
near.depthWrite=false;color=center({near,far});assert(color[1]>245&&color[0]<5);
|
||||
near.depthWrite=true;near.cull=2;color=center({near});assert(color[0]>245);
|
||||
// Original FlyTrace uses LESS, additive blending and inherited depth write.
|
||||
auto equal=near;equal.cull=1;equal.firstIndex=3;equal.blend=equal.additive=true;equal.depthLess=true;
|
||||
for(int i=3;i<6;++i)vertices[i].position[2]=.2f;
|
||||
near.cull=1;color=center({near,equal});assert(color[0]>245 && color[1]<5);
|
||||
equal.depthLess=false;color=center({near,equal});assert(color[0]>245 && color[1]>245);
|
||||
equal.depthLess=true;equal.depthWrite=true;color=center({equal,near});assert(color[0]>245 && color[1]<5); // near defaults LESSEQUAL
|
||||
auto behind=near;behind.firstIndex=6;behind.depthLess=true;
|
||||
for(int i=6;i<9;++i){vertices[i].position[2]=.4f;vertices[i].color[3]=255;}
|
||||
color=center({equal,behind});assert(color[1]>245 && color[2]<5);
|
||||
equal.depthWrite=false;color=center({equal,behind});assert(color[2]>245 && color[1]<5);
|
||||
equal.depth=false;color=center({near,equal});assert(color[0]>245 && color[1]>245);
|
||||
for(int i=3;i<6;++i)vertices[i].position[2]=.8f;
|
||||
for(int i=6;i<9;++i){vertices[i].position[2]=.1f;vertices[i].color[3]=51;}
|
||||
// Perspective-correct color interpolation: top W=2 doubles its reciprocal denominator.
|
||||
auto saved=vertices;
|
||||
vertices[2].position[1]*=2;vertices[2].position[2]*=2;vertices[2].position[3]=2;
|
||||
|
||||
@@ -124,6 +124,12 @@ int main(int argc, char** argv) {
|
||||
runtime.execute("assert mouseModule.mouseController.isAttached(), calls\n"
|
||||
"assert mouseModule.mouseController.GetAttachedSlotNumber() == 0, 'pick slot'\n");
|
||||
assert(wm->IsAttaching());
|
||||
runtime.execute("import grpImage\nicon_positions=[]\noriginal_set_position=grpImage.SetPosition\n"
|
||||
"grpImage.SetPosition=lambda h,x,y: icon_positions.append((h,x,y))\n"
|
||||
"mouseModule.mouseController.Update(100,200)\n"
|
||||
"mc=mouseModule.mouseController\n"
|
||||
"assert icon_positions[-1][2] < 200-mc.AttachedIconHalfHeight-30,icon_positions\n"
|
||||
"grpImage.SetPosition=original_set_position\n");
|
||||
// Tap an empty cell: dropped there with the original move packet.
|
||||
Tap(router, x5, y5);
|
||||
runtime.execute("assert not mouseModule.mouseController.isAttached(), ('drop', attached(), calls)\n"
|
||||
|
||||
@@ -0,0 +1,326 @@
|
||||
#include "python_runtime.h"
|
||||
#include "python_gameplay_modules.h"
|
||||
#include "eter_net/PythonNetworkStream.h"
|
||||
#include "eter_net/NetworkActorManager.h"
|
||||
#include "eter_render/RaceData.h"
|
||||
#include "eter_render/CRenderTarget.h"
|
||||
#include "eter_effect/FlyingManager.h"
|
||||
#include "eter_render/MapObjectManager.h"
|
||||
#include "test_rundir.h"
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <cmath>
|
||||
#include <array>
|
||||
using namespace ava2;
|
||||
namespace fs=std::filesystem;
|
||||
static uint32_t motionRandom=0,motionRandomCalls=0;
|
||||
static uint32_t RandomMotion() {++motionRandomCalls;return motionRandom;}
|
||||
static uint32_t motionClock=1000;
|
||||
static uint32_t Clock() {return motionClock;}
|
||||
static uint32_t shakeRandomCalls=0;
|
||||
static uint32_t ShakeRandom() {static const uint32_t values[]={0,3,1,4,0,5};return values[(shakeRandomCalls++)%6];}
|
||||
static void require(bool ok,const char* why) {if(!ok) throw std::runtime_error(why);}
|
||||
int main(int argc,char** argv) {
|
||||
if(argc!=2) return 2;
|
||||
const auto previous=fs::current_path();
|
||||
if(!ava2_test::EnterTestRunDir()) return ava2_test::kSkip;
|
||||
const auto stdlib=fs::absolute(argv[1]);
|
||||
const auto model=fs::absolute("ymir work/pc/warrior/warrior_assasin1.gr2");
|
||||
const auto animation=fs::absolute("ymir work/pc/warrior/general/wait.gr2");
|
||||
const std::array<fs::path,3> variantAnimations={animation,fs::absolute("ymir work/pc/warrior/general/walk.gr2"),fs::absolute("ymir work/pc/warrior/general/run.gr2")};
|
||||
if(!fs::exists(model) || !fs::exists(animation) || !fs::exists(variantAnimations[1]) || !fs::exists(variantAnimations[2])) return ava2_test::kSkip;
|
||||
const auto root=fs::temp_directory_path()/("ava2-motion-"+std::to_string(std::chrono::steady_clock::now().time_since_epoch().count()));
|
||||
try {
|
||||
fs::create_directories(root);fs::current_path(root);
|
||||
auto* race=RaceManager::Instance().CreateRace(1);race->RegisterMotionMode(1);
|
||||
for(uint16_t index=1;index<=RaceData::NAME_JOY;++index) {
|
||||
const auto path=root/(std::to_string(index)+".msa");
|
||||
std::ofstream(path)<<"ScriptType MotionData\nMotionFileName \""<<animation.string()<<"\"\nMotionDuration 1\n"
|
||||
<<(index==RaceData::NAME_SKILL ? "Group LoopData\n{\nMotionLoopCount -1\nLoopCancelEnable 1\nLoopStartTime 0\nLoopEndTime 0.3\n}\n" : "");
|
||||
require(race->RegisterMotion(1,index,path.string(),100),"synthetic motion registration");
|
||||
}
|
||||
std::ofstream(root/"skillgate.txt")<<"type active\nname Gate\niconfilename icon.dds\nneedspformula 1\nmotionindex 1\n";
|
||||
std::weak_ptr<CRenderTarget> preview;
|
||||
{
|
||||
PythonRuntime python(stdlib,root);auto& net=PythonNetworkStream::Instance();auto& actors=NetworkActorManager::Instance();
|
||||
preview=CRenderTargetManager::Instance().CreateRenderTarget(12345);
|
||||
actors.Clear();net.SetPhase(PHASE_GAME);net.SetMainActorVID(10);
|
||||
SNetworkActorData main{};main.m_dwVID=10;main.m_dwRace=1;main.m_bType=6;
|
||||
SNetworkActorData target=main;target.m_dwVID=20;target.m_stName="MotionTarget";
|
||||
actors.AppendActor(main);actors.AppendActor(target);
|
||||
auto actor=actors.GetActorInstance(10);auto victim=actors.GetActorInstance(20);
|
||||
require(actor && victim && actor->SetModel(model.string()) && victim->SetModel(model.string()),"GR2 motion fixture");
|
||||
actor->SetHP(1000);victim->SetHP(1000);actor->SetPosition(0,0,0);victim->SetPosition(100,0,0);
|
||||
require(actor->SetLoopMotionIndex(RaceData::NAME_WAIT),"wait motion fixture");
|
||||
python.execute("import player,net\nclass W:\n def __init__(self): self.fail=0\n def OnFishingFailure(self): self.fail+=1\nw=W()\nnet.SetPhaseWindow(net.PHASE_WINDOW_GAME,w)\nplayer.SetGameWindow(w)\n");
|
||||
python.execute("import skill\nskill.RegisterSkill(220,'skillgate.txt')\n");SetPlayerSkill(30,220);SetPlayerSkillLevel(220,0,1);SetPlayerStatusPoint(7,100);
|
||||
require(actor->InterceptMotionIndex(RaceData::NAME_SKILL,false) && actor->CanUseSkill(),"cancel-enabled current skill fixture");
|
||||
net.ClearSendQueue();ClickSkillSlot(30);require(net.GetSendQueue().empty(),"ClickSkillSlot bypassed original second IsUsingSkill gate");
|
||||
require(actor->SetLoopMotionIndex(RaceData::NAME_WAIT),"restore wait after skill gate");
|
||||
auto motion=[&](uint32_t index) {require(uint32_t(actor->GetCurrentMotion())==index,"incorrect current motion");};
|
||||
auto next=[&]() {actor->Update(actor->GetMotionDuration()+0.01f);};
|
||||
auto fishing=[&](uint8_t subtype,uint32_t vid=10,uint8_t dir=0) {
|
||||
const uint8_t packet[]={89,subtype,uint8_t(vid),uint8_t(vid>>8),uint8_t(vid>>16),uint8_t(vid>>24),dir};
|
||||
net.PushRecvData(packet,sizeof(packet));net.ProcessRecvData();
|
||||
};
|
||||
fishing(2);next();motion(RaceData::NAME_WAIT); // React ignored outside WAIT/REACT fishing motions.
|
||||
fishing(0,10,18);require(actor->GetYaw()==90,"fishing direction is not BYTE*5");
|
||||
require(!actor->IsFishing(),"queued throw treated as fishing");next();motion(RaceData::NAME_FISHING_THROW);
|
||||
require(!actor->IsFishing(),"throw treated as fishing");
|
||||
fishing(1);next();motion(RaceData::NAME_FISHING_WAIT);require(actor->IsFishing(),"wait not fishing");
|
||||
fishing(2);next();motion(RaceData::NAME_FISHING_REACT);require(actor->IsFishing(),"react not fishing");
|
||||
next();motion(RaceData::NAME_FISHING_WAIT);
|
||||
fishing(1);motion(RaceData::NAME_FISHING_STOP);require(!actor->IsFishing(),"stop remains fishing");next();motion(RaceData::NAME_WAIT);
|
||||
fishing(0);next();next();motion(RaceData::NAME_FISHING_WAIT);
|
||||
fishing(3);motion(RaceData::NAME_FISHING_CATCH);next();motion(RaceData::NAME_WAIT);
|
||||
fishing(4);motion(RaceData::NAME_FISHING_FAIL);python.execute("assert w.fail==1\n");next();motion(RaceData::NAME_WAIT);
|
||||
fishing(4,20);python.execute("assert w.fail==1\n"); // Remote failure does not call local UI.
|
||||
fishing(0,999);motion(RaceData::NAME_WAIT);
|
||||
uint8_t dig[]={134,10,0,0,0,20,0,0,0,3};
|
||||
net.PushRecvData(dig,5);net.ProcessRecvData();next();motion(RaceData::NAME_WAIT);
|
||||
net.PushRecvData(dig+5,5);net.ProcessRecvData();require(std::abs(actor->GetYaw()-90)<0.001f,"dig target facing");
|
||||
for(int count=0;count<3;++count) {next();motion(RaceData::NAME_DIG);}
|
||||
next();motion(RaceData::NAME_WAIT); // Exactly the received count, no extra repetition.
|
||||
for(uint32_t start:{uint32_t(RaceData::NAME_KISS_START),uint32_t(RaceData::NAME_FRENCH_KISS_START)}) {
|
||||
for(uint32_t job=0;job<4;++job) {
|
||||
require(actor->InterceptMotionIndex(start+job,false),"kiss motion fixture");
|
||||
python.execute("assert player.IsActingEmotion()==1\n");
|
||||
next();python.execute("assert player.IsActingEmotion()==0\n");
|
||||
}
|
||||
}
|
||||
for(uint32_t index:{uint32_t(RaceData::NAME_CLAP),uint32_t(RaceData::NAME_DANCE_1),uint32_t(RaceData::NAME_DIG),uint32_t(RaceData::NAME_SLAP_HIT_START)}) {
|
||||
require(actor->InterceptMotionIndex(index,false),"nonkiss fixture");python.execute("assert player.IsActingEmotion()==0\n");
|
||||
}
|
||||
// Original dual-emotion scheduler: 500ms delay, 100-unit approach, high/low roles.
|
||||
auto* secondRace=RaceManager::Instance().CreateRace(2);secondRace->RegisterMotionMode(1);
|
||||
for(uint16_t index=1;index<=RaceData::NAME_JOY;++index)require(secondRace->RegisterMotion(1,index,(root/(std::to_string(index)+".msa")).string(),100),"second job motions");
|
||||
require(victim->SetRace(2) && victim->SetModel(model.string()),"second job model");
|
||||
actors.GetActorData(20)->m_dwRace=2;
|
||||
actor->SetLoopMotionIndex(RaceData::NAME_WAIT);victim->SetLoopMotionIndex(RaceData::NAME_WAIT);
|
||||
actor->SetPosition(0,0,0);victim->SetPosition(500,0,0);actor->SetSpeed(100);
|
||||
actors.SetTimeSourceForTest(Clock);motionClock=1000;
|
||||
net.ServerCommand("kiss 10 20");require(actors.IsEmotionProcessing(),"main emotion processing not started");
|
||||
require(!actors.BeginDualEmotion(10,20,RaceData::NAME_KISS_START,RaceData::NAME_KISS_START),"overlapping pair accepted");
|
||||
SetPlayerJoystick(true,1,0);float yaw=0;require(!GetPlayerMovementYaw(0,yaw),"movement input not blocked during approach");
|
||||
actor->SetMoveTarget(999,999);require(!actor->HasMoveTarget(),"click movement bypassed emotion lock");
|
||||
actor->MoveInDirection(90,1);require(actor->GetX()==0,"direct movement bypassed lock");
|
||||
SNetworkMoveActorData move{};move.m_dwVID=10;move.m_dwFunc=0;move.m_lPosX=700;move.m_lPosY=0;
|
||||
actors.MoveActor(move);motionClock=1499;actors.Update(0);
|
||||
require(actor->GetX()==0 && victim->GetX()==500,"emotion started before deadline/network move escaped lock");
|
||||
motionClock=1500;actors.Update(0);require(actor->GetX()==0 && actor->GetCurrentMotion()==MotionType::Run,"approach not started at deadline");
|
||||
actors.Update(1);require(actor->GetX()==100 && actors.IsEmotionProcessing(),"approach teleported or unlocked early");
|
||||
for(int step=0;step<3;++step)actors.Update(1);
|
||||
require(actor->GetX()==400 && victim->GetX()==500 && !actors.IsEmotionProcessing(),"dual spacing/completion");
|
||||
require(uint32_t(actor->GetCurrentMotion())==RaceData::NAME_KISS_START+2 && uint32_t(victim->GetCurrentMotion())==RaceData::NAME_KISS_START+1,"dual job selection");
|
||||
require(std::abs(actor->GetYaw()-90)<0.001f && std::abs(victim->GetYaw()-270)<0.001f,"dual mutual facing");
|
||||
require(!GetPlayerMovementYaw(0,yaw),"movement unlocked during kiss playback");
|
||||
actors.Update(actor->GetMotionDuration()+0.01f);actors.Update(0);
|
||||
require(actor->GetCurrentMotion()==MotionType::Wait && GetPlayerMovementYaw(0,yaw),"emotion input did not recover");
|
||||
// Stop packets resume after playback instead of getting discarded.
|
||||
require(actors.GetActorData(10)->m_lDstX==700,"deferred movement was discarded");
|
||||
SetPlayerJoystick(false,0,0);
|
||||
actor->SetPosition(400,0,0);victim->SetPosition(500,0,0);motionClock=2000;
|
||||
net.ServerCommand("slap 10 20");motionClock=2500;actors.Update(0);
|
||||
require(uint32_t(actor->GetCurrentMotion())==RaceData::NAME_SLAP_HIT_START+2 && uint32_t(victim->GetCurrentMotion())==RaceData::NAME_SLAP_HURT_START+1,"MAKELONG slap roles reversed");
|
||||
actors.Update(actor->GetMotionDuration()+0.01f);
|
||||
// Clock rollover and coincident positions must remain finite.
|
||||
actor->SetPosition(0,0,0);victim->SetPosition(0,0,0);motionClock=0xffffff00;
|
||||
net.ServerCommand("french_kiss 10 20");motionClock+=499;actors.Update(0);require(actors.IsEmotionProcessing(),"rollover deadline early");
|
||||
++motionClock;actors.Update(0);require(!actors.IsEmotionProcessing() && std::isfinite(actor->GetX()) && std::isfinite(actor->GetZ()),"coincident pair/rollover invalid");
|
||||
actors.Update(actor->GetMotionDuration()+0.01f);motionClock=3000;
|
||||
net.ServerCommand("kiss 10 20");actors.RemoveActor(20);
|
||||
require(!actors.IsEmotionProcessing() && !actor->IsEmotionMovementLocked(),"deleted target left input locked");
|
||||
require(!actors.BeginDualEmotion(10,10,RaceData::NAME_KISS_START,RaceData::NAME_KISS_START),"self pair accepted");
|
||||
SNetworkActorData third=main;third.m_dwVID=30;third.m_dwRace=2;
|
||||
actors.AppendActor(third);auto thirdActor=actors.GetActorInstance(30);
|
||||
require(thirdActor->SetModel(model.string()),"main target model");thirdActor->SetPosition(500,0,0);
|
||||
net.SetMainActorVID(30);motionClock=3500;
|
||||
require(actors.BeginDualEmotion(10,30,RaceData::NAME_KISS_START,RaceData::NAME_KISS_START) && actors.IsEmotionProcessing(),"target main not locked");
|
||||
actors.RemoveActor(10);
|
||||
require(!actors.IsEmotionProcessing() && !thirdActor->IsEmotionMovementLocked(),"source removal left main target locked");
|
||||
actors.SetTimeSourceForTest(nullptr);
|
||||
// AVA2 GetRandomMotionKey: cumulative BYTE percentages, never normalized.
|
||||
auto* variants=RaceManager::Instance().CreateRace(779);variants->RegisterMotionMode(1);
|
||||
std::array<float,3> durations{};
|
||||
for(int index=0;index<3;++index) {
|
||||
auto parsed=gr2::File::load_path(variantAnimations[index].string(),nullptr);
|
||||
require(parsed && !parsed->file_info().animations.empty(),"original variant GR2");durations[index]=parsed->file_info().animations[0].duration;
|
||||
const auto path=root/("variant"+std::to_string(index)+".msa");
|
||||
std::ofstream(path)<<"ScriptType MotionData\nMotionFileName \""<<variantAnimations[index].string()<<"\"\nMotionDuration "<<index+1<<"\n";
|
||||
require(variants->RegisterMotion(1,RaceData::NAME_WAIT,path.string(),index==0?15:index==1?25:60),"variant registration");
|
||||
}
|
||||
require(variants->RegisterMotion(1,RaceData::NAME_DAMAGE,(root/"1.msa").string(),100),"speed motion registration");
|
||||
ActorInstance weighted;require(weighted.SetRace(779) && weighted.SetModel(model.string()),"weighted motion model");
|
||||
weighted.SetMotionRandomSourceForTest(RandomMotion);
|
||||
auto checkVariant=[&](unsigned expected) {
|
||||
require(weighted.SetLoopMotionIndex(RaceData::NAME_WAIT),"weighted loop");
|
||||
require(weighted.GetCurrentRaceMotionData() && weighted.GetCurrentRaceMotionData()->motionDuration==float(expected+1),"events bound to wrong variant");
|
||||
require(weighted.GetCurrentRaceMotionData()->motionFileName==variantAnimations[expected].string(),"variant metadata path");
|
||||
require(std::abs(weighted.GetMotionDuration()-std::max(0.1f,durations[expected]))<0.0001f,"GR2 differs from bound event variant");
|
||||
};
|
||||
for(motionRandom=0;motionRandom<100;++motionRandom)checkVariant(motionRandom<15?0:motionRandom<40?1:2);
|
||||
variants->SetMotionRandomWeight(1,RaceData::NAME_WAIT,0,0);variants->SetMotionRandomWeight(1,RaceData::NAME_WAIT,1,20);variants->SetMotionRandomWeight(1,RaceData::NAME_WAIT,2,0);
|
||||
motionRandom=19;checkVariant(1);motionRandom=20;checkVariant(0);motionRandom=99;checkVariant(0); // Uncovered probability falls back to sub-index 0.
|
||||
variants->SetMotionRandomWeight(1,RaceData::NAME_WAIT,0,80);variants->SetMotionRandomWeight(1,RaceData::NAME_WAIT,1,80);
|
||||
motionRandom=79;checkVariant(0);motionRandom=80;checkVariant(1);motionRandom=99;checkVariant(1);
|
||||
// Mode resolution and variant selection happen once when a queued motion binds.
|
||||
weighted.SetLoopMotionIndex(RaceData::NAME_WAIT,2);weighted.Update(0.01f);require(std::abs(weighted.GetAnimTime()-0.02f)<0.0001f,"explicit loop speed ignored");
|
||||
auto calls=motionRandomCalls;require(weighted.PushMotionIndex(RaceData::NAME_DAMAGE,false,0.5f),"queued speed motion");
|
||||
require(motionRandomCalls==calls,"queued motion sampled before activation");
|
||||
weighted.Update(weighted.GetMotionDuration()/2+0.01f);require(weighted.GetCurrentMotion()==MotionType::Damage,"queued motion not activated");
|
||||
weighted.Update(0.1f);require(std::abs(weighted.GetAnimTime()-0.05f)<0.0001f,"queued speed lost");
|
||||
require(weighted.PushMotionIndex(RaceData::NAME_WAIT,true,2),"queued loop speed");
|
||||
weighted.Update(weighted.GetMotionDuration()/0.5f+0.01f);require(motionRandomCalls==calls+1,"queued loop did not sample exactly once");
|
||||
weighted.Update(0.01f);require(std::abs(weighted.GetAnimTime()-0.02f)<0.0001f,"queued loop speed lost");
|
||||
const auto before=weighted.GetAnimTime();require(!weighted.InterceptMotionIndex(RaceData::NAME_DAMAGE,false,0) && weighted.GetAnimTime()==before,"invalid speed changed state");
|
||||
require(weighted.InterceptMotionIndex(RaceData::NAME_DAMAGE,false,2),"explicit intercept speed");weighted.Update(0.01f);
|
||||
require(std::abs(weighted.GetAnimTime()-0.02f)<0.0001f,"intercept speed ignored");
|
||||
for(int cancel=0;cancel<2;++cancel) {
|
||||
const auto path=root/("skillcancel"+std::to_string(cancel)+".msa");
|
||||
std::ofstream(path)<<"MotionFileName \""<<animation.string()<<"\"\nMotionDuration 1\nGroup LoopData\n{\nMotionLoopCount -1\nLoopCancelEnable "<<cancel<<"\nLoopStartTime 0\nLoopEndTime 0.3\n}\n";
|
||||
require(variants->RegisterMotion(1,RaceData::NAME_SKILL+cancel,path.string(),100),"cancel skill motion registration");
|
||||
require(weighted.InterceptMotionIndex(RaceData::NAME_SKILL+cancel,false),"cancel skill motion bind");
|
||||
require(weighted.CanUseSkill()==bool(cancel),"LoopCancelEnable not used for skill permission");
|
||||
}
|
||||
weighted.Stun();require(!weighted.CanUseSkill(),"stunned cancellable skill accepted");weighted.Revive();
|
||||
require(weighted.CanUseSkill(),"revived cancellable skill locked");
|
||||
// Real GR2 loop playback consumes queued actor/position flight targets,
|
||||
// then restores the original primary; no inspection-only queue assertion.
|
||||
const auto flightLoop=root/"flightloop.msa";
|
||||
std::ofstream(flightLoop)<<"MotionFileName \""<<animation.string()<<"\"\nMotionDuration 1\nGroup LoopData\n{\nMotionLoopCount 1\nLoopStartTime 0\nLoopEndTime 0.1\n}\n";
|
||||
require(variants->RegisterMotion(1,RaceData::NAME_SKILL+5,flightLoop.string(),100),"flight loop motion registration");
|
||||
SNetworkActorData flightVictim=third;flightVictim.m_dwVID=31;actors.AppendActor(flightVictim);
|
||||
weighted.ClearFlyTarget();weighted.SetFlyTarget(30);weighted.AddFlyTarget(31);weighted.AddFlyTarget(123,45,678);
|
||||
require(weighted.InterceptMotionIndex(RaceData::NAME_SKILL+5,false,uint32_t(270),1),"flight loop bind");
|
||||
weighted.Update(0.11f);require(weighted.GetFlyTargetVID()==31,"first queued flight not consumed");
|
||||
weighted.Update(0.11f);float flightPosition[3];
|
||||
require(weighted.GetFlyTargetVID()==0 && weighted.GetFlyTargetPosition(flightPosition)
|
||||
&& flightPosition[0]==123 && flightPosition[1]==45 && flightPosition[2]==678,"position flight queue/order");
|
||||
weighted.Update(weighted.GetMotionDuration()+0.01f);require(weighted.GetFlyTargetVID()==30,"flight primary not restored");
|
||||
weighted.ClearFlyTarget();require(!weighted.HasFlyTarget(),"flight clear retained backup");actors.RemoveActor(31);
|
||||
require(weighted.SetLoopMotionIndex(RaceData::NAME_WAIT),"shoot damage wait fixture");
|
||||
const int hpBeforeShoot=weighted.GetHP();weighted.OnShootDamage();
|
||||
require(weighted.GetCurrentMotion()==MotionType::Damage && weighted.GetHP()==hpBeforeShoot,"shoot damage motion/HP mismatch");
|
||||
weighted.Update(weighted.GetMotionDuration()+0.01f);require(weighted.GetCurrentMotion()==MotionType::Wait,"shoot damage did not queue wait");
|
||||
require(weighted.InterceptMotionIndex(RaceData::NAME_SKILL+5,false),"shoot locked skill fixture");
|
||||
weighted.OnShootDamage();require(uint32_t(weighted.GetCurrentMotion())==RaceData::NAME_SKILL+5,"shoot damage interrupted locked skill");
|
||||
require(weighted.InterceptMotionIndex(RaceData::NAME_SKILL+1,false),"shoot cancellable skill fixture");
|
||||
weighted.OnShootDamage();require(weighted.GetCurrentMotion()==MotionType::Damage,"shoot reaction ignored cancel-enabled skill");
|
||||
weighted.Stun();weighted.OnShootDamage();require(weighted.IsDead(),"shoot damage on stunned actor did not die");weighted.Revive();
|
||||
// MSA FLY event -> live object tracking -> actor damage reaction and skill callback.
|
||||
const auto flightScript=root/"tracking.msf",flightMotion=root/"tracking.msa";
|
||||
std::ofstream(flightScript)<<"InitialVelocity 1000\nRange 10000\nBombRange 5\nHomingFlag 1\nHomingMaxAngle 181\n";
|
||||
std::ofstream(flightMotion)<<"MotionFileName \""<<animation.string()<<"\"\nMotionDuration 1\nGroup MotionEventData\n{\nMotionEventDataCount 1\nGroup Event00\n{\nMotionEventType 6\nStartingTime 0.02\nAttachingEnable 0\nAttachingBoneName \"\"\nFlyFileName \""<<flightScript.string()<<"\"\nFlyPosition 0 0 0\n}\n}\n";
|
||||
require(variants->RegisterMotion(1,RaceData::NAME_SKILL+6,flightMotion.string(),100),"tracking motion registration");
|
||||
SNetworkActorData liveFlightTarget=main;liveFlightTarget.m_dwVID=31;actors.AppendActor(liveFlightTarget);
|
||||
auto liveTarget=actors.GetActorInstance(31);require(liveTarget->SetModel(model.string()) && liveTarget->SetLoopMotionIndex(RaceData::NAME_WAIT),"tracking target model");
|
||||
liveTarget->SetPosition(100,0,0);weighted.SetPosition(0,0,0);weighted.SetFlyTarget(31);
|
||||
unsigned shots=0,explosions=0;weighted.SetFlyEventHandler({{},[&](uint32_t skill){require(skill==270,"shoot skill identity");++shots;},[&](uint32_t skill){require(skill==270,"hit skill identity");++explosions;}});
|
||||
auto& flying=FlyingManager::Instance();flying.DeleteAllInstances();
|
||||
require(weighted.InterceptMotionIndex(RaceData::NAME_SKILL+6,false,uint32_t(270),1),"tracking FLY bind");
|
||||
weighted.Update(0.04f);require(shots==1 && flying.GetActiveInstanceCount()==1,"MSA FLY did not spawn");
|
||||
liveTarget->SetPosition(200,0,0);flying.Update(0.3f,0.3f);
|
||||
require(explosions==1 && flying.GetActiveInstanceCount()==0 && liveTarget->GetCurrentMotion()==MotionType::Damage,"FLY live target/reaction/callback chain");
|
||||
flying.Update(0.3f,0.6f);require(explosions==1,"FLY hit callback repeated");
|
||||
// Source primary CG51, like extra CG53, carries graphic Y (negative game Y).
|
||||
auto* primaryRace=RaceManager::Instance().GetRaceDataPointer(1);
|
||||
require(primaryRace->RegisterMotion(1,RaceData::NAME_SKILL+10,flightMotion.string(),100)
|
||||
&& primaryRace->SetMotionRandomWeight(1,RaceData::NAME_SKILL+10,0,0),"primary packet FLY fixture");
|
||||
auto sender=actors.GetActorInstance(30);require(sender->SetRace(1) && sender->SetModel(model.string()) && sender->SetLoopMotionIndex(RaceData::NAME_WAIT),"primary packet actor fixture");
|
||||
liveTarget->SetPosition(200,0,50);ProcessPlayerAttack(0,0,false);sender->SetFlyTarget(31);net.ClearSendQueue();
|
||||
require(sender->InterceptMotionIndex(RaceData::NAME_SKILL+10,false),"primary packet FLY bind");
|
||||
require(net.GetSendQueue()==std::vector<uint8_t>({51,31,0,0,0,200,0,0,0,206,255,255,255}),"primary fly target graphic Y wire sign");
|
||||
weighted.ClearFlyEventHandler();weighted.ClearFlyTarget();actors.RemoveActor(31);
|
||||
// Real model OBB proxy: endpoint hits, altitude, yaw and manager background callback.
|
||||
fs::copy_file(model,root/"obstacle.gr2");
|
||||
MapObjectManager obstacles;require(obstacles.AddObject("obstacle.gr2",500,50,0,30),"flight obstacle model");
|
||||
const auto& obstacle=obstacles.GetObjects().front();require(obstacle.has_collision,"model collision proxy absent");
|
||||
const auto& box=obstacle.obb;
|
||||
const float center[3]={box.centerX,box.centerY,box.centerZ};
|
||||
const float obstacleStart[3]={center[0]-5000,center[1],center[2]},after[3]={center[0]+5000,center[1],center[2]};
|
||||
const float aboveBox[3]={center[0],center[1]+box.halfExtents[1]+10,center[2]};
|
||||
require(obstacles.CheckFlyingCollision(obstacleStart,center) && !obstacles.CheckFlyingCollision(aboveBox,aboveBox),"real OBB endpoint/height check");
|
||||
require(!obstacles.CheckFlyingCollision(obstacleStart,after),"OBB changed to continuous sweep instead of source endpoints");
|
||||
auto collisionData=std::make_shared<FlyingData>();collisionData->initial_velocity=100;collisionData->range=10000;collisionData->hit_on_background=true;
|
||||
FlyingInstance obstacleFlight(collisionData,center,after);unsigned obstacleHits=0;FlyCollisionCallbacks collisionCallbacks;
|
||||
collisionCallbacks.onBackground=[&]{++obstacleHits;};obstacleFlight.SetCollisionCallbacks(collisionCallbacks);
|
||||
require(!obstacleFlight.Update(0,0,nullptr,&obstacles) && obstacleHits==1,"real model background dispatch");
|
||||
// Source shake changes the graphic matrix only; sample once per Actor.Update.
|
||||
weighted.SetPosition(0,0,0);weighted.SetShakeSourcesForTest(Clock,ShakeRandom);motionClock=1000;shakeRandomCalls=0;
|
||||
require(weighted.SetLoopMotionIndex(RaceData::NAME_WAIT),"shake wait fixture");weighted.OnShootDamage();
|
||||
motionClock=1100;weighted.Update(0.01f);auto shaken=weighted.BuildDrawCommands();
|
||||
require(!shaken.empty() && std::abs(shaken.front().world[12]-3)<0.001f && std::abs(shaken.front().world[13]-5)<0.001f
|
||||
&& std::abs(shaken.front().world[14]-4)<0.001f,"source shake axes/amplitude/inclusive deadline");
|
||||
require(weighted.GetX()==0 && weighted.GetY()==0 && weighted.GetZ()==0 && shakeRandomCalls==6,"shake moved logical position/wrong RNG count");
|
||||
weighted.BuildDrawCommands();require(shakeRandomCalls==6,"draw sampled shake a second time");
|
||||
motionClock=1101;weighted.Update(0.01f);auto unshaken=weighted.BuildDrawCommands();
|
||||
require(!unshaken.empty() && unshaken.front().world[12]==0 && unshaken.front().world[13]==0 && unshaken.front().world[14]==0
|
||||
&& shakeRandomCalls==6,"expired shake not cleared");
|
||||
motionClock=1200;require(weighted.InterceptMotionIndex(RaceData::NAME_SKILL+5,false),"shake locked skill fixture");weighted.OnShootDamage();weighted.Update(0.01f);
|
||||
require(uint32_t(weighted.GetCurrentMotion())==RaceData::NAME_SKILL+5 && shakeRandomCalls==12,"locked skill did not shake");
|
||||
motionClock=1301;weighted.Update(0.01f);weighted.Stun();weighted.OnShootDamage();weighted.Update(0.01f);
|
||||
require(weighted.IsDead() && shakeRandomCalls==12,"stunned death started shake");weighted.Revive();weighted.SetShakeSourcesForTest(nullptr,nullptr);
|
||||
// AVA2 IsPoly includes TYPE_PC with a non-player race, as well as TYPE_POLY.
|
||||
weighted.SetActorType(6);require(weighted.IsPolymorph(),"PC monster race not polymorph");
|
||||
weighted.SetMotionMode(2);require(weighted.GetMotionMode()==1,"polymorph mode not GENERAL");
|
||||
const auto beforePolyCalls=motionRandomCalls;
|
||||
require(weighted.InterceptMotionIndex(RaceData::NAME_WAIT,false,2),"poly intercept");
|
||||
require(motionRandomCalls==beforePolyCalls && weighted.GetCurrentRaceMotionData()->motionDuration==1,"poly intercept randomized instead of base key");
|
||||
weighted.Update(0.1f);
|
||||
require(std::abs(weighted.GetAnimTime()-weighted.GetMotionDuration()*0.2f/1.1f)<0.0001f,"poly 1.1-second scaling missing");
|
||||
require(weighted.InterceptMotionIndex(RaceData::NAME_WAIT,true),"poly loop intercept");
|
||||
weighted.Update(0.1f);
|
||||
require(std::abs(weighted.GetAnimTime()-weighted.GetMotionDuration()*0.1f/1.1f)<0.0001f,"poly loop intercept normalization missing");
|
||||
require(weighted.SetLoopMotionIndex(RaceData::NAME_WAIT,2),"poly ordinary loop");
|
||||
require(motionRandomCalls==beforePolyCalls+1,"ordinary poly loop incorrectly bypassed random selection");
|
||||
weighted.Update(0.01f);require(std::abs(weighted.GetAnimTime()-0.02f)<0.0001f,"ordinary poly loop incorrectly normalized");
|
||||
weighted.SetActorType(0);require(!weighted.IsPolymorph(),"ordinary monster classified as poly");
|
||||
weighted.SetActorType(7);require(weighted.IsPolymorph(),"TYPE_POLY missing");
|
||||
require(weighted.SetRace(1),"normal PC classification fixture");
|
||||
weighted.SetActorType(6);require(!weighted.IsPolymorph(),"normal PC classified as poly");
|
||||
weighted.SetActorType(7);require(weighted.IsPolymorph(),"explicit poly depends on race");
|
||||
auto* walkRace=RaceManager::Instance().CreateRace(780);walkRace->RegisterMotionMode(1);
|
||||
require(walkRace->RegisterMotion(1,RaceData::NAME_WAIT,(root/"1.msa").string(),100)
|
||||
&& walkRace->RegisterMotion(1,RaceData::NAME_RUN,(root/"1.msa").string(),100),"walking speed race");
|
||||
SNetworkActorData walker{};walker.m_dwVID=40;walker.m_dwRace=780;walker.m_bType=6;walker.m_dwMovSpd=150;walker.m_dwAtkSpd=175;
|
||||
actors.AppendActor(walker);auto walking=actors.GetActorInstance(40);
|
||||
require(walking->IsPolymorph(),"network PC monster type not propagated");
|
||||
actors.SetSash(40,123);
|
||||
require(actors.GetActorData(40)->m_dwSash==0,"polymorph PC accepted sash");
|
||||
require(walking->GetAttackSpeed()==1.75f,"creation attack speed not normalized");
|
||||
require(walking->SetModel(model.string()) && walking->PlayMotion(MotionType::Run,true),"walking model");
|
||||
walking->Update(0.1f);require(std::abs(walking->GetAnimTime()-0.15f)<0.0001f,"packet move speed not applied to animation");
|
||||
SNetworkUpdateActorData speedUpdate{};speedUpdate.m_dwVID=40;speedUpdate.m_dwMovSpd=200;
|
||||
actors.UpdateActor(speedUpdate);require(walking->GetAnimTime()==0,"speed change did not restart move loop");
|
||||
walking->Update(0.1f);require(std::abs(walking->GetAnimTime()-0.2f)<0.0001f,"live walking speed update ignored");
|
||||
speedUpdate.m_dwMovSpd=0;actors.UpdateActor(speedUpdate);walking->Update(0.1f);
|
||||
require(walking->GetMoveAnimationSpeed()==0 && walking->GetAnimTime()==0,"zero packet speed not frozen");
|
||||
SNetworkMoveActorData stoppedMove{};stoppedMove.m_dwVID=40;stoppedMove.m_dwFunc=1;stoppedMove.m_lPosX=500;
|
||||
actors.MoveActor(stoppedMove);actors.Update(0.1f);require(walking->GetX()==0,"zero speed fell back to invented movement");
|
||||
speedUpdate.m_dwMovSpd=1101;actors.UpdateActor(speedUpdate);require(walking->GetMoveAnimationSpeed()==0,"original overflow-to-zero rule lost");
|
||||
for(uint32_t speed : {0u,1u,100u,175u,1100u,1101u,0xffffffffu}) {
|
||||
speedUpdate.m_dwAtkSpd=speed;actors.UpdateActor(speedUpdate);
|
||||
require(walking->GetAttackSpeed()==(speed<=1100?float(speed)/100:0),"updated attack speed boundary");
|
||||
walker.m_dwVID=41;walker.m_dwAtkSpd=speed;walker.m_dwMountVnum=780;actors.AppendActor(walker);
|
||||
require(actors.GetActorInstance(41)->GetAttackSpeed()==walking->GetAttackSpeed(),"creation/update attack speed disagree");
|
||||
auto* mounted=actors.GetActorData(41);
|
||||
require(mounted && mounted->m_pMountInstance && mounted->m_pMountInstance->GetAttackSpeed()==walking->GetAttackSpeed(),"mount creation attack speed disagree");
|
||||
auto mountUpdate=speedUpdate;mountUpdate.m_dwVID=41;mountUpdate.m_dwMountVnum=780;mountUpdate.m_dwAtkSpd=200;
|
||||
actors.UpdateActor(mountUpdate);
|
||||
require(mounted->m_pMountInstance && mounted->m_pMountInstance->GetAttackSpeed()==2,"mount update attack speed ignored");
|
||||
actors.RemoveActor(41);
|
||||
}
|
||||
python.execute("player.SetGameWindow(0)\nnet.ClearPhaseWindow(net.PHASE_WINDOW_GAME,w)\n");
|
||||
actors.Clear();net.ResetConnection();
|
||||
}
|
||||
require(preview.expired(),"preview singleton retained runtime-owned resources after shutdown");
|
||||
require(CRenderTargetManager::Instance().GetFreeIndex(12345,12345)==12345,"preview index not released on shutdown");
|
||||
fs::current_path(previous);fs::remove_all(root);
|
||||
std::cout<<"AVA2 emotion queries, fishing transitions and digging queues passed\n";return 0;
|
||||
} catch(const std::exception& error) {
|
||||
fs::current_path(previous);fs::remove_all(root);std::cerr<<error.what()<<'\n';return 1;
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <vector>
|
||||
#include <bit>
|
||||
#include <chrono>
|
||||
#include <limits>
|
||||
#include <filesystem>
|
||||
|
||||
using namespace ava2;
|
||||
@@ -102,6 +103,7 @@ void TestSpeedTreeModelGeneration() {
|
||||
assert(!canopy.positions.empty() && !canopy.indices.empty() && "Canopy must have geometry");
|
||||
assert(canopy.alpha_test && canopy.alpha_ref == 84 && "Canopy must have alpha test 84");
|
||||
assert(canopy.cull_mode == 1 && "Canopy must be double sided");
|
||||
assert(!trunk.lighting && !canopy.lighting && "Original static tree colors must not receive dynamic lighting twice");
|
||||
|
||||
std::cout << " -> Oak Tree generated: Trunk verts=" << trunk.positions.size() / 3
|
||||
<< ", tris=" << trunk.indices.size() / 3
|
||||
@@ -121,8 +123,8 @@ void TestSpeedTreeModelGeneration() {
|
||||
void TestWindMotionSimulation() {
|
||||
std::cout << "[Test] Wind Motion Simulation & Anchoring..." << std::endl;
|
||||
auto tree = SpeedTreeModel::CreateProcedural("BlowingPine", 1000.0f, "bark.dds", "leaves.dds");
|
||||
auto draws_t0 = tree->BuildDrawCommands(0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 25.0f);
|
||||
auto draws_t1 = tree->BuildDrawCommands(0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.57f, 25.0f);
|
||||
auto draws_t0 = tree->BuildDrawCommands(0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 25.0f, nullptr, nullptr, true);
|
||||
auto draws_t1 = tree->BuildDrawCommands(0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.57f, 25.0f, nullptr, nullptr, true);
|
||||
|
||||
// Check base vertex (y ~ 0) stays anchored
|
||||
float base_x0 = draws_t0[0].positions[0];
|
||||
@@ -157,8 +159,10 @@ void TestSpeedTreeForestSystem() {
|
||||
// Place trees in front of camera
|
||||
forest.CreateInstance(0.0f, 0.0f, 300.0f, 1001, 0.0f, 1.0f);
|
||||
forest.CreateInstance(50.0f, 0.0f, 350.0f, 1002, 30.0f, 1.0f);
|
||||
// Place one tree behind camera (Z = -500)
|
||||
forest.CreateInstance(0.0f, 0.0f, -500.0f, 1001, 0.0f, 1.0f);
|
||||
// Place its entire bounding sphere behind the camera. An origin behind
|
||||
// the camera is insufficient when the generated canopy crosses the plane.
|
||||
const float behind=-(forest.GetMainTree(1001)->GetRadius()*2+100);
|
||||
forest.CreateInstance(0.0f, 0.0f, behind, 1001, 0.0f, 1.0f);
|
||||
|
||||
assert(forest.GetInstanceCount() == 3 && "Instance count mismatch");
|
||||
forest.UpdateSystem(0.033f);
|
||||
@@ -177,7 +181,7 @@ void TestSpeedTreeForestSystem() {
|
||||
0.0f, 0.0f, -1.0f, 0.0f
|
||||
};
|
||||
|
||||
auto culled_draws = forest.BuildDrawCommands(view, proj, 0.0f, 50.0f, 0.0f, 2000.0f);
|
||||
auto culled_draws = forest.BuildDrawCommands(view, proj, 0.0f, 50.0f, 0.0f, std::abs(behind)+2000.0f);
|
||||
assert(!culled_draws.empty() && "Visible trees must produce draw commands");
|
||||
// Front trees (1 tree = 2 draws, 1 grass = 1 draw -> 3 draws total)
|
||||
assert(culled_draws.size() == 3 && "Behind-camera tree must be culled (3 draws expected)");
|
||||
@@ -206,27 +210,23 @@ void TestBillboardRendering() {
|
||||
assert(nearDraws.size()==2 && nearDraws[0].positions.size()>12);
|
||||
camera={0,0,2000};
|
||||
auto transition=model.BuildDrawCommands(0,0,0,0,1,0,15,nullptr,&camera);
|
||||
assert(transition.size()==4 && transition[2].positions.size()==12);
|
||||
camera={0,0,4000};
|
||||
auto farDraws=model.BuildDrawCommands(0,0,0,0,1,0,15,nullptr,&camera);
|
||||
assert(farDraws.size()==2 && farDraws[0].positions.size()==12 && farDraws[1].positions.size()==12);
|
||||
assert(farDraws[0].alpha_test && farDraws[0].alpha_ref==84);
|
||||
// Windows CSpeedTreeWrapper::Advance forces SetLodLevel(1): near, overlap
|
||||
// and far cameras all draw full geometry, not atlas billboard substitutes.
|
||||
assert(transition.size()==nearDraws.size() && farDraws.size()==nearDraws.size());
|
||||
for(size_t i=0;i<nearDraws.size();++i) {
|
||||
assert(transition[i].indices==nearDraws[i].indices && farDraws[i].indices==nearDraws[i].indices);
|
||||
assert(farDraws[i].positions.size()==nearDraws[i].positions.size());
|
||||
assert(farDraws[i].uv0==nearDraws[i].uv0);
|
||||
}
|
||||
assert(farDraws[1].alpha_test && farDraws[1].alpha_ref==84);
|
||||
auto windy=model.BuildDrawCommands(0,0,0,0,1,10,30,nullptr,&camera);
|
||||
assert(farDraws[0].positions==windy[0].positions && farDraws[1].positions==windy[1].positions);
|
||||
assert(model.BuildDrawCommands(0,0,0,0,1,0).size()==2);
|
||||
// A different camera heading, tree yaw and scale must still face the camera.
|
||||
camera={4000,0,0};
|
||||
auto rotated=model.BuildDrawCommands(0,0,0,90,2,0,15,nullptr,&camera);
|
||||
float centerX=0,centerZ=0;
|
||||
for(size_t i=0;i<4;++i) {
|
||||
centerX+=rotated[0].positions[i*3]*0.25f;
|
||||
centerZ+=rotated[0].positions[i*3+2]*0.25f;
|
||||
}
|
||||
float dx=camera[0]-centerX,dz=camera[2]-centerZ,length=std::hypot(dx,dz);
|
||||
for(size_t i=0;i<4;++i) {
|
||||
assert(std::abs(rotated[0].normals[i*3]-dx/length)<0.001f);
|
||||
assert(std::abs(rotated[0].normals[i*3+2]-dz/length)<0.001f);
|
||||
}
|
||||
assert(farDraws[1].positions!=windy[1].positions); // Full foliage still receives wind at distance.
|
||||
// The SDK's independent billboard builder remains available to other consumers.
|
||||
auto billboards=impl->BuildBillboardMeshes(camera);
|
||||
assert(billboards.size()==2 && billboards[0].vertices.size()==4 && billboards[1].vertices.size()==4);
|
||||
|
||||
}
|
||||
|
||||
void TestFrondRendering() {
|
||||
@@ -242,8 +242,11 @@ void TestFrondRendering() {
|
||||
SpeedTreeModel model(impl);
|
||||
auto draws=model.BuildDrawCommands(0,0,0,0,1,0);
|
||||
assert(draws.size()==2 && impl->GetLeafMesh().vertices.empty());
|
||||
assert(draws[1].alpha_test && draws[1].alpha_ref==84 && draws[1].cull_mode==1);
|
||||
auto windy=model.BuildDrawCommands(0,0,0,0,1,2);
|
||||
assert(draws[1].alpha_test && draws[1].alpha_ref==84 && draws[1].cull_mode==1 && !draws[1].lighting);
|
||||
auto later=model.BuildDrawCommands(0,0,0,0,1,2);
|
||||
assert(later[0].positions==draws[0].positions && later[1].positions==draws[1].positions);
|
||||
assert(later[0].normals==draws[0].normals && later[1].normals==draws[1].normals);
|
||||
auto windy=model.BuildDrawCommands(0,0,0,0,1,2,15,nullptr,nullptr,true);
|
||||
bool moved=false;
|
||||
for(size_t i=0;i<draws[1].positions.size();++i) {
|
||||
assert(std::isfinite(windy[1].positions[i]));
|
||||
@@ -275,6 +278,32 @@ void TestAuthoredLeafRendering() {
|
||||
auto changed=model.BuildDrawCommands(0,0,0,90,2,0,0,nullptr,&camera);
|
||||
assert(changed[1].positions!=draws[1].positions);
|
||||
assert(changed[1].uv0==draws[1].uv0 && changed[1].indices==draws[1].indices);
|
||||
speedtree::WindParameters frame;frame.strength=0.75f;frame.legacy_leaf_rocking=true;frame.legacy_leaf_phase=1;
|
||||
frame.matrices={std::array<float,16>{1,0,0,0,0,1,0,0,0,0,1,0,10000,20000,30000,1}};
|
||||
auto first=model.BuildDrawCommands(30,40,50,90,2,0,15,&frame,&camera);
|
||||
frame.legacy_leaf_phase=3;
|
||||
auto rocking=model.BuildDrawCommands(30,40,50,90,2,0,15,&frame,&camera);
|
||||
assert(rocking[0].positions==first[0].positions && rocking[0].normals==first[0].normals);
|
||||
assert(rocking[1].positions!=first[1].positions);
|
||||
// Rotation is around the authored pivot, without translating it using wind matrices.
|
||||
const auto& vertices=impl->GetLeafMesh().vertices;
|
||||
for(size_t i=0;i<vertices.size();++i) {
|
||||
const auto& v=vertices[i];
|
||||
float localPivot[3]={v.position[0]-v.leaf_pivot_offset[0],v.position[1]-v.leaf_pivot_offset[1],v.position[2]-v.leaf_pivot_offset[2]};
|
||||
float pivot[3]={30+2*localPivot[2],40+2*localPivot[1],50-2*localPivot[0]};
|
||||
float expected=0,actual=0;
|
||||
for(size_t axis=0;axis<3;++axis) {
|
||||
expected+=4*v.leaf_pivot_offset[axis]*v.leaf_pivot_offset[axis];
|
||||
float d=rocking[1].positions[i*3+axis]-pivot[axis];actual+=d*d;
|
||||
}
|
||||
assert(std::abs(actual-expected)<0.05f);
|
||||
}
|
||||
const auto identity=std::array<float,16>{1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1};
|
||||
auto neutral=frame;neutral.matrices={identity};
|
||||
auto neutralDraws=model.BuildDrawCommands(30,40,50,90,2,0,15,&neutral,&camera);
|
||||
for(size_t i=0;i<rocking.size();++i)assert(rocking[i].positions==neutralDraws[i].positions);
|
||||
auto cpu=model.BuildDrawCommands(30,40,50,90,2,0,15,&frame,&camera,true);
|
||||
assert(cpu[0].positions!=rocking[0].positions && cpu[1].positions!=rocking[1].positions);
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
||||
@@ -6,6 +6,9 @@
|
||||
#endif
|
||||
#include "python_runtime.h"
|
||||
#include "python_gameplay_modules.h"
|
||||
#include "python_touch.h"
|
||||
#include "python_item.h"
|
||||
#include "eter_render/Gr2ModelRenderer.h"
|
||||
#include "app/input/touch_router.h"
|
||||
#include "eter_ui/PythonWindowManager.h"
|
||||
#include "eter_ui/PythonWindow.h"
|
||||
@@ -17,6 +20,7 @@
|
||||
#include <Python.h>
|
||||
#include <SDL3/SDL.h>
|
||||
#include <array>
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
#include <filesystem>
|
||||
@@ -28,7 +32,9 @@ namespace {
|
||||
|
||||
struct GameSink final : ava2::input::TouchSink {
|
||||
UI::CWindowManager* wm = nullptr;
|
||||
int ui_downs = 0, taps = 0;
|
||||
int ui_downs = 0, taps = 0, skill_casts=0, skill_slot=-1;
|
||||
int SkillAt(float x,float y) override {return ava2::TouchSkillAt(*wm,long(x),long(y));}
|
||||
void Skill(int slot,float,float,bool) override {++skill_casts;skill_slot=slot;}
|
||||
bool attack = false;
|
||||
bool IsUiAt(float x, float y) override {
|
||||
auto* win = wm->PickWindow(long(x), long(y));
|
||||
@@ -126,6 +132,31 @@ int main(int argc, char** argv) {
|
||||
router.FingerUp(1, 160.0f + layout.joy_radius, H - 180.0f, 220);
|
||||
assert(!sink.attack && !ava2::GetPlayerMovementYaw(0.0f, yaw));
|
||||
|
||||
runtime.execute("hud.joystick.OnUpdate()\nassert not hud.joystick.base_bar.IsShow() and not hud.joystick.knob.IsShow()\n");
|
||||
// Skill shortcut resolves the current slot through the real picked Python window, including rim.
|
||||
runtime.execute("player.GetSkillIndex=lambda n: 1\nplayer.GetLocalQuickSlot=lambda n: (player.SLOT_TYPE_SKILL, 17)\n"
|
||||
"shortcut=hud.combat_wheel.slots[0]\nshortcut_xy=shortcut.GetGlobalPosition()\n");
|
||||
auto* xy=PyDict_GetItemString(PyModule_GetDict(main),"shortcut_xy");
|
||||
const float sx=float(PyInt_AsLong(PyTuple_GetItem(xy,0)))+2,sy=float(PyInt_AsLong(PyTuple_GetItem(xy,1)))+2;
|
||||
assert(sink.SkillAt(sx,sy)==17);router.FingerDown(8,sx,sy,230);router.FingerMove(8,sx+60,sy,240);router.Update(241);
|
||||
assert(sink.skill_casts==1 && sink.skill_slot==17);
|
||||
runtime.execute("hud.combat_wheel.OnUpdate()\nassert hud.combat_wheel.aim_marker.IsShow()\n");
|
||||
router.FingerCancel(8,250);runtime.execute("hud.combat_wheel.OnUpdate()\nassert not hud.combat_wheel.aim_marker.IsShow()\n");
|
||||
// Real actor/item tap adapter: approach, completion and stale item generation.
|
||||
auto& manager=ava2::NetworkActorManager::Instance();auto& network=ava2::PythonNetworkStream::Instance();manager.Clear();
|
||||
ava2::SNetworkActorData mainData{};mainData.m_dwVID=100;mainData.m_bType=6;manager.AppendActor(mainData);network.SetMainActorVID(100);
|
||||
auto mainActor=manager.GetActorInstance(100);mainActor->SetPosition(-1000,0,0);
|
||||
ava2::SNetworkActorData npcData{};npcData.m_dwVID=101;npcData.m_bType=1;manager.AppendActor(npcData);auto npc=manager.GetActorInstance(101);npc->SetPosition(0,0,0);npc->SetHP(100);
|
||||
ava2::Gr2SceneRenderer scene(W,H);scene.SetCameraLookAt(0,100,-500,0,0,0,0,1,0);scene.SetPerspective(60,float(W)/H,1,3000);
|
||||
float px,py;assert(scene.ProjectToScreen(0,0,0,px,py));network.ClearSendQueue();
|
||||
assert(ava2::HandlePlayerTouchWorldTap(scene,px+20,py));assert(mainActor->HasMoveTarget());
|
||||
mainActor->SetPosition(-400,0,0);ava2::ProcessPlayerTouchInteraction();assert(!mainActor->HasMoveTarget());
|
||||
const auto click=network.GetSendQueue();assert(click==std::vector<uint8_t>({61,101,0,0,0,26,101,0,0,0}));
|
||||
auto& ground=ava2::CPythonItem::Instance();ground.CreateItem(102,27001,0,0,0,false);mainActor->SetPosition(-1000,0,0);network.ClearSendQueue();
|
||||
assert(ava2::HandlePlayerTouchWorldTap(scene,px,py) && mainActor->HasMoveTarget());
|
||||
ground.DeleteItem(102);ground.CreateItem(102,27001,0,0,0,false);mainActor->SetPosition(0,0,0);ava2::ProcessPlayerTouchInteraction();
|
||||
assert(network.GetSendQueue().empty() && !mainActor->HasMoveTarget());
|
||||
assert(ava2::HandlePlayerTouchWorldTap(scene,px,py));assert(!network.GetSendQueue().empty());ground.DeleteAllItems();manager.Clear();
|
||||
// HUD button taps go to the window manager, open world taps become world clicks.
|
||||
router.FingerDown(3, tb_x, tb_y, 300);
|
||||
router.FingerUp(3, tb_x, tb_y, 350);
|
||||
|
||||
@@ -15,6 +15,10 @@ namespace {
|
||||
|
||||
struct RecordingSink : TouchSink {
|
||||
// One UI window: a 200x100 box at (500, 50).
|
||||
bool skills=false;
|
||||
struct Cast {int slot;float x,y;bool repeat;};std::vector<Cast> casts;
|
||||
int SkillAt(float x,float y) override {return skills && x>=500 && x<700 && y>=50 && y<150?7:-1;}
|
||||
void Skill(int slot,float x,float y,bool repeat) override {casts.push_back({slot,x,y,repeat});}
|
||||
bool IsUiAt(float x, float y) override { return x >= 500 && x < 700 && y >= 50 && y < 150; }
|
||||
void UiMouseMove(float x, float y) override { log("move", x, y); }
|
||||
void UiMouseDown(float x, float y) override { log("down", x, y); }
|
||||
@@ -317,6 +321,27 @@ void ui_gestures() {
|
||||
"drag");
|
||||
}
|
||||
|
||||
void floating_edges_and_skills() {
|
||||
RecordingSink sink;TouchRouter r;r.SetSink(&sink);r.SetLayout(layout());r.SetWorldEnabled(true);
|
||||
r.FingerDown(0,1,719,1000);
|
||||
expect(near(sink.joy_x,0) && near(sink.joy_y,0),"edge landing moved before dragging");
|
||||
expect(near(r.GetJoystick().base_x,100) && near(r.GetJoystick().base_y,620),"visual base not clamped");
|
||||
r.FingerMove(0,101,719,1010);expect(near(sink.joy_x,1) && near(sink.joy_y,0),"edge joystick uses visual origin");
|
||||
r.FingerCancel(0,1020);r.FingerDown(1,101,719,1040);
|
||||
expect(near(sink.joy_x,1) && near(sink.joy_y,0),"reacquire lost true touch origin");r.CancelAll();
|
||||
sink.skills=true;r.FingerDown(0,600,100,2000);r.FingerUp(0,600,100,2050);
|
||||
expect(sink.casts.size()==1 && !sink.casts[0].repeat && sink.casts[0].x==0,"skill tap not exactly once");
|
||||
r.FingerDown(0,600,100,3000);r.FingerDown(1,600,100,3001);expect(r.FingerCount()==1,"duplicate skill fingers");
|
||||
r.FingerDown(2,200,500,3002);r.FingerMove(2,300,500,3003);
|
||||
r.FingerDown(3,1180,620,3004);r.FingerDown(4,900,300,3005);r.FingerMove(4,940,300,3006);
|
||||
r.FingerMove(0,740,100,3010);r.Update(3011);
|
||||
expect(sink.casts.size()==2 && near(sink.casts.back().x,140) && sink.attack && near(sink.joy_x,1) && sink.rot_x>0,"skill/attack/joystick/camera ownership");
|
||||
r.Update(3100);expect(sink.casts.size()==2,"repeat ignores cadence");r.Update(3211);
|
||||
expect(sink.casts.size()==3 && sink.casts.back().repeat,"held skill did not repeat");
|
||||
r.FingerUp(0,740,100,3220);r.Update(3500);expect(sink.casts.size()==3,"skill lift recast");r.CancelAll();
|
||||
r.FingerDown(0,600,100,4000);r.FingerCancel(0,4050);r.Update(4500);expect(sink.casts.size()==3,"cancelled pending skill cast");
|
||||
r.FingerDown(0,600,100,5000);r.SetWorldEnabled(false);r.Update(5500);expect(sink.casts.size()==3,"phase change kept skill held");
|
||||
}
|
||||
void default_layout() {
|
||||
const TouchLayout l = TouchLayout::ForScreen(1600, 720);
|
||||
expect(l.joy_x == 0 && l.joy_w > 0 && l.joy_y + l.joy_h <= 720.5f, "default joystick area");
|
||||
@@ -335,6 +360,7 @@ int main() {
|
||||
ui_gestures();
|
||||
system_edges();
|
||||
default_layout();
|
||||
floating_edges_and_skills();
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << "touch_router_test: " << e.what() << '\n';
|
||||
return 1;
|
||||
|
||||
@@ -0,0 +1,530 @@
|
||||
#include "python_runtime.h"
|
||||
#include "python_app.h"
|
||||
#include "python_gameplay_modules.h"
|
||||
#include "python_native_modules.h"
|
||||
#include "python_background.h"
|
||||
#include "protocol.h"
|
||||
#include "eter_net/PythonNetworkStream.h"
|
||||
#include "eter_net/NetworkActorManager.h"
|
||||
#include "eter_net/PythonSafeBox.h"
|
||||
#include "eter_effect/EffectManager.h"
|
||||
#include "eter_render/RaceData.h"
|
||||
#include "eter_ui/PythonWindow.h"
|
||||
#include "shared/common/Singleton.h"
|
||||
#include "mount_rules.h"
|
||||
#include "eter_base/Random.h"
|
||||
#include <bit>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <cmath>
|
||||
#include <chrono>
|
||||
|
||||
using namespace ava2;
|
||||
namespace fs=std::filesystem;
|
||||
static void require(bool ok,const char* message) {if(!ok)throw std::runtime_error(message);}
|
||||
struct SingletonPrefix {virtual ~SingletonPrefix()=default; uint64_t padding=0;};
|
||||
struct OffsetSingleton : SingletonPrefix, CSingleton<OffsetSingleton> {int value=73;};
|
||||
static void write(const fs::path& path,const std::string& text) {
|
||||
fs::create_directories(path.parent_path());std::ofstream(path,std::ios::binary)<<text;
|
||||
}
|
||||
int main(int argc,char** argv) {
|
||||
if(argc!=3) return 2;
|
||||
const auto previous=fs::current_path();
|
||||
const auto root=fs::temp_directory_path()/ ("ava2_windows_behavior_"+std::to_string(std::chrono::steady_clock::now().time_since_epoch().count()));
|
||||
try {
|
||||
require(!OffsetSingleton::InstancePtr(),"singleton initially registered");
|
||||
{
|
||||
OffsetSingleton instance;
|
||||
require(static_cast<void*>(static_cast<CSingleton<OffsetSingleton>*>(&instance))!=static_cast<void*>(&instance),"nonzero singleton base offset fixture");
|
||||
require(OffsetSingleton::InstancePtr()==&instance && OffsetSingleton::Instance().value==73 && &OffsetSingleton::instance()==&instance,"multiple-inheritance singleton adjustment");
|
||||
}
|
||||
require(!OffsetSingleton::InstancePtr(),"singleton retained destroyed instance");
|
||||
auto stdlib=fs::absolute(argv[1]);fs::create_directories(root);fs::current_path(root);
|
||||
write(root/"locale/en/atlasinfo.txt","parity_map 0 0 1 1\ntarget_map 102400 204800 1 1\n");
|
||||
write(root/"map/parity_map/setting.txt","ScriptType MapSetting\nMapSize 1 1\nBasePosition 0 0\n");
|
||||
write(root/"map/parity_map/000000/height.raw",std::string(131*131*2,0));
|
||||
write(root/"map/parity_map/000000/attr.atr",std::string(256*256,char(4)));
|
||||
const std::string texture="TextureSet\nTextureCount 4\nStart Texture004\n\"d:\\ymir work\\terrainmaps\\alternate.dds\"\n2\n3\n0.25\n0.5\n0\n0\n0\nEnd Texture004\n";
|
||||
write(root/"textureset/alternate.txt",texture);
|
||||
write(root/"skill/cooldown.txt","type\tguild\nname\tCooldown\niconfilename\ticon.dds\ncooltimeformula\t20\n");
|
||||
write(root/"map/target_map/setting.txt","ScriptType MapSetting\nMapSize 1 1\nBasePosition 102400 204800\n");
|
||||
std::vector<uint16_t> targetHeights(131*131,200);
|
||||
write(root/"map/target_map/000000/height.raw",std::string(reinterpret_cast<const char*>(targetHeights.data()),targetHeights.size()*2));
|
||||
auto effectFixture=[&](const char* name,const char* texture,int offset) {
|
||||
write(root/(std::string("ymir work/")+name),
|
||||
"Group Particle { List TimeEventPosition { 0 MOVING_TYPE_DIRECT "+std::to_string(offset)+" 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 { "+texture+" } } }");
|
||||
};
|
||||
effectFixture("effect/etc/direction/direction_land.mse","regular.dds",0);
|
||||
effectFixture("effect/direction/direction_land2.mse","shop.dds",0);
|
||||
const char* compassTextures[]={"detected.dds","small.dds","middle.dds","large.dds"};
|
||||
const char* compassFiles[]={"effect/etc/firecracker/find_out.mse","effect/etc/compass/appear_small.mse",
|
||||
"effect/etc/compass/appear_middle.mse","effect/etc/compass/appear_large.mse"};
|
||||
for(int distance=0;distance<4;++distance) effectFixture(compassFiles[distance],compassTextures[distance],100);
|
||||
{
|
||||
PythonRuntime python(stdlib,root);auto& net=PythonNetworkStream::Instance();
|
||||
python.execute("import net, player, app, background, skill\n"
|
||||
"class Window:\n"
|
||||
" def __init__(self): self.calls=[]\n"
|
||||
" def OnSafeBoxError(self): self.calls.append('safe')\n"
|
||||
" def OpenSafeboxWindow(self,size): self.calls.append(('open',size))\n"
|
||||
" def OpenMallWindow(self,size): self.calls.append(('mallopen',size))\n"
|
||||
" def RefreshSafebox(self): self.calls.append('box')\n"
|
||||
" def RefreshMall(self): self.calls.append('mall')\n"
|
||||
" def RefreshSafeboxMoney(self): self.calls.append('money')\n"
|
||||
" def RefreshStamina(self): self.calls.append('stamina')\n"
|
||||
" def RefreshMobile(self): self.calls.append('mobile')\n"
|
||||
" def StartCatchKing(self): self.calls.append('king')\n"
|
||||
" def OnCannotShotError(self,vid,reason): self.calls.append(('shot',vid,reason))\n"
|
||||
" def BINARY_OpenAtlasWindow(self): self.calls.append('atlas')\n"
|
||||
" def BINARY_ServerCommand_Run(self,s): return False\n"
|
||||
" def RunUseSkillEvent(self,slot,time): self.calls.append(('cooldown',slot,time))\n"
|
||||
" def OnCannotUseSkill(self,vid,reason): self.calls.append(('skill',vid,reason))\n"
|
||||
"w=Window()\nnet.SetPhaseWindow(net.PHASE_WINDOW_GAME,w)\nplayer.SetGameWindow(w)\n");
|
||||
net.SetPhase(PHASE_GAME);
|
||||
python.execute("import wndMgr\nfont_handle=wndMgr.RegisterTextLine(w,'UI')\nwndMgr.SetFontColor(font_handle,0.5,1.0,0.25)\n");
|
||||
auto* font=static_cast<UI::CTextLine*>(PyLong_AsVoidPtr(PyDict_GetItemString(PyModule_GetDict(PyImport_AddModule("__main__")),"font_handle")));
|
||||
require(font && font->GetFontColor()==0xff7fff3f,"font components changed valid Win32 truncation");
|
||||
python.execute("wndMgr.SetFontColor(font_handle,-100.0,128.0,float('nan'))\n");
|
||||
require(font->GetFontColor()==0xff00ff00,"invalid font components not bounded");
|
||||
python.execute("wndMgr.SetFontColor(font_handle,0x12345678)\n");
|
||||
require(font->GetFontColor()==0x12345678,"packed font color changed");
|
||||
python.execute("wndMgr.Destroy(font_handle)\n");
|
||||
// Original GC wrong password is a single-byte packet, no inventory refresh.
|
||||
uint8_t wrong=HEADER_GC_SAFEBOX_WRONG_PASSWORD;net.PushRecvData(&wrong,1);net.ProcessRecvData();
|
||||
python.execute("assert w.calls==['safe'],w.calls\nw.calls=[]\n");
|
||||
uint8_t size[]={88,9};net.PushRecvData(size,1);net.ProcessRecvData();
|
||||
python.execute("assert w.calls==[]\n");
|
||||
net.PushRecvData(size+1,1);net.ProcessRecvData();
|
||||
uint8_t mallSize[]={122,18};net.PushRecvData(mallSize,2);net.ProcessRecvData();
|
||||
require(CPythonSafeBox::Instance().GetCurrentSafeBoxSize()==45
|
||||
&& CPythonSafeBox::Instance().GetMallSize()==90,"warehouse rows multiplied as pages");
|
||||
const TItemData* item=nullptr;
|
||||
require(CPythonSafeBox::Instance().GetItemDataPtr(44,&item)
|
||||
&& !CPythonSafeBox::Instance().GetItemDataPtr(45,&item),"warehouse slot boundary");
|
||||
python.execute("assert w.calls==[('open',9),('mallopen',18)],w.calls\nw.calls=[]\n");
|
||||
std::vector<uint8_t> stored(144,0);stored[0]=85;stored[1]=1;stored[4]=42;stored[8]=2;
|
||||
// Literal Win32 offsets: sockets start at odd byte 21, attributes at 53.
|
||||
stored[21]=0x78;stored[22]=0x56;stored[23]=0x34;stored[24]=0x12;
|
||||
stored[53]=7;stored[54]=0xc7;stored[55]=0xcf; // signed -12345
|
||||
std::vector<uint8_t> batch=stored;batch.insert(batch.end(),stored.begin(),stored.end());
|
||||
stored[0]=128;batch.insert(batch.end(),stored.begin(),stored.end());net.PushRecvData(batch);net.ProcessRecvData();
|
||||
require(CPythonSafeBox::Instance().GetItemDataPtr(0,&item) && item->alSockets[0]==0x12345678
|
||||
&& item->aAttr[0].bType==7 && item->aAttr[0].sValue==-12345,"unaligned wire item bytes changed");
|
||||
SetPlayerItemData(1,7,*item);
|
||||
python.execute("assert player.GetItemAttribute(7,0)==(7,-12345)\n");
|
||||
python.execute("assert w.calls==['box','mall'],w.calls\nw.calls=[]\n");
|
||||
uint8_t erase[]={86,0,129,0};net.PushRecvData(erase,4);net.ProcessRecvData();
|
||||
require(CPythonSafeBox::Instance().GetItemDataPtr(0,&item) && item->vnum==0,"warehouse deletion state");
|
||||
uint8_t money[]={84,0x70,0x11,1,0};net.PushRecvData(money,5);net.ProcessRecvData();
|
||||
require(CPythonSafeBox::Instance().GetMoney()==70000,"warehouse money");
|
||||
python.execute("assert w.calls==['box','mall','money'],w.calls\nw.calls=[]\n");
|
||||
auto command=[&](const std::string& text) {
|
||||
std::vector<uint8_t> bytes(10+text.size(),0);bytes[0]=HEADER_GC_CHAT;
|
||||
bytes[1]=uint8_t(bytes.size());bytes[2]=uint8_t(bytes.size()>>8);bytes[3]=CHAT_TYPE_COMMAND;
|
||||
std::copy(text.begin(),text.end(),bytes.begin()+9);net.PushRecvData(bytes);net.ProcessRecvData();
|
||||
};
|
||||
command("StartStaminaConsume 4 100");require(GetPlayerStatusPoint(9)==100,"start stamina status");
|
||||
SetGameFrameDelta(0.125f);python.execute("app.UpdateGame()\nassert player.GetStatus(player.STAMINA)==99\n");
|
||||
python.execute("app.UpdateGame()\nassert player.GetStatus(player.STAMINA)==99\nassert w.calls==['stamina','stamina'],w.calls\n");
|
||||
command("StopStaminaConsume 42");python.execute("app.UpdateGame()\nassert player.GetStatus(player.STAMINA)==42\nassert len(w.calls)==2\n");
|
||||
command("StartStaminaConsume 4");python.execute("app.UpdateGame()\nassert player.GetStatus(player.STAMINA)==42\n");
|
||||
command("sms");command("nosms");python.execute("assert w.calls[-2:]==['mobile','mobile']\nassert player.HasMobilePhoneNumber()==0\n");
|
||||
command("StartStaminaConsume 1 9");ResetPlayerState();UpdatePlayerStamina(1);
|
||||
require(GetPlayerStatusPoint(9)==0,"reset retained stamina consumption");
|
||||
|
||||
net.SetPhase(PHASE_SELECT);net.ClearSendQueue();
|
||||
python.execute("net.SendMobileMessagePacket('Bob','hi')\n");
|
||||
std::vector<uint8_t> expected(31,0);expected[0]=107;expected[1]=31;
|
||||
expected[3]='B';expected[4]='o';expected[5]='b';expected[28]='h';expected[29]='i';
|
||||
require(net.GetSendQueue()==expected && net.GetSendPackets().size()==1,"SMS wire/sequence boundary");
|
||||
auto longName=wire::mobile_message(std::string(40,'N'),"");
|
||||
require(longName.size()==29 && longName[27]==0 && longName[26]=='N',"SMS name termination");
|
||||
require(wire::mobile_message("Bob",std::string(65506,'x')).size()==65535,"SMS WORD boundary");
|
||||
require(wire::mobile_message("Bob",std::string(65507,'x')).empty(),"SMS oversized frame");
|
||||
auto sendCheck=[&](const char* script,const std::vector<uint8_t>& expected) {
|
||||
net.ClearSendQueue();python.execute(script);require(net.GetSendQueue()==expected,"extended feature send differs from Windows");
|
||||
require(expected.empty() || net.GetSendPackets().size()==1,"extended send sequence boundary");
|
||||
};
|
||||
sendCheck("net.Send67AttrPacket(258,-1,-2,0x1234)\n",{208,2,255,254,255,0x34,0x12});
|
||||
sendCheck("net.Send67AttrClosePacket()\n",{209});
|
||||
sendCheck("net.SendMiniGameCatchKingStart(257)\n",{163,5,0,0,1});
|
||||
sendCheck("net.SendMiniGameCatchKingDeckCardClick()\n",{163,4,0,1});
|
||||
sendCheck("net.SendMiniGameCatchKingFieldCardClick(-1)\n",{163,5,0,2,255});
|
||||
sendCheck("net.SendMiniGameCatchKingReward()\n",{163,4,0,3});
|
||||
python.execute("w.calls=[]\nnet.OpenCatchKing()\nassert w.calls==['king']\nw.calls=[]\n");
|
||||
sendCheck("net.CalendarOpen()\nnet.CalendarClose()\nnet.CalendarSend(1,2,'12:34','23:45')\n",{});
|
||||
|
||||
auto& actors=NetworkActorManager::Instance();actors.Clear();net.SetMainActorVID(1);
|
||||
python.execute("assert player.IsPVPInstance(2)==0 and player.IsInSafeArea()==0\n");
|
||||
SNetworkActorData main{};main.m_dwVID=1;main.m_dwGuildID=10;main.m_lCurX=100;main.m_lCurY=200;
|
||||
SNetworkActorData target{};target.m_dwVID=2;target.m_dwGuildID=20;
|
||||
actors.AppendActor(main);actors.AppendActor(target);actors.InsertPVPKey(1,2);
|
||||
std::vector<uint8_t> opened(22,0);opened[0]=220;
|
||||
sendCheck("net.CalendarOpen()\n",opened);opened[1]=1;sendCheck("net.CalendarClose()\n",opened);
|
||||
sendCheck("net.CalendarSend(-1,0x12345678,'12:34X7','23:45')\n",
|
||||
{220,2,255,255,255,255,0x78,0x56,0x34,0x12,'1','2',':','3','4','X','2','3',':','4','5',0});
|
||||
python.execute("assert player.IsPVPInstance(2)==1 and player.IsPVPInstance(99)==0\n");
|
||||
net.SetPhase(PHASE_GAME);
|
||||
python.execute("w.calls=[]\nplayer.SetTarget(0)\nplayer.ActEmotion(999)\nassert w.calls==[('shot',1,'NEED_TARGET')],w.calls\n");
|
||||
actors.GetActorData(2)->m_stName="Target Name";
|
||||
python.execute("player.SetTarget(2)\n");net.ClearSendQueue();python.execute("player.ActEmotion(0)\n");
|
||||
auto kiss=wire::chat("/kiss Target Name",CHAT_TYPE_TALKING);
|
||||
require(net.GetSendQueue()==kiss,"emotion request must use alive target name, not supplied ID");
|
||||
actors.GetActorData(2)->m_pActorInstance->SetHP(0);net.ClearSendQueue();
|
||||
python.execute("w.calls=[]\nplayer.ActEmotion(12)\nassert w.calls==[('shot',1,'NEED_TARGET')]\n");
|
||||
require(net.GetSendQueue().empty(),"emotion sent to dead target");actors.GetActorData(2)->m_pActorInstance->SetHP(1000);
|
||||
python.execute("player.SetTarget(0)\nw.calls=[]\n");
|
||||
actors.RemovePVPKey(1,2);actors.InsertGVGKey(10,20);python.execute("assert player.IsPVPInstance(2)==1\n");
|
||||
actors.RemoveGVGKey(10,20);actors.GetActorData(1)->m_duelMode=DUEL_CANNOTATTACK;
|
||||
python.execute("assert player.IsPVPInstance(2)==1\n"); // Original GetDuelMode checks any nonzero mode.
|
||||
actors.GetActorData(1)->m_duelMode=DUEL_NONE;
|
||||
python.execute("assert player.IsPVPInstance(2)==0\n");
|
||||
auto* a=actors.GetActorData(1);auto* b=actors.GetActorData(2);a->m_bType=b->m_bType=6;
|
||||
python.execute("assert player.CanAttackInstance(2)==0 and player.CanAttackInstance(1)==0\n");
|
||||
actors.InsertPVPKey(1,2);python.execute("assert player.CanAttackInstance(2)==1\n");actors.RemovePVPKey(1,2);
|
||||
a->m_duelMode=DUEL_CANNOTATTACK;python.execute("assert player.IsPVPInstance(2)==1 and player.CanAttackInstance(2)==0\n");
|
||||
a->m_duelMode=DUEL_START;python.execute("assert player.CanAttackInstance(2)==0\n");
|
||||
actors.InsertDUELKey(1,2);python.execute("assert player.CanAttackInstance(2)==1\n");a->m_duelMode=DUEL_NONE;
|
||||
a->m_byPKMode=1;b->m_byPKMode=4;python.execute("assert player.CanAttackInstance(2)==0\n");
|
||||
b->m_byPKMode=0;python.execute("assert player.CanAttackInstance(2)==1\n");
|
||||
AppendPartyMember(10,"self");AppendPartyMember(20,"target");LinkPartyMember(10,1);LinkPartyMember(20,2);
|
||||
python.execute("assert player.CanAttackInstance(2)==0\n");
|
||||
b->m_dwEmpireID=2;python.execute("assert player.CanAttackInstance(2)==1\n");b->m_dwEmpireID=0;
|
||||
b->m_bType=2;python.execute("assert player.CanAttackInstance(2)==1\n");
|
||||
b->m_bType=4;b->m_dwRace=13000;python.execute("assert player.CanAttackInstance(2)==1\n");
|
||||
b->m_dwRace=13001;python.execute("assert player.CanAttackInstance(2)==0\n");
|
||||
net.SetPhase(PHASE_GAME);command("ObserverMode 1");b->m_bType=0;
|
||||
python.execute("assert player.CanAttackInstance(2)==0\n");command("ObserverMode 0");
|
||||
require(CPythonBackground::Instance().LoadMap("parity_map"),"fixture map load");
|
||||
python.execute("assert player.IsInSafeArea()==1\n");
|
||||
std::vector<uint8_t> clear(256*256,0);auto* terrain=CPythonBackground::Instance().GetTerrain();
|
||||
require(terrain->LoadAttrFromBuffer(clear.data(),clear.size()),"safe attr fixture");
|
||||
python.execute("assert player.IsInSafeArea()==0\nbackground.TextureChange('alternate.txt')\n");
|
||||
auto uv=terrain->GetTextureUv(4,3200,6400);
|
||||
require(std::abs(uv[0]-2.25f)<1e-6 && std::abs(uv[1]-5.5f)<1e-6,"original terrain UV matrix");
|
||||
auto draw=terrain->BuildPatchDraw(0,0);
|
||||
auto at=terrain->GetTextureUv(4,draw.positions[0],draw.positions[2]);
|
||||
require(draw.texture0=="ymir work/terrainmaps/alternate.dds" && draw.uv0[0]==at[0] && draw.uv0[1]==at[1],"texture change not reflected in draw");
|
||||
require(!terrain->LoadTextureSetFromString("Start Texture004\n\"bad.dds\"\nnan\nEnd Texture004\n"),"invalid UV set accepted");
|
||||
require(terrain->GetTextureUv(4,3200,6400)==uv,"invalid set destroyed previous transform");
|
||||
|
||||
// The real target receive dispatcher must create/follow/delete world effects,
|
||||
// not just minimap entries. Use a nonzero map origin to catch double/missing conversion.
|
||||
auto& bg=CPythonBackground::Instance();auto& effects=EffectManager::Instance();
|
||||
effects.DeleteAllInstances();require(bg.LoadMap("target_map"),"direct target map load");
|
||||
auto updateTarget=[&](uint32_t id,uint32_t x,uint32_t y,uint8_t type) {
|
||||
std::vector<uint8_t> packet(14,0);packet[0]=123;packet[13]=type;
|
||||
for(int byte=0;byte<4;++byte) {packet[1+byte]=id>>(8*byte);packet[5+byte]=x>>(8*byte);packet[9+byte]=y>>(8*byte);}
|
||||
net.PushRecvData(packet);net.ProcessRecvData();
|
||||
};
|
||||
auto deleteTarget=[&](uint32_t id) {
|
||||
uint8_t packet[]={124,uint8_t(id),uint8_t(id>>8),uint8_t(id>>16),uint8_t(id>>24)};
|
||||
net.PushRecvData(packet,sizeof(packet));net.ProcessRecvData();
|
||||
};
|
||||
auto drawCenter=[&](float x,float y,float z,const char* texture) {
|
||||
float identity[16]={1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1};float eye[]={0,100,-200};
|
||||
std::vector<Render3DDraw> draws;effects.BuildDrawCommands(identity,identity,eye,draws);
|
||||
require(draws.size()==1 && draws[0].positions.size()==12,"target effect missing/duplicated");
|
||||
float center[3]={};for(size_t i=0;i<12;++i)center[i%3]+=draws[0].positions[i]/4;
|
||||
require(std::abs(center[0]-x)<0.01f && std::abs(center[1]-y)<0.01f && std::abs(center[2]-z)<0.01f,"target effect coordinate/follow transform");
|
||||
require(draws[0].texture0.find(texture)!=std::string::npos,"wrong target effect resource");
|
||||
};
|
||||
updateTarget(77,102500,205000,1);effects.Update(0.1f);drawCenter(100,100,200,"regular.dds");
|
||||
require(bg.Warp(102500,205000),"target map warp");require(effects.GetActiveInstanceCount()==0,"warp kept prior map target");
|
||||
updateTarget(77,102500,205000,1);effects.Update(0.1f);drawCenter(100,100,200,"regular.dds");
|
||||
updateTarget(77,102700,205300,1);drawCenter(300,100,500,"regular.dds");
|
||||
deleteTarget(77);require(effects.GetActiveInstanceCount()==0,"target delete kept instance");
|
||||
updateTarget(77,102900,205500,5);effects.Update(0.1f);drawCenter(500,100,700,"shop.dds");
|
||||
deleteTarget(77);
|
||||
auto* moving=actors.GetActorData(1);require(moving && moving->m_pActorInstance,"target actor fixture");
|
||||
moving->m_pActorInstance->SetPosition(40,60,80);
|
||||
std::vector<uint8_t> targetCreate(43,0);targetCreate[0]=125;targetCreate[1]=78;targetCreate[38]=1;targetCreate[42]=2;
|
||||
net.PushRecvData(targetCreate.data(),10);net.ProcessRecvData();require(effects.GetActiveInstanceCount()==0,"fragmented target created early");
|
||||
net.PushRecvData(targetCreate.data()+10,33);net.ProcessRecvData();bg.Update(0,0,0);effects.Update(0.1f);
|
||||
drawCenter(40,60,80,"regular.dds");
|
||||
// The first actor binding survives repeated create; coordinate updates cannot override it.
|
||||
bg.CreateTargetEffect(78,uint32_t(2));updateTarget(78,102900,205500,1);
|
||||
moving->m_pActorInstance->SetPosition(70,90,110);bg.Update(0,0,0);drawCenter(70,90,110,"regular.dds");
|
||||
deleteTarget(78);bg.Update(0,0,0);require(effects.GetActiveInstanceCount()==0,"deleted actor target recreated");
|
||||
bg.CreateTargetEffectShop(79,uint32_t(1));bg.Update(0,0,0);effects.Update(0.1f);drawCenter(70,90,110,"shop.dds");
|
||||
deleteTarget(79);bg.Update(0,0,0);require(effects.GetActiveInstanceCount()==0,"shop binding survived delete");
|
||||
auto* targetTerrain=bg.GetTerrain();std::vector<uint16_t> emptyHeight(131*131,0);
|
||||
require(targetTerrain->LoadFromBuffer(emptyHeight.data(),emptyHeight.size()),"zero-height fixture");
|
||||
updateTarget(80,102500,205000,5);bg.Update(0,0,0);require(effects.GetActiveInstanceCount()==0,"zero-height target not deferred");
|
||||
require(targetTerrain->LoadFromBuffer(targetHeights.data(),targetHeights.size()),"loaded-height fixture");
|
||||
bg.Update(0,0,0);effects.Update(0.1f);drawCenter(100,100,200,"regular.dds"); // Original shared reserve uses regular resource.
|
||||
deleteTarget(80);
|
||||
for(int distance=0;distance<4;++distance) {
|
||||
command("StoneDetect 1 "+std::to_string(distance)+" 90");effects.Update(0.1f);
|
||||
drawCenter(70,90,10,compassTextures[distance]); // fmod(540-90,360)=90; local X rotates toward -Z.
|
||||
effects.DeleteAllInstances();
|
||||
}
|
||||
command("StoneDetect 1 256 450");effects.Update(0.1f);drawCenter(70,90,10,"detected.dds");effects.DeleteAllInstances();
|
||||
command("StoneDetect 999 1 90");command("StoneDetect 1 4 90");command("StoneDetect 1 1");command("StoneDetect 1 1 nan");
|
||||
require(effects.GetActiveInstanceCount()==0,"invalid StoneDetect emitted effect");
|
||||
bg.CreateTargetEffect(81,uint32_t(1));bg.Update(0,0,0);
|
||||
effects.DeleteAllInstances();bg.Update(0,0,0);require(effects.GetActiveInstanceCount()==1,"dead target instance not recreated");
|
||||
const auto unrelated=effects.CreateEffect("d:/ymir work/effect/etc/direction/direction_land.mse");
|
||||
bg.Destroy();require(effects.GetActiveInstanceCount()==1 && effects.IsAliveEffect(unrelated),"map destroy leaked targets/deleted unrelated effects");
|
||||
effects.DeleteAllInstances();
|
||||
|
||||
actors.Clear();require(LoadSkillDescriptions("skilldesc-missing.txt")==false,"missing fixture accepted");
|
||||
python.execute("skill.RegisterSkill(200,'skill/cooldown.txt')\nw.calls=[]\n");
|
||||
SetPlayerSkill(3,200);SetPlayerStatusPoint(19,1000);SetPlayerStatusPoint(21,200);
|
||||
UseGuildSkill(3);python.execute("assert w.calls==[('cooldown',3,10.0)],w.calls\n");
|
||||
// SkillDesc's empty motion column creates real no-motion skills, so
|
||||
// permission tests assert actual packets without relying on absent GR2s.
|
||||
auto desc=[](unsigned id,const std::string& attrs,const std::string& weapons="",const std::string& motion="",const std::string& count="") {
|
||||
std::vector<std::string> columns(17);columns[0]=std::to_string(id);columns[1]="active";columns[2]="Gate";columns[10]=attrs;columns[11]=weapons;columns[13]=motion;columns[14]="0";columns[15]=count;columns[16]="0";
|
||||
std::string row;for(size_t i=0;i<columns.size();++i) {if(i)row+='\t';row+=columns[i];}return row+'\n';
|
||||
};
|
||||
write(root/"skill/gates.txt",desc(210,"")+desc(211,"HORSE_SKILL")+desc(212,"PASSIVE")+desc(213,"ATTACK_SKILL")
|
||||
+desc(3,"TOGGLE")+desc(4,"TOGGLE|STANDING_SKILL")+desc(220,"")+desc(221,"")+desc(222,"")
|
||||
+desc(223,"USE_HP")+desc(224,"CAN_USE_IF_NOT_ENOUGH")+desc(225,"NEED_EMPTY_BOTTLE|NEED_POISON_BOTTLE")
|
||||
+desc(226,"WEAPON_LIMITATION","EMPTY_HAND")+desc(227,"WEAPON_LIMITATION","BOW")+desc(131,"")+desc(228,"TOGGLE")
|
||||
+desc(229,"CHARGE_ATTACK")+desc(230,"")+desc(231,"")
|
||||
+desc(240,"NEED_TARGET")+desc(241,"NEED_TARGET|NEED_CORPSE")
|
||||
+desc(242,"NEED_TARGET|ONLY_FOR_ALLIANCE")+desc(243,"NEED_TARGET|ONLY_FOR_ALLIANCE|CAN_USE_FOR_ME")
|
||||
+desc(244,"NEED_TARGET|CAN_USE_FOR_ME")+desc(245,"SEARCH_TARGET")+desc(246,"")+desc(250,"","","1")
|
||||
+desc(260,"NEED_TARGET")+desc(261,"NEED_TARGET|ONLY_FOR_ALLIANCE")+desc(262,"NEED_TARGET|CHARGE_ATTACK")
|
||||
+desc(270,"NEED_TARGET|FAN_RANGE","","","3")+desc(271,"NEED_TARGET|CIRCLE_RANGE","","","3")
|
||||
+desc(272,"NEED_TARGET","","","3")+desc(273,"NEED_TARGET|FAN_RANGE|CIRCLE_RANGE","","","3")
|
||||
+desc(274,"NEED_TARGET|CIRCLE_RANGE","","1","2")+desc(275,"NEED_TARGET","","","0")
|
||||
+desc(276,"NEED_TARGET","","","1")+desc(277,"NEED_TARGET","","","2+k")
|
||||
+desc(278,"NEED_TARGET","","","5000")+desc(279,"NEED_TARGET|ATTACK_SKILL"));
|
||||
require(LoadSkillDescriptions("skill/gates.txt"),"skill permission fixture");
|
||||
auto table=[](unsigned id,const std::string& cost,const std::string& cooldown="0",unsigned range=0) {
|
||||
std::vector<std::string> columns(27);columns[0]=std::to_string(id);columns[8]=cost;columns[11]=cooldown;columns[25]=std::to_string(range);columns[26]="0";
|
||||
std::string row;for(size_t i=0;i<columns.size();++i) {if(i)row+='\t';row+=columns[i];}return row+'\n';
|
||||
};
|
||||
write(root/"skill/costs.txt",table(210,"1")+table(211,"1")+table(213,"1")+table(220,"20")+table(221,"0")+table(222,"-1")
|
||||
+table(223,"20")+table(224,"20")+table(225,"1")+table(226,"1")+table(227,"1")+table(131,"0")+table(228,"0")
|
||||
+table(229,"20","20")+table(230,"20","20")+table(231,"1.9")
|
||||
+table(240,"1")+table(241,"1")+table(242,"1")+table(243,"1")+table(244,"1")+table(245,"1")+table(246,"1")+table(250,"1")
|
||||
+table(260,"1","0",200)+table(261,"1","0",200)+table(262,"1","20",200)
|
||||
+table(270,"1","0",2000)+table(271,"1","0",2000)+table(272,"1","0",2000)+table(273,"1","0",2000)
|
||||
+table(274,"1","0",2000)+table(275,"1","0",2000)+table(276,"1","0",2000)+table(277,"1","0",2000)+table(278,"1","0",2000)+table(279,"1","2",2000));
|
||||
require(LoadSkillTable("skill/costs.txt"),"skill cost table fixture");
|
||||
SetPlayerSkill(10,210);SetPlayerSkill(11,211);SetPlayerSkill(12,212);SetPlayerSkill(13,213);
|
||||
for(int index : {210,211,212,213})SetPlayerSkillLevel(index,0,1);
|
||||
SetPlayerStatusPoint(5,100);SetPlayerStatusPoint(7,100);
|
||||
auto resetCalls=[&]() {net.ClearSendQueue();python.execute("w.calls=[]\n");};
|
||||
resetCalls();ClickSkillSlot(10);require(net.GetSendQueue().empty(),"skill without main actor sent packet");
|
||||
SNetworkActorData caster{};caster.m_dwVID=1;caster.m_bType=6;caster.m_dwRace=0;actors.AppendActor(caster);net.SetMainActorVID(1);
|
||||
auto* casting=actors.GetActorData(1);auto& castingActor=*casting->m_pActorInstance;
|
||||
auto reject=[&](int slot) {resetCalls();ClickSkillSlot(slot);require(net.GetSendQueue().empty(),"blocked skill sent packet");python.execute("assert w.calls==[],w.calls\n");};
|
||||
reject(12);castingActor.SetActorType(7);reject(10);castingActor.SetActorType(6);
|
||||
command("ObserverMode 1");reject(10);command("ObserverMode 0");
|
||||
casting->m_awPart[RaceData::PART_MAIN]=201;reject(10);casting->m_awPart[RaceData::PART_MAIN]=0;
|
||||
casting->m_awPart[RaceData::PART_WEAPON]=29101;reject(10);casting->m_awPart[RaceData::PART_WEAPON]=0;
|
||||
castingActor.Stun();reject(10);castingActor.SetSleep(false);castingActor.Revive();
|
||||
resetCalls();ClickSkillSlot(11);require(net.GetSendQueue().empty(),"unmounted horse skill sent");
|
||||
python.execute("assert w.calls==[('skill',1,'HAVE_TO_RIDE')],w.calls\n");
|
||||
castingActor.SetMountingHorse(true);casting->m_dwMountVnum=20107;reject(11);
|
||||
SetPlayerSkill(107,107);SetPlayerSkillLevel(107,0,19);reject(11);
|
||||
SetPlayerSkillLevel(107,0,20);casting->m_dwMountVnum=20104;reject(11);
|
||||
casting->m_dwMountVnum=20107;resetCalls();ClickSkillSlot(10);
|
||||
require(net.GetSendQueue().empty(),"mounted regular skill sent");python.execute("assert w.calls==[('skill',1,'NOT_HORSE_SKILL')],w.calls\n");
|
||||
resetCalls();ClickSkillSlot(11);require(net.GetSendQueue()==std::vector<uint8_t>({233,211,0,0,0,0,0,0,0}),"mounted skill packet differs");
|
||||
python.execute("assert w.calls==[('cooldown',11,0.0)],w.calls\n");
|
||||
castingActor.SetMountingHorse(false);casting->m_dwMountVnum=0;resetCalls();ClickSkillSlot(10);
|
||||
require(net.GetSendQueue()==std::vector<uint8_t>({233,210,0,0,0,0,0,0,0}),"normal skill packet differs");
|
||||
SetPlayerSkill(14,3);SetPlayerSkill(15,4);SetPlayerAffect(14);SetPlayerAffect(15);
|
||||
resetCalls();ClickSkillSlot(14);
|
||||
require(net.GetSendQueue()==std::vector<uint8_t>({233,3,0,0,0,14,0,0,0}),"ordinary toggle lost skill-slot argument");
|
||||
python.execute("assert w.calls==[],w.calls\n");
|
||||
castingActor.SetActorType(7);reject(14);resetCalls();ClickSkillSlot(15);
|
||||
require(net.GetSendQueue()==std::vector<uint8_t>({233,4,0,0,0,0,0,0,0}),"standing toggle permission exception changed");
|
||||
python.execute("assert w.calls==[],w.calls\n");castingActor.SetActorType(6);
|
||||
require(bg.LoadMap("parity_map"),"skill safe map fixture");resetCalls();ClickSkillSlot(13);
|
||||
require(net.GetSendQueue().empty(),"safe-zone attack skill sent");python.execute("assert w.calls==[('skill',1,'IN_SAFE')],w.calls\n");
|
||||
auto failed=[&](int slot,const char* reason) {
|
||||
resetCalls();ClickSkillSlot(slot);require(net.GetSendQueue().empty(),"unusable skill sent a packet");
|
||||
python.execute(std::string("assert w.calls==[('skill',1,'")+reason+"')],w.calls\n");
|
||||
};
|
||||
auto accepted=[&](int slot,unsigned index,float cooltime=0) {
|
||||
resetCalls();ClickSkillSlot(slot);
|
||||
require(net.GetSendQueue()==std::vector<uint8_t>({233,uint8_t(index),uint8_t(index>>8),0,0,0,0,0,0}),"resource boundary skill packet");
|
||||
python.execute("assert w.calls==[('cooldown',"+std::to_string(slot)+","+std::to_string(cooltime)+")],w.calls\n");
|
||||
};
|
||||
for(int index=220;index<=228;++index) {SetPlayerSkill(index-200,index);SetPlayerSkillLevel(index,0,1);}
|
||||
SetPlayerSkill(29,131);SetPlayerSkillLevel(131,0,1);
|
||||
SetPlayerSkillLevel(220,0,0);failed(20,"NOT_YET_LEARN");
|
||||
python.execute("assert player.ToggleLevelLimit()==0\n");accepted(20,220);
|
||||
python.execute("assert player.ToggleLevelLimit()==1\n");SetPlayerSkillLevel(220,0,1);
|
||||
SetPlayerStatusPoint(7,19);failed(20,"NOT_ENOUGH_SP");SetPlayerStatusPoint(7,20);accepted(20,220);
|
||||
require(GetPlayerStatusPoint(7)==20,"client deducted skill resources before server response");
|
||||
failed(21,"NOT_ENOUGH_SP");SetPlayerStatusPoint(7,0);accepted(22,222);accepted(29,131);accepted(28,228);
|
||||
failed(24,"NOT_ENOUGH_SP");SetPlayerStatusPoint(7,1);accepted(24,224);
|
||||
SetPlayerStatusPoint(5,19);SetPlayerStatusPoint(7,100);failed(23,"NOT_ENOUGH_HP");
|
||||
SetPlayerStatusPoint(5,20);SetPlayerStatusPoint(7,19);failed(23,"NOT_ENOUGH_SP");
|
||||
SetPlayerStatusPoint(7,20);accepted(23,223);
|
||||
failed(25,"NEED_EMPTY_BOTTLE");TItemData bottle{};bottle.vnum=27995;SetPlayerItemData(5,100,bottle);
|
||||
failed(25,"NEED_POISON_BOTTLE");bottle.vnum=27996;SetPlayerItemData(6,179,bottle);accepted(25,225);
|
||||
accepted(26,226);failed(27,"NOT_MATCHABLE_WEAPON");
|
||||
castingActor.SetMotionMode(8);failed(20,"REMOVE_FISHING_ROD");castingActor.SetMotionMode(1);
|
||||
casting->m_affectFlags[0]|=1u<<31;SetPlayerStatusPoint(5,0);SetPlayerStatusPoint(7,0);accepted(23,223);
|
||||
casting->m_affectFlags[0]&=~(1u<<31);
|
||||
for(int index=229;index<=231;++index) {SetPlayerSkill(index-198,index);SetPlayerSkillLevel(index,0,1);}
|
||||
SetPlayerStatusPoint(7,20);accepted(31,229,10);failed(31,"WAIT_COOLTIME");
|
||||
casting->m_affectFlags[0]|=1u<<31;SetPlayerStatusPoint(7,0);accepted(31,229,10);
|
||||
casting->m_affectFlags[0]&=~(1u<<31);SetPlayerStatusPoint(7,20);accepted(32,230,10);
|
||||
casting->m_affectFlags[0]|=1u<<31;SetPlayerStatusPoint(7,0);failed(32,"WAIT_COOLTIME");
|
||||
python.execute("assert player.ToggleCoolTime()==0\n");accepted(32,230,10);python.execute("assert player.ToggleCoolTime()==1\n");
|
||||
casting->m_affectFlags[0]&=~(1u<<31);failed(33,"NOT_ENOUGH_SP");SetPlayerStatusPoint(7,1);accepted(33,231);
|
||||
python.execute("player_only=Window()\nplayer.SetGameWindow(player_only)\n");
|
||||
accepted(33,231);SetPlayerStatusPoint(7,0);failed(20,"NOT_ENOUGH_SP");
|
||||
python.execute("assert player_only.calls==[],player_only.calls\nplayer.SetGameWindow(w)\n");
|
||||
for(int index=240;index<=246;++index) {SetPlayerSkill(index-200,index);SetPlayerSkillLevel(index,0,1);}
|
||||
SetPlayerStatusPoint(7,100);SetPlayerStatusPoint(5,100);castingActor.SetPosition(0,0,0);
|
||||
auto* skillTerrain=bg.GetTerrain();std::vector<uint8_t> attrs(256*256,0);
|
||||
require(skillTerrain->LoadAttrFromBuffer(attrs.data(),attrs.size()),"skill target safe fixture");
|
||||
auto select=[&](uint32_t vid) {python.execute("player.SetTarget("+std::to_string(vid)+")\n");};
|
||||
auto targetAccepted=[&](int slot,unsigned index,uint32_t vid,bool changed=false) {
|
||||
resetCalls();ClickSkillSlot(slot);std::vector<uint8_t> expected;
|
||||
if(changed) {expected={61,uint8_t(vid),uint8_t(vid>>8),uint8_t(vid>>16),uint8_t(vid>>24)};}
|
||||
std::vector<uint8_t> use={233,uint8_t(index),uint8_t(index>>8),0,0,uint8_t(vid),uint8_t(vid>>8),uint8_t(vid>>16),uint8_t(vid>>24)};
|
||||
expected.insert(expected.end(),use.begin(),use.end());require(net.GetSendQueue()==expected,"skill target wire VID mismatch");
|
||||
};
|
||||
select(99999);failed(40,"NEED_TARGET");failed(41,"ONLY_FOR_CORPSE");
|
||||
targetAccepted(44,244,1);require(castingActor.GetFlyTargetVID()==1,"self fallback fly target");
|
||||
SNetworkActorData enemy{};enemy.m_dwVID=2;enemy.m_bType=0;enemy.m_dwRace=999999;actors.AppendActor(enemy);
|
||||
auto enemyActor=actors.GetActorInstance(2);enemyActor->SetPosition(100,0,0);
|
||||
select(2);targetAccepted(40,240,2);require(castingActor.GetFlyTargetVID()==2 && std::abs(castingActor.GetYaw()-90)<0.001f,"enemy fly target/facing");
|
||||
// Mobile drag aims toward a valid hostile target and uses the original packet path.
|
||||
SetPlayerSkill(79,279);SetPlayerSkillLevel(279,0,1);select(0);resetCalls();
|
||||
UsePlayerTouchSkill(79,100,0,0,false);
|
||||
require(net.GetSendQueue()==std::vector<uint8_t>({61,2,0,0,0,233,23,1,0,0,2,0,0,0}),"mobile aim target/skill packet mismatch");
|
||||
require(std::abs(castingActor.GetYaw()-90)<0.001f,"mobile screen aim yaw");
|
||||
resetCalls();UsePlayerTouchSkill(79,100,0,0,true);require(net.GetSendQueue().empty(),"mobile repeated cooling skill sent packet");
|
||||
python.execute("assert w.calls==[],w.calls\n");EndSkillCoolTime(279);UsePlayerTouchSkill(79,100,0,0,true);
|
||||
require(net.GetSendQueue()==std::vector<uint8_t>({233,23,1,0,0,2,0,0,0}),"mobile ready skill did not repeat");
|
||||
EndSkillCoolTime(279);select(0);resetCalls();UsePlayerTouchSkill(79,0,0,0,false);
|
||||
require(net.GetSendQueue()==std::vector<uint8_t>({61,2,0,0,0,233,23,1,0,0,2,0,0,0}),"mobile tap did not acquire nearby hostile");
|
||||
resetCalls();UsePlayerTouchSkill(10,0,0,0,true);require(net.GetSendQueue().empty(),"mobile utility skill repeated");
|
||||
failed(41,"ONLY_FOR_CORPSE");enemyActor->Die();failed(40,"NEED_TARGET");
|
||||
actors.SetPickedInstanceVID(2);failed(40,"NEED_TARGET");actors.ClearPickedInstance();
|
||||
targetAccepted(41,241,2);enemyActor->Revive();
|
||||
failed(42,"ONLY_FOR_ALLIANCE");targetAccepted(43,243,1);
|
||||
select(1);failed(42,"CANNOT_USE_SELF");targetAccepted(43,243,1);
|
||||
SNetworkActorData ally{};ally.m_dwVID=3;ally.m_bType=6;ally.m_dwRace=0;actors.AppendActor(ally);
|
||||
actors.GetActorInstance(3)->SetPosition(100,0,0);select(3);targetAccepted(42,242,3);failed(40,"CANNOT_ATTACK");
|
||||
select(2);targetAccepted(46,246,0);python.execute("assert player.GetTargetVID()==2\n");
|
||||
// Selected dead actor falls back to a live native picked actor, with target packet first.
|
||||
enemyActor->Die();actors.SetPickedInstanceVID(3);select(2);targetAccepted(42,242,3,true);actors.ClearPickedInstance();enemyActor->Revive();
|
||||
attrs[1]=TerrainAttr::ATTR_BANPK;require(skillTerrain->LoadAttrFromBuffer(attrs.data(),attrs.size()),"safe enemy attr");
|
||||
select(2);failed(40,"CANNOT_ATTACK_ENEMY_IN_SAFE_AREA");attrs[1]=0;
|
||||
require(skillTerrain->LoadAttrFromBuffer(attrs.data(),attrs.size()),"clear safe enemy attr");
|
||||
castingActor.SetYaw(90);select(0);targetAccepted(45,245,2,true);python.execute("assert player.GetTargetVID()==2\n");
|
||||
enemyActor->SetPosition(-100,0,0);castingActor.SetYaw(90);select(0);failed(45,"NEED_TARGET");
|
||||
select(3);actors.RemoveActor(3);failed(42,"NEED_TARGET");
|
||||
SNetworkActorData farther=enemy;farther.m_dwVID=4;actors.AppendActor(farther);
|
||||
actors.GetActorInstance(4)->SetPosition(1200,0,0);enemyActor->SetPosition(1900,0,0);
|
||||
select(0);targetAccepted(45,245,2,true); // Both keys clamp to 1000: lower VID wins.
|
||||
actors.RemoveActor(4);enemyActor->SetPosition(2000,0,0);select(0);targetAccepted(45,245,2,true);
|
||||
enemyActor->SetPosition(2001,0,0);select(0);failed(45,"NEED_TARGET");
|
||||
SetPlayerSkill(50,250);SetPlayerSkillLevel(250,0,1);reject(50); // No motion data: no move/use packet or cooldown.
|
||||
for(int index=260;index<=262;++index) {SetPlayerSkill(index-200,index);SetPlayerSkillLevel(index,0,1);}
|
||||
castingActor.SetPosition(0,0,0);castingActor.SetSpeed(100);enemyActor->SetPosition(1000,0,0);select(2);
|
||||
resetCalls();ClickSkillSlot(60);require(net.GetSendQueue().empty(),"far skill sent before approach");
|
||||
ProcessPlayerReservedSkill();require(castingActor.HasMoveTarget(),"reserved skill did not steer");
|
||||
castingActor.Update(1);require(std::abs(castingActor.GetX()-100)<0.001f,"reserved movement did not advance");
|
||||
castingActor.Stun();ProcessPlayerReservedSkill();require(!castingActor.HasMoveTarget(),"stun did not pause owned approach");
|
||||
castingActor.Update(1);require(std::abs(castingActor.GetX()-100)<0.001f,"stunned reservation kept moving");
|
||||
castingActor.Revive();ProcessPlayerReservedSkill();require(castingActor.HasMoveTarget(),"reservation did not resume after revive");
|
||||
enemyActor->SetPosition(1200,0,0);ProcessPlayerReservedSkill();float mx,mz;castingActor.GetMoveTarget(mx,mz);
|
||||
require(mx==1200 && mz==0,"reservation did not follow moving target");
|
||||
castingActor.SetPosition(1010,0,0);ProcessPlayerReservedSkill();require(net.GetSendQueue().empty(),"190-unit reserved boundary not strict");
|
||||
castingActor.SetPosition(1011,0,0);select(99999);net.ClearSendQueue();ProcessPlayerReservedSkill();
|
||||
require(net.GetSendQueue()==std::vector<uint8_t>({61,2,0,0,0,233,4,1,0,0,2,0,0,0}) && !castingActor.HasMoveTarget(),"reservation did not restore/cast/stop");
|
||||
auto sent=net.GetSendQueue();ProcessPlayerReservedSkill();require(net.GetSendQueue()==sent,"reservation cast twice");
|
||||
auto reserve=[&](uint32_t vid,int slot=60) {CancelPlayerReservedSkill();castingActor.SetPosition(0,0,0);select(vid);resetCalls();ClickSkillSlot(slot);ProcessPlayerReservedSkill();};
|
||||
reserve(2);SetPlayerJoystick(true,1,0);SetPlayerJoystick(false,0,0);require(!castingActor.HasMoveTarget(),"joystick did not cancel reservation");
|
||||
ProcessPlayerReservedSkill();require(net.GetSendQueue().empty(),"cancelled reservation sent");
|
||||
reserve(2);python.execute("player.SetSingleDIKKeyState(17,1)\nplayer.SetSingleDIKKeyState(17,0)\n");require(!castingActor.HasMoveTarget(),"keyboard did not cancel");
|
||||
reserve(2);SetPlayerAttackKey(true);SetPlayerAttackKey(false);require(!castingActor.HasMoveTarget(),"attack did not cancel");
|
||||
SNetworkActorData transient=enemy;transient.m_dwVID=5;actors.AppendActor(transient);actors.GetActorInstance(5)->SetPosition(1200,0,0);
|
||||
reserve(5);actors.RemoveActor(5);ProcessPlayerReservedSkill();require(!castingActor.HasMoveTarget() && net.GetSendQueue().empty(),"deleted skill target left movement");
|
||||
actors.AppendActor(transient);actors.GetActorInstance(5)->SetPosition(1200,0,0);reserve(5);
|
||||
auto oldTarget=actors.GetActorInstance(5);actors.RemoveActor(5);actors.AppendActor(transient);ProcessPlayerReservedSkill();
|
||||
require(!castingActor.HasMoveTarget() && net.GetSendQueue().empty(),"reused target VID inherited skill");actors.RemoveActor(5);
|
||||
SNetworkActorData friendActor{};friendActor.m_dwVID=3;friendActor.m_bType=6;actors.AppendActor(friendActor);actors.GetActorInstance(3)->SetPosition(1200,0,0);
|
||||
reserve(3,61);castingActor.SetPosition(1011,0,0);ProcessPlayerReservedSkill();
|
||||
require(net.GetSendQueue()==std::vector<uint8_t>({233,5,1,0,0,3,0,0,0}),"friendly reserved skill");
|
||||
reserve(2);net.SetMainActorVID(3);ProcessPlayerReservedSkill();require(!castingActor.HasMoveTarget(),"main actor change did not cancel");net.SetMainActorVID(1);
|
||||
SetPlayerStatusPoint(34,1);enemyActor->SetPosition(250,0,0);castingActor.SetPosition(0,0,0);select(2);targetAccepted(60,260,2);
|
||||
SetPlayerStatusPoint(34,0);enemyActor->SetPosition(100,0,0);attrs[1]=TerrainAttr::ATTR_BLOCK;
|
||||
require(skillTerrain->LoadAttrFromBuffer(attrs.data(),attrs.size()),"blocked skill target");failed(60,"CANNOT_APPROACH");targetAccepted(40,240,2);
|
||||
attrs[1]=0;require(skillTerrain->LoadAttrFromBuffer(attrs.data(),attrs.size()),"clear blocked skill target");
|
||||
auto* hugeRace=RaceManager::Instance().CreateRace(2493);hugeRace->RegisterMotionMode(1);require(enemyActor->SetRace(2493),"huge race fixture");
|
||||
enemyActor->SetPosition(390,0,0);targetAccepted(60,260,2);
|
||||
enemyActor->SetPosition(1000,0,0);select(2);resetCalls();ClickSkillSlot(62);
|
||||
require(net.GetSendQueue()==std::vector<uint8_t>({233,6,1,0,0,0,0,0,0}),"charge opening request");
|
||||
resetCalls();ClickSkillSlot(62);require(net.GetSendQueue().empty(),"charge opening repeated");
|
||||
casting->m_affectFlags[0]|=1u<<31;ProcessPlayerReservedSkill();castingActor.SetPosition(611,0,0);resetCalls();ProcessPlayerReservedSkill();
|
||||
require(net.GetSendQueue()==std::vector<uint8_t>({233,6,1,0,0,2,0,0,0}),"charge reserved completion");
|
||||
casting->m_affectFlags[0]&=~(1u<<31);CancelPlayerReservedSkill();
|
||||
// Multi-flight selection: actual MSM defending spheres, deterministic source RNG,
|
||||
// and CG53 byte ordering before the final CG233 (also before a failed motion bind).
|
||||
write(root/"skill/defend.msm","Group AttachingData\n{\nAttachingDataCount 1\nGroup AttachingData00\n{\nCollisionType 3\nIsAttaching 0\nSphereDataCount 2\nGroup SphereData00\n{\nRadius 10\nPosition 0 0 0\n}\nGroup SphereData01\n{\nRadius 20\nPosition 20 0 500\n}\n}\n}\n");
|
||||
auto* flightRace=RaceManager::Instance().CreateRace(30001);flightRace->RegisterMotionMode(1);
|
||||
require(flightRace->LoadRaceData("skill/defend.msm") && flightRace->GetDefendingSpheres().size()==2,"defending sphere positions not retained");
|
||||
auto addEnemy=[&](uint32_t vid,float x,float z) {
|
||||
SNetworkActorData data{};data.m_dwVID=vid;data.m_bType=0;data.m_dwRace=30001;actors.AppendActor(data);
|
||||
auto instance=actors.GetActorInstance(vid);require(instance->SetRace(30001),"flight race binding");instance->SetPosition(x,0,z);return instance;
|
||||
};
|
||||
for(int index=270;index<=278;++index) {SetPlayerSkill(index-200,index);SetPlayerSkillLevel(index,0,1);}
|
||||
castingActor.SetPosition(0,0,0);enemyActor->SetPosition(0,0,150);select(2);
|
||||
auto near=addEnemy(20,0,100),tie=addEnemy(21,0,100),side=addEnemy(22,100,0),dead=addEnemy(23,0,50);
|
||||
dead->Die(); // Dead targets never consume an additional slot.
|
||||
auto word=[](const std::vector<uint8_t>& bytes,size_t offset) {
|
||||
return uint32_t(bytes[offset])|(uint32_t(bytes[offset+1])<<8)|(uint32_t(bytes[offset+2])<<16)|(uint32_t(bytes[offset+3])<<24);
|
||||
};
|
||||
auto flightCast=[&](int slot,unsigned index,const std::vector<uint32_t>& extra,bool bindFails=false) {
|
||||
castingActor.ClearFlyTarget();resetCalls();ClickSkillSlot(slot);const auto& bytes=net.GetSendQueue();
|
||||
require(bytes.size()==extra.size()*13+(bindFails?0:9),"multi-flight packet length");
|
||||
for(size_t i=0;i<extra.size();++i)require(bytes[i*13]==53 && word(bytes,i*13+1)==extra[i],"multi-flight sorting/VID/header");
|
||||
if(!bindFails)require(bytes[extra.size()*13]==233 && word(bytes,extra.size()*13+1)==index && word(bytes,extra.size()*13+5)==2,"multi-flight final use target/order");
|
||||
require(castingActor.GetFlyTargetVID()==2,"additional flights replaced primary");
|
||||
};
|
||||
flightCast(70,270,{20,21}); // Equal distance: source map order, primary excluded.
|
||||
require(std::bit_cast<int32_t>(word(net.GetSendQueue(),9))==-100,"real target CG53 graphic Y sign");
|
||||
flightCast(71,271,{20,21});
|
||||
near->SetPosition(0,0,1500);tie->SetPosition(0,0,1200);side->SetPosition(100,0,0);
|
||||
flightCast(70,270,{20,21}); // Fan distance keys both clamp to 1000, unlike circle.
|
||||
flightCast(71,271,{22,21});flightCast(73,273,{20,21}); // FAN takes precedence.
|
||||
side->SetPosition(0,0,2010);near->SetPosition(0,0,3000);tie->SetPosition(0,0,3000);
|
||||
require(!castingActor.IsClickableDistanceDestInstance(*side,2000),"sphere range equality not strict");
|
||||
side->SetPosition(0,0,2009);require(castingActor.IsClickableDistanceDestInstance(*side,2000),"sphere radius not included in range");
|
||||
side->SetPosition(100,10000,0);require(!castingActor.IsClickableDistanceDestInstance(*side,2000),"sphere height ignored");
|
||||
ActorInstance noSphere;noSphere.SetPosition(0,0,0);require(!castingActor.IsClickableDistanceDestInstance(noSphere,2000),"unknown defense invented cylinder");
|
||||
near->SetPosition(0,0,100);castingActor.SetPosition(0,0,100);require(castingActor.IsClickableDistanceDestInstance(*near,150),"caster graphic Y conversion mismatch");
|
||||
castingActor.SetPosition(0,0,0);near->SetPosition(0,0,3000);
|
||||
eter::srandom(1);std::array<int32_t,4> expectedRandom{};
|
||||
for(int i=0;i<2;++i) {
|
||||
const float angle=eter::frandom(-10,10)*3.14159265358979323846f/180;
|
||||
expectedRandom[i*2]=int32_t(8000*std::sin(angle));expectedRandom[i*2+1]=int32_t(-8000*std::cos(angle));
|
||||
}
|
||||
eter::srandom(1);flightCast(72,272,{0,0});
|
||||
for(int i=0;i<2;++i)require(std::bit_cast<int32_t>(word(net.GetSendQueue(),i*13+5))==expectedRandom[i*2]
|
||||
&& std::bit_cast<int32_t>(word(net.GetSendQueue(),i*13+9))==expectedRandom[i*2+1],"random fill generator/8000 cone/coordinates");
|
||||
near->SetPosition(0,0,100);flightCast(74,274,{20},true); // Expansion precedes failed bind; no use/cooldown.
|
||||
python.execute("assert w.calls==[],w.calls\n");flightCast(75,275,{});flightCast(76,276,{});
|
||||
SetPlayerSkillLevel(277,0,20);flightCast(77,277,{0}); // DWORD truncation of 2+k.
|
||||
resetCalls();ClickSkillSlot(78);require(net.GetSendQueue().empty(),"malformed count generated unbounded packets");
|
||||
for(uint32_t vid:{20,21,22,23})actors.RemoveActor(vid);castingActor.ClearFlyTarget();
|
||||
require(MountLevel(20101)==1 && MountLevel(20104)==2 && MountLevel(20109)==3 && MountLevel(32008)==0
|
||||
&& MountLevel(20228)==3 && MountLevel(99999)==0,"original mount cases changed");
|
||||
actors.Clear();bg.Destroy();
|
||||
python.execute("player.SetGameWindow(0)\nnet.ClearPhaseWindow(net.PHASE_WINDOW_GAME,w)\n");
|
||||
net.ResetConnection();CPythonBackground::Instance().Destroy();
|
||||
}
|
||||
fs::current_path(previous);fs::remove_all(root);
|
||||
std::cout<<"AVA2 Windows network, player and terrain behavior parity passed\n";return 0;
|
||||
} catch(const std::exception& e) {fs::current_path(previous);fs::remove_all(root);std::cerr<<e.what()<<'\n';return 1;}
|
||||
}
|
||||
Reference in New Issue
Block a user