From 4eb6c48285e30ca5306f63ab622bd5ae3a6085b6 Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Fri, 12 Aug 2022 18:42:12 +0200 Subject: [PATCH 1/5] Avoid copying in InputManager --- apps/openmw/mwbase/inputmanager.hpp | 6 +++--- apps/openmw/mwgui/settingswindow.cpp | 15 ++++++--------- apps/openmw/mwinput/bindingsmanager.cpp | 12 ++++++------ apps/openmw/mwinput/bindingsmanager.hpp | 6 +++--- apps/openmw/mwinput/inputmanagerimp.cpp | 6 +++--- apps/openmw/mwinput/inputmanagerimp.hpp | 6 +++--- apps/openmw/mwscript/interpretercontext.cpp | 16 ++++++++-------- 7 files changed, 32 insertions(+), 35 deletions(-) diff --git a/apps/openmw/mwbase/inputmanager.hpp b/apps/openmw/mwbase/inputmanager.hpp index e22d7f00bc..14679ffd25 100644 --- a/apps/openmw/mwbase/inputmanager.hpp +++ b/apps/openmw/mwbase/inputmanager.hpp @@ -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 getActionKeySorting() = 0; + virtual const std::initializer_list& getActionKeySorting() = 0; ///Actions available for binding to controller buttons - virtual std::vector getActionControllerSorting() = 0; + virtual const std::initializer_list& 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; diff --git a/apps/openmw/mwgui/settingswindow.cpp b/apps/openmw/mwgui/settingswindow.cpp index f83d3a562f..d2429dfcf0 100644 --- a/apps/openmw/mwgui/settingswindow.cpp +++ b/apps/openmw/mwgui/settingswindow.cpp @@ -700,23 +700,20 @@ namespace MWGui MyGUI::Gui::getInstance().destroyWidget(mControlsBox->getChildAt(0)); MWBase::Environment::get().getWindowManager()->removeStaticMessageBox(); - std::vector 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("SandTextButton", MyGUI::IntCoord(), MyGUI::Align::Default); leftText->setCaptionWithReplacing(desc); diff --git a/apps/openmw/mwinput/bindingsmanager.cpp b/apps/openmw/mwinput/bindingsmanager.cpp index b3e3590125..a1b4845250 100644 --- a/apps/openmw/mwinput/bindingsmanager.cpp +++ b/apps/openmw/mwinput/bindingsmanager.cpp @@ -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 BindingsManager::getActionKeySorting() + const std::initializer_list& BindingsManager::getActionKeySorting() { - static const std::vector actions + static const std::initializer_list 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 BindingsManager::getActionControllerSorting() + const std::initializer_list& BindingsManager::getActionControllerSorting() { - static const std::vector actions + static const std::initializer_list 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, diff --git a/apps/openmw/mwinput/bindingsmanager.hpp b/apps/openmw/mwinput/bindingsmanager.hpp index 668cccd4ca..3808a21dfd 100644 --- a/apps/openmw/mwinput/bindingsmanager.hpp +++ b/apps/openmw/mwinput/bindingsmanager.hpp @@ -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 getActionKeySorting(); - std::vector getActionControllerSorting(); + const std::initializer_list& getActionKeySorting(); + const std::initializer_list& getActionControllerSorting(); void enableDetectingBindingMode (int action, bool keyboard); bool isDetectingBindingState() const; diff --git a/apps/openmw/mwinput/inputmanagerimp.cpp b/apps/openmw/mwinput/inputmanagerimp.cpp index abc66de70d..9a7b84722a 100644 --- a/apps/openmw/mwinput/inputmanagerimp.cpp +++ b/apps/openmw/mwinput/inputmanagerimp.cpp @@ -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 InputManager::getActionKeySorting() + const std::initializer_list& InputManager::getActionKeySorting() { return mBindingsManager->getActionKeySorting(); } - std::vector InputManager::getActionControllerSorting() + const std::initializer_list& InputManager::getActionControllerSorting() { return mBindingsManager->getActionControllerSorting(); } diff --git a/apps/openmw/mwinput/inputmanagerimp.hpp b/apps/openmw/mwinput/inputmanagerimp.hpp index 7b3029e11a..dbc980e446 100644 --- a/apps/openmw/mwinput/inputmanagerimp.hpp +++ b/apps/openmw/mwinput/inputmanagerimp.hpp @@ -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 getActionKeySorting() override; - std::vector getActionControllerSorting() override; + const std::initializer_list& getActionKeySorting() override; + const std::initializer_list& getActionControllerSorting() override; void enableDetectingBindingMode (int action, bool keyboard) override; void resetToDefaultKeyBindings() override; void resetToDefaultControllerBindings() override; diff --git a/apps/openmw/mwscript/interpretercontext.cpp b/apps/openmw/mwscript/interpretercontext.cpp index 78e41d9aeb..535697df89 100644 --- a/apps/openmw/mwscript/interpretercontext.cpp +++ b/apps/openmw/mwscript/interpretercontext.cpp @@ -254,11 +254,11 @@ namespace MWScript std::string InterpreterContext::getActionBinding(std::string_view targetAction) const { MWBase::InputManager* input = MWBase::Environment::get().getInputManager(); - std::vector 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()->mBase->mRace; + const std::string& race = world->getPlayerPtr().get()->mBase->mRace; return world->getStore().get().find(race)->mName; } std::string InterpreterContext::getPCClass() const { MWBase::World *world = MWBase::Environment::get().getWorld(); - std::string class_ = world->getPlayerPtr().get()->mBase->mClass; + const std::string& class_ = world->getPlayerPtr().get()->mBase->mClass; return world->getStore().get().find(class_)->mName; } @@ -369,7 +369,7 @@ namespace MWScript const ESM::Faction *faction = store.get().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().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) From 51938f9ef7d3e5a140142d3ceee2372bb3a429b7 Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Fri, 12 Aug 2022 19:42:35 +0200 Subject: [PATCH 2/5] Use string_view in Interpreter::Context --- apps/openmw/mwbase/world.hpp | 4 +- apps/openmw/mwdialogue/filter.cpp | 4 +- apps/openmw/mwgui/windowmanagerimp.cpp | 2 +- apps/openmw/mwscript/cellextensions.cpp | 7 +- apps/openmw/mwscript/globalscripts.cpp | 6 +- apps/openmw/mwscript/globalscripts.hpp | 3 +- apps/openmw/mwscript/interpretercontext.cpp | 89 ++++++++----------- apps/openmw/mwscript/interpretercontext.hpp | 34 ++++--- apps/openmw/mwworld/worldimp.cpp | 4 +- apps/openmw/mwworld/worldimp.hpp | 4 +- .../openmw_test_suite/mwscript/test_utils.hpp | 24 ++--- components/interpreter/context.hpp | 24 ++--- 12 files changed, 93 insertions(+), 112 deletions(-) diff --git a/apps/openmw/mwbase/world.hpp b/apps/openmw/mwbase/world.hpp index bae14e4a8e..437a048f5a 100644 --- a/apps/openmw/mwbase/world.hpp +++ b/apps/openmw/mwbase/world.hpp @@ -190,12 +190,12 @@ namespace MWBase virtual char getGlobalVariableType(std::string_view name) const = 0; ///< Return ' ', if there is no global variable with this name. - virtual std::string getCellName (const MWWorld::CellStore *cell = nullptr) const = 0; + virtual std::string_view getCellName(const MWWorld::CellStore* cell = nullptr) const = 0; ///< Return name of the cell. /// /// \note If cell==0, the cell the player is currently in will be used instead to /// generate a name. - virtual std::string getCellName(const ESM::Cell* cell) const = 0; + virtual std::string_view getCellName(const ESM::Cell* cell) const = 0; virtual void removeRefScript (MWWorld::RefData *ref) = 0; //< Remove the script attached to ref from mLocalScripts diff --git a/apps/openmw/mwdialogue/filter.cpp b/apps/openmw/mwdialogue/filter.cpp index 516cfff767..20092f936c 100644 --- a/apps/openmw/mwdialogue/filter.cpp +++ b/apps/openmw/mwdialogue/filter.cpp @@ -138,7 +138,7 @@ bool MWDialogue::Filter::testPlayer (const ESM::DialInfo& info) const if (!info.mCell.empty()) { // supports partial matches, just like getPcCell - const std::string& playerCell = MWBase::Environment::get().getWorld()->getCellName(player.getCell()); + std::string_view playerCell = MWBase::Environment::get().getWorld()->getCellName(player.getCell()); bool match = playerCell.length()>=info.mCell.length() && Misc::StringUtils::ciEqual(playerCell.substr (0, info.mCell.length()), info.mCell); if (!match) @@ -485,7 +485,7 @@ bool MWDialogue::Filter::getSelectStructBoolean (const SelectWrapper& select) co case SelectWrapper::Function_NotCell: { - const std::string& actorCell = MWBase::Environment::get().getWorld()->getCellName(mActor.getCell()); + std::string_view actorCell = MWBase::Environment::get().getWorld()->getCellName(mActor.getCell()); return !(actorCell.length() >= select.getName().length() && Misc::StringUtils::ciEqual(actorCell.substr(0, select.getName().length()), select.getName())); } diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index e8b92eaae6..77bc0d7713 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -917,7 +917,7 @@ namespace MWGui { mMap->requestMapRender(cell); - std::string name = MWBase::Environment::get().getWorld()->getCellName (cell); + std::string name{MWBase::Environment::get().getWorld()->getCellName(cell)}; mMap->setCellName( name ); mHud->setCellName( name ); diff --git a/apps/openmw/mwscript/cellextensions.cpp b/apps/openmw/mwscript/cellextensions.cpp index 0419d37962..a8d918e6cb 100644 --- a/apps/openmw/mwscript/cellextensions.cpp +++ b/apps/openmw/mwscript/cellextensions.cpp @@ -170,11 +170,8 @@ namespace MWScript } const MWWorld::CellStore *cell = MWMechanics::getPlayer().getCell(); - std::string current = MWBase::Environment::get().getWorld()->getCellName(cell); - Misc::StringUtils::lowerCaseInPlace(current); - - bool match = current.length()>=name.length() && - current.substr (0, name.length())==name; + std::string_view current = MWBase::Environment::get().getWorld()->getCellName(cell); + bool match = Misc::StringUtils::ciCompareLen(name, current, name.length()) == 0; runtime.push (match ? 1 : 0); } diff --git a/apps/openmw/mwscript/globalscripts.cpp b/apps/openmw/mwscript/globalscripts.cpp index 0739c49f1b..26cef4f54f 100644 --- a/apps/openmw/mwscript/globalscripts.cpp +++ b/apps/openmw/mwscript/globalscripts.cpp @@ -95,14 +95,14 @@ namespace struct IdGettingVisitor { - std::string operator()(const MWWorld::Ptr& ptr) const + std::string_view operator()(const MWWorld::Ptr& ptr) const { if(ptr.isEmpty()) return {}; return ptr.mRef->mRef.getRefId(); } - std::string operator()(const std::pair& pair) const + std::string_view operator()(const std::pair& pair) const { return pair.second; } @@ -125,7 +125,7 @@ namespace MWScript return ptr; } - std::string GlobalScriptDesc::getId() const + std::string_view GlobalScriptDesc::getId() const { return std::visit(IdGettingVisitor {}, mTarget); } diff --git a/apps/openmw/mwscript/globalscripts.hpp b/apps/openmw/mwscript/globalscripts.hpp index 556f815238..92272c05bd 100644 --- a/apps/openmw/mwscript/globalscripts.hpp +++ b/apps/openmw/mwscript/globalscripts.hpp @@ -2,6 +2,7 @@ #define GAME_SCRIPT_GLOBALSCRIPTS_H #include +#include #include #include #include @@ -44,7 +45,7 @@ namespace MWScript MWWorld::Ptr getPtr(); // Resolves mTarget to a Ptr and caches the (potentially empty) result - std::string getId() const; // Returns the target's ID -- if any + std::string_view getId() const; // Returns the target's ID -- if any }; class GlobalScripts diff --git a/apps/openmw/mwscript/interpretercontext.cpp b/apps/openmw/mwscript/interpretercontext.cpp index 535697df89..6490d07d05 100644 --- a/apps/openmw/mwscript/interpretercontext.cpp +++ b/apps/openmw/mwscript/interpretercontext.cpp @@ -26,8 +26,7 @@ namespace MWScript { - const MWWorld::Ptr InterpreterContext::getReferenceImp ( - const std::string& id, bool activeOnly, bool doThrow) const + const MWWorld::Ptr InterpreterContext::getReferenceImp(std::string_view id, bool activeOnly, bool doThrow) const { if (!id.empty()) { @@ -45,7 +44,7 @@ namespace MWScript } } - const Locals& InterpreterContext::getMemberLocals (std::string& id, bool global) + const Locals& InterpreterContext::getMemberLocals(std::string_view& id, bool global) const { if (global) @@ -66,7 +65,7 @@ namespace MWScript } } - Locals& InterpreterContext::getMemberLocals (std::string& id, bool global) + Locals& InterpreterContext::getMemberLocals(std::string_view& id, bool global) { if (global) { @@ -88,8 +87,7 @@ namespace MWScript MissingImplicitRefError::MissingImplicitRefError() : std::runtime_error("no implicit reference") {} - int InterpreterContext::findLocalVariableIndex (const std::string& scriptId, - std::string_view name, char type) const + int InterpreterContext::findLocalVariableIndex(std::string_view scriptId, std::string_view name, char type) const { int index = MWBase::Environment::get().getScriptManager()->getLocals (scriptId). searchIndex (type, name); @@ -130,7 +128,7 @@ namespace MWScript mGlobalScriptDesc = globalScriptDesc; } - std::string InterpreterContext::getTarget() const + std::string_view InterpreterContext::getTarget() const { if(!mReference.isEmpty()) return mReference.mRef->mRef.getRefId(); @@ -237,7 +235,7 @@ namespace MWScript MWBase::Environment::get().getWorld()->getStore().get(); std::vector ids; - for (auto& globalVariable : globals) + for (const auto& globalVariable : globals) { ids.emplace_back(globalVariable.mId); } @@ -273,7 +271,7 @@ namespace MWScript return "None"; } - std::string InterpreterContext::getActorName() const + std::string_view InterpreterContext::getActorName() const { const MWWorld::Ptr& ptr = getReferenceImp(); if (ptr.getClass().isNpc()) @@ -286,28 +284,28 @@ namespace MWScript return creature->mName; } - std::string InterpreterContext::getNPCRace() const + std::string_view InterpreterContext::getNPCRace() const { - ESM::NPC npc = *getReferenceImp().get()->mBase; - const ESM::Race* race = MWBase::Environment::get().getWorld()->getStore().get().find(npc.mRace); + const ESM::NPC* npc = getReferenceImp().get()->mBase; + const ESM::Race* race = MWBase::Environment::get().getWorld()->getStore().get().find(npc->mRace); return race->mName; } - std::string InterpreterContext::getNPCClass() const + std::string_view InterpreterContext::getNPCClass() const { - ESM::NPC npc = *getReferenceImp().get()->mBase; - const ESM::Class* class_ = MWBase::Environment::get().getWorld()->getStore().get().find(npc.mClass); + const ESM::NPC* npc = getReferenceImp().get()->mBase; + const ESM::Class* class_ = MWBase::Environment::get().getWorld()->getStore().get().find(npc->mClass); return class_->mName; } - std::string InterpreterContext::getNPCFaction() const + std::string_view InterpreterContext::getNPCFaction() const { - ESM::NPC npc = *getReferenceImp().get()->mBase; - const ESM::Faction* faction = MWBase::Environment::get().getWorld()->getStore().get().find(npc.mFaction); + const ESM::NPC* npc = getReferenceImp().get()->mBase; + const ESM::Faction* faction = MWBase::Environment::get().getWorld()->getStore().get().find(npc->mFaction); return faction->mName; } - std::string InterpreterContext::getNPCRank() const + std::string_view InterpreterContext::getNPCRank() const { const MWWorld::Ptr& ptr = getReferenceImp(); std::string_view faction = ptr.getClass().getPrimaryFaction(ptr); @@ -324,28 +322,27 @@ namespace MWScript return fact->mRanks[rank]; } - std::string InterpreterContext::getPCName() const + std::string_view InterpreterContext::getPCName() const { MWBase::World *world = MWBase::Environment::get().getWorld(); - ESM::NPC player = *world->getPlayerPtr().get()->mBase; - return player.mName; + return world->getPlayerPtr().get()->mBase->mName; } - std::string InterpreterContext::getPCRace() const + std::string_view InterpreterContext::getPCRace() const { MWBase::World *world = MWBase::Environment::get().getWorld(); const std::string& race = world->getPlayerPtr().get()->mBase->mRace; return world->getStore().get().find(race)->mName; } - std::string InterpreterContext::getPCClass() const + std::string_view InterpreterContext::getPCClass() const { MWBase::World *world = MWBase::Environment::get().getWorld(); const std::string& class_ = world->getPlayerPtr().get()->mBase->mClass; return world->getStore().get().find(class_)->mName; } - std::string InterpreterContext::getPCRank() const + std::string_view InterpreterContext::getPCRank() const { MWBase::World *world = MWBase::Environment::get().getWorld(); MWWorld::Ptr player = world->getPlayerPtr(); @@ -374,7 +371,7 @@ namespace MWScript return faction->mRanks[rank]; } - std::string InterpreterContext::getPCNextRank() const + std::string_view InterpreterContext::getPCNextRank() const { MWBase::World *world = MWBase::Environment::get().getWorld(); MWWorld::Ptr player = world->getPlayerPtr(); @@ -411,9 +408,9 @@ namespace MWScript return player.getClass().getNpcStats (player).getBounty(); } - std::string InterpreterContext::getCurrentCellName() const + std::string_view InterpreterContext::getCurrentCellName() const { - return MWBase::Environment::get().getWorld()->getCellName(); + return MWBase::Environment::get().getWorld()->getCellName(); } void InterpreterContext::executeActivation(const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) @@ -430,59 +427,47 @@ namespace MWScript int InterpreterContext::getMemberShort(std::string_view id, std::string_view name, bool global) const { - std::string scriptId (id); + const Locals& locals = getMemberLocals(id, global); - const Locals& locals = getMemberLocals (scriptId, global); - - return locals.mShorts[findLocalVariableIndex (scriptId, name, 's')]; + return locals.mShorts[findLocalVariableIndex(id, name, 's')]; } int InterpreterContext::getMemberLong(std::string_view id, std::string_view name, bool global) const { - std::string scriptId (id); - - const Locals& locals = getMemberLocals (scriptId, global); + const Locals& locals = getMemberLocals(id, global); - return locals.mLongs[findLocalVariableIndex (scriptId, name, 'l')]; + return locals.mLongs[findLocalVariableIndex(id, name, 'l')]; } float InterpreterContext::getMemberFloat(std::string_view id, std::string_view name, bool global) const { - std::string scriptId (id); - - const Locals& locals = getMemberLocals (scriptId, global); + const Locals& locals = getMemberLocals(id, global); - return locals.mFloats[findLocalVariableIndex (scriptId, name, 'f')]; + return locals.mFloats[findLocalVariableIndex(id, name, 'f')]; } void InterpreterContext::setMemberShort(std::string_view id, std::string_view name, int value, bool global) { - std::string scriptId (id); + Locals& locals = getMemberLocals(id, global); - Locals& locals = getMemberLocals (scriptId, global); - - locals.mShorts[findLocalVariableIndex (scriptId, name, 's')] = value; + locals.mShorts[findLocalVariableIndex(id, name, 's')] = value; } void InterpreterContext::setMemberLong(std::string_view id, std::string_view name, int value, bool global) { - std::string scriptId (id); - - Locals& locals = getMemberLocals (scriptId, global); + Locals& locals = getMemberLocals(id, global); - locals.mLongs[findLocalVariableIndex (scriptId, name, 'l')] = value; + locals.mLongs[findLocalVariableIndex(id, name, 'l')] = value; } void InterpreterContext::setMemberFloat(std::string_view id, std::string_view name, float value, bool global) { - std::string scriptId (id); - - Locals& locals = getMemberLocals (scriptId, global); + Locals& locals = getMemberLocals(id, global); - locals.mFloats[findLocalVariableIndex (scriptId, name, 'f')] = value; + locals.mFloats[findLocalVariableIndex(id, name, 'f')] = value; } MWWorld::Ptr InterpreterContext::getReference(bool required) const diff --git a/apps/openmw/mwscript/interpretercontext.hpp b/apps/openmw/mwscript/interpretercontext.hpp index b675e850d2..c53dd88ab3 100644 --- a/apps/openmw/mwscript/interpretercontext.hpp +++ b/apps/openmw/mwscript/interpretercontext.hpp @@ -28,18 +28,16 @@ namespace MWScript /// If \a id is empty, a reference the script is run from is returned or in case /// of a non-local script the reference derived from the target ID. - const MWWorld::Ptr getReferenceImp (const std::string& id = "", - bool activeOnly = false, bool doThrow=true) const; + const MWWorld::Ptr getReferenceImp(std::string_view id = {}, bool activeOnly = false, bool doThrow = true) const; - const Locals& getMemberLocals (std::string& id, bool global) const; + const Locals& getMemberLocals(std::string_view& id, bool global) const; ///< \a id is changed to the respective script ID, if \a id wasn't a script ID before - Locals& getMemberLocals (std::string& id, bool global); + Locals& getMemberLocals(std::string_view& id, bool global); ///< \a id is changed to the respective script ID, if \a id wasn't a script ID before /// Throws an exception if local variable can't be found. - int findLocalVariableIndex (const std::string& scriptId, std::string_view name, - char type) const; + int findLocalVariableIndex(std::string_view scriptId, std::string_view name, char type) const; public: InterpreterContext (std::shared_ptr globalScriptDesc); @@ -47,7 +45,7 @@ namespace MWScript InterpreterContext (MWScript::Locals *locals, const MWWorld::Ptr& reference); ///< The ownership of \a locals is not transferred. 0-pointer allowed. - std::string getTarget() const override; + std::string_view getTarget() const override; int getLocalShort (int index) const override; @@ -87,29 +85,29 @@ namespace MWScript std::string getActionBinding(std::string_view action) const override; - std::string getActorName() const override; + std::string_view getActorName() const override; - std::string getNPCRace() const override; + std::string_view getNPCRace() const override; - std::string getNPCClass() const override; + std::string_view getNPCClass() const override; - std::string getNPCFaction() const override; + std::string_view getNPCFaction() const override; - std::string getNPCRank() const override; + std::string_view getNPCRank() const override; - std::string getPCName() const override; + std::string_view getPCName() const override; - std::string getPCRace() const override; + std::string_view getPCRace() const override; - std::string getPCClass() const override; + std::string_view getPCClass() const override; - std::string getPCRank() const override; + std::string_view getPCRank() const override; - std::string getPCNextRank() const override; + std::string_view getPCNextRank() const override; int getPCBounty() const override; - std::string getCurrentCellName() const override; + std::string_view getCurrentCellName() const override; void executeActivation(const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor); ///< Execute the activation action for this ptr. If ptr is mActivated, mark activation as handled. diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index d6f8db9f24..14ac64f51f 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -670,14 +670,14 @@ namespace MWWorld return mCurrentDate->getMonthName(month); } - std::string World::getCellName (const MWWorld::CellStore *cell) const + std::string_view World::getCellName(const MWWorld::CellStore* cell) const { if (!cell) cell = mWorldScene->getCurrentCell(); return getCellName(cell->getCell()); } - std::string World::getCellName(const ESM::Cell* cell) const + std::string_view World::getCellName(const ESM::Cell* cell) const { if (cell) { diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index 68a0d73eb8..c48504cb05 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -280,12 +280,12 @@ namespace MWWorld char getGlobalVariableType(std::string_view name) const override; ///< Return ' ', if there is no global variable with this name. - std::string getCellName (const MWWorld::CellStore *cell = nullptr) const override; + std::string_view getCellName(const MWWorld::CellStore* cell = nullptr) const override; ///< Return name of the cell. /// /// \note If cell==0, the cell the player is currently in will be used instead to /// generate a name. - std::string getCellName(const ESM::Cell* cell) const override; + std::string_view getCellName(const ESM::Cell* cell) const override; void removeRefScript (MWWorld::RefData *ref) override; //< Remove the script attached to ref from mLocalScripts diff --git a/apps/openmw_test_suite/mwscript/test_utils.hpp b/apps/openmw_test_suite/mwscript/test_utils.hpp index 780a0ac519..67173810ca 100644 --- a/apps/openmw_test_suite/mwscript/test_utils.hpp +++ b/apps/openmw_test_suite/mwscript/test_utils.hpp @@ -140,7 +140,7 @@ namespace LocalVariables mLocals; std::map> mMembers; public: - std::string getTarget() const override { return {}; }; + std::string_view getTarget() const override { return {}; }; int getLocalShort(int index) const override { return mLocals.getShort(index); }; @@ -176,29 +176,29 @@ namespace std::string getActionBinding(std::string_view action) const override { return {}; }; - std::string getActorName() const override { return {}; }; + std::string_view getActorName() const override { return {}; }; - std::string getNPCRace() const override { return {}; }; + std::string_view getNPCRace() const override { return {}; }; - std::string getNPCClass() const override { return {}; }; + std::string_view getNPCClass() const override { return {}; }; - std::string getNPCFaction() const override { return {}; }; + std::string_view getNPCFaction() const override { return {}; }; - std::string getNPCRank() const override { return {}; }; + std::string_view getNPCRank() const override { return {}; }; - std::string getPCName() const override { return {}; }; + std::string_view getPCName() const override { return {}; }; - std::string getPCRace() const override { return {}; }; + std::string_view getPCRace() const override { return {}; }; - std::string getPCClass() const override { return {}; }; + std::string_view getPCClass() const override { return {}; }; - std::string getPCRank() const override { return {}; }; + std::string_view getPCRank() const override { return {}; }; - std::string getPCNextRank() const override { return {}; }; + std::string_view getPCNextRank() const override { return {}; }; int getPCBounty() const override { return {}; }; - std::string getCurrentCellName() const override { return {}; }; + std::string_view getCurrentCellName() const override { return {}; }; int getMemberShort(std::string_view id, std::string_view name, bool global) const override { diff --git a/components/interpreter/context.hpp b/components/interpreter/context.hpp index df97bcf232..7ff627be0a 100644 --- a/components/interpreter/context.hpp +++ b/components/interpreter/context.hpp @@ -13,7 +13,7 @@ namespace Interpreter virtual ~Context() {} - virtual std::string getTarget() const = 0; + virtual std::string_view getTarget() const = 0; virtual int getLocalShort (int index) const = 0; @@ -56,29 +56,29 @@ namespace Interpreter virtual std::string getActionBinding(std::string_view action) const = 0; - virtual std::string getActorName() const = 0; + virtual std::string_view getActorName() const = 0; - virtual std::string getNPCRace() const = 0; + virtual std::string_view getNPCRace() const = 0; - virtual std::string getNPCClass() const = 0; + virtual std::string_view getNPCClass() const = 0; - virtual std::string getNPCFaction() const = 0; + virtual std::string_view getNPCFaction() const = 0; - virtual std::string getNPCRank() const = 0; + virtual std::string_view getNPCRank() const = 0; - virtual std::string getPCName() const = 0; + virtual std::string_view getPCName() const = 0; - virtual std::string getPCRace() const = 0; + virtual std::string_view getPCRace() const = 0; - virtual std::string getPCClass() const = 0; + virtual std::string_view getPCClass() const = 0; - virtual std::string getPCRank() const = 0; + virtual std::string_view getPCRank() const = 0; - virtual std::string getPCNextRank() const = 0; + virtual std::string_view getPCNextRank() const = 0; virtual int getPCBounty() const = 0; - virtual std::string getCurrentCellName() const = 0; + virtual std::string_view getCurrentCellName() const = 0; virtual int getMemberShort(std::string_view id, std::string_view name, bool global) const = 0; From 2deec591cd8a42111e8196d33d93d3345ea1a2b6 Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Fri, 12 Aug 2022 20:56:50 +0200 Subject: [PATCH 3/5] Use heterogenous maps for scripts --- apps/openmw/mwbase/scriptmanager.hpp | 6 +++--- apps/openmw/mwgui/container.cpp | 2 +- apps/openmw/mwscript/globalscripts.cpp | 10 ++++------ apps/openmw/mwscript/globalscripts.hpp | 7 ++++--- apps/openmw/mwscript/scriptmanagerimp.cpp | 22 ++++++++++------------ apps/openmw/mwscript/scriptmanagerimp.hpp | 10 ++++------ 6 files changed, 26 insertions(+), 31 deletions(-) diff --git a/apps/openmw/mwbase/scriptmanager.hpp b/apps/openmw/mwbase/scriptmanager.hpp index 67b9593a20..be62722139 100644 --- a/apps/openmw/mwbase/scriptmanager.hpp +++ b/apps/openmw/mwbase/scriptmanager.hpp @@ -1,7 +1,7 @@ #ifndef GAME_MWBASE_SCRIPTMANAGER_H #define GAME_MWBASE_SCRIPTMANAGER_H -#include +#include namespace Interpreter { @@ -38,10 +38,10 @@ namespace MWBase virtual void clear() = 0; - virtual bool run (const std::string& name, Interpreter::Context& interpreterContext) = 0; + virtual bool run(std::string_view name, Interpreter::Context& interpreterContext) = 0; ///< Run the script with the given name (compile first, if not compiled yet) - virtual bool compile (const std::string& name) = 0; + virtual bool compile(std::string_view name) = 0; ///< Compile script with the given namen /// \return Success? diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 52fc04ddf2..f8bc3b57ba 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -261,7 +261,7 @@ namespace MWGui if (!script.empty() && MWBase::Environment::get().getWorld()->getScriptsEnabled()) { MWScript::InterpreterContext interpreterContext (&ptr.getRefData().getLocals(), ptr); - MWBase::Environment::get().getScriptManager()->run(std::string{script}, interpreterContext); + MWBase::Environment::get().getScriptManager()->run(script, interpreterContext); } // Clean up summoned creatures as well diff --git a/apps/openmw/mwscript/globalscripts.cpp b/apps/openmw/mwscript/globalscripts.cpp index 26cef4f54f..35a666234b 100644 --- a/apps/openmw/mwscript/globalscripts.cpp +++ b/apps/openmw/mwscript/globalscripts.cpp @@ -309,17 +309,16 @@ namespace MWScript Locals& GlobalScripts::getLocals(std::string_view name) { - std::string name2 = ::Misc::StringUtils::lowerCase (name); - auto iter = mScripts.find (name2); + auto iter = mScripts.find(name); if (iter==mScripts.end()) { - const ESM::Script *script = mStore.get().find(name2); + const ESM::Script *script = mStore.get().find(name); auto desc = std::make_shared(); desc->mLocals.configure (*script); - iter = mScripts.insert (std::make_pair (name2, desc)).first; + iter = mScripts.emplace(name, desc).first; } return iter->second->mLocals; @@ -327,8 +326,7 @@ namespace MWScript const Locals* GlobalScripts::getLocalsIfPresent(std::string_view name) const { - std::string name2 = ::Misc::StringUtils::lowerCase (name); - auto iter = mScripts.find (name2); + auto iter = mScripts.find(name); if (iter==mScripts.end()) return nullptr; return &iter->second->mLocals; diff --git a/apps/openmw/mwscript/globalscripts.hpp b/apps/openmw/mwscript/globalscripts.hpp index 92272c05bd..fa1602fc80 100644 --- a/apps/openmw/mwscript/globalscripts.hpp +++ b/apps/openmw/mwscript/globalscripts.hpp @@ -3,13 +3,14 @@ #include #include -#include +#include #include #include #include - #include +#include + #include "locals.hpp" #include "../mwworld/ptr.hpp" @@ -51,7 +52,7 @@ namespace MWScript class GlobalScripts { const MWWorld::ESMStore& mStore; - std::map > mScripts; + std::unordered_map, ::Misc::StringUtils::CiHash, ::Misc::StringUtils::CiEqual> mScripts; public: diff --git a/apps/openmw/mwscript/scriptmanagerimp.cpp b/apps/openmw/mwscript/scriptmanagerimp.cpp index a0ae49ad98..7a22cda8b1 100644 --- a/apps/openmw/mwscript/scriptmanagerimp.cpp +++ b/apps/openmw/mwscript/scriptmanagerimp.cpp @@ -39,14 +39,14 @@ namespace MWScript std::sort (mScriptBlacklist.begin(), mScriptBlacklist.end()); } - bool ScriptManager::compile (const std::string& name) + bool ScriptManager::compile(std::string_view name) { mParser.reset(); mErrorHandler.reset(); if (const ESM::Script *script = mStore.get().find (name)) { - mErrorHandler.setContext(name); + mErrorHandler.setContext(script->mId); bool Success = true; try @@ -89,10 +89,10 @@ namespace MWScript return false; } - bool ScriptManager::run (const std::string& name, Interpreter::Context& interpreterContext) + bool ScriptManager::run(std::string_view name, Interpreter::Context& interpreterContext) { // compile script - ScriptCollection::iterator iter = mScripts.find (name); + auto iter = mScripts.find(name); if (iter==mScripts.end()) { @@ -167,27 +167,25 @@ namespace MWScript const Compiler::Locals& ScriptManager::getLocals(std::string_view name) { - std::string name2 = Misc::StringUtils::lowerCase (name); - { - auto iter = mScripts.find (name2); + auto iter = mScripts.find(name); if (iter!=mScripts.end()) return iter->second.mLocals; } { - auto iter = mOtherLocals.find (name2); + auto iter = mOtherLocals.find(name); if (iter!=mOtherLocals.end()) return iter->second; } - if (const ESM::Script *script = mStore.get().search (name2)) + if (const ESM::Script* script = mStore.get().search(name)) { Compiler::Locals locals; - const Compiler::ContextOverride override(mErrorHandler, name2 + "[local variables]"); + const Compiler::ContextOverride override(mErrorHandler, std::string{name} + "[local variables]"); std::istringstream stream (script->mScriptText); Compiler::QuickFileParser parser (mErrorHandler, mCompilerContext, locals); @@ -207,12 +205,12 @@ namespace MWScript locals.clear(); } - auto iter = mOtherLocals.emplace(name2, locals).first; + auto iter = mOtherLocals.emplace(name, locals).first; return iter->second; } - throw std::logic_error("script " + name2 + " does not exist"); + throw std::logic_error("script " + std::string{name} + " does not exist"); } GlobalScripts& ScriptManager::getGlobalScripts() diff --git a/apps/openmw/mwscript/scriptmanagerimp.hpp b/apps/openmw/mwscript/scriptmanagerimp.hpp index d32d6e822c..4926f4b61f 100644 --- a/apps/openmw/mwscript/scriptmanagerimp.hpp +++ b/apps/openmw/mwscript/scriptmanagerimp.hpp @@ -53,11 +53,9 @@ namespace MWScript {} }; - typedef std::map ScriptCollection; - - ScriptCollection mScripts; + std::unordered_map mScripts; GlobalScripts mGlobalScripts; - std::map mOtherLocals; + std::unordered_map mOtherLocals; std::vector mScriptBlacklist; public: @@ -68,10 +66,10 @@ namespace MWScript void clear() override; - bool run (const std::string& name, Interpreter::Context& interpreterContext) override; + bool run(std::string_view name, Interpreter::Context& interpreterContext) override; ///< Run the script with the given name (compile first, if not compiled yet) - bool compile (const std::string& name) override; + bool compile(std::string_view name) override; ///< Compile script with the given namen /// \return Success? From 4e9335f10ae52602bec339d1c9234ec73d3c2a47 Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Sat, 13 Aug 2022 11:15:12 +0200 Subject: [PATCH 4/5] Fix include --- apps/openmw/mwscript/globalscripts.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwscript/globalscripts.hpp b/apps/openmw/mwscript/globalscripts.hpp index fa1602fc80..bd8d879031 100644 --- a/apps/openmw/mwscript/globalscripts.hpp +++ b/apps/openmw/mwscript/globalscripts.hpp @@ -3,8 +3,9 @@ #include #include -#include +#include #include +#include #include #include #include From eaa108d25ddc68790f98468641332f519a0a0356 Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Sun, 14 Aug 2022 14:39:58 +0200 Subject: [PATCH 5/5] Return string_view from SoundId methods --- apps/openmw/mwbase/windowmanager.hpp | 2 +- apps/openmw/mwclass/activator.cpp | 10 +++++----- apps/openmw/mwclass/activator.hpp | 4 ++-- apps/openmw/mwclass/apparatus.cpp | 8 ++++---- apps/openmw/mwclass/apparatus.hpp | 4 ++-- apps/openmw/mwclass/armor.cpp | 16 ++++++++-------- apps/openmw/mwclass/armor.hpp | 4 ++-- apps/openmw/mwclass/book.cpp | 8 ++++---- apps/openmw/mwclass/book.hpp | 4 ++-- apps/openmw/mwclass/clothing.cpp | 12 ++++++------ apps/openmw/mwclass/clothing.hpp | 4 ++-- apps/openmw/mwclass/creature.cpp | 10 +++++----- apps/openmw/mwclass/creature.hpp | 4 ++-- apps/openmw/mwclass/ingredient.cpp | 8 ++++---- apps/openmw/mwclass/ingredient.hpp | 4 ++-- apps/openmw/mwclass/light.cpp | 8 ++++---- apps/openmw/mwclass/light.hpp | 4 ++-- apps/openmw/mwclass/lockpick.cpp | 8 ++++---- apps/openmw/mwclass/lockpick.hpp | 4 ++-- apps/openmw/mwclass/misc.cpp | 12 ++++++------ apps/openmw/mwclass/misc.hpp | 4 ++-- apps/openmw/mwclass/npc.cpp | 18 +++++++++--------- apps/openmw/mwclass/npc.hpp | 2 +- apps/openmw/mwclass/potion.cpp | 8 ++++---- apps/openmw/mwclass/potion.hpp | 4 ++-- apps/openmw/mwclass/probe.cpp | 8 ++++---- apps/openmw/mwclass/probe.hpp | 4 ++-- apps/openmw/mwclass/repair.cpp | 8 ++++---- apps/openmw/mwclass/repair.hpp | 4 ++-- apps/openmw/mwclass/weapon.cpp | 10 ++++------ apps/openmw/mwclass/weapon.hpp | 4 ++-- apps/openmw/mwgui/alchemywindow.cpp | 2 +- apps/openmw/mwgui/container.cpp | 2 +- apps/openmw/mwgui/draganddrop.cpp | 4 ++-- apps/openmw/mwgui/inventorywindow.cpp | 4 ++-- apps/openmw/mwgui/tradewindow.cpp | 2 +- apps/openmw/mwgui/windowmanagerimp.cpp | 2 +- apps/openmw/mwgui/windowmanagerimp.hpp | 2 +- apps/openmw/mwmechanics/character.cpp | 10 +++++----- apps/openmw/mwrender/weaponanimation.cpp | 2 +- apps/openmw/mwworld/action.cpp | 2 +- apps/openmw/mwworld/action.hpp | 3 ++- apps/openmw/mwworld/class.cpp | 6 +++--- apps/openmw/mwworld/class.hpp | 6 +++--- components/esm3/loadweap.hpp | 9 ++++++++- 45 files changed, 137 insertions(+), 131 deletions(-) diff --git a/apps/openmw/mwbase/windowmanager.hpp b/apps/openmw/mwbase/windowmanager.hpp index 2d3be688b6..072b73b50b 100644 --- a/apps/openmw/mwbase/windowmanager.hpp +++ b/apps/openmw/mwbase/windowmanager.hpp @@ -335,7 +335,7 @@ namespace MWBase /// Cycle to next or previous weapon virtual void cycleWeapon(bool next) = 0; - virtual void playSound(const std::string& soundId, float volume = 1.f, float pitch = 1.f) = 0; + virtual void playSound(std::string_view soundId, float volume = 1.f, float pitch = 1.f) = 0; virtual void addCell(MWWorld::CellStore* cell) = 0; virtual void removeCell(MWWorld::CellStore* cell) = 0; diff --git a/apps/openmw/mwclass/activator.cpp b/apps/openmw/mwclass/activator.cpp index af9826b3f0..15fd472561 100644 --- a/apps/openmw/mwclass/activator.cpp +++ b/apps/openmw/mwclass/activator.cpp @@ -132,11 +132,11 @@ namespace MWClass return MWWorld::Ptr(cell.insert(ref), &cell); } - std::string Activator::getSoundIdFromSndGen(const MWWorld::Ptr &ptr, const std::string &name) const + std::string_view Activator::getSoundIdFromSndGen(const MWWorld::Ptr& ptr, std::string_view name) const { const std::string model = getModel(ptr); // Assume it's not empty, since we wouldn't have gotten the soundgen otherwise const MWWorld::ESMStore &store = MWBase::Environment::get().getWorld()->getStore(); - std::string creatureId; + std::string_view creatureId; const VFS::Manager* const vfs = MWBase::Environment::get().getResourceSystem()->getVFS(); for (const ESM::Creature &iter : store.get()) @@ -180,10 +180,10 @@ namespace MWClass return fallbacksounds[Misc::Rng::rollDice(fallbacksounds.size(), prng)]->mSound; } - return std::string(); + return {}; } - int Activator::getSndGenTypeFromName(const std::string &name) + int Activator::getSndGenTypeFromName(std::string_view name) { if (name == "left") return ESM::SoundGenerator::LeftFoot; @@ -202,6 +202,6 @@ namespace MWClass if (name == "land") return ESM::SoundGenerator::Land; - throw std::runtime_error(std::string("Unexpected soundgen type: ")+name); + throw std::runtime_error("Unexpected soundgen type: " + std::string(name)); } } diff --git a/apps/openmw/mwclass/activator.hpp b/apps/openmw/mwclass/activator.hpp index 6f2f8cc28b..824f510dfd 100644 --- a/apps/openmw/mwclass/activator.hpp +++ b/apps/openmw/mwclass/activator.hpp @@ -13,7 +13,7 @@ namespace MWClass MWWorld::Ptr copyToCellImpl(const MWWorld::ConstPtr &ptr, MWWorld::CellStore &cell) const override; - static int getSndGenTypeFromName(const std::string &name); + static int getSndGenTypeFromName(std::string_view name); public: void insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const override; @@ -45,7 +45,7 @@ namespace MWClass bool isActivator() const override; - std::string getSoundIdFromSndGen(const MWWorld::Ptr &ptr, const std::string &name) const override; + std::string_view getSoundIdFromSndGen(const MWWorld::Ptr& ptr, std::string_view name) const override; }; } diff --git a/apps/openmw/mwclass/apparatus.cpp b/apps/openmw/mwclass/apparatus.cpp index 421f15e67f..14fcea07db 100644 --- a/apps/openmw/mwclass/apparatus.cpp +++ b/apps/openmw/mwclass/apparatus.cpp @@ -67,14 +67,14 @@ namespace MWClass return ref->mBase->mData.mValue; } - std::string Apparatus::getUpSoundId (const MWWorld::ConstPtr& ptr) const + std::string_view Apparatus::getUpSoundId(const MWWorld::ConstPtr& ptr) const { - return std::string("Item Apparatus Up"); + return "Item Apparatus Up"; } - std::string Apparatus::getDownSoundId (const MWWorld::ConstPtr& ptr) const + std::string_view Apparatus::getDownSoundId(const MWWorld::ConstPtr& ptr) const { - return std::string("Item Apparatus Down"); + return "Item Apparatus Down"; } std::string Apparatus::getInventoryIcon (const MWWorld::ConstPtr& ptr) const diff --git a/apps/openmw/mwclass/apparatus.hpp b/apps/openmw/mwclass/apparatus.hpp index 89aadbf357..1f9e907b06 100644 --- a/apps/openmw/mwclass/apparatus.hpp +++ b/apps/openmw/mwclass/apparatus.hpp @@ -36,10 +36,10 @@ namespace MWClass MWGui::ToolTipInfo getToolTipInfo (const MWWorld::ConstPtr& ptr, int count) const override; ///< @return the content of the tool tip to be displayed. raises exception if the object has no tooltip. - std::string getUpSoundId (const MWWorld::ConstPtr& ptr) const override; + std::string_view getUpSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the pick up sound Id - std::string getDownSoundId (const MWWorld::ConstPtr& ptr) const override; + std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the put down sound Id std::string getInventoryIcon (const MWWorld::ConstPtr& ptr) const override; diff --git a/apps/openmw/mwclass/armor.cpp b/apps/openmw/mwclass/armor.cpp index 29e5ecb7fd..6ab731d0bd 100644 --- a/apps/openmw/mwclass/armor.cpp +++ b/apps/openmw/mwclass/armor.cpp @@ -161,26 +161,26 @@ namespace MWClass return ref->mBase->mData.mValue; } - std::string Armor::getUpSoundId (const MWWorld::ConstPtr& ptr) const + std::string_view Armor::getUpSoundId(const MWWorld::ConstPtr& ptr) const { int es = getEquipmentSkill(ptr); if (es == ESM::Skill::LightArmor) - return std::string("Item Armor Light Up"); + return "Item Armor Light Up"; else if (es == ESM::Skill::MediumArmor) - return std::string("Item Armor Medium Up"); + return "Item Armor Medium Up"; else - return std::string("Item Armor Heavy Up"); + return "Item Armor Heavy Up"; } - std::string Armor::getDownSoundId (const MWWorld::ConstPtr& ptr) const + std::string_view Armor::getDownSoundId(const MWWorld::ConstPtr& ptr) const { int es = getEquipmentSkill(ptr); if (es == ESM::Skill::LightArmor) - return std::string("Item Armor Light Down"); + return "Item Armor Light Down"; else if (es == ESM::Skill::MediumArmor) - return std::string("Item Armor Medium Down"); + return "Item Armor Medium Down"; else - return std::string("Item Armor Heavy Down"); + return "Item Armor Heavy Down"; } std::string Armor::getInventoryIcon (const MWWorld::ConstPtr& ptr) const diff --git a/apps/openmw/mwclass/armor.hpp b/apps/openmw/mwclass/armor.hpp index 468fd831b3..2c1bb965ae 100644 --- a/apps/openmw/mwclass/armor.hpp +++ b/apps/openmw/mwclass/armor.hpp @@ -50,10 +50,10 @@ namespace MWClass int getValue (const MWWorld::ConstPtr& ptr) const override; ///< Return trade value of the object. Throws an exception, if the object can't be traded. - std::string getUpSoundId (const MWWorld::ConstPtr& ptr) const override; + std::string_view getUpSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the pick up sound Id - std::string getDownSoundId (const MWWorld::ConstPtr& ptr) const override; + std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the put down sound Id std::string getInventoryIcon (const MWWorld::ConstPtr& ptr) const override; diff --git a/apps/openmw/mwclass/book.cpp b/apps/openmw/mwclass/book.cpp index 2fb328b62a..d87a1c5d19 100644 --- a/apps/openmw/mwclass/book.cpp +++ b/apps/openmw/mwclass/book.cpp @@ -84,14 +84,14 @@ namespace MWClass return ref->mBase->mData.mValue; } - std::string Book::getUpSoundId (const MWWorld::ConstPtr& ptr) const + std::string_view Book::getUpSoundId(const MWWorld::ConstPtr& ptr) const { - return std::string("Item Book Up"); + return "Item Book Up"; } - std::string Book::getDownSoundId (const MWWorld::ConstPtr& ptr) const + std::string_view Book::getDownSoundId(const MWWorld::ConstPtr& ptr) const { - return std::string("Item Book Down"); + return "Item Book Down"; } std::string Book::getInventoryIcon (const MWWorld::ConstPtr& ptr) const diff --git a/apps/openmw/mwclass/book.hpp b/apps/openmw/mwclass/book.hpp index 65af358268..5d028d6699 100644 --- a/apps/openmw/mwclass/book.hpp +++ b/apps/openmw/mwclass/book.hpp @@ -34,10 +34,10 @@ namespace MWClass int getValue (const MWWorld::ConstPtr& ptr) const override; ///< Return trade value of the object. Throws an exception, if the object can't be traded. - std::string getUpSoundId (const MWWorld::ConstPtr& ptr) const override; + std::string_view getUpSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the pick up sound Id - std::string getDownSoundId (const MWWorld::ConstPtr& ptr) const override; + std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the put down sound Id std::string getInventoryIcon (const MWWorld::ConstPtr& ptr) const override; diff --git a/apps/openmw/mwclass/clothing.cpp b/apps/openmw/mwclass/clothing.cpp index 3a0a69e45b..9e77b1d898 100644 --- a/apps/openmw/mwclass/clothing.cpp +++ b/apps/openmw/mwclass/clothing.cpp @@ -119,26 +119,26 @@ namespace MWClass return ref->mBase->mData.mValue; } - std::string Clothing::getUpSoundId (const MWWorld::ConstPtr& ptr) const + std::string_view Clothing::getUpSoundId(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef *ref = ptr.get(); if (ref->mBase->mData.mType == 8) { - return std::string("Item Ring Up"); + return "Item Ring Up"; } - return std::string("Item Clothes Up"); + return "Item Clothes Up"; } - std::string Clothing::getDownSoundId (const MWWorld::ConstPtr& ptr) const + std::string_view Clothing::getDownSoundId(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef *ref = ptr.get(); if (ref->mBase->mData.mType == 8) { - return std::string("Item Ring Down"); + return "Item Ring Down"; } - return std::string("Item Clothes Down"); + return "Item Clothes Down"; } std::string Clothing::getInventoryIcon (const MWWorld::ConstPtr& ptr) const diff --git a/apps/openmw/mwclass/clothing.hpp b/apps/openmw/mwclass/clothing.hpp index bfb6869561..be486a740e 100644 --- a/apps/openmw/mwclass/clothing.hpp +++ b/apps/openmw/mwclass/clothing.hpp @@ -42,10 +42,10 @@ namespace MWClass int getValue (const MWWorld::ConstPtr& ptr) const override; ///< Return trade value of the object. Throws an exception, if the object can't be traded. - std::string getUpSoundId (const MWWorld::ConstPtr& ptr) const override; + std::string_view getUpSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the pick up sound Id - std::string getDownSoundId (const MWWorld::ConstPtr& ptr) const override; + std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the put down sound Id std::string getInventoryIcon (const MWWorld::ConstPtr& ptr) const override; diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index 19eddfec86..b0ca07c61b 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -593,11 +593,11 @@ namespace MWClass return (ref->mBase->mRecordFlags & ESM::FLAG_Persistent) != 0; } - std::string Creature::getSoundIdFromSndGen(const MWWorld::Ptr &ptr, const std::string &name) const + std::string_view Creature::getSoundIdFromSndGen(const MWWorld::Ptr& ptr, std::string_view name) const { int type = getSndGenTypeFromName(ptr, name); if (type < 0) - return std::string(); + return {}; std::vector sounds; std::vector fallbacksounds; @@ -650,7 +650,7 @@ namespace MWClass if (!fallbacksounds.empty()) return fallbacksounds[Misc::Rng::rollDice(fallbacksounds.size(), prng)]->mSound; - return std::string(); + return {}; } MWWorld::Ptr Creature::copyToCellImpl(const MWWorld::ConstPtr &ptr, MWWorld::CellStore &cell) const @@ -680,7 +680,7 @@ namespace MWClass return isFlagBitSet(ptr, static_cast(ESM::Creature::Walks | ESM::Creature::Bipedal)); } - int Creature::getSndGenTypeFromName(const MWWorld::Ptr &ptr, const std::string &name) + int Creature::getSndGenTypeFromName(const MWWorld::Ptr& ptr, std::string_view name) { if(name == "left") { @@ -719,7 +719,7 @@ namespace MWClass if(name == "land") return ESM::SoundGenerator::Land; - throw std::runtime_error(std::string("Unexpected soundgen type: ")+name); + throw std::runtime_error("Unexpected soundgen type: " + std::string(name)); } float Creature::getSkill(const MWWorld::Ptr &ptr, int skill) const diff --git a/apps/openmw/mwclass/creature.hpp b/apps/openmw/mwclass/creature.hpp index 17f208a532..2eec015554 100644 --- a/apps/openmw/mwclass/creature.hpp +++ b/apps/openmw/mwclass/creature.hpp @@ -24,7 +24,7 @@ namespace MWClass MWWorld::Ptr copyToCellImpl(const MWWorld::ConstPtr &ptr, MWWorld::CellStore &cell) const override; - static int getSndGenTypeFromName(const MWWorld::Ptr &ptr, const std::string &name); + static int getSndGenTypeFromName(const MWWorld::Ptr& ptr, std::string_view name); // cached GMSTs struct GMST @@ -97,7 +97,7 @@ namespace MWClass bool isPersistent (const MWWorld::ConstPtr& ptr) const override; - std::string getSoundIdFromSndGen(const MWWorld::Ptr &ptr, const std::string &name) const override; + std::string_view getSoundIdFromSndGen(const MWWorld::Ptr& ptr, std::string_view name) const override; MWMechanics::Movement& getMovementSettings (const MWWorld::Ptr& ptr) const override; ///< Return desired movement. diff --git a/apps/openmw/mwclass/ingredient.cpp b/apps/openmw/mwclass/ingredient.cpp index 45dc165564..4b523335af 100644 --- a/apps/openmw/mwclass/ingredient.cpp +++ b/apps/openmw/mwclass/ingredient.cpp @@ -79,14 +79,14 @@ namespace MWClass return action; } - std::string Ingredient::getUpSoundId (const MWWorld::ConstPtr& ptr) const + std::string_view Ingredient::getUpSoundId(const MWWorld::ConstPtr& ptr) const { - return std::string("Item Ingredient Up"); + return "Item Ingredient Up"; } - std::string Ingredient::getDownSoundId (const MWWorld::ConstPtr& ptr) const + std::string_view Ingredient::getDownSoundId(const MWWorld::ConstPtr& ptr) const { - return std::string("Item Ingredient Down"); + return "Item Ingredient Down"; } std::string Ingredient::getInventoryIcon (const MWWorld::ConstPtr& ptr) const diff --git a/apps/openmw/mwclass/ingredient.hpp b/apps/openmw/mwclass/ingredient.hpp index 5520397ebe..15a879ba94 100644 --- a/apps/openmw/mwclass/ingredient.hpp +++ b/apps/openmw/mwclass/ingredient.hpp @@ -37,10 +37,10 @@ namespace MWClass std::unique_ptr use (const MWWorld::Ptr& ptr, bool force=false) const override; ///< Generate action for using via inventory menu - std::string getUpSoundId (const MWWorld::ConstPtr& ptr) const override; + std::string_view getUpSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the pick up sound Id - std::string getDownSoundId (const MWWorld::ConstPtr& ptr) const override; + std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the put down sound Id std::string getInventoryIcon (const MWWorld::ConstPtr& ptr) const override; diff --git a/apps/openmw/mwclass/light.cpp b/apps/openmw/mwclass/light.cpp index 71f882fac4..6694c68c0b 100644 --- a/apps/openmw/mwclass/light.cpp +++ b/apps/openmw/mwclass/light.cpp @@ -122,14 +122,14 @@ namespace MWClass return ref->mBase->mData.mValue; } - std::string Light::getUpSoundId (const MWWorld::ConstPtr& ptr) const + std::string_view Light::getUpSoundId(const MWWorld::ConstPtr& ptr) const { - return std::string("Item Misc Up"); + return "Item Misc Up"; } - std::string Light::getDownSoundId (const MWWorld::ConstPtr& ptr) const + std::string_view Light::getDownSoundId(const MWWorld::ConstPtr& ptr) const { - return std::string("Item Misc Down"); + return "Item Misc Down"; } diff --git a/apps/openmw/mwclass/light.hpp b/apps/openmw/mwclass/light.hpp index f917693246..81b1f0fd92 100644 --- a/apps/openmw/mwclass/light.hpp +++ b/apps/openmw/mwclass/light.hpp @@ -48,10 +48,10 @@ namespace MWClass int getValue (const MWWorld::ConstPtr& ptr) const override; ///< Return trade value of the object. Throws an exception, if the object can't be traded. - std::string getUpSoundId (const MWWorld::ConstPtr& ptr) const override; + std::string_view getUpSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the pick up sound Id - std::string getDownSoundId (const MWWorld::ConstPtr& ptr) const override; + std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the put down sound Id std::string getInventoryIcon (const MWWorld::ConstPtr& ptr) const override; diff --git a/apps/openmw/mwclass/lockpick.cpp b/apps/openmw/mwclass/lockpick.cpp index 64396f5505..d97d207695 100644 --- a/apps/openmw/mwclass/lockpick.cpp +++ b/apps/openmw/mwclass/lockpick.cpp @@ -78,14 +78,14 @@ namespace MWClass return ref->mBase->mData.mValue; } - std::string Lockpick::getUpSoundId (const MWWorld::ConstPtr& ptr) const + std::string_view Lockpick::getUpSoundId(const MWWorld::ConstPtr& ptr) const { - return std::string("Item Lockpick Up"); + return "Item Lockpick Up"; } - std::string Lockpick::getDownSoundId (const MWWorld::ConstPtr& ptr) const + std::string_view Lockpick::getDownSoundId(const MWWorld::ConstPtr& ptr) const { - return std::string("Item Lockpick Down"); + return "Item Lockpick Down"; } std::string Lockpick::getInventoryIcon (const MWWorld::ConstPtr& ptr) const diff --git a/apps/openmw/mwclass/lockpick.hpp b/apps/openmw/mwclass/lockpick.hpp index 0e873efb15..66a5652068 100644 --- a/apps/openmw/mwclass/lockpick.hpp +++ b/apps/openmw/mwclass/lockpick.hpp @@ -38,10 +38,10 @@ namespace MWClass int getValue (const MWWorld::ConstPtr& ptr) const override; ///< Return trade value of the object. Throws an exception, if the object can't be traded. - std::string getUpSoundId (const MWWorld::ConstPtr& ptr) const override; + std::string_view getUpSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the pick up sound Id - std::string getDownSoundId (const MWWorld::ConstPtr& ptr) const override; + std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the put down sound Id std::string getInventoryIcon (const MWWorld::ConstPtr& ptr) const override; diff --git a/apps/openmw/mwclass/misc.cpp b/apps/openmw/mwclass/misc.cpp index 2e4de8865a..4897b016ae 100644 --- a/apps/openmw/mwclass/misc.cpp +++ b/apps/openmw/mwclass/misc.cpp @@ -105,18 +105,18 @@ namespace MWClass return value; } - std::string Miscellaneous::getUpSoundId (const MWWorld::ConstPtr& ptr) const + std::string_view Miscellaneous::getUpSoundId(const MWWorld::ConstPtr& ptr) const { if (isGold(ptr)) - return std::string("Item Gold Up"); - return std::string("Item Misc Up"); + return "Item Gold Up"; + return "Item Misc Up"; } - std::string Miscellaneous::getDownSoundId (const MWWorld::ConstPtr& ptr) const + std::string_view Miscellaneous::getDownSoundId(const MWWorld::ConstPtr& ptr) const { if (isGold(ptr)) - return std::string("Item Gold Down"); - return std::string("Item Misc Down"); + return "Item Gold Down"; + return "Item Misc Down"; } std::string Miscellaneous::getInventoryIcon (const MWWorld::ConstPtr& ptr) const diff --git a/apps/openmw/mwclass/misc.hpp b/apps/openmw/mwclass/misc.hpp index 7a3f97bd58..deae059d07 100644 --- a/apps/openmw/mwclass/misc.hpp +++ b/apps/openmw/mwclass/misc.hpp @@ -34,10 +34,10 @@ namespace MWClass int getValue (const MWWorld::ConstPtr& ptr) const override; ///< Return trade value of the object. Throws an exception, if the object can't be traded. - std::string getUpSoundId (const MWWorld::ConstPtr& ptr) const override; + std::string_view getUpSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the pick up sound Id - std::string getDownSoundId (const MWWorld::ConstPtr& ptr) const override; + std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the put down sound Id std::string getInventoryIcon (const MWWorld::ConstPtr& ptr) const override; diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index 86fbe496a7..c6d3c380ed 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -1229,13 +1229,13 @@ namespace MWClass } - std::string Npc::getSoundIdFromSndGen(const MWWorld::Ptr &ptr, const std::string &name) const + std::string_view Npc::getSoundIdFromSndGen(const MWWorld::Ptr& ptr, std::string_view name) const { if(name == "left" || name == "right") { MWBase::World *world = MWBase::Environment::get().getWorld(); if(world->isFlying(ptr)) - return std::string(); + return {}; osg::Vec3f pos(ptr.getRefData().getPosition().asVec3()); if(world->isSwimming(ptr)) return (name == "left") ? "Swim Left" : "Swim Right"; @@ -1249,7 +1249,7 @@ namespace MWClass int weaponType = ESM::Weapon::None; MWMechanics::getActiveWeapon(ptr, &weaponType); if (weaponType == ESM::Weapon::None) - return std::string(); + return {}; } const MWWorld::InventoryStore &inv = Npc::getInventoryStore(ptr); @@ -1267,12 +1267,12 @@ namespace MWClass return (name == "left") ? "FootHeavyLeft" : "FootHeavyRight"; } } - return std::string(); + return {}; } // Morrowind ignores land soundgen for NPCs if(name == "land") - return std::string(); + return {}; if(name == "swimleft") return "Swim Left"; if(name == "swimright") @@ -1282,13 +1282,13 @@ namespace MWClass // only for biped creatures? if(name == "moan") - return std::string(); + return {}; if(name == "roar") - return std::string(); + return {}; if(name == "scream") - return std::string(); + return {}; - throw std::runtime_error(std::string("Unexpected soundgen type: ")+name); + throw std::runtime_error("Unexpected soundgen type: " + std::string(name)); } MWWorld::Ptr Npc::copyToCellImpl(const MWWorld::ConstPtr &ptr, MWWorld::CellStore &cell) const diff --git a/apps/openmw/mwclass/npc.hpp b/apps/openmw/mwclass/npc.hpp index 4d8ebde7a3..019d3d6272 100644 --- a/apps/openmw/mwclass/npc.hpp +++ b/apps/openmw/mwclass/npc.hpp @@ -125,7 +125,7 @@ namespace MWClass bool isPersistent (const MWWorld::ConstPtr& ptr) const override; - std::string getSoundIdFromSndGen(const MWWorld::Ptr &ptr, const std::string &name) const override; + std::string_view getSoundIdFromSndGen(const MWWorld::Ptr& ptr, std::string_view name) const override; std::string getModel(const MWWorld::ConstPtr &ptr) const override; diff --git a/apps/openmw/mwclass/potion.cpp b/apps/openmw/mwclass/potion.cpp index bb89d74d1f..0902651e9c 100644 --- a/apps/openmw/mwclass/potion.cpp +++ b/apps/openmw/mwclass/potion.cpp @@ -72,14 +72,14 @@ namespace MWClass return ref->mBase->mData.mValue; } - std::string Potion::getUpSoundId (const MWWorld::ConstPtr& ptr) const + std::string_view Potion::getUpSoundId(const MWWorld::ConstPtr& ptr) const { - return std::string("Item Potion Up"); + return "Item Potion Up"; } - std::string Potion::getDownSoundId (const MWWorld::ConstPtr& ptr) const + std::string_view Potion::getDownSoundId(const MWWorld::ConstPtr& ptr) const { - return std::string("Item Potion Down"); + return "Item Potion Down"; } std::string Potion::getInventoryIcon (const MWWorld::ConstPtr& ptr) const diff --git a/apps/openmw/mwclass/potion.hpp b/apps/openmw/mwclass/potion.hpp index f0a0a0cedc..9dabe28e5d 100644 --- a/apps/openmw/mwclass/potion.hpp +++ b/apps/openmw/mwclass/potion.hpp @@ -37,10 +37,10 @@ namespace MWClass std::unique_ptr use (const MWWorld::Ptr& ptr, bool force=false) const override; ///< Generate action for using via inventory menu - std::string getUpSoundId (const MWWorld::ConstPtr& ptr) const override; + std::string_view getUpSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the pick up sound Id - std::string getDownSoundId (const MWWorld::ConstPtr& ptr) const override; + std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the put down sound Id std::string getInventoryIcon (const MWWorld::ConstPtr& ptr) const override; diff --git a/apps/openmw/mwclass/probe.cpp b/apps/openmw/mwclass/probe.cpp index 5bd217772e..73bd911203 100644 --- a/apps/openmw/mwclass/probe.cpp +++ b/apps/openmw/mwclass/probe.cpp @@ -78,14 +78,14 @@ namespace MWClass return ref->mBase->mData.mValue; } - std::string Probe::getUpSoundId (const MWWorld::ConstPtr& ptr) const + std::string_view Probe::getUpSoundId(const MWWorld::ConstPtr& ptr) const { - return std::string("Item Probe Up"); + return "Item Probe Up"; } - std::string Probe::getDownSoundId (const MWWorld::ConstPtr& ptr) const + std::string_view Probe::getDownSoundId(const MWWorld::ConstPtr& ptr) const { - return std::string("Item Probe Down"); + return "Item Probe Down"; } std::string Probe::getInventoryIcon (const MWWorld::ConstPtr& ptr) const diff --git a/apps/openmw/mwclass/probe.hpp b/apps/openmw/mwclass/probe.hpp index 0aa6941380..5922fa9899 100644 --- a/apps/openmw/mwclass/probe.hpp +++ b/apps/openmw/mwclass/probe.hpp @@ -38,10 +38,10 @@ namespace MWClass int getValue (const MWWorld::ConstPtr& ptr) const override; ///< Return trade value of the object. Throws an exception, if the object can't be traded. - std::string getUpSoundId (const MWWorld::ConstPtr& ptr) const override; + std::string_view getUpSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the pick up sound Id - std::string getDownSoundId (const MWWorld::ConstPtr& ptr) const override; + std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the put down sound Id std::string getInventoryIcon (const MWWorld::ConstPtr& ptr) const override; diff --git a/apps/openmw/mwclass/repair.cpp b/apps/openmw/mwclass/repair.cpp index 216057c203..4977092d60 100644 --- a/apps/openmw/mwclass/repair.cpp +++ b/apps/openmw/mwclass/repair.cpp @@ -67,14 +67,14 @@ namespace MWClass return ref->mBase->mData.mValue; } - std::string Repair::getUpSoundId (const MWWorld::ConstPtr& ptr) const + std::string_view Repair::getUpSoundId(const MWWorld::ConstPtr& ptr) const { - return std::string("Item Repair Up"); + return "Item Repair Up"; } - std::string Repair::getDownSoundId (const MWWorld::ConstPtr& ptr) const + std::string_view Repair::getDownSoundId(const MWWorld::ConstPtr& ptr) const { - return std::string("Item Repair Down"); + return "Item Repair Down"; } std::string Repair::getInventoryIcon (const MWWorld::ConstPtr& ptr) const diff --git a/apps/openmw/mwclass/repair.hpp b/apps/openmw/mwclass/repair.hpp index 519989c785..eec8c4fce0 100644 --- a/apps/openmw/mwclass/repair.hpp +++ b/apps/openmw/mwclass/repair.hpp @@ -34,10 +34,10 @@ namespace MWClass int getValue (const MWWorld::ConstPtr& ptr) const override; ///< Return trade value of the object. Throws an exception, if the object can't be traded. - std::string getUpSoundId (const MWWorld::ConstPtr& ptr) const override; + std::string_view getUpSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the pick up sound Id - std::string getDownSoundId (const MWWorld::ConstPtr& ptr) const override; + std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the put down sound Id std::string getInventoryIcon (const MWWorld::ConstPtr& ptr) const override; diff --git a/apps/openmw/mwclass/weapon.cpp b/apps/openmw/mwclass/weapon.cpp index 7a5ad50c31..d734acc229 100644 --- a/apps/openmw/mwclass/weapon.cpp +++ b/apps/openmw/mwclass/weapon.cpp @@ -123,20 +123,18 @@ namespace MWClass return ref->mBase->mData.mValue; } - std::string Weapon::getUpSoundId (const MWWorld::ConstPtr& ptr) const + std::string_view Weapon::getUpSoundId(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef *ref = ptr.get(); int type = ref->mBase->mData.mType; - std::string soundId = MWMechanics::getWeaponType(type)->mSoundId; - return soundId + " Up"; + return MWMechanics::getWeaponType(type)->mSoundIdUp; } - std::string Weapon::getDownSoundId (const MWWorld::ConstPtr& ptr) const + std::string_view Weapon::getDownSoundId(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef *ref = ptr.get(); int type = ref->mBase->mData.mType; - std::string soundId = MWMechanics::getWeaponType(type)->mSoundId; - return soundId + " Down"; + return MWMechanics::getWeaponType(type)->mSoundIdDown; } std::string Weapon::getInventoryIcon (const MWWorld::ConstPtr& ptr) const diff --git a/apps/openmw/mwclass/weapon.hpp b/apps/openmw/mwclass/weapon.hpp index 5ed2cee45a..246f9abeda 100644 --- a/apps/openmw/mwclass/weapon.hpp +++ b/apps/openmw/mwclass/weapon.hpp @@ -48,10 +48,10 @@ namespace MWClass int getValue (const MWWorld::ConstPtr& ptr) const override; ///< Return trade value of the object. Throws an exception, if the object can't be traded. - std::string getUpSoundId (const MWWorld::ConstPtr& ptr) const override; + std::string_view getUpSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the pick up sound Id - std::string getDownSoundId (const MWWorld::ConstPtr& ptr) const override; + std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the put down sound Id std::string getInventoryIcon (const MWWorld::ConstPtr& ptr) const override; diff --git a/apps/openmw/mwgui/alchemywindow.cpp b/apps/openmw/mwgui/alchemywindow.cpp index fd4a21cf10..ac1ebd2038 100644 --- a/apps/openmw/mwgui/alchemywindow.cpp +++ b/apps/openmw/mwgui/alchemywindow.cpp @@ -290,7 +290,7 @@ namespace MWGui { update(); - std::string sound = item.getClass().getUpSoundId(item); + std::string_view sound = item.getClass().getUpSoundId(item); MWBase::Environment::get().getWindowManager()->playSound(sound); } } diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index f8bc3b57ba..fafeb8b1ce 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -219,7 +219,7 @@ namespace MWGui { // play the sound of the first object MWWorld::Ptr item = mModel->getItem(i).mBase; - std::string sound = item.getClass().getUpSoundId(item); + std::string_view sound = item.getClass().getUpSoundId(item); MWBase::Environment::get().getWindowManager()->playSound(sound); } diff --git a/apps/openmw/mwgui/draganddrop.cpp b/apps/openmw/mwgui/draganddrop.cpp index cfe60db5dd..543c7f9e1a 100644 --- a/apps/openmw/mwgui/draganddrop.cpp +++ b/apps/openmw/mwgui/draganddrop.cpp @@ -62,7 +62,7 @@ void DragAndDrop::startDrag (int index, SortFilterItemModel* sortModel, ItemMode mSourceSortModel = playerFilterModel; } - std::string sound = mItem.mBase.getClass().getUpSoundId(mItem.mBase); + std::string_view sound = mItem.mBase.getClass().getUpSoundId(mItem.mBase); MWBase::Environment::get().getWindowManager()->playSound (sound); if (mSourceSortModel) @@ -92,7 +92,7 @@ void DragAndDrop::startDrag (int index, SortFilterItemModel* sortModel, ItemMode void DragAndDrop::drop(ItemModel *targetModel, ItemView *targetView) { - std::string sound = mItem.mBase.getClass().getDownSoundId(mItem.mBase); + std::string_view sound = mItem.mBase.getClass().getDownSoundId(mItem.mBase); MWBase::Environment::get().getWindowManager()->playSound(sound); // We can't drop a conjured item to the ground; the target container should always be the source container diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index 6a6bca3e1e..1063e8e4fe 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -246,7 +246,7 @@ namespace MWGui } const ItemStack& item = mTradeModel->getItem(index); - std::string sound = item.mBase.getClass().getDownSoundId(item.mBase); + std::string_view sound = item.mBase.getClass().getDownSoundId(item.mBase); MWWorld::Ptr object = item.mBase; int count = item.mCount; @@ -356,7 +356,7 @@ namespace MWGui { ensureSelectedItemUnequipped(count); const ItemStack& item = mTradeModel->getItem(mSelectedItem); - std::string sound = item.mBase.getClass().getUpSoundId(item.mBase); + std::string_view sound = item.mBase.getClass().getUpSoundId(item.mBase); MWBase::Environment::get().getWindowManager()->playSound(sound); if (item.mType == ItemStack::Type_Barter) diff --git a/apps/openmw/mwgui/tradewindow.cpp b/apps/openmw/mwgui/tradewindow.cpp index 18ac1061ba..f7c46d3c83 100644 --- a/apps/openmw/mwgui/tradewindow.cpp +++ b/apps/openmw/mwgui/tradewindow.cpp @@ -204,7 +204,7 @@ namespace MWGui void TradeWindow::sellItem(MyGUI::Widget* sender, int count) { const ItemStack& item = mTradeModel->getItem(mItemToSell); - std::string sound = item.mBase.getClass().getUpSoundId(item.mBase); + std::string_view sound = item.mBase.getClass().getUpSoundId(item.mBase); MWBase::Environment::get().getWindowManager()->playSound(sound); TradeItemModel* playerTradeModel = MWBase::Environment::get().getWindowManager()->getInventoryWindow()->getTradeModel(); diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index 77bc0d7713..f8adeabffe 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -2105,7 +2105,7 @@ namespace MWGui mInventoryWindow->cycle(next); } - void WindowManager::playSound(const std::string& soundId, float volume, float pitch) + void WindowManager::playSound(std::string_view soundId, float volume, float pitch) { if (soundId.empty()) return; diff --git a/apps/openmw/mwgui/windowmanagerimp.hpp b/apps/openmw/mwgui/windowmanagerimp.hpp index 117733d061..ea45e34e94 100644 --- a/apps/openmw/mwgui/windowmanagerimp.hpp +++ b/apps/openmw/mwgui/windowmanagerimp.hpp @@ -374,7 +374,7 @@ namespace MWGui /// Cycle to next or previous weapon void cycleWeapon(bool next) override; - void playSound(const std::string& soundId, float volume = 1.f, float pitch = 1.f) override; + void playSound(std::string_view soundId, float volume = 1.f, float pitch = 1.f) override; void addCell(MWWorld::CellStore* cell) override; void removeCell(MWWorld::CellStore* cell) override; diff --git a/apps/openmw/mwmechanics/character.cpp b/apps/openmw/mwmechanics/character.cpp index 7e45911d9b..528fdd75ad 100644 --- a/apps/openmw/mwmechanics/character.cpp +++ b/apps/openmw/mwmechanics/character.cpp @@ -936,13 +936,13 @@ void CharacterController::handleTextKey(std::string_view groupname, SceneUtil::T auto& charClass = mPtr.getClass(); if (evt.substr(0, 10) == "soundgen: ") { - std::string soundgen = std::string(evt.substr(10)); + std::string_view soundgen = evt.substr(10); // The event can optionally contain volume and pitch modifiers float volume=1.f, pitch=1.f; if (soundgen.find(' ') != std::string::npos) { - std::vector tokens; + std::vector tokens; Misc::StringUtils::split(soundgen, tokens); soundgen = tokens[0]; if (tokens.size() >= 2) @@ -959,7 +959,7 @@ void CharacterController::handleTextKey(std::string_view groupname, SceneUtil::T } } - std::string sound = charClass.getSoundIdFromSndGen(mPtr, soundgen); + std::string_view sound = charClass.getSoundIdFromSndGen(mPtr, soundgen); if(!sound.empty()) { MWBase::SoundManager *sndMgr = MWBase::Environment::get().getSoundManager(); @@ -1129,7 +1129,7 @@ bool CharacterController::updateWeaponState() const bool isWerewolf = cls.isNpc() && cls.getNpcStats(mPtr).isWerewolf(); - std::string downSoundId; + std::string_view downSoundId; bool weaponChanged = false; bool ammunition = true; float weapSpeed = 1.f; @@ -1304,7 +1304,7 @@ bool CharacterController::updateWeaponState() if (!mWeapon.isEmpty() && mWeaponType != ESM::Weapon::HandToHand && isRealWeapon(weaptype)) { - std::string upSoundId = mWeapon.getClass().getUpSoundId(mWeapon); + std::string_view upSoundId = mWeapon.getClass().getUpSoundId(mWeapon); if (!upSoundId.empty()) sndMgr->playSound3D(mPtr, upSoundId, 1.0f, 1.0f); } diff --git a/apps/openmw/mwrender/weaponanimation.cpp b/apps/openmw/mwrender/weaponanimation.cpp index 0572eae3be..31ed5c0e11 100644 --- a/apps/openmw/mwrender/weaponanimation.cpp +++ b/apps/openmw/mwrender/weaponanimation.cpp @@ -73,7 +73,7 @@ void WeaponAnimation::attachArrow(const MWWorld::Ptr& actor) ESM::WeaponType::Class weapclass = MWMechanics::getWeaponType(type)->mWeaponClass; if (weapclass == ESM::WeaponType::Thrown) { - std::string soundid = weaponSlot->getClass().getUpSoundId(*weaponSlot); + std::string_view soundid = weaponSlot->getClass().getUpSoundId(*weaponSlot); if(!soundid.empty()) { MWBase::SoundManager *sndMgr = MWBase::Environment::get().getSoundManager(); diff --git a/apps/openmw/mwworld/action.cpp b/apps/openmw/mwworld/action.cpp index 32a3c8f96d..6a2cab1b87 100644 --- a/apps/openmw/mwworld/action.cpp +++ b/apps/openmw/mwworld/action.cpp @@ -58,7 +58,7 @@ void MWWorld::Action::execute (const Ptr& actor, bool noSound) executeImp (actor); } -void MWWorld::Action::setSound (const std::string& id) +void MWWorld::Action::setSound(std::string_view id) { mSoundId = id; } diff --git a/apps/openmw/mwworld/action.hpp b/apps/openmw/mwworld/action.hpp index 2f9804053e..df1f848a47 100644 --- a/apps/openmw/mwworld/action.hpp +++ b/apps/openmw/mwworld/action.hpp @@ -2,6 +2,7 @@ #define GAME_MWWORLD_ACTION_H #include +#include #include "ptr.hpp" @@ -39,7 +40,7 @@ namespace MWWorld void execute (const Ptr& actor, bool noSound = false); - void setSound (const std::string& id); + void setSound(std::string_view id); void setSoundOffset(float offset); }; } diff --git a/apps/openmw/mwworld/class.cpp b/apps/openmw/mwworld/class.cpp index 3389bfd727..18c810d642 100644 --- a/apps/openmw/mwworld/class.cpp +++ b/apps/openmw/mwworld/class.cpp @@ -251,17 +251,17 @@ namespace MWWorld getClasses().emplace(instance.getType(), &instance); } - std::string Class::getUpSoundId (const ConstPtr& ptr) const + std::string_view Class::getUpSoundId (const ConstPtr& ptr) const { throw std::runtime_error ("class does not have an up sound"); } - std::string Class::getDownSoundId (const ConstPtr& ptr) const + std::string_view Class::getDownSoundId (const ConstPtr& ptr) const { throw std::runtime_error ("class does not have an down sound"); } - std::string Class::getSoundIdFromSndGen(const Ptr &ptr, const std::string &type) const + std::string_view Class::getSoundIdFromSndGen(const Ptr& ptr, std::string_view type) const { throw std::runtime_error("class does not support soundgen look up"); } diff --git a/apps/openmw/mwworld/class.hpp b/apps/openmw/mwworld/class.hpp index 8d6e7bfc06..c17c865abe 100644 --- a/apps/openmw/mwworld/class.hpp +++ b/apps/openmw/mwworld/class.hpp @@ -235,15 +235,15 @@ namespace MWWorld /// /// (default implementation: return false) - virtual std::string getUpSoundId (const ConstPtr& ptr) const; + virtual std::string_view getUpSoundId(const ConstPtr& ptr) const; ///< Return the up sound ID of \a ptr or throw an exception, if class does not support ID retrieval /// (default implementation: throw an exception) - virtual std::string getDownSoundId (const ConstPtr& ptr) const; + virtual std::string_view getDownSoundId(const ConstPtr& ptr) const; ///< Return the down sound ID of \a ptr or throw an exception, if class does not support ID retrieval /// (default implementation: throw an exception) - virtual std::string getSoundIdFromSndGen(const Ptr &ptr, const std::string &type) const; + virtual std::string_view getSoundIdFromSndGen(const Ptr& ptr, std::string_view type) const; ///< Returns the sound ID for \a ptr of the given soundgen \a type. virtual float getArmorRating (const MWWorld::Ptr& ptr) const; diff --git a/components/esm3/loadweap.hpp b/components/esm3/loadweap.hpp index ee7fc845c4..7b84603511 100644 --- a/components/esm3/loadweap.hpp +++ b/components/esm3/loadweap.hpp @@ -103,13 +103,20 @@ struct WeaponType //std::string mDisplayName; // TODO: will be needed later for editor std::string mShortGroup; std::string mLongGroup; - std::string mSoundId; + std::string mSoundIdDown; + std::string mSoundIdUp; std::string mAttachBone; std::string mSheathingBone; Skill::SkillEnum mSkill; Class mWeaponClass; int mAmmoType; int mFlags; + + WeaponType(std::string shortGroup, std::string longGroup, const std::string& soundId, std::string attachBone, + std::string sheathingBone, Skill::SkillEnum skill, Class weaponClass, int ammoType, int flags) : + mShortGroup(std::move(shortGroup)), mLongGroup(std::move(longGroup)), mSoundIdDown(soundId + " Down"), + mSoundIdUp(soundId + " Up"), mAttachBone(std::move(attachBone)), mSheathingBone(std::move(sheathingBone)), + mSkill(skill), mWeaponClass(weaponClass), mAmmoType(ammoType), mFlags(flags) {}; }; }