Include the current addon, terrain integrations, tools, regression tests and recorded development evidence.
47 lines
2.5 KiB
Python
47 lines
2.5 KiB
Python
"""Exercise the shipped paper framing calculation; native rendering is separate."""
|
|
from policy_harness import ROOT, body, run
|
|
source = ROOT / 'addons/core/Scripts/Game/ERR/30_Map/ERRM_SharedMapComponent.c'
|
|
method = body(source, 'static bool FitPaperView(').replace('inout float zoom', 'float& zoom').replace('out vector centre', 'vector& centre').replace('Math.Max', 'maxf').replace('Math.Clamp', 'clampf')
|
|
run(r'''
|
|
#include <array>
|
|
#include <algorithm>
|
|
#include <cassert>
|
|
#include <cmath>
|
|
using vector = std::array<float, 3>;
|
|
float maxf(float a,float b){return std::max(a,b);}
|
|
float clampf(float x,float lo,float hi){return std::clamp(x,lo,hi);}
|
|
''' + method + r'''
|
|
void check(vector pos, vector offset, vector size, float width, float height) {
|
|
float zoom=0.12f;vector centre{};
|
|
assert(FitPaperView(pos,offset,size,width,height,zoom,centre));
|
|
float halfX=width/(2*zoom),halfZ=height/(2*zoom);
|
|
assert(centre[0]-halfX>=offset[0]-0.01f);
|
|
assert(centre[2]-halfZ>=offset[2]-0.01f);
|
|
assert(centre[0]+halfX<=offset[0]+size[0]+0.01f);
|
|
assert(centre[2]+halfZ<=offset[2]+size[2]+0.01f);
|
|
// Keep an in-bounds holder on the paper even when its centre must shift.
|
|
for(int axis:{0,2}) if(pos[axis]>=offset[axis]&&pos[axis]<=offset[axis]+size[axis]) {
|
|
float half=axis==0?halfX:halfZ;
|
|
assert(std::abs(pos[axis]-centre[axis])<=half+2/zoom+0.01f);
|
|
}
|
|
}
|
|
int main() {
|
|
vector size{15360,0,15360},origin{0,0,0};
|
|
// Actual Chernarus failure: captured north edge was 16610, beyond 15360.
|
|
check({5556.82f,465.062f,14906.5f},origin,size,296.05f,407.467f);
|
|
for(float x:{0.f,50.f,7680.f,15310.f,15360.f})
|
|
for(float z:{0.f,50.f,7680.f,15310.f,15360.f})
|
|
for(auto resolution: {vector{155,213,0},vector{858,1181,0},vector{1488,2048,0}})
|
|
check({x,0,z},origin,size,resolution[0],resolution[1]);
|
|
check({-4000,0,15000},{-4096,0,10240},{8192,0,6144},858,1181);
|
|
check({0,0,0},origin,{1024,0,512},1488,2048); // zoom in to fit a small terrain
|
|
check({20000,0,20000},origin,size,858,1181); // a terrain carrier outside map bounds
|
|
float zoom=.12f;vector centre{};
|
|
assert(FitPaperView({7680,0,7680},origin,size,744,1024,zoom,centre));
|
|
assert(zoom==.12f&¢re[0]==7680&¢re[2]==7680); // interior framing unchanged
|
|
assert(!FitPaperView(origin,origin,{0,0,15360},744,1024,zoom,centre));
|
|
assert(!FitPaperView(origin,origin,size,0,1024,zoom,centre));
|
|
}
|
|
''')
|
|
print('PASS: actual paper framing stays inside terrain bounds at edges, corners, shifted origins and different resolutions; small terrains fit by zooming')
|