Avoid copying in InputManager

pull/3228/head
Evil Eye 2 years ago
parent 64a72fcb16
commit 4eb6c48285

@ -52,7 +52,7 @@ namespace MWBase
virtual void toggleControlSwitch(std::string_view sw, bool value) = 0; virtual void toggleControlSwitch(std::string_view sw, bool value) = 0;
virtual bool getControlSwitch(std::string_view sw) = 0; virtual bool getControlSwitch(std::string_view sw) = 0;
virtual std::string getActionDescription (int action) const = 0; virtual std::string_view getActionDescription(int action) const = 0;
virtual std::string getActionKeyBindingName (int action) const = 0; virtual std::string getActionKeyBindingName (int action) const = 0;
virtual std::string getActionControllerBindingName (int action) const = 0; virtual std::string getActionControllerBindingName (int action) const = 0;
virtual bool actionIsActive(int action) const = 0; virtual bool actionIsActive(int action) const = 0;
@ -64,9 +64,9 @@ namespace MWBase
virtual int getMouseMoveY() const = 0; virtual int getMouseMoveY() const = 0;
///Actions available for binding to keyboard buttons ///Actions available for binding to keyboard buttons
virtual std::vector<int> getActionKeySorting() = 0; virtual const std::initializer_list<int>& getActionKeySorting() = 0;
///Actions available for binding to controller buttons ///Actions available for binding to controller buttons
virtual std::vector<int> getActionControllerSorting() = 0; virtual const std::initializer_list<int>& getActionControllerSorting() = 0;
virtual int getNumActions() = 0; virtual int getNumActions() = 0;
///If keyboard is true, only pay attention to keyboard events. If false, only pay attention to controller events (excluding esc) ///If keyboard is true, only pay attention to keyboard events. If false, only pay attention to controller events (excluding esc)
virtual void enableDetectingBindingMode (int action, bool keyboard) = 0; virtual void enableDetectingBindingMode (int action, bool keyboard) = 0;

