Files
Bret Curtis d69b861fcb Restore TemplateRef as a nameable marker for scene dumps
Deleting the wrapper missed that it had a second job: being a type serialize.cpp could ignore by name, which a bare osg::Object parked in a user data container cannot be singled out for. Without it a scene dump hoists the entire template subtree into the user-data block and demotes the node's real children to bare UniqueID back-references, and no blunt filter can fix that because the same containers carry shaderPrefix, recordIndex and fileHash value objects that the dump should keep. TemplateMultiRef stays gone, the eight call sites still share one addTemplateRef helper that ignores a null template, and holding a ref_ptr<const osg::Object> means no call site needs a const_cast any more.
2026-09-20 12:18:52 +02:00

45 lines
1.4 KiB
C++

#ifndef OPENMW_COMPONENTS_SCENEUTIL_TEMPLATEREF_H
#define OPENMW_COMPONENTS_SCENEUTIL_TEMPLATEREF_H
#include <osg/CopyOp>
#include <osg/Object>
#include <osg/UserDataContainer>
#include <osg/ref_ptr>
namespace SceneUtil
{
/// Holds a reference to the object a shallow copy was made from, so the template outlives everything copied from
/// it and a cache holding the template still sees it as in use. The wrapper is what makes that reference nameable:
/// serialize.cpp ignores "SceneUtil::TemplateRef" so scene dumps skip the template, which a bare osg::Object
/// parked in a user data container could not be singled out for. Nothing ever reads the reference back out.
class TemplateRef : public osg::Object
{
public:
TemplateRef() = default;
explicit TemplateRef(const osg::Object* object)
: mObject(object)
{
}
TemplateRef(const TemplateRef& copy, const osg::CopyOp&)
: mObject(copy.mObject)
{
}
META_Object(SceneUtil, TemplateRef)
private:
osg::ref_ptr<const osg::Object> mObject;
};
/// Pin @a tmpl's lifetime to @a derived's. Call after a shallow copy; a null template is ignored.
inline void addTemplateRef(osg::Object& derived, const osg::Object* tmpl)
{
if (tmpl != nullptr)
derived.getOrCreateUserDataContainer()->addUserObject(new TemplateRef(tmpl));
}
}
#endif