1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-02-04 03:40:14 +00:00

Use ranged for loops in GenericObjectCache

This commit is contained in:
elsid 2023-12-25 14:17:12 +01:00
parent 2f0613c8d4
commit 7b1ee2780b
No known key found for this signature in database
GPG Key ID: 4DE04C198CBA7625

View File

@ -139,26 +139,18 @@ namespace Resource
void releaseGLObjects(osg::State* state) void releaseGLObjects(osg::State* state)
{ {
std::lock_guard<std::mutex> lock(_objectCacheMutex); std::lock_guard<std::mutex> lock(_objectCacheMutex);
for (typename ObjectCacheMap::iterator itr = _objectCache.begin(); itr != _objectCache.end(); ++itr) for (const auto& [k, v] : _objectCache)
{ v.mValue->releaseGLObjects(state);
osg::Object* object = itr->second.mValue.get();
object->releaseGLObjects(state);
}
} }
/** call node->accept(nv); for all nodes in the objectCache. */ /** call node->accept(nv); for all nodes in the objectCache. */
void accept(osg::NodeVisitor& nv) void accept(osg::NodeVisitor& nv)
{ {
std::lock_guard<std::mutex> lock(_objectCacheMutex); std::lock_guard<std::mutex> lock(_objectCacheMutex);
for (typename ObjectCacheMap::iterator itr = _objectCache.begin(); itr != _objectCache.end(); ++itr) for (const auto& [k, v] : _objectCache)
{ if (osg::Object* const object = v.mValue.get())
if (osg::Object* object = itr->second.mValue.get()) if (osg::Node* const node = dynamic_cast<osg::Node*>(object))
{
osg::Node* node = dynamic_cast<osg::Node*>(object);
if (node)
node->accept(nv); node->accept(nv);
}
}
} }
/** call operator()(KeyType, osg::Object*) for each object in the cache. */ /** call operator()(KeyType, osg::Object*) for each object in the cache. */
@ -166,8 +158,8 @@ namespace Resource
void call(Functor&& f) void call(Functor&& f)
{ {
std::lock_guard<std::mutex> lock(_objectCacheMutex); std::lock_guard<std::mutex> lock(_objectCacheMutex);
for (typename ObjectCacheMap::iterator it = _objectCache.begin(); it != _objectCache.end(); ++it) for (const auto& [k, v] : _objectCache)
f(it->first, it->second.mValue.get()); f(k, v.mValue.get());
} }
/** Get the number of objects in the cache. */ /** Get the number of objects in the cache. */