mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-03-22 15:05:03 +01:00
key binding lookup, ai vehicle activation delay
This commit is contained in:
10
Driver.cpp
10
Driver.cpp
@@ -1719,6 +1719,9 @@ TController::TController(bool AI, TDynamicObject *NewControll, bool InitPsyche,
|
||||
#endif
|
||||
LogFile.flush();
|
||||
}
|
||||
|
||||
// HACK: give the simulation a small window to potentially replace the AI with a human driver
|
||||
fActionTime = -2.0;
|
||||
};
|
||||
|
||||
void TController::CloseLog()
|
||||
@@ -2511,7 +2514,10 @@ void TController::SetDriverPsyche()
|
||||
|
||||
bool TController::PrepareEngine()
|
||||
{ // odpalanie silnika
|
||||
bool OK = false,
|
||||
// HACK: don't immediately activate inert vehicle in case the simulation is about to replace us with human driver
|
||||
if( /* ( mvOccupied->Vel < 1.0 ) && */ ( fActionTime < 0.0 ) ) { return false; }
|
||||
|
||||
bool OK = false,
|
||||
voltfront = false,
|
||||
voltrear = false;
|
||||
LastReactionTime = 0.0;
|
||||
@@ -4663,7 +4669,7 @@ TController::UpdateSituation(double dt) {
|
||||
fVoltage = 0.5 * (fVoltage + std::max( mvControlling->GetAnyTrainsetVoltage(), mvControlling->PantographVoltage ) );
|
||||
if( fVoltage < mvControlling->EnginePowerSource.CollectorParameters.MinV ) {
|
||||
// gdy rozłączenie WS z powodu niskiego napięcia
|
||||
if( fActionTime >= 0 ) {
|
||||
if( fActionTime >= PrepareTime ) {
|
||||
// jeśli czas oczekiwania nie został ustawiony, losowy czas oczekiwania przed ponownym załączeniem jazdy
|
||||
fActionTime = -2.0 - Random( 10 );
|
||||
}
|
||||
|
||||
@@ -470,6 +470,14 @@ eu07_application::get_input_hint( user_command const Command ) const {
|
||||
return m_modes[ m_modestack.top() ]->get_input_hint( Command );
|
||||
}
|
||||
*/
|
||||
int
|
||||
eu07_application::key_binding( user_command const Command ) const {
|
||||
|
||||
if( m_modestack.empty() ) { return -1; }
|
||||
|
||||
return m_modes[ m_modestack.top() ]->key_binding( Command );
|
||||
}
|
||||
|
||||
void
|
||||
eu07_application::on_key( int const Key, int const Scancode, int const Action, int const Mods ) {
|
||||
|
||||
|
||||
@@ -71,6 +71,9 @@ public:
|
||||
std::string
|
||||
get_input_hint( user_command const Command ) const;
|
||||
*/
|
||||
// provides key code associated with specified command
|
||||
int
|
||||
key_binding( user_command const Command ) const;
|
||||
// input handlers
|
||||
void
|
||||
on_key( int const Key, int const Scancode, int const Action, int const Mods );
|
||||
|
||||
@@ -71,9 +71,13 @@ public:
|
||||
virtual
|
||||
void
|
||||
on_event_poll() = 0;
|
||||
virtual
|
||||
// provides key code associated with specified command
|
||||
virtual
|
||||
int
|
||||
key_binding( user_command const Command ) const = 0;
|
||||
virtual
|
||||
bool
|
||||
is_command_processor() = 0;
|
||||
is_command_processor() const = 0;
|
||||
|
||||
protected:
|
||||
// members
|
||||
|
||||
@@ -83,10 +83,10 @@ driver_mode::drivermode_input::init() {
|
||||
}
|
||||
|
||||
std::string
|
||||
driver_mode::drivermode_input::command_hints( std::pair<user_command, user_command> const &Commands ) const {
|
||||
driver_mode::drivermode_input::binding_hints( std::pair<user_command, user_command> const &Commands ) const {
|
||||
|
||||
auto const inputhintleft { keyboard.mapping( Commands.first ) };
|
||||
auto const inputhintright { keyboard.mapping( Commands.second ) };
|
||||
auto const inputhintleft { keyboard.binding_hint( Commands.first ) };
|
||||
auto const inputhintright { keyboard.binding_hint( Commands.second ) };
|
||||
std::string inputhints =
|
||||
inputhintleft
|
||||
+ ( inputhintright.empty() ? "" :
|
||||
@@ -296,14 +296,14 @@ driver_mode::update() {
|
||||
// in regular mode show control functions, for defined controls
|
||||
auto const controlname { train->GetLabel( GfxRenderer->Pick_Control() ) };
|
||||
if( false == controlname.empty() ) {
|
||||
auto const bindings { m_input.mouse.bindings( controlname ) };
|
||||
auto inputhints { m_input.command_hints( bindings ) };
|
||||
auto const mousecommands { m_input.mouse.bindings( controlname ) };
|
||||
auto inputhints { m_input.binding_hints( mousecommands ) };
|
||||
// if the commands bound with the control don't have any assigned keys try potential fallbacks
|
||||
if( inputhints.empty() ) {
|
||||
inputhints = m_input.command_hints( m_input.command_fallback( bindings.first ) );
|
||||
inputhints = m_input.binding_hints( m_input.command_fallback( mousecommands.first ) );
|
||||
}
|
||||
if( inputhints.empty() ) {
|
||||
inputhints = m_input.command_hints( m_input.command_fallback( bindings.second ) );
|
||||
inputhints = m_input.binding_hints( m_input.command_fallback( mousecommands.second ) );
|
||||
}
|
||||
// ready or not, here we go
|
||||
if( inputhints.empty() ) {
|
||||
@@ -411,6 +411,13 @@ driver_mode::exit() {
|
||||
|
||||
}
|
||||
|
||||
// provides key code associated with specified command
|
||||
int
|
||||
driver_mode::key_binding( user_command const Command ) const {
|
||||
|
||||
return m_input.keyboard.binding( Command );
|
||||
}
|
||||
|
||||
void
|
||||
driver_mode::on_key( int const Key, int const Scancode, int const Action, int const Mods ) {
|
||||
|
||||
@@ -496,7 +503,7 @@ driver_mode::on_event_poll() {
|
||||
}
|
||||
|
||||
bool
|
||||
driver_mode::is_command_processor() {
|
||||
driver_mode::is_command_processor() const {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -51,8 +51,11 @@ public:
|
||||
on_scroll( double const Xoffset, double const Yoffset ) override;
|
||||
void
|
||||
on_event_poll() override;
|
||||
// provides key code associated with specified command
|
||||
int
|
||||
key_binding( user_command const Command ) const override;
|
||||
bool
|
||||
is_command_processor() override;
|
||||
is_command_processor() const override;
|
||||
|
||||
private:
|
||||
// types
|
||||
@@ -82,7 +85,7 @@ private:
|
||||
bool init();
|
||||
void poll();
|
||||
std::string
|
||||
command_hints( std::pair<user_command, user_command> const &Commands ) const;
|
||||
binding_hints( std::pair<user_command, user_command> const &Commands ) const;
|
||||
std::pair<user_command, user_command>
|
||||
command_fallback( user_command const Command ) const;
|
||||
};
|
||||
|
||||
@@ -47,8 +47,10 @@ driver_ui::driver_ui() {
|
||||
bool
|
||||
driver_ui::on_key_( int const Key, int const Scancode, int const Action, int const Mods ) {
|
||||
|
||||
// if the pause is on ignore block other input
|
||||
if( m_paused ) { return true; }
|
||||
if( m_paused ) {
|
||||
// if the pause is on block input except for the pause key which we let the owner deal with
|
||||
return ( Key != Application.key_binding( user_command::pausetoggle ) );
|
||||
}
|
||||
|
||||
switch( Key ) {
|
||||
|
||||
|
||||
@@ -271,8 +271,14 @@ editor_mode::on_event_poll() {
|
||||
m_input.poll();
|
||||
}
|
||||
|
||||
int
|
||||
editor_mode::key_binding( user_command const Command ) const {
|
||||
|
||||
return m_input.keyboard.binding( Command );
|
||||
}
|
||||
|
||||
bool
|
||||
editor_mode::is_command_processor() {
|
||||
editor_mode::is_command_processor() const {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -47,8 +47,11 @@ public:
|
||||
on_scroll( double const Xoffset, double const Yoffset ) override;
|
||||
void
|
||||
on_event_poll() override;
|
||||
// provides key code associated with specified command
|
||||
int
|
||||
key_binding( user_command const Command ) const override;
|
||||
bool
|
||||
is_command_processor() override;
|
||||
is_command_processor() const override;
|
||||
|
||||
private:
|
||||
// types
|
||||
|
||||
@@ -298,7 +298,7 @@ std::unordered_map<int, std::string> keytonamemap = {
|
||||
};
|
||||
|
||||
std::string
|
||||
keyboard_input::mapping( user_command const Command ) const {
|
||||
keyboard_input::binding_hint( user_command const Command ) const {
|
||||
|
||||
if( Command == user_command::none ) { return ""; }
|
||||
|
||||
@@ -308,16 +308,16 @@ keyboard_input::mapping( user_command const Command ) const {
|
||||
auto const lookup { keytonamemap.find( binding & 0xffff ) };
|
||||
if( lookup == keytonamemap.end() ) { return ""; }
|
||||
|
||||
std::string mapping;
|
||||
std::string hint;
|
||||
if( ( binding & keymodifier::shift ) != 0 ) {
|
||||
mapping += "SHIFT ";
|
||||
hint += "SHIFT ";
|
||||
}
|
||||
if( ( binding & keymodifier::control ) != 0 ) {
|
||||
mapping += "CTRL ";
|
||||
hint += "CTRL ";
|
||||
}
|
||||
mapping += lookup->second;
|
||||
hint += lookup->second;
|
||||
|
||||
return mapping;
|
||||
return hint;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
@@ -45,8 +45,10 @@ public:
|
||||
user_command const
|
||||
command() const {
|
||||
return m_command; }
|
||||
int
|
||||
binding( user_command const Command ) const;
|
||||
std::string
|
||||
mapping( user_command const Command ) const;
|
||||
binding_hint( user_command const Command ) const;
|
||||
|
||||
protected:
|
||||
// types
|
||||
@@ -92,8 +94,6 @@ private:
|
||||
};
|
||||
|
||||
// methods
|
||||
int
|
||||
binding( user_command const Command ) const;
|
||||
bool
|
||||
is_movement_key( int const Key ) const;
|
||||
|
||||
|
||||
@@ -45,6 +45,9 @@ public:
|
||||
on_scroll( double const Xoffset, double const Yoffset ) override { ; }
|
||||
void
|
||||
on_event_poll() override { ; }
|
||||
// provides key code associated with specified command
|
||||
int
|
||||
key_binding( user_command const Command ) const override { return -1; }
|
||||
bool
|
||||
is_command_processor() override { return false; }
|
||||
is_command_processor() const override { return false; }
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user