Fix tree rendering and authored collision, add FPS display and packaging safeguards
This commit is contained in:
@@ -236,6 +236,7 @@ int main(int argc, char** argv) {
|
||||
require(!background.LoadMap("reset_map") && !background.IsMapReady(),"non-finite terrain heights accepted");
|
||||
background.Destroy();
|
||||
require(background.LoadMap("test_bg_map"),"forest clock map load");
|
||||
require(background.GetForest()->GetWindStrength()==0.2f,"environment default wind not propagated");
|
||||
SpeedTreeForest reference;
|
||||
reference.CreateInstance(0,0,300,191919,0,1,"clock");
|
||||
background.GetForest()->CreateInstance(0,0,300,191919,0,1,"clock");
|
||||
|
||||
@@ -250,6 +250,13 @@ int main(){
|
||||
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");
|
||||
triangle.z_write=true;triangle.alpha_test=true;triangle.alpha_ref=84;triangle.diffuse={0x54FFFFFF,0x54FFFFFF,0x54FFFFFF};
|
||||
scene.Clear(0,1);scene.RenderDraw(surface,triangle);check(scene.GetDepthBuffer()[pixel]==1,"software alpha accepted equal reference");
|
||||
triangle.diffuse={0x55FFFFFF,0x55FFFFFF,0x55FFFFFF};scene.RenderDraw(surface,triangle);check(scene.GetDepthBuffer()[pixel]<1,"software alpha rejected greater reference");
|
||||
scene.Clear(0,1);triangle.alpha_ref=0;triangle.diffuse={0x01FFFFFF,0x01FFFFFF,0x01FFFFFF};scene.RenderDraw(surface,triangle);check(scene.GetDepthBuffer()[pixel]<1,"zero alpha reference replaced by fallback threshold");
|
||||
scene.Clear(0,1);triangle.diffuse={0x00FFFFFF,0x00FFFFFF,0x00FFFFFF};scene.RenderDraw(surface,triangle);check(scene.GetDepthBuffer()[pixel]==1,"fully transparent fragment wrote depth");
|
||||
scene.Clear(0,1);triangle.alpha_ref=84;triangle.diffuse={0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF};triangle.material_diffuse[3]=0.25f;scene.RenderDraw(surface,triangle);
|
||||
check(scene.GetDepthBuffer()[pixel]==1,"alpha tested before material modulation");
|
||||
SDL_DestroySurface(surface);
|
||||
trace.Clear();check(trace.IsEmpty(),"tail clear retained history");
|
||||
// Actor resolver weak identity must reject deletion and same-VID replacement.
|
||||
|
||||
@@ -76,6 +76,13 @@ int main() {
|
||||
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;}
|
||||
// Tree bark/canopy use the same strict alpha=84 mask. Equal must not write depth.
|
||||
auto maskedTree=near;maskedTree.cull=1;maskedTree.alphaRef=84.f/255;
|
||||
const Uint8 alpha84[4]={255,0,0,84},alpha85[4]={255,0,0,85},alpha0[4]={255,0,0,0},alpha1[4]={255,0,0,1};
|
||||
maskedTree.texture=scene.Texture("tree-alpha84",1,1,alpha84);color=center({maskedTree,far});assert(color[1]>245&&color[0]<5);
|
||||
maskedTree.texture=scene.Texture("tree-alpha85",1,1,alpha85);color=center({maskedTree,far});assert(color[0]>245&&color[1]<5);
|
||||
maskedTree.alphaRef=0;maskedTree.texture=scene.Texture("tree-alpha0",1,1,alpha0);color=center({maskedTree,far});assert(color[1]>245&&color[0]<5);
|
||||
maskedTree.texture=scene.Texture("tree-alpha1",1,1,alpha1);color=center({maskedTree,far});assert(color[0]>245&&color[1]<5);
|
||||
// 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;
|
||||
|
||||
@@ -14,6 +14,9 @@ class PackagingTests(unittest.TestCase):
|
||||
scripts = source / 'upstream/python-root'
|
||||
scripts.mkdir(parents=True)
|
||||
(scripts / 'uiCommon.py').write_text('class Dialog: pass\n')
|
||||
(scripts / 'no.py').write_text('autoLogin = 1\n')
|
||||
(scripts / 'lib').mkdir()
|
||||
(scripts / 'lib/wa_ac.py').write_text('saved account fixture\n')
|
||||
(scripts / 'pack_maker').symlink_to(base / 'outside')
|
||||
packs = base / 'pack_maker'
|
||||
packs.mkdir()
|
||||
@@ -30,6 +33,8 @@ class PackagingTests(unittest.TestCase):
|
||||
self.assertIn('root/uiCommon.py', manifest['files'])
|
||||
self.assertTrue((output / 'root/uiCommon.py').is_file())
|
||||
self.assertFalse((output / 'root/pack_maker').exists())
|
||||
self.assertFalse((output / 'root/no.py').exists())
|
||||
self.assertFalse((output / 'root/lib/wa_ac.py').exists())
|
||||
self.assertEqual((output / 'svside/empty.jpg').read_bytes(), loose.read_bytes())
|
||||
self.assertIn('rework_inv/new_equipment_bg.tga', manifest['files'])
|
||||
self.assertEqual((output / 'rework_inv/new_equipment_bg.tga').read_bytes(), data.read_bytes())
|
||||
|
||||
@@ -29,6 +29,8 @@ int main(int argc,char** argv) {
|
||||
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 gateModel=fs::absolute("ymir work/zone/a/building/a1-middledam-01.gr2");
|
||||
const auto gateAttribute=fs::absolute("ymir work/zone/a/building/a1-middledam-01.mdatr");
|
||||
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;
|
||||
@@ -243,6 +245,48 @@ int main(int argc,char** argv) {
|
||||
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.CheckMovementCollision(obstacleStart,center,1),"movement passed through a solid box");
|
||||
require(!obstacles.CheckMovementCollision(aboveBox,aboveBox,1),"overhead movement blocked by flattened box");
|
||||
const float belowBox[3]={center[0],center[1]-box.halfExtents[1]-40,center[2]};
|
||||
require(!obstacles.CheckMovementCollision(belowBox,belowBox,30),"movement below a box blocked by its footprint");
|
||||
ActorInstance overheadWalker;overheadWalker.SetPosition(center[0]-100,center[1]+box.halfExtents[1]+50,center[2]);overheadWalker.SetSpeed(100);
|
||||
overheadWalker.MoveInDirection(90,1,nullptr,&obstacles);
|
||||
require(std::abs(overheadWalker.GetX()-center[0])<0.01f,"actor could not walk above an object footprint");
|
||||
if(fs::exists(gateModel) && fs::exists(gateAttribute)) {
|
||||
fs::copy_file(gateModel,root/"gate.gr2");fs::copy_file(gateAttribute,root/"gate.mdatr");
|
||||
MapObjectManager gates;
|
||||
require(gates.AddObject("gate.gr2",66907.429688f,19664.039063f,72199.484375f,30),"reported town gate fixture");
|
||||
const auto& gate=gates.GetObjects().front();
|
||||
require(gate.has_authored_planes && gate.collision_planes.size()==6,"town gate authored collision planes missing");
|
||||
const float entrance[3]={66041.5f,19725.5f,71337.5f},advance[3]={66048.5f,19725.5f,71348.9f};
|
||||
require(gates.CheckCollision(advance[0],advance[2],30),"reported gate no longer reproduces old solid footprint");
|
||||
require(!gates.CheckMovementCollision(entrance,advance,30),"authored planes still seal reported gate opening");
|
||||
ActorInstance gateWalker;gateWalker.SetPosition(entrance[0],entrance[1]-30,entrance[2]);gateWalker.SetSpeed(100);
|
||||
gateWalker.MoveInDirection(31.55f,0.15f,nullptr,&gates);
|
||||
require(std::hypot(gateWalker.GetX()-entrance[0],gateWalker.GetZ()-entrance[2])>14,"actor still stuck at reported gate opening");
|
||||
gateWalker.SetPosition(entrance[0],entrance[1]-30,entrance[2]);
|
||||
for(int step=0;step<200;++step)gateWalker.MoveInDirection(31.55f,0.1f,nullptr,&gates);
|
||||
require(std::hypot(gateWalker.GetX()-entrance[0],gateWalker.GetZ()-entrance[2])>1999,"actor blocked while crossing entire gate opening");
|
||||
for(const auto& plane:gate.collision_planes) {
|
||||
float nearWall[3],intoWall[3];
|
||||
for(int k=0;k<3;++k){nearWall[k]=plane.center[k]+plane.normal[k]*40;intoWall[k]=plane.center[k]+plane.normal[k]*20;}
|
||||
require(gates.CheckMovementCollision(nearWall,intoWall,30),"authored gate wall lost collision");
|
||||
require(!plane.Intersects(intoWall,nearWall,30,true),"authored plane prevents escaping overlap");
|
||||
}
|
||||
std::cout<<"Reported town gate opening and all 6 walls verified\n";
|
||||
}
|
||||
{
|
||||
// A real empty attribute file intentionally disables dummy collisions;
|
||||
// a truncated attribute must retain the existing solid fallback.
|
||||
const char emptyAttribute[22]="AttributeData";
|
||||
std::ofstream(root/"obstacle.mdatr",std::ios::binary).write(emptyAttribute,22);
|
||||
MapObjectManager emptyObstacles;require(emptyObstacles.AddObject("obstacle.gr2",500,50,0,30),"empty attribute fixture");
|
||||
require(emptyObstacles.GetObjects().front().has_authored_planes && !emptyObstacles.CheckMovementCollision(obstacleStart,center,30),"empty authored attribute replaced by solid dummy");
|
||||
std::ofstream(root/"obstacle.mdatr",std::ios::binary).write(emptyAttribute,18);
|
||||
MapObjectManager brokenObstacles;require(brokenObstacles.AddObject("obstacle.gr2",500,50,0,30),"broken attribute fixture");
|
||||
require(!brokenObstacles.GetObjects().front().has_authored_planes && brokenObstacles.CheckMovementCollision(obstacleStart,center,30),"truncated attribute removed solid collision");
|
||||
fs::remove(root/"obstacle.mdatr");
|
||||
}
|
||||
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;
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <chrono>
|
||||
#include <limits>
|
||||
#include <filesystem>
|
||||
#include "src/eter_render/ActorInstance.h"
|
||||
|
||||
using namespace ava2;
|
||||
|
||||
@@ -306,6 +307,80 @@ void TestAuthoredLeafRendering() {
|
||||
assert(cpu[0].positions!=rocking[0].positions && cpu[1].positions!=rocking[1].positions);
|
||||
}
|
||||
|
||||
void TestBoundsSharingAndWindPropagation() {
|
||||
SptFixtures fixtures;SpeedTreeForest forest;
|
||||
forest.RegisterPropertyData({12345,"Wide",fixtures.write("wide.spt",1000),1000,0});
|
||||
auto* first=forest.CreateInstance(300,0,500,12345,90,2);
|
||||
auto model=first->model;std::array<float,3> center;float radius;
|
||||
model->GetWorldBounds(first->x,first->y,first->z,first->yaw,first->scale,center,radius);
|
||||
auto expanded=model->BuildDrawCommands(first->x,first->y,first->z,first->yaw,first->scale,1,1);
|
||||
for(const auto& draw:expanded)for(size_t i=0;i<draw.positions.size();i+=3) {
|
||||
float distance=0;for(int k=0;k<3;++k){float delta=draw.positions[i+k]-center[k];distance+=delta*delta;}
|
||||
assert(distance<=radius*radius+1);
|
||||
}
|
||||
float view[16]={1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1};
|
||||
float proj[16]={0.0001f,0,0,0,0,0.0001f,0,0,0,0,0.00005f,0,0,0,0.5f,1};
|
||||
auto visible=forest.BuildDrawCommands(view,proj,0,50,0,50);
|
||||
assert(!visible.empty()); // Origin beyond 50, crown still intersects distance sphere.
|
||||
assert(visible[0].geometry && visible[0].positions.empty());
|
||||
assert(visible[0].alpha_test && visible[0].alpha_ref==84 && !visible[0].alpha_blend);
|
||||
auto shared=visible[0].geometry;
|
||||
auto again=forest.BuildDrawCommands(view,proj,0,50,0,50);
|
||||
assert(again[0].geometry==shared);
|
||||
const auto& local=visible[0].Mesh().positions;
|
||||
for(size_t i=0;i<local.size();i+=3) {
|
||||
const float* m=visible[0].world;
|
||||
const float actual[3]={local[i]*m[0]+local[i+1]*m[4]+local[i+2]*m[8]+m[12],local[i]*m[1]+local[i+1]*m[5]+local[i+2]*m[9]+m[13],local[i]*m[2]+local[i+1]*m[6]+local[i+2]*m[10]+m[14]};
|
||||
for(int k=0;k<3;++k)assert(std::abs(actual[k]-expanded[0].positions[i+k])<0.01f);
|
||||
}
|
||||
assert(first->windStrength==1 && forest.GetWindStrength()==0);
|
||||
forest.UpdateSystem(1);const float phase=first->leafWind.GetLeafPhase();
|
||||
forest.SetWindStrength(0.2f);assert(first->windStrength==0.2f && std::abs(first->leafWind.GetLeafPhase()-phase)<0.001f);
|
||||
auto* later=forest.CreateInstance(-300,0,500,12345);assert(later->windStrength==1);
|
||||
forest.SetWindStrength(0.2f);assert(later->windStrength==1); // Same-value setter doesn't update new instances, like source.
|
||||
forest.SetWindStrength(0.4f);assert(first->windStrength==0.4f && later->windStrength==0.4f);
|
||||
forest.SetWindStrength(std::numeric_limits<float>::quiet_NaN());assert(forest.GetWindStrength()==0.4f);
|
||||
forest.SetCpuWindEnabled(true);auto cpu=forest.BuildDrawCommands(view,proj,0,50,0,0);assert(!cpu[0].geometry);
|
||||
forest.SetCpuWindEnabled(false);again=forest.BuildDrawCommands(view,proj,0,50,0,0);assert(again[0].geometry==shared);
|
||||
// Dense instances share one trunk stream instead of allocating a copy for each tree/frame.
|
||||
for(int i=0;i<128;++i)forest.CreateInstance(float(i),0,500,12345);
|
||||
auto dense=forest.BuildDrawCommands(view,proj,0,50,0,0);size_t trunks=0;
|
||||
for(const auto& draw:dense)if(draw.geometry){assert(draw.geometry==shared);++trunks;}
|
||||
assert(trunks==130);
|
||||
}
|
||||
void TestTreeCollisionPrimitives() {
|
||||
SptFixtures fixtures;auto bytes=SyntheticSpt(300);
|
||||
auto u=[&](uint32_t v){for(int k=0;k<4;++k)bytes.push_back(uint8_t(v>>(k*8)));};
|
||||
auto f=[&](float v){u(std::bit_cast<uint32_t>(v));};
|
||||
u(12000);u(12002);f(100);f(200);f(300);f(20);
|
||||
u(12003);f(0);f(0);f(0);f(10);f(100);
|
||||
u(12004);f(-100);f(0);f(0);f(50);f(50);f(50);u(12001);
|
||||
auto path=fixtures.directory/"collision.spt";{std::ofstream file(path,std::ios::binary);file.write(reinterpret_cast<const char*>(bytes.data()),bytes.size());}
|
||||
auto partial=SyntheticSpt(300);for(int k=0;k<4;++k)partial.push_back(uint8_t(22000>>(k*8)));partial.push_back(0);
|
||||
auto partialPath=fixtures.directory/"partial.spt";{std::ofstream file(partialPath,std::ios::binary);file.write(reinterpret_cast<const char*>(partial.data()),partial.size());}
|
||||
auto partialModel=SpeedTreeModel::Create(partialPath.string(),300);assert(partialModel && !partialModel->GetSptInfo().metadata_complete && partialModel->GetSptInfo().unsupported_token==22000);
|
||||
SpeedTreeForest resourceTest;
|
||||
auto* named=resourceTest.CreateInstance(0,0,0,7,0,1,path.string().c_str());assert(named && named->model->GetHeight()==300);
|
||||
resourceTest.RegisterPropertyData({8,"Missing",(fixtures.directory/"missing.spt").string(),300,0});
|
||||
assert(!resourceTest.CreateInstance(0,0,0,8) && !resourceTest.HasMainTree(9));
|
||||
assert(!resourceTest.CreateInstance(0,0,0,9,0,1,(fixtures.directory/"missing.spt").string().c_str()));
|
||||
auto forest=std::make_unique<SpeedTreeForest>();forest->RegisterPropertyData({4242,"Collision",path.string(),300,0});
|
||||
auto* instance=forest->CreateInstance(10,20,30,4242,90,2);
|
||||
assert(instance->model->GetSptInfo().collision_objects.size()==3);
|
||||
MapObjectManager objects;objects.SetTreeForest(forest.get());
|
||||
float start[3]={0,320,230},end[3]={220,320,230};assert(objects.CheckFlyingCollision(start,end,0));
|
||||
assert(objects.CheckMovementCollision(start,end,0)); // Both endpoints outside: swept crossing still blocks.
|
||||
start[1]=end[1]=340;assert(!objects.CheckFlyingCollision(start,end,0)); // Strict sphere tangency.
|
||||
float cstart[3]={-50,50,30},cend[3]={0,50,30};assert(objects.CheckMovementCollision(cstart,cend,30));
|
||||
float high[3]={0,200,30};assert(!objects.CheckMovementCollision(high,high,1));
|
||||
float tangent[3]={20,50,30};assert(objects.CheckFlyingCollision(tangent,tangent,0)); // Cylinder inclusive.
|
||||
float box[3]={-90,50,30};assert(!objects.CheckFlyingCollision(box,box,1));
|
||||
float inside[3]={110,320,230},outside[3]={140,320,230};assert(!objects.CheckMovementCollision(inside,outside,0));
|
||||
ActorInstance actor;actor.SetPosition(-50,20,30);actor.SetSpeed(100);actor.MoveInDirection(90,0.5f,nullptr,&objects);assert(actor.GetX()<-20);
|
||||
forest->DeleteInstance(instance);assert(!objects.CheckFlyingCollision(cstart,cend,30));
|
||||
forest->CreateInstance(10,20,30,4242);assert(objects.CheckFlyingCollision(cstart,cend,30));
|
||||
forest.reset();assert(!objects.CheckFlyingCollision(cstart,cend,30)); // Borrowed forest lifetime protected.
|
||||
}
|
||||
int main() {
|
||||
std::cout << "=== Running SpeedTree & Forest Engine Tests ===" << std::endl;
|
||||
TestPrtParsing();
|
||||
@@ -316,6 +391,8 @@ int main() {
|
||||
TestBillboardRendering();
|
||||
TestFrondRendering();
|
||||
TestAuthoredLeafRendering();
|
||||
TestBoundsSharingAndWindPropagation();
|
||||
TestTreeCollisionPrimitives();
|
||||
std::cout << "=== ALL SpeedTree & Forest Tests PASSED (100%) ===" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user