mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-01 17:37:09 +01:00
test(editor): golden round trips of the tracks and of the //$ lines, the cant at the joints
The safety net of the track editor before its domain model changes (E0 of
editor-tracks-tests.md): what the editor reads from the scenery files and
writes back is read, written and read again in tests/unit, with no game data.
Tracks (test_track_text.cpp, data/tracks/). Entries written the way the game
writes them, read by TTrack::Load() and written by export_as_text(), come out
byte for byte the same, and read again give the same track field by field:
plain tracks with all their attributes (events, speed, isolated, overhead,
vradius, rail profile, friction cell), a curve with cant, radius, uneven,
buckle, cwr and sleeper models, a bridge, switches with trackbed, frogs,
movable nose, blades, uneven of both paths and timbers, a turntable, paths of
pieces, the speeds +40, -40, 0.5, 0 and none of tracks, switches and
turntables, a river, a tributary, a road and a crossing. What the game writes
otherwise than given is checked as it is (table as turn, mountain as
mountains, the length of the path, a switch heard from 10 m, the events in
order, names in lower case, model paths with forward slashes, the texture
length, rolls as floats, no overhead and no vradius left out).
The seam: TTrack built from text with no scene. The engine stubs of the tests
had none of it, so the tests link the few sources reading and writing a track
takes (world/Track.cpp, Segment.cpp, TrackUneven.cpp, MemCell.cpp,
scene/scenenode.cpp, utilities/Timer.cpp, rendering/geometrybank.cpp) and
track_stubs.cpp stands in for the rest: a renderer keeping the materials by
their names, and the scene, events, vehicles and the geometry of the rails,
which reading and writing never reach and which stop the test with their name
if one does. It tests the game's own Load() and export, where a parser of its
own would have meant rewriting Load(), and changes no code of the game. The
stub of basic_node::radius_() goes, scenenode.cpp brings the real one. The
rails don't buckle in the tests (TrackBuckle.cpp needs the environment), the
buckle declared is read and written either way; material names go through a
stand-in, the game's material manager isn't tested here.
The //$ lines (test_editor_records.cpp, data/records/). Their readers and
writers were members of editor_mode, srk_tool and the stores, with the scene
around them; they move as they were into editor/editorRecords.cpp, the one
place each kind is read and written, which the stores call (and which the
migration to the project file of E3 will need apart anyway). The methods of
scene::layer_context move into scene/scenelayercontext.cpp so it links alone.
Each kind, h r k p t w b s c o z, read from golden lines and written back comes
out the same, in the coordinates of the file and of a file placed at an
origin; //$e, the descriptions of the templates, read and saved by
editor_includes in a template in a scratch folder, leaves the file as it was.
Cant (test_cant.cpp). The paths an alignment lays roll by asin(cant/gauge),
signed with the turn, back to the cant of the line at every end; a curve the
other way rolls the other way. At a joint editor_track::match_rolls() gives
the joined track the roll for the travel across it, turned where the paths
face or stand back to back, and the track written keeps it. The inspector's
own conversion on 1500 mm stays in its lambdas here; named, as
editor_mode::cant_of_roll()/roll_of_cant(), it comes with the quick fixes.
Known bugs found, tests of the change each (doctest::should_fail, passing
until fixed, then reported to drop the decorator), data/tracks/known_lost.scn:
- angle1/angle2 are read and dropped: not written back.
- fouling1/fouling2 are read and dropped: not written back.
- name@circuit: the circuit is taken out of the name with the letter before
the @ ("tor1@iso1" becomes track "tor"; substr(0, i - 1)).
- the attributes of the entry (gauge, friction, texture sizes, speed...) are
written to 6 significant digits, a float has 9: more digits are lost on the
first save.
None in the //$ lines.
Unit tests: 957 cases before, 974 after, all passing.
This commit is contained in:
@@ -204,6 +204,7 @@ set(SOURCES
|
||||
"editor/editorSwitchStore.cpp"
|
||||
"editor/editorSwitchCurve.cpp"
|
||||
"editor/editorKilometrage.cpp"
|
||||
"editor/editorRecords.cpp"
|
||||
"editor/editorStation.cpp"
|
||||
"editor/editorSwitchDesign.cpp"
|
||||
"editor/editorConnections.cpp"
|
||||
@@ -279,6 +280,7 @@ set(SOURCES
|
||||
"application/scenarioloaderuilayer.cpp"
|
||||
"scene/scenenodegroups.cpp"
|
||||
"scene/scenelayers.cpp"
|
||||
"scene/scenelayercontext.cpp"
|
||||
"scene/scenelayerssave.cpp"
|
||||
"scene/sceneterrain.cpp"
|
||||
"scene/heightmapterrain.cpp"
|
||||
|
||||
+10
-15
@@ -16,6 +16,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include <regex>
|
||||
#include <optional>
|
||||
#include "application/editormode.h"
|
||||
#include "editor/editorRecords.hpp"
|
||||
#include "application/editormodeshared.h"
|
||||
#include "application/editorgestures.h"
|
||||
#include "scene/scenenodegroups.h"
|
||||
@@ -3267,7 +3268,7 @@ bool editor_mode::save()
|
||||
if (false == m_saved_camera.has_value() || glm::distance(m_saved_camera->first, glm::dvec3{Camera.Pos}) > 0.5 || glm::distance(m_saved_camera->second, glm::vec3{Camera.Angle}) > 0.01f)
|
||||
{
|
||||
m_saved_camera = std::make_pair(glm::dvec3{Camera.Pos}, glm::vec3{Camera.Angle});
|
||||
scene::Layers.mark(scene::layer_handle{1}, "//$c", {format("%.3f %.3f %.3f %.5f %.5f", Camera.Pos.x, Camera.Pos.y, Camera.Pos.z, Camera.Angle.x, Camera.Angle.y)});
|
||||
scene::Layers.mark(scene::layer_handle{1}, "//$c", {editor_records::camera_line({glm::dvec3{Camera.Pos}, glm::vec3{Camera.Angle}})});
|
||||
}
|
||||
if (auto const map{editor_orthophoto::mark(m_orthophoto.settings(), m_orthophoto.enabled(), m_orthophoto.settings().north != 0.0 || m_orthophoto.settings().east != 0.0)}; false == m_orthophoto_scenery.empty() && map != m_orthophoto_mark && (m_orthophoto.enabled() || false == m_orthophoto_mark.empty()))
|
||||
{
|
||||
@@ -7030,21 +7031,15 @@ void editor_mode::enter()
|
||||
{
|
||||
m_opened_at_track = true;
|
||||
auto const saved{scene::Layers.empty() ? std::vector<std::string>{} : scene::Layers.marked(scene::layer_handle{1}, "//$c")};
|
||||
if (false == saved.empty())
|
||||
if (auto const camera{editor_records::read_camera(saved)})
|
||||
{
|
||||
std::istringstream values(saved.front());
|
||||
glm::dvec3 position{0.0};
|
||||
glm::vec3 angle{0.0f};
|
||||
if (values >> position.x >> position.y >> position.z >> angle.x >> angle.y)
|
||||
{
|
||||
Camera.Pos = position;
|
||||
Camera.Angle = angle;
|
||||
Camera.m_owner = nullptr;
|
||||
FreeFlyModeFlag = true;
|
||||
Global.pCamera = Camera;
|
||||
m_saved_camera = {position, angle};
|
||||
WriteLog("Editor: camera where it was at the last save");
|
||||
}
|
||||
Camera.Pos = camera->position;
|
||||
Camera.Angle = camera->angle;
|
||||
Camera.m_owner = nullptr;
|
||||
FreeFlyModeFlag = true;
|
||||
Global.pCamera = Camera;
|
||||
m_saved_camera = {camera->position, camera->angle};
|
||||
WriteLog("Editor: camera where it was at the last save");
|
||||
}
|
||||
for (auto *track : simulation::Paths.sequence())
|
||||
{
|
||||
|
||||
@@ -43,6 +43,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include "editor/editorSpeed.hpp"
|
||||
#include "editor/editorRoad.hpp"
|
||||
#include "editor/editorProfile.hpp"
|
||||
#include "editor/editorRecords.hpp"
|
||||
#include "editor/editorGroundFollow.hpp"
|
||||
#include "editor/editorInfra.hpp"
|
||||
#include "editor/editorGauge.hpp"
|
||||
@@ -130,7 +131,8 @@ class editor_mode : public application_mode, private editor_track::observer, pri
|
||||
bool picking;
|
||||
};
|
||||
|
||||
struct stored_profile;
|
||||
// grade lines designed in the editor, kept in the scenery files as "//$p" comment lines
|
||||
using stored_profile = editor_records::grade_profile;
|
||||
struct EditorSnapshot
|
||||
{
|
||||
enum class Action { Move, Rotate, Scale, Add, Delete, TrackEdit, Other, RoadEdit, Array, Bend, Terrain, Kilometrage };
|
||||
@@ -3282,16 +3284,6 @@ class editor_mode : public application_mode, private editor_track::observer, pri
|
||||
std::string error;
|
||||
};
|
||||
profile_state m_profile;
|
||||
// grade lines designed in the editor, kept in the scenery files as "//$p" comment lines
|
||||
struct stored_profile
|
||||
{
|
||||
scene::layer_handle layer{null_handle};
|
||||
double length{0.0};
|
||||
glm::dvec3 start{0.0}, end{0.0}, middle{0.0}; // of the route, world space
|
||||
double origin{0.0};
|
||||
profile::line line;
|
||||
double departure{-1.0}; // of the track from the design when it was kept; -1 as kept by an older editor
|
||||
};
|
||||
std::vector<stored_profile> m_profiles;
|
||||
bool m_profiles_loaded{false};
|
||||
void profile_library_load();
|
||||
|
||||
@@ -12,6 +12,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "application/editormode.h"
|
||||
#include "editor/editorRecords.hpp"
|
||||
#include "application/editorprojection.h"
|
||||
#include "application/editormodeshared.h"
|
||||
#include "editor/editorFormat.hpp"
|
||||
@@ -75,7 +76,8 @@ std::string editor_mode::grade_line_key(std::string const &Name, TTrack const &T
|
||||
return format("%s@%lld,%lld", Name.c_str(), static_cast<long long>(std::llround(start.x)), static_cast<long long>(std::llround(start.z)));
|
||||
}
|
||||
|
||||
// the grade lines shared go to the scenery files as "//$w" comment lines, by those keys
|
||||
// the grade lines shared go to the scenery files as "//$w" comment lines, by those keys: editor_records::read_grade_lines() and
|
||||
// grade_line_lines()
|
||||
void editor_mode::grade_lines_load()
|
||||
{
|
||||
auto &state{m_nmt_state};
|
||||
@@ -83,18 +85,11 @@ void editor_mode::grade_lines_load()
|
||||
return;
|
||||
state.grade_lines_loaded = true;
|
||||
for (auto const layer : scene::Layers.marked_layers(kGradeLineMark))
|
||||
for (auto const &text : scene::Layers.marked(layer, kGradeLineMark))
|
||||
for (auto const &entry : editor_records::read_grade_lines(scene::Layers.marked(layer, kGradeLineMark)))
|
||||
{
|
||||
std::istringstream line{text};
|
||||
std::string keyword, name, hand;
|
||||
int number{0};
|
||||
line >> keyword >> name >> number;
|
||||
if (keyword == "gradeline" && false == line.fail())
|
||||
{
|
||||
state.grade_lines[name] = number;
|
||||
if (line >> hand && hand == "hand")
|
||||
state.grade_lines_hand.insert(name);
|
||||
}
|
||||
state.grade_lines[entry.key] = entry.number;
|
||||
if (entry.hand)
|
||||
state.grade_lines_hand.insert(entry.key);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,7 +97,7 @@ void editor_mode::grade_lines_store()
|
||||
{
|
||||
if (scene::Layers.empty())
|
||||
return;
|
||||
std::map<scene::layer_handle, std::vector<std::string>> lines;
|
||||
std::map<scene::layer_handle, std::vector<editor_records::grade_line>> lines;
|
||||
for (auto const layer : scene::Layers.marked_layers(kGradeLineMark))
|
||||
lines[layer];
|
||||
for (auto const *track : simulation::Paths.sequence())
|
||||
@@ -117,14 +112,11 @@ void editor_mode::grade_lines_store()
|
||||
auto layer{scene::Layers.resolve(track->layer())};
|
||||
if (false == scene::Layers.valid(layer) || false == scene::Layers.accepts(layer))
|
||||
layer = scene::Layers.active();
|
||||
auto &those{lines[layer]};
|
||||
if (those.empty())
|
||||
those.emplace_back("# the tracks sharing a grade line, each with the number of it; the simulation skips these lines");
|
||||
those.push_back(format("gradeline %s %d%s", key.c_str(), found->second, hand ? " hand" : ""));
|
||||
lines[layer].push_back({key, found->second, hand});
|
||||
}
|
||||
for (auto &[layer, those] : lines)
|
||||
if (scene::Layers.valid(layer))
|
||||
scene::Layers.mark(layer, kGradeLineMark, std::move(those));
|
||||
scene::Layers.mark(layer, kGradeLineMark, editor_records::grade_line_lines(those));
|
||||
}
|
||||
|
||||
bool editor_mode::on_route_grade_line(TTrack const &Track)
|
||||
|
||||
@@ -9,6 +9,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "application/editormode.h"
|
||||
#include "editor/editorRecords.hpp"
|
||||
#include "application/editorprojection.h"
|
||||
#include "application/editormodeshared.h"
|
||||
#include "editor/editorFormat.hpp"
|
||||
@@ -660,27 +661,22 @@ struct bindable_objects
|
||||
}
|
||||
};
|
||||
|
||||
// format of the lines, coordinates in the space of the file:
|
||||
// <kind> <category> <x y z of the object> <file or name, - if none> <turns 0/1> <anchor count> { <path> <start x y z> <end x y z> }
|
||||
// the object is the model, the include (position from its parameters), the traction piece (its first point), the memory
|
||||
// cell or the event launcher found at the location; the anchors name the paths by their ends
|
||||
// the object of the line, the model, the include (position from its parameters), the traction piece (its first point), the memory
|
||||
// cell or the event launcher found at the location, bound to the paths named by their ends; the lines and their format:
|
||||
// editor_records::read_binding() and binding_line()
|
||||
std::optional<infra::binding> read_binding(std::string const &Text, scene::layer_context const &Context, bindable_objects const &Objects)
|
||||
{
|
||||
double const tolerance{0.05};
|
||||
std::istringstream line{Text};
|
||||
std::string kindname;
|
||||
std::string key;
|
||||
int group{0};
|
||||
int turns{0};
|
||||
int count{0};
|
||||
glm::dvec3 location;
|
||||
line >> kindname >> group >> location.x >> location.y >> location.z >> key >> turns >> count;
|
||||
if (line.fail() || count < 1 || count > 4)
|
||||
auto const read{editor_records::read_binding(Text, Context)};
|
||||
if (false == read.has_value())
|
||||
return std::nullopt;
|
||||
location = Context.to_world(location);
|
||||
auto const &kindname{read->kind};
|
||||
auto const &key{read->key};
|
||||
auto const location{read->location};
|
||||
auto const count{static_cast<int>(read->anchors.size())};
|
||||
infra::binding binding;
|
||||
binding.group = static_cast<infra::category>(std::clamp(group, 0, static_cast<int>(infra::category::environment)));
|
||||
binding.turns = (turns != 0);
|
||||
binding.group = static_cast<infra::category>(std::clamp(read->category, 0, static_cast<int>(infra::category::environment)));
|
||||
binding.turns = read->turns;
|
||||
auto found{false};
|
||||
if (kindname == infra::name(infra::kind::model))
|
||||
{
|
||||
@@ -719,18 +715,15 @@ std::optional<infra::binding> read_binding(std::string const &Text, scene::layer
|
||||
return std::nullopt;
|
||||
for (int i = 0; i < count && found; ++i)
|
||||
{
|
||||
int path{0};
|
||||
glm::dvec3 start;
|
||||
glm::dvec3 end;
|
||||
line >> path >> start.x >> start.y >> start.z >> end.x >> end.y >> end.z;
|
||||
start = Context.to_world(start);
|
||||
end = Context.to_world(end);
|
||||
auto const path{read->anchors[i].path};
|
||||
auto const &start{read->anchors[i].start};
|
||||
auto const &end{read->anchors[i].end};
|
||||
auto const track{Objects.paths.find(start, tolerance, [&](TTrack *Track) {
|
||||
return path >= 0 && path < static_cast<int>(Track->m_paths.size()) &&
|
||||
glm::distance(Track->m_paths[path].points[segment_data::point::start], start) <= tolerance &&
|
||||
glm::distance(Track->m_paths[path].points[segment_data::point::end], end) <= tolerance;
|
||||
})};
|
||||
if (line.fail() || false == track.has_value())
|
||||
if (false == track.has_value())
|
||||
{
|
||||
found = false;
|
||||
break;
|
||||
@@ -816,24 +809,23 @@ void editor_mode::infra_store()
|
||||
layer = scene::Layers.active();
|
||||
if (false == scene::Layers.valid(layer))
|
||||
layer = 1;
|
||||
auto const &context{scene::Layers.layer(layer).context_insert()};
|
||||
auto const local = [&](glm::dvec3 const &Point) {
|
||||
auto const point{context.to_local(Point)};
|
||||
return format("%.4f %.4f %.4f", point.x, point.y, point.z);
|
||||
};
|
||||
auto text{std::string{infra::name(binding.type)} + ' ' + std::to_string(static_cast<int>(binding.group)) + ' ' + local(points.front()) + ' ' + object_key(binding) + ' ' +
|
||||
(binding.turns ? "1 " : "0 ") + std::to_string(binding.anchors.size())};
|
||||
editor_records::binding line;
|
||||
line.kind = infra::name(binding.type);
|
||||
line.category = static_cast<int>(binding.group);
|
||||
line.location = points.front();
|
||||
line.key = object_key(binding);
|
||||
line.turns = binding.turns;
|
||||
for (auto const &anchor : binding.anchors)
|
||||
{
|
||||
auto const &path{anchor.at.track->m_paths[anchor.at.path]};
|
||||
text += ' ' + std::to_string(anchor.at.path) + ' ' + local(path.points[segment_data::point::start]) + ' ' + local(path.points[segment_data::point::end]);
|
||||
line.anchors.push_back({anchor.at.path, path.points[segment_data::point::start], path.points[segment_data::point::end]});
|
||||
}
|
||||
lines[layer].push_back(std::move(text));
|
||||
lines[layer].push_back(editor_records::binding_line(line, scene::Layers.layer(layer).context_insert()));
|
||||
}
|
||||
for (auto &entry : lines)
|
||||
{
|
||||
if (false == entry.second.empty())
|
||||
entry.second.insert(entry.second.begin(), "# objects bound to the paths in the track editor, they follow changes of the track; the simulation skips these lines");
|
||||
entry.second.insert(entry.second.begin(), editor_records::binding_heading());
|
||||
scene::Layers.mark(entry.first, kBindingMark, std::move(entry.second));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include "imgui/imgui.h"
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <iterator>
|
||||
#include <cstdio>
|
||||
#include <limits>
|
||||
#include <map>
|
||||
@@ -154,12 +155,7 @@ bool sampled_chainage(std::vector<editor_track::route_sample> const &Samples, gl
|
||||
|
||||
}
|
||||
|
||||
// format of the lines, coordinates in the space of the file:
|
||||
// profile <route length> <start x y z> <end x y z> <middle x y z>
|
||||
// speed <km/h> origin <chainage of the start> join <start 0/1> <end 0/1>
|
||||
// norms <grade max> <grade over switches max> <k of R >= k*V^2> <R min> <change needing a curve> <constant grade min> <fixed tolerance>
|
||||
// point <chainage> <elevation> <vertical curve R> <automatic R 0/1>
|
||||
// end
|
||||
// the lines and their format: editor_records::read_profiles() and profile_lines()
|
||||
void editor_mode::profile_library_load()
|
||||
{
|
||||
if (m_profiles_loaded)
|
||||
@@ -167,72 +163,8 @@ void editor_mode::profile_library_load()
|
||||
m_profiles_loaded = true;
|
||||
m_profiles.clear();
|
||||
for (auto const layer : scene::Layers.marked_layers(kProfileMark))
|
||||
{
|
||||
auto const &context{scene::Layers.layer(layer).context_insert()};
|
||||
auto const height = [&](double const Local) { return context.to_world({0.0, Local, 0.0}).y; };
|
||||
std::optional<stored_profile> current;
|
||||
for (auto const &text : scene::Layers.marked(layer, kProfileMark))
|
||||
{
|
||||
std::istringstream line{text};
|
||||
std::string keyword;
|
||||
line >> keyword;
|
||||
if (keyword == "profile")
|
||||
{
|
||||
stored_profile entry;
|
||||
entry.layer = layer;
|
||||
glm::dvec3 start;
|
||||
glm::dvec3 end;
|
||||
glm::dvec3 middle;
|
||||
line >> entry.length >> start.x >> start.y >> start.z >> end.x >> end.y >> end.z >> middle.x >> middle.y >> middle.z;
|
||||
if (line.fail())
|
||||
{
|
||||
current.reset();
|
||||
continue;
|
||||
}
|
||||
entry.start = context.to_world(start);
|
||||
entry.end = context.to_world(end);
|
||||
entry.middle = context.to_world(middle);
|
||||
current = entry;
|
||||
continue;
|
||||
}
|
||||
if (false == current.has_value())
|
||||
continue;
|
||||
auto &entry{*current};
|
||||
std::string word;
|
||||
if (keyword == "speed")
|
||||
{
|
||||
int start{1};
|
||||
int end{1};
|
||||
line >> entry.line.speed >> word >> entry.origin >> word >> start >> end;
|
||||
entry.line.join_start = (start != 0);
|
||||
entry.line.join_end = (end != 0);
|
||||
}
|
||||
else if (keyword == "norms")
|
||||
{
|
||||
auto &norms{entry.line.norms};
|
||||
line >> norms.grade_max >> norms.grade_switch_max >> norms.radius_factor >> norms.radius_min >> norms.curve_threshold >> norms.element_min >> norms.fixed_tolerance;
|
||||
}
|
||||
else if (keyword == "departure")
|
||||
line >> entry.departure;
|
||||
else if (keyword == "point")
|
||||
{
|
||||
profile::pvi point;
|
||||
int automatic{0};
|
||||
line >> point.chainage >> point.elevation >> point.radius >> automatic;
|
||||
if (line.fail())
|
||||
continue;
|
||||
point.elevation = height(point.elevation);
|
||||
point.automatic = (automatic != 0);
|
||||
entry.line.points.push_back(point);
|
||||
}
|
||||
else if (keyword == "end")
|
||||
{
|
||||
if (entry.line.points.size() >= 2 && entry.length > 0.0)
|
||||
m_profiles.push_back(entry);
|
||||
current.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
for (auto &entry : editor_records::read_profiles(scene::Layers.marked(layer, kProfileMark), scene::Layers.layer(layer).context_insert(), layer))
|
||||
m_profiles.push_back(std::move(entry));
|
||||
if (false == m_profiles.empty())
|
||||
WriteLog("Editor: " + std::to_string(m_profiles.size()) + " vertical profile design(s) read from the scenery", logtype::generic);
|
||||
}
|
||||
@@ -245,29 +177,9 @@ void editor_mode::profile_library_mark(std::vector<scene::layer_handle> Layers)
|
||||
{
|
||||
if (false == scene::Layers.valid(layer))
|
||||
continue;
|
||||
auto const &context{scene::Layers.layer(layer).context_insert()};
|
||||
auto const local = [&](glm::dvec3 const &Point) {
|
||||
auto const point{context.to_local(Point)};
|
||||
return format("%.4f %.4f %.4f", point.x, point.y, point.z);
|
||||
};
|
||||
std::vector<std::string> lines;
|
||||
for (auto const &entry : m_profiles)
|
||||
{
|
||||
if (entry.layer != layer)
|
||||
continue;
|
||||
if (lines.empty())
|
||||
lines.emplace_back("# vertical profiles (grade lines) designed in the track editor, the simulation skips these lines");
|
||||
lines.push_back(format("profile %.4f ", entry.length) + local(entry.start) + ' ' + local(entry.end) + ' ' + local(entry.middle));
|
||||
lines.push_back(format("speed %.1f origin %.4f join %d %d", entry.line.speed, entry.origin, entry.line.join_start ? 1 : 0, entry.line.join_end ? 1 : 0));
|
||||
auto const &norms{entry.line.norms};
|
||||
lines.push_back(format("norms %.4f %.4f %.4f %.1f %.4f %.2f %.4f", norms.grade_max, norms.grade_switch_max, norms.radius_factor, norms.radius_min, norms.curve_threshold, norms.element_min, norms.fixed_tolerance));
|
||||
if (entry.departure >= 0.0)
|
||||
lines.push_back(format("departure %.4f", entry.departure));
|
||||
for (auto const &point : entry.line.points)
|
||||
lines.push_back(format("point %.4f %.4f %.1f %d", point.chainage, context.to_local({0.0, point.elevation, 0.0}).y, point.radius, point.automatic ? 1 : 0));
|
||||
lines.emplace_back("end");
|
||||
}
|
||||
scene::Layers.mark(layer, kProfileMark, std::move(lines));
|
||||
std::vector<stored_profile> profiles;
|
||||
std::copy_if(m_profiles.begin(), m_profiles.end(), std::back_inserter(profiles), [&](stored_profile const &Entry) { return Entry.layer == layer; });
|
||||
scene::Layers.mark(layer, kProfileMark, editor_records::profile_lines(profiles, scene::Layers.layer(layer).context_insert()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -312,18 +224,8 @@ void editor_mode::fitted_load()
|
||||
m_fitted_loaded = true;
|
||||
m_fitted.clear();
|
||||
for (auto const layer : scene::Layers.marked_layers(kFittedMark))
|
||||
for (auto const &text : scene::Layers.marked(layer, kFittedMark))
|
||||
{
|
||||
std::istringstream line{text};
|
||||
std::string keyword, name, shape, kind;
|
||||
line >> keyword >> name >> shape;
|
||||
if (keyword == "fitted" && false == line.fail())
|
||||
{
|
||||
line >> kind;
|
||||
auto const value{std::strtoull(shape.c_str(), nullptr, 16)};
|
||||
m_fitted[{name, value}] = {layer, value, kind == "hand"};
|
||||
}
|
||||
}
|
||||
for (auto const &fitted : editor_records::read_fitted(scene::Layers.marked(layer, kFittedMark)))
|
||||
m_fitted[{fitted.name, fitted.shape}] = {layer, fitted.shape, fitted.hand};
|
||||
}
|
||||
|
||||
void editor_mode::fitted_set(std::vector<TTrack *> const &Tracks, bool const Hand)
|
||||
@@ -362,16 +264,11 @@ void editor_mode::fitted_set(std::vector<TTrack *> const &Tracks, bool const Han
|
||||
{
|
||||
if (false == scene::Layers.valid(layer))
|
||||
continue;
|
||||
std::vector<std::string> lines;
|
||||
std::vector<editor_records::fitted_track> tracks;
|
||||
for (auto const &[key, mark] : m_fitted)
|
||||
{
|
||||
if (mark.layer != layer || false == standing.contains(key))
|
||||
continue;
|
||||
if (lines.empty())
|
||||
lines.emplace_back("# the tracks whose grade line was fitted in the track editor, with their shape then; the simulation skips these lines");
|
||||
lines.push_back(format("fitted %s %016llx%s", key.first.c_str(), static_cast<unsigned long long>(mark.shape), mark.hand ? " hand" : ""));
|
||||
}
|
||||
scene::Layers.mark(layer, kFittedMark, std::move(lines));
|
||||
if (mark.layer == layer && standing.contains(key))
|
||||
tracks.push_back({key.first, mark.shape, mark.hand});
|
||||
scene::Layers.mark(layer, kFittedMark, editor_records::fitted_lines(tracks));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -110,11 +110,6 @@ std::string word_of(std::string const &Text)
|
||||
return result.empty() ? std::string{"-"} : result;
|
||||
}
|
||||
|
||||
std::string shown(std::string const &Word)
|
||||
{
|
||||
return Word == "-" ? std::string{} : Word;
|
||||
}
|
||||
|
||||
// the number of the switch of a unit: of its name once named after the station, of its record, else of its place
|
||||
std::string unit_number(station::unit const &Unit, std::string const &Stem, std::size_t const Index)
|
||||
{
|
||||
@@ -875,76 +870,28 @@ void srk_tool::load()
|
||||
m_records.clear();
|
||||
if (scene::Layers.empty())
|
||||
return;
|
||||
// the lines and their format: editor_records::read_station() and station_lines()
|
||||
for (auto const layer : scene::Layers.marked_layers(kMark))
|
||||
for (auto const &text : scene::Layers.marked(layer, kMark))
|
||||
{
|
||||
std::istringstream words{text};
|
||||
std::string word;
|
||||
if ((words >> word).fail() || word != "station")
|
||||
auto read{editor_records::read_station(text)};
|
||||
if (false == read.has_value())
|
||||
continue;
|
||||
record entry;
|
||||
entry.layer = layer;
|
||||
words >> entry.code;
|
||||
while (words >> word)
|
||||
{
|
||||
if (word == "line")
|
||||
words >> entry.line;
|
||||
else if (word == "km")
|
||||
words >> entry.km;
|
||||
else if (word == "from")
|
||||
entry.reversed = (words >> word) && word == "right";
|
||||
else if (word == "braking")
|
||||
words >> entry.braking;
|
||||
else if (word == "blocks" && words >> word)
|
||||
for (std::size_t from = 0; from < word.size();)
|
||||
{
|
||||
auto const comma{std::min(word.find(',', from), word.size())};
|
||||
auto const item{word.substr(from, comma - from)};
|
||||
if (auto const equals{item.find('=')}; equals != std::string::npos && equals > 0)
|
||||
{
|
||||
auto const kind{item.substr(equals + 1)};
|
||||
entry.blocks[item.substr(0, equals)] = kind == "sbl4" ? block_kind::four : kind == "sbl" || kind == "sbl3" ? block_kind::three : block_kind::semi;
|
||||
}
|
||||
from = comma + 1;
|
||||
}
|
||||
else if (word == "ways" && words >> word)
|
||||
for (std::size_t from = 0; from < word.size();)
|
||||
{
|
||||
auto const comma{std::min(word.find(',', from), word.size())};
|
||||
auto const item{word.substr(from, comma - from)};
|
||||
if (auto const equals{item.find('=')}; equals != std::string::npos && equals > 0)
|
||||
entry.ways[item.substr(0, equals)] = item.substr(equals + 1) == "2";
|
||||
from = comma + 1;
|
||||
}
|
||||
else if (word == "joints" && words >> word)
|
||||
// +x/y/z for one put by hand, -x/y/z for a planned one taken away
|
||||
for (std::size_t from = 0; from < word.size();)
|
||||
{
|
||||
auto const comma{std::min(word.find(',', from), word.size())};
|
||||
auto const item{word.substr(from, comma - from)};
|
||||
glm::dvec3 point{0.0};
|
||||
if (item.size() > 1 && (item.front() == '+' || item.front() == '-') && std::sscanf(item.c_str() + 1, "%lf/%lf/%lf", &point.x, &point.y, &point.z) == 3)
|
||||
(item.front() == '+' ? entry.joints_added : entry.joints_removed).push_back(point);
|
||||
from = comma + 1;
|
||||
}
|
||||
else if (word == "anchor")
|
||||
words >> entry.anchor;
|
||||
else if (word == "name")
|
||||
{
|
||||
std::getline(words, entry.name);
|
||||
entry.name.erase(0, entry.name.find_first_not_of(' '));
|
||||
// windows-1250 like the rest of the scenery file; earlier builds wrote it in utf-8, which stays as it is
|
||||
if (std::u32string decoded; false == utf8_to_utf32(entry.name, decoded))
|
||||
entry.name = win1250_to_utf8(entry.name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
entry.code = shown(entry.code);
|
||||
entry.line = shown(entry.line);
|
||||
entry.km = shown(entry.km);
|
||||
entry.anchor = std::move(read->anchor);
|
||||
entry.code = std::move(read->code);
|
||||
entry.name = std::move(read->name);
|
||||
entry.line = std::move(read->line);
|
||||
entry.km = std::move(read->km);
|
||||
entry.reversed = read->reversed;
|
||||
entry.braking = read->braking;
|
||||
entry.blocks = std::move(read->blocks);
|
||||
entry.ways = std::move(read->ways);
|
||||
entry.joints_added = std::move(read->joints_added);
|
||||
entry.joints_removed = std::move(read->joints_removed);
|
||||
entry.track = simulation::Paths.find(entry.anchor);
|
||||
if (false == entry.anchor.empty())
|
||||
m_records.push_back(std::move(entry));
|
||||
m_records.push_back(std::move(entry));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -959,29 +906,11 @@ void srk_tool::store()
|
||||
layers.push_back(entry.layer);
|
||||
for (auto const layer : layers)
|
||||
{
|
||||
std::vector<std::string> lines;
|
||||
std::vector<editor_records::station> stations;
|
||||
for (auto const &entry : m_records)
|
||||
{
|
||||
if (entry.layer != layer)
|
||||
continue;
|
||||
if (lines.empty())
|
||||
lines.emplace_back("# stations described in the track editor, the simulation skips these lines");
|
||||
auto const braking{entry.braking > 0 ? format(" braking %d", entry.braking) : std::string{}};
|
||||
std::string blocks;
|
||||
for (auto const &[signal, kind] : entry.blocks)
|
||||
if (false == signal.empty() && signal.find_first_of(" ,=\t") == std::string::npos)
|
||||
blocks += (blocks.empty() ? " blocks " : ",") + signal + (kind == block_kind::four ? "=sbl4" : kind == block_kind::three ? "=sbl" : "=semi");
|
||||
std::string ways;
|
||||
for (auto const &[signal, both] : entry.ways)
|
||||
if (false == signal.empty() && signal.find_first_of(" ,=\t") == std::string::npos)
|
||||
ways += (ways.empty() ? " ways " : ",") + signal + (both ? "=2" : "=1");
|
||||
std::string joints;
|
||||
for (auto const *list : {&entry.joints_added, &entry.joints_removed})
|
||||
for (auto const &point : *list)
|
||||
joints += (joints.empty() ? " joints " : ",") + format("%c%.3f/%.3f/%.3f", list == &entry.joints_added ? '+' : '-', point.x, point.y, point.z);
|
||||
lines.push_back(format("station %s line %s km %s from %s anchor %s%s%s%s%s name %s", word_of(entry.code).c_str(), word_of(entry.line).c_str(), word_of(entry.km).c_str(), entry.reversed ? "right" : "left", anchor_of(entry).c_str(), braking.c_str(), blocks.c_str(), ways.c_str(), joints.c_str(), utf8_to_win1250(entry.name).c_str()));
|
||||
}
|
||||
scene::Layers.mark(layer, kMark, std::move(lines));
|
||||
if (entry.layer == layer)
|
||||
stations.push_back({anchor_of(entry), entry.code, entry.name, entry.line, entry.km, entry.reversed, entry.braking, entry.blocks, entry.ways, entry.joints_added, entry.joints_removed});
|
||||
scene::Layers.mark(layer, kMark, editor_records::station_lines(stations));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
#pragma once
|
||||
|
||||
#include "application/editortool.h"
|
||||
#include "editor/editorRecords.hpp"
|
||||
#include "editor/editorStation.hpp"
|
||||
#include "scene/scenelayers.h"
|
||||
|
||||
@@ -84,13 +85,8 @@ class srk_tool final : public editor_tool
|
||||
editor_templates &m_templates;
|
||||
editor_signals &m_signals;
|
||||
editor_guide &m_guide;
|
||||
// the block of a line out of the station
|
||||
enum class block_kind
|
||||
{
|
||||
semi, // semi-automatic: a warning disc before the entry signal
|
||||
three, // the automatic one of three aspects: the block sections no shorter than the braking distance
|
||||
four // of four aspects, the warning two signals ahead: the sections no shorter than half of it
|
||||
};
|
||||
// the block of a line out of the station: semi-automatic, the automatic one of three aspects, of four, as the //$s lines keep it
|
||||
using block_kind = editor_records::block_kind;
|
||||
// where the block of a line out of the station comes from
|
||||
enum class block_reason
|
||||
{
|
||||
|
||||
@@ -11,6 +11,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include "editor/editorAlignmentStore.hpp"
|
||||
#include "editor/editorFormat.hpp"
|
||||
#include "editor/editorGeometry.hpp"
|
||||
#include "editor/editorRecords.hpp"
|
||||
|
||||
#include "world/Track.h"
|
||||
#include "simulation/simulation.h"
|
||||
@@ -18,6 +19,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <iterator>
|
||||
#include <limits>
|
||||
#include <map>
|
||||
#include <set>
|
||||
@@ -39,42 +41,7 @@ std::vector<record> g_base; // as they were before the changes not yet in the un
|
||||
bool g_changed{false};
|
||||
bool g_loaded{false};
|
||||
|
||||
// format of the lines, coordinates in the space of the file:
|
||||
// alignment <start x y z> <end x y z>
|
||||
// source <designed> origin <chainage of the start> shape <parabola|clothoid> speed <km/h> [fit <m>]
|
||||
// ends <start direction x z> <end direction x z> <start grade> <end grade> <start R> <end R>
|
||||
// norms <gauge> <unbalanced> <cant max> <cant rate> <ramp factor> <jerk> <straight between curves, s> <arc min> <arc min factor>
|
||||
// pieces <pieces of a transition> <angle of an arc piece>
|
||||
// vertex <x> <z> <offset> <R> <L in> <L out> <cant> <reverse 0/1> <compound 0/1> <share> <arcs> [<R> <L> <share>]... [spirals 1]
|
||||
// spirals: two transition curves with no arc between them, their lengths following from R
|
||||
// [cants <first> <arc>...]: the cants of the radii of a compound curve set one by one, below 0 the cant in proportion to the curvature
|
||||
// [ramps <in offset> <in length> <out offset> <out length>]: the cant ramps of the curve where they don't go along its transitions,
|
||||
// their outer ends from the start and from the end of the curve, into it above 0; a length below 0 keeps the ramp along the transition
|
||||
// click <x y z>: a point clicked when the line was laid, its curves fitted to them
|
||||
// kept <from> <to>: the stretch of the line the design is kept for, chainages from its start, where tracks along it were deleted
|
||||
// element <straight|transition|arc> <vertex> <chainage> <length> <R at the start> <R at the end> <cant> <start x> <start z> <direction x> <direction z>
|
||||
// radii signed with the turn, 0 for no curvature
|
||||
// end
|
||||
char const *shape_name(alignment::transition_shape const Shape)
|
||||
{
|
||||
return Shape == alignment::transition_shape::clothoid ? "clothoid" : "parabola";
|
||||
}
|
||||
|
||||
glm::dvec2 local_direction(scene::layer_context const &Context, glm::dvec3 const &Point, glm::dvec2 const &Direction)
|
||||
{
|
||||
auto const from{Context.to_local(Point)};
|
||||
auto const to{Context.to_local(Point + glm::dvec3{Direction.x, 0.0, Direction.y})};
|
||||
auto const direction{plan_of(to - from)};
|
||||
return glm::length(direction) > 1e-12 ? glm::normalize(direction) : Direction;
|
||||
}
|
||||
|
||||
glm::dvec2 world_direction(scene::layer_context const &Context, glm::dvec3 const &Local, glm::dvec2 const &Direction)
|
||||
{
|
||||
auto const from{Context.to_world(Local)};
|
||||
auto const to{Context.to_world(Local + glm::dvec3{Direction.x, 0.0, Direction.y})};
|
||||
auto const direction{plan_of(to - from)};
|
||||
return glm::length(direction) > 1e-12 ? glm::normalize(direction) : Direction;
|
||||
}
|
||||
// the lines and their format: editor_records::read_alignments() and alignment_lines()
|
||||
|
||||
// the points of the line every kStep from the start of the stretch it's kept for
|
||||
void sample(record &Record)
|
||||
@@ -116,67 +83,9 @@ void mark(scene::layer_handle const Layer)
|
||||
{
|
||||
if (false == scene::Layers.valid(Layer))
|
||||
return;
|
||||
auto const &context{scene::Layers.layer(Layer).context_insert()};
|
||||
auto const local = [&](glm::dvec3 const &Point) {
|
||||
auto const point{context.to_local(Point)};
|
||||
return format("%.4f %.4f %.4f", point.x, point.y, point.z);
|
||||
};
|
||||
std::vector<std::string> lines;
|
||||
for (auto const &entry : g_records)
|
||||
{
|
||||
if (entry.layer != Layer)
|
||||
continue;
|
||||
if (lines.empty())
|
||||
lines.emplace_back("# horizontal alignments designed in the track editor, the simulation skips these lines");
|
||||
auto const &design{entry.design};
|
||||
lines.push_back("alignment " + local(design.start) + ' ' + local(design.end));
|
||||
lines.push_back(format("source %s origin %.4f shape %s speed %.1f", entry.source.c_str(), entry.origin, shape_name(design.shape), design.speed) + (entry.fit > 0.0 ? format(" fit %.3f", entry.fit) : std::string{}));
|
||||
auto const startdirection{local_direction(context, design.start, design.start_direction)};
|
||||
auto const enddirection{local_direction(context, design.end, design.end_direction)};
|
||||
auto ends{format("ends %.9f %.9f %.9f %.9f %.6f %.6f %.3f %.3f", startdirection.x, startdirection.y, enddirection.x, enddirection.y, design.start_grade, design.end_grade, design.start_radius, design.end_radius)};
|
||||
// the sides the adjoining tracks turn to, and the curves going on from them with their cants, written since there are such
|
||||
if (design.start_turn != 0 || design.end_turn != 0)
|
||||
ends += format(" turns %d %d", design.start_turn, design.end_turn);
|
||||
if (design.start_curved || design.end_curved)
|
||||
ends += format(" curved %d %d %.1f %.1f", design.start_curved ? 1 : 0, design.end_curved ? 1 : 0, design.start_cant, design.end_cant);
|
||||
lines.push_back(ends);
|
||||
auto const &norms{design.norms};
|
||||
lines.push_back(format("norms %.1f %.3f %.1f %.1f %.2f %.3f %.2f %.2f %.3f", norms.gauge, norms.unbalanced, norms.cant_max, norms.cant_rate, norms.ramp_factor, norms.jerk, norms.tangent_min_time, norms.arc_min, norms.arc_min_factor));
|
||||
lines.push_back(format("pieces %d %.3f", design.transition_pieces, design.arc_piece_angle));
|
||||
if (false == entry.whole())
|
||||
lines.push_back(format("kept %.4f %.4f", entry.from, entry.kept_to()));
|
||||
for (auto const &vertex : design.vertices)
|
||||
{
|
||||
auto const position{context.to_local({vertex.position.x, 0.0, vertex.position.y})};
|
||||
auto text{format("vertex %.4f %.4f %.4f %.3f %.3f %.3f %.1f %d %d %.9f %zu", position.x, position.z, vertex.offset, vertex.radius, vertex.transition_in, vertex.transition_out, vertex.cant, vertex.reverse_turn ? 1 : 0, vertex.compound ? 1 : 0,
|
||||
vertex.share, vertex.arcs.size())};
|
||||
for (auto const &arc : vertex.arcs)
|
||||
text += format(" %.3f %.3f %.9f", arc.radius, arc.transition, arc.share);
|
||||
if (vertex.spirals)
|
||||
text += " spirals 1";
|
||||
if (vertex.first_cant >= 0.0 || std::any_of(vertex.arcs.begin(), vertex.arcs.end(), [](alignment::compound_arc const &Arc) { return Arc.cant >= 0.0; }))
|
||||
{
|
||||
text += format(" cants %.1f", vertex.first_cant);
|
||||
for (auto const &arc : vertex.arcs)
|
||||
text += format(" %.1f", arc.cant);
|
||||
}
|
||||
if (vertex.own_ramps())
|
||||
text += format(" ramps %.3f %.3f %.3f %.3f", vertex.ramp_in_offset, vertex.ramp_in_length, vertex.ramp_out_offset, vertex.ramp_out_length);
|
||||
lines.push_back(text);
|
||||
}
|
||||
for (auto const &click : entry.clicks)
|
||||
lines.push_back("click " + local(click));
|
||||
for (auto const &e : entry.result.elements)
|
||||
{
|
||||
auto const station{alignment::evaluate(entry.result, e.chainage)};
|
||||
auto const start{context.to_local(station.position)};
|
||||
auto const direction{local_direction(context, station.position, glm::normalize(plan_of(station.direction)))};
|
||||
auto const element{describe(e)};
|
||||
lines.push_back(format("element %s %d %.4f %.4f %.3f %.3f %.1f %.4f %.4f %.9f %.9f", element.kind.c_str(), element.vertex, element.chainage, element.length, element.radius_start, element.radius_end, element.cant, start.x, start.z, direction.x, direction.y));
|
||||
}
|
||||
lines.emplace_back("end");
|
||||
}
|
||||
scene::Layers.mark(Layer, kMark, std::move(lines));
|
||||
std::vector<record> records;
|
||||
std::copy_if(g_records.begin(), g_records.end(), std::back_inserter(records), [&](record const &Entry) { return Entry.layer == Layer; });
|
||||
scene::Layers.mark(Layer, kMark, editor_records::alignment_lines(records, scene::Layers.layer(Layer).context_insert()));
|
||||
}
|
||||
|
||||
// the vertex as seen from the other end of the line
|
||||
@@ -269,43 +178,7 @@ int merge(record const &Entry)
|
||||
|
||||
} // namespace
|
||||
|
||||
stored_element describe(alignment::element const &Element)
|
||||
{
|
||||
stored_element result;
|
||||
result.vertex = Element.vertex;
|
||||
result.chainage = Element.chainage;
|
||||
result.length = Element.length;
|
||||
result.cant = Element.cant;
|
||||
auto const sign{Element.turn < 0 ? -1.0 : 1.0};
|
||||
auto const radius = [&](double const Curvature) { return Curvature > 1e-12 ? sign / Curvature : 0.0; };
|
||||
switch (Element.kind)
|
||||
{
|
||||
case alignment::element_kind::transition_in:
|
||||
result.radius_end = sign * Element.radius;
|
||||
break;
|
||||
case alignment::element_kind::arc:
|
||||
result.radius_end = sign * Element.radius;
|
||||
result.radius_start = result.radius_end;
|
||||
break;
|
||||
case alignment::element_kind::transition_out:
|
||||
result.radius_start = sign * Element.radius;
|
||||
break;
|
||||
case alignment::element_kind::spiral:
|
||||
result.radius_start = radius(Element.curvature_start);
|
||||
result.radius_end = radius(Element.curvature_end);
|
||||
break;
|
||||
default:
|
||||
result.cant = 0.0;
|
||||
break;
|
||||
}
|
||||
if (result.radius_start == 0.0 && result.radius_end == 0.0)
|
||||
result.kind = "straight";
|
||||
else if (std::abs(result.radius_start - result.radius_end) < 1e-6)
|
||||
result.kind = "arc";
|
||||
else
|
||||
result.kind = "transition";
|
||||
return result;
|
||||
}
|
||||
// describe(): with the lines, editor/editorRecords.cpp
|
||||
|
||||
void reset()
|
||||
{
|
||||
@@ -318,125 +191,6 @@ void reset()
|
||||
namespace
|
||||
{
|
||||
|
||||
std::optional<record> read_start(std::istringstream &Line, scene::layer_context const &Context, scene::layer_handle const Layer)
|
||||
{
|
||||
record entry;
|
||||
entry.layer = Layer;
|
||||
glm::dvec3 start;
|
||||
glm::dvec3 end;
|
||||
Line >> start.x >> start.y >> start.z >> end.x >> end.y >> end.z;
|
||||
if (Line.fail())
|
||||
return std::nullopt;
|
||||
entry.design.start = Context.to_world(start);
|
||||
entry.design.end = Context.to_world(end);
|
||||
return entry;
|
||||
}
|
||||
|
||||
std::optional<alignment::vertex> read_vertex(std::istringstream &Line, scene::layer_context const &Context)
|
||||
{
|
||||
alignment::vertex vertex;
|
||||
glm::dvec3 position{0.0};
|
||||
int reverse{0};
|
||||
int compound{0};
|
||||
std::size_t arcs{0};
|
||||
Line >> position.x >> position.z >> vertex.offset >> vertex.radius >> vertex.transition_in >> vertex.transition_out >> vertex.cant >> reverse >> compound >> vertex.share >> arcs;
|
||||
for (std::size_t i = 0; i < arcs && false == Line.fail(); ++i)
|
||||
{
|
||||
alignment::compound_arc arc;
|
||||
Line >> arc.radius >> arc.transition >> arc.share;
|
||||
vertex.arcs.push_back(arc);
|
||||
}
|
||||
if (Line.fail())
|
||||
return std::nullopt;
|
||||
// written since the bends of the straights are eased with two transition curves, the lines of before end with the arcs
|
||||
for (std::string word; Line >> word;)
|
||||
{
|
||||
if (int value{0}; word == "spirals" && Line >> value)
|
||||
vertex.spirals = (value != 0);
|
||||
// the cants of the arcs of a compound curve, set one by one: of the first arc and of the ones after it, below 0 in proportion
|
||||
if (word == "cants")
|
||||
{
|
||||
Line >> vertex.first_cant;
|
||||
for (auto &arc : vertex.arcs)
|
||||
Line >> arc.cant;
|
||||
}
|
||||
if (word == "ramps")
|
||||
Line >> vertex.ramp_in_offset >> vertex.ramp_in_length >> vertex.ramp_out_offset >> vertex.ramp_out_length;
|
||||
}
|
||||
position = Context.to_world(position);
|
||||
vertex.position = {position.x, position.z};
|
||||
vertex.reverse_turn = (reverse != 0);
|
||||
vertex.compound = (compound != 0);
|
||||
return vertex;
|
||||
}
|
||||
|
||||
void read_part(record &Entry, std::string const &Keyword, std::istringstream &Line, scene::layer_context const &Context)
|
||||
{
|
||||
auto &design{Entry.design};
|
||||
std::string word;
|
||||
if (Keyword == "source")
|
||||
{
|
||||
std::string shape;
|
||||
Line >> Entry.source >> word >> Entry.origin >> word >> shape >> word >> design.speed;
|
||||
design.shape = shape == "clothoid" ? alignment::transition_shape::clothoid : alignment::transition_shape::cubic_parabola;
|
||||
if (Line >> word && word == "fit")
|
||||
Line >> Entry.fit;
|
||||
}
|
||||
else if (Keyword == "ends")
|
||||
{
|
||||
glm::dvec2 startdirection;
|
||||
glm::dvec2 enddirection;
|
||||
Line >> startdirection.x >> startdirection.y >> enddirection.x >> enddirection.y >> design.start_grade >> design.end_grade >> design.start_radius >> design.end_radius;
|
||||
design.start_direction = world_direction(Context, Context.to_local(design.start), startdirection);
|
||||
design.end_direction = world_direction(Context, Context.to_local(design.end), enddirection);
|
||||
for (std::string key; Line >> key;)
|
||||
{
|
||||
if (key == "turns")
|
||||
Line >> design.start_turn >> design.end_turn;
|
||||
if (int start{0}, end{0}; key == "curved" && Line >> start >> end >> design.start_cant >> design.end_cant)
|
||||
{
|
||||
design.start_curved = (start != 0);
|
||||
design.end_curved = (end != 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (Keyword == "norms")
|
||||
{
|
||||
auto &norms{design.norms};
|
||||
Line >> norms.gauge >> norms.unbalanced >> norms.cant_max >> norms.cant_rate >> norms.ramp_factor >> norms.jerk >> norms.tangent_min_time >> norms.arc_min >> norms.arc_min_factor;
|
||||
}
|
||||
else if (Keyword == "pieces")
|
||||
Line >> design.transition_pieces >> design.arc_piece_angle;
|
||||
else if (Keyword == "vertex")
|
||||
{
|
||||
if (auto const vertex{read_vertex(Line, Context)})
|
||||
design.vertices.push_back(*vertex);
|
||||
}
|
||||
else if (Keyword == "element")
|
||||
{
|
||||
stored_element e;
|
||||
Line >> e.kind >> e.vertex >> e.chainage >> e.length >> e.radius_start >> e.radius_end >> e.cant;
|
||||
if (false == Line.fail())
|
||||
Entry.elements.push_back(e);
|
||||
}
|
||||
else if (Keyword == "click")
|
||||
{
|
||||
glm::dvec3 point;
|
||||
if (Line >> point.x >> point.y >> point.z)
|
||||
Entry.clicks.push_back(Context.to_world(point));
|
||||
}
|
||||
else if (Keyword == "kept")
|
||||
{
|
||||
double from;
|
||||
double to;
|
||||
if (Line >> from >> to && to > from)
|
||||
{
|
||||
Entry.from = std::max(0.0, from);
|
||||
Entry.to = to;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void close_record(record &Entry, std::string const &Layer)
|
||||
{
|
||||
finish(Entry);
|
||||
@@ -453,25 +207,8 @@ void close_record(record &Entry, std::string const &Layer)
|
||||
|
||||
void load_layer(scene::layer_handle const Layer)
|
||||
{
|
||||
auto const &context{scene::Layers.layer(Layer).context_insert()};
|
||||
std::optional<record> current;
|
||||
for (auto const &text : scene::Layers.marked(Layer, kMark))
|
||||
{
|
||||
std::istringstream line{text};
|
||||
std::string keyword;
|
||||
line >> keyword;
|
||||
if (keyword == "alignment")
|
||||
current = read_start(line, context, Layer);
|
||||
else if (false == current.has_value())
|
||||
continue;
|
||||
else if (keyword == "end")
|
||||
{
|
||||
close_record(*current, scene::Layers.layer(Layer).name);
|
||||
current.reset();
|
||||
}
|
||||
else
|
||||
read_part(*current, keyword, line, context);
|
||||
}
|
||||
for (auto &entry : editor_records::read_alignments(scene::Layers.marked(Layer, kMark), scene::Layers.layer(Layer).context_insert(), Layer))
|
||||
close_record(entry, scene::Layers.layer(Layer).name);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -9,6 +9,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "editor/editorKilometrage.hpp"
|
||||
#include "editor/editorRecords.hpp"
|
||||
#include "editor/editorAlignmentStore.hpp"
|
||||
#include "editor/editorFormat.hpp"
|
||||
#include "editor/editorGeometry.hpp"
|
||||
@@ -66,47 +67,16 @@ void drop_axes()
|
||||
|
||||
using span = editor_track::route_span;
|
||||
|
||||
std::string word(std::string const &Text)
|
||||
{
|
||||
return Text.empty() ? std::string{"-"} : Text;
|
||||
}
|
||||
|
||||
// format of the lines, coordinates in the space of the file:
|
||||
// mark <line> <x y z> way <x z> km <km> [beyond <km>]
|
||||
// via <line> <x y z>
|
||||
// the lines and their format: editor_records::read_kilometrage() and kilometrage_lines()
|
||||
void store(scene::layer_handle const Layer)
|
||||
{
|
||||
if (false == scene::Layers.valid(Layer))
|
||||
return;
|
||||
auto const &context{scene::Layers.layer(Layer).context_insert()};
|
||||
std::vector<std::string> lines;
|
||||
auto const heading = [&]() {
|
||||
if (lines.empty())
|
||||
lines.emplace_back("# kilometrage of the lines set in the track editor, the simulation skips these lines");
|
||||
};
|
||||
for (auto const &entry : g_marks)
|
||||
{
|
||||
if (entry.layer != Layer)
|
||||
continue;
|
||||
heading();
|
||||
auto const point{context.to_local(entry.point)};
|
||||
auto const ahead{context.to_local(entry.point + glm::dvec3{entry.way.x, 0.0, entry.way.y})};
|
||||
auto way{plan_of(ahead - point)};
|
||||
way = glm::length(way) > 1e-12 ? glm::normalize(way) : entry.way;
|
||||
auto text{format("mark %s %.4f %.4f %.4f way %.9f %.9f km %.3f", word(entry.line).c_str(), point.x, point.y, point.z, way.x, way.y, entry.km)};
|
||||
if (entry.beyond.has_value())
|
||||
text += format(" beyond %.3f", *entry.beyond);
|
||||
lines.push_back(text);
|
||||
}
|
||||
for (auto const &entry : g_vias)
|
||||
{
|
||||
if (entry.layer != Layer)
|
||||
continue;
|
||||
heading();
|
||||
auto const point{context.to_local(entry.point)};
|
||||
lines.push_back(format("via %s %.4f %.4f %.4f", word(entry.line).c_str(), point.x, point.y, point.z));
|
||||
}
|
||||
scene::Layers.mark(Layer, kMark, std::move(lines));
|
||||
std::vector<mark> marks;
|
||||
std::copy_if(g_marks.begin(), g_marks.end(), std::back_inserter(marks), [&](mark const &Entry) { return Entry.layer == Layer; });
|
||||
std::vector<via> vias;
|
||||
std::copy_if(g_vias.begin(), g_vias.end(), std::back_inserter(vias), [&](via const &Entry) { return Entry.layer == Layer; });
|
||||
scene::Layers.mark(Layer, kMark, editor_records::kilometrage_lines(marks, vias, scene::Layers.layer(Layer).context_insert()));
|
||||
}
|
||||
|
||||
void changed(std::set<scene::layer_handle> const &Layers)
|
||||
@@ -606,47 +576,7 @@ void load()
|
||||
g_vias.clear();
|
||||
drop_axes();
|
||||
for (auto const layer : scene::Layers.marked_layers(kMark))
|
||||
{
|
||||
auto const &context{scene::Layers.layer(layer).context_insert()};
|
||||
for (auto const &text : scene::Layers.marked(layer, kMark))
|
||||
{
|
||||
std::istringstream line{text};
|
||||
std::string keyword;
|
||||
mark entry;
|
||||
entry.layer = layer;
|
||||
glm::dvec3 point{0.0};
|
||||
glm::dvec2 way{0.0, 1.0};
|
||||
line >> keyword;
|
||||
if (keyword == "via")
|
||||
{
|
||||
via entry;
|
||||
entry.layer = layer;
|
||||
glm::dvec3 point{0.0};
|
||||
line >> entry.line >> point.x >> point.y >> point.z;
|
||||
if (line.fail() || entry.line.empty())
|
||||
continue;
|
||||
entry.point = context.to_world(point);
|
||||
g_vias.push_back(std::move(entry));
|
||||
continue;
|
||||
}
|
||||
if (keyword != "mark")
|
||||
continue;
|
||||
line >> entry.line >> point.x >> point.y >> point.z >> keyword >> way.x >> way.y >> keyword >> entry.km;
|
||||
if (line.fail() || entry.line.empty() || false == std::isfinite(entry.km))
|
||||
continue;
|
||||
while (line >> keyword)
|
||||
if (keyword == "beyond")
|
||||
{
|
||||
double beyond{0.0};
|
||||
if (line >> beyond)
|
||||
entry.beyond = beyond;
|
||||
}
|
||||
entry.point = context.to_world(point);
|
||||
entry.way = plan_of(context.to_world(point + glm::dvec3{way.x, 0.0, way.y}) - entry.point);
|
||||
entry.way = glm::length(entry.way) > 1e-12 ? glm::normalize(entry.way) : glm::dvec2{0.0, 1.0};
|
||||
g_marks.push_back(std::move(entry));
|
||||
}
|
||||
}
|
||||
editor_records::read_kilometrage(scene::Layers.marked(layer, kMark), scene::Layers.layer(layer).context_insert(), layer, g_marks, g_vias);
|
||||
g_base = current();
|
||||
g_changed = false;
|
||||
if (false == g_marks.empty())
|
||||
|
||||
@@ -11,6 +11,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include "editor/editorOrthophoto.hpp"
|
||||
#include "editor/editorHttp.hpp"
|
||||
#include "editor/editorGeometry.hpp"
|
||||
#include "editor/editorRecords.hpp"
|
||||
|
||||
#include "rendering/renderer.h"
|
||||
#include "scene/scene.h"
|
||||
@@ -757,40 +758,15 @@ bool editor_orthophoto::owns(gfx::geometry_handle const &Geometry)
|
||||
return Geometry.bank != 0 && std::find(scene_banks.begin(), scene_banks.end(), Geometry.bank) != scene_banks.end();
|
||||
}
|
||||
|
||||
// the line of the scenery and its format: editor_records::orthophoto_line() and read_orthophoto()
|
||||
std::string editor_orthophoto::mark(config const &Config, bool const Enabled, bool const Origin)
|
||||
{
|
||||
// how the imagery is shown is the user's, kept with the editor (EditorSettings); the scenery keeps whether it's on and where the
|
||||
// scenery lies
|
||||
char text[256];
|
||||
std::snprintf(text, sizeof(text), "on %d", Enabled ? 1 : 0);
|
||||
std::string result{text};
|
||||
if (Origin)
|
||||
{
|
||||
std::snprintf(text, sizeof(text), " origin %.2f %.2f", Config.north, Config.east);
|
||||
result += text;
|
||||
}
|
||||
return result;
|
||||
return editor_records::orthophoto_line(Enabled, Origin, Config.north, Config.east);
|
||||
}
|
||||
|
||||
bool editor_orthophoto::read_mark(std::string const &Text, config &Config, bool &Enabled)
|
||||
{
|
||||
std::istringstream words{Text};
|
||||
std::string key;
|
||||
auto found{false};
|
||||
// the year, opacity, radius and the rest the lines of the older sceneries carry are passed over: the user's settings stand
|
||||
while (words >> key)
|
||||
{
|
||||
if (key == "on")
|
||||
words >> Enabled;
|
||||
else if (key == "origin")
|
||||
words >> Config.north >> Config.east;
|
||||
else
|
||||
continue;
|
||||
if (words.fail())
|
||||
return found;
|
||||
found = true;
|
||||
}
|
||||
return found;
|
||||
return editor_records::read_orthophoto(Text, Enabled, Config.north, Config.east);
|
||||
}
|
||||
|
||||
void editor_orthophoto::enabled(bool State)
|
||||
@@ -891,35 +867,15 @@ void editor_orthophoto::restart_prefetch()
|
||||
m_wakeup.notify_all();
|
||||
}
|
||||
|
||||
// the lines of the scenery and their format: editor_records::area_lines() and read_area()
|
||||
std::vector<std::string> editor_orthophoto::area_lines(std::vector<glm::dvec2> const &Polygon)
|
||||
{
|
||||
std::vector<std::string> lines;
|
||||
if (Polygon.size() < 3)
|
||||
return lines;
|
||||
lines.emplace_back("# the area the editor downloads the orthophoto and the terrain model in, PUWG 1992 easting northing");
|
||||
for (auto const &point : Polygon)
|
||||
{
|
||||
char text[64];
|
||||
std::snprintf(text, sizeof(text), "point %.2f %.2f", point.x, point.y);
|
||||
lines.emplace_back(text);
|
||||
}
|
||||
return lines;
|
||||
return editor_records::area_lines(Polygon);
|
||||
}
|
||||
|
||||
std::vector<glm::dvec2> editor_orthophoto::read_area(std::vector<std::string> const &Lines)
|
||||
{
|
||||
std::vector<glm::dvec2> polygon;
|
||||
for (auto const &line : Lines)
|
||||
{
|
||||
std::istringstream words{line};
|
||||
std::string keyword;
|
||||
glm::dvec2 point{0.0};
|
||||
if (words >> keyword && keyword == "point" && words >> point.x >> point.y)
|
||||
polygon.push_back(point);
|
||||
}
|
||||
if (polygon.size() < 3)
|
||||
polygon.clear();
|
||||
return polygon;
|
||||
return editor_records::read_area(Lines);
|
||||
}
|
||||
|
||||
void editor_orthophoto::refit()
|
||||
|
||||
@@ -0,0 +1,944 @@
|
||||
/*
|
||||
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 "editor/editorRecords.hpp"
|
||||
#include "editor/editorFormat.hpp"
|
||||
#include "editor/editorGeometry.hpp"
|
||||
|
||||
#include "utilities/utilities.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <sstream>
|
||||
|
||||
namespace editor_records
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
using geometry::plan_of;
|
||||
|
||||
// //$h -----------------------------------------------------------------------------------------------------------------------------
|
||||
// format of the lines, coordinates in the space of the file:
|
||||
// alignment <start x y z> <end x y z>
|
||||
// source <designed> origin <chainage of the start> shape <parabola|clothoid> speed <km/h> [fit <m>]
|
||||
// ends <start direction x z> <end direction x z> <start grade> <end grade> <start R> <end R>
|
||||
// norms <gauge> <unbalanced> <cant max> <cant rate> <ramp factor> <jerk> <straight between curves, s> <arc min> <arc min factor>
|
||||
// pieces <pieces of a transition> <angle of an arc piece>
|
||||
// vertex <x> <z> <offset> <R> <L in> <L out> <cant> <reverse 0/1> <compound 0/1> <share> <arcs> [<R> <L> <share>]... [spirals 1]
|
||||
// spirals: two transition curves with no arc between them, their lengths following from R
|
||||
// [cants <first> <arc>...]: the cants of the radii of a compound curve set one by one, below 0 the cant in proportion to the curvature
|
||||
// [ramps <in offset> <in length> <out offset> <out length>]: the cant ramps of the curve where they don't go along its transitions,
|
||||
// their outer ends from the start and from the end of the curve, into it above 0; a length below 0 keeps the ramp along the transition
|
||||
// click <x y z>: a point clicked when the line was laid, its curves fitted to them
|
||||
// kept <from> <to>: the stretch of the line the design is kept for, chainages from its start, where tracks along it were deleted
|
||||
// element <straight|transition|arc> <vertex> <chainage> <length> <R at the start> <R at the end> <cant> <start x> <start z> <direction x> <direction z>
|
||||
// radii signed with the turn, 0 for no curvature
|
||||
// end
|
||||
char const *shape_name(alignment::transition_shape const Shape)
|
||||
{
|
||||
return Shape == alignment::transition_shape::clothoid ? "clothoid" : "parabola";
|
||||
}
|
||||
|
||||
glm::dvec2 local_direction(scene::layer_context const &Context, glm::dvec3 const &Point, glm::dvec2 const &Direction)
|
||||
{
|
||||
auto const from{Context.to_local(Point)};
|
||||
auto const to{Context.to_local(Point + glm::dvec3{Direction.x, 0.0, Direction.y})};
|
||||
auto const direction{plan_of(to - from)};
|
||||
return glm::length(direction) > 1e-12 ? glm::normalize(direction) : Direction;
|
||||
}
|
||||
|
||||
glm::dvec2 world_direction(scene::layer_context const &Context, glm::dvec3 const &Local, glm::dvec2 const &Direction)
|
||||
{
|
||||
auto const from{Context.to_world(Local)};
|
||||
auto const to{Context.to_world(Local + glm::dvec3{Direction.x, 0.0, Direction.y})};
|
||||
auto const direction{plan_of(to - from)};
|
||||
return glm::length(direction) > 1e-12 ? glm::normalize(direction) : Direction;
|
||||
}
|
||||
|
||||
std::optional<alignment_store::record> read_start(std::istringstream &Line, scene::layer_context const &Context, scene::layer_handle const Layer)
|
||||
{
|
||||
alignment_store::record entry;
|
||||
entry.layer = Layer;
|
||||
glm::dvec3 start;
|
||||
glm::dvec3 end;
|
||||
Line >> start.x >> start.y >> start.z >> end.x >> end.y >> end.z;
|
||||
if (Line.fail())
|
||||
return std::nullopt;
|
||||
entry.design.start = Context.to_world(start);
|
||||
entry.design.end = Context.to_world(end);
|
||||
return entry;
|
||||
}
|
||||
|
||||
std::optional<alignment::vertex> read_vertex(std::istringstream &Line, scene::layer_context const &Context)
|
||||
{
|
||||
alignment::vertex vertex;
|
||||
glm::dvec3 position{0.0};
|
||||
int reverse{0};
|
||||
int compound{0};
|
||||
std::size_t arcs{0};
|
||||
Line >> position.x >> position.z >> vertex.offset >> vertex.radius >> vertex.transition_in >> vertex.transition_out >> vertex.cant >> reverse >> compound >> vertex.share >> arcs;
|
||||
for (std::size_t i = 0; i < arcs && false == Line.fail(); ++i)
|
||||
{
|
||||
alignment::compound_arc arc;
|
||||
Line >> arc.radius >> arc.transition >> arc.share;
|
||||
vertex.arcs.push_back(arc);
|
||||
}
|
||||
if (Line.fail())
|
||||
return std::nullopt;
|
||||
// written since the bends of the straights are eased with two transition curves, the lines of before end with the arcs
|
||||
for (std::string word; Line >> word;)
|
||||
{
|
||||
if (int value{0}; word == "spirals" && Line >> value)
|
||||
vertex.spirals = (value != 0);
|
||||
// the cants of the arcs of a compound curve, set one by one: of the first arc and of the ones after it, below 0 in proportion
|
||||
if (word == "cants")
|
||||
{
|
||||
Line >> vertex.first_cant;
|
||||
for (auto &arc : vertex.arcs)
|
||||
Line >> arc.cant;
|
||||
}
|
||||
if (word == "ramps")
|
||||
Line >> vertex.ramp_in_offset >> vertex.ramp_in_length >> vertex.ramp_out_offset >> vertex.ramp_out_length;
|
||||
}
|
||||
position = Context.to_world(position);
|
||||
vertex.position = {position.x, position.z};
|
||||
vertex.reverse_turn = (reverse != 0);
|
||||
vertex.compound = (compound != 0);
|
||||
return vertex;
|
||||
}
|
||||
|
||||
void read_part(alignment_store::record &Entry, std::string const &Keyword, std::istringstream &Line, scene::layer_context const &Context)
|
||||
{
|
||||
auto &design{Entry.design};
|
||||
std::string word;
|
||||
if (Keyword == "source")
|
||||
{
|
||||
std::string shape;
|
||||
Line >> Entry.source >> word >> Entry.origin >> word >> shape >> word >> design.speed;
|
||||
design.shape = shape == "clothoid" ? alignment::transition_shape::clothoid : alignment::transition_shape::cubic_parabola;
|
||||
if (Line >> word && word == "fit")
|
||||
Line >> Entry.fit;
|
||||
}
|
||||
else if (Keyword == "ends")
|
||||
{
|
||||
glm::dvec2 startdirection;
|
||||
glm::dvec2 enddirection;
|
||||
Line >> startdirection.x >> startdirection.y >> enddirection.x >> enddirection.y >> design.start_grade >> design.end_grade >> design.start_radius >> design.end_radius;
|
||||
design.start_direction = world_direction(Context, Context.to_local(design.start), startdirection);
|
||||
design.end_direction = world_direction(Context, Context.to_local(design.end), enddirection);
|
||||
for (std::string key; Line >> key;)
|
||||
{
|
||||
if (key == "turns")
|
||||
Line >> design.start_turn >> design.end_turn;
|
||||
if (int start{0}, end{0}; key == "curved" && Line >> start >> end >> design.start_cant >> design.end_cant)
|
||||
{
|
||||
design.start_curved = (start != 0);
|
||||
design.end_curved = (end != 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (Keyword == "norms")
|
||||
{
|
||||
auto &norms{design.norms};
|
||||
Line >> norms.gauge >> norms.unbalanced >> norms.cant_max >> norms.cant_rate >> norms.ramp_factor >> norms.jerk >> norms.tangent_min_time >> norms.arc_min >> norms.arc_min_factor;
|
||||
}
|
||||
else if (Keyword == "pieces")
|
||||
Line >> design.transition_pieces >> design.arc_piece_angle;
|
||||
else if (Keyword == "vertex")
|
||||
{
|
||||
if (auto const vertex{read_vertex(Line, Context)})
|
||||
design.vertices.push_back(*vertex);
|
||||
}
|
||||
else if (Keyword == "element")
|
||||
{
|
||||
alignment_store::stored_element e;
|
||||
Line >> e.kind >> e.vertex >> e.chainage >> e.length >> e.radius_start >> e.radius_end >> e.cant;
|
||||
if (false == Line.fail())
|
||||
Entry.elements.push_back(e);
|
||||
}
|
||||
else if (Keyword == "click")
|
||||
{
|
||||
glm::dvec3 point;
|
||||
if (Line >> point.x >> point.y >> point.z)
|
||||
Entry.clicks.push_back(Context.to_world(point));
|
||||
}
|
||||
else if (Keyword == "kept")
|
||||
{
|
||||
double from;
|
||||
double to;
|
||||
if (Line >> from >> to && to > from)
|
||||
{
|
||||
Entry.from = std::max(0.0, from);
|
||||
Entry.to = to;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// //$r -----------------------------------------------------------------------------------------------------------------------------
|
||||
// format of the lines, coordinates in the space of the file:
|
||||
// <switch|slip|crossing|double|connection> <name> <type> <rail> <R> <n of 1:n> <hand L|R|-> <a> <b> <R of the main track, + right, - left, 0 straight>
|
||||
// parts <count> <names>... [shape <main end along, across> <diverging end along, across>] start <x y z> dir <x z>
|
||||
// km <km|-> number <label|-> source <designed|measured> [middle <R in the middle of the slip curves of a double slip>]
|
||||
// [lift <m> <from x y z> <to x y z> ramp <m> [liftend <m>]]
|
||||
std::string switch_word(std::string const &Text)
|
||||
{
|
||||
if (Text.empty())
|
||||
return "-";
|
||||
auto result{Text};
|
||||
std::replace(result.begin(), result.end(), ' ', '_');
|
||||
return result;
|
||||
}
|
||||
|
||||
// //$k -----------------------------------------------------------------------------------------------------------------------------
|
||||
// format of the lines, coordinates in the space of the file:
|
||||
// mark <line> <x y z> way <x z> km <km> [beyond <km>]
|
||||
// via <line> <x y z>
|
||||
std::string kilometrage_word(std::string const &Text)
|
||||
{
|
||||
return Text.empty() ? std::string{"-"} : Text;
|
||||
}
|
||||
|
||||
// //$s -----------------------------------------------------------------------------------------------------------------------------
|
||||
// a word of the record line: blanks taken out, - for none
|
||||
std::string station_word(std::string const &Text)
|
||||
{
|
||||
std::string result;
|
||||
for (auto const c : Text)
|
||||
if (false == std::isspace(static_cast<unsigned char>(c)))
|
||||
result += c;
|
||||
return result.empty() ? std::string{"-"} : result;
|
||||
}
|
||||
|
||||
std::string shown(std::string const &Word)
|
||||
{
|
||||
return Word == "-" ? std::string{} : Word;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// //$h -------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
std::vector<alignment_store::record> read_alignments(std::vector<std::string> const &Lines, scene::layer_context const &Context, scene::layer_handle const Layer)
|
||||
{
|
||||
std::vector<alignment_store::record> result;
|
||||
std::optional<alignment_store::record> current;
|
||||
for (auto const &text : Lines)
|
||||
{
|
||||
std::istringstream line{text};
|
||||
std::string keyword;
|
||||
line >> keyword;
|
||||
if (keyword == "alignment")
|
||||
current = read_start(line, Context, Layer);
|
||||
else if (false == current.has_value())
|
||||
continue;
|
||||
else if (keyword == "end")
|
||||
{
|
||||
result.push_back(std::move(*current));
|
||||
current.reset();
|
||||
}
|
||||
else
|
||||
read_part(*current, keyword, line, Context);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<std::string> alignment_lines(std::vector<alignment_store::record> const &Records, scene::layer_context const &Context)
|
||||
{
|
||||
auto const local = [&](glm::dvec3 const &Point) {
|
||||
auto const point{Context.to_local(Point)};
|
||||
return format("%.4f %.4f %.4f", point.x, point.y, point.z);
|
||||
};
|
||||
std::vector<std::string> lines;
|
||||
for (auto const &entry : Records)
|
||||
{
|
||||
if (lines.empty())
|
||||
lines.emplace_back("# horizontal alignments designed in the track editor, the simulation skips these lines");
|
||||
auto const &design{entry.design};
|
||||
lines.push_back("alignment " + local(design.start) + ' ' + local(design.end));
|
||||
lines.push_back(format("source %s origin %.4f shape %s speed %.1f", entry.source.c_str(), entry.origin, shape_name(design.shape), design.speed) + (entry.fit > 0.0 ? format(" fit %.3f", entry.fit) : std::string{}));
|
||||
auto const startdirection{local_direction(Context, design.start, design.start_direction)};
|
||||
auto const enddirection{local_direction(Context, design.end, design.end_direction)};
|
||||
auto ends{format("ends %.9f %.9f %.9f %.9f %.6f %.6f %.3f %.3f", startdirection.x, startdirection.y, enddirection.x, enddirection.y, design.start_grade, design.end_grade, design.start_radius, design.end_radius)};
|
||||
// the sides the adjoining tracks turn to, and the curves going on from them with their cants, written since there are such
|
||||
if (design.start_turn != 0 || design.end_turn != 0)
|
||||
ends += format(" turns %d %d", design.start_turn, design.end_turn);
|
||||
if (design.start_curved || design.end_curved)
|
||||
ends += format(" curved %d %d %.1f %.1f", design.start_curved ? 1 : 0, design.end_curved ? 1 : 0, design.start_cant, design.end_cant);
|
||||
lines.push_back(ends);
|
||||
auto const &norms{design.norms};
|
||||
lines.push_back(format("norms %.1f %.3f %.1f %.1f %.2f %.3f %.2f %.2f %.3f", norms.gauge, norms.unbalanced, norms.cant_max, norms.cant_rate, norms.ramp_factor, norms.jerk, norms.tangent_min_time, norms.arc_min, norms.arc_min_factor));
|
||||
lines.push_back(format("pieces %d %.3f", design.transition_pieces, design.arc_piece_angle));
|
||||
if (false == entry.whole())
|
||||
lines.push_back(format("kept %.4f %.4f", entry.from, entry.kept_to()));
|
||||
for (auto const &vertex : design.vertices)
|
||||
{
|
||||
auto const position{Context.to_local({vertex.position.x, 0.0, vertex.position.y})};
|
||||
auto text{format("vertex %.4f %.4f %.4f %.3f %.3f %.3f %.1f %d %d %.9f %zu", position.x, position.z, vertex.offset, vertex.radius, vertex.transition_in, vertex.transition_out, vertex.cant, vertex.reverse_turn ? 1 : 0, vertex.compound ? 1 : 0,
|
||||
vertex.share, vertex.arcs.size())};
|
||||
for (auto const &arc : vertex.arcs)
|
||||
text += format(" %.3f %.3f %.9f", arc.radius, arc.transition, arc.share);
|
||||
if (vertex.spirals)
|
||||
text += " spirals 1";
|
||||
if (vertex.first_cant >= 0.0 || std::any_of(vertex.arcs.begin(), vertex.arcs.end(), [](alignment::compound_arc const &Arc) { return Arc.cant >= 0.0; }))
|
||||
{
|
||||
text += format(" cants %.1f", vertex.first_cant);
|
||||
for (auto const &arc : vertex.arcs)
|
||||
text += format(" %.1f", arc.cant);
|
||||
}
|
||||
if (vertex.own_ramps())
|
||||
text += format(" ramps %.3f %.3f %.3f %.3f", vertex.ramp_in_offset, vertex.ramp_in_length, vertex.ramp_out_offset, vertex.ramp_out_length);
|
||||
lines.push_back(text);
|
||||
}
|
||||
for (auto const &click : entry.clicks)
|
||||
lines.push_back("click " + local(click));
|
||||
for (auto const &e : entry.result.elements)
|
||||
{
|
||||
auto const station{alignment::evaluate(entry.result, e.chainage)};
|
||||
auto const start{Context.to_local(station.position)};
|
||||
auto const direction{local_direction(Context, station.position, glm::normalize(plan_of(station.direction)))};
|
||||
auto const element{alignment_store::describe(e)};
|
||||
lines.push_back(format("element %s %d %.4f %.4f %.3f %.3f %.1f %.4f %.4f %.9f %.9f", element.kind.c_str(), element.vertex, element.chainage, element.length, element.radius_start, element.radius_end, element.cant, start.x, start.z, direction.x, direction.y));
|
||||
}
|
||||
lines.emplace_back("end");
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
} // namespace editor_records
|
||||
|
||||
// the element as the //$h lines give it
|
||||
alignment_store::stored_element alignment_store::describe(alignment::element const &Element)
|
||||
{
|
||||
stored_element result;
|
||||
result.vertex = Element.vertex;
|
||||
result.chainage = Element.chainage;
|
||||
result.length = Element.length;
|
||||
result.cant = Element.cant;
|
||||
auto const sign{Element.turn < 0 ? -1.0 : 1.0};
|
||||
auto const radius = [&](double const Curvature) { return Curvature > 1e-12 ? sign / Curvature : 0.0; };
|
||||
switch (Element.kind)
|
||||
{
|
||||
case alignment::element_kind::transition_in:
|
||||
result.radius_end = sign * Element.radius;
|
||||
break;
|
||||
case alignment::element_kind::arc:
|
||||
result.radius_end = sign * Element.radius;
|
||||
result.radius_start = result.radius_end;
|
||||
break;
|
||||
case alignment::element_kind::transition_out:
|
||||
result.radius_start = sign * Element.radius;
|
||||
break;
|
||||
case alignment::element_kind::spiral:
|
||||
result.radius_start = radius(Element.curvature_start);
|
||||
result.radius_end = radius(Element.curvature_end);
|
||||
break;
|
||||
default:
|
||||
result.cant = 0.0;
|
||||
break;
|
||||
}
|
||||
if (result.radius_start == 0.0 && result.radius_end == 0.0)
|
||||
result.kind = "straight";
|
||||
else if (std::abs(result.radius_start - result.radius_end) < 1e-6)
|
||||
result.kind = "arc";
|
||||
else
|
||||
result.kind = "transition";
|
||||
return result;
|
||||
}
|
||||
|
||||
namespace editor_records
|
||||
{
|
||||
|
||||
// //$r -------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
std::vector<switch_store::record> read_switches(std::vector<std::string> const &Lines, scene::layer_context const &Context, scene::layer_handle const Layer)
|
||||
{
|
||||
std::vector<switch_store::record> result;
|
||||
for (auto const &text : Lines)
|
||||
{
|
||||
std::istringstream line{text};
|
||||
switch_store::record entry;
|
||||
entry.layer = Layer;
|
||||
std::string keyword;
|
||||
std::string hand;
|
||||
std::string km;
|
||||
std::size_t count{0};
|
||||
line >> entry.kind;
|
||||
if (entry.kind != "switch" && entry.kind != "slip" && entry.kind != "crossing" && entry.kind != "double" && entry.kind != "connection")
|
||||
continue;
|
||||
line >> entry.name >> entry.type >> entry.rail >> entry.radius >> entry.ratio >> hand >> entry.a >> entry.b >> entry.main_radius >> keyword >> count;
|
||||
if (line.fail() || keyword != "parts" || count == 0 || count > 64)
|
||||
continue;
|
||||
entry.hand = hand.empty() ? '-' : hand.front();
|
||||
entry.parts.resize(count);
|
||||
for (auto &part : entry.parts)
|
||||
line >> part;
|
||||
glm::dvec3 start{0.0};
|
||||
glm::dvec3 ahead{0.0};
|
||||
glm::dvec2 direction{0.0, 1.0};
|
||||
line >> keyword;
|
||||
if (keyword == "shape")
|
||||
{
|
||||
line >> entry.shape.x >> entry.shape.y >> entry.shape.z >> entry.shape.w >> keyword;
|
||||
entry.shaped = true;
|
||||
}
|
||||
line >> start.x >> start.y >> start.z >> keyword >> direction.x >> direction.y >> keyword >> km >> keyword >> entry.number >> keyword >> entry.source;
|
||||
if (line.fail())
|
||||
continue;
|
||||
while (line >> keyword)
|
||||
{
|
||||
if (keyword == "middle")
|
||||
line >> entry.middle;
|
||||
else if (keyword == "lift")
|
||||
{
|
||||
glm::dvec3 from{0.0}, to{0.0};
|
||||
line >> entry.lift >> from.x >> from.y >> from.z >> to.x >> to.y >> to.z >> keyword >> entry.ramp;
|
||||
entry.lift_end = entry.lift;
|
||||
entry.lift_from = Context.to_world(from);
|
||||
entry.lift_to = Context.to_world(to);
|
||||
}
|
||||
else if (keyword == "liftend")
|
||||
line >> entry.lift_end;
|
||||
}
|
||||
entry.start = Context.to_world(start);
|
||||
ahead = Context.to_world(start + glm::dvec3{direction.x, 0.0, direction.y});
|
||||
entry.direction = plan_of(ahead - entry.start);
|
||||
entry.direction = glm::length(entry.direction) > 1e-12 ? glm::normalize(entry.direction) : glm::dvec2{0.0, 1.0};
|
||||
if (km != "-")
|
||||
{
|
||||
char *end{nullptr};
|
||||
auto const value{std::strtod(km.c_str(), &end)};
|
||||
if (end != km.c_str() && *end == '\0' && std::isfinite(value))
|
||||
entry.km = value * 1000.0;
|
||||
}
|
||||
result.push_back(std::move(entry));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<std::string> switch_lines(std::vector<switch_store::record> const &Records, scene::layer_context const &Context)
|
||||
{
|
||||
std::vector<std::string> lines;
|
||||
for (auto const &entry : Records)
|
||||
{
|
||||
if (lines.empty())
|
||||
lines.emplace_back("# switches placed in the track editor, the simulation skips these lines");
|
||||
auto const start{Context.to_local(entry.start)};
|
||||
auto const ahead{Context.to_local(entry.start + glm::dvec3{entry.direction.x, 0.0, entry.direction.y})};
|
||||
auto direction{plan_of(ahead - start)};
|
||||
direction = glm::length(direction) > 1e-12 ? glm::normalize(direction) : entry.direction;
|
||||
auto text{format("%s %s %s %s %.3f %.3f %c %.3f %.3f %.3f parts %zu", entry.kind.c_str(), switch_word(entry.name).c_str(), switch_word(entry.type).c_str(), switch_word(entry.rail).c_str(), entry.radius, entry.ratio, entry.hand, entry.a, entry.b,
|
||||
entry.main_radius, entry.parts.size())};
|
||||
for (auto const &part : entry.parts)
|
||||
text += ' ' + switch_word(part);
|
||||
if (entry.shaped)
|
||||
text += format(" shape %.4f %.4f %.4f %.4f", entry.shape.x, entry.shape.y, entry.shape.z, entry.shape.w);
|
||||
text += format(" start %.4f %.4f %.4f dir %.9f %.9f km ", start.x, start.y, start.z, direction.x, direction.y);
|
||||
text += entry.km.has_value() ? format("%.3f", *entry.km / 1000.0) : std::string{"-"};
|
||||
text += " number " + switch_word(entry.number) + " source " + switch_word(entry.source);
|
||||
if (entry.middle > 0.0)
|
||||
text += format(" middle %.3f", entry.middle);
|
||||
if (entry.lift != 0.0 || entry.lift_end != 0.0)
|
||||
{
|
||||
auto const from{Context.to_local(entry.lift_from)};
|
||||
auto const to{Context.to_local(entry.lift_to)};
|
||||
text += format(" lift %.4f %.4f %.4f %.4f %.4f %.4f %.4f ramp %.3f", entry.lift, from.x, from.y, from.z, to.x, to.y, to.z, entry.ramp);
|
||||
if (entry.lift_end != entry.lift)
|
||||
text += format(" liftend %.4f", entry.lift_end);
|
||||
}
|
||||
lines.push_back(text);
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
// //$k -------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
void read_kilometrage(std::vector<std::string> const &Lines, scene::layer_context const &Context, scene::layer_handle const Layer, std::vector<kilometrage::mark> &Marks, std::vector<kilometrage::via> &Vias)
|
||||
{
|
||||
for (auto const &text : Lines)
|
||||
{
|
||||
std::istringstream line{text};
|
||||
std::string keyword;
|
||||
kilometrage::mark entry;
|
||||
entry.layer = Layer;
|
||||
glm::dvec3 point{0.0};
|
||||
glm::dvec2 way{0.0, 1.0};
|
||||
line >> keyword;
|
||||
if (keyword == "via")
|
||||
{
|
||||
kilometrage::via via;
|
||||
via.layer = Layer;
|
||||
glm::dvec3 at{0.0};
|
||||
line >> via.line >> at.x >> at.y >> at.z;
|
||||
if (line.fail() || via.line.empty())
|
||||
continue;
|
||||
via.point = Context.to_world(at);
|
||||
Vias.push_back(std::move(via));
|
||||
continue;
|
||||
}
|
||||
if (keyword != "mark")
|
||||
continue;
|
||||
line >> entry.line >> point.x >> point.y >> point.z >> keyword >> way.x >> way.y >> keyword >> entry.km;
|
||||
if (line.fail() || entry.line.empty() || false == std::isfinite(entry.km))
|
||||
continue;
|
||||
while (line >> keyword)
|
||||
if (keyword == "beyond")
|
||||
{
|
||||
double beyond{0.0};
|
||||
if (line >> beyond)
|
||||
entry.beyond = beyond;
|
||||
}
|
||||
entry.point = Context.to_world(point);
|
||||
entry.way = plan_of(Context.to_world(point + glm::dvec3{way.x, 0.0, way.y}) - entry.point);
|
||||
entry.way = glm::length(entry.way) > 1e-12 ? glm::normalize(entry.way) : glm::dvec2{0.0, 1.0};
|
||||
Marks.push_back(std::move(entry));
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> kilometrage_lines(std::vector<kilometrage::mark> const &Marks, std::vector<kilometrage::via> const &Vias, scene::layer_context const &Context)
|
||||
{
|
||||
std::vector<std::string> lines;
|
||||
auto const heading = [&]() {
|
||||
if (lines.empty())
|
||||
lines.emplace_back("# kilometrage of the lines set in the track editor, the simulation skips these lines");
|
||||
};
|
||||
for (auto const &entry : Marks)
|
||||
{
|
||||
heading();
|
||||
auto const point{Context.to_local(entry.point)};
|
||||
auto const ahead{Context.to_local(entry.point + glm::dvec3{entry.way.x, 0.0, entry.way.y})};
|
||||
auto way{plan_of(ahead - point)};
|
||||
way = glm::length(way) > 1e-12 ? glm::normalize(way) : entry.way;
|
||||
auto text{format("mark %s %.4f %.4f %.4f way %.9f %.9f km %.3f", kilometrage_word(entry.line).c_str(), point.x, point.y, point.z, way.x, way.y, entry.km)};
|
||||
if (entry.beyond.has_value())
|
||||
text += format(" beyond %.3f", *entry.beyond);
|
||||
lines.push_back(text);
|
||||
}
|
||||
for (auto const &entry : Vias)
|
||||
{
|
||||
heading();
|
||||
auto const point{Context.to_local(entry.point)};
|
||||
lines.push_back(format("via %s %.4f %.4f %.4f", kilometrage_word(entry.line).c_str(), point.x, point.y, point.z));
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
// //$p -------------------------------------------------------------------------------------------------------------------------------
|
||||
// format of the lines, coordinates in the space of the file:
|
||||
// profile <length> <start x y z> <end x y z> <middle x y z>
|
||||
// speed <km/h> origin <chainage of the start> join <start 0/1> <end 0/1>
|
||||
// norms <grade max> <grade over switches max> <k of R >= k*V^2> <R min> <change needing a curve> <constant grade min> <fixed tolerance>
|
||||
// [departure <m>]
|
||||
// point <chainage> <elevation> <vertical curve R> <automatic R 0/1>
|
||||
// end
|
||||
|
||||
std::vector<grade_profile> read_profiles(std::vector<std::string> const &Lines, scene::layer_context const &Context, scene::layer_handle const Layer)
|
||||
{
|
||||
std::vector<grade_profile> result;
|
||||
auto const height = [&](double const Local) { return Context.to_world({0.0, Local, 0.0}).y; };
|
||||
std::optional<grade_profile> current;
|
||||
for (auto const &text : Lines)
|
||||
{
|
||||
std::istringstream line{text};
|
||||
std::string keyword;
|
||||
line >> keyword;
|
||||
if (keyword == "profile")
|
||||
{
|
||||
grade_profile entry;
|
||||
entry.layer = Layer;
|
||||
glm::dvec3 start;
|
||||
glm::dvec3 end;
|
||||
glm::dvec3 middle;
|
||||
line >> entry.length >> start.x >> start.y >> start.z >> end.x >> end.y >> end.z >> middle.x >> middle.y >> middle.z;
|
||||
if (line.fail())
|
||||
{
|
||||
current.reset();
|
||||
continue;
|
||||
}
|
||||
entry.start = Context.to_world(start);
|
||||
entry.end = Context.to_world(end);
|
||||
entry.middle = Context.to_world(middle);
|
||||
current = entry;
|
||||
continue;
|
||||
}
|
||||
if (false == current.has_value())
|
||||
continue;
|
||||
auto &entry{*current};
|
||||
std::string word;
|
||||
if (keyword == "speed")
|
||||
{
|
||||
int start{1};
|
||||
int end{1};
|
||||
line >> entry.line.speed >> word >> entry.origin >> word >> start >> end;
|
||||
entry.line.join_start = (start != 0);
|
||||
entry.line.join_end = (end != 0);
|
||||
}
|
||||
else if (keyword == "norms")
|
||||
{
|
||||
auto &norms{entry.line.norms};
|
||||
line >> norms.grade_max >> norms.grade_switch_max >> norms.radius_factor >> norms.radius_min >> norms.curve_threshold >> norms.element_min >> norms.fixed_tolerance;
|
||||
}
|
||||
else if (keyword == "departure")
|
||||
line >> entry.departure;
|
||||
else if (keyword == "point")
|
||||
{
|
||||
profile::pvi point;
|
||||
int automatic{0};
|
||||
line >> point.chainage >> point.elevation >> point.radius >> automatic;
|
||||
if (line.fail())
|
||||
continue;
|
||||
point.elevation = height(point.elevation);
|
||||
point.automatic = (automatic != 0);
|
||||
entry.line.points.push_back(point);
|
||||
}
|
||||
else if (keyword == "end")
|
||||
{
|
||||
if (entry.line.points.size() >= 2 && entry.length > 0.0)
|
||||
result.push_back(entry);
|
||||
current.reset();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<std::string> profile_lines(std::vector<grade_profile> const &Profiles, scene::layer_context const &Context)
|
||||
{
|
||||
auto const local = [&](glm::dvec3 const &Point) {
|
||||
auto const point{Context.to_local(Point)};
|
||||
return format("%.4f %.4f %.4f", point.x, point.y, point.z);
|
||||
};
|
||||
std::vector<std::string> lines;
|
||||
for (auto const &entry : Profiles)
|
||||
{
|
||||
if (lines.empty())
|
||||
lines.emplace_back("# vertical profiles (grade lines) designed in the track editor, the simulation skips these lines");
|
||||
lines.push_back(format("profile %.4f ", entry.length) + local(entry.start) + ' ' + local(entry.end) + ' ' + local(entry.middle));
|
||||
lines.push_back(format("speed %.1f origin %.4f join %d %d", entry.line.speed, entry.origin, entry.line.join_start ? 1 : 0, entry.line.join_end ? 1 : 0));
|
||||
auto const &norms{entry.line.norms};
|
||||
lines.push_back(format("norms %.4f %.4f %.4f %.1f %.4f %.2f %.4f", norms.grade_max, norms.grade_switch_max, norms.radius_factor, norms.radius_min, norms.curve_threshold, norms.element_min, norms.fixed_tolerance));
|
||||
if (entry.departure >= 0.0)
|
||||
lines.push_back(format("departure %.4f", entry.departure));
|
||||
for (auto const &point : entry.line.points)
|
||||
lines.push_back(format("point %.4f %.4f %.1f %d", point.chainage, Context.to_local({0.0, point.elevation, 0.0}).y, point.radius, point.automatic ? 1 : 0));
|
||||
lines.emplace_back("end");
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
// //$t -------------------------------------------------------------------------------------------------------------------------------
|
||||
// format of the lines: fitted <name> <shape, 16 hex digits> [hand]
|
||||
|
||||
std::vector<fitted_track> read_fitted(std::vector<std::string> const &Lines)
|
||||
{
|
||||
std::vector<fitted_track> result;
|
||||
for (auto const &text : Lines)
|
||||
{
|
||||
std::istringstream line{text};
|
||||
std::string keyword, name, shape, kind;
|
||||
line >> keyword >> name >> shape;
|
||||
if (keyword == "fitted" && false == line.fail())
|
||||
{
|
||||
line >> kind;
|
||||
result.push_back({name, std::strtoull(shape.c_str(), nullptr, 16), kind == "hand"});
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<std::string> fitted_lines(std::vector<fitted_track> const &Tracks)
|
||||
{
|
||||
std::vector<std::string> lines;
|
||||
for (auto const &track : Tracks)
|
||||
{
|
||||
if (lines.empty())
|
||||
lines.emplace_back("# the tracks whose grade line was fitted in the track editor, with their shape then; the simulation skips these lines");
|
||||
lines.push_back(format("fitted %s %016llx%s", track.name.c_str(), static_cast<unsigned long long>(track.shape), track.hand ? " hand" : ""));
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
// //$w -------------------------------------------------------------------------------------------------------------------------------
|
||||
// format of the lines: gradeline <key> <number> [hand]
|
||||
|
||||
std::vector<grade_line> read_grade_lines(std::vector<std::string> const &Lines)
|
||||
{
|
||||
std::vector<grade_line> result;
|
||||
for (auto const &text : Lines)
|
||||
{
|
||||
std::istringstream line{text};
|
||||
std::string keyword, name, hand;
|
||||
int number{0};
|
||||
line >> keyword >> name >> number;
|
||||
if (keyword == "gradeline" && false == line.fail())
|
||||
result.push_back({name, number, (line >> hand) && hand == "hand"});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<std::string> grade_line_lines(std::vector<grade_line> const &Lines)
|
||||
{
|
||||
std::vector<std::string> lines;
|
||||
for (auto const &entry : Lines)
|
||||
{
|
||||
if (lines.empty())
|
||||
lines.emplace_back("# the tracks sharing a grade line, each with the number of it; the simulation skips these lines");
|
||||
lines.push_back(format("gradeline %s %d%s", entry.key.c_str(), entry.number, entry.hand ? " hand" : ""));
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
// //$b -------------------------------------------------------------------------------------------------------------------------------
|
||||
// format of the lines, coordinates in the space of the file:
|
||||
// <kind> <category> <x y z of the object> <file or name, - if none> <turns 0/1> <anchor count> { <path> <start x y z> <end x y z> }
|
||||
// the object is the model, the include (position from its parameters), the traction piece (its first point), the memory
|
||||
// cell or the event launcher found at the location; the anchors name the paths by their ends
|
||||
|
||||
std::optional<binding> read_binding(std::string const &Line, scene::layer_context const &Context)
|
||||
{
|
||||
if (Line.empty() || Line.front() == '#')
|
||||
return std::nullopt;
|
||||
std::istringstream line{Line};
|
||||
binding result;
|
||||
int turns{0};
|
||||
int count{0};
|
||||
line >> result.kind >> result.category >> result.location.x >> result.location.y >> result.location.z >> result.key >> turns >> count;
|
||||
if (line.fail() || count < 1 || count > 4)
|
||||
return std::nullopt;
|
||||
result.location = Context.to_world(result.location);
|
||||
result.turns = (turns != 0);
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
binding::anchor anchor;
|
||||
line >> anchor.path >> anchor.start.x >> anchor.start.y >> anchor.start.z >> anchor.end.x >> anchor.end.y >> anchor.end.z;
|
||||
if (line.fail())
|
||||
return std::nullopt;
|
||||
anchor.start = Context.to_world(anchor.start);
|
||||
anchor.end = Context.to_world(anchor.end);
|
||||
result.anchors.push_back(anchor);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string binding_line(binding const &Binding, scene::layer_context const &Context)
|
||||
{
|
||||
auto const local = [&](glm::dvec3 const &Point) {
|
||||
auto const point{Context.to_local(Point)};
|
||||
return format("%.4f %.4f %.4f", point.x, point.y, point.z);
|
||||
};
|
||||
auto text{Binding.kind + ' ' + std::to_string(Binding.category) + ' ' + local(Binding.location) + ' ' + Binding.key + ' ' + (Binding.turns ? "1 " : "0 ") + std::to_string(Binding.anchors.size())};
|
||||
for (auto const &anchor : Binding.anchors)
|
||||
text += ' ' + std::to_string(anchor.path) + ' ' + local(anchor.start) + ' ' + local(anchor.end);
|
||||
return text;
|
||||
}
|
||||
|
||||
std::string binding_heading()
|
||||
{
|
||||
return "# objects bound to the paths in the track editor, they follow changes of the track; the simulation skips these lines";
|
||||
}
|
||||
|
||||
// //$s -------------------------------------------------------------------------------------------------------------------------------
|
||||
// format of the lines:
|
||||
// station <code> line <number> km <km> from <left|right> anchor <switch> [braking <m>] [blocks <signal>=<semi|sbl|sbl4>,...]
|
||||
// [ways <signal>=<1|2>,...] [joints <+|-><x>/<y>/<z>,...] name <the rest of the line, windows-1250>
|
||||
// - for an empty word, the joints in the world
|
||||
|
||||
std::optional<station> read_station(std::string const &Line)
|
||||
{
|
||||
std::istringstream words{Line};
|
||||
std::string word;
|
||||
if ((words >> word).fail() || word != "station")
|
||||
return std::nullopt;
|
||||
station entry;
|
||||
words >> entry.code;
|
||||
while (words >> word)
|
||||
{
|
||||
if (word == "line")
|
||||
words >> entry.line;
|
||||
else if (word == "km")
|
||||
words >> entry.km;
|
||||
else if (word == "from")
|
||||
entry.reversed = (words >> word) && word == "right";
|
||||
else if (word == "braking")
|
||||
words >> entry.braking;
|
||||
else if (word == "blocks" && words >> word)
|
||||
for (std::size_t from = 0; from < word.size();)
|
||||
{
|
||||
auto const comma{std::min(word.find(',', from), word.size())};
|
||||
auto const item{word.substr(from, comma - from)};
|
||||
if (auto const equals{item.find('=')}; equals != std::string::npos && equals > 0)
|
||||
{
|
||||
auto const kind{item.substr(equals + 1)};
|
||||
entry.blocks[item.substr(0, equals)] = kind == "sbl4" ? block_kind::four : kind == "sbl" || kind == "sbl3" ? block_kind::three : block_kind::semi;
|
||||
}
|
||||
from = comma + 1;
|
||||
}
|
||||
else if (word == "ways" && words >> word)
|
||||
for (std::size_t from = 0; from < word.size();)
|
||||
{
|
||||
auto const comma{std::min(word.find(',', from), word.size())};
|
||||
auto const item{word.substr(from, comma - from)};
|
||||
if (auto const equals{item.find('=')}; equals != std::string::npos && equals > 0)
|
||||
entry.ways[item.substr(0, equals)] = item.substr(equals + 1) == "2";
|
||||
from = comma + 1;
|
||||
}
|
||||
else if (word == "joints" && words >> word)
|
||||
// +x/y/z for one put by hand, -x/y/z for a planned one taken away
|
||||
for (std::size_t from = 0; from < word.size();)
|
||||
{
|
||||
auto const comma{std::min(word.find(',', from), word.size())};
|
||||
auto const item{word.substr(from, comma - from)};
|
||||
glm::dvec3 point{0.0};
|
||||
if (item.size() > 1 && (item.front() == '+' || item.front() == '-') && std::sscanf(item.c_str() + 1, "%lf/%lf/%lf", &point.x, &point.y, &point.z) == 3)
|
||||
(item.front() == '+' ? entry.joints_added : entry.joints_removed).push_back(point);
|
||||
from = comma + 1;
|
||||
}
|
||||
else if (word == "anchor")
|
||||
words >> entry.anchor;
|
||||
else if (word == "name")
|
||||
{
|
||||
std::getline(words, entry.name);
|
||||
entry.name.erase(0, entry.name.find_first_not_of(' '));
|
||||
// windows-1250 like the rest of the scenery file; earlier builds wrote it in utf-8, which stays as it is
|
||||
if (std::u32string decoded; false == utf8_to_utf32(entry.name, decoded))
|
||||
entry.name = win1250_to_utf8(entry.name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
entry.code = shown(entry.code);
|
||||
entry.line = shown(entry.line);
|
||||
entry.km = shown(entry.km);
|
||||
if (entry.anchor.empty())
|
||||
return std::nullopt;
|
||||
return entry;
|
||||
}
|
||||
|
||||
std::vector<std::string> station_lines(std::vector<station> const &Stations)
|
||||
{
|
||||
std::vector<std::string> lines;
|
||||
for (auto const &entry : Stations)
|
||||
{
|
||||
if (lines.empty())
|
||||
lines.emplace_back("# stations described in the track editor, the simulation skips these lines");
|
||||
auto const braking{entry.braking > 0 ? format(" braking %d", entry.braking) : std::string{}};
|
||||
std::string blocks;
|
||||
for (auto const &[signal, kind] : entry.blocks)
|
||||
if (false == signal.empty() && signal.find_first_of(" ,=\t") == std::string::npos)
|
||||
blocks += (blocks.empty() ? " blocks " : ",") + signal + (kind == block_kind::four ? "=sbl4" : kind == block_kind::three ? "=sbl" : "=semi");
|
||||
std::string ways;
|
||||
for (auto const &[signal, both] : entry.ways)
|
||||
if (false == signal.empty() && signal.find_first_of(" ,=\t") == std::string::npos)
|
||||
ways += (ways.empty() ? " ways " : ",") + signal + (both ? "=2" : "=1");
|
||||
std::string joints;
|
||||
for (auto const *list : {&entry.joints_added, &entry.joints_removed})
|
||||
for (auto const &point : *list)
|
||||
joints += (joints.empty() ? " joints " : ",") + format("%c%.3f/%.3f/%.3f", list == &entry.joints_added ? '+' : '-', point.x, point.y, point.z);
|
||||
lines.push_back(format("station %s line %s km %s from %s anchor %s%s%s%s%s name %s", station_word(entry.code).c_str(), station_word(entry.line).c_str(), station_word(entry.km).c_str(), entry.reversed ? "right" : "left", entry.anchor.c_str(),
|
||||
braking.c_str(), blocks.c_str(), ways.c_str(), joints.c_str(), utf8_to_win1250(entry.name).c_str()));
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
// //$c -------------------------------------------------------------------------------------------------------------------------------
|
||||
// format of the line: <x y z> <pitch> <yaw>
|
||||
|
||||
std::optional<camera> read_camera(std::vector<std::string> const &Lines)
|
||||
{
|
||||
if (Lines.empty())
|
||||
return std::nullopt;
|
||||
std::istringstream values(Lines.front());
|
||||
camera result;
|
||||
if (values >> result.position.x >> result.position.y >> result.position.z >> result.angle.x >> result.angle.y)
|
||||
return result;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::string camera_line(camera const &Camera)
|
||||
{
|
||||
return format("%.3f %.3f %.3f %.5f %.5f", Camera.position.x, Camera.position.y, Camera.position.z, Camera.angle.x, Camera.angle.y);
|
||||
}
|
||||
|
||||
// //$o -------------------------------------------------------------------------------------------------------------------------------
|
||||
// format of the line: on <0/1> [origin <north> <east>]
|
||||
|
||||
std::string orthophoto_line(bool const Enabled, bool const Origin, double const North, double const East)
|
||||
{
|
||||
// how the imagery is shown is the user's, kept with the editor (EditorSettings); the scenery keeps whether it's on and where the
|
||||
// scenery lies
|
||||
char text[256];
|
||||
std::snprintf(text, sizeof(text), "on %d", Enabled ? 1 : 0);
|
||||
std::string result{text};
|
||||
if (Origin)
|
||||
{
|
||||
std::snprintf(text, sizeof(text), " origin %.2f %.2f", North, East);
|
||||
result += text;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool read_orthophoto(std::string const &Line, bool &Enabled, double &North, double &East)
|
||||
{
|
||||
std::istringstream words{Line};
|
||||
std::string key;
|
||||
auto found{false};
|
||||
// the year, opacity, radius and the rest the lines of the older sceneries carry are passed over: the user's settings stand
|
||||
while (words >> key)
|
||||
{
|
||||
if (key == "on")
|
||||
words >> Enabled;
|
||||
else if (key == "origin")
|
||||
words >> North >> East;
|
||||
else
|
||||
continue;
|
||||
if (words.fail())
|
||||
return found;
|
||||
found = true;
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
// //$z -------------------------------------------------------------------------------------------------------------------------------
|
||||
// format of the lines: point <easting> <northing>
|
||||
|
||||
std::vector<std::string> area_lines(std::vector<glm::dvec2> const &Polygon)
|
||||
{
|
||||
std::vector<std::string> lines;
|
||||
if (Polygon.size() < 3)
|
||||
return lines;
|
||||
lines.emplace_back("# the area the editor downloads the orthophoto and the terrain model in, PUWG 1992 easting northing");
|
||||
for (auto const &point : Polygon)
|
||||
{
|
||||
char text[64];
|
||||
std::snprintf(text, sizeof(text), "point %.2f %.2f", point.x, point.y);
|
||||
lines.emplace_back(text);
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
std::vector<glm::dvec2> read_area(std::vector<std::string> const &Lines)
|
||||
{
|
||||
std::vector<glm::dvec2> polygon;
|
||||
for (auto const &line : Lines)
|
||||
{
|
||||
std::istringstream words{line};
|
||||
std::string keyword;
|
||||
glm::dvec2 point{0.0};
|
||||
if (words >> keyword && keyword == "point" && words >> point.x >> point.y)
|
||||
polygon.push_back(point);
|
||||
}
|
||||
if (polygon.size() < 3)
|
||||
polygon.clear();
|
||||
return polygon;
|
||||
}
|
||||
|
||||
} // namespace editor_records
|
||||
@@ -0,0 +1,146 @@
|
||||
/*
|
||||
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 <cstdint>
|
||||
#include <map>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#include "editor/editorAlignmentStore.hpp"
|
||||
#include "editor/editorKilometrage.hpp"
|
||||
#include "editor/editorProfile.hpp"
|
||||
#include "editor/editorSwitchStore.hpp"
|
||||
#include "scene/scenelayers.h"
|
||||
|
||||
// the lines the track editor keeps in the scenery files after its //$ marks, which the simulation skips: what each kind says, read
|
||||
// from the text of the lines (the mark taken off, as scene::node_layers::marked() gives them) and written into it, in one place. The
|
||||
// coordinates in the lines are those of the file, the records have them in the world: Context is the placement in effect where
|
||||
// the lines are (basic_layer::context_insert()). What the records stand for in the scene (the tracks, the objects bound to them, the
|
||||
// switches of a station) is found by those who keep them; the records here are what the lines say
|
||||
namespace editor_records
|
||||
{
|
||||
|
||||
// //$h, the horizontal alignments designed (alignment_store): the records closed by their end lines, as read, their designs not yet
|
||||
// made into lines
|
||||
std::vector<alignment_store::record> read_alignments(std::vector<std::string> const &Lines, scene::layer_context const &Context, scene::layer_handle const Layer);
|
||||
// the records with their designs made (record::result), the heading comment first
|
||||
std::vector<std::string> alignment_lines(std::vector<alignment_store::record> const &Records, scene::layer_context const &Context);
|
||||
|
||||
// //$r, the switches placed (switch_store)
|
||||
std::vector<switch_store::record> read_switches(std::vector<std::string> const &Lines, scene::layer_context const &Context, scene::layer_handle const Layer);
|
||||
std::vector<std::string> switch_lines(std::vector<switch_store::record> const &Records, scene::layer_context const &Context);
|
||||
|
||||
// //$k, the kilometrage of the lines (kilometrage)
|
||||
void read_kilometrage(std::vector<std::string> const &Lines, scene::layer_context const &Context, scene::layer_handle const Layer, std::vector<kilometrage::mark> &Marks, std::vector<kilometrage::via> &Vias);
|
||||
std::vector<std::string> kilometrage_lines(std::vector<kilometrage::mark> const &Marks, std::vector<kilometrage::via> const &Vias, scene::layer_context const &Context);
|
||||
|
||||
// //$p, the grade lines designed in the profile tool
|
||||
struct grade_profile
|
||||
{
|
||||
scene::layer_handle layer{null_handle};
|
||||
double length{0.0};
|
||||
glm::dvec3 start{0.0}, end{0.0}, middle{0.0}; // of the route, world space
|
||||
double origin{0.0};
|
||||
profile::line line;
|
||||
double departure{-1.0}; // of the track from the design when it was kept; -1 as kept by an older editor
|
||||
};
|
||||
std::vector<grade_profile> read_profiles(std::vector<std::string> const &Lines, scene::layer_context const &Context, scene::layer_handle const Layer);
|
||||
std::vector<std::string> profile_lines(std::vector<grade_profile> const &Profiles, scene::layer_context const &Context);
|
||||
|
||||
// //$t, the tracks whose grade line was fitted, by name, with their shape then
|
||||
struct fitted_track
|
||||
{
|
||||
std::string name;
|
||||
std::uint64_t shape{0};
|
||||
bool hand{false}; // edited with the profile tool
|
||||
};
|
||||
std::vector<fitted_track> read_fitted(std::vector<std::string> const &Lines);
|
||||
std::vector<std::string> fitted_lines(std::vector<fitted_track> const &Tracks);
|
||||
|
||||
// //$w, the tracks sharing a grade line, by their key (editor_mode::grade_line_key), each with the number of it
|
||||
struct grade_line
|
||||
{
|
||||
std::string key;
|
||||
int number{0};
|
||||
bool hand{false};
|
||||
};
|
||||
std::vector<grade_line> read_grade_lines(std::vector<std::string> const &Lines);
|
||||
std::vector<std::string> grade_line_lines(std::vector<grade_line> const &Lines);
|
||||
|
||||
// //$b, an object bound to the paths: its kind (infra::name()), category, location, file or name, whether it turns with the track, and
|
||||
// the paths it's bound to, named by their ends
|
||||
struct binding
|
||||
{
|
||||
std::string kind;
|
||||
int category{0};
|
||||
glm::dvec3 location{0.0};
|
||||
std::string key{"-"}; // the file of a model or of an include, the name of a memory cell or an event launcher; - for none
|
||||
bool turns{false};
|
||||
struct anchor
|
||||
{
|
||||
int path{0};
|
||||
glm::dvec3 start{0.0};
|
||||
glm::dvec3 end{0.0};
|
||||
};
|
||||
std::vector<anchor> anchors; // 1 to 4
|
||||
};
|
||||
// lines starting with # are comments, none for them; none for a line it can't read either
|
||||
std::optional<binding> read_binding(std::string const &Line, scene::layer_context const &Context);
|
||||
std::string binding_line(binding const &Binding, scene::layer_context const &Context);
|
||||
// the comment the lines of the bindings start with
|
||||
std::string binding_heading();
|
||||
|
||||
// //$s, the stations described in the signalling tool (srk_tool)
|
||||
enum class block_kind
|
||||
{
|
||||
semi, // semi-automatic: a warning disc before the entry signal
|
||||
three, // the automatic one of three aspects: the block sections no shorter than the braking distance
|
||||
four // of four aspects, the warning two signals ahead: the sections no shorter than half of it
|
||||
};
|
||||
struct station
|
||||
{
|
||||
std::string anchor; // the name of a switch of the station
|
||||
std::string code; // the abbreviation of the station, as MMz
|
||||
std::string name; // utf-8
|
||||
std::string line; // the number of the railway line
|
||||
std::string km; // of the axis of the station along the line, empty while unknown
|
||||
bool reversed{false}; // the km rise to the left of the schematic, the switches numbered from there
|
||||
int braking{0}; // m, the braking distance of the line set by hand, 0: after its speed
|
||||
std::map<std::string, block_kind> blocks; // of the lines by their entry signals, as set by hand
|
||||
std::map<std::string, bool> ways; // the automatic block of the lines by their entry signals both ways, as set by hand
|
||||
std::vector<glm::dvec3> joints_added; // the joints of the track circuits put by hand, on plain tracks
|
||||
std::vector<glm::dvec3> joints_removed; // where the planned joints were taken away by hand
|
||||
};
|
||||
// none for a line which isn't one of a station, or names no switch
|
||||
std::optional<station> read_station(std::string const &Line);
|
||||
std::vector<std::string> station_lines(std::vector<station> const &Stations);
|
||||
|
||||
// //$c, where the camera was at the last save
|
||||
struct camera
|
||||
{
|
||||
glm::dvec3 position{0.0};
|
||||
glm::vec3 angle{0.f};
|
||||
};
|
||||
std::optional<camera> read_camera(std::vector<std::string> const &Lines);
|
||||
std::string camera_line(camera const &Camera);
|
||||
|
||||
// //$o, whether the orthophoto is on and, with Origin, where the scenery lies on the map, PUWG 1992 northing and easting; the settings
|
||||
// the older sceneries carry besides are passed over. returns: false if the line says none of it
|
||||
std::string orthophoto_line(bool const Enabled, bool const Origin, double const North, double const East);
|
||||
bool read_orthophoto(std::string const &Line, bool &Enabled, double &North, double &East);
|
||||
|
||||
// //$z, the area the editor downloads the orthophoto and the terrain model in, PUWG 1992 easting northing: none, below 3 points
|
||||
std::vector<std::string> area_lines(std::vector<glm::dvec2> const &Polygon);
|
||||
std::vector<glm::dvec2> read_area(std::vector<std::string> const &Lines);
|
||||
|
||||
} // namespace editor_records
|
||||
@@ -12,6 +12,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include "editor/editorFormat.hpp"
|
||||
#include "editor/editorGeometry.hpp"
|
||||
#include "editor/editorAlignmentStore.hpp"
|
||||
#include "editor/editorRecords.hpp"
|
||||
|
||||
#include "world/Track.h"
|
||||
#include "simulation/simulation.h"
|
||||
@@ -19,6 +20,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <iterator>
|
||||
#include <cstdlib>
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
@@ -39,18 +41,7 @@ std::vector<record> g_base; // as they were before the changes not yet in the un
|
||||
bool g_changed{false};
|
||||
bool g_loaded{false};
|
||||
|
||||
// format of the lines, coordinates in the space of the file:
|
||||
// <switch|slip|crossing|double> <name> <type> <rail> <R> <n of 1:n> <hand L|R|-> <a> <b> <R of the main track, + right, - left, 0 straight>
|
||||
// parts <count> <names>... shape <main end along, across> <diverging end along, across> start <x y z> dir <x z>
|
||||
// km <km|-> number <label|-> source <designed|measured> [middle <R in the middle of the slip curves of a double slip>]
|
||||
std::string word(std::string const &Text)
|
||||
{
|
||||
if (Text.empty())
|
||||
return "-";
|
||||
auto result{Text};
|
||||
std::replace(result.begin(), result.end(), ' ', '_');
|
||||
return result;
|
||||
}
|
||||
// the lines and their format: editor_records::read_switches() and switch_lines()
|
||||
|
||||
glm::dvec2 direction_of(TTrack const &Track)
|
||||
{
|
||||
@@ -102,40 +93,9 @@ void mark(scene::layer_handle const Layer)
|
||||
{
|
||||
if (false == scene::Layers.valid(Layer))
|
||||
return;
|
||||
auto const &context{scene::Layers.layer(Layer).context_insert()};
|
||||
std::vector<std::string> lines;
|
||||
for (auto const &entry : g_records)
|
||||
{
|
||||
if (entry.layer != Layer)
|
||||
continue;
|
||||
if (lines.empty())
|
||||
lines.emplace_back("# switches placed in the track editor, the simulation skips these lines");
|
||||
auto const start{context.to_local(entry.start)};
|
||||
auto const ahead{context.to_local(entry.start + glm::dvec3{entry.direction.x, 0.0, entry.direction.y})};
|
||||
auto direction{plan_of(ahead - start)};
|
||||
direction = glm::length(direction) > 1e-12 ? glm::normalize(direction) : entry.direction;
|
||||
auto text{format("%s %s %s %s %.3f %.3f %c %.3f %.3f %.3f parts %zu", entry.kind.c_str(), word(entry.name).c_str(), word(entry.type).c_str(), word(entry.rail).c_str(), entry.radius, entry.ratio, entry.hand, entry.a, entry.b, entry.main_radius,
|
||||
entry.parts.size())};
|
||||
for (auto const &part : entry.parts)
|
||||
text += ' ' + word(part);
|
||||
if (entry.shaped)
|
||||
text += format(" shape %.4f %.4f %.4f %.4f", entry.shape.x, entry.shape.y, entry.shape.z, entry.shape.w);
|
||||
text += format(" start %.4f %.4f %.4f dir %.9f %.9f km ", start.x, start.y, start.z, direction.x, direction.y);
|
||||
text += entry.km.has_value() ? format("%.3f", *entry.km / 1000.0) : std::string{"-"};
|
||||
text += " number " + word(entry.number) + " source " + word(entry.source);
|
||||
if (entry.middle > 0.0)
|
||||
text += format(" middle %.3f", entry.middle);
|
||||
if (entry.lift != 0.0 || entry.lift_end != 0.0)
|
||||
{
|
||||
auto const from{context.to_local(entry.lift_from)};
|
||||
auto const to{context.to_local(entry.lift_to)};
|
||||
text += format(" lift %.4f %.4f %.4f %.4f %.4f %.4f %.4f ramp %.3f", entry.lift, from.x, from.y, from.z, to.x, to.y, to.z, entry.ramp);
|
||||
if (entry.lift_end != entry.lift)
|
||||
text += format(" liftend %.4f", entry.lift_end);
|
||||
}
|
||||
lines.push_back(text);
|
||||
}
|
||||
scene::Layers.mark(Layer, kMark, std::move(lines));
|
||||
std::vector<record> records;
|
||||
std::copy_if(g_records.begin(), g_records.end(), std::back_inserter(records), [&](record const &Entry) { return Entry.layer == Layer; });
|
||||
scene::Layers.mark(Layer, kMark, editor_records::switch_lines(records, scene::Layers.layer(Layer).context_insert()));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@@ -155,68 +115,8 @@ void load()
|
||||
g_loaded = true;
|
||||
g_records.clear();
|
||||
for (auto const layer : scene::Layers.marked_layers(kMark))
|
||||
{
|
||||
auto const &context{scene::Layers.layer(layer).context_insert()};
|
||||
for (auto const &text : scene::Layers.marked(layer, kMark))
|
||||
{
|
||||
std::istringstream line{text};
|
||||
record entry;
|
||||
entry.layer = layer;
|
||||
std::string keyword;
|
||||
std::string hand;
|
||||
std::string km;
|
||||
std::size_t count{0};
|
||||
line >> entry.kind;
|
||||
if (entry.kind != "switch" && entry.kind != "slip" && entry.kind != "crossing" && entry.kind != "double" && entry.kind != "connection")
|
||||
continue;
|
||||
line >> entry.name >> entry.type >> entry.rail >> entry.radius >> entry.ratio >> hand >> entry.a >> entry.b >> entry.main_radius >> keyword >> count;
|
||||
if (line.fail() || keyword != "parts" || count == 0 || count > 64)
|
||||
continue;
|
||||
entry.hand = hand.empty() ? '-' : hand.front();
|
||||
entry.parts.resize(count);
|
||||
for (auto &part : entry.parts)
|
||||
line >> part;
|
||||
glm::dvec3 start{0.0};
|
||||
glm::dvec3 ahead{0.0};
|
||||
glm::dvec2 direction{0.0, 1.0};
|
||||
line >> keyword;
|
||||
if (keyword == "shape")
|
||||
{
|
||||
line >> entry.shape.x >> entry.shape.y >> entry.shape.z >> entry.shape.w >> keyword;
|
||||
entry.shaped = true;
|
||||
}
|
||||
line >> start.x >> start.y >> start.z >> keyword >> direction.x >> direction.y >> keyword >> km >> keyword >> entry.number >> keyword >> entry.source;
|
||||
if (line.fail())
|
||||
continue;
|
||||
while (line >> keyword)
|
||||
{
|
||||
if (keyword == "middle")
|
||||
line >> entry.middle;
|
||||
else if (keyword == "lift")
|
||||
{
|
||||
glm::dvec3 from{0.0}, to{0.0};
|
||||
line >> entry.lift >> from.x >> from.y >> from.z >> to.x >> to.y >> to.z >> keyword >> entry.ramp;
|
||||
entry.lift_end = entry.lift;
|
||||
entry.lift_from = context.to_world(from);
|
||||
entry.lift_to = context.to_world(to);
|
||||
}
|
||||
else if (keyword == "liftend")
|
||||
line >> entry.lift_end;
|
||||
}
|
||||
entry.start = context.to_world(start);
|
||||
ahead = context.to_world(start + glm::dvec3{direction.x, 0.0, direction.y});
|
||||
entry.direction = plan_of(ahead - entry.start);
|
||||
entry.direction = glm::length(entry.direction) > 1e-12 ? glm::normalize(entry.direction) : glm::dvec2{0.0, 1.0};
|
||||
if (km != "-")
|
||||
{
|
||||
char *end{nullptr};
|
||||
auto const value{std::strtod(km.c_str(), &end)};
|
||||
if (end != km.c_str() && *end == '\0' && std::isfinite(value))
|
||||
entry.km = value * 1000.0;
|
||||
}
|
||||
for (auto &entry : editor_records::read_switches(scene::Layers.marked(layer, kMark), scene::Layers.layer(layer).context_insert(), layer))
|
||||
g_records.push_back(std::move(entry));
|
||||
}
|
||||
}
|
||||
g_base = g_records;
|
||||
g_changed = false;
|
||||
if (false == g_records.empty())
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
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 "scene/scenelayers.h"
|
||||
|
||||
namespace scene
|
||||
{
|
||||
|
||||
// converts world space location to the one which produces it when loaded with this context in effect
|
||||
glm::dvec3 layer_context::to_local(glm::dvec3 Location) const
|
||||
{
|
||||
// reverse of the transformation done by the scenery loader: rotation around the vertical axis, then scale, then offset
|
||||
Location -= offset;
|
||||
Location /= glm::dvec3{scale};
|
||||
if (rotation != glm::vec3{0.f})
|
||||
{
|
||||
Location = glm::rotateY<double>(Location, -glm::radians(static_cast<double>(rotation.y)));
|
||||
}
|
||||
return Location;
|
||||
}
|
||||
|
||||
glm::dvec3 layer_context::to_world(glm::dvec3 Location) const
|
||||
{
|
||||
if (rotation != glm::vec3{0.f})
|
||||
{
|
||||
Location = glm::rotateY<double>(Location, glm::radians(static_cast<double>(rotation.y)));
|
||||
}
|
||||
Location *= glm::dvec3{scale};
|
||||
Location += offset;
|
||||
return Location;
|
||||
}
|
||||
|
||||
bool layer_context::matches(layer_context const &Other) const
|
||||
{
|
||||
return glm::all(glm::epsilonEqual(offset, Other.offset, 1e-4)) && glm::all(glm::epsilonEqual(rotation, Other.rotation, 1e-4f)) && glm::all(glm::epsilonEqual(scale, Other.scale, 1e-5f));
|
||||
}
|
||||
|
||||
} // namespace scene
|
||||
+1
-28
@@ -32,34 +32,7 @@ namespace scene
|
||||
|
||||
node_layers Layers;
|
||||
|
||||
// converts world space location to the one which produces it when loaded with this context in effect
|
||||
glm::dvec3 layer_context::to_local(glm::dvec3 Location) const
|
||||
{
|
||||
// reverse of the transformation done by the scenery loader: rotation around the vertical axis, then scale, then offset
|
||||
Location -= offset;
|
||||
Location /= glm::dvec3{scale};
|
||||
if (rotation != glm::vec3{0.f})
|
||||
{
|
||||
Location = glm::rotateY<double>(Location, -glm::radians(static_cast<double>(rotation.y)));
|
||||
}
|
||||
return Location;
|
||||
}
|
||||
|
||||
glm::dvec3 layer_context::to_world(glm::dvec3 Location) const
|
||||
{
|
||||
if (rotation != glm::vec3{0.f})
|
||||
{
|
||||
Location = glm::rotateY<double>(Location, glm::radians(static_cast<double>(rotation.y)));
|
||||
}
|
||||
Location *= glm::dvec3{scale};
|
||||
Location += offset;
|
||||
return Location;
|
||||
}
|
||||
|
||||
bool layer_context::matches(layer_context const &Other) const
|
||||
{
|
||||
return glm::all(glm::epsilonEqual(offset, Other.offset, 1e-4)) && glm::all(glm::epsilonEqual(rotation, Other.rotation, 1e-4f)) && glm::all(glm::epsilonEqual(scale, Other.scale, 1e-5f));
|
||||
}
|
||||
// layer_context: scene/scenelayercontext.cpp, which the unit tests of the //$ lines of the editor link alone
|
||||
|
||||
std::size_t basic_layer::item_count() const
|
||||
{
|
||||
|
||||
@@ -34,6 +34,22 @@ add_executable(${UNIT_TESTS_NAME}
|
||||
"${CMAKE_SOURCE_DIR}/editor/editorFouling.cpp"
|
||||
# and the http client the editor fetches its aids with
|
||||
"${CMAKE_SOURCE_DIR}/editor/editorHttp.cpp"
|
||||
# and the //$ lines it keeps in the scenery files, and the descriptions of the templates (//$e)
|
||||
"${CMAKE_SOURCE_DIR}/editor/editorRecords.cpp"
|
||||
"${CMAKE_SOURCE_DIR}/scene/scenelayercontext.cpp"
|
||||
"${CMAKE_SOURCE_DIR}/editor/editorIncludeInfo.cpp"
|
||||
# the tracks read from the text of the scenery files and written back, with no scene (test_track_text.cpp): the track and
|
||||
# what reading and writing it takes, the rest of the engine it reaches for stood in by track_stubs.cpp
|
||||
"${CMAKE_SOURCE_DIR}/world/Track.cpp"
|
||||
"${CMAKE_SOURCE_DIR}/world/Segment.cpp"
|
||||
"${CMAKE_SOURCE_DIR}/world/TrackUneven.cpp"
|
||||
"${CMAKE_SOURCE_DIR}/world/MemCell.cpp"
|
||||
"${CMAKE_SOURCE_DIR}/scene/scenenode.cpp"
|
||||
"${CMAKE_SOURCE_DIR}/utilities/Timer.cpp"
|
||||
"${CMAKE_SOURCE_DIR}/rendering/geometrybank.cpp"
|
||||
track_stubs.cpp
|
||||
# and the cant the track editor matches at the joints of the tracks
|
||||
"${CMAKE_SOURCE_DIR}/editor/editorTrackShape.cpp"
|
||||
${UNIT_TEST_CASES})
|
||||
|
||||
# the core library brings the game's build settings along
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
// //$h: horizontal alignments designed in the track editor, as editor_records::alignment_lines() writes them. The element lines are
|
||||
// the ones the design makes (alignment::compute()), which the editor writes in place of those it read
|
||||
//$h # horizontal alignments designed in the track editor, the simulation skips these lines
|
||||
//$h alignment 0.0000 0.0000 0.0000 1000.0000 0.0000 1000.0000
|
||||
//$h source designed origin 1200.0000 shape clothoid speed 100.0 fit 0.125
|
||||
//$h ends 0.000000000 1.000000000 1.000000000 0.000000000 0.000000 0.000000 0.000 0.000
|
||||
//$h norms 1500.0 0.600 150.0 35.0 10.00 0.300 2.00 30.00 0.400
|
||||
//$h pieces 3 2.000
|
||||
//$h vertex 0.0000 1000.0000 0.0000 400.000 60.000 60.000 80.0 0 0 0.500000000 0
|
||||
//$h click 0.0000 0.0000 50.0000
|
||||
//$h element straight -1 0.0000 569.6307 0.000 0.000 0.0 0.0000 0.0000 0.000000000 1.000000000
|
||||
//$h element transition 0 569.6307 60.0000 0.000 -400.000 80.0 0.0000 569.6307 0.000000000 1.000000000
|
||||
//$h element arc 0 629.6307 568.3185 -400.000 -400.000 80.0 1.4994 629.5970 0.074929707 0.997188818
|
||||
//$h element transition 0 1197.9492 60.0000 -400.000 0.000 80.0 370.4030 998.5006 0.997188818 0.074929707
|
||||
//$h element straight -1 1257.9492 569.6307 0.000 0.000 0.0 430.3693 1000.0000 1.000000000 0.000000000
|
||||
//$h end
|
||||
//$h alignment 2000.0000 0.0000 0.0000 3000.0000 0.0000 2000.0000
|
||||
//$h source traced origin 0.0000 shape parabola speed 80.0
|
||||
//$h ends 0.000000000 1.000000000 1.000000000 0.000000000 0.000000 0.000000 1200.000 0.000 turns 1 0 curved 1 0 60.0 0.0
|
||||
//$h norms 1500.0 0.600 150.0 35.0 10.00 0.300 2.00 30.00 0.400
|
||||
//$h pieces 2 1.500
|
||||
//$h kept 10.0000 1500.0000
|
||||
//$h vertex 2000.0000 2000.0000 0.0000 600.000 50.000 50.000 70.0 0 1 0.500000000 1 900.000 40.000 0.500000000 cants 70.0 50.0 ramps 0.000 -1.000 5.000 60.000
|
||||
//$h element straight -1 0.0000 1289.6263 0.000 0.000 0.0 2000.0000 0.0000 0.000000000 1.000000000
|
||||
//$h element transition 0 1289.6263 50.0000 0.000 -600.000 70.0 2000.0000 1289.6263 0.000000000 1.000000000
|
||||
//$h element arc 0 1339.6263 433.7389 -600.000 -600.000 70.0 2000.6944 1339.6176 0.041654611 0.999132070
|
||||
//$h element transition 0 1773.3652 40.0000 -600.000 -900.000 70.0 2167.1634 1729.9587 0.692223009 0.721683660
|
||||
//$h element arc 0 1813.3652 650.6083 -900.000 -900.000 50.0 2195.6917 1757.9894 0.731227954 0.682133183
|
||||
//$h element transition 0 2463.9735 50.0000 -900.000 0.000 50.0 2784.6148 1999.5371 0.999614222 0.027774206
|
||||
//$h element straight -1 2513.9735 165.3891 0.000 0.000 0.0 2834.6109 2000.0000 1.000000000 0.000000000
|
||||
//$h end
|
||||
@@ -0,0 +1,5 @@
|
||||
// //$z: the area the orthophoto and the terrain model are downloaded in, as editor_records::area_lines() writes it
|
||||
//$z # the area the editor downloads the orthophoto and the terrain model in, PUWG 1992 easting northing
|
||||
//$z point 645000.00 512000.00
|
||||
//$z point 646000.00 512000.00
|
||||
//$z point 646000.50 513000.25
|
||||
@@ -0,0 +1,4 @@
|
||||
// //$b: objects bound to the paths, as editor_records::binding_line() writes them, after binding_heading()
|
||||
//$b # objects bound to the paths in the track editor, they follow changes of the track; the simulation skips these lines
|
||||
//$b model 2 10.0000 0.5000 20.0000 models/slupy/slup.t3d 1 1 0 0.0000 0.0000 0.0000 0.0000 0.0000 100.0000
|
||||
//$b memcell 4 12.0000 0.0000 30.0000 sem_mem 0 2 0 0.0000 0.0000 0.0000 0.0000 0.0000 100.0000 1 0.0000 0.0000 0.0000 5.0000 0.0000 100.0000
|
||||
@@ -0,0 +1,2 @@
|
||||
// //$c: where the camera was at the last save, as editor_records::camera_line() writes it
|
||||
//$c 1234.500 56.250 -789.125 0.12500 -1.50000
|
||||
@@ -0,0 +1,4 @@
|
||||
// //$t: the tracks whose grade line was fitted, as editor_records::fitted_lines() writes them
|
||||
//$t # the tracks whose grade line was fitted in the track editor, with their shape then; the simulation skips these lines
|
||||
//$t fitted tor_1 00ff00ff12345678
|
||||
//$t fitted tor_2 0123456789abcdef hand
|
||||
@@ -0,0 +1,4 @@
|
||||
// //$w: the tracks sharing a grade line, as editor_records::grade_line_lines() writes them
|
||||
//$w # the tracks sharing a grade line, each with the number of it; the simulation skips these lines
|
||||
//$w gradeline tor_1@100,200 3
|
||||
//$w gradeline tor_2@-50,7 3 hand
|
||||
@@ -0,0 +1,5 @@
|
||||
// //$k: the kilometrage of the lines, as editor_records::kilometrage_lines() writes it: the marks, then the vias
|
||||
//$k # kilometrage of the lines set in the track editor, the simulation skips these lines
|
||||
//$k mark 91 100.0000 0.0000 200.0000 way 0.000000000 1.000000000 km 12.345
|
||||
//$k mark 91 100.0000 0.0000 1200.0000 way 0.000000000 1.000000000 km 13.345 beyond 14.000
|
||||
//$k via 91 105.0000 0.0000 700.0000
|
||||
@@ -0,0 +1,3 @@
|
||||
// //$o: the orthophoto on, with where the scenery lies, and off, where it lies nowhere, as editor_records::orthophoto_line() writes it
|
||||
//$o on 1 origin 512345.67 645678.90
|
||||
//$o on 0
|
||||
@@ -0,0 +1,10 @@
|
||||
// //$p: grade lines designed in the profile tool, as editor_records::profile_lines() writes them
|
||||
//$p # vertical profiles (grade lines) designed in the track editor, the simulation skips these lines
|
||||
//$p profile 500.0000 0.0000 100.0000 0.0000 0.0000 102.5000 500.0000 0.0000 101.2500 250.0000
|
||||
//$p speed 120.0 origin 1000.0000 join 1 0
|
||||
//$p norms 6.0000 2.5000 0.4000 2000.0 2.0000 50.00 0.0050
|
||||
//$p departure 0.0150
|
||||
//$p point 0.0000 100.0000 0.0 0
|
||||
//$p point 250.0000 101.0000 10000.0 1
|
||||
//$p point 500.0000 102.5000 0.0 0
|
||||
//$p end
|
||||
@@ -0,0 +1,11 @@
|
||||
//$e version: 1
|
||||
//$e name: Semaphore, 2 arms
|
||||
//$e category: signals
|
||||
//$e description: a semaphore of the tests of the descriptions
|
||||
//$e signal: {kind: semaphore, mount: mast, arms: 2, height: 5.5, aspects: {Sr1: stop, S2: vmax}}
|
||||
//$e params:
|
||||
//$e - {id: 1, role: name, label: Name}
|
||||
//$e - {id: 2, role: pos.x}
|
||||
//$e - {id: 3, role: free, label: Track, default: tor1}
|
||||
// the template of the tests of the descriptions (//$e): its content is left as it is
|
||||
node -1 0 (p1)_mem memcell (p2) 0 0 none 0 0 (p3) endmemcell
|
||||
@@ -0,0 +1,4 @@
|
||||
// //$s: stations described in the signalling tool, as editor_records::station_lines() writes them; the names in windows-1250
|
||||
//$s # stations described in the track editor, the simulation skips these lines
|
||||
//$s station MMz line 91 km 12.345 from left anchor z1 braking 700 blocks bpd_a=sbl4,bpd_b=semi ways bpd_a=2 joints +100.000/0.000/200.000,-110.500/0.000/205.250 name £ódŸ Kaliska
|
||||
//$s station - line - km - from right anchor z7 blocks x=sbl name Stacja
|
||||
@@ -0,0 +1,5 @@
|
||||
// //$r: switches placed in the track editor, as editor_records::switch_lines() writes them
|
||||
//$r # switches placed in the track editor, the simulation skips these lines
|
||||
//$r switch z1 Rz 60E1 500.000 12.000 L 15.550 15.550 0.000 parts 1 z1 shape 33.2300 0.0000 33.1000 1.8000 start 100.0000 0.0000 200.0000 dir 0.000000000 1.000000000 km 12.345 number 1 source designed
|
||||
//$r connection c1 Rz 60E1 500.000 12.000 R 15.550 15.550 -1200.000 parts 2 z3 z4 start 110.0000 0.0000 210.0000 dir 0.600000000 0.800000000 km - number - source measured lift 0.0600 110.0000 0.0000 210.0000 150.0000 0.0000 240.0000 ramp 60.000 liftend 0.0400
|
||||
//$r slip s1 Rkpd 49E1 190.000 9.000 - 16.615 16.615 0.000 parts 4 s1a s1b s1c s1d start 0.0000 0.0000 0.0000 dir 1.000000000 0.000000000 km 0.500 number 5ab source designed middle 300.000
|
||||
@@ -0,0 +1,11 @@
|
||||
// what TTrack::Load() reads and export_as_text() doesn't write back yet: each the entry of a test of test_track_text.cpp which fails
|
||||
// until it does (doctest::should_fail)
|
||||
// angle1, angle2: the angles the ends of the track are cut at, read and dropped ("not used/implemented")
|
||||
node -1 0 angles track normal 10 1.435 0.15 25 20 0 flat unvis 0 0 0 0 0 0 0 0 0 0 0 0 10 0 0 angle1 15 angle2 -15 endtrack
|
||||
// fouling1, fouling2: the models of the fouling points at the ends, read and dropped ("not used/implemented")
|
||||
node -1 0 fouling track normal 10 1.435 0.15 25 20 0 flat unvis 0 0 0 0 0 0 0 0 0 0 0 0 10 0 0 fouling1 ukres_a fouling2 ukres_b endtrack
|
||||
// the isolated circuit after @ in the name: taken out of the name with the letter before the @
|
||||
node -1 0 tor1@iso1 track normal 10 1.435 0.15 25 20 0 flat unvis 0 0 0 0 0 0 0 0 0 0 0 0 10 0 0 endtrack
|
||||
// the attributes are written to 6 significant digits, short of the 9 of a float: the gauge, the friction, the speed and the texture
|
||||
// height here lose their last digits on the first save
|
||||
node -1 0 digits track normal 10 1.4351234 0.1512345 25 20 0 flat vis rail 4 ballast 0.2012345 0.5 1.1 0 0 0 0 0 0 0 0 0 0 0 0 10 0 0 velocity 87.65432 endtrack
|
||||
@@ -0,0 +1,9 @@
|
||||
// the other paths TTrack::Load() reads, written the way the game writes them: read and written back each comes out the same
|
||||
// a river, whose texture height is written upwards as of the tracks and kept downwards
|
||||
node -1 0 river1 track river 50 10 0.15 25 20 0 flat vis woda 10 brzeg 1 2 0.5 0 0 0 0 0 0 0 0 0 0 0 0 50 0 0 endtrack
|
||||
// a tributary, a river of its first path, the second one kept to be written back
|
||||
node -1 0 tributary1 track tributary 50 10 0.15 25 20 0 flat unvis 0 0 0 0 0 0 0 0 0 0 0 0 50 0 0 0 0 50 0 0 0 0 0 0 0 0 10 50 0 0 endtrack
|
||||
// a road, invisible
|
||||
node -1 0 road1 track road 50 6 0.15 25 20 0 flat unvis 0 0 0 0 0 0 0 0 0 0 0 0 50 0 0 velocity 50 endtrack
|
||||
// a road crossing, invisible, of the two paths of its first road
|
||||
node -1 0 cross1 track cross 20 6 0.15 25 20 0 flat unvis -10 0 0 0 0 0 0 0 0 0 10 0 0 0 0 0 0 -10 0 0 0 0 0 0 0 0 0 10 0 0 endtrack
|
||||
@@ -0,0 +1,6 @@
|
||||
// paths made of pieces (pieces1, pieces2), kept after the path itself for the versions which know only the path: read and written back
|
||||
// each comes out the same
|
||||
// a plain track of two pieces
|
||||
node -1 0 pieced track normal 60 1.435 0.15 25 20 0 flat vis rail_screw_used1 4 tpbps-new2 0.2 0.5 1.1 0 0 0 0 0 0 0 0 0 0 0 0 60 0 0 pieces1 2 0 0 0 0 0 0 0 0 0 0 0 0 30 0 0 0 0 30 0 0 0 0 0 0 0 0 0 60 0 0 endtrack
|
||||
// a switch whose diverging path is made of two pieces joining its ends
|
||||
node -1 0 piecedswitch track switch 33.23 1.435 0.25 10 20 0 flat vis rail_screw_used1 4 tpbps-new2 0.2 0.5 1.1 0 0 0 0 0 0 11 0 0 -11 0 0 33.23 0 0 0 0 0 0 0 0 11 0.6 0 -11 1.8 0 33.1 0 300 pieces2 2 0 0 0 0 0 0 5 0 0 -5 0.25 0 15 0 600 0.25 0 15 0 0.5 0 5 1.2 0 -5 1.8 0 33.1 0 300 endtrack
|
||||
@@ -0,0 +1,7 @@
|
||||
// plain tracks, each written the way the game writes it (TTrack::export_as_text_): read and written back it comes out the same
|
||||
// a straight with the attributes of a plain track, the events in the order they're written in
|
||||
node -1 0 plain track normal 100 1.435 0.15 25 20 0 flat vis rail_screw_used1 4 tpbps-new2 0.2 0.5 1.1 0 0 0 0 0 0 0 0 0 0 0 0 100 0 0 event0 plain_ev0 eventall0 plain_all0 event1 plain_ev1 eventall1 plain_all1 event2 plain_ev2 eventall2 plain_all2 velocity 100 isolated plain_iso overhead 0 vradius 5000 railprofile s49 friction plain_cell endtrack
|
||||
// a curve with cant, its rolls at both ends, a radius, the unevenness, the buckle, the welded rail and the sleeper models
|
||||
node 500 10.5 curve track normal 24.7933 1.435 0.15 25 20 0 mountains vis rail_screw_used1 4 tpbps-new2 0.2 0.5 1.1 100 2 50 1.5 0 0 20 -5 0 -20 110 2.5 70 2.25 300 velocity 80 uneven 18;12;10;8;6 buckle 30;20;15;1 cwr 22;2;1 sleepermodel 0.6 models/tory/podklad.e3d none 0 0 -0.1 -0.05 endtrack
|
||||
// on a bridge, invisible, damaged
|
||||
node -1 0 bridge track normal 40 1.435 0.2 -1 10 1 bridge unvis 0 0 0 0 0 0 0 0 0 0 0 0 40 0 0 endtrack
|
||||
@@ -0,0 +1,13 @@
|
||||
// the speeds of tracks, switches and turntables: a limit, a limit of the diverging track (below 0), a limit below 1 km/h and none (0)
|
||||
// read and written back each comes out the same
|
||||
node -1 0 v40 track normal 10 1.435 0.15 25 20 0 flat unvis 0 0 0 0 0 0 0 0 0 0 0 0 10 0 0 velocity 40 endtrack
|
||||
node -1 0 vminus40 track normal 10 1.435 0.15 25 20 0 flat unvis 0 0 0 0 0 0 0 0 0 0 0 0 10 0 0 velocity -40 endtrack
|
||||
node -1 0 vhalf track normal 10 1.435 0.15 25 20 0 flat unvis 0 0 0 0 0 0 0 0 0 0 0 0 10 0 0 velocity 0.5 endtrack
|
||||
node -1 0 vzero track normal 10 1.435 0.15 25 20 0 flat unvis 0 0 0 0 0 0 0 0 0 0 0 0 10 0 0 velocity 0 endtrack
|
||||
node -1 0 vnone track normal 10 1.435 0.15 25 20 0 flat unvis 0 0 0 0 0 0 0 0 0 0 0 0 10 0 0 endtrack
|
||||
node -1 0 sw40 track switch 33.23 1.435 0.25 10 20 0 flat unvis 0 0 0 0 0 0 0 0 0 0 0 0 33.23 0 0 0 0 0 0 0 0 11 0.6 0 -11 1.8 0 33.1 0 300 velocity 40 endtrack
|
||||
node -1 0 swminus40 track switch 33.23 1.435 0.25 10 20 0 flat unvis 0 0 0 0 0 0 0 0 0 0 0 0 33.23 0 0 0 0 0 0 0 0 11 0.6 0 -11 1.8 0 33.1 0 300 velocity -40 endtrack
|
||||
node -1 0 swhalf track switch 33.23 1.435 0.25 10 20 0 flat unvis 0 0 0 0 0 0 0 0 0 0 0 0 33.23 0 0 0 0 0 0 0 0 11 0.6 0 -11 1.8 0 33.1 0 300 velocity 0.5 endtrack
|
||||
node -1 0 swzero track switch 33.23 1.435 0.25 10 20 0 flat unvis 0 0 0 0 0 0 0 0 0 0 0 0 33.23 0 0 0 0 0 0 0 0 11 0.6 0 -11 1.8 0 33.1 0 300 velocity 0 endtrack
|
||||
node -1 0 tthalf track turn 20 1.435 0.15 25 20 0 flat unvis -10 0 0 0 0 0 0 0 0 0 10 0 0 0 0 velocity 0.5 endtrack
|
||||
node -1 0 ttzero track turn 20 1.435 0.15 25 20 0 flat unvis -10 0 0 0 0 0 0 0 0 0 10 0 0 0 0 velocity 0 endtrack
|
||||
@@ -0,0 +1,6 @@
|
||||
// switches, written the way the game writes them: read and written back each comes out the same
|
||||
// a switch with all its attributes: the speed of the diverging track, the trackbed, the frog made from the rails, the movable nose,
|
||||
// the blades, the unevenness of both paths, the timbers
|
||||
node -1 0 switch1 track switch 33.23 1.435 0.25 10 20 0 flat vis rail_screw_used1 4 tpbps-new2 0.2 0.5 1.1 0 0 0 0 0 0 11 0 0 -11 0 0 33.23 0 0 0 0 0 0 0 0 11 0.6 0 -11 1.8 0 33.1 0 300 velocity -40 isolated switch_iso trackbed tpbps-new2 frogs movablenose blades 5.5 0.16 uneven 14;10;8;6;4;2 timbermodel models/tory/rz_podklady.e3d none endtrack
|
||||
// a plain switch, invisible
|
||||
node -1 0 switch2 track switch 33.23 1.435 0.25 10 20 0 flat unvis 0 0 0 0 0 0 0 0 0 0 0 0 33.23 0 0 0 0 0 0 0 0 11 -0.6 0 -11 -1.8 0 33.1 0 -300 endtrack
|
||||
@@ -0,0 +1,2 @@
|
||||
// turntables, written the way the game writes them: read and written back each comes out the same
|
||||
node -1 0 turntable1 track turn 20 1.435 0.15 25 20 0 flat vis rail_screw_used1 4 tpbps-new2 0.2 0.5 1.1 -10 0 0 0 0 0 0 0 0 0 10 0 0 0 0 velocity 10 endtrack
|
||||
@@ -105,11 +105,6 @@ void node_layers::instance_begin(std::string const &, source_span const &) { //
|
||||
// no layers in the tests, so nothing to keep track of
|
||||
}
|
||||
|
||||
// basic_node has no key function for the Itanium C++ ABI (tooltip() is declared plain but defined inline), so
|
||||
// GCC and Clang emit its vtable wherever scenenode.h is used, here too, and the vtable wants radius_().
|
||||
// the same as the game's, in scene/scenenode.cpp
|
||||
float basic_node::radius_() const {
|
||||
return 0.f;
|
||||
}
|
||||
// basic_node, whose vtable GCC and Clang emit wherever scenenode.h is used, is the game's: scene/scenenode.cpp is a part of the tests
|
||||
|
||||
} // namespace scene
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
// the cant of the tracks the editor lays and joins: from mm to the roll of the paths and back, signed with the turn, and matched
|
||||
// across the joints of the tracks
|
||||
//
|
||||
// the inspector of the editor shows and takes the cant on a base of 1500 mm in lambdas of its own (application/editormodetrack.cpp);
|
||||
// named, as editor_mode::cant_of_roll() and roll_of_cant(), they come with the quick fixes of the track editing, and their tests with them
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "doctest.h"
|
||||
#include "editor/editorAlignment.hpp"
|
||||
#include "editor/editorGeometry.hpp"
|
||||
#include "editor/editorTrack.hpp"
|
||||
#include "track_text.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace {
|
||||
|
||||
// a corner of two straights eased by a curve of R 400 with transitions of 60 m and a cant of 80 mm: from the origin along z, then
|
||||
// along x, to +x for Side 1 and to -x for Side -1
|
||||
alignment::design corner(double const Side) {
|
||||
alignment::design design;
|
||||
design.start = {0.0, 0.0, 0.0};
|
||||
design.end = {1000.0 * Side, 0.0, 1000.0};
|
||||
design.start_direction = {0.0, 1.0};
|
||||
design.end_direction = {Side, 0.0};
|
||||
alignment::vertex vertex;
|
||||
vertex.position = {0.0, 1000.0};
|
||||
vertex.radius = 400.0;
|
||||
vertex.transition_in = 60.0;
|
||||
vertex.transition_out = 60.0;
|
||||
vertex.cant = 80.0;
|
||||
design.vertices.push_back(vertex);
|
||||
return design;
|
||||
}
|
||||
|
||||
// the cant of a roll, mm, as the editor takes it from the paths: on the gauge of the design, a roll above 0 a cant above 0
|
||||
double cant_of(float const Roll, double const Gauge) {
|
||||
return Gauge * std::sin(glm::radians(static_cast<double>(Roll)));
|
||||
}
|
||||
|
||||
// the paths of the line with the chainage of the start of each
|
||||
struct laid_path {
|
||||
segment_data path;
|
||||
double from{0.0};
|
||||
double to{0.0};
|
||||
};
|
||||
std::vector<laid_path> laid(alignment::result const &Line, alignment::design const &Design) {
|
||||
std::vector<laid_path> result;
|
||||
double chainage{0.0};
|
||||
for (auto const &path : alignment::pieces(Line, Design, alignment::minimum_pieces(Line, Design))) {
|
||||
auto const length{geometry::bezier{path}.plan_length()};
|
||||
result.push_back({path, chainage, chainage + length});
|
||||
chainage += length;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("cant: the paths of a curve roll by the cant designed on the gauge, mm to degrees and back, signed with the turn") {
|
||||
for (auto const side : {1.0, -1.0}) {
|
||||
CAPTURE(side);
|
||||
auto const design{corner(side)};
|
||||
auto const line{alignment::compute(design)};
|
||||
REQUIRE(line.valid);
|
||||
auto const gauge{design.norms.gauge};
|
||||
auto const paths{laid(line, design)};
|
||||
REQUIRE_FALSE(paths.empty());
|
||||
auto steepest{0.f};
|
||||
for (auto const &[path, from, to] : paths) {
|
||||
// the cant the rolls at the ends of each path come back to is the one of the line there, with the sign of its turn
|
||||
for (auto const &[roll, chainage] : {std::pair{path.rolls[0], from}, std::pair{path.rolls[1], to}}) {
|
||||
CAPTURE(chainage);
|
||||
auto const station{alignment::evaluate(line, chainage)};
|
||||
CHECK(cant_of(roll, gauge) == doctest::Approx(station.turn * station.cant).epsilon(1e-3).scale(1.0));
|
||||
if (std::abs(roll) > std::abs(steepest)) {
|
||||
steepest = roll;
|
||||
}
|
||||
}
|
||||
}
|
||||
// the arc rolls by the cant of the curve: 80 mm on the gauge, the sign of its turn
|
||||
CHECK(std::abs(steepest) == doctest::Approx(glm::degrees(std::asin(80.0 / gauge))).epsilon(1e-4));
|
||||
CHECK((steepest < 0.f) == (side > 0.0));
|
||||
}
|
||||
// a curve the other way rolls the other way, by as much
|
||||
auto const right{laid(alignment::compute(corner(1.0)), corner(1.0))};
|
||||
auto const left{laid(alignment::compute(corner(-1.0)), corner(-1.0))};
|
||||
REQUIRE(right.size() == left.size());
|
||||
for (std::size_t index = 0; index < right.size(); ++index) {
|
||||
CHECK(right[index].path.rolls[0] == doctest::Approx(-left[index].path.rolls[0]));
|
||||
CHECK(right[index].path.rolls[1] == doctest::Approx(-left[index].path.rolls[1]));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("cant: at a joint the editor gives the joined track the roll of the track, turned with the way its path goes") {
|
||||
test::track_reading const reading;
|
||||
using kind = editor_track::point_kind;
|
||||
// a straight along z with a ramp of the cant, 1.5 degrees at its start and 2.25 at its end, and one to join to it
|
||||
std::string const ramp{"node -1 0 a track normal 10 1.435 0.15 25 20 0 flat unvis 0 0 0 1.5 0 0 0 0 0 0 0 0 10 2.25 0 endtrack\n"};
|
||||
auto const joined = [](char const *Name) {
|
||||
return std::string{"node -1 0 "} + Name + " track normal 10 1.435 0.15 25 20 0 flat unvis 0 0 10 0 0 0 0 0 0 0 0 0 20 0 0 endtrack\n";
|
||||
};
|
||||
// the roll of a path at its end, for the travel into the path: as it is at its start, turned at its end, where the path comes out
|
||||
auto const track{test::read_track(ramp)};
|
||||
CHECK(editor_track::joint_roll(*track, {0, kind::start}) == doctest::Approx(1.5));
|
||||
CHECK(editor_track::joint_roll(*track, {0, kind::end}) == doctest::Approx(-2.25));
|
||||
CHECK(editor_track::joint_roll(*track, {1, kind::end}) == 0.0); // no such path
|
||||
|
||||
struct joint_case {
|
||||
char const *what;
|
||||
kind own;
|
||||
kind theirs;
|
||||
int changed; // the roll of the joined track the joint sets: 0 at its start, 1 at its end
|
||||
float roll;
|
||||
};
|
||||
for (auto const &[what, own, theirs, changed, roll] : {
|
||||
joint_case{"the end to the start, one path on from the other: the same roll", kind::end, kind::start, 0, 2.25f},
|
||||
joint_case{"the end to the end, the paths facing: the roll turned", kind::end, kind::end, 1, -2.25f},
|
||||
joint_case{"the start to the start, the paths back to back: the roll turned", kind::start, kind::start, 0, -1.5f},
|
||||
joint_case{"the start to the end, one path on from the other: the same roll", kind::start, kind::end, 1, 1.5f},
|
||||
}) {
|
||||
CAPTURE(what);
|
||||
auto const other{test::read_track(joined("b"))};
|
||||
editor_track::match_rolls(*track, {{{0, own}, other.get(), {0, theirs}}});
|
||||
CHECK(other->m_paths[0].rolls[changed] == roll);
|
||||
CHECK(other->m_paths[0].rolls[1 - changed] == 0.f);
|
||||
// the cant seen from either side of the joint, for the travel across it, is the same
|
||||
CHECK(editor_track::joint_roll(*other, {0, theirs}) == doctest::Approx(-editor_track::joint_roll(*track, {0, own})));
|
||||
// and it's what the editor writes
|
||||
auto const again{test::read_track(test::written(*other))};
|
||||
CHECK(again->m_paths[0].rolls == other->m_paths[0].rolls);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,332 @@
|
||||
// the lines the track editor keeps in the scenery files after its //$ marks, read and written back by editor_records
|
||||
// (editor/editorRecords.cpp), the one place the stores of the editor read and write them: the lines of data/records/ are written the
|
||||
// way the editor writes them, so each kind read and written back comes out the same, which a second reading then reads the same as
|
||||
// the first. The descriptions of the templates (//$e) are read and written by editor_includes, in the template files themselves
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "doctest.h"
|
||||
#include "editor/editorIncludeInfo.hpp"
|
||||
#include "editor/editorRecords.hpp"
|
||||
#include "scratch.h"
|
||||
#include "utilities/Globals.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <iterator>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace {
|
||||
|
||||
std::string file_text(std::string const &Path) {
|
||||
std::ifstream file{Path, std::ios::binary};
|
||||
REQUIRE(file.is_open());
|
||||
return {std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>()};
|
||||
}
|
||||
|
||||
// the lines of the file of data/records/ with the mark, the mark taken off as scene::node_layers::scan() takes it: with the blanks
|
||||
// after it, the line ends left out
|
||||
std::vector<std::string> marked(std::string const &File, std::string const &Mark) {
|
||||
std::vector<std::string> result;
|
||||
std::istringstream lines{file_text(std::string{EU07_UNIT_TESTS_DATA} + "/records/" + File)};
|
||||
for (std::string line; std::getline(lines, line);) {
|
||||
while (false == line.empty() && (line.back() == '\r' || line.back() == '\n')) {
|
||||
line.pop_back();
|
||||
}
|
||||
if (line.starts_with(Mark + ' ')) {
|
||||
line.erase(0, Mark.size());
|
||||
line.erase(0, line.find_first_not_of(" \t"));
|
||||
result.push_back(line);
|
||||
}
|
||||
}
|
||||
REQUIRE_FALSE(result.empty());
|
||||
return result;
|
||||
}
|
||||
|
||||
// the lines one under another, for a failed check to show them
|
||||
std::string text(std::vector<std::string> const &Lines) {
|
||||
std::string result;
|
||||
for (auto const &line : Lines) {
|
||||
result += line + '\n';
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// the lines without the comments, which the readers pass over
|
||||
std::vector<std::string> uncommented(std::vector<std::string> Lines) {
|
||||
std::erase_if(Lines, [](std::string const &Line) { return Line.starts_with("#"); });
|
||||
return Lines;
|
||||
}
|
||||
|
||||
// the placement of a file included at an origin: the lines say the same of other places in the world
|
||||
scene::layer_context moved() {
|
||||
scene::layer_context context;
|
||||
context.offset = {1000.0, 5.0, -2000.0};
|
||||
return context;
|
||||
}
|
||||
|
||||
scene::layer_handle constexpr layer{3};
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("editor records: the horizontal alignments (//$h) read and written back come out the same") {
|
||||
auto const lines{marked("alignment.scn", "//$h")};
|
||||
for (auto const &context : {scene::layer_context{}, moved()}) {
|
||||
auto records{editor_records::read_alignments(lines, context, layer)};
|
||||
REQUIRE(records.size() == 2);
|
||||
auto const &record{records.front()};
|
||||
CHECK(record.layer == layer);
|
||||
CHECK(record.design.start == context.to_world({0.0, 0.0, 0.0}));
|
||||
CHECK(record.design.end == context.to_world({1000.0, 0.0, 1000.0}));
|
||||
CHECK(record.source == "designed");
|
||||
CHECK(record.origin == 1200.0);
|
||||
CHECK(record.fit == 0.125);
|
||||
CHECK(record.design.shape == alignment::transition_shape::clothoid);
|
||||
CHECK(record.design.speed == 100.0);
|
||||
CHECK(record.design.norms.gauge == 1500.0);
|
||||
CHECK(record.design.transition_pieces == 3);
|
||||
REQUIRE(record.design.vertices.size() == 1);
|
||||
CHECK(record.design.vertices.front().radius == 400.0);
|
||||
CHECK(record.design.vertices.front().cant == 80.0);
|
||||
REQUIRE(record.clicks.size() == 1);
|
||||
CHECK(record.clicks.front() == context.to_world({0.0, 0.0, 50.0}));
|
||||
CHECK(record.elements.size() == 5);
|
||||
CHECK(record.whole());
|
||||
// a compound curve with the cants of its arcs and ramps of its own, from a curved track, kept for a part of its line
|
||||
auto const &compound{records.back()};
|
||||
CHECK(compound.source == "traced");
|
||||
CHECK(compound.design.shape == alignment::transition_shape::cubic_parabola);
|
||||
CHECK(compound.design.start_radius == 1200.0);
|
||||
CHECK(compound.design.start_turn == 1);
|
||||
CHECK(compound.design.start_curved);
|
||||
CHECK(compound.design.start_cant == 60.0);
|
||||
CHECK(compound.from == 10.0);
|
||||
CHECK(compound.to == 1500.0);
|
||||
REQUIRE(compound.design.vertices.size() == 1);
|
||||
auto const &vertex{compound.design.vertices.front()};
|
||||
CHECK(vertex.compound);
|
||||
REQUIRE(vertex.arcs.size() == 1);
|
||||
CHECK(vertex.arcs.front().radius == 900.0);
|
||||
CHECK(vertex.first_cant == 70.0);
|
||||
CHECK(vertex.arcs.front().cant == 50.0);
|
||||
CHECK(vertex.ramp_out_length == 60.0);
|
||||
// the lines of the elements are the ones the designs make, as alignment_store makes them before it writes the records
|
||||
for (auto &entry : records) {
|
||||
entry.result = alignment::compute(entry.design);
|
||||
REQUIRE(entry.result.valid);
|
||||
}
|
||||
CHECK(text(editor_records::alignment_lines(records, context)) == text(lines));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("editor records: the switches placed (//$r) read and written back come out the same") {
|
||||
auto const lines{marked("switch.scn", "//$r")};
|
||||
for (auto const &context : {scene::layer_context{}, moved()}) {
|
||||
auto const records{editor_records::read_switches(lines, context, layer)};
|
||||
REQUIRE(records.size() == 3);
|
||||
auto const &plain{records[0]};
|
||||
CHECK(plain.kind == "switch");
|
||||
CHECK(plain.name == "z1");
|
||||
CHECK(plain.type == "Rz");
|
||||
CHECK(plain.rail == "60E1");
|
||||
CHECK(plain.radius == 500.0);
|
||||
CHECK(plain.ratio == 12.0);
|
||||
CHECK(plain.hand == 'L');
|
||||
CHECK(plain.parts == std::vector<std::string>{"z1"});
|
||||
CHECK(plain.shaped);
|
||||
CHECK(plain.start == context.to_world({100.0, 0.0, 200.0}));
|
||||
REQUIRE(plain.km.has_value());
|
||||
CHECK(*plain.km == doctest::Approx(12345.0));
|
||||
auto const &connection{records[1]};
|
||||
CHECK(connection.main_radius == -1200.0);
|
||||
CHECK_FALSE(connection.km.has_value());
|
||||
CHECK(connection.source == "measured");
|
||||
CHECK(connection.lift == 0.06);
|
||||
CHECK(connection.lift_end == 0.04);
|
||||
CHECK(connection.lift_to == context.to_world({150.0, 0.0, 240.0}));
|
||||
CHECK(connection.ramp == 60.0);
|
||||
CHECK(records[2].parts.size() == 4);
|
||||
CHECK(records[2].middle == 300.0);
|
||||
CHECK(text(editor_records::switch_lines(records, context)) == text(lines));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("editor records: the kilometrage (//$k) read and written back comes out the same") {
|
||||
auto const lines{marked("kilometrage.scn", "//$k")};
|
||||
for (auto const &context : {scene::layer_context{}, moved()}) {
|
||||
std::vector<kilometrage::mark> marks;
|
||||
std::vector<kilometrage::via> vias;
|
||||
editor_records::read_kilometrage(lines, context, layer, marks, vias);
|
||||
REQUIRE(marks.size() == 2);
|
||||
REQUIRE(vias.size() == 1);
|
||||
CHECK(marks[0].line == "91");
|
||||
CHECK(marks[0].point == context.to_world({100.0, 0.0, 200.0}));
|
||||
CHECK(marks[0].km == 12.345);
|
||||
CHECK_FALSE(marks[0].beyond.has_value());
|
||||
CHECK(marks[1].beyond == 14.0);
|
||||
CHECK(vias[0].point == context.to_world({105.0, 0.0, 700.0}));
|
||||
CHECK(text(editor_records::kilometrage_lines(marks, vias, context)) == text(lines));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("editor records: the grade lines designed (//$p) read and written back come out the same") {
|
||||
auto const lines{marked("profile.scn", "//$p")};
|
||||
for (auto const &context : {scene::layer_context{}, moved()}) {
|
||||
auto const profiles{editor_records::read_profiles(lines, context, layer)};
|
||||
REQUIRE(profiles.size() == 1);
|
||||
auto const &profile{profiles.front()};
|
||||
CHECK(profile.length == 500.0);
|
||||
CHECK(profile.start == context.to_world({0.0, 100.0, 0.0}));
|
||||
CHECK(profile.line.speed == 120.0);
|
||||
CHECK(profile.origin == 1000.0);
|
||||
CHECK(profile.line.join_start);
|
||||
CHECK_FALSE(profile.line.join_end);
|
||||
CHECK(profile.line.norms.radius_min == 2000.0);
|
||||
CHECK(profile.departure == 0.015);
|
||||
REQUIRE(profile.line.points.size() == 3);
|
||||
CHECK(profile.line.points[1].elevation == context.to_world({0.0, 101.0, 0.0}).y);
|
||||
CHECK(profile.line.points[1].radius == 10000.0);
|
||||
CHECK(profile.line.points[1].automatic);
|
||||
CHECK(text(editor_records::profile_lines(profiles, context)) == text(lines));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("editor records: the tracks fitted (//$t) and sharing a grade line (//$w) read and written back come out the same") {
|
||||
auto const fitted{marked("fitted.scn", "//$t")};
|
||||
auto const tracks{editor_records::read_fitted(fitted)};
|
||||
REQUIRE(tracks.size() == 2);
|
||||
CHECK(tracks[0].name == "tor_1");
|
||||
CHECK(tracks[0].shape == 0x00ff00ff12345678ull);
|
||||
CHECK_FALSE(tracks[0].hand);
|
||||
CHECK(tracks[1].hand);
|
||||
CHECK(text(editor_records::fitted_lines(tracks)) == text(fitted));
|
||||
|
||||
auto const shared{marked("gradeline.scn", "//$w")};
|
||||
auto const lines{editor_records::read_grade_lines(shared)};
|
||||
REQUIRE(lines.size() == 2);
|
||||
CHECK(lines[0].key == "tor_1@100,200");
|
||||
CHECK(lines[0].number == 3);
|
||||
CHECK_FALSE(lines[0].hand);
|
||||
CHECK(lines[1].hand);
|
||||
CHECK(text(editor_records::grade_line_lines(lines)) == text(shared));
|
||||
}
|
||||
|
||||
TEST_CASE("editor records: the objects bound to the paths (//$b) read and written back come out the same") {
|
||||
auto const lines{marked("binding.scn", "//$b")};
|
||||
for (auto const &context : {scene::layer_context{}, moved()}) {
|
||||
std::vector<std::string> written{editor_records::binding_heading()};
|
||||
std::vector<editor_records::binding> bindings;
|
||||
for (auto const &line : uncommented(lines)) {
|
||||
auto const binding{editor_records::read_binding(line, context)};
|
||||
REQUIRE(binding.has_value());
|
||||
bindings.push_back(*binding);
|
||||
written.push_back(editor_records::binding_line(*binding, context));
|
||||
}
|
||||
REQUIRE(bindings.size() == 2);
|
||||
CHECK(bindings[0].kind == "model");
|
||||
CHECK(bindings[0].category == 2);
|
||||
CHECK(bindings[0].location == context.to_world({10.0, 0.5, 20.0}));
|
||||
CHECK(bindings[0].key == "models/slupy/slup.t3d");
|
||||
CHECK(bindings[0].turns);
|
||||
REQUIRE(bindings[1].anchors.size() == 2);
|
||||
CHECK(bindings[1].anchors[1].path == 1);
|
||||
CHECK(bindings[1].anchors[1].end == context.to_world({5.0, 0.0, 100.0}));
|
||||
CHECK(text(written) == text(lines));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("editor records: the stations described (//$s) read and written back come out the same, their names in windows-1250") {
|
||||
auto const lines{marked("station.scn", "//$s")};
|
||||
std::vector<editor_records::station> stations;
|
||||
for (auto const &line : uncommented(lines)) {
|
||||
auto const station{editor_records::read_station(line)};
|
||||
REQUIRE(station.has_value());
|
||||
stations.push_back(*station);
|
||||
}
|
||||
REQUIRE(stations.size() == 2);
|
||||
auto const &first{stations[0]};
|
||||
CHECK(first.code == "MMz");
|
||||
CHECK(first.line == "91");
|
||||
CHECK(first.km == "12.345");
|
||||
CHECK_FALSE(first.reversed);
|
||||
CHECK(first.anchor == "z1");
|
||||
CHECK(first.braking == 700);
|
||||
CHECK(first.blocks.at("bpd_a") == editor_records::block_kind::four);
|
||||
CHECK(first.blocks.at("bpd_b") == editor_records::block_kind::semi);
|
||||
CHECK(first.ways.at("bpd_a"));
|
||||
REQUIRE(first.joints_added.size() == 1);
|
||||
REQUIRE(first.joints_removed.size() == 1);
|
||||
CHECK(first.joints_removed.front() == glm::dvec3{110.5, 0.0, 205.25});
|
||||
CHECK(first.name == "\xC5\x81\xC3\xB3\x64\xC5\xBA Kaliska"); // Łódź Kaliska, in utf-8
|
||||
// the words left empty are read as none
|
||||
CHECK(stations[1].code.empty());
|
||||
CHECK(stations[1].km.empty());
|
||||
CHECK(stations[1].reversed);
|
||||
CHECK(stations[1].blocks.at("x") == editor_records::block_kind::three);
|
||||
CHECK(text(editor_records::station_lines(stations)) == text(lines));
|
||||
}
|
||||
|
||||
TEST_CASE("editor records: the camera (//$c), the orthophoto (//$o) and its area (//$z) read and written back come out the same") {
|
||||
auto const camera{marked("camera.scn", "//$c")};
|
||||
auto const place{editor_records::read_camera(camera)};
|
||||
REQUIRE(place.has_value());
|
||||
CHECK(place->position == glm::dvec3{1234.5, 56.25, -789.125});
|
||||
CHECK(place->angle == glm::vec3{0.125f, -1.5f, 0.f});
|
||||
CHECK(editor_records::camera_line(*place) == camera.front());
|
||||
|
||||
for (auto const &line : marked("orthophoto.scn", "//$o")) {
|
||||
CAPTURE(line);
|
||||
bool enabled{false};
|
||||
double north{0.0};
|
||||
double east{0.0};
|
||||
REQUIRE(editor_records::read_orthophoto(line, enabled, north, east));
|
||||
// the editor writes where the scenery lies when it lies somewhere
|
||||
CHECK(editor_records::orthophoto_line(enabled, north != 0.0 || east != 0.0, north, east) == line);
|
||||
}
|
||||
|
||||
auto const area{marked("area.scn", "//$z")};
|
||||
auto const polygon{editor_records::read_area(area)};
|
||||
REQUIRE(polygon.size() == 3);
|
||||
CHECK(polygon[2] == glm::dvec2{646000.5, 513000.25});
|
||||
CHECK(text(editor_records::area_lines(polygon)) == text(area));
|
||||
}
|
||||
|
||||
TEST_CASE("editor records: the description of a template (//$e) read and written back comes out the same, and the rest of the file with it") {
|
||||
test::scratch_folder const folder{"editor_records_templates"};
|
||||
auto const original{file_text(std::string{EU07_UNIT_TESTS_DATA} + "/records/semaphore.inc")};
|
||||
folder.write("semaphore.inc", original);
|
||||
// the templates are read from the folder of the scenery
|
||||
struct scenery_folder {
|
||||
explicit scenery_folder(std::string const &Path) : before{Global.asCurrentSceneryPath} { Global.asCurrentSceneryPath = Path; }
|
||||
~scenery_folder() { Global.asCurrentSceneryPath = before; }
|
||||
scenery_folder(scenery_folder const &) = delete;
|
||||
scenery_folder &operator=(scenery_folder const &) = delete;
|
||||
std::string before;
|
||||
} const scenery{folder.path()};
|
||||
|
||||
include_info first;
|
||||
std::string error;
|
||||
REQUIRE(editor_includes::load("semaphore.inc", first, error));
|
||||
CHECK(first.name == "Semaphore, 2 arms");
|
||||
CHECK(first.category == "signals");
|
||||
CHECK(first.signal_kind == "semaphore");
|
||||
CHECK(first.signal_arms == 2);
|
||||
CHECK(first.signal_height == 5.5);
|
||||
REQUIRE(first.parameters.size() == 3);
|
||||
CHECK(first.parameters[0].role == "name");
|
||||
CHECK(first.parameters[2].value == "tor1");
|
||||
REQUIRE(editor_includes::save("semaphore.inc", first, error));
|
||||
CHECK(file_text(folder.path("semaphore.inc")) == original);
|
||||
include_info second;
|
||||
REQUIRE(editor_includes::load("semaphore.inc", second, error));
|
||||
CHECK(second.name == first.name);
|
||||
CHECK(second.description == first.description);
|
||||
CHECK(second.signal_aspects == first.signal_aspects);
|
||||
REQUIRE(second.parameters.size() == first.parameters.size());
|
||||
for (std::size_t index = 0; index < first.parameters.size(); ++index) {
|
||||
CHECK(second.parameters[index].id == first.parameters[index].id);
|
||||
CHECK(second.parameters[index].role == first.parameters[index].role);
|
||||
CHECK(second.parameters[index].label == first.parameters[index].label);
|
||||
CHECK(second.parameters[index].value == first.parameters[index].value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,212 @@
|
||||
// the tracks of the scenery files read and written back by the game's own TTrack::Load() and export_as_text(), the safety net of the
|
||||
// track editor, which writes the tracks it changes this way: the entries in data/tracks/ are written the way the game writes them,
|
||||
// so each read and written back comes out the same, and what a second reading gives is what the first gave. what doesn't survive yet
|
||||
// is in data/tracks/known_lost.scn, the tests of it fail until it does (doctest::should_fail)
|
||||
//
|
||||
// the tracks are read with no scene: the parts of the engine a track reaches for are stand-ins (track_stubs.cpp). the materials are
|
||||
// kept by the names given, where the game's material manager names them after the files it finds; the rails don't buckle by the heat,
|
||||
// world/TrackBuckle.cpp isn't a part of the tests, the buckle declared is read and written either way
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "doctest.h"
|
||||
#include "track_text.h"
|
||||
#include "rendering/renderer.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <fstream>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace {
|
||||
|
||||
using test::read_track;
|
||||
using test::track_reading;
|
||||
using test::written;
|
||||
|
||||
std::string material_name(material_handle const Material) {
|
||||
return Material != null_handle ? GfxRenderer->Material(Material)->GetName() : std::string{"-"};
|
||||
}
|
||||
|
||||
void add_path(std::ostringstream &Text, segment_data const &Path) {
|
||||
for (auto const &point : Path.points) {
|
||||
Text << ' ' << point.x << ' ' << point.y << ' ' << point.z;
|
||||
}
|
||||
Text << " rolls " << Path.rolls[0] << ' ' << Path.rolls[1] << " radius " << Path.radius;
|
||||
}
|
||||
|
||||
// what the track got of its entry, field by field, one to a line
|
||||
std::string fields(TTrack &Track) {
|
||||
std::ostringstream text;
|
||||
text.precision(17);
|
||||
text << "name " << Track.name() << '\n'
|
||||
<< "type " << Track.eType << " category " << Track.iCategoryFlag << " tributary " << Track.m_tributary << '\n'
|
||||
<< "width " << Track.fTrackWidth << " friction " << Track.fFriction << " sound " << Track.fSoundDistance << '\n'
|
||||
<< "quality " << Track.iQualityFlag << " damage " << Track.iDamageFlag << " environment " << Track.eEnvironment << '\n'
|
||||
<< "visible " << Track.visible() << '\n'
|
||||
<< "materials " << material_name(Track.m_material1) << ' ' << material_name(Track.m_material2) << '\n'
|
||||
<< "texture " << Track.fTexLength << ' ' << Track.fTexHeight1 - Track.fTexHeightOffset << ' ' << Track.fTexWidth << ' ' << Track.fTexSlope << '\n';
|
||||
for (auto const &path : Track.m_paths) {
|
||||
text << "path";
|
||||
add_path(text, path);
|
||||
text << '\n';
|
||||
for (auto const &piece : path.pieces) {
|
||||
text << " piece";
|
||||
add_path(text, piece);
|
||||
text << '\n';
|
||||
}
|
||||
}
|
||||
for (auto const *events : {&Track.m_events0, &Track.m_events0all, &Track.m_events1, &Track.m_events1all, &Track.m_events2, &Track.m_events2all}) {
|
||||
text << "events";
|
||||
for (auto const &event : *events) {
|
||||
text << ' ' << event.first;
|
||||
}
|
||||
text << '\n';
|
||||
}
|
||||
text << "velocity " << Track.VelocityGet() << '\n';
|
||||
if (Track.SwitchExtension) {
|
||||
auto const &extension{*Track.SwitchExtension};
|
||||
text << "switch velocity " << extension.fVelocity << " trackbed " << material_name(extension.m_material3) << " frogs " << extension.m_frogs << " movable nose " << extension.m_movablenose
|
||||
<< " blades " << extension.m_bladeheel << ' ' << extension.m_bladethrow << '\n';
|
||||
}
|
||||
text << "isolated";
|
||||
for (auto const *isolated : Track.Isolated) {
|
||||
text << ' ' << isolated->asName;
|
||||
}
|
||||
text << '\n'
|
||||
<< "overhead " << Track.fOverhead << " vertical radius " << Track.fVerticalRadius << '\n'
|
||||
<< "rail profile " << Track.m_profile1.first << '\n'
|
||||
<< track_uneven::write_attribute(Track.m_uneven, Track.eType == tt_Switch) << '\n'
|
||||
<< track_buckle::write_buckle(Track.m_buckledeclared) << track_buckle::write_cwr(Track.m_cwr) << '\n'
|
||||
<< "friction cell " << Track.m_friction.first << '\n'
|
||||
<< "sleepers " << Track.m_sleeper_enabled << ' ' << Track.m_sleeper_frequency << ' ' << Track.m_sleeper_model_name << ' ' << Track.m_sleeper_skin_name << ' ' << Track.m_sleeper_offset.x << ' '
|
||||
<< Track.m_sleeper_offset.y << ' ' << Track.m_sleeper_offset.z << ' ' << Track.m_sleeper_ballast_z << '\n'
|
||||
<< "timbers " << Track.m_timber_model_name << ' ' << Track.m_timber_skin_name << '\n';
|
||||
return text.str();
|
||||
}
|
||||
|
||||
// the entries of the file of data/tracks/, a line each; lines starting with // are comments
|
||||
std::vector<std::string> entries(std::string const &File) {
|
||||
std::ifstream file{std::string{EU07_UNIT_TESTS_DATA} + "/tracks/" + File, std::ios::binary};
|
||||
REQUIRE(file.is_open());
|
||||
std::vector<std::string> result;
|
||||
for (std::string line; std::getline(file, line);) {
|
||||
if (false == line.empty() && line.back() == '\r') {
|
||||
line.pop_back();
|
||||
}
|
||||
if (line.empty() || line.starts_with("//")) {
|
||||
continue;
|
||||
}
|
||||
result.push_back(line + '\n');
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// the entry of the track of the name in the file
|
||||
std::string entry(std::string const &File, std::string const &Name) {
|
||||
for (auto const &text : entries(File)) {
|
||||
std::istringstream words{text};
|
||||
std::string node, rangemax, rangemin, name;
|
||||
words >> node >> rangemax >> rangemin >> name;
|
||||
if (name == Name) {
|
||||
return text;
|
||||
}
|
||||
}
|
||||
FAIL("no track " << Name << " in " << File);
|
||||
return {};
|
||||
}
|
||||
|
||||
// read, written, read again and written again
|
||||
struct round_trip {
|
||||
explicit round_trip(std::string const &Text) : first{read_track(Text)}, text{written(*first)}, second{read_track(text)}, again{written(*second)} {}
|
||||
std::unique_ptr<TTrack> first;
|
||||
std::string text;
|
||||
std::unique_ptr<TTrack> second;
|
||||
std::string again;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("track text: each entry of data/tracks/ read and written back comes out the same, and read again gives the same track") {
|
||||
track_reading const reading;
|
||||
for (auto const *file : {"plain.scn", "switch.scn", "turntable.scn", "pieces.scn", "speeds.scn", "other.scn"}) {
|
||||
for (auto const &text : entries(file)) {
|
||||
CAPTURE(file);
|
||||
CAPTURE(text);
|
||||
round_trip const trip{text};
|
||||
CHECK(trip.text == text);
|
||||
CHECK(fields(*trip.second) == fields(*trip.first));
|
||||
CHECK(trip.again == trip.text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("track text: what the game writes otherwise than it was given, the same from the first save on") {
|
||||
track_reading const reading;
|
||||
struct normalized {
|
||||
char const *what;
|
||||
std::string given;
|
||||
std::string written;
|
||||
};
|
||||
std::string const plain{"node -1 0 n track normal 10 1.435 0.15 25 20 0 flat unvis 0 0 0 0 0 0 0 0 0 0 0 0 10 0 0 "};
|
||||
std::string const turntable{"1.435 0.15 25 20 0 flat unvis -10 0 0 0 0 0 0 0 0 0 10 0 0 0 0 endtrack\n"};
|
||||
std::string const switchpaths{"0 0 0 0 0 0 0 0 0 0 0 0 33.23 0 0 0 0 0 0 0 0 11 0.6 0 -11 1.8 0 33.1 0 300 endtrack\n"};
|
||||
std::vector<normalized> const cases{
|
||||
{"a turntable entered as table is written as turn", "node -1 0 t track table 20 " + turntable, "node -1 0 t track turn 20 " + turntable},
|
||||
{"mountain is written as mountains", "node -1 0 m track normal 10 1.435 0.15 25 20 0 mountain unvis 0 0 0 0 0 0 0 0 0 0 0 0 10 0 0 endtrack\n",
|
||||
"node -1 0 m track normal 10 1.435 0.15 25 20 0 mountains unvis 0 0 0 0 0 0 0 0 0 0 0 0 10 0 0 endtrack\n"},
|
||||
{"an environment the game doesn't know is written as none", "node -1 0 e track normal 10 1.435 0.15 25 20 0 desert unvis 0 0 0 0 0 0 0 0 0 0 0 0 10 0 0 endtrack\n",
|
||||
"node -1 0 e track normal 10 1.435 0.15 25 20 0 none unvis 0 0 0 0 0 0 0 0 0 0 0 0 10 0 0 endtrack\n"},
|
||||
{"the length is the one of the path, whatever the entry says", "node -1 0 n track normal 12 1.435 0.15 25 20 0 flat unvis 0 0 0 0 0 0 0 0 0 0 0 0 10 0 0 endtrack\n", plain + "endtrack\n"},
|
||||
{"a switch is heard from 10 m, whatever the entry says", "node -1 0 s track switch 33.23 1.435 0.25 25 20 0 flat unvis " + switchpaths,
|
||||
"node -1 0 s track switch 33.23 1.435 0.25 10 20 0 flat unvis " + switchpaths},
|
||||
{"the events go in the order of their kinds", plain + "event2 b eventall1 c event0 a endtrack\n", plain + "event0 a eventall1 c event2 b endtrack\n"},
|
||||
{"the names are read in lower case, the paths of the models as they are, with forward slashes",
|
||||
"node -1 0 N track normal 10 1.435 0.15 25 20 0 flat unvis 0 0 0 0 0 0 0 0 0 0 0 0 10 0 0 event0 Sem_A isolated Iso_B sleepermodel 0.6 Models\\Tory\\Podklad.e3d Skin 0 0 0 0 endtrack\n",
|
||||
plain + "event0 sem_a isolated iso_b sleepermodel 0.6 Models/Tory/Podklad.e3d Skin 0 0 0 0 endtrack\n"},
|
||||
{"a texture repeated at less than 1 cm is repeated at 4 m", "node -1 0 n track normal 10 1.435 0.15 25 20 0 flat vis rail 0 ballast 0.2 0.5 1.1 0 0 0 0 0 0 0 0 0 0 0 0 10 0 0 endtrack\n",
|
||||
"node -1 0 n track normal 10 1.435 0.15 25 20 0 flat vis rail 4 ballast 0.2 0.5 1.1 0 0 0 0 0 0 0 0 0 0 0 0 10 0 0 endtrack\n"},
|
||||
{"the rolls are written as the floats they're read into", "node -1 0 n track normal 10 1.435 0.15 25 20 0 flat unvis 0 0 0 3.4377 0 0 0 0 0 0 0 0 10 -3.4377 0 endtrack\n",
|
||||
"node -1 0 n track normal 10 1.435 0.15 25 20 0 flat unvis 0 0 0 3.43770003318787 0 0 0 0 0 0 0 0 10 -3.43770003318787 0 endtrack\n"},
|
||||
{"no overhead line (-1) and no vertical radius (0) aren't written", plain + "overhead -1 vradius 0 endtrack\n", plain + "endtrack\n"},
|
||||
};
|
||||
for (auto const &[what, given, expected] : cases) {
|
||||
CAPTURE(what);
|
||||
round_trip const trip{given};
|
||||
CHECK(trip.text == expected);
|
||||
CHECK(trip.again == trip.text);
|
||||
}
|
||||
}
|
||||
|
||||
// what doesn't survive yet: each fails until it does, then doctest reports the test passing against should_fail, and the entry goes
|
||||
// over to the files of the entries which come out the same
|
||||
|
||||
TEST_CASE("track text: the angles the ends are cut at are written back (known lost: read and dropped)" * doctest::should_fail()) {
|
||||
track_reading const reading;
|
||||
round_trip const trip{entry("known_lost.scn", "angles")};
|
||||
CHECK(trip.text.find(" angle1 15 ") != std::string::npos);
|
||||
CHECK(trip.text.find(" angle2 -15 ") != std::string::npos);
|
||||
}
|
||||
|
||||
TEST_CASE("track text: the fouling points are written back (known lost: read and dropped)" * doctest::should_fail()) {
|
||||
track_reading const reading;
|
||||
round_trip const trip{entry("known_lost.scn", "fouling")};
|
||||
CHECK(trip.text.find(" fouling1 ukres_a ") != std::string::npos);
|
||||
CHECK(trip.text.find(" fouling2 ukres_b ") != std::string::npos);
|
||||
}
|
||||
|
||||
TEST_CASE("track text: a name with the isolated circuit after @ keeps its letters (known lost: the one before the @)" * doctest::should_fail()) {
|
||||
track_reading const reading;
|
||||
round_trip const trip{entry("known_lost.scn", "tor1@iso1")};
|
||||
// the circuit is taken out of the name and written as an attribute, which reads the same
|
||||
REQUIRE(trip.first->Isolated.size() == 1);
|
||||
CHECK(trip.first->Isolated.front()->asName == "iso1");
|
||||
CHECK(trip.first->name() == "tor1");
|
||||
}
|
||||
|
||||
TEST_CASE("track text: the attributes keep every digit of the floats they're read into (known lost: written to 6 digits)" * doctest::should_fail()) {
|
||||
track_reading const reading;
|
||||
round_trip const trip{entry("known_lost.scn", "digits")};
|
||||
CHECK(fields(*trip.second) == fields(*trip.first));
|
||||
}
|
||||
@@ -0,0 +1,222 @@
|
||||
// stand-ins for the parts of the engine which the tracks reach for (world/Track.cpp and the sources linked with it, see
|
||||
// CMakeLists.txt), so test_track_text.cpp can read a track from its text and write it back with the game's own TTrack::Load()
|
||||
// and export_as_text(), with no scene. what reading and writing a track does use works: the log, the materials kept by their
|
||||
// names (unit_tests_material_renderer()). the rest is the simulation of a scene the tests don't make: the events, the vehicles
|
||||
// on the tracks, the regions, the geometry of the rails. it's never reached by reading or writing a track, and a test which
|
||||
// strays into it stops with the name of what it reached, rather than passing on a stand-in which does nothing
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "world/Track.h"
|
||||
#include "editor/editorTrack.hpp"
|
||||
#include "world/TrackRails.h"
|
||||
#include "world/TrackSleepers.h"
|
||||
#include "world/Event.h"
|
||||
#include "world/MemCell.h"
|
||||
#include "model/AnimModel.h"
|
||||
#include "model/MdlMngr.h"
|
||||
#include "vehicle/DynObj.h"
|
||||
#include "vehicle/Driver.h"
|
||||
#include "scene/scene.h"
|
||||
#include "simulation/simulation.h"
|
||||
#include "rendering/renderer.h"
|
||||
#include "input/messaging.h"
|
||||
#include "utilities/Logs.h"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace {
|
||||
|
||||
[[noreturn]] void absent(char const *What) {
|
||||
std::cerr << "unit tests: " << What << " isn't a part of the tests, see tests/unit/track_stubs.cpp\n";
|
||||
std::abort();
|
||||
}
|
||||
|
||||
// a material known by its name alone
|
||||
struct named_material final : IMaterial {
|
||||
explicit named_material(std::string Name) : name{std::move(Name)} {}
|
||||
void finalize(bool) override { /* nothing to load */ }
|
||||
bool update() override { return false; }
|
||||
float get_or_guess_opacity() const override { return 1.f; }
|
||||
bool is_translucent() const override { return false; }
|
||||
glm::vec2 GetSize() const override { return {-1.f, -1.f}; }
|
||||
std::string GetName() const override { return name; }
|
||||
std::optional<float> GetSelfillum() const override { return std::nullopt; }
|
||||
int GetShadowRank() const override { return 0; }
|
||||
texture_handle GetTexture(int) const override { return null_handle; }
|
||||
std::string name;
|
||||
};
|
||||
|
||||
// a renderer which draws nothing and keeps the materials asked for by their names, as they're given: the game's material
|
||||
// manager reads the files and names them after where it found them, which takes a scenery and its textures
|
||||
class material_renderer final : public gfx_renderer {
|
||||
public:
|
||||
auto Fetch_Material(std::string const &Filename, bool const) -> material_handle override {
|
||||
for (std::size_t index = 0; index < m_materials.size(); ++index) {
|
||||
if (m_materials[index].name == Filename) {
|
||||
return static_cast<material_handle>(index + 1);
|
||||
}
|
||||
}
|
||||
m_materials.emplace_back(Filename);
|
||||
return static_cast<material_handle>(m_materials.size());
|
||||
}
|
||||
auto Material(material_handle const Material) const -> IMaterial const * override {
|
||||
return Material > 0 && static_cast<std::size_t>(Material) <= m_materials.size() ? &m_materials[Material - 1] : IMaterial::null_material();
|
||||
}
|
||||
|
||||
auto Init(GLFWwindow *) -> bool override { absent("renderer: Init"); }
|
||||
bool AddViewport(global_settings::extraviewport_config const &) override { absent("renderer: AddViewport"); }
|
||||
void Shutdown() override { absent("renderer: Shutdown"); }
|
||||
auto Render() -> bool override { absent("renderer: Render"); }
|
||||
void SwapBuffers() override { absent("renderer: SwapBuffers"); }
|
||||
auto Framerate() -> float override { absent("renderer: Framerate"); }
|
||||
auto Create_Bank() -> gfx::geometrybank_handle override { absent("renderer: Create_Bank"); }
|
||||
auto Insert(gfx::index_array &, gfx::vertex_array &, gfx::userdata_array &, gfx::geometrybank_handle const &, int const) -> gfx::geometry_handle override { absent("renderer: Insert"); }
|
||||
auto Insert(gfx::vertex_array &, gfx::userdata_array &, gfx::geometrybank_handle const &, int const) -> gfx::geometry_handle override { absent("renderer: Insert"); }
|
||||
auto Replace(gfx::vertex_array &, gfx::userdata_array &, gfx::geometry_handle const &, int const, std::size_t const) -> bool override { absent("renderer: Replace"); }
|
||||
auto Append(gfx::vertex_array &, gfx::userdata_array &, gfx::geometry_handle const &, int const) -> bool override { absent("renderer: Append"); }
|
||||
auto Indices(gfx::geometry_handle const &) const -> gfx::index_array const & override { absent("renderer: Indices"); }
|
||||
auto Vertices(gfx::geometry_handle const &) const -> gfx::vertex_array const & override { absent("renderer: Vertices"); }
|
||||
auto UserData(gfx::geometry_handle const &) const -> gfx::userdata_array const & override { absent("renderer: UserData"); }
|
||||
void Bind_Material(material_handle const, TSubModel const *, lighting_data const *) override { absent("renderer: Bind_Material"); }
|
||||
auto Fetch_Shader(std::string const &) -> std::shared_ptr<gl::program> override { absent("renderer: Fetch_Shader"); }
|
||||
auto Fetch_Texture(std::string const &, bool const, GLint) -> texture_handle override { absent("renderer: Fetch_Texture"); }
|
||||
void Bind_Texture(texture_handle const) override { absent("renderer: Bind_Texture"); }
|
||||
void Bind_Texture(std::size_t const, texture_handle const) override { absent("renderer: Bind_Texture"); }
|
||||
auto Texture(texture_handle const) -> ITexture & override { absent("renderer: Texture"); }
|
||||
auto Texture(texture_handle const) const -> ITexture const & override { absent("renderer: Texture"); }
|
||||
void Pick_Control_Callback(std::function<void(TSubModel const *, const glm::vec2)>) override { absent("renderer: Pick_Control_Callback"); }
|
||||
void Pick_Node_Callback(std::function<void(scene::basic_node *)>) override { absent("renderer: Pick_Node_Callback"); }
|
||||
auto Pick_Control() const -> TSubModel const * override { absent("renderer: Pick_Control"); }
|
||||
auto Pick_Node() const -> scene::basic_node const * override { absent("renderer: Pick_Node"); }
|
||||
auto Mouse_Position() const -> glm::dvec3 override { absent("renderer: Mouse_Position"); }
|
||||
void Update(double const) override { absent("renderer: Update"); }
|
||||
void Update_Pick_Control() override { absent("renderer: Update_Pick_Control"); }
|
||||
void Update_Pick_Node() override { absent("renderer: Update_Pick_Node"); }
|
||||
auto Update_Mouse_Position() -> glm::dvec3 override { absent("renderer: Update_Mouse_Position"); }
|
||||
bool Debug_Ui_State(std::optional<bool>) override { absent("renderer: Debug_Ui_State"); }
|
||||
auto info_times() const -> std::string const & override { absent("renderer: info_times"); }
|
||||
auto info_stats() const -> std::string const & override { absent("renderer: info_stats"); }
|
||||
imgui_renderer *GetImguiRenderer() override { absent("renderer: GetImguiRenderer"); }
|
||||
void MakeScreenshot() override { absent("renderer: MakeScreenshot"); }
|
||||
|
||||
private:
|
||||
std::vector<named_material> m_materials;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
// for the tests: puts a renderer in place which keeps the materials by their names and draws nothing (true), or takes it away (false)
|
||||
void unit_tests_material_renderer(bool const Enabled) {
|
||||
GfxRenderer = Enabled ? std::make_unique<material_renderer>() : nullptr;
|
||||
}
|
||||
|
||||
// the renderer -----------------------------------------------------------------------------------------------------------
|
||||
|
||||
std::unique_ptr<gfx_renderer> GfxRenderer; // NOSONAR the engine's extern global, rendering/renderer.h
|
||||
|
||||
// the key function of the class for GCC and Clang, which put its vtable where it's defined
|
||||
auto gfx_renderer::Terrain_Material(material_handle const, std::vector<gfx::terrain_layer> const &, int const, std::uint8_t const *, glm::vec3 const &) -> material_handle { // NOSONAR signature from rendering/renderer.h
|
||||
absent("gfx_renderer::Terrain_Material");
|
||||
}
|
||||
|
||||
// the log --------------------------------------------------------------------------------------------------------------
|
||||
|
||||
void Error(std::string const &asMessage, bool const) { // NOSONAR signature from utilities/Logs.h
|
||||
ErrorLog(asMessage);
|
||||
}
|
||||
|
||||
// the simulation of the scene ------------------------------------------------------------------------------------------
|
||||
|
||||
namespace simulation {
|
||||
|
||||
event_manager Events; // NOSONAR the engine's extern global, simulation/simulation.h
|
||||
memory_table Memory; // NOSONAR the engine's extern global, simulation/simulation.h
|
||||
path_table Paths; // NOSONAR the engine's extern global, simulation/simulation.h
|
||||
instance_table Instances; // NOSONAR the engine's extern global, simulation/simulation.h
|
||||
scene::basic_region *Region{nullptr}; // NOSONAR the engine's extern global, simulation/simulation.h
|
||||
|
||||
} // namespace simulation
|
||||
|
||||
event_manager::~event_manager() = default; // the tests put no events in it
|
||||
|
||||
basic_event *event_manager::FindEvent(std::string const &) { absent("event_manager::FindEvent"); }
|
||||
bool event_manager::AddToQuery(basic_event *, TDynamicObject const *, double) { absent("event_manager::AddToQuery"); }
|
||||
|
||||
namespace scene {
|
||||
|
||||
bool basic_cell::RaTrackAnimAdd(TTrack *) { absent("basic_cell::RaTrackAnimAdd"); }
|
||||
void basic_cell::insert(TTrack *) { absent("basic_cell::insert"); }
|
||||
basic_cell &basic_section::cell(glm::dvec3 const &, glm::ivec2 const &) { absent("basic_section::cell"); }
|
||||
bool basic_region::point_inside(glm::dvec3 const &) { absent("basic_region::point_inside"); }
|
||||
basic_section &basic_region::section(glm::dvec3 const &) { absent("basic_region::section"); }
|
||||
std::tuple<TTrack *, int> basic_region::find_path(glm::dvec3 const &, TTrack const *) { absent("basic_region::find_path"); }
|
||||
void basic_region::TrackJoin(TTrack *) { absent("basic_region::TrackJoin"); }
|
||||
|
||||
} // namespace scene
|
||||
|
||||
void multiplayer::WyslijString(std::string const &, int) { absent("multiplayer::WyslijString"); }
|
||||
|
||||
// the vehicles and the models ------------------------------------------------------------------------------------------
|
||||
|
||||
void TDynamicObject::Move(double) { absent("TDynamicObject::Move"); }
|
||||
void TDynamicObject::RenderSounds() { absent("TDynamicObject::RenderSounds"); }
|
||||
void TDynamicObject::RadioStop() { absent("TDynamicObject::RadioStop"); }
|
||||
void TDynamicObject::OverheadTrack(float) { absent("TDynamicObject::OverheadTrack"); }
|
||||
std::string const &TController::TrainName() const { absent("TController::TrainName"); }
|
||||
bool TController::PutCommand(std::string, double, double, glm::dvec3 const *, TStopReason) { absent("TController::PutCommand"); }
|
||||
std::shared_ptr<TAnimContainer> TAnimModel::GetContainer(std::string const &) { absent("TAnimModel::GetContainer"); }
|
||||
void TAnimContainer::EventAssign(basic_event *) { absent("TAnimContainer::EventAssign"); }
|
||||
TModel3d *TModelsManager::GetModel(std::string const &, bool const, bool const, int) { absent("TModelsManager::GetModel"); }
|
||||
|
||||
// the buckling of the rails by the heat, world/TrackBuckle.cpp: the tests read the tracks with it off (Global.track_buckling)
|
||||
|
||||
track_buckle::shape TTrack::resolve_buckle(track_buckle::declared const &, std::uint32_t const) const { absent("TTrack::resolve_buckle"); }
|
||||
void TTrack::buckle_pass_enter(TDynamicObject const &) { absent("TTrack::buckle_pass_enter"); }
|
||||
void TTrack::buckle_pass_leave() { absent("TTrack::buckle_pass_leave"); }
|
||||
|
||||
// the geometry of the rails and the sleepers, world/Rail*.cpp and world/Sleeper*.cpp ------------------------------------
|
||||
|
||||
namespace track_rails {
|
||||
|
||||
// what's kept of the rails around: nothing, with no rails laid
|
||||
void forget() { /* nothing kept */ }
|
||||
rail_size measure_rail(gfx::vertex_array const &) { absent("track_rails::measure_rail"); }
|
||||
int blade_steps(TTrack const &, int const) { absent("track_rails::blade_steps"); }
|
||||
double blade_length(TTrack const &, int const) { absent("track_rails::blade_length"); }
|
||||
TTrack const *runon_track(TTrack const &, int const) { absent("track_rails::runon_track"); }
|
||||
double blade_runon(TTrack const &, int const) { absent("track_rails::blade_runon"); }
|
||||
material_handle cut_material(material_handle const) { absent("track_rails::cut_material"); }
|
||||
void cap_loft(gfx::vertex_array const &, std::size_t const, bool const, bool const, gfx::vertex_array &) { absent("track_rails::cap_loft"); }
|
||||
gfx::userdata_array worn_userdata(std::size_t const, bool const) { absent("track_rails::worn_userdata"); }
|
||||
void cut_faces(gfx::vertex_array const &, std::size_t const, bool const, bool const, gfx::geometrybank_handle const &, TTrack::geometryhandle_sequence &, bool const) { absent("track_rails::cut_faces"); }
|
||||
reused_chunks::reused_chunks(chunk_pool *) { absent("track_rails::reused_chunks"); }
|
||||
reused_chunks::~reused_chunks() = default;
|
||||
gfx::geometry_handle insert_chunk(gfx::vertex_array &, gfx::userdata_array &, gfx::geometrybank_handle const &, int const) { absent("track_rails::insert_chunk"); }
|
||||
|
||||
} // namespace track_rails
|
||||
|
||||
track_rails::switch_blade const &TTrack::blade(int const) const { absent("TTrack::blade"); }
|
||||
double TTrack::blades_throw() const { absent("TTrack::blades_throw"); }
|
||||
track_rails::rail_layout TTrack::plan_rails(bool const, bool const) { absent("TTrack::plan_rails"); }
|
||||
TTrack::rail_drawing TTrack::make_rail_drawing(gfx::geometrybank_handle const &) const { absent("TTrack::make_rail_drawing"); }
|
||||
bool TTrack::lay_rail(track_rails::rail_layout const &, rail_drawing const &, gfx::vertex_array const &, track_rails::rail_course const &, geometryhandle_sequence &, geometryhandle_sequence &) { absent("TTrack::lay_rail"); }
|
||||
|
||||
namespace track_sleepers {
|
||||
|
||||
bool lays(TTrack const &) { absent("track_sleepers::lays"); }
|
||||
void unsettle_around(TTrack const &) { absent("track_sleepers::unsettle_around"); }
|
||||
|
||||
} // namespace track_sleepers
|
||||
|
||||
// the track editor, editor/editorTrack.cpp: the tests take the rolls of the joints of editor/editorTrackShape.cpp alone ----------------
|
||||
|
||||
editor_track::point_ref editor_track::end_of(point_ref const &) { absent("editor_track::end_of"); }
|
||||
glm::dvec3 editor_track::point_position(TTrack const &, point_ref const &) { absent("editor_track::point_position"); }
|
||||
bool editor_track::is_connected(TTrack const &, point_ref const &) { absent("editor_track::is_connected"); }
|
||||
bool editor_track::is_supported(TTrack const &) { absent("editor_track::is_supported"); }
|
||||
std::vector<std::pair<TTrack *, editor_track::point_ref>> editor_track::connected_points(TTrack const &, glm::dvec3 const &) { absent("editor_track::connected_points"); }
|
||||
editor_track::state editor_track::capture(TTrack const &) { absent("editor_track::capture"); }
|
||||
@@ -0,0 +1,66 @@
|
||||
#pragma once
|
||||
|
||||
// tracks read from the text of their entries and written back by the game's own TTrack::Load() and export_as_text(), with no scene:
|
||||
// the parts of the engine a track reaches for are stand-ins (track_stubs.cpp)
|
||||
|
||||
#include "doctest.h"
|
||||
#include "world/Track.h"
|
||||
#include "utilities/Globals.h"
|
||||
#include "utilities/parser.h"
|
||||
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
void unit_tests_material_renderer(bool Enabled); // track_stubs.cpp
|
||||
|
||||
namespace test {
|
||||
|
||||
// for as long as it lives the tracks can be read: a renderer to keep their materials, the buckling of the rails off
|
||||
class track_reading {
|
||||
public:
|
||||
track_reading() : m_buckling{Global.track_buckling} {
|
||||
unit_tests_material_renderer(true);
|
||||
Global.track_buckling = global_settings::track_buckling_mode::off;
|
||||
}
|
||||
~track_reading() {
|
||||
Global.track_buckling = m_buckling;
|
||||
unit_tests_material_renderer(false);
|
||||
TIsolated::DeleteAll();
|
||||
}
|
||||
track_reading(track_reading const &) = delete;
|
||||
track_reading &operator=(track_reading const &) = delete;
|
||||
|
||||
private:
|
||||
global_settings::track_buckling_mode m_buckling;
|
||||
};
|
||||
|
||||
// the track of the node entry, read as the scenery loader reads it (state_serializer::deserialize_node and deserialize_path)
|
||||
inline std::unique_ptr<TTrack> read_track(std::string const &Text) {
|
||||
// with a spare endtrack: Load() reads the attributes until it meets one, and an entry short of a number would have it read on past
|
||||
// the end of the text forever, where now it stops and the entry comes out different
|
||||
cParser parser{Text + " endtrack", cParser::buffer_TEXT};
|
||||
parser.getTokens();
|
||||
std::string keyword;
|
||||
parser >> keyword;
|
||||
REQUIRE(keyword == "node");
|
||||
scene::node_data data;
|
||||
parser.getTokens(4);
|
||||
parser >> data.range_max >> data.range_min >> data.name >> data.type;
|
||||
if (data.name == "none") {
|
||||
data.name.clear();
|
||||
}
|
||||
REQUIRE(data.type == "track");
|
||||
auto track{std::make_unique<TTrack>(data)};
|
||||
track->Load(&parser, glm::dvec3{0.0});
|
||||
return track;
|
||||
}
|
||||
|
||||
// the entry of the track, as the scenery save writes it
|
||||
inline std::string written(TTrack const &Track) {
|
||||
std::ostringstream text;
|
||||
Track.export_as_text(text);
|
||||
return text.str();
|
||||
}
|
||||
|
||||
} // namespace test
|
||||
Reference in New Issue
Block a user