17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-30 13:10:29 +01:00

feat(editor): insert switches by dragging, paths from free ends

This commit is contained in:
maj00r
2026-10-02 23:58:48 +02:00
parent 32798a32bb
commit 1985758a86
5 changed files with 415 additions and 3 deletions

View File

@@ -1432,6 +1432,34 @@ TTrack *editor_track::clone(TTrack const &Template)
return track;
}
TTrack *editor_track::create_path(TTrack const &Style, segment_data const &Path)
{
char const *environments[] = {"flat", "mountains", "canyon", "tunnel", "bridge", "bank"};
auto const environment{Style.eEnvironment >= e_flat && Style.eEnvironment <= e_bank ? environments[Style.eEnvironment] : "flat"};
auto const category{Style.iCategoryFlag & 15};
std::ostringstream text;
text.precision(std::numeric_limits<double>::digits10);
text << (category == 2 ? "road " : category == 4 ? "river " : "normal ") << glm::distance(Path.points[segment_data::point::start], Path.points[segment_data::point::end]) << ' ' << Style.fTrackWidth << ' ' << Style.fFriction << ' ' << Style.fSoundDistance << ' ' << Style.iQualityFlag << ' ' << 0 << ' ' << environment << ' ';
if (Style.m_visible)
text << "vis " << material_name(Style.m_material1) << ' ' << Style.fTexLength << ' ' << material_name(Style.m_material2) << ' ' << texture_height(Style) << ' ' << Style.fTexWidth << ' ' << Style.fTexSlope << ' ';
else
text << "unvis ";
auto const &start{Path.points[segment_data::point::start]};
auto const &control1{Path.points[segment_data::point::control1]};
auto const &control2{Path.points[segment_data::point::control2]};
auto const &end{Path.points[segment_data::point::end]};
text << start.x << ' ' << start.y << ' ' << start.z << ' ' << Path.rolls[0] << ' ' << control1.x << ' ' << control1.y << ' ' << control1.z << ' ' << control2.x << ' ' << control2.y << ' ' << control2.z << ' ' << end.x << ' ' << end.y << ' ' << end.z << ' ' << Path.rolls[1] << ' ' << Path.radius << ' ';
auto const speed{velocity(Style)};
if (speed > 0.0)
text << "velocity " << speed << ' ';
if (category == 1 && false == Style.m_profile1.first.empty())
text << "railprofile " << Style.m_profile1.first << ' ';
text << "endtrack\n";
auto *track{load_path(text.str(), Style)};
track->m_paths = {Path};
return track;
}
TTrack *editor_track::load_path(std::string const &Text, TTrack const &Template)
{
cParser parser(Text, cParser::buffer_TEXT);

View File

@@ -144,6 +144,8 @@ class editor_track
};
static std::vector<switch_template> standard_switch_templates();
static std::vector<switch_template> find_switch_templates();
static TTrack *load_path(std::string const &Text, TTrack const &Template);
static TTrack *create_path(TTrack const &Style, segment_data const &Path);
static std::vector<segment_data> place_switch(switch_template const &Template, glm::dvec3 const &Origin, glm::dvec2 const &Direction, int const Side, double const Grade);
static TTrack *create_switch(switch_template const &Template, std::vector<segment_data> const &Paths, TTrack const &Style);
static void move_straights(std::vector<straight> const &Lines, std::vector<std::pair<glm::dvec3, glm::dvec3>> const &Ends);
@@ -169,6 +171,5 @@ class editor_track
static void store_switch_path(TTrack &Switch, int const Path);
static void rebuild_geometry(TTrack &Track);
static TTrack *clone(TTrack const &Template);
static TTrack *load_path(std::string const &Text, TTrack const &Template);
static void move_straight(straight const &Line, glm::dvec3 const &Start, glm::dvec3 const &End, std::function<bool(TTrack const *)> const &Member);
};