diff --git a/scene/sceneterrain.cpp b/scene/sceneterrain.cpp index afee3eda..39f0f02d 100644 --- a/scene/sceneterrain.cpp +++ b/scene/sceneterrain.cpp @@ -614,7 +614,7 @@ bool terrain_file::convert(std::string const &Textfile, std::string const &Binar return result; } -// makes sure binary version of specified text terrain file is in place and matches the text +// makes sure binary version of specified text terrain file is in place and matches the text, as far as the settings ask for it terrain_file::state terrain_file::prepare(std::string const &Textfile, std::string const &Binaryfile) { file_header header; @@ -628,10 +628,20 @@ terrain_file::state terrain_file::prepare(std::string const &Textfile, std::stri return (binarypresent ? state::binary : state::missing); } + // how far the check goes is up to the settings (file.binary.terrain.checksum): none at all, length of the text, or its length and checksum + if (binarypresent && Global.file_binary_terrain_checksum <= 0) + { + return state::binary; + } std::string text; auto textloaded{false}; if (binarypresent && (header.sourcesize == textsize)) { + if (Global.file_binary_terrain_checksum == 1) + { + // NOTE: this takes a text changed without a change of its length for the one the binary file was made from + return state::binary; + } // the length is the same; the checksum tells whether the content is, too textloaded = read_file(Textfile, text); if (textloaded && (text.size() == header.sourcesize) && (checksum(text.data(), text.size()) == header.sourcechecksum)) diff --git a/scene/sceneterrain.h b/scene/sceneterrain.h index 773cb821..b719604b 100644 --- a/scene/sceneterrain.h +++ b/scene/sceneterrain.h @@ -39,7 +39,7 @@ class terrain_file // converts specified text terrain file to binary format. returns: true on success, false otherwise. // description of the result or of the failure is stored in Message, if provided static bool convert(std::string const &Textfile, std::string const &Binaryfile, std::string *Message = nullptr); - // makes sure binary version of specified text terrain file is in place and matches the text + // makes sure binary version of specified text terrain file is in place and matches the text, as far as the settings ask for it static state prepare(std::string const &Textfile, std::string const &Binaryfile); // makes content of specified binary terrain file a part of provided region. the geometry is loaded right away, // or left for the sections of the region to load when they're about to be used. returns: true on success, false otherwise diff --git a/utilities/Globals.cpp b/utilities/Globals.cpp index 47b04d18..7ce2446a 100644 --- a/utilities/Globals.cpp +++ b/utilities/Globals.cpp @@ -630,6 +630,15 @@ bool global_settings::ConfigParseSimulation(cParser& Parser, const std::string& return true; } + if (token == "file.binary.terrain.checksum") + { + // off, simple or full; anything else leaves the setting as it was + std::string mode; + ParseOne(Parser, mode, 1, true); + file_binary_terrain_checksum = (mode == "off" ? 0 : mode == "simple" ? 1 : mode == "full" ? 2 : file_binary_terrain_checksum); + return true; + } + if (token == "inactivepause") { ParseOne(Parser, bInactivePause); @@ -1582,6 +1591,7 @@ global_settings::export_as_text( std::ostream &Output ) const { export_as_text( Output, "latitude", fLatitudeDeg ); export_as_text( Output, "convertmodels", iConvertModels ); export_as_text( Output, "file.binary.terrain", file_binary_terrain ); + export_as_text( Output, "file.binary.terrain.checksum", std::string( file_binary_terrain_checksum == 0 ? "off" : file_binary_terrain_checksum == 1 ? "simple" : "full" ) ); export_as_text( Output, "inactivepause", bInactivePause ); export_as_text( Output, "slowmotion", iSlowMotionMask ); export_as_text( Output, "hideconsole", bHideConsole ); diff --git a/utilities/Globals.h b/utilities/Globals.h index 632a2a5d..acf0c00f 100644 --- a/utilities/Globals.h +++ b/utilities/Globals.h @@ -88,6 +88,7 @@ struct global_settings { int iConvertModels{ 0 }; // tworzenie plików binarnych int iConvertIndexRange{ 1000 }; // range of duplicate vertex scan bool file_binary_terrain{ true }; // enable binary terrain (de)serialization + int file_binary_terrain_checksum{ 1 }; // check of a binary terrain file (.btf) against its text: 0 = none, 1 = length of the text, 2 = length and checksum bool file_binary_terrain_state{true}; int file_binary_terrain_skipped{0}; // number of terrain includes left out by the parser during the current scenery load // logs