mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-10-17 20:19:20 +02:00
The track layout library came in as a subproject of its own -- its own CMakeLists, its own install and export rules, its own include tree -- which only made the build harder to follow now that everything else is a module. It is part of the editor, so it lives where the editor lives. - editor/plan_*.cppm / plan_*.cpp: the fifteen interface units and twelve implementation units, flat in editor/ beside editorTerrain and orthophoto, with the plan_ prefix keeping them clear of what was already there (editor/turnouts is the preset catalogue, so the geometry is plan_turnout_geometry). - modules are named eu07.editor.plan_*, like every other module in the tree. - namespaces move under the editor's own: editor::plan, editor::plan::geometry, ::io, ::render. The library's old name is gone from the sources and the docs. - every moved file carries the MPL header the rest of the tree carries; it had none. version.hpp went with the subproject: macros only, and unused. - the umbrella header is dropped -- nothing imported it. - the unit tests survive the fold: editor/tests, behind EU07_EDITOR_PLAN_TESTS (off by default), compiles the interfaces a second time into a small library of its own, because a test can only import modules from a target it links and linking the game would drag the whole simulator in. The code under test needs nothing but a compiler. 7/7 pass. - a switch may now be written with two dashes as well: --editor beside -editor. Builds with clang 22 (-DWITH_BETTER_RENDERER=OFF); -editor and --editor both come up in the editor on empty ground.
89 lines
2.3 KiB
C++
89 lines
2.3 KiB
C++
/*
|
|
This Source Code Form is subject to the
|
|
terms of the Mozilla Public License, v.
|
|
2.0. If a copy of the MPL was not
|
|
distributed with this file, You can
|
|
obtain one at
|
|
http://mozilla.org/MPL/2.0/.
|
|
*/
|
|
module;
|
|
#include <cstdint>
|
|
#include <string>
|
|
#include <variant>
|
|
#include <vector>
|
|
|
|
module eu07.editor.plan_model;
|
|
|
|
namespace editor::plan {
|
|
namespace {
|
|
|
|
template <typename Container, typename Id>
|
|
auto* lookup(Container& items, Id id) {
|
|
if (id == Id::none) {
|
|
return decltype(&items[0]){nullptr};
|
|
}
|
|
for (auto& item : items) {
|
|
if (item.id == id) {
|
|
return &item;
|
|
}
|
|
}
|
|
return decltype(&items[0]){nullptr};
|
|
}
|
|
|
|
} // namespace
|
|
|
|
ElementId mint_element(Document& document) { return static_cast<ElementId>(document.next_id++); }
|
|
TrackId mint_track(Document& document) { return static_cast<TrackId>(document.next_id++); }
|
|
TurnoutId mint_turnout(Document& document) { return static_cast<TurnoutId>(document.next_id++); }
|
|
|
|
const Track* find_track(const Document& document, TrackId id) {
|
|
return lookup(document.tracks, id);
|
|
}
|
|
Track* find_track(Document& document, TrackId id) { return lookup(document.tracks, id); }
|
|
|
|
const TurnoutPlacement* find_turnout(const Document& document, TurnoutId id) {
|
|
return lookup(document.turnouts, id);
|
|
}
|
|
TurnoutPlacement* find_turnout(Document& document, TurnoutId id) {
|
|
return lookup(document.turnouts, id);
|
|
}
|
|
|
|
const TurnoutType* find_type(const Document& document, const std::string& name) {
|
|
for (const auto& type : document.turnout_types) {
|
|
if (type.name == name) {
|
|
return &type;
|
|
}
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
const Element* find_element(const Document& document, ElementId id) {
|
|
if (id == ElementId::none) {
|
|
return nullptr;
|
|
}
|
|
for (const auto& track : document.tracks) {
|
|
for (const auto& element : track.elements) {
|
|
if (element.id == id) {
|
|
return &element;
|
|
}
|
|
}
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
const Track* find_element_track(const Document& document, ElementId id) {
|
|
if (id == ElementId::none) {
|
|
return nullptr;
|
|
}
|
|
for (const auto& track : document.tracks) {
|
|
for (const auto& element : track.elements) {
|
|
if (element.id == id) {
|
|
return &track;
|
|
}
|
|
}
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
} // namespace editor::plan
|