18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-20 13:54:58 +01:00

Merge branch 'master' into feat/renderers-cleanup

This commit is contained in:
2026-11-16 21:44:48 +01:00
264 changed files with 41203 additions and 10041 deletions

View File

@@ -1548,7 +1548,15 @@ basic_region::find_traction( glm::dvec3 const &Point, TTraction const *Other, in
std::vector<basic_section *> const &
basic_region::sections( glm::dvec3 const &Point, float const Radius ) {
m_scratchpad.sections.clear();
sections( Point, Radius, m_scratchpad.sections );
return m_scratchpad.sections;
}
// finds sections inside specified sphere, put in the list given in place of what it held
void
basic_region::sections( glm::dvec3 const &Point, float const Radius, std::vector<basic_section *> &Sections ) const {
Sections.clear();
auto const centerx { static_cast<int>( std::floor( Point.x / EU07_SECTIONSIZE + EU07_REGIONSIDESECTIONCOUNT / 2 ) ) };
auto const centerz { static_cast<int>( std::floor( Point.z / EU07_SECTIONSIZE + EU07_REGIONSIDESECTIONCOUNT / 2 ) ) };
@@ -1570,11 +1578,10 @@ basic_region::sections( glm::dvec3 const &Point, float const Radius ) {
if( section != nullptr
&& glm::length2(section->area().center - Point) <= sq(section->area().radius + padding + Radius) ) {
m_scratchpad.sections.emplace_back( section );
Sections.emplace_back( section );
}
}
}
return m_scratchpad.sections;
}
// checks whether specified point is within boundaries of the region

View File

@@ -553,6 +553,10 @@ public:
// finds sections inside specified sphere. returns: list of sections
std::vector<basic_section *> const &
sections( glm::dvec3 const &Point, float const Radius );
// finds sections inside specified sphere, put in the list given in place of what it held. unlike the one above it shares no list
// of its own, so it's safe while other threads look for sections too
void
sections( glm::dvec3 const &Point, float const Radius, std::vector<basic_section *> &Sections ) const;
void
create_map_geometry();
void

View File

