Files
AVA2/tests/minimap_test.cpp
shenleiandClaude Opus 5.5 9077aa389a AVA2 client Windows parity passes (gr2 BitKnit2/64-bit, GamePhase handlers, python modules)
- gr2: BitKnit2 decompression, 64-bit LE files, compressed curves
- net: remaining GamePhase handlers, generated GC packet table
- python: event/chat/chr/minimap/guild/quest/messenger/shop-search and
  other native modules ported against the AVA2 Windows client
- render: D3D8 fixed-function lighting in Gr2ModelRenderer, terrain
  without baked shade; cape/NPC equipment attachment
- tests + audits updated; docs/PORT-PLAN.md and WINDOWS-PARITY.md

Batch 4 (render pipeline: background.*, app.RenderGame/UpdateGame,
camera bindings, main.cpp fake-content removal) is still in progress.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 10:43:01 +09:00

184 lines
11 KiB
C++

// CPythonMiniMap / miniMap against the original AVA2 PythonMiniMap.cpp + PythonMiniMapModule.cpp:
// LoadAtlas from setting.txt + atlas.sub, the <map>_point.txt marks (case-sensitive types, start/end
// blocks), Update's mark classification and radius, observers, targets, GetInfo/GetAtlasInfo tuples,
// guild areas, way/signal points, the atlas window callbacks and the module surface.
#include "python_minimap.h"
#include "python_gameplay_modules.h"
#include "python_runtime.h"
#include "guild_state.h"
#include "eter_net/NetworkActorManager.h"
#include <cmath>
#include <cstdint>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <stdexcept>
#include <string>
#include <vector>
using namespace ava2;
namespace fs = std::filesystem;
void require(bool ok,const char* why) { if(!ok)throw std::runtime_error(why); }
void spit(const fs::path& p,const std::string& s) { fs::create_directories(p.parent_path());std::ofstream f(p,std::ios::binary);f<<s; }
std::string tga(unsigned w,unsigned h) {
std::string t(18,'\0');t[2]=2;t[12]=char(w&0xff);t[13]=char(w>>8);t[14]=char(h&0xff);t[15]=char(h>>8);t[16]=32;t[17]=8;
return t+std::string(size_t(w)*h*4,'\x7f');
}
bool near(float a,float b) { return std::fabs(a-b)<1e-3f; }
uint32_t g_now=1000;
uint32_t now() { return g_now; }
SNetworkActorData actor(uint32_t vid,uint8_t type,uint32_t race,long x,long y,const char* name) {
SNetworkActorData a{};a.m_dwVID=vid;a.m_bType=type;a.m_dwRace=race;a.m_lCurX=x;a.m_lCurY=y;a.m_stName=name;return a;
}
int main(int argc,char** argv) {
if(argc!=3)return 2;
try {
const fs::path root=fs::temp_directory_path()/"ava2_minimap_test";
fs::remove_all(root);fs::create_directories(root);
fs::current_path(root);
spit(root/"locale/en/atlasinfo.txt","testmap 409600 204800 2 3\n");
spit(root/"map/testmap/setting.txt","ScriptType MapSetting\nMapSize 2 3\nBasePosition 409600 204800\n");
spit(root/"map/testmap/001002/height.raw",std::string(2*131*131,'\0'));
spit(root/"testmap/atlas.tga",tga(256,384));
spit(root/"testmap/atlas.sub","title subImage\nversion 2.0\nimage atlas.tga\nleft 0\ntop 0\nright 256\nbottom 384\n");
spit(root/"ymir work/ui/minimap/whitemark_new.tga",tga(8,8));
spit(root/"ymir work/ui/minimap/boss_mark_new.tga",tga(12,12));
spit(root/"locale/en/map/testmap_point.txt",
"0 NPC 2560 5120 Guard\n1\tWARP\t25600\t51200\t\"Gate A\"\n2 MONSTER 1 1 Mob\n3 npc 1 1 lower\n4 NPC 1\n"
"start 5\nWARP 100 200 Blk\nend\n");
PythonRuntime python(argv[1],root);
auto& mm=CPythonMiniMap::Instance();
mm.SetTimeSourceForTest(now);
// Module surface: the 27 Windows functions, no RegisterColor; no map yet.
python.execute(
"import miniMap as m\n"
"names=('SetScale','ScaleUp','ScaleDown','SetMiniMapSize','SetCenterPosition','Destroy','Create','Update','Render',"
"'Show','Hide','isShow','GetInfo','LoadAtlas','UpdateAtlas','RenderAtlas','ShowAtlas','HideAtlas','isShowAtlas','IsAtlas',"
"'GetAtlasInfo','GetAtlasSize','AddWayPoint','RemoveWayPoint','RegisterAtlasWindow','UnregisterAtlasWindow','GetGuildAreaID')\n"
"assert sorted(n for n in dir(m) if not n.startswith('_') and not n.startswith('TYPE_'))==sorted(names)\n"
"assert (m.TYPE_OPC,m.TYPE_NPC,m.TYPE_WARP,m.TYPE_WAYPOINT,m.TYPE_PARTY,m.TYPE_EMPIRE)==(0,3,5,6,7,8)\n"
"assert m.GetAtlasSize()==(0,0,0) and m.IsAtlas()==0 and m.isShow()==0 and m.isShowAtlas()==0\n"
"assert m.LoadAtlas() is None and m.IsAtlas()==0\n"
"assert m.SetScale('x') is None\n"
"m.Create()\n");
// Main actor + the classification set around (40000,60000).
auto& actors=NetworkActorManager::Instance();
actors.Clear();
actors.AppendActor(actor(1,6,0,40000,60000,"Hero"));actors.SetMainActorVID(1);
actors.AppendActor(actor(2,6,0,42000,60000,"Other"));
actors.AppendActor(actor(3,6,0,40000,59000,"Mate"));
auto ghost=actor(4,6,0,40500,60500,"Ghost");ghost.m_affectFlags[0]=1u<<NetworkActorManager::AFFECT_INVISIBILITY;actors.AppendActor(ghost);
actors.AppendActor(actor(5,2,8001,39000,60000,"Stone"));
actors.AppendActor(actor(6,1,30005,41000,61000,"Shop"));
actors.AppendActor(actor(7,1,20000,39500,61000,"Npc"));
actors.AppendActor(actor(8,0,101,40000,63000,"Wolf"));
actors.AppendActor(actor(9,0,691,38000,58000,"Boss"));
actors.AppendActor(actor(10,1,691,41000,59000,"BossNpc"));
actors.AppendActor(actor(11,3,0,39000,59000,"Warp"));
actors.AppendActor(actor(12,0,101,47000,60000,"Far"));
actors.AppendActor(actor(13,0,101,45000,65000,"Corner"));
NetworkActorManager::SetPartyMemberQuery([](uint32_t vid){return vid==3;});
require(WarpBackgroundMap(409600+40000,204800+60000),"warp");
auto v=mm.GetTestView();
require(v.atlasBaseX==409600 && v.atlasBaseY==204800 && v.atlasMaxX==51200.0f && v.atlasMaxY==76800.0f,"setting.txt base/size");
// 0 NPC, 1 WARP kept; MONSTER dropped, "npc" and the lower-cased "warp" of the start block do not match, short row skipped.
require(v.npcMarks==1 && v.warpMarks==1 && v.bossMarks==0,"point.txt marks");
mm.Update(40000,60000);
v=mm.GetTestView();
require(v.scale==2.0f && v.radius==64.0f && near(v.centerCellX,72.0f) && near(v.centerCellY,44.0f),"center/radius");
require(v.otherPC->size()==1 && v.partyPC->size()==1 && v.metin->size()==1 && v.offlineShop->size()==1,"pc/stone/shop");
require(v.npc->size()==2 && v.monster->size()==1 && v.boss->size()==1 && v.warp->size()==1,"npc/monster/boss/warp");
require(near((*v.otherPC)[0].m_fX,80.0f) && near((*v.otherPC)[0].m_fY,60.0f),"other pc mark");
require((*v.partyPC)[0].m_eNameColor==NetworkActorManager::NAMECOLOR_PARTY && near((*v.partyPC)[0].m_fY,50.0f),"party mark");
// Observer: 1 s lerp towards the destination.
mm.AddObserver(50,40000,61000);
mm.MoveObserver(50,41000,61000);
g_now+=500;
mm.Update(40000,60000);
v=mm.GetTestView();
require(v.observers==1 && v.partyPC->size()==2 && near((*v.partyPC)[1].m_fX,65.0f) && near((*v.partyPC)[1].m_fY,70.0f),"observer lerp");
mm.RemoveObserver(50);
// Targets: a location target clamps to the 55px window (+2), a VID target follows its actor.
mm.CreateTarget(900,"T");
mm.UpdateTarget(900,409600+50000,204800+60000);
mm.UpdateTarget(900,409600-1,204800+60000); // below base: ignored
mm.UpdateTarget(900,-5,204800+60000); // unsigned: above base+max, ignored
mm.CreateTarget(901,"V",8);
mm.UpdateTarget(901,409600,204800); // actor exists: ignored
mm.Update(40000,60000);
float tx=0,ty=0;
require(mm.GetTargetMiniMapPosition(900,&tx,&ty) && near(tx,117.0f) && near(ty,62.0f),"location target");
require(mm.GetTargetMiniMapPosition(901,&tx,&ty) && near(tx,60.0f) && near(ty,90.0f),"vid target");
mm.DeleteTarget(900);mm.DeleteTarget(901);
require(!mm.GetTargetMiniMapPosition(900,&tx,&ty),"delete target");
// Atlas marks from HEADER_GC_NPC_POSITION: the warp name is cut at the first space.
mm.ClearAtlasMarkInfo();
mm.RegisterAtlasMark(1,20000,"Guard",2560,5120,0);
mm.RegisterAtlasMark(3,0,"North Gate",10000,10000,0);
mm.RegisterAtlasMark(0,691,"Boss",30000,30000,120);
GetGuildState().names[77]="Clan";
mm.RegisterGuildArea(1,77,1000,1000,2000,2000);
mm.RegisterGuildArea(2,78,20000,40000,1000,1000);
mm.AddSignalPoint(100,100);
require(mm.GetTestView().wayPoints==1,"signal waypoint");
mm.ClearAllSignalPoint();
require(mm.GetTestView().wayPoints==0,"signal cleared");
const auto& ma=*actors.GetActorData(1);(void)ma;
char script[4096];
std::snprintf(script,sizeof(script),
"npc=%ld\nwarp=%ld\nwp=%ld\nparty=%ld\nother=%ld\nhero=%ld\n"
"class Atlas:\n def __init__(self):\n self.shown=0\n self.center=None\n"
" def Show(self):\n self.shown+=1\n def SetCenterPositionAdjust(self,x,y):\n self.center=(x,y)\n"
"a=Atlas()\nm.RegisterAtlasWindow(a)\n"
"assert m.GetAtlasSize()==(1,256,384) and m.IsAtlas()==1\n"
"m.ShowAtlas()\nm.UpdateAtlas()\nm.RenderAtlas(10,20)\nassert m.isShowAtlas()==1\n"
"assert m.GetAtlasInfo(22.8,45.6)==(1,'Guard',25,51,npc,0,0),m.GetAtlasInfo(22.8,45.6)\n"
"assert m.GetAtlasInfo(60,70)==(1,'North',100,100,warp,0,0),m.GetAtlasInfo(60,70)\n"
"assert m.GetAtlasInfo(160,170)==(1,'Boss',300,300,-1,0,120)\n"
"assert m.GetAtlasInfo(10+200,20+300)==(1,'Hero',400,600,hero,0,0)\n"
"assert m.GetAtlasInfo(20,30)==(1,'Clan',20,20,party,77,0),m.GetAtlasInfo(20,30)\n"
"assert m.GetAtlasInfo(10+102,20+202)==(1,'empty_guild_area',205,405,party,0,0)\n"
"assert m.GetAtlasInfo(250,400)==(0,'',0,0,0,0,0)\n"
"m.AddWayPoint(5,6000.0,6000.0,'wp')\nm.AddWayPoint(5,1.0,1.0,'dup')\n"
"assert m.GetAtlasInfo(40,50)==(1,'wp',60,60,wp,0,0)\n"
"m.RemoveWayPoint(5)\nassert m.GetAtlasInfo(40,50)==(0,'',0,0,0,0,0)\n"
"assert m.GetGuildAreaID(1500,1500)==77 and m.GetGuildAreaID(999,1500)==-1 and m.GetGuildAreaID(-1.0,0)==-1\n"
"m.LoadAtlas()\nassert a.shown==1\n"
"m.Show()\nassert m.isShow()==1\nm.Render(100,200)\n"
"assert m.GetInfo(164,264)==(1,'Hero',400,600,hero),m.GetInfo(164,264)\n"
"assert m.GetInfo(184,264)==(1,'Other',420,600,other),m.GetInfo(184,264)\n"
"assert m.GetInfo(100,200)==(0,'',0,0,0)\n"
"m.SetScale(9)\nm.ScaleDown()\nm.ScaleDown()\nm.ScaleDown()\nm.ScaleDown()\n"
"assert m.GetInfo(184,264)==(0,'',0,0,0)\n",
long(int32_t(NetworkActorManager::GetIndexedNameColor(NetworkActorManager::NAMECOLOR_NPC))),
long(int32_t(NetworkActorManager::GetIndexedNameColor(NetworkActorManager::NAMECOLOR_WARP))),
long(int32_t(NetworkActorManager::GetIndexedNameColor(NetworkActorManager::NAMECOLOR_WAYPOINT))),
long(int32_t(NetworkActorManager::GetIndexedNameColor(NetworkActorManager::NAMECOLOR_PARTY))),
long(int32_t(NetworkActorManager::GetIndexedNameColor(actors.GetNameColorIndex(2)))),
long(int32_t(NetworkActorManager::GetIndexedNameColor(actors.GetNameColorIndex(1)))));
python.execute(script);
v=mm.GetTestView();
require(v.scale==0.5f && v.radius==16.0f,"scale clamp");
mm.SetAtlasCenterPosition(3,4);
python.execute("assert a.center==(3,4)\nm.UnregisterAtlasWindow()\nm.Destroy()\n"
"assert m.isShow()==0 and m.IsAtlas()==0 and m.GetAtlasSize()==(1,0,0)\n");
// LoadAtlas cleared the guild areas; Destroy keeps the atlas mark vectors, as on Windows.
v=mm.GetTestView();
require(v.guildAreas==0 && v.npcMarks==1 && v.wayPoints==0 && v.scale==2.0f,"destroy");
actors.Clear();
NetworkActorManager::SetPartyMemberQuery(nullptr);
fs::current_path(fs::temp_directory_path());
fs::remove_all(root);
std::cout<<"AVA2 miniMap parity passed\n";
} catch(const std::exception& e) { std::cerr<<e.what()<<'\n';return 1; }
}