mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-20 11:34:57 +01:00
wasm display support
This commit is contained in:
@@ -38,6 +38,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include <thread>
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
#include <format>
|
||||
/*
|
||||
namespace input {
|
||||
|
||||
@@ -10035,7 +10036,10 @@ bool TTrain::Update(double const Deltatime)
|
||||
// screens
|
||||
|
||||
if (!FreeFlyModeFlag && simulation::Train == this) // don't bother if we're outside
|
||||
{
|
||||
update_screens(Deltatime);
|
||||
update_wasm_screens();
|
||||
}
|
||||
|
||||
// update direction relay
|
||||
if (prevBatState != mvOccupied->Power24vIsAvailable)
|
||||
@@ -10564,6 +10568,92 @@ void TTrain::update_screens(double dt)
|
||||
}
|
||||
}
|
||||
|
||||
void TTrain::update_wasm_screens()
|
||||
{
|
||||
auto &queue{Application.wasm_screens()};
|
||||
for (auto &entry : m_wasmscreens)
|
||||
{
|
||||
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_wasm_screen(cParser &Parser)
|
||||
{
|
||||
wasm_screen_entry entry;
|
||||
// the block is read whole even when the wasm 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};
|
||||
if (entry.config.target != "none" && false == find_screen_surface(entry.config.target, "WASM Screen", submodel, texture))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
entry.screen = Application.wasm_screens().acquire({.kind = wasm_screen_kind::cab,
|
||||
.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)
|
||||
{
|
||||
// the wasm screens are off
|
||||
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_wasmscreens.emplace_back(std::move(entry));
|
||||
}
|
||||
|
||||
void TTrain::add_distance(double const Distance)
|
||||
{
|
||||
|
||||
@@ -10739,6 +10829,7 @@ bool TTrain::InitializeCab(int NewCabNo, std::string const &asFileName)
|
||||
m_controlmapper.clear();
|
||||
// clear python screens
|
||||
m_screens.clear();
|
||||
m_wasmscreens.clear();
|
||||
// reset sound positions
|
||||
auto const nullvector{glm::vec3()};
|
||||
std::vector<std::reference_wrapper<std::optional<sound_source>>> sounds = {
|
||||
@@ -10930,23 +11021,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
|
||||
{
|
||||
@@ -10973,6 +11051,10 @@ 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 == "wasmscreen:")
|
||||
{
|
||||
load_wasm_screen(parser);
|
||||
}
|
||||
else if (token == "pyscreenupdatetime:")
|
||||
{
|
||||
parser.getTokens();
|
||||
|
||||
Reference in New Issue
Block a user