init commit
This commit is contained in:
commit
15ab48343a
187 files changed
+12644
No files matched your search
@@ -0,0 +1,116 @@
|
||||
#include "assets/level.hpp"
|
||||
#include "assets/model.hpp"
|
||||
#include "assets/palette.hpp"
|
||||
#include "assets/sprites.hpp"
|
||||
#include "core/vfs.hpp"
|
||||
#include "render/world_geometry.hpp"
|
||||
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
|
||||
using namespace top_octane;
|
||||
|
||||
#define CHECK(cond) \
|
||||
do { \
|
||||
if (!(cond)) { \
|
||||
std::cerr << "FAIL [" << __FILE__ << ":" << __LINE__ << "]: " #cond << "\n"; \
|
||||
return 1; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
int main() {
|
||||
Vfs vfs;
|
||||
CHECK(vfs.init(HIOCTANE_DEFAULT_DATA_DIR));
|
||||
|
||||
assets::Palette pal;
|
||||
CHECK(pal.load(vfs));
|
||||
|
||||
// Verify CPU geometry generation for all 6 tracks
|
||||
for (int l = 1; l <= 6; ++l) {
|
||||
assets::LevelData lvl;
|
||||
CHECK(lvl.load(vfs, l));
|
||||
|
||||
render::WorldGeometry geo = render::build_level_geometry(lvl);
|
||||
CHECK(geo.terrain_verts.size() == (assets::kMapWidth - 1) * (assets::kMapHeight - 1) * 4u);
|
||||
CHECK(geo.terrain_indices.size() == (assets::kMapWidth - 1) * (assets::kMapHeight - 1) * 6u);
|
||||
CHECK(!geo.column_verts.empty());
|
||||
CHECK(!geo.column_indices.empty());
|
||||
CHECK(geo.column_indices.size() % 6 == 0);
|
||||
|
||||
for (const auto& v : geo.terrain_verts) {
|
||||
CHECK(std::isfinite(v.pos.x) && std::isfinite(v.pos.y) && std::isfinite(v.pos.z));
|
||||
CHECK(v.tile >= 0.0f && v.tile < 256.0f);
|
||||
CHECK(v.light >= 0.25f && v.light <= 1.5f);
|
||||
CHECK(v.u >= -1e-4f && v.u <= 1.0001f);
|
||||
CHECK(v.v >= -1e-4f && v.v <= 1.0001f);
|
||||
}
|
||||
for (const auto& v : geo.column_verts) {
|
||||
CHECK(std::isfinite(v.pos.x) && std::isfinite(v.pos.y) && std::isfinite(v.pos.z));
|
||||
CHECK(v.tile >= 0.0f && v.tile < 256.0f);
|
||||
CHECK(v.u >= -1e-4f && v.u <= 1.0001f);
|
||||
CHECK(v.v >= -1e-4f && v.v <= 1.0001f);
|
||||
}
|
||||
|
||||
// Verify strict outward counter-clockwise triangle winding on terrain (+Y) & 3D columns
|
||||
auto check_winding = [&](const std::vector<render::WorldVertex>& verts,
|
||||
const std::vector<uint32_t>& indices,
|
||||
bool heightmap_up) -> bool {
|
||||
for (size_t i = 0; i + 2 < indices.size(); i += 3) {
|
||||
const auto& v0 = verts[indices[i + 0]];
|
||||
const auto& v1 = verts[indices[i + 1]];
|
||||
const auto& v2 = verts[indices[i + 2]];
|
||||
Vec3 tri_n = (v1.pos - v0.pos).cross(v2.pos - v0.pos);
|
||||
if (tri_n.len_sq() <= 1e-8f) {
|
||||
return false;
|
||||
}
|
||||
if (heightmap_up) {
|
||||
if (tri_n.y <= 0.0f) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
Vec3 avg_n = v0.normal + v1.normal + v2.normal;
|
||||
if (tri_n.dot(avg_n) <= 0.0f) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
CHECK(check_winding(geo.terrain_verts, geo.terrain_indices, true));
|
||||
CHECK(check_winding(geo.column_verts, geo.column_indices, false));
|
||||
|
||||
// Verify partial morph region update stays valid
|
||||
render::update_terrain_region(lvl, 10, 80, 15, 85, geo.terrain_verts);
|
||||
|
||||
std::cout << " Level " << l << " geo: terrain_tris=" << geo.terrain_indices.size() / 3
|
||||
<< " column_tris=" << geo.column_indices.size() / 3 << "\n";
|
||||
}
|
||||
|
||||
// Verify TRACK0-1 full track silhouette preview sprites for all 6 tracks
|
||||
{
|
||||
assets::SpriteBank track_bank;
|
||||
CHECK(track_bank.load(vfs, "DATA/TRACK0-1.DAT", "DATA/TRACK0-1.TAB", pal));
|
||||
static constexpr int kPreviewIndices[6] = {1, 3, 6, 7, 9, 11};
|
||||
for (int idx : kPreviewIndices) {
|
||||
CHECK(static_cast<size_t>(idx) < track_bank.sprites.size());
|
||||
const auto& sp = track_bank.sprites[idx];
|
||||
CHECK(sp.width >= 50 && sp.height >= 90);
|
||||
CHECK(!sp.rgba.empty());
|
||||
}
|
||||
}
|
||||
|
||||
// Verify 3D model GPU geometry conversion
|
||||
assets::ObjectTextureAtlas atlas;
|
||||
CHECK(atlas.load(vfs, pal));
|
||||
const char* keys[] = {"CAR0-0", "TANK0-0", "JUGGA0-0", "JET0-0", "BIKE0-0", "SKIM0-0", "RECOV0-0"};
|
||||
for (const char* k : keys) {
|
||||
assets::ModelMesh mesh;
|
||||
CHECK(mesh.load(vfs, std::string("OBJECTS/DATA/") + k + ".DAT", &atlas));
|
||||
render::ModelGeometry mg = render::build_model_geometry(mesh, pal);
|
||||
CHECK(!mg.verts.empty());
|
||||
CHECK(mg.indices.size() == mesh.triangles.size() * 3u);
|
||||
}
|
||||
|
||||
std::cout << "[PASS] All 6 Levels & Vehicle 3D Render Geometry validated\n";
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user