mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-21 21:49:19 +02:00
build 171031: reduced footprint for binary region terrain file
This commit is contained in:
@@ -13,6 +13,17 @@ Copyright (C) 2007-2014 Maciej Cierniak
|
|||||||
*/
|
*/
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
#include "mctools.h"
|
#include "mctools.h"
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#ifndef WIN32
|
||||||
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#define stat _stat
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "Globals.h"
|
#include "Globals.h"
|
||||||
|
|
||||||
/*================================================*/
|
/*================================================*/
|
||||||
@@ -275,8 +286,18 @@ extract_value( bool &Variable, std::string const &Key, std::string const &Input,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileExists( std::string const &Filename ) {
|
bool
|
||||||
|
FileExists( std::string const &Filename ) {
|
||||||
|
|
||||||
std::ifstream file( Filename );
|
std::ifstream file( Filename );
|
||||||
return( true == file.is_open() );
|
return( true == file.is_open() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// returns time of last modification for specified file
|
||||||
|
__time64_t
|
||||||
|
last_modified( std::string const &Filename ) {
|
||||||
|
|
||||||
|
struct stat filestat;
|
||||||
|
if( ::stat( Filename.c_str(), &filestat ) == 0 ) { return filestat.st_mtime; }
|
||||||
|
else { return 0; }
|
||||||
|
}
|
||||||
|
|||||||
@@ -158,3 +158,6 @@ bool
|
|||||||
extract_value( bool &Variable, std::string const &Key, std::string const &Input, std::string const &Default );
|
extract_value( bool &Variable, std::string const &Key, std::string const &Input, std::string const &Default );
|
||||||
|
|
||||||
bool FileExists( std::string const &Filename );
|
bool FileExists( std::string const &Filename );
|
||||||
|
|
||||||
|
// returns time of last modification for specified file
|
||||||
|
__time64_t last_modified( std::string const &Filename );
|
||||||
45
scene.cpp
45
scene.cpp
@@ -224,6 +224,11 @@ basic_cell::deserialize( std::istream &Input ) {
|
|||||||
while( itemcount-- ) {
|
while( itemcount-- ) {
|
||||||
m_lines.emplace_back( lines_node().deserialize( Input ) );
|
m_lines.emplace_back( lines_node().deserialize( Input ) );
|
||||||
}
|
}
|
||||||
|
// cell activation flag
|
||||||
|
m_active = (
|
||||||
|
( false == m_shapesopaque.empty() )
|
||||||
|
|| ( false == m_shapestranslucent.empty() )
|
||||||
|
|| ( false == m_lines.empty() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
// adds provided shape to the cell
|
// adds provided shape to the cell
|
||||||
@@ -877,18 +882,27 @@ basic_region::serialize( std::string const &Scenariofile ) const {
|
|||||||
|
|
||||||
std::ofstream output { filename, std::ios::binary };
|
std::ofstream output { filename, std::ios::binary };
|
||||||
|
|
||||||
// region file version 0
|
// region file version 1
|
||||||
// header: EU07SBT + version (0-255)
|
// header: EU07SBT + version (0-255)
|
||||||
sn_utils::ls_uint32( output, MAKE_ID4( 'E', 'U', '0', '7' ) );
|
sn_utils::ls_uint32( output, MAKE_ID4( 'E', 'U', '0', '7' ) );
|
||||||
sn_utils::ls_uint32( output, MAKE_ID4( 'S', 'B', 'T', 0 ) );
|
sn_utils::ls_uint32( output, MAKE_ID4( 'S', 'B', 'T', 1 ) );
|
||||||
// sections
|
// sections
|
||||||
// TBD, TODO: build table of sections and file offsets, if we postpone section loading until they're within range
|
// TBD, TODO: build table of sections and file offsets, if we postpone section loading until they're within range
|
||||||
for( auto section : m_sections ) {
|
std::uint32_t sectioncount { 0 };
|
||||||
// length of section data, followed by section data (if any)
|
for( auto *section : m_sections ) {
|
||||||
if( section != nullptr ) {
|
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 ); }
|
section->serialize( output ); }
|
||||||
else {
|
++sectionindex;
|
||||||
sn_utils::ls_uint32( output, 0 ); }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -907,7 +921,7 @@ basic_region::deserialize( std::string const &Scenariofile ) {
|
|||||||
if( false == FileExists( filename ) ) {
|
if( false == FileExists( filename ) ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// region file version 0
|
// region file version 1
|
||||||
// file type and version check
|
// file type and version check
|
||||||
std::ifstream input( filename, std::ios::binary );
|
std::ifstream input( filename, std::ios::binary );
|
||||||
|
|
||||||
@@ -915,20 +929,21 @@ basic_region::deserialize( std::string const &Scenariofile ) {
|
|||||||
uint32_t headertype { sn_utils::ld_uint32( input ) };
|
uint32_t headertype { sn_utils::ld_uint32( input ) };
|
||||||
|
|
||||||
if( ( headermain != MAKE_ID4( 'E', 'U', '0', '7' )
|
if( ( headermain != MAKE_ID4( 'E', 'U', '0', '7' )
|
||||||
|| ( headertype != MAKE_ID4( 'S', 'B', 'T', 0 ) ) ) ) {
|
|| ( headertype != MAKE_ID4( 'S', 'B', 'T', 1 ) ) ) ) {
|
||||||
// wrong file type
|
// wrong file type
|
||||||
ErrorLog( "Bad file: \"" + filename + "\" is of either unrecognized type or version" );
|
WriteLog( "Bad file: \"" + filename + "\" is of either unrecognized type or version" );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// sections
|
// sections
|
||||||
// TBD, TODO: build table of sections and file offsets, if we postpone section loading until they're within range
|
// TBD, TODO: build table of sections and file offsets, if we postpone section loading until they're within range
|
||||||
for( auto §ion : m_sections ) {
|
// section count
|
||||||
// length of section data, followed by section data (if any)
|
auto sectioncount { sn_utils::ld_uint32( input ) };
|
||||||
|
while( sectioncount-- ) {
|
||||||
|
// section index, followed by section data size, followed by section data
|
||||||
|
auto *§ion { m_sections[ sn_utils::ld_uint32( input ) ] };
|
||||||
auto const sectionsize { sn_utils::ld_uint32( input ) };
|
auto const sectionsize { sn_utils::ld_uint32( input ) };
|
||||||
if( sectionsize != 0 ) {
|
section = new basic_section();
|
||||||
section = new basic_section();
|
section->deserialize( input );
|
||||||
section->deserialize( input );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -80,7 +80,11 @@ shape_node::shapenode_data::serialize( std::ostream &Output ) const {
|
|||||||
// vertex count, followed by vertex data
|
// vertex count, followed by vertex data
|
||||||
sn_utils::ls_uint32( Output, vertices.size() );
|
sn_utils::ls_uint32( Output, vertices.size() );
|
||||||
for( auto const &vertex : vertices ) {
|
for( auto const &vertex : vertices ) {
|
||||||
vertex.serialize( Output );
|
basic_vertex(
|
||||||
|
glm::vec3{ vertex.position - origin },
|
||||||
|
vertex.normal,
|
||||||
|
vertex.texture )
|
||||||
|
.serialize( Output );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,8 +109,12 @@ shape_node::shapenode_data::deserialize( std::istream &Input ) {
|
|||||||
// NOTE: geometry handle is acquired during geometry creation
|
// NOTE: geometry handle is acquired during geometry creation
|
||||||
// vertex data
|
// vertex data
|
||||||
vertices.resize( sn_utils::ld_uint32( Input ) );
|
vertices.resize( sn_utils::ld_uint32( Input ) );
|
||||||
|
basic_vertex localvertex;
|
||||||
for( auto &vertex : vertices ) {
|
for( auto &vertex : vertices ) {
|
||||||
vertex.deserialize( Input );
|
localvertex.deserialize( Input );
|
||||||
|
vertex.position = origin + glm::dvec3{ localvertex.position };
|
||||||
|
vertex.normal = localvertex.normal;
|
||||||
|
vertex.texture = localvertex.texture;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -456,7 +464,11 @@ lines_node::linesnode_data::serialize( std::ostream &Output ) const {
|
|||||||
// vertex count, followed by vertex data
|
// vertex count, followed by vertex data
|
||||||
sn_utils::ls_uint32( Output, vertices.size() );
|
sn_utils::ls_uint32( Output, vertices.size() );
|
||||||
for( auto const &vertex : vertices ) {
|
for( auto const &vertex : vertices ) {
|
||||||
vertex.serialize( Output );
|
basic_vertex(
|
||||||
|
glm::vec3{ vertex.position - origin },
|
||||||
|
vertex.normal,
|
||||||
|
vertex.texture )
|
||||||
|
.serialize( Output );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -477,8 +489,12 @@ lines_node::linesnode_data::deserialize( std::istream &Input ) {
|
|||||||
// NOTE: geometry handle is acquired during geometry creation
|
// NOTE: geometry handle is acquired during geometry creation
|
||||||
// vertex data
|
// vertex data
|
||||||
vertices.resize( sn_utils::ld_uint32( Input ) );
|
vertices.resize( sn_utils::ld_uint32( Input ) );
|
||||||
|
basic_vertex localvertex;
|
||||||
for( auto &vertex : vertices ) {
|
for( auto &vertex : vertices ) {
|
||||||
vertex.deserialize( Input );
|
localvertex.deserialize( Input );
|
||||||
|
vertex.position = origin + glm::dvec3{ localvertex.position };
|
||||||
|
vertex.normal = localvertex.normal;
|
||||||
|
vertex.texture = localvertex.texture;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,15 +39,22 @@ state_manager::deserialize( std::string const &Scenariofile ) {
|
|||||||
// TODO: check first for presence of serialized binary files
|
// TODO: check first for presence of serialized binary files
|
||||||
// if this fails, fall back on the legacy text format
|
// if this fails, fall back on the legacy text format
|
||||||
scene::scratch_data importscratchpad;
|
scene::scratch_data importscratchpad;
|
||||||
importscratchpad.binary.terrain = Region->deserialize( Scenariofile );
|
if( Scenariofile != "$.scn" ) {
|
||||||
|
// compilation to binary file isn't supported for rainsted-created overrides
|
||||||
|
importscratchpad.binary.terrain = Region->deserialize( Scenariofile );
|
||||||
|
}
|
||||||
// NOTE: for the time being import from text format is a given, since we don't have full binary serialization
|
// NOTE: for the time being import from text format is a given, since we don't have full binary serialization
|
||||||
cParser scenarioparser( Scenariofile, cParser::buffer_FILE, Global::asCurrentSceneryPath, Global::bLoadTraction );
|
cParser scenarioparser( Scenariofile, cParser::buffer_FILE, Global::asCurrentSceneryPath, Global::bLoadTraction );
|
||||||
|
|
||||||
if( false == scenarioparser.ok() ) { return false; }
|
if( false == scenarioparser.ok() ) { return false; }
|
||||||
|
|
||||||
deserialize( scenarioparser, importscratchpad );
|
deserialize( scenarioparser, importscratchpad );
|
||||||
// if we didn't find usable binary version of the scenario files, create them now for future use
|
if( ( false == importscratchpad.binary.terrain )
|
||||||
if( false == importscratchpad.binary.terrain ) { Region->serialize( Scenariofile ); }
|
&& ( Scenariofile != "$.scn" ) ) {
|
||||||
|
// if we didn't find usable binary version of the scenario files, create them now for future use
|
||||||
|
// as long as the scenario file wasn't rainsted-created base file override
|
||||||
|
Region->serialize( Scenariofile );
|
||||||
|
}
|
||||||
|
|
||||||
Global::iPause &= ~0x10; // koniec pauzy wczytywania
|
Global::iPause &= ~0x10; // koniec pauzy wczytywania
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user