This PR aims to solve all issues with `Groundcover` view distance handling in a satisfying way while preserving other optimisations that benefit other features. The main idea here is not to rely on `ViewData` updates for distance culling calculations because we can not accurately determine distance against lazily updated views. Instead, we perform an accurate measurement in a cull callback we can run every frame in `Groundcover` itself. While we do have to add some code to handle this feature, it is quite loosely coupled code that could be useful elsewhere in the future. These changes should address a performance regression @akortunov experienced.
I have been informed by @akortunov that my addition of `Groundcover::getViewDistance` is not working in some cases. Investigations revealed that some `ViewData` code interacting with my additions had been quite thoroughly optimised in a way that was not sufficiently documented and interfered with the new feature. With this PR we repair `getViewDistance` while preserving such optimisations and add a necessary comment to avoid issues in the future. In addition, we now rebuild views when the global `mViewDistance` changes.
This PR fixes a recent regression concerning enable and disable commands with object paging. In addition, we add a necessary comment to avoid such issues in the future.
Currently, we use an `UnrefQueue` which supposedly aims to transfer destruction costs to another thread. The implications of this unusual pattern can not be well understood because some allocators might free resources more efficiently if they are freed by the same thread that allocated them. In addition, `UnrefQueue` complicates the validation of thread safety in our engine. Lastly, our current usage of `UnrefQueue` triggers `ref()`, `unref()` atomic operations as objects are passed into the queue. These operations could be more expensive than the actual destruction.
With this PR we thus remove `UnrefQueue`. We can expect these changes to have a minor impact at most because we free most resources elsewhere in `ResourceSystem::updateCache`.
Currently, we disable a paging root node that we only need in exterior cells by setting its node mask to 0 when transitioning into an interior cell. Node masks are not ideal for this usage case because Node::getBound is unaware of masks. With this PR we just detach the unused node from the scene graph. _shadowedScene->getBound() in the MWShadowTechnique should return a much better value in interior cells with these changes.
Currently, we always traverse the scene graph an additional time with a ComputeLightSpaceBounds visitor during shadow casting. ComputeLightSpaceBounds is only useful when the shadow casting mask allows us to shrink the bounds of the rendered scene, so we guard its traversal with a check against getCastsShadowTraversalMask. In practice, this guard never works because we build the traversal mask inclusively.
With this PR we limit the getCastsShadowTraversalMask check to relevant masks. This new check allows us to skip a superfluous ComputeLightSpaceBounds traversal with most settings.
Firstly, this PR reintroduces commit "Recreate a special case for IntersectionVisitor on QuadTreeWorld" we forgot to reapply while reverting a revert commit. Secondly, in cases we still need to build a view for an intersection visitor, we now use the available `osgUtil::IntersectionVisitor::getReferenceEyePoint` instead of falling back to the origin position that was previously causing long rebuild times.
This reduces average time spent on in. 5 milliseconds as a base precision is
quite a lot considering that for 60 FPS frame time is 1000/16 = ~16.67 ms
when it's a cell loading frame and there is more important work to do rather
than sleeping.
Sprinkle a couple of constexpr found by VS
See merge request OpenMW/openmw!800
(cherry picked from commit 5e8ea624bc85acebf457592dd10b790124ecf6ef)
5704b2ac Sprinkle a couple of constexpr found by VS
Move static variable declaration out of the loop
Remove redundant boolean argument from applyDrawableProperties()
Improve HeightCullCallback class formatting
/home/elsid/dev/openmw/components/terrain/terraingrid.cpp:31:9: warning: Call to virtual function during destruction [clang-analyzer-optin.cplusplus.VirtualCall]
unloadCell(mGrid.begin()->first.first, mGrid.begin()->first.second);
^
/home/elsid/dev/openmw/components/terrain/terraingrid.cpp:29:12: note: Assuming the condition is true
while (!mGrid.empty())
^
/home/elsid/dev/openmw/components/terrain/terraingrid.cpp:29:5: note: Loop condition is true. Entering loop body
while (!mGrid.empty())
^
/home/elsid/dev/openmw/components/terrain/terraingrid.cpp:31:9: note: This destructor of an object of type '~TerrainGrid' has not returned when the virtual method was called
unloadCell(mGrid.begin()->first.first, mGrid.begin()->first.second);
^
/home/elsid/dev/openmw/components/terrain/terraingrid.cpp:31:9: note: Call to virtual function during destruction