Remove unneeded character saving, we always get it from translated string if needed

It causes undefined behavior in C++20, see #4735
This commit is contained in:
Benau 2022-02-25 11:20:52 +08:00
parent dcdc66b8f5
commit c63faf395f
6 changed files with 7 additions and 29 deletions

View File

@ -32,11 +32,6 @@ void Binding::save(std::ofstream& stream) const
stream << "event=\"" << m_type << "\" "; stream << "event=\"" << m_type << "\" ";
stream << "id=\"" << m_id << "\" "; stream << "id=\"" << m_id << "\" ";
if (m_type == Input::IT_KEYBOARD)
{
stream << "character=\"" << m_character << "\" ";
}
// Only serialize the direction and the range for stick motions // Only serialize the direction and the range for stick motions
if (m_type == Input::IT_STICKMOTION) if (m_type == Input::IT_STICKMOTION)
{ {
@ -58,12 +53,6 @@ bool Binding::load(const XMLNode *action)
// Default settings for button // Default settings for button
m_range = Input::AR_HALF; m_range = Input::AR_HALF;
m_dir = Input::AD_NEUTRAL; m_dir = Input::AD_NEUTRAL;
m_character = 0;
// XMLNode only supports stringw, not wchar_t*
core::stringw s;
action->get("character", &s);
if(s.size()>0)
m_character = s[0];
// If the action is not a stick motion (button or key) // If the action is not a stick motion (button or key)
if (m_type == Input::IT_STICKMOTION) if (m_type == Input::IT_STICKMOTION)
@ -97,9 +86,6 @@ irr::core::stringw Binding::getAsString() const
break; break;
case Input::IT_KEYBOARD: case Input::IT_KEYBOARD:
s = "?"; s = "?";
if(m_character)
s[0]=m_character;
switch(m_id) switch(m_id)
{ {
//I18N: input configuration screen: mouse button //I18N: input configuration screen: mouse button

View File

@ -40,7 +40,6 @@ private:
int m_id; int m_id;
Input::AxisDirection m_dir; Input::AxisDirection m_dir;
Input::AxisRange m_range; Input::AxisRange m_range;
wchar_t m_character;
public: public:
/** Returns the type of device this binding is using. */ /** Returns the type of device this binding is using. */
Input::InputType getType() const {return m_type; } Input::InputType getType() const {return m_type; }
@ -57,10 +56,9 @@ public:
/** Defines all values of this binding. */ /** Defines all values of this binding. */
void set(Input::InputType type, int id, void set(Input::InputType type, int id,
Input::AxisDirection dir, Input::AxisDirection dir,
Input::AxisRange range, Input::AxisRange range)
wchar_t character)
{ {
m_type = type; m_id=id; m_dir=dir; m_range=range; m_character=character; m_type = type; m_id=id; m_dir=dir; m_range=range;
} // set } // set
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------

View File

@ -179,10 +179,9 @@ void DeviceConfig::setBinding ( const PlayerAction action,
const Input::InputType type, const Input::InputType type,
const int id, const int id,
Input::AxisDirection direction, Input::AxisDirection direction,
Input::AxisRange range, Input::AxisRange range)
wchar_t character)
{ {
m_bindings[action].set(type, id, direction, range, character); m_bindings[action].set(type, id, direction, range);
} // setBinding } // setBinding
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------

View File

@ -89,8 +89,7 @@ public:
const Input::InputType type, const Input::InputType type,
const int id, const int id,
Input::AxisDirection direction = Input::AD_NEUTRAL, Input::AxisDirection direction = Input::AD_NEUTRAL,
Input::AxisRange range = Input::AR_HALF, Input::AxisRange range = Input::AR_HALF);
wchar_t character=0);
bool getMenuAction(Input::InputType type, bool getMenuAction(Input::InputType type,
const int id, const int id,
int* value, int* value,

View File

@ -563,8 +563,6 @@ void DeviceManager::save()
configfile << "<!--\n" configfile << "<!--\n"
<< "Event 1 : Keyboard button press\n" << "Event 1 : Keyboard button press\n"
<< " 'id' indicates which button, as defined by irrlicht's EKEY_CODE enum\n" << " 'id' indicates which button, as defined by irrlicht's EKEY_CODE enum\n"
<< " 'character' contains the associated unicode character.\n"
<< " Only used as fallback when displaying special characters in the UI.\n"
<< "Event 2 : Gamepad stick motion\n" << "Event 2 : Gamepad stick motion\n"
<< " 'id' indicates which stick, starting from 0\n" << " 'id' indicates which stick, starting from 0\n"
<< " 'direction' 0 means negative, 1 means positive\n" << " 'direction' 0 means negative, 1 means positive\n"

View File

@ -436,8 +436,7 @@ void OptionsScreenDevice::gotSensedInput(const Input& sensed_input)
KeyboardConfig* keyboard = (KeyboardConfig*)m_config; KeyboardConfig* keyboard = (KeyboardConfig*)m_config;
keyboard->setBinding(binding_to_set, Input::IT_KEYBOARD, keyboard->setBinding(binding_to_set, Input::IT_KEYBOARD,
sensed_input.m_button_id, Input::AD_NEUTRAL, sensed_input.m_button_id, Input::AD_NEUTRAL,
Input::AR_HALF, Input::AR_HALF);
sensed_input.m_character);
// refresh display // refresh display
updateInputButtons(); updateInputButtons();
@ -495,8 +494,7 @@ void OptionsScreenDevice::gotSensedInput(const Input& sensed_input)
KeyboardConfig* keyboard = (KeyboardConfig*)m_config; KeyboardConfig* keyboard = (KeyboardConfig*)m_config;
keyboard->setBinding(binding_to_set, Input::IT_NONE, keyboard->setBinding(binding_to_set, Input::IT_NONE,
sensed_input.m_button_id, Input::AD_NEUTRAL, sensed_input.m_button_id, Input::AD_NEUTRAL,
Input::AR_HALF, Input::AR_HALF);
sensed_input.m_character);
// refresh display // refresh display
updateInputButtons(); updateInputButtons();