From ffbaacdb0e368a130e851fbae1635c8ea0cc2b32 Mon Sep 17 00:00:00 2001 From: tmj-fstate Date: Tue, 31 Oct 2017 21:43:31 +0100 Subject: [PATCH] build 171031: reduced footprint for binary region terrain file --- McZapkie/mctools.cpp | 23 +++++++++++++++++++++- McZapkie/mctools.h | 3 +++ scene.cpp | 45 +++++++++++++++++++++++++++++--------------- scenenode.cpp | 24 +++++++++++++++++++---- simulation.cpp | 13 ++++++++++--- version.h | 2 +- 6 files changed, 86 insertions(+), 24 deletions(-) diff --git a/McZapkie/mctools.cpp b/McZapkie/mctools.cpp index 2b63e841..7cb32c88 100644 --- a/McZapkie/mctools.cpp +++ b/McZapkie/mctools.cpp @@ -13,6 +13,17 @@ Copyright (C) 2007-2014 Maciej Cierniak */ #include "stdafx.h" #include "mctools.h" + +#include +#include +#ifndef WIN32 +#include +#endif + +#ifdef WIN32 +#define stat _stat +#endif + #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 ); 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; } +} diff --git a/McZapkie/mctools.h b/McZapkie/mctools.h index 6692710b..518cd77d 100644 --- a/McZapkie/mctools.h +++ b/McZapkie/mctools.h @@ -158,3 +158,6 @@ bool extract_value( bool &Variable, std::string const &Key, std::string const &Input, std::string const &Default ); bool FileExists( std::string const &Filename ); + +// returns time of last modification for specified file +__time64_t last_modified( std::string const &Filename ); \ No newline at end of file diff --git a/scene.cpp b/scene.cpp index 00a9cddf..cdf7e511 100644 --- a/scene.cpp +++ b/scene.cpp @@ -224,6 +224,11 @@ basic_cell::deserialize( std::istream &Input ) { while( itemcount-- ) { 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 @@ -877,18 +882,27 @@ basic_region::serialize( std::string const &Scenariofile ) const { std::ofstream output { filename, std::ios::binary }; - // region file version 0 + // region file version 1 // header: EU07SBT + version (0-255) 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 // TBD, TODO: build table of sections and file offsets, if we postpone section loading until they're within range - for( auto section : m_sections ) { - // length of section data, followed by section data (if any) + 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 ); } - else { - sn_utils::ls_uint32( output, 0 ); } + ++sectionindex; } } @@ -907,7 +921,7 @@ basic_region::deserialize( std::string const &Scenariofile ) { if( false == FileExists( filename ) ) { return false; } - // region file version 0 + // region file version 1 // file type and version check 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 ) }; 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 - ErrorLog( "Bad file: \"" + filename + "\" is of either unrecognized type or version" ); + 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 - for( auto §ion : m_sections ) { - // length of section data, followed by section data (if any) + // section count + 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 ) }; - if( sectionsize != 0 ) { - section = new basic_section(); - section->deserialize( input ); - } + section = new basic_section(); + section->deserialize( input ); } return true; diff --git a/scenenode.cpp b/scenenode.cpp index 5feef77e..f223986c 100644 --- a/scenenode.cpp +++ b/scenenode.cpp @@ -80,7 +80,11 @@ shape_node::shapenode_data::serialize( std::ostream &Output ) const { // vertex count, followed by vertex data sn_utils::ls_uint32( Output, vertices.size() ); 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 // vertex data vertices.resize( sn_utils::ld_uint32( Input ) ); + basic_vertex localvertex; 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 sn_utils::ls_uint32( Output, vertices.size() ); 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 // vertex data vertices.resize( sn_utils::ld_uint32( Input ) ); + basic_vertex localvertex; 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; } } diff --git a/simulation.cpp b/simulation.cpp index 1c469dd0..181e22b3 100644 --- a/simulation.cpp +++ b/simulation.cpp @@ -39,15 +39,22 @@ state_manager::deserialize( std::string const &Scenariofile ) { // TODO: check first for presence of serialized binary files // if this fails, fall back on the legacy text format 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 cParser scenarioparser( Scenariofile, cParser::buffer_FILE, Global::asCurrentSceneryPath, Global::bLoadTraction ); if( false == scenarioparser.ok() ) { return false; } 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 ) { Region->serialize( Scenariofile ); } + if( ( false == importscratchpad.binary.terrain ) + && ( 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 return true; diff --git a/version.h b/version.h index 405dacc3..e7a0964f 100644 --- a/version.h +++ b/version.h @@ -1,5 +1,5 @@ #pragma once #define VERSION_MAJOR 17 -#define VERSION_MINOR 1030 +#define VERSION_MINOR 1031 #define VERSION_REVISION 0