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

Merge remote-tracking branch 'origin/master' into feat/persistent-odometer-store

# Conflicts:
#	vehicle/DynObj.h
This commit is contained in:
jerrrrycho
2026-11-11 08:17:40 +01:00
70 changed files with 11421 additions and 369 deletions

View File

@@ -22,6 +22,7 @@ http://mozilla.org/MPL/2.0/.
#include "utilities/Globals.h"
#include "simulation/simulation.h"
#include "simulation/blackboxrecorder.h"
#include "world/Event.h"
#include "simulation/simulationtime.h"
#include "vehicle/Camera.h"
@@ -39,6 +40,7 @@ http://mozilla.org/MPL/2.0/.
#include <thread>
#include <cmath>
#include <algorithm>
#include <format>
/*
namespace input {
@@ -8807,6 +8809,7 @@ bool TTrain::Update(double const Deltatime)
command_data commanddata;
while (simulation::Commands.pop(commanddata, static_cast<std::size_t>(command_target::vehicle) | id()))
{
simulation::Blackbox.command(DynamicObject, commanddata.command, commanddata.action, commanddata.param1, commanddata.param2);
auto lookup = m_commandhandlers.find(commanddata.command);
if (lookup != m_commandhandlers.end())
@@ -10037,7 +10040,10 @@ bool TTrain::Update(double const Deltatime)
// screens
if (!FreeFlyModeFlag && simulation::Train == this) // don't bother if we're outside
{
update_screens(Deltatime);
update_script_screens();
}
// update direction relay
if (prevBatState != mvOccupied->Power24vIsAvailable)
@@ -10566,6 +10572,99 @@ void TTrain::update_screens(double dt)
}
}
void TTrain::update_script_screens()
{
auto &queue{Application.screens()};
for (auto &entry : m_scriptscreens)
{
if (false == queue.due(*entry.screen))
{
continue;
}
auto input{GetTrainState(entry.parameters)};
input->insert("touches", *entry.touch_list);
entry.touch_list->clear();
queue.submit(entry.screen, std::move(input), id());
}
}
bool TTrain::find_screen_surface(std::string const &Target, std::string_view const Kind, TSubModel *&Submodel, ITexture *&Texture) const
{
Submodel = DynamicObject->mdKabina ? DynamicObject->mdKabina->GetFromName(Target) :
DynamicObject->mdLowPolyInt ? DynamicObject->mdLowPolyInt->GetFromName(Target) :
nullptr;
if (Submodel == nullptr)
{
WriteLog(std::format("{}: submodel {} not found - Ignoring screen", Kind, Target));
return false;
}
auto const material{Submodel->GetMaterial()};
if (material <= 0)
{
// sub model nie posiada tekstury lub tekstura wymienna - nie obslugiwana
WriteLog(std::format("{}: invalid texture id {} - Ignoring screen", Kind, material));
return false;
}
Texture = &GfxRenderer->Texture(GfxRenderer->Material(material)->GetTexture(0));
return true;
}
void TTrain::load_script_screen(cParser &Parser, script_language const Language)
{
script_screen_entry entry;
// the block is read whole even when the script screens are off
entry.config.deserialize(Parser);
if (entry.config.script.empty())
{
return;
}
if (substr_path(entry.config.script).empty())
{
entry.config.script = DynamicObject->asBaseDir + entry.config.script;
}
TSubModel *submodel{nullptr};
ITexture *texture{nullptr};
auto &queue{Application.screens()};
if (false == queue.runs(Language))
{
// the screens of the language are off
return;
}
if (entry.config.target != "none" &&
false == find_screen_surface(entry.config.target, Language == script_language::lua ? "Lua Screen" : "WASM Screen", submodel, texture))
{
return;
}
entry.screen = queue.acquire({.kind = script_screen_kind::cab,
.language = Language,
.script = entry.config.script,
.key = std::format("cab:{}:{}:{}", DynamicObject->name(), entry.config.target, entry.config.script),
.texture = texture,
.frames = entry.config.frames});
if (entry.screen == nullptr)
{
return;
}
if (texture != nullptr)
{
// make the surface static so it doesn't get destroyed by garbage collector if the user spends long time outside cab
texture->create(true);
}
if (false == entry.config.parameters.empty())
{
entry.parameters = dictionary_source(entry.config.parameters);
}
entry.touch_list = std::make_shared<std::vector<glm::vec2>>();
if (submodel != nullptr)
{
submodel->screen_touch_list = entry.touch_list;
}
m_scriptscreens.emplace_back(std::move(entry));
}
void TTrain::add_distance(double const Distance)
{
@@ -10741,6 +10840,7 @@ bool TTrain::InitializeCab(int NewCabNo, std::string const &asFileName)
m_controlmapper.clear();
// clear python screens
m_screens.clear();
m_scriptscreens.clear();
// reset sound positions
auto const nullvector{glm::vec3()};
std::vector<std::reference_wrapper<std::optional<sound_source>>> sounds = {
@@ -10932,23 +11032,10 @@ bool TTrain::InitializeCab(int NewCabNo, std::string const &asFileName)
TSubModel *submodel = nullptr;
if (screen.target != "none")
{
submodel = DynamicObject->mdKabina ? DynamicObject->mdKabina->GetFromName(screen.target) :
DynamicObject->mdLowPolyInt ? DynamicObject->mdLowPolyInt->GetFromName(screen.target) :
nullptr;
if (submodel == nullptr)
if (false == find_screen_surface(screen.target, "Python Screen", submodel, tex))
{
WriteLog("Python Screen: submodel " + screen.target + " not found - Ignoring screen");
continue;
}
auto const material{submodel->GetMaterial()};
if (material <= 0)
{
// sub model nie posiada tekstury lub tekstura wymienna - nie obslugiwana
WriteLog("Python Screen: invalid texture id " + std::to_string(material) + " - Ignoring screen");
continue;
}
tex = &GfxRenderer->Texture(GfxRenderer->Material(material)->GetTexture(0));
}
else
{
@@ -10975,6 +11062,14 @@ bool TTrain::InitializeCab(int NewCabNo, std::string const &asFileName)
if (Global.python_displaywindows)
m_screens.back().viewer = std::make_unique<python_screen_viewer>(rt, m_screens.back().touch_list, m_screens.back().script);
}
else if (token == "luascreen:")
{
load_script_screen(parser, script_language::lua);
}
else if (token == "wasmscreen:")
{
load_script_screen(parser, script_language::wasm);
}
else if (token == "pyscreenupdatetime:")
{
parser.getTokens();