Improvements to ignored light list setting

The pointer to the LightListCallback is now stored in the Animation, which eliminates the need for dynamic_cast. Also, when the object root is recreated, the previously used LightListCallback will be reused, so we no longer need the objectRootReset() notifier.

Finally, there was a bug when saving and reloading the game, the getIgnoredLightSources() were not being set, as the ActorAnimation constructor completes before the NpcAnimation sets the ObjectRoot. This was solved by creating the LightListCallback in advance in the Animation constructor.
pull/75/head
scrawl 8 years ago
parent 11565b5966
commit 1893617ec9

@ -83,17 +83,6 @@ void ActorAnimation::itemRemoved(const MWWorld::ConstPtr& item, int /*count*/)
}
}
void ActorAnimation::objectRootReset()
{
if (SceneUtil::LightListCallback* callback = findLightListCallback())
{
for (ItemLightMap::iterator iter = mItemLights.begin(); iter != mItemLights.end(); ++iter)
{
callback->getIgnoredLightSources().insert(iter->second);
}
}
}
void ActorAnimation::addHiddenItemLight(const MWWorld::ConstPtr& item, const ESM::Light* esmLight)
{
if (mItemLights.find(item) != mItemLights.end())
@ -115,7 +104,7 @@ void ActorAnimation::addHiddenItemLight(const MWWorld::ConstPtr& item, const ESM
mInsert->addChild(lightSource);
if (SceneUtil::LightListCallback* callback = findLightListCallback())
if (SceneUtil::LightListCallback* callback = mLightListCallback)
callback->getIgnoredLightSources().insert(lightSource.get());
mItemLights.insert(std::make_pair(item, lightSource));
@ -127,7 +116,7 @@ void ActorAnimation::removeHiddenItemLight(const MWWorld::ConstPtr& item)
if (iter == mItemLights.end())
return;
if (SceneUtil::LightListCallback* callback = findLightListCallback())
if (SceneUtil::LightListCallback* callback = mLightListCallback)
{
std::set<SceneUtil::LightSource*>::iterator ignoredIter = callback->getIgnoredLightSources().find(iter->second.get());
if (ignoredIter != callback->getIgnoredLightSources().end())
@ -138,18 +127,4 @@ void ActorAnimation::removeHiddenItemLight(const MWWorld::ConstPtr& item)
mItemLights.erase(iter);
}
SceneUtil::LightListCallback* ActorAnimation::findLightListCallback()
{
if (osg::Callback* callback = mObjectRoot->getCullCallback())
{
do
{
if (SceneUtil::LightListCallback* lightListCallback = dynamic_cast<SceneUtil::LightListCallback *>(callback))
return lightListCallback;
}
while ((callback = callback->getNestedCallback()));
}
return NULL;
}
}

@ -38,15 +38,10 @@ class ActorAnimation : public Animation, public MWWorld::ContainerStoreListener
virtual void itemAdded(const MWWorld::ConstPtr& item, int count);
virtual void itemRemoved(const MWWorld::ConstPtr& item, int count);
protected:
virtual void objectRootReset();
private:
void addHiddenItemLight(const MWWorld::ConstPtr& item, const ESM::Light* esmLight);
void removeHiddenItemLight(const MWWorld::ConstPtr& item);
SceneUtil::LightListCallback* findLightListCallback();
typedef std::map<MWWorld::ConstPtr, osg::ref_ptr<SceneUtil::LightSource> > ItemLightMap;
ItemLightMap mItemLights;

@ -429,6 +429,8 @@ namespace MWRender
{
for(size_t i = 0;i < sNumBlendMasks;i++)
mAnimationTimePtr[i].reset(new AnimationTime);
mLightListCallback = new SceneUtil::LightListCallback;
}
Animation::~Animation()
@ -1095,6 +1097,8 @@ namespace MWRender
osg::ref_ptr<osg::StateSet> previousStateset;
if (mObjectRoot)
{
if (mLightListCallback)
mObjectRoot->removeCullCallback(mLightListCallback);
previousStateset = mObjectRoot->getStateSet();
mObjectRoot->getParent(0)->removeChild(mObjectRoot);
}
@ -1150,7 +1154,9 @@ namespace MWRender
removeTriBipVisitor.remove();
}
mObjectRoot->addCullCallback(new SceneUtil::LightListCallback);
if (!mLightListCallback)
mLightListCallback = new SceneUtil::LightListCallback;
mObjectRoot->addCullCallback(mLightListCallback);
objectRootReset();
}

@ -25,6 +25,7 @@ namespace NifOsg
namespace SceneUtil
{
class LightSource;
class LightListCallback;
class Skeleton;
}
@ -273,6 +274,8 @@ protected:
float mAlpha;
osg::ref_ptr<SceneUtil::LightListCallback> mLightListCallback;
const NodeMap& getNodeMap() const;
/* Sets the appropriate animations on the bone groups based on priority.

Loading…
Cancel
Save