17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-03 16:40:21 +01:00

perf(scenery): runs of model instances read straight from the text by a reader made for them, shared between threads; anything the reader doesn't cover left to the parser; model and skin located once for a run of instances; lookup of nodes by uuid filled on load only for a scenery opened for editing

This commit is contained in:
2026-10-06 21:58:49 +02:00
parent 96cd3e32ef
commit 90c5420396
9 changed files with 696 additions and 29 deletions

View File

@@ -832,3 +832,44 @@ bool cParser::InLayerFile() const
{
return mIncludeParser ? mIncludeParser->InLayerFile() : (false == mFile.empty() && false == mIncFile);
}
std::string_view cParser::remainingText() const
{
if (false == tokens.empty())
{
return {};
}
// each parser on the way gets to change the tokens of the file being read
auto const *source{this};
while (true)
{
if (false == source->parameters.empty() || false == source->skipComments || source->mComments.size() != 2)
{
return {};
}
if (source->mIncludeParser == nullptr)
{
break;
}
source = source->mIncludeParser.get();
}
// NOTE: the first token of a file is left to the regular code, which deals with the byte order mark
if (source->mFirstToken || source->mEofBit || source->mFailBit || static_cast<std::size_t>(source->mPosition) >= source->mBuffer.size())
{
return {};
}
return std::string_view{source->mBuffer}.substr(static_cast<std::size_t>(source->mPosition));
}
void cParser::skipText(std::size_t const Count, std::size_t const Lines, std::size_t const Tokenlength)
{
if (mIncludeParser)
{
mIncludeParser->skipText(Count, Lines, Tokenlength);
return;
}
mPosition = static_cast<std::streamoff>(std::min(static_cast<std::size_t>(mPosition) + Count, mBuffer.size()));
mLine += Lines;
mTokenEnd = mPosition;
mTokenBegin = mPosition - static_cast<std::streamoff>(std::min(Tokenlength, static_cast<std::size_t>(mPosition)));
}

View File

@@ -10,6 +10,7 @@ http://mozilla.org/MPL/2.0/.
#pragma once
#include <string>
#include <string_view>
#include <sstream>
#include <fstream>
#include <vector>
@@ -107,6 +108,16 @@ class cParser //: public std::stringstream
std::streamoff TokenEnd() const;
// true if the most recently read token came straight from a scenery file which isn't an *.inc node template
bool InLayerFile() const;
// text which follows the most recently read token, for the readers which take entries of a known kind straight from
// the text instead of token by token. empty if the tokens can't be taken that way: some wait to be picked up, there
// are parameters of an include to put in them, or comment marks other than the standard ones are in use
std::string_view remainingText() const;
// moves past specified amount of the text returned by remainingText(): Lines is the number of line breaks in it,
// Tokenlength the length of the token it ends with
void skipText(std::size_t Count, std::size_t Lines, std::size_t Tokenlength);
// converts text holding a plain number without involving a stream. returns: true on success, false if the text needs regular treatment
template <typename Type_>
static bool parseNumber( std::string_view Token, Type_ &Output );
bool expandIncludes = true;
bool allowRandomIncludes = false;
bool skipComments = true;
@@ -158,9 +169,6 @@ class cParser //: public std::stringstream
bool hasChar();
bool getChar( char &Char );
void updateCharClasses( char const *Break );
// converts text holding a plain number without involving a stream. returns: true on success, false if the text needs regular treatment
template <typename Type_>
static bool parseNumber( std::string const &Token, Type_ &Output );
// members:
bool m_autoclear { true }; // unretrieved tokens are discarded when another read command is issued (legacy behaviour)
bool LoadTraction { true }; // load traction?
@@ -202,7 +210,7 @@ cParser::getToken( bool const ToLower, const char *Break );
template<typename Type_>
bool
cParser::parseNumber( std::string const &Token, Type_ &Output ) {
cParser::parseNumber( std::string_view const Token, Type_ &Output ) {
using type = std::remove_cv_t<Type_>;
if constexpr(