mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-10-17 15:39:20 +02:00
A baked heightfield was trusted for as long as its file was readable, and the logic container while the .scn was older than it: an edited include went unnoticed by both, and node keys leaned on file dates, so merely touching a file changed them. And cooking only ever happened as a side effect of starting a scenery. Every cooked artifact now has a manifest beside it - <scenario>.ehf.deps, <scenario>.logic.deps - listing each file it was made from with its size, modification time and a hash of its content (simulation/cookdeps). The parser records what it includes as it reads, so the list is exactly what the load read. An artifact is current when every listed file still has its content: size and time are the quick check, and when either differs the content is hashed, so a touched or copied file does not force a rebuild and an edited one always does. A file added to the scenery cannot be in a manifest; the files read are compared with it after the load, and a mismatch sends the terrain to be baked on the next start - the new file's nodes, whose keys are unknown, are drawn as geometry meanwhile - and the logic, cooked from the loaded state, is cooked at once. The terrain depends on what the scenario includes and not on the scenario file itself, which the launcher rewrites on every start; the logic depends on both, since events can be written in either, and costs milliseconds to cook again. With the manifest vouching for file content, a triangle node's key is its file, line, include parameters and placement, without the date. -cook loads a scenery, brings whatever is stale up to date, and quits: the step that prepares a scenery ahead of play. It closes the window directly, as there is no simulation to wind down; a quit command waited a minute in the queue for one. Baking on a first start stays as the fallback, and -nobaketerrain still turns it off. Tried on a copy of baltyk with a terrain include of its own: a fresh cook bakes and cooks everything, a second finds nothing to do, a touched file changes nothing, an edited include is caught by its hash and both artifacts are rebuilt, and a new include has the logic recooked at once and the terrain on the next run. A cooking run of baltyk takes 5.5 s with nothing stale and 10.7 s with everything to do.
130 lines
6.0 KiB
C++
130 lines
6.0 KiB
C++
/*
|
|
This Source Code Form is subject to the
|
|
terms of the Mozilla Public License, v.
|
|
2.0. If a copy of the MPL was not
|
|
distributed with this file, You can
|
|
obtain one at
|
|
http://mozilla.org/MPL/2.0/.
|
|
*/
|
|
module;
|
|
#include <array>
|
|
#include <chrono>
|
|
#include <cstddef>
|
|
#include <deque>
|
|
#include <limits>
|
|
#include <mutex>
|
|
#include <type_traits>
|
|
#include <utility>
|
|
#include <sstream>
|
|
#include <vector>
|
|
#include <ostream>
|
|
#include <string>
|
|
#include <functional>
|
|
#include <unordered_map>
|
|
#include <memory>
|
|
|
|
export module eu07.simulation.simulationstateserializer;
|
|
import eu07.glm;
|
|
import eu07.audio.sound;
|
|
import eu07.utilities.parser;
|
|
import eu07.simcore;
|
|
import eu07.scene.prefab;
|
|
import eu07.simulation.logiccook;
|
|
import eu07.simulation.terrainbake;
|
|
|
|
export {
|
|
|
|
|
|
|
|
namespace simulation {
|
|
|
|
struct deserializer_state {
|
|
std::string scenariofile;
|
|
// the named scenery has no file on disk: the world is empty, so there's nothing to compile to SBT
|
|
bool blank{ false };
|
|
cParser input;
|
|
// every file the scenery includes, as it is read: what anything cooked from this load
|
|
// depends on
|
|
std::shared_ptr<std::vector<std::string>> included { std::make_shared<std::vector<std::string>>() };
|
|
scene::scratch_data scratchpad;
|
|
using deserializefunctionbind = std::function<void()>;
|
|
std::unordered_map<
|
|
std::string,
|
|
deserializefunctionbind> functionmap;
|
|
|
|
deserializer_state(std::string const &File, cParser::buffertype const Type, const std::string &Path, bool const Loadtraction)
|
|
: scenariofile(File), input(File, Type, Path, Loadtraction) { }
|
|
};
|
|
|
|
class state_serializer {
|
|
|
|
public:
|
|
|
|
// methods
|
|
// starts deserialization from specified file, returns context pointer on success, throws otherwise
|
|
std::shared_ptr<deserializer_state>
|
|
deserialize_begin(std::string const &Scenariofile);
|
|
// continues deserialization for given context, amount limited by time, returns true if needs to be called again
|
|
bool
|
|
deserialize_continue(std::shared_ptr<deserializer_state> state);
|
|
// stores class data in specified file, in legacy (text) format
|
|
void
|
|
export_as_text( std::string const &Scenariofile ) const;
|
|
// create new model from node stirng
|
|
TAnimModel * create_model(std::string const &src, std::string const &name, const glm::dvec3 &position);
|
|
// create new eventlauncher from node stirng
|
|
TEventLauncher * create_eventlauncher(std::string const &src, std::string const &name, const glm::dvec3 &position);
|
|
|
|
private:
|
|
// methods
|
|
// restores class data from provided stream
|
|
void deserialize_area( cParser &Input, scene::scratch_data &Scratchpad );
|
|
void deserialize_isolated( cParser &Input, scene::scratch_data &Scratchpad );
|
|
void deserialize_assignment( cParser &Input, scene::scratch_data &Scratchpad );
|
|
void deserialize_atmo( cParser &Input, scene::scratch_data &Scratchpad );
|
|
void deserialize_camera( cParser &Input, scene::scratch_data &Scratchpad );
|
|
void deserialize_config( cParser &Input, scene::scratch_data &Scratchpad );
|
|
void deserialize_description( cParser &Input, scene::scratch_data &Scratchpad );
|
|
void deserialize_event( cParser &Input, scene::scratch_data &Scratchpad );
|
|
void deserialize_lua( cParser &Input, scene::scratch_data &Scratchpad );
|
|
void deserialize_firstinit( cParser &Input, scene::scratch_data &Scratchpad );
|
|
void deserialize_group( cParser &Input, scene::scratch_data &Scratchpad );
|
|
void deserialize_endgroup( cParser &Input, scene::scratch_data &Scratchpad );
|
|
void deserialize_light( cParser &Input, scene::scratch_data &Scratchpad );
|
|
void deserialize_node( cParser &Input, scene::scratch_data &Scratchpad );
|
|
void deserialize_prefab( cParser &Input, scene::scratch_data &Scratchpad );
|
|
|
|
void deserialize_origin( cParser &Input, scene::scratch_data &Scratchpad );
|
|
void deserialize_endorigin( cParser &Input, scene::scratch_data &Scratchpad );
|
|
void deserialize_scale( cParser &Input, scene::scratch_data &Scratchpad );
|
|
void deserialize_endscale( cParser &Input, scene::scratch_data &Scratchpad );
|
|
void deserialize_rotate( cParser &Input, scene::scratch_data &Scratchpad );
|
|
void deserialize_sky( cParser &Input, scene::scratch_data &Scratchpad );
|
|
void deserialize_test( cParser &Input, scene::scratch_data &Scratchpad );
|
|
void deserialize_time( cParser &Input, scene::scratch_data &Scratchpad );
|
|
void deserialize_trainset( cParser &Input, scene::scratch_data &Scratchpad );
|
|
void deserialize_terrain( cParser &Input, scene::scratch_data &Scratchpad );
|
|
void deserialize_editorterrain( cParser &Input, scene::scratch_data &Scratchpad );
|
|
void deserialize_endtrainset( cParser &Input, scene::scratch_data &Scratchpad );
|
|
TTrack * deserialize_path( cParser &Input, scene::scratch_data &Scratchpad, scene::node_data const &Nodedata );
|
|
TTraction * deserialize_traction( cParser &Input, scene::scratch_data &Scratchpad, scene::node_data const &Nodedata );
|
|
TTractionPowerSource * deserialize_tractionpowersource( cParser &Input, scene::scratch_data &Scratchpad, scene::node_data const &Nodedata );
|
|
TMemCell * deserialize_memorycell( cParser &Input, scene::scratch_data &Scratchpad, scene::node_data const &Nodedata );
|
|
TEventLauncher * deserialize_eventlauncher( cParser &Input, scene::scratch_data &Scratchpad, scene::node_data const &Nodedata );
|
|
TAnimModel * deserialize_model( cParser &Input, scene::scratch_data &Scratchpad, scene::node_data const &Nodedata );
|
|
TDynamicObject * deserialize_dynamic( cParser &Input, scene::scratch_data &Scratchpad, scene::node_data const &Nodedata );
|
|
sound_source * deserialize_sound( cParser &Input, scene::scratch_data &Scratchpad, scene::node_data const &Nodedata );
|
|
void init_time();
|
|
// skips content of stream until specified token
|
|
void skip_until( cParser &Input, std::string const &Token );
|
|
// transforms provided location by specifed rotation and offset
|
|
glm::dvec3 transform( glm::dvec3 Location, scene::scratch_data const &Scratchpad );
|
|
void export_nodes_to_stream( std::ostream &, bool Dirty ) const;
|
|
};
|
|
|
|
} // simulation
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
} // export
|