1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-07 12:54:00 +00:00
OpenMW/apps/openmw/mwrender/navmesh.hpp
elsid a2d596dbc7
Prepare navmesh scene asynchronously
It is expensive operation to generate new osg::Group for updated navmesh tile
which noticeably slows down main thread primarily because of
SceneManager::recreateShaders call. Move it to the preload work queue that is
used by RenderingManager. Leave to main thread only manipulations on the root
node.

Also move deallocation of no more needed data to the work queue. It's also
quite expensive operation because SceneManager::recreateShaders allocates a
new state set for each osg::Geometry. Deallocating them takes time.

Avoid creating another work item if there is existing one that is not started
yet.

Make sure results are accepted in the proper serialized order by selecting
completed work item with maximum {id, version}.
2022-04-20 23:14:31 +02:00

84 lines
1.8 KiB
C++

#ifndef OPENMW_MWRENDER_NAVMESH_H
#define OPENMW_MWRENDER_NAVMESH_H
#include <components/detournavigator/version.hpp>
#include <components/detournavigator/tileposition.hpp>
#include <components/misc/guarded.hpp>
#include <osg/ref_ptr>
#include <cstddef>
#include <map>
#include <memory>
#include <vector>
class dtNavMesh;
namespace osg
{
class Group;
class Geometry;
class StateSet;
}
namespace DetourNavigator
{
class NavMeshCacheItem;
struct Settings;
}
namespace SceneUtil
{
class WorkQueue;
}
namespace MWRender
{
class NavMesh
{
public:
explicit NavMesh(const osg::ref_ptr<osg::Group>& root, const osg::ref_ptr<SceneUtil::WorkQueue>& workQueue,
bool enabled);
~NavMesh();
bool toggle();
void update(const std::shared_ptr<Misc::ScopeGuarded<DetourNavigator::NavMeshCacheItem>>& navMesh,
std::size_t id, const DetourNavigator::Settings& settings);
void reset();
void enable();
void disable();
bool isEnabled() const
{
return mEnabled;
}
private:
struct Tile
{
DetourNavigator::Version mVersion;
osg::ref_ptr<osg::Group> mGroup;
};
struct LessByTilePosition;
struct CreateNavMeshTileGroups;
struct DeallocateCreateNavMeshTileGroups;
osg::ref_ptr<osg::Group> mRootNode;
osg::ref_ptr<SceneUtil::WorkQueue> mWorkQueue;
osg::ref_ptr<osg::StateSet> mGroupStateSet;
osg::ref_ptr<osg::StateSet> mDebugDrawStateSet;
bool mEnabled;
std::size_t mId;
DetourNavigator::Version mVersion;
std::map<DetourNavigator::TilePosition, Tile> mTiles;
std::vector<osg::ref_ptr<CreateNavMeshTileGroups>> mWorkItems;
};
}
#endif