diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 533a7eab3..737d4da64 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -153,28 +153,44 @@ void Animation::setObjectRoot(Ogre::SceneNode *node, const std::string &model, b } } -void Animation::setRenderProperties(const NifOgre::ObjectList &objlist, Ogre::uint32 visflags, Ogre::uint8 solidqueue, Ogre::uint8 transqueue) -{ - for(size_t i = 0;i < objlist.mEntities.size();i++) + +class VisQueueSet { + Ogre::uint32 mVisFlags; + Ogre::uint8 mSolidQueue, mTransQueue; + +public: + VisQueueSet(Ogre::uint32 visflags, Ogre::uint8 solidqueue, Ogre::uint8 transqueue) + : mVisFlags(visflags), mSolidQueue(solidqueue), mTransQueue(transqueue) + { } + + void operator()(Ogre::Entity *entity) const { - Ogre::Entity *ent = objlist.mEntities[i]; - if(visflags != 0) - ent->setVisibilityFlags(visflags); + if(mVisFlags != 0) + entity->setVisibilityFlags(mVisFlags); - for(unsigned int j = 0;j < ent->getNumSubEntities();++j) + unsigned int numsubs = entity->getNumSubEntities(); + for(unsigned int i = 0;i < numsubs;++i) { - Ogre::SubEntity* subEnt = ent->getSubEntity(j); - subEnt->setRenderQueueGroup(subEnt->getMaterial()->isTransparent() ? transqueue : solidqueue); + Ogre::SubEntity* subEnt = entity->getSubEntity(i); + subEnt->setRenderQueueGroup(subEnt->getMaterial()->isTransparent() ? mTransQueue : mSolidQueue); } } - for(size_t i = 0;i < objlist.mParticles.size();i++) + + void operator()(Ogre::ParticleSystem *psys) const { - Ogre::ParticleSystem *part = objlist.mParticles[i]; - if(visflags != 0) - part->setVisibilityFlags(visflags); + if(mVisFlags != 0) + psys->setVisibilityFlags(mVisFlags); // TODO: Check particle material for actual transparency - part->setRenderQueueGroup(transqueue); + psys->setRenderQueueGroup(mTransQueue); } +}; + +void Animation::setRenderProperties(const NifOgre::ObjectList &objlist, Ogre::uint32 visflags, Ogre::uint8 solidqueue, Ogre::uint8 transqueue) +{ + std::for_each(objlist.mEntities.begin(), objlist.mEntities.end(), + VisQueueSet(visflags, solidqueue, transqueue)); + std::for_each(objlist.mParticles.begin(), objlist.mParticles.end(), + VisQueueSet(visflags, solidqueue, transqueue)); } diff --git a/apps/openmw/mwrender/npcanimation.cpp b/apps/openmw/mwrender/npcanimation.cpp index 2d3cea12f..971cf58fe 100644 --- a/apps/openmw/mwrender/npcanimation.cpp +++ b/apps/openmw/mwrender/npcanimation.cpp @@ -389,18 +389,25 @@ void NpcAnimation::updateParts(bool forceupdate) } } +class SetObjectGroup { + int mGroup; + +public: + SetObjectGroup(int group) : mGroup(group) { } + + void operator()(Ogre::MovableObject *obj) const + { + obj->getUserObjectBindings().setUserAny(Ogre::Any(mGroup)); + } +}; + NifOgre::ObjectList NpcAnimation::insertBoundedPart(const std::string &model, int group, const std::string &bonename) { NifOgre::ObjectList objects = NifOgre::Loader::createObjects(mSkelBase, bonename, mInsert, model); setRenderProperties(objects, (mViewMode == VM_FirstPerson) ? RV_FirstPerson : mVisibilityFlags, RQG_Main, RQG_Alpha); - for(size_t i = 0;i < objects.mEntities.size();i++) - { - Ogre::Entity *ent = objects.mEntities[i]; - ent->getUserObjectBindings().setUserAny(Ogre::Any(group)); - } - for(size_t i = 0;i < objects.mParticles.size();i++) - objects.mParticles[i]->getUserObjectBindings().setUserAny(Ogre::Any(group)); + std::for_each(objects.mEntities.begin(), objects.mEntities.end(), SetObjectGroup(group)); + std::for_each(objects.mParticles.begin(), objects.mParticles.end(), SetObjectGroup(group)); if(objects.mSkelBase) { @@ -576,7 +583,8 @@ void NpcAnimation::showWeapons(bool showWeapon) mWeapon = inv.getSlot(MWWorld::InventoryStore::Slot_CarriedRight); if(mWeapon != inv.end()) // special case for weapons { - std::string mesh = MWWorld::Class::get(*mWeapon).getModel(*mWeapon); + MWWorld::Ptr weapon = *mWeapon; + std::string mesh = MWWorld::Class::get(weapon).getModel(weapon); addOrReplaceIndividualPart(ESM::PRT_Weapon, MWWorld::InventoryStore::Slot_CarriedRight, 1, mesh); } }