95 lines
3.2 KiB
C++
95 lines
3.2 KiB
C++
#include <cmath>
|
|
#include <cstdio>
|
|
#include <string>
|
|
|
|
#include "level/level_data.hpp"
|
|
#include "level/validation.hpp"
|
|
|
|
namespace {
|
|
|
|
int failures = 0;
|
|
|
|
void check(bool ok, const char* what) {
|
|
if (!ok) {
|
|
std::fprintf(stderr, "FAIL: %s\n", what);
|
|
++failures;
|
|
}
|
|
}
|
|
|
|
bool near(float a, float b) { return std::fabs(a - b) < 0.0001f; }
|
|
|
|
} // namespace
|
|
|
|
int main() {
|
|
const level::LevelData original = level::floor01_default();
|
|
const std::string text = level::serialize(original);
|
|
level::LevelData loaded;
|
|
std::string error;
|
|
check(level::parse(text, loaded, error), error.c_str());
|
|
check(level::serialize(loaded) == text, "serialize/parse round-trip");
|
|
|
|
check(loaded.rooms.size() == 10, "room count");
|
|
check(loaded.walls.size() == 44, "wall line count");
|
|
check(loaded.doors.size() == 3, "door count");
|
|
check(loaded.props.size() == 150, "prop count");
|
|
int outfits = 0;
|
|
int destructible = 0;
|
|
for (const auto& p : loaded.props) {
|
|
if (!p.room_kind.empty()) ++outfits;
|
|
if (p.destructible) ++destructible;
|
|
}
|
|
check(outfits == 115, "room outfit prop count");
|
|
check(destructible == 35, "destructible dressing count");
|
|
check(loaded.rituals.size() == 3, "ritual count");
|
|
check(loaded.thermo.size() == 4, "thermo door count");
|
|
|
|
const auto walls = level::build_world_walls(loaded);
|
|
int door_walls = 0;
|
|
for (const auto& w : walls) {
|
|
if (w.door >= 0) ++door_walls;
|
|
check(w.rect.x1 > w.rect.x0, "wall has positive width");
|
|
check(w.rect.y1 > w.rect.y0, "wall has positive depth");
|
|
}
|
|
check(door_walls == 3, "gated door walls");
|
|
|
|
level::Prop decor;
|
|
decor.kind = PropKind::Decor;
|
|
decor.pos = {12.5f, 44.0f};
|
|
decor.w = 1.1f;
|
|
decor.h = 1.5f;
|
|
decor.model = "assets/models/props/plant.glb";
|
|
decor.yaw = 0.75f;
|
|
loaded.props.push_back(decor);
|
|
level::LevelData reparsed;
|
|
check(level::parse(level::serialize(loaded), reparsed, error), error.c_str());
|
|
check(!reparsed.props.empty(), "decor survived round-trip");
|
|
const auto& last = reparsed.props.back();
|
|
check(last.kind == PropKind::Decor, "decor kind");
|
|
check(last.model == decor.model, "decor model path");
|
|
check(near(last.yaw, decor.yaw), "decor yaw");
|
|
check(near(last.pos.x, decor.pos.x) && near(last.pos.y, decor.pos.y),
|
|
"decor position");
|
|
|
|
level::LevelData single;
|
|
level::WallLine line;
|
|
line.axis = 0;
|
|
line.coord = 50.0f;
|
|
line.from = 0.0f;
|
|
line.to = 100.0f;
|
|
line.gaps.push_back({40.0f, 60.0f});
|
|
single.walls.push_back(line);
|
|
const auto segments = level::build_world_walls(single);
|
|
check(segments.size() == 2, "gap splits wall into two segments");
|
|
if (segments.size() == 2) {
|
|
check(segments[0].rect.x1 <= segments[1].rect.x0, "gap stays open");
|
|
}
|
|
|
|
const auto valid = level::validate(original);
|
|
check(valid.ok(), "Floor 01 connectivity");
|
|
level::LevelData broken = original;
|
|
broken.rooms.push_back({"ISLAND", {300, 300, 310, 310}, RoomKind::Side, 0, 0});
|
|
check(!level::validate(broken).ok(), "unreachable room is reported");
|
|
|
|
if (failures == 0) std::printf("level_core_test: all checks passed\n");
|
|
return failures == 0 ? 0 : 1;
|
|
}
|