OpenBF1942-Plus
Refractor 1, rebuilt from scratch
Loading...
Searching...
No Matches
terrain.h
Go to the documentation of this file.
1// Terrain: Init/Terrain.con settings + Heightmap.raw. Spec: docs/formats/terrain.md
2#pragma once
3#include <cstdint>
4#include <string>
5#include <vector>
6
7namespace obf {
8
9struct TerrainInfo {
10 float world_size = 0, y_scale = 0, water_level = 0;
11 std::string heightmap, tex_base; // VFS paths without extension
12 std::string detail; // detailTexName: VFS path without extension; empty if none
13 std::string material_map; // materialMap: VFS path without extension; empty if none
14 int material_size = 0; // materialSize: cells per side
15};
16
17// shortcut: scans GeometryTemplate.<key> lines instead of running the CON interpreter;
18// replace when the engine gets a C++ CON interpreter (placing objects needs it).
19TerrainInfo parse_terrain_con(const std::string& text);
20
21struct Heightmap {
22 int n = 0; // samples per side
23 std::vector<uint16_t> h;
24 float y_scale = 0;
25 // row = z / cell, column = x / cell (verified against object positions on all maps)
26 float height(int row, int col) const { return h[static_cast<size_t>(row) * n + col] * y_scale / 256.0f; }
27};
28
29Heightmap load_heightmap(const std::vector<uint8_t>& raw, float y_scale);
30
31} // namespace obf
Definition anim.cpp:7
TerrainInfo parse_terrain_con(const std::string &text)
Definition terrain.cpp:13
Heightmap load_heightmap(const std::vector< uint8_t > &raw, float y_scale)
Definition terrain.cpp:38
Definition terrain.h:21
float height(int row, int col) const
Definition terrain.h:26
int n
Definition terrain.h:22
std::vector< uint16_t > h
Definition terrain.h:23
float y_scale
Definition terrain.h:24
Definition terrain.h:9
std::string material_map
Definition terrain.h:13
std::string detail
Definition terrain.h:12
int material_size
Definition terrain.h:14
std::string tex_base
Definition terrain.h:11
float water_level
Definition terrain.h:10
std::string heightmap
Definition terrain.h:11
float y_scale
Definition terrain.h:10
float world_size
Definition terrain.h:10