18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-02 20:05:23 +01:00

Merge branch 'feat/eu07m-gref' into feat/eu07m-geometry-streaming

Brings the .r3a extension and modelformat r3a (2fe1064f9). Globals keeps this branch's modelstreaming settings, with r3a written for modelformat. What this branch adds is renamed with it: the model files .r3a, the family store .r3p.
This commit is contained in:
maj00r
2026-11-30 22:13:14 +01:00
13 changed files with 56 additions and 49 deletions
+21 -14
View File
@@ -1,4 +1,4 @@
# The EU07M model format (`.eu07m`)
# The EU07M model format (`.r3a`)
The successor of E3D: a fully binary model format. A file is read with almost no processing, straight into the buffers of OpenGL
4.6 and Vulkan 1.4. It carries TRS nodes, skinning, typed components and metadata of nodes and vertex groups, and it extends without
@@ -196,16 +196,23 @@ of the game, the folders of a family are 7% to 38% of their size with their shar
in each of those streams in that order, then its indices. Its id is 128 bits: two FNV-1a 64 of its bytes, with the seeds
`0xcbf29ce484222325` and `0x84222325cbf29ce4`. A primitive can be kept in the store only when its vertex and index ranges are
its own.
- **The store** of the family is `geometry.eu07mpack` in the folder of the models: a 32 B header (magic `EU7P`, `u16` major 1,
- **The store** of the family is `geometry.r3p` in the folder of the models: a 32 B header (magic `EU7P`, `u16` major 1,
`u16` minor 0, `u32` block count, `u32` flags, `u64` offset of the index, 8 B of zeroes), the blocks one after another, each
packed with zstd when it saves an eighth, and the index: entries of 40 B (`u64 × 2` id, `u64` offset, `u32` size in the file,
`u32` size unpacked, `u32` flags (0x1 zstd), `u32` 0), sorted by the id.
- **In a model file,** `GREF` names the primitives kept in the store. The writer leaves their vertex and index ranges out of the
streams of the file; the reader takes their blocks from the store, checks the id and the counts of each, and puts them back in
their places, so the model in memory always has its whole streams and nothing past the reader knows the difference. A model
with references and no store, or a block which isn't the one referred to, is refused with the reason in the log. `GREF` is a
streams of the file; the reader takes their blocks from the store by their ids, checks the counts of each, and puts them back
in their places, so the model in memory always has its whole streams and nothing past the reader knows the difference. The
bytes of a block are hashed again and compared with its id only when the content of the file is checked too (`verify_hash`,
the tools); the game goes by the id and the counts. A model with references and no store, or a block which isn't the one
referred to, is refused with the reason in the log. `GREF` is a
required section, so a reader which doesn't know it refuses the file rather than reading short streams.
- **The game** opens the store of a folder once and keeps it, reading the blocks from it as the models ask for them.
- **The game** keeps the store of a folder open, with the size and the time of its file, and reads the blocks from it as the
models ask for them; a store whose file changed (packed again while the game runs) is opened again. A store which can't be
opened is logged once per folder, with the reason.
- **Settled before the data is packed:** the id of a block (two FNV-1a 64) is part of the format. A change of it is a new major
version and a repack of every store, so it is to be decided before the stores go into the SVN; the order of the blocks in a
store (now by id) and reading a model's blocks at once are free to change, as the index finds a block wherever it lies.
- **The tools.** `eu07 -eu07m pack <folder> [minimum bytes]` moves every block of at least the minimum (4096 by default) which
occurs more than once in the models of the folder into its store, made anew from all of them, and writes the models again
referring to it; each model is read back and compared with what it was before it's replaced. `eu07 -eu07m unpack <folder>`
@@ -253,7 +260,7 @@ component; `0xFFFFFFFF` = none.
## Conversion from E3D and T3D
`eu07 -eu07m convert <input.e3d|.t3d> <output.eu07m> [dynamic]` loads the model with the existing loader (as `-e3d` does) and writes
`eu07 -eu07m convert <input.e3d|.t3d> <output.r3a> [dynamic]` loads the model with the existing loader (as `-e3d` does) and writes
it as EU07M:
- A submodel becomes a node. The order of the children and the names stay, so `GetFromName`, the `.mmd` and the events work as
@@ -268,13 +275,13 @@ it as EU07M:
game makes of it, not from its `.t3d`.
- A replaceable skin `-k` drawn in the translucent pass (bit k−1 of the E3D flags) has the `translucent` flag in `MATL`.
The other commands: `eu07 -eu07m dump <file.eu07m>` (the content as text, clips included) and `eu07 -eu07m validate <file.eu07m>`
The other commands: `eu07 -eu07m dump <file.r3a>` (the content as text, clips included) and `eu07 -eu07m validate <file.r3a>`
(a check of the file with the hash of its content).
## In the game
With `modelformat eu07m` in `eu07.ini`, a model with an `.eu07m` file beside its `.e3d` / `.t3d` (or alone) is loaded from it
(`TModel3d::LoadFromEU07M`). The default `modelformat legacy` leaves `.eu07m` files alone.
With `modelformat r3a` in `eu07.ini`, a model with an `.r3a` file beside its `.e3d` / `.t3d` (or alone) is loaded from it
(`TModel3d::LoadFromEU07M`). The default `modelformat legacy` leaves `.r3a` files alone.
- **The Vulkan renderer** keeps the streams of an EU07M model as they lie in the file: positions (12 B), attributes from `VATT`
(16 B), user data and indices, each in a buffer of its own in the bank (`vertex_kind::scene_compact`). The shaders read the
@@ -390,13 +397,13 @@ own. It applies to EU07M and E3D models alike.
### Streaming of the geometry
With `modelstreaming yes` in `eu07.ini` (the default; `no` turns it off), and `modelformat eu07m`, the vertex and index streams of the larger scenery
With `modelstreaming yes` in `eu07.ini` (the default; `no` turns it off), and `modelformat r3a`, the vertex and index streams of the larger scenery
models are read when the models are about to be drawn and let go of when they're unused for a while. The table of sections makes it
possible: the loading of the scenery reads only the structure of such a model (everything but `VPOS VATT VSKN VSKW VUSR VBND IDX2
IDX4`, one read of the beginning of the file), and the streams are read later from the same file, with the blocks of the store
(`GREF`). The format doesn't change for it.
- **Which models.** A scenery model (`node … model`) of an `.eu07m` file of at least `modelstreaming.minsize` KiB (default 256),
- **Which models.** A scenery model (`node … model`) of an `.r3a` file of at least `modelstreaming.minsize` KiB (default 256),
without skins, stars and texts of E3D, with `BNDS`. The size of the file decides, so a smaller model is read once, whole, as
without the streaming. Vehicles, cabs, loads and every other model are loaded whole, as
before. A streamed model asked for by anything else than the scenery (a vehicle of the same file) has its geometry loaded and kept.
@@ -430,5 +437,5 @@ IDX4`, one read of the beginning of the file), and the streams are read later fr
## Backward compatibility
E3D and T3D are read as before. An `.eu07m` file is loaded only when it exists, behind the switch `modelformat eu07m` in
`eu07.ini`. The current release doesn't read `.eu07m`.
E3D and T3D are read as before. An `.r3a` file is loaded only when it exists, behind the switch `modelformat r3a` in
`eu07.ini`. The current release doesn't read `.r3a`.
+2 -2
View File
@@ -172,8 +172,8 @@ TModelsManager::find_on_disk( std::string const &Name ) {
std::vector<std::string> extensions { { ".e3d" }, { ".t3d" } };
if( Global.modelformat_eu07m ) {
// a model may come as an .eu07m alone
extensions.emplace_back( ".eu07m" );
// a model may come as an .r3a alone
extensions.emplace_back( ".r3a" );
}
for( auto const &extension : extensions ) {
+3 -3
View File
@@ -1831,7 +1831,7 @@ glm::vec3 TSubModel::offset(float const Geometrytestoffsetthreshold) const
namespace
{
// modelformat eu07m: an .eu07m older than the .e3d / .t3d it was made from isn't used, the model was changed after it was
// modelformat r3a: an .r3a older than the .e3d / .t3d it was made from isn't used, the model was changed after it was
// converted (the hash of the source in its header would need the source read whole to be compared)
bool eu07m_up_to_date(std::string const &Eu07m, std::initializer_list<std::string> const Sources)
{
@@ -1953,10 +1953,10 @@ bool TModel3d::LoadFromFile(std::string const &FileName, bool dynamic)
Init();
assign_lod_ranges(Root, name);
}
else if (auto const eu07mfile{Global.modelformat_eu07m ? FileCased(name + ".eu07m") : std::string{}};
else if (auto const eu07mfile{Global.modelformat_eu07m ? FileCased(name + ".r3a") : std::string{}};
(false == eu07mfile.empty()) && eu07m_up_to_date(eu07mfile, {binaryfile, textfile}) && LoadFromEU07M(eu07mfile, dynamic))
{
// modelformat eu07m: the .eu07m made from the model takes its place; one which doesn't load leaves the .e3d / .t3d to go on
// modelformat r3a: the .r3a made from the model takes its place; one which doesn't load leaves the .e3d / .t3d to go on
asBinary = "";
Init();
assign_lod_ranges(Root, name);
+4 -4
View File
@@ -317,7 +317,7 @@ bool load_source(std::string const &Input, bool const Dynamic, TModel3d &Source,
auto const start{std::chrono::steady_clock::now()};
if (extension_of(Input) == ".e3d")
Source.LoadFromBinFile(Input, Dynamic);
else if (extension_of(Input) == ".eu07m")
else if (extension_of(Input) == ".r3a")
Source.LoadFromEU07M(Input, Dynamic);
else
Source.LoadFromTextFile(Input, Dynamic);
@@ -478,7 +478,7 @@ void model_diff::geometry(TSubModel const &Left, TSubModel const &Right) {
int command_diff(int const Argc, char *Argv[]) {
if (Argc < 5) {
std::cerr << "usage: -eu07m diff <model.e3d|model.t3d> <model.eu07m> [dynamic 0|1]\n";
std::cerr << "usage: -eu07m diff <model.e3d|model.t3d> <model.r3a> [dynamic 0|1]\n";
return 2;
}
if (false == start_tools(Argc, Argv))
@@ -503,7 +503,7 @@ int command_diff(int const Argc, char *Argv[]) {
int command_convert(int const Argc, char *Argv[]) {
if (Argc < 5) {
std::cerr << "usage: -eu07m convert <model.e3d|model.t3d> <model.eu07m> [dynamic 0|1] [convertmodels flags]\n";
std::cerr << "usage: -eu07m convert <model.e3d|model.t3d> <model.r3a> [dynamic 0|1] [convertmodels flags]\n";
return 2;
}
std::string const input{Argv[3]};
@@ -545,7 +545,7 @@ int command_convert(int const Argc, char *Argv[]) {
int command_read(int const Argc, char *Argv[], bool const Dump) {
if (Argc < 4) {
std::cerr << std::format("usage: -eu07m {} <model.eu07m>\n", Dump ? "dump" : "validate");
std::cerr << std::format("usage: -eu07m {} <model.r3a>\n", Dump ? "dump" : "validate");
return 2;
}
auto const file{read_whole_file(Argv[3])};
+1 -1
View File
@@ -377,7 +377,7 @@ struct packed_rotation {
};
static_assert(sizeof(packed_rotation) == 8);
// the geometry of a primitive kept in the geometry store of the family of the model (geometry.eu07mpack beside the file) instead of
// the geometry of a primitive kept in the geometry store of the family of the model (geometry.r3p beside the file) instead of
// in the file: its vertices in every vertex stream of the file and its indices. the writer leaves its ranges out of the streams of the
// file, and the reader puts the block of the store back in their place, so the model in memory always has its whole streams
struct geometry_reference_record {
+1 -1
View File
@@ -73,7 +73,7 @@ bool write_file(std::filesystem::path const &Path, std::span<std::byte const> Da
bool is_model(std::filesystem::directory_entry const &Entry) {
auto extension{Entry.path().extension().string()};
std::ranges::transform(extension, extension.begin(), [](unsigned char const Letter) { return static_cast<char>(std::tolower(Letter)); });
return Entry.is_regular_file() && extension == ".eu07m";
return Entry.is_regular_file() && extension == ".r3a";
}
// the models of the folder read whole, with the store there is; false when one can't be read
+1 -1
View File
@@ -28,7 +28,7 @@ struct pack_result {
};
// the geometry of the primitives of at least MinBytes which occur more than once in the models of the folder moved to its store
// (geometry.eu07mpack), made anew from all of them; the models are written again referring to it. every model is read back and
// (geometry.r3p), made anew from all of them; the models are written again referring to it. every model is read back and
// compared with what it was before it's replaced. what was done goes to Log
pack_result pack_folder(std::filesystem::path const &Folder, std::size_t MinBytes, std::ostream &Log);
// the models of the folder written again with their whole geometry; the store is left for the user to delete
+2 -2
View File
@@ -10,7 +10,7 @@ http://mozilla.org/MPL/2.0/.
#pragma once
// the geometry shared by the models of a family (the variants of a vehicle): blocks of the geometry of primitives kept once in the
// store of the folder (geometry.eu07mpack) and referred to by the models (GREF) instead of being repeated in each of them
// store of the folder (geometry.r3p) and referred to by the models (GREF) instead of being repeated in each of them
#include "model/eu07m/eu07m_model.h"
@@ -26,7 +26,7 @@ namespace eu07m {
using block_id = std::array<std::uint64_t, 2>;
// the name of the store in the folder of the models
constexpr char const *store_file_name{"geometry.eu07mpack"};
constexpr char const *store_file_name{"geometry.r3p"};
// the streams a block carries, in this order after its header
namespace block_streams {
+6 -6
View File
@@ -92,7 +92,7 @@ TEST_CASE("eu07m streaming: a file read from the disk is the model read from mem
for (auto const compress : {false, true}) {
CAPTURE(compress);
auto const file{eu07m::write(original, {compress, 9})};
auto const path{folder.write("model.eu07m", as_text(file))};
auto const path{folder.write("model.r3a", as_text(file))};
eu07m::model frommemory;
auto const memory{eu07m::read(file, frommemory, game_options(true))};
REQUIRE_MESSAGE(memory.ok, memory.error);
@@ -113,7 +113,7 @@ TEST_CASE("eu07m streaming: without the streams the structure alone is read and
{
test::scratch_folder folder{"eu07m_streaming_structure"};
auto const original{streamed_model()};
auto const path{folder.write("model.eu07m", as_text(eu07m::write(original)))};
auto const path{folder.write("model.r3a", as_text(eu07m::write(original)))};
eu07m::model structure;
auto const result{eu07m::read_file(path, structure, game_options(false))};
REQUIRE_MESSAGE(result.ok, result.error);
@@ -155,7 +155,7 @@ TEST_CASE("eu07m streaming: the structure is read without touching the streams")
entry.flags |= eu07m::section_flags::zstd;
std::memcpy(file.data() + offset, &entry, sizeof(entry));
}
auto const path{folder.write("model.eu07m", as_text(file))};
auto const path{folder.write("model.r3a", as_text(file))};
eu07m::model model;
auto const structure{eu07m::read_file(path, model, game_options(false))};
CHECK_MESSAGE(structure.ok, structure.error);
@@ -169,14 +169,14 @@ TEST_CASE("eu07m streaming: a file cut short or missing is refused with a reason
test::scratch_folder folder{"eu07m_streaming_broken"};
auto const file{eu07m::write(streamed_model())};
eu07m::model model;
auto const missing{eu07m::read_file(folder.path("none.eu07m"), model, game_options(false))};
auto const missing{eu07m::read_file(folder.path("none.r3a"), model, game_options(false))};
CHECK_FALSE(missing.ok);
CHECK_FALSE(missing.error.empty());
auto const shortpath{folder.write("short.eu07m", as_text(file).substr(0, file.size() - 8))};
auto const shortpath{folder.write("short.r3a", as_text(file).substr(0, file.size() - 8))};
auto const cut{eu07m::read_file(shortpath, model, game_options(false))};
CHECK_FALSE(cut.ok);
CHECK(cut.error.find("cut short") != std::string::npos);
auto const tinypath{folder.write("tiny.eu07m", as_text(file).substr(0, 10))};
auto const tinypath{folder.write("tiny.r3a", as_text(file).substr(0, 10))};
auto const tiny{eu07m::read_file(tinypath, model, game_options(false))};
CHECK_FALSE(tiny.ok);
CHECK(tiny.error.find("shorter than the header") != std::string::npos);
+5 -5
View File
@@ -177,9 +177,9 @@ TEST_CASE("gref: a folder packed and unpacked") {
auto const a{variant(40, 0.f, 1.f)};
auto const b{variant(40, 0.f, 2.f)};
auto const c{variant(40, 5.f, 3.f)};
save(folder / "a.eu07m", eu07m::write(a));
save(folder / "b.eu07m", eu07m::write(b));
save(folder / "c.eu07m", eu07m::write(c));
save(folder / "a.r3a", eu07m::write(a));
save(folder / "b.r3a", eu07m::write(b));
save(folder / "c.r3a", eu07m::write(c));
std::ostringstream log;
auto const packed{eu07m::pack_folder(folder, 4096, log)};
@@ -195,7 +195,7 @@ TEST_CASE("gref: a folder packed and unpacked") {
REQUIRE(store.open(folder / eu07m::store_file_name, error));
eu07m::read_options options;
options.blocks = memory_source(store);
for (auto const &[name, original] : {std::pair{"a.eu07m", &a}, std::pair{"b.eu07m", &b}, std::pair{"c.eu07m", &c}}) {
for (auto const &[name, original] : {std::pair{"a.r3a", &a}, std::pair{"b.r3a", &b}, std::pair{"c.r3a", &c}}) {
eu07m::model read;
REQUIRE(eu07m::read(load(folder / name), read, options).ok);
CHECK(same_streams(read, *original));
@@ -207,7 +207,7 @@ TEST_CASE("gref: a folder packed and unpacked") {
auto const unpacked{eu07m::unpack_folder(folder, log)};
REQUIRE(unpacked.ok);
eu07m::model whole;
REQUIRE(eu07m::read(load(folder / "b.eu07m"), whole, {}).ok);
REQUIRE(eu07m::read(load(folder / "b.r3a"), whole, {}).ok);
CHECK(whole.geometry_references.empty());
CHECK(same_streams(whole, b));
std::filesystem::remove_all(folder);
+3 -3
View File
@@ -216,7 +216,7 @@ TEST_CASE("skinning: the skinned tube is a valid EU07M file") {
CHECK(read.weights.size() == read.positions.size());
CHECK(read.primitives[0].skin == 0);
// kept in the scratch folder for a look in the game
auto const path{std::filesystem::path{EU07_UNIT_TESTS_SCRATCH} / "skinned_tube.eu07m"};
auto const path{std::filesystem::path{EU07_UNIT_TESTS_SCRATCH} / "skinned_tube.r3a"};
std::ofstream output{path, std::ios::binary};
output.write(reinterpret_cast<char const *>(file.data()), static_cast<std::streamsize>(file.size()));
CHECK(output.good());
@@ -243,7 +243,7 @@ TEST_CASE("skinning: the tube bent by a clip of its own") {
}
CHECK(eu07m::validate(model, 16).empty());
auto const file{eu07m::write(model, {true, 9})};
auto const path{std::filesystem::path{EU07_UNIT_TESTS_SCRATCH} / "clip_tube.eu07m"};
auto const path{std::filesystem::path{EU07_UNIT_TESTS_SCRATCH} / "clip_tube.r3a"};
std::ofstream output{path, std::ios::binary};
output.write(reinterpret_cast<char const *>(file.data()), static_cast<std::streamsize>(file.size()));
CHECK(output.good());
@@ -292,7 +292,7 @@ TEST_CASE("skinning: the tube moved by channels") {
model.add_component(eu07m::component::channel, eu07m::target_kind::model, 0, eu07m::payload_writer{}.put(phase).put(toclip).data());
CHECK(eu07m::validate(model, 16).empty());
auto const file{eu07m::write(model, {true, 9})};
auto const path{std::filesystem::path{EU07_UNIT_TESTS_SCRATCH} / "channel_tube.eu07m"};
auto const path{std::filesystem::path{EU07_UNIT_TESTS_SCRATCH} / "channel_tube.r3a"};
std::ofstream output{path, std::ios::binary};
output.write(reinterpret_cast<char const *>(file.data()), static_cast<std::streamsize>(file.size()));
CHECK(output.good());
+4 -4
View File
@@ -1001,16 +1001,16 @@ bool global_settings::ConfigParseSimulation(cParser& Parser, const std::string&
if (token == "modelformat")
{
// eu07m: a model with an .eu07m file beside its .e3d / .t3d is loaded from it; legacy: the .eu07m files are left alone
// r3a: a model with an .r3a file beside its .e3d / .t3d is loaded from it; legacy: the .r3a files are left alone
std::string value;
ParseOne(Parser, value, 1);
modelformat_eu07m = value == "eu07m";
modelformat_eu07m = value == "r3a";
return true;
}
if (token == "modelstreaming")
{
// yes: the geometry of the larger scenery models of .eu07m files is read when they're about to be drawn
// yes: the geometry of the larger scenery models of .r3a files is read when they're about to be drawn
ParseOne(Parser, modelstreaming);
return true;
}
@@ -2726,7 +2726,7 @@ global_settings::export_as_text( std::ostream &Output ) const {
export_as_text( Output, "hiddenevents", iHiddenEvents );
export_as_text( Output, "pause", ( iPause & 1 ) != 0 );
export_as_text(Output, "priorityLoadText3D", priorityLoadText3D);
export_as_text(Output, "modelformat", std::string{modelformat_eu07m ? "eu07m" : "legacy"});
export_as_text(Output, "modelformat", std::string{modelformat_eu07m ? "r3a" : "legacy"});
export_as_text(Output, "modelstreaming", modelstreaming);
export_as_text(Output, "modelstreaming.minsize", modelstreaming_minsize);
export_as_text(Output, "modelstreaming.evictafter", modelstreaming_evictafter);
+3 -3
View File
@@ -121,11 +121,11 @@ struct global_settings {
int file_binary_terrain_skipped{0}; // number of terrain includes left out by the parser during the current scenery load
// logs
bool priorityLoadText3D{false}; // ladowanie T3D priorytetowo
bool modelformat_eu07m{false}; // modelformat eu07m: models are loaded from their .eu07m files where there are some
// modelstreaming yes: the geometry of the larger scenery models loaded from .eu07m files is read when they're about to be drawn and
bool modelformat_eu07m{false}; // modelformat r3a: models are loaded from their .r3a files where there are some
// modelstreaming yes: the geometry of the larger scenery models loaded from .r3a files is read when they're about to be drawn and
// let go of when they're unused for a while (rendering/geometrystreamer.h); no: it's read with the models, as before
bool modelstreaming{true};
int modelstreaming_minsize{256}; // KiB of the .eu07m file, below which a model is loaded whole
int modelstreaming_minsize{256}; // KiB of the .r3a file, below which a model is loaded whole
float modelstreaming_evictafter{30.f}; // seconds a streamed model goes undrawn before its geometry is let go of
int modelstreaming_budget{0}; // MB of the geometry of the streamed models above which it's let go of sooner; 0 no limit
int iWriteLogEnabled{ 3 }; // maska bitowa: 1-zapis do pliku, 2-okienko, 4-nazwy torów