93 lines
3.5 KiB
C++
93 lines
3.5 KiB
C++
#include "property/property.h"
|
|
#include "property/property_manager.h"
|
|
#include <iostream>
|
|
#include <cassert>
|
|
#include <cmath>
|
|
|
|
using namespace metin2::property;
|
|
|
|
int main() {
|
|
std::cout << "[Test 1] Parse YPRT Building Property..." << std::endl;
|
|
const std::string sample_prb =
|
|
"YPRT\r\n"
|
|
"2847291832\r\n"
|
|
"buildingfile\t\"d:/ymir work/zone/b/building01.gr2\"\r\n"
|
|
"isbuilding\t\"1\"\r\n"
|
|
"propertyname\t\"building_temple\"\r\n"
|
|
"propertytype\t\"Building\"\r\n"
|
|
"shadowflag\t\"1\"\r\n";
|
|
|
|
Property prb;
|
|
bool ok_prb = prb.ReadFromMemory(sample_prb.data(), sample_prb.size(), "property/b/temple.prb");
|
|
assert(ok_prb);
|
|
assert(prb.GetCRC() == 2847291832);
|
|
assert(prb.GetData().property_type == PROPERTY_TYPE_BUILDING);
|
|
assert(prb.GetData().property_name == "building_temple");
|
|
assert(prb.GetData().model_file == "d:/ymir work/zone/b/building01.gr2");
|
|
assert(prb.GetData().has_collision == true);
|
|
|
|
std::string shadow_val;
|
|
assert(prb.GetString("shadowflag", shadow_val));
|
|
assert(shadow_val == "1");
|
|
|
|
std::cout << "[Test 2] Parse YPRT Tree Property (.prt)..." << std::endl;
|
|
const std::string sample_prt =
|
|
"YPRT\n"
|
|
"1048576293\n"
|
|
"propertyname\t\"tree_pine_01\"\n"
|
|
"propertytype\t\"Tree\"\n"
|
|
"treefile\t\"d:/ymir work/tree/pine_01.spt\"\n"
|
|
"treesize\t\"1200\"\n"
|
|
"treevariance\t\"250\"\n";
|
|
|
|
Property prt;
|
|
bool ok_prt = prt.ReadFromMemory(sample_prt.data(), sample_prt.size(), "property/tree/pine.prt");
|
|
assert(ok_prt);
|
|
assert(prt.GetCRC() == 1048576293);
|
|
assert(prt.GetData().property_type == PROPERTY_TYPE_TREE);
|
|
assert(prt.GetData().model_file == "d:/ymir work/tree/pine_01.spt");
|
|
|
|
std::cout << "[Test 3] PropertyManager caching & lookup..." << std::endl;
|
|
PropertyManager mgr;
|
|
assert(mgr.RegisterFromMemory("property/b/temple.prb", sample_prb.data(), sample_prb.size()));
|
|
assert(mgr.RegisterFromMemory("property/tree/pine.prt", sample_prt.data(), sample_prt.size()));
|
|
assert(mgr.GetCount() == 2);
|
|
|
|
auto prop1 = mgr.GetByCRC(2847291832);
|
|
assert(prop1 != nullptr);
|
|
assert(prop1->GetData().property_name == "building_temple");
|
|
|
|
auto prop2 = mgr.GetByPath("property/tree/pine.prt");
|
|
assert(prop2 != nullptr);
|
|
assert(prop2->GetCRC() == 1048576293);
|
|
|
|
std::cout << "[Test 4] Oriented Bounding Box (OBB) 2D collision & penetration..." << std::endl;
|
|
OrientedBoundingBox obb;
|
|
obb.center[0] = 100.0f;
|
|
obb.center[1] = 0.0f;
|
|
obb.center[2] = 200.0f;
|
|
obb.half_extents[0] = 50.0f; // Width 100
|
|
obb.half_extents[1] = 50.0f;
|
|
obb.half_extents[2] = 100.0f; // Length 200
|
|
obb.yaw_rad = 0.0f; // Axis-aligned
|
|
|
|
// Test a point clearly outside
|
|
assert(!obb.IntersectsCircle2D(300.0f, 200.0f, 20.0f));
|
|
|
|
// Test a point colliding with the right edge (x = 150)
|
|
// Circle at (160, 200) with radius 20 -> penetrates edge by 10
|
|
float nx = 0.0f, nz = 0.0f, pen = 0.0f;
|
|
bool col = obb.GetPenetrationAndNormal(160.0f, 200.0f, 20.0f, nx, nz, pen);
|
|
assert(col);
|
|
assert(std::abs(pen - 10.0f) < 1e-4f);
|
|
assert(std::abs(nx - 1.0f) < 1e-4f); // Pushes towards +X
|
|
assert(std::abs(nz - 0.0f) < 1e-4f);
|
|
|
|
// Test rotated OBB (45 degrees = PI/4)
|
|
obb.yaw_rad = 3.14159265f * 0.25f;
|
|
assert(obb.IntersectsCircle2D(100.0f, 200.0f, 10.0f)); // Center point always intersects
|
|
|
|
std::cout << "All Property SDK tests passed successfully!" << std::endl;
|
|
return 0;
|
|
}
|