16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-22 19:49:19 +02:00

lua changes, smooth train brake

This commit is contained in:
milek7
2017-12-29 16:12:08 +01:00
parent 1d028e2539
commit 19d4c51915
5 changed files with 145 additions and 110 deletions

View File

@@ -402,6 +402,7 @@ int main(int argc, char *argv[])
input::Keyboard.poll(); input::Keyboard.poll();
if (input::uart) if (input::uart)
input::uart->poll(); input::uart->poll();
simulation::Commands.update();
if( true == Global::InputMouse ) { input::Mouse.poll(); } if( true == Global::InputMouse ) { input::Mouse.poll(); }
if( true == Global::InputGamepad ) { input::Gamepad.poll(); } if( true == Global::InputGamepad ) { input::Gamepad.poll(); }
} }

View File

@@ -719,14 +719,13 @@ void TTrain::OnCommand_independentbrakebailoff( TTrain *Train, command_data cons
} }
void TTrain::OnCommand_trainbrakeincrease( TTrain *Train, command_data const &Command ) { void TTrain::OnCommand_trainbrakeincrease( TTrain *Train, command_data const &Command ) {
if( Command.action != GLFW_RELEASE ) { if( Command.action != GLFW_RELEASE ) {
if( Train->mvOccupied->BrakeHandle == FV4a ) { if( Train->mvOccupied->BrakeHandle == FV4a ) {
Train->mvOccupied->BrakeLevelAdd( 0.1 /*15.0 * Command.time_delta*/ ); Train->mvOccupied->BrakeLevelAdd( Global::fBrakeStep * Command.time_delta );
} }
else { else {
if( Train->mvOccupied->BrakeLevelAdd( Global::fBrakeStep ) ) { if( Train->mvOccupied->BrakeLevelAdd( Global::fBrakeStep * Command.time_delta ) ) {
// nieodpowiedni warunek; true, jeśli można dalej kręcić // nieodpowiedni warunek; true, jeśli można dalej kręcić
Train->keybrakecount = 0; Train->keybrakecount = 0;
if( ( Train->is_eztoer() ) && ( Train->mvOccupied->BrakeCtrlPos < 3 ) ) { if( ( Train->is_eztoer() ) && ( Train->mvOccupied->BrakeCtrlPos < 3 ) ) {
@@ -743,7 +742,7 @@ void TTrain::OnCommand_trainbrakedecrease( TTrain *Train, command_data const &Co
if( Command.action != GLFW_RELEASE ) { if( Command.action != GLFW_RELEASE ) {
// press or hold // press or hold
if( Train->mvOccupied->BrakeHandle == FV4a ) { if( Train->mvOccupied->BrakeHandle == FV4a ) {
Train->mvOccupied->BrakeLevelAdd( -0.1 /*-15.0 * Command.time_delta*/ ); Train->mvOccupied->BrakeLevelAdd( -Global::fBrakeStep * Command.time_delta );
} }
else { else {
// nową wersję dostarczył ZiomalCl ("fixed looped sound in ezt when using NUM_9 key") // nową wersję dostarczył ZiomalCl ("fixed looped sound in ezt when using NUM_9 key")
@@ -756,7 +755,7 @@ void TTrain::OnCommand_trainbrakedecrease( TTrain *Train, command_data const &Co
// Ra: uzależnić dźwięk od zmiany stanu EP, nie od klawisza // Ra: uzależnić dźwięk od zmiany stanu EP, nie od klawisza
Train->dsbPneumaticSwitch.play(); Train->dsbPneumaticSwitch.play();
} }
Train->mvOccupied->BrakeLevelAdd( -Global::fBrakeStep ); Train->mvOccupied->BrakeLevelAdd( -Global::fBrakeStep * Command.time_delta );
} }
else else
Train->keybrakecount += 1; Train->keybrakecount += 1;

View File

@@ -19,70 +19,70 @@ namespace simulation {
command_queue Commands; command_queue Commands;
commanddescription_sequence Commands_descriptions = { commanddescription_sequence Commands_descriptions = {
{ "mastercontrollerincrease", command_target::vehicle }, { "mastercontrollerincrease", command_target::vehicle, command_mode::oneoff },
{ "mastercontrollerincreasefast", command_target::vehicle }, { "mastercontrollerincreasefast", command_target::vehicle, command_mode::oneoff },
{ "mastercontrollerdecrease", command_target::vehicle }, { "mastercontrollerdecrease", command_target::vehicle, command_mode::oneoff },
{ "mastercontrollerdecreasefast", command_target::vehicle }, { "mastercontrollerdecreasefast", command_target::vehicle, command_mode::oneoff },
{ "secondcontrollerincrease", command_target::vehicle }, { "secondcontrollerincrease", command_target::vehicle, command_mode::oneoff },
{ "secondcontrollerincreasefast", command_target::vehicle }, { "secondcontrollerincreasefast", command_target::vehicle, command_mode::oneoff },
{ "secondcontrollerdecrease", command_target::vehicle }, { "secondcontrollerdecrease", command_target::vehicle, command_mode::oneoff },
{ "secondcontrollerdecreasefast", command_target::vehicle }, { "secondcontrollerdecreasefast", command_target::vehicle, command_mode::oneoff },
{ "mucurrentindicatorothersourceactivate", command_target::vehicle }, { "mucurrentindicatorothersourceactivate", command_target::vehicle, command_mode::oneoff },
{ "independentbrakeincrease", command_target::vehicle }, { "independentbrakeincrease", command_target::vehicle, command_mode::oneoff },
{ "independentbrakeincreasefast", command_target::vehicle }, { "independentbrakeincreasefast", command_target::vehicle, command_mode::oneoff },
{ "independentbrakedecrease", command_target::vehicle }, { "independentbrakedecrease", command_target::vehicle, command_mode::oneoff },
{ "independentbrakedecreasefast", command_target::vehicle }, { "independentbrakedecreasefast", command_target::vehicle, command_mode::oneoff },
{ "independentbrakebailoff", command_target::vehicle }, { "independentbrakebailoff", command_target::vehicle, command_mode::oneoff },
{ "trainbrakeincrease", command_target::vehicle }, { "trainbrakeincrease", command_target::vehicle, command_mode::continuous },
{ "trainbrakedecrease", command_target::vehicle }, { "trainbrakedecrease", command_target::vehicle, command_mode::continuous },
{ "trainbrakecharging", command_target::vehicle }, { "trainbrakecharging", command_target::vehicle, command_mode::oneoff },
{ "trainbrakerelease", command_target::vehicle }, { "trainbrakerelease", command_target::vehicle, command_mode::oneoff },
{ "trainbrakefirstservice", command_target::vehicle }, { "trainbrakefirstservice", command_target::vehicle, command_mode::oneoff },
{ "trainbrakeservice", command_target::vehicle }, { "trainbrakeservice", command_target::vehicle, command_mode::oneoff },
{ "trainbrakefullservice", command_target::vehicle }, { "trainbrakefullservice", command_target::vehicle, command_mode::oneoff },
{ "trainbrakeemergency", command_target::vehicle }, { "trainbrakeemergency", command_target::vehicle, command_mode::oneoff },
{ "manualbrakeincrease", command_target::vehicle }, { "manualbrakeincrease", command_target::vehicle, command_mode::oneoff },
{ "manualbrakedecrease", command_target::vehicle }, { "manualbrakedecrease", command_target::vehicle, command_mode::oneoff },
{ "alarmchaintoggle", command_target::vehicle }, { "alarmchaintoggle", command_target::vehicle, command_mode::oneoff },
{ "wheelspinbrakeactivate", command_target::vehicle }, { "wheelspinbrakeactivate", command_target::vehicle, command_mode::oneoff },
{ "sandboxactivate", command_target::vehicle }, { "sandboxactivate", command_target::vehicle, command_mode::oneoff },
{ "reverserincrease", command_target::vehicle }, { "reverserincrease", command_target::vehicle, command_mode::oneoff },
{ "reverserdecrease", command_target::vehicle }, { "reverserdecrease", command_target::vehicle, command_mode::oneoff },
{ "linebreakertoggle", command_target::vehicle }, { "linebreakertoggle", command_target::vehicle, command_mode::oneoff },
{ "convertertoggle", command_target::vehicle }, { "convertertoggle", command_target::vehicle, command_mode::oneoff },
{ "convertertogglelocal", command_target::vehicle }, { "convertertogglelocal", command_target::vehicle, command_mode::oneoff },
{ "converteroverloadrelayreset", command_target::vehicle }, { "converteroverloadrelayreset", command_target::vehicle, command_mode::oneoff },
{ "compressortoggle", command_target::vehicle }, { "compressortoggle", command_target::vehicle, command_mode::oneoff },
{ "compressortogglelocal", command_target::vehicle }, { "compressortogglelocal", command_target::vehicle, command_mode::oneoff },
{ "motoroverloadrelaythresholdtoggle", command_target::vehicle }, { "motoroverloadrelaythresholdtoggle", command_target::vehicle, command_mode::oneoff },
{ "motoroverloadrelayreset", command_target::vehicle }, { "motoroverloadrelayreset", command_target::vehicle, command_mode::oneoff },
{ "notchingrelaytoggle", command_target::vehicle }, { "notchingrelaytoggle", command_target::vehicle, command_mode::oneoff },
{ "epbrakecontroltoggle", command_target::vehicle }, { "epbrakecontroltoggle", command_target::vehicle, command_mode::oneoff },
{ "brakeactingspeedincrease", command_target::vehicle }, { "brakeactingspeedincrease", command_target::vehicle, command_mode::oneoff },
{ "brakeactingspeeddecrease", command_target::vehicle }, { "brakeactingspeeddecrease", command_target::vehicle, command_mode::oneoff },
{ "mubrakingindicatortoggle", command_target::vehicle }, { "mubrakingindicatortoggle", command_target::vehicle, command_mode::oneoff },
{ "alerteracknowledge", command_target::vehicle }, { "alerteracknowledge", command_target::vehicle, command_mode::oneoff },
{ "hornlowactivate", command_target::vehicle }, { "hornlowactivate", command_target::vehicle, command_mode::oneoff },
{ "hornhighactivate", command_target::vehicle }, { "hornhighactivate", command_target::vehicle, command_mode::oneoff },
{ "radiotoggle", command_target::vehicle }, { "radiotoggle", command_target::vehicle, command_mode::oneoff },
{ "radiostoptest", command_target::vehicle }, { "radiostoptest", command_target::vehicle, command_mode::oneoff },
/* /*
const int k_FailedEngineCutOff = 35; const int k_FailedEngineCutOff = 35;
*/ */
{ "viewturn", command_target::entity }, { "viewturn", command_target::entity, command_mode::oneoff },
{ "movevector", command_target::entity }, { "movevector", command_target::entity, command_mode::oneoff },
{ "moveleft", command_target::entity }, { "moveleft", command_target::entity, command_mode::oneoff },
{ "moveright", command_target::entity }, { "moveright", command_target::entity, command_mode::oneoff },
{ "moveforward", command_target::entity }, { "moveforward", command_target::entity, command_mode::oneoff },
{ "moveback", command_target::entity }, { "moveback", command_target::entity, command_mode::oneoff },
{ "moveup", command_target::entity }, { "moveup", command_target::entity, command_mode::oneoff },
{ "movedown", command_target::entity }, { "movedown", command_target::entity, command_mode::oneoff },
{ "moveleftfast", command_target::entity }, { "moveleftfast", command_target::entity, command_mode::oneoff },
{ "moverightfast", command_target::entity }, { "moverightfast", command_target::entity, command_mode::oneoff },
{ "moveforwardfast", command_target::entity }, { "moveforwardfast", command_target::entity, command_mode::oneoff },
{ "movebackfast", command_target::entity }, { "movebackfast", command_target::entity, command_mode::oneoff },
{ "moveupfast", command_target::entity }, { "moveupfast", command_target::entity, command_mode::oneoff },
{ "movedownfast", command_target::entity }, { "movedownfast", command_target::entity, command_mode::oneoff },
/* /*
const int k_CabForward = 42; const int k_CabForward = 42;
const int k_CabBackward = 43; const int k_CabBackward = 43;
@@ -92,51 +92,51 @@ const int k_ProgramQuit = 46;
// const int k_ProgramPause= 47; // const int k_ProgramPause= 47;
const int k_ProgramHelp = 48; const int k_ProgramHelp = 48;
*/ */
{ "doortoggleleft", command_target::vehicle }, { "doortoggleleft", command_target::vehicle, command_mode::oneoff },
{ "doortoggleright", command_target::vehicle }, { "doortoggleright", command_target::vehicle, command_mode::oneoff },
{ "departureannounce", command_target::vehicle }, { "departureannounce", command_target::vehicle, command_mode::oneoff },
{ "doorlocktoggle", command_target::vehicle }, { "doorlocktoggle", command_target::vehicle, command_mode::oneoff },
{ "pantographcompressorvalvetoggle", command_target::vehicle }, { "pantographcompressorvalvetoggle", command_target::vehicle, command_mode::oneoff },
{ "pantographcompressoractivate", command_target::vehicle }, { "pantographcompressoractivate", command_target::vehicle, command_mode::oneoff },
{ "pantographtogglefront", command_target::vehicle }, { "pantographtogglefront", command_target::vehicle, command_mode::oneoff },
{ "pantographtogglerear", command_target::vehicle }, { "pantographtogglerear", command_target::vehicle, command_mode::oneoff },
{ "pantographlowerall", command_target::vehicle }, { "pantographlowerall", command_target::vehicle, command_mode::oneoff },
{ "heatingtoggle", command_target::vehicle }, { "heatingtoggle", command_target::vehicle, command_mode::oneoff },
/* /*
// const int k_FreeFlyMode= 59; // const int k_FreeFlyMode= 59;
*/ */
{ "lightspresetactivatenext", command_target::vehicle }, { "lightspresetactivatenext", command_target::vehicle, command_mode::oneoff },
{ "lightspresetactivateprevious", command_target::vehicle }, { "lightspresetactivateprevious", command_target::vehicle, command_mode::oneoff },
{ "headlighttoggleleft", command_target::vehicle }, { "headlighttoggleleft", command_target::vehicle, command_mode::oneoff },
{ "headlighttoggleright", command_target::vehicle }, { "headlighttoggleright", command_target::vehicle, command_mode::oneoff },
{ "headlighttoggleupper", command_target::vehicle }, { "headlighttoggleupper", command_target::vehicle, command_mode::oneoff },
{ "redmarkertoggleleft", command_target::vehicle }, { "redmarkertoggleleft", command_target::vehicle, command_mode::oneoff },
{ "redmarkertoggleright", command_target::vehicle }, { "redmarkertoggleright", command_target::vehicle, command_mode::oneoff },
{ "headlighttogglerearleft", command_target::vehicle }, { "headlighttogglerearleft", command_target::vehicle, command_mode::oneoff },
{ "headlighttogglerearright", command_target::vehicle }, { "headlighttogglerearright", command_target::vehicle, command_mode::oneoff },
{ "headlighttogglerearupper", command_target::vehicle }, { "headlighttogglerearupper", command_target::vehicle, command_mode::oneoff },
{ "redmarkertogglerearleft", command_target::vehicle }, { "redmarkertogglerearleft", command_target::vehicle, command_mode::oneoff },
{ "redmarkertogglerearright", command_target::vehicle }, { "redmarkertogglerearright", command_target::vehicle, command_mode::oneoff },
{ "headlightsdimtoggle", command_target::vehicle }, { "headlightsdimtoggle", command_target::vehicle, command_mode::oneoff },
{ "motorconnectorsopen", command_target::vehicle }, { "motorconnectorsopen", command_target::vehicle, command_mode::oneoff },
{ "motordisconnect", command_target::vehicle }, { "motordisconnect", command_target::vehicle, command_mode::oneoff },
{ "interiorlighttoggle", command_target::vehicle }, { "interiorlighttoggle", command_target::vehicle, command_mode::oneoff },
{ "interiorlightdimtoggle", command_target::vehicle }, { "interiorlightdimtoggle", command_target::vehicle, command_mode::oneoff },
{ "instrumentlighttoggle", command_target::vehicle }, { "instrumentlighttoggle", command_target::vehicle, command_mode::oneoff },
/* /*
const int k_EndSign = 70; const int k_EndSign = 70;
const int k_Active = 71; const int k_Active = 71;
*/ */
{ "generictoggle0", command_target::vehicle }, { "generictoggle0", command_target::vehicle, command_mode::oneoff },
{ "generictoggle1", command_target::vehicle }, { "generictoggle1", command_target::vehicle, command_mode::oneoff },
{ "generictoggle2", command_target::vehicle }, { "generictoggle2", command_target::vehicle, command_mode::oneoff },
{ "generictoggle3", command_target::vehicle }, { "generictoggle3", command_target::vehicle, command_mode::oneoff },
{ "generictoggle4", command_target::vehicle }, { "generictoggle4", command_target::vehicle, command_mode::oneoff },
{ "generictoggle5", command_target::vehicle }, { "generictoggle5", command_target::vehicle, command_mode::oneoff },
{ "generictoggle6", command_target::vehicle }, { "generictoggle6", command_target::vehicle, command_mode::oneoff },
{ "generictoggle7", command_target::vehicle }, { "generictoggle7", command_target::vehicle, command_mode::oneoff },
{ "generictoggle8", command_target::vehicle }, { "generictoggle8", command_target::vehicle, command_mode::oneoff },
{ "generictoggle9", command_target::vehicle }, { "generictoggle9", command_target::vehicle, command_mode::oneoff },
{ "batterytoggle", command_target::vehicle } { "batterytoggle", command_target::vehicle }
/* /*
const int k_WalkMode = 73; const int k_WalkMode = 73;
@@ -145,14 +145,36 @@ const int k_WalkMode = 73;
} }
void command_queue::update()
{
double delta = Timer::GetDeltaTime();
for (user_command c : m_active_continuous)
{
auto const &desc = simulation::Commands_descriptions[ static_cast<std::size_t>( c ) ];
command_data data { c, GLFW_REPEAT, 0, 0, command_data::desired_state_t::TOGGLE, delta };
auto lookup = m_commands.emplace((size_t)desc.target, commanddata_sequence() );
lookup.first->second.emplace( data );
}
}
// posts specified command for specified recipient // posts specified command for specified recipient
void void
command_queue::push( command_data const &Command, std::size_t const Recipient ) { command_queue::push( command_data const &Command, std::size_t const Recipient ) {
auto const &desc = simulation::Commands_descriptions[ static_cast<std::size_t>( Command.command ) ];
if (desc.mode == command_mode::continuous)
{
if (Command.action == GLFW_PRESS)
m_active_continuous.emplace(Command.command);
else if (Command.action == GLFW_RELEASE)
m_active_continuous.erase(Command.command);
}
else
{
auto lookup = m_commands.emplace( Recipient, commanddata_sequence() ); auto lookup = m_commands.emplace( Recipient, commanddata_sequence() );
// recipient stack was either located or created, so we can add to it quite safely // recipient stack was either located or created, so we can add to it quite safely
lookup.first->second.emplace( Command ); lookup.first->second.emplace( Command );
} }
}
// retrieves oldest posted command for specified recipient, if any. returns: true on retrieval, false if there's nothing to retrieve // retrieves oldest posted command for specified recipient, if any. returns: true on retrieval, false if there's nothing to retrieve
bool bool

View File

@@ -11,6 +11,7 @@ http://mozilla.org/MPL/2.0/.
#include <unordered_map> #include <unordered_map>
#include <queue> #include <queue>
#include <unordered_set>
enum class user_command { enum class user_command {
@@ -155,10 +156,15 @@ enum class command_target {
entity = 0x40000 entity = 0x40000
}; };
struct command_description { enum class command_mode {
oneoff,
continuous
};
struct command_description {
std::string name; std::string name;
command_target target; command_target target;
command_mode mode;
}; };
struct command_data { struct command_data {
@@ -191,6 +197,7 @@ public:
// retrieves oldest posted command for specified recipient, if any. returns: true on retrieval, false if there's nothing to retrieve // retrieves oldest posted command for specified recipient, if any. returns: true on retrieval, false if there's nothing to retrieve
bool bool
pop( command_data &Command, std::size_t const Recipient ); pop( command_data &Command, std::size_t const Recipient );
void update();
private: private:
// types // types
@@ -199,6 +206,9 @@ private:
// members // members
commanddatasequence_map m_commands; commanddatasequence_map m_commands;
// TODO: this set should contain more than just user_command
// also, maybe that and all continuous input logic should be in command_relay?
std::unordered_set<user_command> m_active_continuous;
}; };
// NOTE: simulation should be a (light) wrapper rather than namespace so we could potentially instance it, // NOTE: simulation should be a (light) wrapper rather than namespace so we could potentially instance it,

View File

@@ -36,6 +36,9 @@ const char lua_ffi[] = "local ffi = require(\"ffi\")\n"
"local module = {}\n" "local module = {}\n"
"\n" "\n"
"module.event_create = ns.scriptapi_event_create\n" "module.event_create = ns.scriptapi_event_create\n"
"function module.event_preparefunc(f)\n"
" return ffi.cast(\"void (*handler)(TEvent*, TDynamicObject*)\", f)\n"
"end\n"
"module.event_find = ns.scriptapi_event_find\n" "module.event_find = ns.scriptapi_event_find\n"
"function module.event_getname(a)\n" "function module.event_getname(a)\n"
" return ffi.string(ns.scriptapi_event_getname(a))\n" " return ffi.string(ns.scriptapi_event_getname(a))\n"