17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-17 02:49:19 +02:00

feat(roads): level crossings, spawn and removal points for road vehicles, deleting points of a road

This commit is contained in:
2026-10-04 00:31:44 +02:00
parent d37dff11e1
commit 3ce9102da0
12 changed files with 2369 additions and 33 deletions

View File

@@ -26,6 +26,7 @@ http://mozilla.org/MPL/2.0/.
#include "rendering/lightarray.h"
#include "world/TractionPower.h"
#include "world/Road.h"
#include "world/RoadPoint.h"
#include "application/application.h"
#include "rendering/renderer.h"
#include "utilities/Logs.h"
@@ -182,6 +183,7 @@ state_serializer::deserialize_continue(std::shared_ptr<deserializer_state> state
// so it's inserted in the region only after that file had its chance to be written
simulation::Roads.create_geometry( Scratchpad );
simulation::Junctions.create_geometry( Scratchpad );
simulation::Roadpoints.create_geometry();
return false;
}
@@ -402,6 +404,8 @@ state_serializer::deserialize_firstinit( cParser &Input, scene::scratch_data &Sc
// the junctions tie the lanes of the roads together, what's left loose after that gets closed by the roads
simulation::Junctions.InitJunctions();
simulation::Roads.InitRoads();
// crossings and traffic points go by the lanes, which are complete at this point
simulation::Roadpoints.InitRoadpoints();
simulation::Traction.InitTraction();
simulation::Events.InitEvents();
simulation::Events.InitLaunchers();
@@ -538,6 +542,20 @@ state_serializer::deserialize_node( cParser &Input, scene::scratch_data &Scratch
scene::Groups.insert( scene::Groups.handle(), junction );
scene::Layers.track( junction, { sourcebegin, Input.TokenEnd() } );
}
else if( roadpoint_node::is_keyword( nodedata.type ) ) {
// level crossing, or a point where road vehicles appear or are taken away
auto *point { new roadpoint_node( nodedata ) };
point->import(
Input,
( Scratchpad.location.offset.empty() ?
glm::dvec3 { 0.0 } :
glm::dvec3 { Scratchpad.location.offset.top() } ) );
if( false == simulation::Roadpoints.insert( point ) ) {
ErrorLog( "Bad scenario: duplicate road point name \"" + point->name() + "\" defined in file \"" + Input.Name() + "\" (line " + std::to_string( inputline ) + ")" );
}
scene::Groups.insert( scene::Groups.handle(), point );
scene::Layers.track( point, { sourcebegin, Input.TokenEnd() } );
}
else if( nodedata.type == "traction" ) {
auto *traction { deserialize_traction( Input, Scratchpad, nodedata ) };
@@ -713,6 +731,9 @@ state_serializer::deserialize_node( cParser &Input, scene::scratch_data &Scratch
{ "track", scene::layer_item::track },
{ "road", scene::layer_item::track },
{ "junction", scene::layer_item::track },
{ "crossing", scene::layer_item::track },
{ "spawn", scene::layer_item::track },
{ "despawn", scene::layer_item::track },
{ "traction", scene::layer_item::traction },
{ "tractionpowersource", scene::layer_item::powersource },
{ "model", scene::layer_item::model },
@@ -1427,6 +1448,11 @@ state_serializer::export_nodes_to_stream(std::ostream &scmfile, bool Dirty) cons
junction->export_as_text( scmfile );
}
}
for( auto const *point : Roadpoints.sequence() ) {
if( point != nullptr && false == point->m_editorremoved && point->dirty() == Dirty && point->group() == null_handle ) {
point->export_as_text( scmfile );
}
}
// traction
scmfile << "// traction\n";
for( auto const *traction : Traction.sequence() ) {
@@ -1482,7 +1508,8 @@ TAnimModel *state_serializer::create_model(const std::string &src, const std::st
std::pair<int, int> state_serializer::preview_include(std::string const &Directive, scene::layer_context const &Context, scene::layer_handle Layer, scene::instance_handle Instance) {
// statements which take more than a single token, with the tokens ending them
static std::unordered_map<std::string, std::string> const nodeends {
{ "dynamic", "enddynamic" }, { "track", "endtrack" }, { "road", "endroad" }, { "junction", "endjunction" }, { "traction", "endtraction" }, { "tractionpowersource", "end" }, { "model", "endmodel" },
{ "dynamic", "enddynamic" }, { "track", "endtrack" }, { "road", "endroad" }, { "junction", "endjunction" }, { "crossing", "endcrossing" }, { "spawn", "endspawn" }, { "despawn", "enddespawn" },
{ "traction", "endtraction" }, { "tractionpowersource", "end" }, { "model", "endmodel" },
{ "triangles", "endtri" }, { "triangle_strip", "endtri" }, { "triangle_fan", "endtri" }, { "lines", "endline" }, { "line_strip", "endline" }, { "line_loop", "endline" },
{ "memcell", "endmemcell" }, { "eventlauncher", "end" }, { "sound", "endsound" } };
static std::unordered_map<std::string, std::string> const statementends {