mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-03 13:35:26 +01:00
ee93aa11c8
A rail vehicle running onto a switch from its frog end by the way the switch is not set to pushes its blades over. Before, the switch was just thrown to that way and nothing remembered it. Now the switch is marked as run through, the log tells it once per run-through, and the scenery can react through the memory cell and event __simulation.runthrough. With physics.derailment new the damaged switch stays out of use for the run: switch events no longer throw it, a vehicle running onto it from its points pushes the loose blades over under its first axle and runs forked (the #496 limits derail it, cause split_switch), and a run-through above 60 km/h derails the vehicle at the switch (cause run_through). In monitor mode the run does not change; the log tells what new would do. Every switch is still taken as trailable, as before.
137 lines
5.7 KiB
C++
137 lines
5.7 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 "simulation/simulationstateserializer.h"
|
|
#include "utilities/Classes.h"
|
|
#include "world/Event.h"
|
|
#include "vehicle/Train.h"
|
|
#include "rendering/particles.h"
|
|
|
|
#ifdef WITH_LUA
|
|
#include "scripting/lua.h"
|
|
#endif
|
|
|
|
namespace simulation {
|
|
|
|
class state_manager {
|
|
|
|
public:
|
|
// methods
|
|
void
|
|
init_scripting_interface();
|
|
// legacy method, calculates changes in simulation state over specified time
|
|
void
|
|
update( double Deltatime, int Iterationcount );
|
|
void
|
|
update_clocks();
|
|
void
|
|
update_scripting_interface();
|
|
// process input commands
|
|
void
|
|
process_commands();
|
|
// create model from node string
|
|
TAnimModel *
|
|
create_model(const std::string &src, const std::string &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. 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 eventlauncher from node string
|
|
TEventLauncher *
|
|
create_eventlauncher(const std::string &src, const std::string &name, const glm::dvec3 &position);
|
|
// creates model instances defined by an include directive placed in the scenery editor
|
|
std::pair<int, int>
|
|
preview_include(std::string const &Directive, scene::layer_context const &Context, scene::layer_handle Layer, scene::instance_handle Instance);
|
|
// replaces models shown for specified include with the ones defined by its current directive. Retired: receives
|
|
// the replaced models made by the editor. they're out of the scene already, but the renderer can still hold on
|
|
// to them for a few frames; pass them to Instances.purge() afterwards
|
|
std::pair<int, int>
|
|
rebuild_include(scene::instance_handle Instance, std::vector<TAnimModel *> &Retired);
|
|
// delete TAnimModel instance
|
|
void
|
|
delete_model(TAnimModel *model);
|
|
// gives TAnimModel instance another name; empty text leaves it without one. returns: false if another instance uses the name
|
|
bool
|
|
rename_model(TAnimModel *model, std::string const &name);
|
|
// delete TEventLauncher instance
|
|
void
|
|
delete_eventlauncher(TEventLauncher *launcher);
|
|
// 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;
|
|
// the vehicle derailed: the log, the black box, the test mode, and the scenery which asked for it. the scenery's
|
|
// memory cells __simulation.derailment and <vehicle>:derailed get the notice (derailment::cell_text(), value 1 the
|
|
// speed [km/h], value 2 the code of the cause) at once, then its events of those names run, the vehicle their
|
|
// activator. __simulation.derailment holds the last derailment of a frame, its event runs once, for the first:
|
|
// an event of one vehicle reads the cell of that vehicle. a scenery declares those it wants: nothing is made at the
|
|
// start, where a node made would take a draw of the random numbers and change every run
|
|
void
|
|
report_derailment( TDynamicObject const &Vehicle, derailment::notice const &Notice );
|
|
// name of the memory cell and of the event of a derailment of any vehicle
|
|
static constexpr std::string_view derailment_name { "__simulation.derailment" };
|
|
// the vehicle ran through the switch (world/switchfork.h) at the Speed [km/h]: the scenery which asked for it. its
|
|
// memory cell __simulation.runthrough gets "<switch> <vehicle>", value 1 the speed, value 2 the way the blades were
|
|
// pushed over to, then its event of that name runs, the vehicle its activator. the events <switch>:forced+ and
|
|
// <switch>:forced- of the scenery run as they always did. as with the derailment, nothing is made at the start
|
|
void
|
|
report_run_through( TTrack const &Switch, TDynamicObject const &Vehicle, double Speed );
|
|
static constexpr std::string_view run_through_name { "__simulation.runthrough" };
|
|
|
|
private:
|
|
// members
|
|
state_serializer m_serializer;
|
|
struct {
|
|
std::shared_ptr<TMemCell> weather, time, date;
|
|
// the weather report last written to __simulation.metar, to tell when something else changed it
|
|
std::string metar;
|
|
} m_scriptinginterface;
|
|
};
|
|
|
|
// passes specified sound to all vehicles within range as a radio message broadcasted on specified channel
|
|
void radio_message( sound_source *Message, int const Channel );
|
|
|
|
extern state_manager State;
|
|
extern event_manager Events;
|
|
extern memory_table Memory;
|
|
extern path_table Paths;
|
|
extern road_table Roads;
|
|
extern sweep_table Sweeps;
|
|
extern junction_table Junctions;
|
|
extern roadpoint_table Roadpoints;
|
|
extern traction_table Traction;
|
|
extern powergridsource_table Powergrid;
|
|
extern instance_table Instances;
|
|
extern vehicle_table Vehicles;
|
|
extern train_table Trains;
|
|
extern light_array Lights;
|
|
extern sound_table Sounds;
|
|
extern particle_manager Particles;
|
|
#ifdef WITH_LUA
|
|
extern lua Lua;
|
|
#endif
|
|
|
|
extern scene::basic_region *Region;
|
|
extern TTrain *Train;
|
|
|
|
extern uint16_t prev_train_id;
|
|
extern bool is_ready;
|
|
|
|
struct deserializer_state;
|
|
|
|
} // simulation
|
|
|
|
//---------------------------------------------------------------------------
|