mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-10-17 09:49:19 +02:00
Checkpoint of the editor branch so work isn't carried loose across a branch switch. Builds. - maj0sted turnout geometry moved into the domain: domain::lay_turnout lays the diverging path (pre-blade lead, blade at beta, arc of alfa-beta, frog rail) and solve_junction is a thin adapter onto it. - the maj0sted web/ tree renamed to editor/ (namespace and paths) - there is no WASM here, it's plain native C++ the editor calls. - click places the switch at its start (początek rozjazdu); the branch's leaving straight is locked tangent to the frog; switches can be slid along the through track and flipped L/P. - Polish turnout templates carry catalogue length (Id-1-consistent lengths), plus blade-angle and pre-blade fields (left 0 until the catalogue figures are in). - TURNOUT_SPEC.md: the Bezier-based runtime/model contract. - also folds in other pending branch changes (scenery, tests) to leave a clean tree.
103 lines
3.4 KiB
C++
103 lines
3.4 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/.
|
|
*/
|
|
|
|
#include "stdafx.h"
|
|
#include "application/scenarioloadermode.h"
|
|
|
|
#include "utilities/Globals.h"
|
|
#include "simulation/simulation.h"
|
|
#include "simulation/simulationtime.h"
|
|
#include "simulation/simulationenvironment.h"
|
|
#include "application/application.h"
|
|
#include "application/scenarioloaderuilayer.h"
|
|
#include "rendering/renderer.h"
|
|
#include "utilities/Logs.h"
|
|
#include "utilities/translation.h"
|
|
|
|
scenarioloader_mode::scenarioloader_mode() {
|
|
m_userinterface = std::make_shared<scenarioloader_ui>();
|
|
}
|
|
|
|
// initializes internal data structures of the mode. returns: true on success, false otherwise
|
|
bool scenarioloader_mode::init() {
|
|
// nothing to do here
|
|
return true;
|
|
}
|
|
|
|
// mode-specific update of simulation data. returns: false on error, true otherwise
|
|
bool scenarioloader_mode::update() {
|
|
if (!Global.ready_to_load)
|
|
// waiting for network connection
|
|
return true;
|
|
|
|
if (!state) {
|
|
WriteLog("using simulation seed: " + std::to_string(Global.random_seed), logtype::generic);
|
|
WriteLog("using simulation starting timestamp: " + std::to_string(Global.starting_timestamp), logtype::generic);
|
|
|
|
Application.set_title( Global.AppName + " (" + Global.SceneryFile + ")" );
|
|
WriteLog( "\nLoading scenario \"" + Global.SceneryFile + "\"..." );
|
|
|
|
timestart = std::chrono::system_clock::now();
|
|
state = simulation::State.deserialize_begin(Global.SceneryFile);
|
|
}
|
|
|
|
try {
|
|
if (simulation::State.deserialize_continue(state))
|
|
return true;
|
|
}
|
|
catch (invalid_scenery_exception &e) {
|
|
ErrorLog( "Bad init: scenario loading failed" );
|
|
state.reset();
|
|
Application.pop_mode();
|
|
}
|
|
|
|
WriteLog( "Scenario loading time: " + std::to_string( std::chrono::duration_cast<std::chrono::seconds>( std::chrono::system_clock::now() - timestart ).count() ) + " seconds" );
|
|
// TODO: implement and use next mode cue
|
|
|
|
// the mode object is kept for the next time a scenery is loaded; without dropping the context
|
|
// here, a later enter() would skip deserialize_begin and finish an already-spent parser again
|
|
state.reset();
|
|
|
|
Application.pop_mode();
|
|
// starting into the editor the simulation never runs at all: there's no driver mode underneath, so
|
|
// no physics, no AI and no timetables - just the loaded world to work on
|
|
Application.push_mode(
|
|
Global.editor_startup ?
|
|
eu07_application::mode::editor :
|
|
eu07_application::mode::driver );
|
|
|
|
return true;
|
|
}
|
|
|
|
bool scenarioloader_mode::is_command_processor() const {
|
|
return false;
|
|
}
|
|
|
|
// maintenance method, called when the mode is activated
|
|
void scenarioloader_mode::enter() {
|
|
// TBD: hide cursor in fullscreen mode?
|
|
Application.set_cursor( GLFW_CURSOR_NORMAL );
|
|
|
|
// a new map from the editor re-enters this mode while the previous load's context is still
|
|
// sitting in `state`; clear it so update() opens the file again instead of re-finishing an
|
|
// exhausted parser (Groups.close / create_map_geometry on an already-built region)
|
|
state.reset();
|
|
|
|
simulation::is_ready = false;
|
|
|
|
Application.set_title( Global.AppName + " (" + Global.SceneryFile + ")" );
|
|
m_userinterface->set_progress(STR("Loading scenery"));
|
|
}
|
|
|
|
// maintenance method, called when the mode is deactivated
|
|
void scenarioloader_mode::exit() {
|
|
simulation::Time.init( Global.starting_timestamp );
|
|
simulation::Environment.init();
|
|
}
|