Use for_each and functors to avoid some for loops

actorid
Chris Robinson 12 years ago
parent de95926e9f
commit 48784c7e2f

@ -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)
{ class VisQueueSet {
for(size_t i = 0;i < objlist.mEntities.size();i++) 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(mVisFlags != 0)
if(visflags != 0) entity->setVisibilityFlags(mVisFlags);
ent->setVisibilityFlags(visflags);
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); Ogre::SubEntity* subEnt = entity->getSubEntity(i);
subEnt->setRenderQueueGroup(subEnt->getMaterial()->isTransparent() ? transqueue : solidqueue); 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(mVisFlags != 0)
if(visflags != 0) psys->setVisibilityFlags(mVisFlags);
part->setVisibilityFlags(visflags);
// TODO: Check particle material for actual transparency // 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));
} }

@ -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 NpcAnimation::insertBoundedPart(const std::string &model, int group, const std::string &bonename)
{ {
NifOgre::ObjectList objects = NifOgre::Loader::createObjects(mSkelBase, bonename, mInsert, model); NifOgre::ObjectList objects = NifOgre::Loader::createObjects(mSkelBase, bonename, mInsert, model);
setRenderProperties(objects, (mViewMode == VM_FirstPerson) ? RV_FirstPerson : mVisibilityFlags, RQG_Main, RQG_Alpha); setRenderProperties(objects, (mViewMode == VM_FirstPerson) ? RV_FirstPerson : mVisibilityFlags, RQG_Main, RQG_Alpha);
for(size_t i = 0;i < objects.mEntities.size();i++) std::for_each(objects.mEntities.begin(), objects.mEntities.end(), SetObjectGroup(group));
{ std::for_each(objects.mParticles.begin(), objects.mParticles.end(), SetObjectGroup(group));
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));
if(objects.mSkelBase) if(objects.mSkelBase)
{ {
@ -576,7 +583,8 @@ void NpcAnimation::showWeapons(bool showWeapon)
mWeapon = inv.getSlot(MWWorld::InventoryStore::Slot_CarriedRight); mWeapon = inv.getSlot(MWWorld::InventoryStore::Slot_CarriedRight);
if(mWeapon != inv.end()) // special case for weapons 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); addOrReplaceIndividualPart(ESM::PRT_Weapon, MWWorld::InventoryStore::Slot_CarriedRight, 1, mesh);
} }
} }

Loading…
Cancel
Save