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 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 getActionControllerBindingName (int action) const = 0;
virtual bool actionIsActive(int action) const = 0;
@ -64,9 +64,9 @@ namespace MWBase
virtual int getMouseMoveY() const = 0;
///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
virtual std::vector<int> getActionControllerSorting() = 0;
virtual const std::initializer_list<int>& getActionControllerSorting() = 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)
virtual void enableDetectingBindingMode (int action, bool keyboard) = 0;

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

@ -421,7 +421,7 @@ namespace MWInput
}
}
std::string BindingsManager::getActionDescription(int action)
std::string_view BindingsManager::getActionDescription(int action)
{
switch (action)
{
@ -506,7 +506,7 @@ namespace MWInput
case A_TogglePostProcessorHUD:
return "#{SettingsMenu:TogglePostProcessorHUD}";
default:
return std::string(); // not configurable
return {}; // not configurable
}
}
@ -557,9 +557,9 @@ namespace MWInput
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_Run, A_AlwaysRun, A_Sneak, A_Activate, A_Use, A_ToggleWeapon, A_ToggleSpell,
@ -572,9 +572,9 @@ namespace MWInput
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_AutoMove, A_Jump, A_Inventory, A_Journal, A_Rest, A_QuickSave, A_QuickLoad, A_ToggleHUD,

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

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

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

@ -254,11 +254,11 @@ namespace MWScript
std::string InterpreterContext::getActionBinding(std::string_view targetAction) const
{
MWBase::InputManager* input = MWBase::Environment::get().getInputManager();
std::vector<int> actions = input->getActionKeySorting ();
const auto& actions = input->getActionKeySorting();
for (const int action : actions)
{
std::string desc = input->getActionDescription (action);
if(desc == "")
std::string_view desc = input->getActionDescription(action);
if(desc.empty())
continue;
if(desc == targetAction)
@ -334,14 +334,14 @@ namespace MWScript
std::string InterpreterContext::getPCRace() const
{
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;
}
std::string InterpreterContext::getPCClass() const
{
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;
}
@ -369,7 +369,7 @@ namespace MWScript
const ESM::Faction *faction = store.get<ESM::Faction>().find(factionId);
if(rank < 0 || rank > 9) // there are only 10 ranks
return "";
return {};
return faction->mRanks[rank];
}
@ -399,7 +399,7 @@ namespace MWScript
const ESM::Faction *faction = store.get<ESM::Faction>().find(factionId);
if(rank < 0)
return "";
return {};
return faction->mRanks[rank];
}
@ -487,7 +487,7 @@ namespace MWScript
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)

Loading…
Cancel
Save