mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-18 00:49:19 +02: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
|
#endif
|
||||||
LogFile.flush();
|
LogFile.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HACK: give the simulation a small window to potentially replace the AI with a human driver
|
||||||
|
fActionTime = -2.0;
|
||||||
};
|
};
|
||||||
|
|
||||||
void TController::CloseLog()
|
void TController::CloseLog()
|
||||||
@@ -2511,7 +2514,10 @@ void TController::SetDriverPsyche()
|
|||||||
|
|
||||||
bool TController::PrepareEngine()
|
bool TController::PrepareEngine()
|
||||||
{ // odpalanie silnika
|
{ // 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,
|
voltfront = false,
|
||||||
voltrear = false;
|
voltrear = false;
|
||||||
LastReactionTime = 0.0;
|
LastReactionTime = 0.0;
|
||||||
@@ -4663,7 +4669,7 @@ TController::UpdateSituation(double dt) {
|
|||||||
fVoltage = 0.5 * (fVoltage + std::max( mvControlling->GetAnyTrainsetVoltage(), mvControlling->PantographVoltage ) );
|
fVoltage = 0.5 * (fVoltage + std::max( mvControlling->GetAnyTrainsetVoltage(), mvControlling->PantographVoltage ) );
|
||||||
if( fVoltage < mvControlling->EnginePowerSource.CollectorParameters.MinV ) {
|
if( fVoltage < mvControlling->EnginePowerSource.CollectorParameters.MinV ) {
|
||||||
// gdy rozłączenie WS z powodu niskiego napięcia
|
// 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
|
// jeśli czas oczekiwania nie został ustawiony, losowy czas oczekiwania przed ponownym załączeniem jazdy
|
||||||
fActionTime = -2.0 - Random( 10 );
|
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 );
|
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
|
void
|
||||||
eu07_application::on_key( int const Key, int const Scancode, int const Action, int const Mods ) {
|
eu07_application::on_key( int const Key, int const Scancode, int const Action, int const Mods ) {
|
||||||
|
|
||||||
|
|||||||
@@ -71,6 +71,9 @@ public:
|
|||||||
std::string
|
std::string
|
||||||
get_input_hint( user_command const Command ) const;
|
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
|
// input handlers
|
||||||
void
|
void
|
||||||
on_key( int const Key, int const Scancode, int const Action, int const Mods );
|
on_key( int const Key, int const Scancode, int const Action, int const Mods );
|
||||||
|
|||||||
@@ -71,9 +71,13 @@ public:
|
|||||||
virtual
|
virtual
|
||||||
void
|
void
|
||||||
on_event_poll() = 0;
|
on_event_poll() = 0;
|
||||||
virtual
|
// provides key code associated with specified command
|
||||||
|
virtual
|
||||||
|
int
|
||||||
|
key_binding( user_command const Command ) const = 0;
|
||||||
|
virtual
|
||||||
bool
|
bool
|
||||||
is_command_processor() = 0;
|
is_command_processor() const = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// members
|
// members
|
||||||
|
|||||||
@@ -83,10 +83,10 @@ driver_mode::drivermode_input::init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string
|
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 inputhintleft { keyboard.binding_hint( Commands.first ) };
|
||||||
auto const inputhintright { keyboard.mapping( Commands.second ) };
|
auto const inputhintright { keyboard.binding_hint( Commands.second ) };
|
||||||
std::string inputhints =
|
std::string inputhints =
|
||||||
inputhintleft
|
inputhintleft
|
||||||
+ ( inputhintright.empty() ? "" :
|
+ ( inputhintright.empty() ? "" :
|
||||||
@@ -296,14 +296,14 @@ driver_mode::update() {
|
|||||||
// in regular mode show control functions, for defined controls
|
// in regular mode show control functions, for defined controls
|
||||||
auto const controlname { train->GetLabel( GfxRenderer->Pick_Control() ) };
|
auto const controlname { train->GetLabel( GfxRenderer->Pick_Control() ) };
|
||||||
if( false == controlname.empty() ) {
|
if( false == controlname.empty() ) {
|
||||||
auto const bindings { m_input.mouse.bindings( controlname ) };
|
auto const mousecommands { m_input.mouse.bindings( controlname ) };
|
||||||
auto inputhints { m_input.command_hints( bindings ) };
|
auto inputhints { m_input.binding_hints( mousecommands ) };
|
||||||
// if the commands bound with the control don't have any assigned keys try potential fallbacks
|
// if the commands bound with the control don't have any assigned keys try potential fallbacks
|
||||||
if( inputhints.empty() ) {
|
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() ) {
|
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
|
// ready or not, here we go
|
||||||
if( inputhints.empty() ) {
|
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
|
void
|
||||||
driver_mode::on_key( int const Key, int const Scancode, int const Action, int const Mods ) {
|
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
|
bool
|
||||||
driver_mode::is_command_processor() {
|
driver_mode::is_command_processor() const {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,8 +51,11 @@ public:
|
|||||||
on_scroll( double const Xoffset, double const Yoffset ) override;
|
on_scroll( double const Xoffset, double const Yoffset ) override;
|
||||||
void
|
void
|
||||||
on_event_poll() override;
|
on_event_poll() override;
|
||||||
|
// provides key code associated with specified command
|
||||||
|
int
|
||||||
|
key_binding( user_command const Command ) const override;
|
||||||
bool
|
bool
|
||||||
is_command_processor() override;
|
is_command_processor() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// types
|
// types
|
||||||
@@ -82,7 +85,7 @@ private:
|
|||||||
bool init();
|
bool init();
|
||||||
void poll();
|
void poll();
|
||||||
std::string
|
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>
|
std::pair<user_command, user_command>
|
||||||
command_fallback( user_command const Command ) const;
|
command_fallback( user_command const Command ) const;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -47,8 +47,10 @@ driver_ui::driver_ui() {
|
|||||||
bool
|
bool
|
||||||
driver_ui::on_key_( int const Key, int const Scancode, int const Action, int const Mods ) {
|
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 ) {
|
||||||
if( m_paused ) { return true; }
|
// 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 ) {
|
switch( Key ) {
|
||||||
|
|
||||||
|
|||||||
@@ -271,8 +271,14 @@ editor_mode::on_event_poll() {
|
|||||||
m_input.poll();
|
m_input.poll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
editor_mode::key_binding( user_command const Command ) const {
|
||||||
|
|
||||||
|
return m_input.keyboard.binding( Command );
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
editor_mode::is_command_processor() {
|
editor_mode::is_command_processor() const {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,8 +47,11 @@ public:
|
|||||||
on_scroll( double const Xoffset, double const Yoffset ) override;
|
on_scroll( double const Xoffset, double const Yoffset ) override;
|
||||||
void
|
void
|
||||||
on_event_poll() override;
|
on_event_poll() override;
|
||||||
|
// provides key code associated with specified command
|
||||||
|
int
|
||||||
|
key_binding( user_command const Command ) const override;
|
||||||
bool
|
bool
|
||||||
is_command_processor() override;
|
is_command_processor() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// types
|
// types
|
||||||
|
|||||||
@@ -298,7 +298,7 @@ std::unordered_map<int, std::string> keytonamemap = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
std::string
|
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 ""; }
|
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 ) };
|
auto const lookup { keytonamemap.find( binding & 0xffff ) };
|
||||||
if( lookup == keytonamemap.end() ) { return ""; }
|
if( lookup == keytonamemap.end() ) { return ""; }
|
||||||
|
|
||||||
std::string mapping;
|
std::string hint;
|
||||||
if( ( binding & keymodifier::shift ) != 0 ) {
|
if( ( binding & keymodifier::shift ) != 0 ) {
|
||||||
mapping += "SHIFT ";
|
hint += "SHIFT ";
|
||||||
}
|
}
|
||||||
if( ( binding & keymodifier::control ) != 0 ) {
|
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
|
user_command const
|
||||||
command() const {
|
command() const {
|
||||||
return m_command; }
|
return m_command; }
|
||||||
|
int
|
||||||
|
binding( user_command const Command ) const;
|
||||||
std::string
|
std::string
|
||||||
mapping( user_command const Command ) const;
|
binding_hint( user_command const Command ) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// types
|
// types
|
||||||
@@ -92,8 +94,6 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
// methods
|
// methods
|
||||||
int
|
|
||||||
binding( user_command const Command ) const;
|
|
||||||
bool
|
bool
|
||||||
is_movement_key( int const Key ) const;
|
is_movement_key( int const Key ) const;
|
||||||
|
|
||||||
|
|||||||
@@ -45,6 +45,9 @@ public:
|
|||||||
on_scroll( double const Xoffset, double const Yoffset ) override { ; }
|
on_scroll( double const Xoffset, double const Yoffset ) override { ; }
|
||||||
void
|
void
|
||||||
on_event_poll() override { ; }
|
on_event_poll() override { ; }
|
||||||
|
// provides key code associated with specified command
|
||||||
|
int
|
||||||
|
key_binding( user_command const Command ) const override { return -1; }
|
||||||
bool
|
bool
|
||||||
is_command_processor() override { return false; }
|
is_command_processor() const override { return false; }
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user