2026-11-30 22:31:51 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "core/math.hpp"
|
|
|
|
|
#include "core/vfs.hpp"
|
|
|
|
|
|
|
|
|
|
#include <array>
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
namespace top_octane::assets {
|
|
|
|
|
|
|
|
|
|
constexpr int kMapWidth = 256;
|
|
|
|
|
constexpr int kMapHeight = 160;
|
|
|
|
|
constexpr int kMaxEntities = 4000;
|
|
|
|
|
constexpr int kMaxColumns = 1024;
|
|
|
|
|
constexpr int kMaxBlocks = 1024;
|
|
|
|
|
|
|
|
|
|
struct LevelEntity {
|
|
|
|
|
uint16_t id = 0;
|
|
|
|
|
uint8_t type = 0;
|
|
|
|
|
uint8_t subtype = 0;
|
|
|
|
|
uint16_t group = 0;
|
|
|
|
|
uint16_t target_group = 0;
|
|
|
|
|
uint16_t unk2 = 0;
|
|
|
|
|
uint16_t unk3 = 0;
|
|
|
|
|
uint16_t active_flag = 0;
|
|
|
|
|
uint16_t next_id = 0;
|
|
|
|
|
uint16_t value = 0;
|
|
|
|
|
uint16_t pos_x_fp8 = 0;
|
|
|
|
|
uint16_t pos_z_fp8 = 0;
|
|
|
|
|
uint16_t aux1 = 0;
|
|
|
|
|
uint16_t aux2 = 0;
|
|
|
|
|
|
|
|
|
|
float tile_x() const { return static_cast<float>(pos_x_fp8) / 256.0f; }
|
|
|
|
|
float tile_z() const { return static_cast<float>(pos_z_fp8) / 256.0f; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct ColumnDefinition {
|
|
|
|
|
uint16_t use_count = 0;
|
|
|
|
|
uint16_t flags = 0;
|
|
|
|
|
uint16_t shape_mask = 0; // Bits 0..7 indicate populated vertical block levels
|
|
|
|
|
uint16_t floor_tex = 0;
|
|
|
|
|
uint16_t unk = 0;
|
|
|
|
|
std::array<int16_t, 8> blocks{};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct BlockDefinition {
|
|
|
|
|
// 6 face textures: 0=North(-Z), 1=East(+X), 2=South(+Z), 3=West(-X), 4=Top(+Y), 5=Bottom(-Y)
|
|
|
|
|
std::array<uint8_t, 6> tex{};
|
|
|
|
|
// attrs[0..5]: per-face 3-bit UV orientation (bit0=flipU, bit1=flipV, bit2=swapUV)
|
|
|
|
|
// attrs[6..7]: 16-bit block use count; attrs[8..9]: reserved
|
|
|
|
|
std::array<uint8_t, 10> attrs{};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct MapEntry {
|
|
|
|
|
uint16_t illumination = 8192; // 8.8 fixed-point brightness (neutral flat = 8192)
|
|
|
|
|
uint16_t height = 2048; // Terrain elevation (sea level baseline = 2048)
|
|
|
|
|
int16_t tex_or_col = 0; // >=0: floor tile tex (0..255); <0: column index (-tex_or_col)
|
|
|
|
|
uint16_t unk3 = 0;
|
|
|
|
|
uint16_t unk4 = 0;
|
|
|
|
|
uint16_t flags = 0; // ((flags >> 4) & 7) gives 3-bit dihedral floor tile orientation (bit0=flipU, bit1=flipV, bit2=swapUV)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct CheckpointGate {
|
|
|
|
|
uint16_t index = 0;
|
|
|
|
|
float x0 = 0.0f, z0 = 0.0f;
|
|
|
|
|
float x1 = 0.0f, z1 = 0.0f;
|
|
|
|
|
float cx = 0.0f, cz = 0.0f;
|
|
|
|
|
Vec2 dir{0.0f, -1.0f}; // approximate track forward direction
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct WaypointNode {
|
|
|
|
|
uint16_t entity_id = 0;
|
|
|
|
|
uint8_t subtype = 0; // 1=corner/slow, 7/8/9/10=normal/fast, 2/3=pit branch
|
|
|
|
|
float x = 0.0f;
|
|
|
|
|
float z = 0.0f;
|
|
|
|
|
uint16_t next_id = 0;
|
|
|
|
|
};
|
|
|
|
|
|
2026-12-01 08:05:04 +02:00
|
|
|
struct MorphDefinition {
|
|
|
|
|
uint16_t entity_id = 0;
|
|
|
|
|
uint16_t source_id = 0;
|
|
|
|
|
uint16_t group = 0;
|
|
|
|
|
bool permanent = false; // subtype 23 (MorphPermanent) vs 16 (MorphOnce)
|
|
|
|
|
int dst_x = 0, dst_z = 0;
|
|
|
|
|
int src_x = 0, src_z = 0;
|
|
|
|
|
int size_x = 0, size_z = 0; // inclusive cell span [0..size_x] x [0..size_z]
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct EffectEntity {
|
|
|
|
|
uint16_t entity_id = 0;
|
|
|
|
|
uint8_t subtype = 0; // 1=ExplosionParticles, 2=DamageCraft, 3=Explosion, 5=SteamStrong, 8=SteamLight
|
|
|
|
|
uint16_t group = 0;
|
|
|
|
|
float x = 0.0f, z = 0.0f;
|
|
|
|
|
};
|
|
|
|
|
|
2026-12-01 08:33:48 +02:00
|
|
|
enum class ChargerType : uint8_t {
|
|
|
|
|
Shield = 1, // Green pitstop bay
|
|
|
|
|
Fuel = 2, // Blue pitstop bay
|
|
|
|
|
Ammo = 3, // Yellow pitstop bay
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct ChargerPad {
|
|
|
|
|
uint16_t region_id = 0;
|
|
|
|
|
ChargerType type = ChargerType::Fuel;
|
|
|
|
|
float cx = 0.0f;
|
|
|
|
|
float cz = 0.0f;
|
|
|
|
|
float half_x = 0.0f;
|
|
|
|
|
float half_z = 0.0f;
|
|
|
|
|
};
|
|
|
|
|
|
2026-11-30 22:31:51 +02:00
|
|
|
struct LevelData {
|
|
|
|
|
int level_number = 1; // 1..6
|
|
|
|
|
int world_index = 0; // 0..5 (corresponding to TEXTU0-x / SKY0-x / TABLE0-x)
|
|
|
|
|
std::string name;
|
|
|
|
|
|
|
|
|
|
std::vector<LevelEntity> entities; // active non-empty entities
|
|
|
|
|
std::vector<LevelEntity> entity_slots; // all 4000 indexed slots
|
|
|
|
|
std::array<ColumnDefinition, kMaxColumns> columns{};
|
|
|
|
|
std::array<BlockDefinition, kMaxBlocks> blocks{};
|
|
|
|
|
std::vector<MapEntry> map; // kMapWidth * kMapHeight
|
|
|
|
|
|
|
|
|
|
std::vector<WaypointNode> main_waypoints; // ordered main closed circuit
|
|
|
|
|
std::vector<CheckpointGate> checkpoints; // ordered val=0..N-1 gates (0 = Start/Finish)
|
|
|
|
|
std::vector<LevelEntity> pickups; // type 5
|
|
|
|
|
std::vector<LevelEntity> props; // type 3
|
|
|
|
|
std::vector<LevelEntity> triggers; // type 8
|
2026-12-01 08:05:04 +02:00
|
|
|
std::vector<MorphDefinition> morphs; // type 2 subtype 16/23 paired with subtype 9/7 source
|
|
|
|
|
std::vector<EffectEntity> effects; // type 2 subtype 1/2/3/5/8
|
2026-12-01 08:33:48 +02:00
|
|
|
std::vector<ChargerPad> pads; // authentic charger regions (type 1=Shield, 2=Fuel, 3=Ammo)
|
|
|
|
|
std::vector<LevelEntity> recovery_spawns; // type 10 (ENTITY_RECOVERY_TRUCK)
|
2026-11-30 22:31:51 +02:00
|
|
|
|
|
|
|
|
int min_x = 0, max_x = kMapWidth - 1;
|
|
|
|
|
int min_z = 0, max_z = kMapHeight - 1;
|
|
|
|
|
|
|
|
|
|
bool load(const Vfs& vfs, int level_num); // level_num in [1..6]
|
|
|
|
|
|
|
|
|
|
const MapEntry& cell(int x, int z) const;
|
|
|
|
|
MapEntry& cell_mut(int x, int z);
|
|
|
|
|
|
|
|
|
|
// Height conversion: sea level baseline 2048 -> 0.0 world height; 512 units = 1.0 tile unit (matches ModelMesh)
|
|
|
|
|
static constexpr float kHeightScale = 1.0f / 512.0f;
|
|
|
|
|
static constexpr float kBaseHeight = 2048.0f;
|
|
|
|
|
|
|
|
|
|
float cell_height_world(int x, int z) const;
|
|
|
|
|
float sample_height_world(float wx, float wz) const;
|
2026-12-01 08:05:04 +02:00
|
|
|
float sample_height_alt_diag(float wx, float wz) const;
|
2026-11-30 22:31:51 +02:00
|
|
|
Vec3 sample_normal_world(float wx, float wz) const;
|
2026-12-01 08:05:04 +02:00
|
|
|
bool is_cell_solid_at_point(int x, int z, float qx, float qz,
|
|
|
|
|
float world_y, float craft_height = 0.42f) const;
|
2026-11-30 22:31:51 +02:00
|
|
|
bool is_cell_solid_at_y(int x, int z, float world_y, float craft_height = 0.42f) const;
|
2026-12-01 08:05:04 +02:00
|
|
|
bool is_cliff_blocking_at_y(int x, int z, float world_y) const;
|
2026-11-30 22:31:51 +02:00
|
|
|
void sample_surface_and_ceiling(float wx, float wz, float craft_y,
|
|
|
|
|
float& out_floor_y, float& out_ceil_y) const;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace top_octane::assets
|