Align AVA2 Windows behavior and improve mobile touch interactions

This commit is contained in:
shen
2026-10-13 23:46:26 -07:00
parent 31c5b3dd9b
commit b3808d8d0c
106 changed files with 5162 additions and 637 deletions
+73
View File
@@ -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"