mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-19 01:46:01 +01:00
Lua script screens beside the WebAssembly ones
This commit is contained in:
@@ -298,6 +298,20 @@ material_data::assign( std::string const &Replacableskin ) {
|
||||
}
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
// a luadestinationsign: or wasmdestinationsign: block, its script in the vehicle folder when it has no path of its own
|
||||
void deserialize_script_sign( cParser &Parser, script_screens::screen_config &Sign, std::string const &Folder ) {
|
||||
|
||||
Sign.deserialize( Parser );
|
||||
if( false == Sign.script.empty()
|
||||
&& substr_path( Sign.script ).empty() ) {
|
||||
Sign.script = Folder + Sign.script;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void TDynamicObject::destination_data::deserialize( cParser &Input ) {
|
||||
|
||||
while( true == deserialize_mapping( Input ) ) {
|
||||
@@ -3141,19 +3155,19 @@ void TDynamicObject::update_destinations() {
|
||||
DestinationSign.destination :
|
||||
DestinationSign.destination_off;
|
||||
|
||||
update_wasm_destination();
|
||||
update_script_destination();
|
||||
}
|
||||
|
||||
void TDynamicObject::update_wasm_destination() {
|
||||
void TDynamicObject::update_script_destination() {
|
||||
|
||||
if( DestinationSign.wasm_sign == nullptr ) { return; }
|
||||
if( DestinationSign.script_sign == nullptr ) { return; }
|
||||
// only while the sign shows the destination it draws
|
||||
if( m_materialdata.replacable_skins[ 4 ] != DestinationSign.destination ) { return; }
|
||||
|
||||
auto &queue { Application.wasm_screens() };
|
||||
if( false == queue.due( *DestinationSign.wasm_sign ) ) { return; }
|
||||
auto &queue { Application.screens() };
|
||||
if( false == queue.due( *DestinationSign.script_sign ) ) { return; }
|
||||
// read anew on every refresh, so the sign follows the timetable
|
||||
queue.submit( DestinationSign.wasm_sign, std::make_shared<dictionary_source>( DestinationSign.wasm_request ), 0 );
|
||||
queue.submit( DestinationSign.script_sign, std::make_shared<dictionary_source>( DestinationSign.script_request ), 0 );
|
||||
}
|
||||
|
||||
bool TDynamicObject::Update(double dt, double dt1)
|
||||
@@ -7095,13 +7109,11 @@ void TDynamicObject::LoadMMediaFile( std::string const &TypeName, std::string co
|
||||
DestinationSign.script = asBaseDir + DestinationSign.script;
|
||||
}
|
||||
}
|
||||
else if( token == "luadestinationsign:" ) {
|
||||
deserialize_script_sign( parser, DestinationSign.lua, asBaseDir );
|
||||
}
|
||||
else if( token == "wasmdestinationsign:" ) {
|
||||
DestinationSign.wasm.deserialize( parser );
|
||||
// supply vehicle folder as script path if none is provided
|
||||
if( false == DestinationSign.wasm.script.empty()
|
||||
&& substr_path( DestinationSign.wasm.script ).empty() ) {
|
||||
DestinationSign.wasm.script = asBaseDir + DestinationSign.wasm.script;
|
||||
}
|
||||
deserialize_script_sign( parser, DestinationSign.wasm, asBaseDir );
|
||||
}
|
||||
// NOTE: legacy key, now expected as optional "background:" parameter in pydestinationsign: { parameter block }
|
||||
else if( token == "destinationsignbackground:" ) {
|
||||
@@ -7122,9 +7134,12 @@ void TDynamicObject::LoadMMediaFile( std::string const &TypeName, std::string co
|
||||
|
||||
if( ReplacableSkin != "none" ) {
|
||||
// potentially set blank destination texture
|
||||
auto const wasmbackground { Global.wasm_enabled && false == DestinationSign.wasm.script.empty() && false == DestinationSign.wasm.background.empty() };
|
||||
auto const &background { wasmbackground ? DestinationSign.wasm.background : DestinationSign.background };
|
||||
auto language { script_language::lua };
|
||||
auto const *scriptsign { script_destination( language ) };
|
||||
auto const &background { ( scriptsign != nullptr && false == scriptsign->background.empty() ) ? scriptsign->background : DestinationSign.background };
|
||||
DestinationSign.destination_off = DestinationFind( background.empty() ? "nowhere" : background );
|
||||
// a blank sign a script draws, drawn once
|
||||
DestinationSign.background_sign = draw_script_texture( background, DestinationSign.destination_off );
|
||||
}
|
||||
|
||||
// assign default samples to sound emitters which weren't included in the config file
|
||||
@@ -7945,7 +7960,7 @@ void TDynamicObject::DestinationClear() {
|
||||
if( false == DestinationSign.has_light ) { return; } // physical destination signs remain up until manually changed
|
||||
// update_destinations() shows the blank sign in place of the missing destination
|
||||
DestinationSign.destination = null_handle;
|
||||
DestinationSign.wasm_sign.reset();
|
||||
DestinationSign.script_sign.reset();
|
||||
}
|
||||
|
||||
void TDynamicObject::DestinationSet(std::string const &to, std::string const &numer) {
|
||||
@@ -7960,7 +7975,7 @@ void TDynamicObject::DestinationSet(std::string const &to, std::string const &nu
|
||||
if( std::abs( m_materialdata.multi_textures ) >= 4 ) { return; } // jak są 4 tekstury wymienne, to nie zmieniać rozkładem
|
||||
if( DestinationSign.sign == nullptr ) { return; } // no sign submodel, no problem
|
||||
// a sign drawn for the previous destination
|
||||
DestinationSign.wasm_sign.reset();
|
||||
DestinationSign.script_sign.reset();
|
||||
|
||||
// now see if we can find any version of the destination texture
|
||||
std::vector<std::string> const destinations = {
|
||||
@@ -7976,7 +7991,7 @@ void TDynamicObject::DestinationSet(std::string const &to, std::string const &nu
|
||||
}
|
||||
}
|
||||
// if we didn't get static texture we might be able to make one
|
||||
if( true == destination_set_wasm( numer ) ) { return; }
|
||||
if( true == destination_set_script( numer ) ) { return; }
|
||||
if( DestinationSign.script.empty() ) { return; } // no script so no way to make the texture
|
||||
if( numer == "none" ) { return; } // blank or incomplete/malformed timetable, don't bother
|
||||
|
||||
@@ -8017,32 +8032,75 @@ std::string TDynamicObject::destination_request( std::string const &Script, std:
|
||||
return signrequest;
|
||||
}
|
||||
|
||||
bool TDynamicObject::destination_set_wasm( std::string const &Numer ) {
|
||||
script_screens::screen_config const *TDynamicObject::script_destination( script_language &Language ) const {
|
||||
|
||||
if( false == Global.wasm_enabled ) { return false; }
|
||||
if( DestinationSign.wasm.script.empty() ) { return false; } // no wasm sign, maybe a python one
|
||||
if( Numer == "none" ) { return false; } // blank or incomplete/malformed timetable, don't bother
|
||||
auto const &screens { Application.screens() };
|
||||
if( false == DestinationSign.lua.script.empty() && screens.runs( script_language::lua ) ) {
|
||||
Language = script_language::lua;
|
||||
return &DestinationSign.lua;
|
||||
}
|
||||
if( false == DestinationSign.wasm.script.empty() && screens.runs( script_language::wasm ) ) {
|
||||
Language = script_language::wasm;
|
||||
return &DestinationSign.wasm;
|
||||
}
|
||||
return nullptr; // no script sign, maybe a python one
|
||||
}
|
||||
|
||||
auto const signrequest { destination_request( DestinationSign.wasm.script, DestinationSign.wasm.instancing, DestinationSign.wasm.parameters ) };
|
||||
bool TDynamicObject::destination_set_script( std::string const &Numer ) {
|
||||
|
||||
if( Numer == "none" ) { return false; } // blank or incomplete/malformed timetable, don't bother
|
||||
auto language { script_language::lua };
|
||||
auto const *scriptsign { script_destination( language ) };
|
||||
if( scriptsign == nullptr ) { return false; }
|
||||
|
||||
auto const signrequest { destination_request( scriptsign->script, scriptsign->instancing, scriptsign->parameters ) };
|
||||
auto const signmaterial { GfxRenderer->Fetch_Material( signrequest ) };
|
||||
if( signmaterial == null_handle ) { return false; }
|
||||
auto &signtexture { GfxRenderer->Texture( GfxRenderer->Material( signmaterial )->GetTexture( 0 ) ) };
|
||||
|
||||
// vehicles showing the same request (one train, one instance) share the screen, as they share the texture
|
||||
auto sign { Application.wasm_screens().acquire( {
|
||||
.kind = wasm_screen_kind::external,
|
||||
.script = DestinationSign.wasm.script,
|
||||
auto sign { Application.screens().acquire( {
|
||||
.kind = script_screen_kind::external,
|
||||
.language = language,
|
||||
.script = scriptsign->script,
|
||||
.key = signrequest,
|
||||
.texture = &signtexture,
|
||||
.frames = DestinationSign.wasm.frames } ) };
|
||||
if( sign == nullptr ) { return false; } // the wasm screens are off
|
||||
.frames = scriptsign->frames } ) };
|
||||
if( sign == nullptr ) { return false; }
|
||||
|
||||
DestinationSign.destination = signmaterial;
|
||||
DestinationSign.wasm_sign = std::move( sign );
|
||||
DestinationSign.wasm_request = signrequest.substr( signrequest.find( '?' ) + 1 );
|
||||
DestinationSign.script_sign = std::move( sign );
|
||||
DestinationSign.script_request = signrequest.substr( signrequest.find( '?' ) + 1 );
|
||||
return true;
|
||||
}
|
||||
|
||||
std::shared_ptr<script_screen> TDynamicObject::draw_script_texture( std::string const &Name, material_handle const Material ) {
|
||||
|
||||
if( false == Name.starts_with( "make:" ) || Material == null_handle ) { return nullptr; }
|
||||
auto const query { Name.find( '?' ) };
|
||||
auto const script { Name.substr( 5, query == std::string::npos ? std::string::npos : query - 5 ) };
|
||||
auto const language { script_language_of( script ) };
|
||||
if( false == language.has_value() ) { return nullptr; } // a python texture, made by the texture itself
|
||||
|
||||
auto &queue { Application.screens() };
|
||||
auto &texture { GfxRenderer->Texture( GfxRenderer->Material( Material )->GetTexture( 0 ) ) };
|
||||
auto screen { queue.acquire( {
|
||||
.kind = script_screen_kind::external,
|
||||
.language = *language,
|
||||
.script = script,
|
||||
.key = Name,
|
||||
.texture = &texture,
|
||||
.frames = 0 } ) };
|
||||
if( screen == nullptr ) { return nullptr; }
|
||||
queue.submit(
|
||||
screen,
|
||||
query == std::string::npos ?
|
||||
std::make_shared<dictionary_source>() :
|
||||
std::make_shared<dictionary_source>( Name.substr( query + 1 ) ),
|
||||
0 );
|
||||
return screen;
|
||||
}
|
||||
|
||||
material_handle TDynamicObject::DestinationFind( std::string Destination ) {
|
||||
|
||||
if( Destination.empty() ) { return null_handle; }
|
||||
|
||||
Reference in New Issue
Block a user