mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-21 15:59:18 +02:00
Add binary scenery format (eu7 v3) with async baking, replacing SBT
Text scenery component files (.scn/.inc/.scm/.ctr) are compiled into per-file binary twins (.scnb/.incb/.scmb/.ctrb), handled transparently at the cParser layer: a fresh twin (mtime-checked, version-matched) is replayed instead of re-tokenizing text; otherwise the text is parsed and a twin is compiled alongside it for next time. Format details: - per-file string interning: keywords/paths stored once, referenced by varint index (so node/endmodel/... are not repeated as text) - numeric tokens stored as 8-byte IEEE doubles, not ASCII - includes kept as references with parameters; random sets stored verbatim and re-evaluated on every load (choice not frozen at compile time) - twin writing offloaded to a bounded thread pool so baking overlaps scene construction instead of blocking the load The legacy terrain-only .sbt path is removed; terrain now loads as ordinary scenery content. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
120
scene/scene.cpp
120
scene/scene.cpp
@@ -24,9 +24,6 @@ http://mozilla.org/MPL/2.0/.
|
||||
|
||||
namespace scene {
|
||||
|
||||
std::string const EU07_FILEEXTENSION_REGION { ".sbt" };
|
||||
std::uint32_t const EU07_FILEHEADER { MAKE_ID4( 'E','U','0','7' ) };
|
||||
std::uint32_t const EU07_FILEVERSION_REGION { MAKE_ID4( 'S', 'B', 'T', '2' ) };
|
||||
std::map<std::string, basic_node *> Hierarchy;
|
||||
|
||||
// potentially activates event handler with the same name as provided node, and within handler activation range
|
||||
@@ -1105,123 +1102,6 @@ basic_region::update_traction( TDynamicObject *Vehicle, int const Pantographinde
|
||||
}
|
||||
}
|
||||
|
||||
// checks whether specified file is a valid region data file
|
||||
bool
|
||||
basic_region::is_scene( std::string const &Scenariofile ) const {
|
||||
|
||||
auto filename { Scenariofile };
|
||||
while( filename[ 0 ] == '$' ) {
|
||||
// trim leading $ char rainsted utility may add to the base name for modified .scn files
|
||||
filename.erase( 0, 1 );
|
||||
}
|
||||
erase_extension( filename );
|
||||
filename = Global.asCurrentSceneryPath + filename;
|
||||
filename += EU07_FILEEXTENSION_REGION;
|
||||
|
||||
if( false == FileExists( filename ) ) {
|
||||
return false;
|
||||
}
|
||||
// file type and version check
|
||||
std::ifstream input( filename, std::ios::binary );
|
||||
|
||||
uint32_t headermain{ sn_utils::ld_uint32( input ) };
|
||||
uint32_t headertype{ sn_utils::ld_uint32( input ) };
|
||||
|
||||
if( ( headermain != EU07_FILEHEADER
|
||||
|| ( headertype != EU07_FILEVERSION_REGION ) ) ) {
|
||||
// wrong file type
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// stores content of the class in file with specified name
|
||||
void
|
||||
basic_region::serialize( std::string const &Scenariofile ) const {
|
||||
|
||||
auto filename { Scenariofile };
|
||||
while( filename[ 0 ] == '$' ) {
|
||||
// trim leading $ char rainsted utility may add to the base name for modified .scn files
|
||||
filename.erase( 0, 1 );
|
||||
}
|
||||
erase_extension( filename );
|
||||
filename = Global.asCurrentSceneryPath + filename;
|
||||
filename += EU07_FILEEXTENSION_REGION;
|
||||
|
||||
std::ofstream output { filename, std::ios::binary };
|
||||
|
||||
// region file version 1
|
||||
// header: EU07SBT + version (0-255)
|
||||
sn_utils::ls_uint32( output, EU07_FILEHEADER );
|
||||
sn_utils::ls_uint32( output, EU07_FILEVERSION_REGION );
|
||||
// sections
|
||||
// TBD, TODO: build table of sections and file offsets, if we postpone section loading until they're within range
|
||||
std::uint32_t sectioncount { 0 };
|
||||
for( auto *section : m_sections ) {
|
||||
if( section != nullptr ) {
|
||||
++sectioncount;
|
||||
}
|
||||
}
|
||||
// section count, followed by section data
|
||||
sn_utils::ls_uint32( output, sectioncount );
|
||||
std::uint32_t sectionindex { 0 };
|
||||
for( auto *section : m_sections ) {
|
||||
// section data: section index, followed by length of section data, followed by section data
|
||||
if( section != nullptr ) {
|
||||
sn_utils::ls_uint32( output, sectionindex );
|
||||
section->serialize( output ); }
|
||||
++sectionindex;
|
||||
}
|
||||
}
|
||||
|
||||
// restores content of the class from file with specified name. returns: true on success, false otherwise
|
||||
bool
|
||||
basic_region::deserialize( std::string const &Scenariofile ) {
|
||||
|
||||
auto filename { Scenariofile };
|
||||
while( filename[ 0 ] == '$' ) {
|
||||
// trim leading $ char rainsted utility may add to the base name for modified .scn files
|
||||
filename.erase( 0, 1 );
|
||||
}
|
||||
erase_extension( filename );
|
||||
filename = Global.asCurrentSceneryPath + filename;
|
||||
filename += EU07_FILEEXTENSION_REGION;
|
||||
|
||||
if( false == FileExists( filename ) ) {
|
||||
Global.file_binary_terrain_state = false;
|
||||
return false;
|
||||
}
|
||||
// region file version 1
|
||||
// file type and version check
|
||||
std::ifstream input( filename, std::ios::binary );
|
||||
|
||||
uint32_t headermain { sn_utils::ld_uint32( input ) };
|
||||
uint32_t headertype { sn_utils::ld_uint32( input ) };
|
||||
|
||||
if( ( headermain != EU07_FILEHEADER
|
||||
|| ( headertype != EU07_FILEVERSION_REGION ) ) ) {
|
||||
// wrong file type
|
||||
WriteLog( "Bad file: \"" + filename + "\" is of either unrecognized type or version" );
|
||||
return false;
|
||||
}
|
||||
// sections
|
||||
// TBD, TODO: build table of sections and file offsets, if we postpone section loading until they're within range
|
||||
// section count
|
||||
auto sectioncount { sn_utils::ld_uint32( input ) };
|
||||
while( sectioncount-- ) {
|
||||
// section index, followed by section data size, followed by section data
|
||||
auto const sectionindex { sn_utils::ld_uint32( input ) };
|
||||
auto const sectionsize { sn_utils::ld_uint32( input ) };
|
||||
if( m_sections[ sectionindex ] == nullptr ) {
|
||||
m_sections[ sectionindex ] = new basic_section();
|
||||
}
|
||||
m_sections[ sectionindex ]->deserialize( input );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// sends content of the class in legacy (text) format to provided stream
|
||||
void
|
||||
basic_region::export_as_text( std::ostream &Output ) const {
|
||||
|
||||
Reference in New Issue
Block a user