mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-03 13:35:26 +01:00
4657928af2
Toward loading the logic by regions (docs/world-format-eu07.md, section 13, D4). The statement table keeps the state of the tape at the start of each statement, the tape reader can move to a statement and read only to its end (parser_tape::reader::seek, with the names of all the files of the tape), and the logic cache gives the table back. With EU07_WORLD_REPLAY_ORDER set, a scenery replayed from its cache goes statement by statement, each from its place on the tape with the transformations it was read with: "file" in the order of the file, "regions" the statements of the whole package ahead of the regions, "regions-first" the regions first. A check for the developers; without the variable the tape plays through as before. The loop of deserialize_continue gives its dispatch to deserialize_statement(), and the transformations go through transformations_of() and restore_transformations(). Checked in the game (--test 120 s, seed 1, world.binary 1): - "file": the physics logs of td.scn and Glinojeck.scn the same bit for bit as from the files, so the moves on the tape and the restored transformations give the very same scenery; - "regions-first": the same bit for bit too, for both; the error logs hold the same lines in another order (the models load in another order); - "regions": td.scn ends up without vehicles, its trainsets read before the tracks they stand on. The first thing D4 has to settle: the statements of the whole package that refer to the regions go after them.
141 lines
8.6 KiB
C++
141 lines
8.6 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/.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "utilities/parser.h"
|
|
#include "world/worldlogiccache.h"
|
|
#include "scene/scene.h"
|
|
#include "scene/scenelayers.h"
|
|
|
|
namespace simulation {
|
|
|
|
struct deserializer_state {
|
|
std::string scenariofile;
|
|
// with world.binary: the tape of the logic cache the parser records, to be written when the scenery is loaded, or the bytes of
|
|
// the tape it replays and their reader
|
|
parser_tape::writer recorder;
|
|
// the statements of the scenery on the tape being recorded, with their regions
|
|
world_logic_cache::statement_table statements;
|
|
// replaying statement by statement in another order than the tape's (EU07_WORLD_REPLAY_ORDER): the table of the cache, the names
|
|
// of the files of the tape, the order and the place in it
|
|
world_logic_cache::statement_table replaytable;
|
|
std::vector<std::string> tapefiles;
|
|
std::vector<std::size_t> order;
|
|
std::size_t ordercursor { 0 };
|
|
std::string tape;
|
|
parser_tape::reader replayer;
|
|
bool recording { false };
|
|
bool replaying { false };
|
|
// the settings the tape depends on besides the files (world/worldlogiccache.h)
|
|
world_logic_cache::load_settings cachesettings;
|
|
cParser input;
|
|
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) { }
|
|
// replays the tape of the logic cache instead of reading the files
|
|
deserializer_state(std::string const &File, std::string &&Tape)
|
|
: scenariofile(File), tape(std::move(Tape)), replayer(tape), replaying(true), input(replayer) { }
|
|
};
|
|
|
|
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
|
|
// the model goes to the layer given, or to the active one with none given
|
|
TAnimModel * create_model(std::string const &src, std::string const &name, const glm::dvec3 &position, scene::layer_handle Layer = null_handle);
|
|
// places the vehicles, given as their node statements, as a trainset on the path, while the simulation runs. returns: the vehicles made
|
|
std::vector<TDynamicObject *> insert_trainset(std::string const &Name, TTrack *Path, double const Offset, std::string const &Vehicles, bool const Reversed = false);
|
|
// create new eventlauncher from node stirng
|
|
TEventLauncher * create_eventlauncher(std::string const &src, std::string const &name, const glm::dvec3 &position);
|
|
// creates model instances defined by an include directive placed or changed in the scenery editor, to show the outcome.
|
|
// everything else the included template defines is left out, and takes effect when the saved scenery is loaded.
|
|
// Context: placement in effect at the location of the directive. returns: number of created models and of skipped statements
|
|
std::pair<int, int> preview_include(std::string const &Directive, scene::layer_context const &Context, scene::layer_handle Layer, scene::instance_handle Instance);
|
|
|
|
private:
|
|
// methods
|
|
// the hash of this build for the logic cache
|
|
static std::uint64_t logic_cache_engine();
|
|
// the state of a scenery load: from its files, or from the tape of its logic cache (world.binary)
|
|
static std::shared_ptr<deserializer_state> make_deserializer_state( std::string const &Scenariofile, bool const Binaryterrain );
|
|
// the statement the keyword begins
|
|
void deserialize_statement( deserializer_state &State, std::string const &Token );
|
|
// replays the statements of the tape in the order of the state
|
|
bool deserialize_ordered( deserializer_state &State, std::chrono::steady_clock::time_point const Started );
|
|
// 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_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_weather( 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_heightmapterrain( cParser &Input, scene::scratch_data &Scratchpad );
|
|
void deserialize_editorterrain( cParser &Input, scene::scratch_data &Scratchpad );
|
|
void deserialize_endtrainset( cParser &Input, scene::scratch_data &Scratchpad );
|
|
void deserialize_reversed( 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 );
|
|
// loads a run of model instances straight from the text. returns: true if any were loaded, false if the definition at hand is left to the parser
|
|
bool deserialize_models( cParser &Input, scene::scratch_data &Scratchpad, scene::node_data &Nodedata, std::size_t Line, std::streamoff Sourcebegin );
|
|
// makes model instance defined by a scenery file a part of the simulation
|
|
void insert_model( TAnimModel *Instance, cParser const &Input, std::size_t Line, scene::source_span const &Span );
|
|
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
|
|
|
|
//---------------------------------------------------------------------------
|