From 02bb352caff635a0cd39e952fcf2efdc5d65685f Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Wed, 14 Oct 2026 16:36:39 +0200 Subject: [PATCH] refactor(physics): read vehicle definitions from text as well as files TMoverParameters::LoadFIZ(path) opens the file and hands the parser over to LoadFIZ_Parse(), which holds what LoadFIZ() did with it before. The new LoadFIZ_Text() reads the same format from a string, so a definition can be made up in memory, e.g. by a unit test. No change in behaviour for files. Co-Authored-By: Claude Opus 5.5 --- McZapkie/MOVER.h | 4 ++++ McZapkie/Mover.cpp | 48 ++++++++++++++++++++++++++++++---------------- 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/McZapkie/MOVER.h b/McZapkie/MOVER.h index 5176eb15..29b3e75c 100644 --- a/McZapkie/MOVER.h +++ b/McZapkie/MOVER.h @@ -13,6 +13,8 @@ http://mozilla.org/MPL/2.0/. #include #include "hamulce.h" #include "scripting/ladderlogic.h" + +class cParser; /* MaSzyna EU07 locomotive simulator Copyright (C) 2001-2004 Maciej Czapkiewicz and others @@ -2534,10 +2536,12 @@ class TMoverParameters /*funkcje ladujace pliki opisujace pojazd*/ bool LoadFIZ(std::string const &chkpath); // Q 20160717 bool LoadChkFile(std::string chkpath); + bool LoadFIZ_Text(std::string const &Text); // the same, from text in the .fiz format bool CheckLocomotiveParameters(bool ReadyFlag, int Dir); std::string EngineDescription(int what) const; private: + bool LoadFIZ_Parse(cParser &Parser); // reads the definition from either of the above void LoadFIZ_Param(std::string const &line); void LoadFIZ_Load(std::string const &line); void LoadFIZ_Dimensions(std::string const &line); diff --git a/McZapkie/Mover.cpp b/McZapkie/Mover.cpp index 16fe3066..9c9d56d9 100644 --- a/McZapkie/Mover.cpp +++ b/McZapkie/Mover.cpp @@ -9559,6 +9559,37 @@ bool TMoverParameters::LoadFIZ(std::string const &chkpath) chkPath = chkpath; // assign class path for reloading ConversionError = 666; + std::string file = TypeName + ".fiz"; + + WriteLog("LOAD FIZ FROM " + file); + /* + std::ifstream in(file); + if (!in.is_open()) + { + WriteLog("E8 - FIZ FILE NOT EXIST."); + return false; + } + */ + cParser fizparser(file, cParser::buffer_FILE, chkpath); + if (false == fizparser.ok()) + { + WriteLog("E8 - FIZ FILE NOT EXIST."); + return false; + } + + return LoadFIZ_Parse(fizparser); +} + +// reads the vehicle definition from text in the .fiz format, e.g. one made up by a unit test +bool TMoverParameters::LoadFIZ_Text(std::string const &Text) +{ + ConversionError = 666; + cParser fizparser(Text, cParser::buffer_TEXT); + return LoadFIZ_Parse(fizparser); +} + +bool TMoverParameters::LoadFIZ_Parse(cParser &fizparser) +{ LISTLINE = 0; startBPT = false; startMPT = false; @@ -9577,23 +9608,6 @@ bool TMoverParameters::LoadFIZ(std::string const &chkpath) startDimmerList = false; startLIGHTSLIST = false; startCOMPRESSORLIST = false; - std::string file = TypeName + ".fiz"; - - WriteLog("LOAD FIZ FROM " + file); - /* - std::ifstream in(file); - if (!in.is_open()) - { - WriteLog("E8 - FIZ FILE NOT EXIST."); - return false; - } - */ - cParser fizparser(file, cParser::buffer_FILE, chkpath); - if (false == fizparser.ok()) - { - WriteLog("E8 - FIZ FILE NOT EXIST."); - return false; - } ConversionError = 0;