From bf3f82b9d4c6f259fe50fe12063b6838d688283a Mon Sep 17 00:00:00 2001 From: Capostrophic Date: Sun, 14 Oct 2018 20:37:40 +0300 Subject: [PATCH] Cleanup --- apps/openmw/mwclass/activator.cpp | 43 +++++++++++-------------------- apps/openmw/mwclass/activator.hpp | 4 +-- apps/openmw/mwclass/creature.cpp | 20 +++++++------- 3 files changed, 27 insertions(+), 40 deletions(-) diff --git a/apps/openmw/mwclass/activator.cpp b/apps/openmw/mwclass/activator.cpp index 7f53709d6c..e0e2013912 100644 --- a/apps/openmw/mwclass/activator.cpp +++ b/apps/openmw/mwclass/activator.cpp @@ -138,19 +138,13 @@ namespace MWClass std::string Activator::getSoundIdFromSndGen(const MWWorld::Ptr &ptr, const std::string &name) const { - std::string model = getModel(ptr); - if (model.empty()) - return std::string(); - - const MWWorld::Store &creaturestore = MWBase::Environment::get().getWorld()->getStore().get(); + 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; - - for (const ESM::Creature &iter : creaturestore) - { - if (iter.mModel.empty()) - continue; - if (Misc::StringUtils::ciEqual(model, "meshes\\" + iter.mModel)) + for (const ESM::Creature &iter : store.get()) + { + if (!iter.mModel.empty() && Misc::StringUtils::ciEqual(model, "meshes\\" + iter.mModel)) { creatureId = !iter.mOriginal.empty() ? iter.mOriginal : iter.mId; break; @@ -160,19 +154,12 @@ namespace MWClass if (creatureId.empty()) return std::string(); - const MWWorld::Store &store = MWBase::Environment::get().getWorld()->getStore().get(); - int type = getSndGenTypeFromName(name); std::vector sounds; - MWWorld::Store::iterator sound = store.begin(); - - while (sound != store.end()) - { + for (auto sound = store.get().begin(); sound != store.get().end(); ++sound) if (type == sound->mType && !sound->mCreature.empty() && (Misc::StringUtils::ciEqual(creatureId, sound->mCreature))) sounds.push_back(&*sound); - ++sound; - } if (!sounds.empty()) return sounds[Misc::Rng::rollDice(sounds.size())]->mSound; @@ -183,24 +170,24 @@ namespace MWClass return std::string(); } - int Activator::getSndGenTypeFromName(const std::string &name) const + int Activator::getSndGenTypeFromName(const std::string &name) { if (name == "left") - return 0; + return ESM::SoundGenerator::LeftFoot; if (name == "right") - return 1; + return ESM::SoundGenerator::RightFoot; if (name == "swimleft") - return 2; + return ESM::SoundGenerator::SwimLeft; if (name == "swimright") - return 3; + return ESM::SoundGenerator::SwimRight; if (name == "moan") - return 4; + return ESM::SoundGenerator::Moan; if (name == "roar") - return 5; + return ESM::SoundGenerator::Roar; if (name == "scream") - return 6; + return ESM::SoundGenerator::Scream; if (name == "land") - return 7; + return ESM::SoundGenerator::Land; throw std::runtime_error(std::string("Unexpected soundgen type: ")+name); } diff --git a/apps/openmw/mwclass/activator.hpp b/apps/openmw/mwclass/activator.hpp index 0f66b74b45..b92dc75cbd 100644 --- a/apps/openmw/mwclass/activator.hpp +++ b/apps/openmw/mwclass/activator.hpp @@ -10,6 +10,8 @@ namespace MWClass virtual MWWorld::Ptr copyToCellImpl(const MWWorld::ConstPtr &ptr, MWWorld::CellStore &cell) const; + static int getSndGenTypeFromName(const std::string &name); + public: virtual void insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const; @@ -46,8 +48,6 @@ namespace MWClass virtual bool isActivator() const; virtual std::string getSoundIdFromSndGen(const MWWorld::Ptr &ptr, const std::string &name) const; - - virtual int getSndGenTypeFromName(const std::string &name) const; }; } diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index 6d0b42bfeb..788e5cd689 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -688,9 +688,9 @@ namespace MWClass MWBase::World *world = MWBase::Environment::get().getWorld(); osg::Vec3f pos(ptr.getRefData().getPosition().asVec3()); if(world->isUnderwater(ptr.getCell(), pos) || world->isWalkingOnWater(ptr)) - return 2; + return ESM::SoundGenerator::SwimLeft; if(world->isOnGround(ptr)) - return 0; + return ESM::SoundGenerator::LeftFoot; return -1; } if(name == "right") @@ -698,23 +698,23 @@ namespace MWClass MWBase::World *world = MWBase::Environment::get().getWorld(); osg::Vec3f pos(ptr.getRefData().getPosition().asVec3()); if(world->isUnderwater(ptr.getCell(), pos) || world->isWalkingOnWater(ptr)) - return 3; + return ESM::SoundGenerator::SwimRight; if(world->isOnGround(ptr)) - return 1; + return ESM::SoundGenerator::RightFoot; return -1; } if(name == "swimleft") - return 2; + return ESM::SoundGenerator::SwimLeft; if(name == "swimright") - return 3; + return ESM::SoundGenerator::SwimRight; if(name == "moan") - return 4; + return ESM::SoundGenerator::Moan; if(name == "roar") - return 5; + return ESM::SoundGenerator::Roar; if(name == "scream") - return 6; + return ESM::SoundGenerator::Scream; if(name == "land") - return 7; + return ESM::SoundGenerator::Land; throw std::runtime_error(std::string("Unexpected soundgen type: ")+name); }