@ -700,23 +700,20 @@ namespace MWGui
MyGUI::Gui::getInstance().destroyWidget(mControlsBox->getChildAt(0)); MyGUI::Gui::getInstance().destroyWidget(mControlsBox->getChildAt(0));
MWBase::Environment::get().getWindowManager()->removeStaticMessageBox(); MWBase::Environment::get().getWindowManager()->removeStaticMessageBox();
std::vector<int> actions; const auto inputManager = MWBase::Environment::get().getInputManager();
if(mKeyboardMode) const auto& actions = mKeyboardMode ? inputManager->getActionKeySorting() : inputManager->getActionControllerSorting();
actions = MWBase::Environment::get().getInputManager()->getActionKeySorting();
else
actions = MWBase::Environment::get().getInputManager()->getActionControllerSorting();
for (const int& action : actions) for (const int& action : actions)
{ {
std::string desc = MWBase::Environment::get().getInputManager()->getActionDescription (action); std::string desc{inputManager->getActionDescription(action)};
if (desc == "") if (desc.empty())
continue; continue;
std::string binding; std::string binding;
if(mKeyboardMode) if(mKeyboardMode)
binding = MWBase::Environment::get().getInputManager()->getActionKeyBindingName(action); binding = inputManager->getActionKeyBindingName(action);
else else
binding = MWBase::Environment::get().getInputManager()->getActionControllerBindingName(action); binding = inputManager->getActionControllerBindingName(action);
Gui::SharedStateButton* leftText = mControlsBox->createWidget<Gui::SharedStateButton>("SandTextButton", MyGUI::IntCoord(), MyGUI::Align::Default); Gui::SharedStateButton* leftText = mControlsBox->createWidget<Gui::SharedStateButton>("SandTextButton", MyGUI::IntCoord(), MyGUI::Align::Default);
leftText->setCaptionWithReplacing(desc); leftText->setCaptionWithReplacing(desc);

@ -421,7 +421,7 @@ namespace MWInput
} }
} }
std::string BindingsManager::getActionDescription(int action) std::string_view BindingsManager::getActionDescription(int action)
{ {
switch (action) switch (action)
{ {
@ -506,7 +506,7 @@ namespace MWInput
case A_TogglePostProcessorHUD: case A_TogglePostProcessorHUD:
return "#{SettingsMenu:TogglePostProcessorHUD}"; return "#{SettingsMenu:TogglePostProcessorHUD}";
default: default:
return std::string(); // not configurable return {}; // not configurable
} }
} }
@ -557,9 +557,9 @@ namespace MWInput
return "#{sNone}"; return "#{sNone}";
} }
std::vector<int> BindingsManager::getActionKeySorting() const std::initializer_list<int>& BindingsManager::getActionKeySorting()
{ {
static const std::vector<int> actions static const std::initializer_list<int> actions
{ {
A_MoveForward, A_MoveBackward, A_MoveLeft, A_MoveRight, A_TogglePOV, A_ZoomIn, A_ZoomOut, A_MoveForward, A_MoveBackward, A_MoveLeft, A_MoveRight, A_TogglePOV, A_ZoomIn, A_ZoomOut,
A_Run, A_AlwaysRun, A_Sneak, A_Activate, A_Use, A_ToggleWeapon, A_ToggleSpell, A_Run, A_AlwaysRun, A_Sneak, A_Activate, A_Use, A_ToggleWeapon, A_ToggleSpell,
@ -572,9 +572,9 @@ namespace MWInput
return actions; return actions;
} }
std::vector<int> BindingsManager::getActionControllerSorting() const std::initializer_list<int>& BindingsManager::getActionControllerSorting()
{ {
static const std::vector<int> actions static const std::initializer_list<int> actions
{ {
A_TogglePOV, A_ZoomIn, A_ZoomOut, A_Sneak, A_Activate, A_Use, A_ToggleWeapon, A_ToggleSpell, A_TogglePOV, A_ZoomIn, A_ZoomOut, A_Sneak, A_Activate, A_Use, A_ToggleWeapon, A_ToggleSpell,
A_AutoMove, A_Jump, A_Inventory, A_Journal, A_Rest, A_QuickSave, A_QuickLoad, A_ToggleHUD, A_AutoMove, A_Jump, A_Inventory, A_Journal, A_Rest, A_QuickSave, A_QuickLoad, A_ToggleHUD,

@ -19,11 +19,11 @@ namespace MWInput
virtual ~BindingsManager(); virtual ~BindingsManager();
std::string getActionDescription (int action); std::string_view getActionDescription(int action);
std::string getActionKeyBindingName (int action); std::string getActionKeyBindingName (int action);
std::string getActionControllerBindingName (int action); std::string getActionControllerBindingName (int action);
std::vector<int> getActionKeySorting(); const std::initializer_list<int>& getActionKeySorting();
std::vector<int> getActionControllerSorting(); const std::initializer_list<int>& getActionControllerSorting();
void enableDetectingBindingMode (int action, bool keyboard); void enableDetectingBindingMode (int action, bool keyboard);
bool isDetectingBindingState() const; bool isDetectingBindingState() const;

@ -146,7 +146,7 @@ namespace MWInput
return mActionManager->getIdleTime() > 0.5; return mActionManager->getIdleTime() > 0.5;
} }
std::string InputManager::getActionDescription(int action) const std::string_view InputManager::getActionDescription(int action) const
{ {
return mBindingsManager->getActionDescription(action); return mBindingsManager->getActionDescription(action);
} }
@ -191,12 +191,12 @@ namespace MWInput
return mMouseManager->getMouseMoveY(); return mMouseManager->getMouseMoveY();
} }
std::vector<int> InputManager::getActionKeySorting() const std::initializer_list<int>& InputManager::getActionKeySorting()
{ {
return mBindingsManager->getActionKeySorting(); return mBindingsManager->getActionKeySorting();
} }
std::vector<int> InputManager::getActionControllerSorting() const std::initializer_list<int>& InputManager::getActionControllerSorting()
{ {
return mBindingsManager->getActionControllerSorting(); return mBindingsManager->getActionControllerSorting();
} }

@ -76,7 +76,7 @@ namespace MWInput
void toggleControlSwitch(std::string_view sw, bool value) override; void toggleControlSwitch(std::string_view sw, bool value) override;
bool getControlSwitch(std::string_view sw) override; bool getControlSwitch(std::string_view sw) override;
std::string getActionDescription (int action) const override; std::string_view getActionDescription(int action) const override;
std::string getActionKeyBindingName (int action) const override; std::string getActionKeyBindingName (int action) const override;
std::string getActionControllerBindingName (int action) const override; std::string getActionControllerBindingName (int action) const override;
bool actionIsActive(int action) const override; bool actionIsActive(int action) const override;
@ -88,8 +88,8 @@ namespace MWInput
int getMouseMoveY() const override; int getMouseMoveY() const override;
int getNumActions() override { return A_Last; } int getNumActions() override { return A_Last; }
std::vector<int> getActionKeySorting() override; const std::initializer_list<int>& getActionKeySorting() override;
std::vector<int> getActionControllerSorting() override; const std::initializer_list<int>& getActionControllerSorting() override;
void enableDetectingBindingMode (int action, bool keyboard) override; void enableDetectingBindingMode (int action, bool keyboard) override;
void resetToDefaultKeyBindings() override; void resetToDefaultKeyBindings() override;
void resetToDefaultControllerBindings() override; void resetToDefaultControllerBindings() override;

@ -254,11 +254,11 @@ namespace MWScript
std::string InterpreterContext::getActionBinding(std::string_view targetAction) const std::string InterpreterContext::getActionBinding(std::string_view targetAction) const
{ {
MWBase::InputManager* input = MWBase::Environment::get().getInputManager(); MWBase::InputManager* input = MWBase::Environment::get().getInputManager();
std::vector<int> actions = input->getActionKeySorting (); const auto& actions = input->getActionKeySorting();
for (const int action : actions) for (const int action : actions)
{ {
std::string desc = input->getActionDescription (action); std::string_view desc = input->getActionDescription(action);
if(desc == "") if(desc.empty())
continue; continue;
if(desc == targetAction) if(desc == targetAction)
@ -334,14 +334,14 @@ namespace MWScript
std::string InterpreterContext::getPCRace() const std::string InterpreterContext::getPCRace() const
{ {
MWBase::World *world = MWBase::Environment::get().getWorld(); MWBase::World *world = MWBase::Environment::get().getWorld();
std::string race = world->getPlayerPtr().get<ESM::NPC>()->mBase->mRace; const std::string& race = world->getPlayerPtr().get<ESM::NPC>()->mBase->mRace;
return world->getStore().get<ESM::Race>().find(race)->mName; return world->getStore().get<ESM::Race>().find(race)->mName;
} }
std::string InterpreterContext::getPCClass() const std::string InterpreterContext::getPCClass() const
{ {
MWBase::World *world = MWBase::Environment::get().getWorld(); MWBase::World *world = MWBase::Environment::get().getWorld();
std::string class_ = world->getPlayerPtr().get<ESM::NPC>()->mBase->mClass; const std::string& class_ = world->getPlayerPtr().get<ESM::NPC>()->mBase->mClass;
return world->getStore().get<ESM::Class>().find(class_)->mName; return world->getStore().get<ESM::Class>().find(class_)->mName;
} }
@ -369,7 +369,7 @@ namespace MWScript
const ESM::Faction *faction = store.get<ESM::Faction>().find(factionId); const ESM::Faction *faction = store.get<ESM::Faction>().find(factionId);
if(rank < 0 || rank > 9) // there are only 10 ranks if(rank < 0 || rank > 9) // there are only 10 ranks
return ""; return {};
return faction->mRanks[rank]; return faction->mRanks[rank];
} }
@ -399,7 +399,7 @@ namespace MWScript
const ESM::Faction *faction = store.get<ESM::Faction>().find(factionId); const ESM::Faction *faction = store.get<ESM::Faction>().find(factionId);
if(rank < 0) if(rank < 0)
return ""; return {};
return faction->mRanks[rank]; return faction->mRanks[rank];
} }
@ -487,7 +487,7 @@ namespace MWScript
MWWorld::Ptr InterpreterContext::getReference(bool required) const MWWorld::Ptr InterpreterContext::getReference(bool required) const
{ {
return getReferenceImp ("", true, required); return getReferenceImp({}, true, required);
} }
void InterpreterContext::updatePtr(const MWWorld::Ptr& base, const MWWorld::Ptr& updated) void InterpreterContext::updatePtr(const MWWorld::Ptr& base, const MWWorld::Ptr& updated)

Loading…
Cancel
Save