@@ -24,6 +24,7 @@ http://mozilla.org/MPL/2.0/.
#include <fstream>
#include <functional>
#include <iterator>
#include <sstream>
#include <string_view>
namespace scene
@@ -567,7 +568,7 @@ void node_layers::stat(layer_handle const Layer)
}
// creates empty layer, included from specified one. returns: handle to the new layer, or null_handle with the explanation in Reason
layer_handle node_layers::create(std::string Name, layer_handle Parent, std::string &Reason, bool const Activate)
layer_handle node_layers::create(std::string Name, layer_handle Parent, std::string &Reason, bool const Activate, std::string Header)
{
Parent = resolve(Parent);
if (false == valid(Parent) || layer(Parent).removed || layer(Parent).binary)
@@ -644,6 +645,7 @@ layer_handle node_layers::create(std::string Name, layer_handle Parent, std::str
created.created = true;
created.editormade = true;
created.anchor = anchor;
created.header = std::move(Header);
// placement the new file is going to be loaded with
created.context_begin = valid(anchor) ? layer(anchor).context_end : layer(Parent).context_insert();
created.context_end = created.context_begin;
@@ -854,26 +856,59 @@ bool node_layers::pending() const
namespace
{
// marks of the lines the editor keeps track of
std::array<char const *, 9> const editormarks{"//$p", "//$h", "//$r", "//$b", "//$c", "//$o", "//$s", "//$k", "//$a"};
// marks of the lines the editor keeps track of. The letters the starters read in a scenery file are left to them: the title //$n,
// the description //$d, the attachments //$f, the image //$i, the id //$l and the old scenery //$a, in the trainsets //$o and //$r
std::array<char const *, 11> const editormarks{"//$p", "//$h", "//$r", "//$b", "//$c", "//$o", "//$s", "//$k", "//$z", "//$w", "//$t"};
// other tools put lines of their own after some of these marks: Rainsted its includes after //$r, the launcher the descriptions
// of the trainsets after //$o. The editor's lines of them are told by their first word
bool editor_line(char const *Mark, std::string const &Text)
// the marks some of these had before, on the letters of the starters: the download area //$z was //$a, the shared grade lines //$w
// were //$n, the fitted tracks //$t were //$f. Their lines are read only by the word the editor wrote in them, or by the start of
// the comment line it put before them, and are kept under the mark they have now: saved, they go and are written again with it
struct moved_mark
{
static std::array<std::pair<std::string_view, std::array<std::string_view, 11>>, 5> const words{{
std::string_view before;
char const *now;
std::string_view word;
std::string_view note;
};
std::array<moved_mark, 3> const movedmarks{{
{"//$a", "//$z", "point", "# the area the editor downloads"},
{"//$n", "//$w", "gradeline", "# the tracks sharing a grade line"},
{"//$f", "//$t", "fitted", "# the tracks whose grade line was fitted"},
}};
std::string_view first_word(std::string const &Text)
{
return std::string_view{Text}.substr(0, Text.find_first_of(" \t"));
}
// other tools put lines of their own after some of these marks: Rainsted its includes after //$r, the starters the descriptions
// of the trainsets after //$o. The editor's lines of them are told by their first words, and so are those of most marks of its
// own, so a line the editor didn't write is never taken off as the scenery is saved
bool editor_line(std::string_view const Mark, std::string const &Text)
{
if (Mark == "//$o")
{
// "on 0" or "on 1", the origin after it (older builds put the settings of the imagery there, from the year on); a trainset
// described as "on ..." isn't the editor's
std::istringstream words{Text};
std::string on, state, next;
return words >> on >> state && on == "on" && (state == "0" || state == "1") && (false == static_cast<bool>(words >> next) || next == "origin" || next == "year");
}
static std::array<std::pair<std::string_view, std::array<std::string_view, 11>>, 7> const words{{
{"//$h", {"#", "alignment", "source", "ends", "norms", "pieces", "kept", "vertex", "click", "element", "end"}},
{"//$r", {"#", "switch", "slip", "crossing", "double", "connection"}},
{"//$o", {"on"}},
{"//$s", {"#", "station"}},
{"//$k", {"#", "mark", "via"}},
{"//$z", {"#", "point"}},
{"//$w", {"#", "gradeline"}},
{"//$t", {"#", "fitted"}},
}};
auto const lookup{std::find_if(words.begin(), words.end(), [&](auto const &Entry) { return Entry.first == Mark; })};
if (lookup == words.end())
{
return true;
}
auto const word{std::string_view{Text}.substr(0, Text.find_first_of(" \t"))};
auto const word{first_word(Text)};
return std::any_of(lookup->second.begin(), lookup->second.end(), [&](std::string_view const Known) { return false == Known.empty() && Known == word; });
}
} // namespace
@@ -897,27 +932,39 @@ void node_layers::scan(layer_handle const Layer)
auto end{content.find('\n', begin)};
end = (end == std::string::npos ? content.size() : end + 1);
auto const first{content.find_first_not_of(" \t", begin)};
// the text after the mark, if the line starts with it
auto const marked_text = [&](std::string_view const Mark, std::string &Text) {
auto const length{Mark.size()};
if (content.compare(first, length, Mark) != 0 || (first + length < end && content[first + length] != ' ' && content[first + length] != '\t' && content[first + length] != '\r' && content[first + length] != '\n'))
{
return false;
}
Text = content.substr(first + length, end - first - length);
while (false == Text.empty() && (Text.back() == '\n' || Text.back() == '\r'))
{
Text.pop_back();
}
Text.erase(0, Text.find_first_not_of(" \t"));
return true;
};
if (first < end)
{
for (auto const *mark : editormarks)
std::string text;
char const *taken{nullptr};
bool moved{false};
auto const mark{std::find_if(editormarks.begin(), editormarks.end(), [&](char const *Mark) { return marked_text(Mark, text); })};
if (mark != editormarks.end())
{
auto const length{std::char_traits<char>::length(mark)};
if (content.compare(first, length, mark) != 0 || (first + length < end && content[first + length] != ' ' && content[first + length] != '\t' && content[first + length] != '\r' && content[first + length] != '\n'))
{
continue;
}
auto text{content.substr(first + length, end - first - length)};
while (false == text.empty() && (text.back() == '\n' || text.back() == '\r'))
{
text.pop_back();
}
text.erase(0, text.find_first_not_of(" \t"));
if (false == editor_line(mark, text))
{
break;
}
m_marked[Layer].push_back({mark, {static_cast<std::streamoff>(begin), static_cast<std::streamoff>(end)}, std::move(text)});
break;
taken = (editor_line(*mark, text) ? *mark : nullptr);
}
else if (auto const before{std::find_if(movedmarks.begin(), movedmarks.end(), [&](moved_mark const &Moved) { return marked_text(Moved.before, text); })}; before != movedmarks.end())
{
taken = (first_word(text) == before->word || text.starts_with(before->note) ? before->now : nullptr);
moved = true;
}
if (nullptr != taken)
{
m_marked[Layer].push_back({taken, {static_cast<std::streamoff>(begin), static_cast<std::streamoff>(end)}, std::move(text), moved});
}
}
begin = end;

View File

@@ -96,6 +96,7 @@ struct basic_layer
bool created{false}; // layer was created in the editor, its file doesn't exist yet
bool editormade{false}; // the file was made by the editor during this session, there's no original content to keep a backup of
layer_handle anchor{null_handle}; // for created layer: sibling its include directive goes after
std::string header; // for created layer: the comment line its file starts with, in place of the general one
bool removed{false}; // layer is to be dropped from the scenery
layer_handle merged{null_handle}; // layer which took over the content of this one
bool dead{false}; // removal or merge of the layer was saved, it's no longer a part of the scenery
@@ -302,8 +303,9 @@ class node_layers
void mark(layer_handle Layer, std::string const &Mark, std::vector<std::string> Lines);
// layer management. changes are applied to the scenery files by save()
// creates empty layer, included from specified one, made active unless told otherwise. returns: handle to the new layer, or null_handle with the explanation in Reason
layer_handle create(std::string Name, layer_handle Parent, std::string &Reason, bool const Activate = true);
// creates empty layer, included from specified one, made active unless told otherwise. its file starts with the comment
// line given, else with the general one. returns: handle to the new layer, or null_handle with the explanation in Reason
layer_handle create(std::string Name, layer_handle Parent, std::string &Reason, bool const Activate = true, std::string Header = {});
bool can_remove(layer_handle Layer, std::string &Reason) const;
// marks specified layer and the layers it includes as dropped from the scenery. their files are left on the disk
bool remove(layer_handle Layer);
@@ -372,6 +374,7 @@ class node_layers
std::string mark;
source_span span; // whole line, its end included
std::string text;
bool moved{false}; // read from the letter its mark had before; the save writes it again with the mark it has now
};
// methods
std::string path(layer_handle const Layer) const;

View File

@@ -1384,6 +1384,24 @@ save_result node_layers::save(std::vector<std::string> const &Rootstatements, st
}
}
// the lines read from the letters the marks had before go to the mark they have now, also those the editor didn't change
for (auto const &[markedlayer, lines] : m_marked)
{
auto const target{resolve(markedlayer)};
if (layer(markedlayer).dead || false == is_output(target) || false == writable(markedlayer))
{
continue;
}
for (auto const &line : lines)
{
if (line.moved && m_marking.count({markedlayer, line.mark}) == 0)
{
push_edit(markedlayer, line.span, {}, nullptr);
markedtext[target].push_back(line.mark + ' ' + line.text);
}
}
}
// node definitions written anew as a whole: the old ones go, the new ones are added to the file like new definitions
std::map<layer_handle, std::vector<std::string>> blocktext;
if (Blocks != nullptr)
@@ -1598,7 +1616,7 @@ save_result node_layers::save(std::vector<std::string> const &Rootstatements, st
if (layer(output).created)
{
// NOTE: the parser treats an empty file as a missing one
text.text = "// scenery layer created in the editor" + eol;
text.text = (layer(output).header.empty() ? std::string{"// scenery layer created in the editor"} : layer(output).header) + eol;
}
composition body;
if (false == compose(state, output, body, 0))
@@ -1896,13 +1914,11 @@ save_result node_layers::save(std::vector<std::string> const &Rootstatements, st
stat(output);
scan(output);
}
for (auto const &marking : m_marking)
// the lines of the merged layers are now in the files of their targets, read again with them: all of them, the ones the
// editor didn't change too, or the next save would write the lines moved off the letters of the starters twice
for (auto marked{m_marked.begin()}; marked != m_marked.end();)
{
if (resolve(marking.first.first) != marking.first.first)
{
// the lines of the merged layer are now in the file of its target
m_marked.erase(marking.first.first);
}
marked = (resolve(marked->first) != marked->first ? m_marked.erase(marked) : std::next(marked));
}
m_marking.clear();
for (auto &included : m_instances)

View File

@@ -794,11 +794,21 @@ basic_node::radius() {
return m_area.radius;
}
// the radius as worked out already, or worked out anew and not kept
float
basic_node::radius() const {
if( m_area.radius == -1.0 ) {
return radius_();
}
return m_area.radius;
}
// radius() subclass details, calculates node's bounding radius
// by default nodes are 'virtual don't extend from their center point
float
basic_node::radius_() {
basic_node::radius_() const {
return 0.f;
}

View File

@@ -101,6 +101,9 @@ public:
gfx::userdata_array userdata;
// terrain file the shape comes from, see scene::terrain_file::reference_of(); 0: none, or not known (only the editor asks)
std::uint16_t terrainfile { 0 };
// drawn pulled towards the camera in the depth buffer, over the surface it lies on: the photos of the editor laid on the
// terrain. not kept by serialize()
bool decal { false };
// methods:
// sends content of the struct to provided stream
void
@@ -127,6 +130,9 @@ public:
// relative to Origin. used by the editor's terrain to own editable geometry it can re-upload.
shape_node &
make_terrain( material_handle const Material, std::vector<world_vertex> Vertices, glm::dvec3 const Origin );
// see shapenode_data::decal
void
decal( bool const Decal ) { m_data.decal = Decal; }
// adds content of provided node to already enclosed geometry. returns: true if merge could be performed
bool
merge( shape_node &Shape );
@@ -380,6 +386,9 @@ public:
location();
float const &
radius();
// the radius as worked out already, or worked out anew and not kept
float
radius() const;
void
visible( bool const Visible );
bool
@@ -423,7 +432,7 @@ public:
private:
// methods
// radius() subclass details, calculates node's bounding radius
virtual float radius_();
virtual float radius_() const;
// serialize() subclass details, sends content of the subclass to provided stream
virtual void serialize_( std::ostream &Output ) const = 0;
// deserialize() subclass details, restores content of the subclass from provided stream