With this PR we refactor `StringUtils::replaceAll` to accept `string_view` as suggested in a code comment. In addition, while we are touching this rebuild happy file, we slim it down a bit by moving a few sparingly used functions elsewhere.
This PR removes dummy serialisers for `StateSetUpdater`, `NodeCallback` and the respective `META` macros that trigger serialisation requirement here.
`StateSetUpdater` and `NodeCallback` are just base classes that can not be used on their own, so there is no need to incorporate them into serialisation. These changes might have minor effects on derived classes that forget to override `className()`, `libraryName()` through `META`, but it makes hardly a difference to now serialise such classes as a dysfunctional `osg::Callback` instead of a dysfunctional `SceneUtil::NodeCallback`.
We currently apply a strange algorithm to `LightManager::mStateSetCache`. For some reason this algorithm inserts hashed keys into `std::map` in a way that fails to handle hash collisions and exhibits worse lookup complexity than `std::unordered_map`. With this PR we just use `std::unordered_map` here.
With this PR we apply `lightMask` to a `Transform` node we create specifically for a light. This mask will allow us to stop traversing such nodes sooner and avoid costly processing associated with `Transform` nodes in the cull visitor.
With this PR we refactor `SceneUtil::KeyframeController` not to require `virtual osg::Callback` inheritance. I suppose such `virtual` overhead is not justified here because it negatively impacts many other classes we derive from `osg::Callback`.
This PR aims to spark the retirement of a questionable pattern I have found all over our code base. I will illustrate how this pattern encourages code duplication, lacks type safety, requires documentation and can be prone to bugs.
```
std::map<std::string, Object> mMap; // Stored in all lowercase for a case-insensitive lookup
std::string lowerKey = Misc::StringUtils::lowerCase(key);
mMap.emplace(lowerKey, object);
std::string lowerKey = Misc::StringUtils::lowerCase(key);
mMap.find(lowerKey);
mMap.find(key); // Not found. Oops!
```
An alternative approach produces no such issues.
```
std::unordered_map<std::string, Object, Misc::StringUtils::CiHash, Misc::StringUtils::CiEqual> mMap;
mMap.emplace(key, object);
mMap.find(key);
```
Of course, such an alternative will work for a `map` as well, but an `unordered_map` is generally preferable over a `map` with these changes because we have moved `lowerCase` into the comparison operator.
In this PR I have refactored `Animation::mNodeMap` accordingly. I have reviewed and adapted all direct and indirect usage of `Animation::mNodeMap` to ensure we do not change behaviour with this PR.
This PR fixes a crash caused by the improperly ensured lifetime of RigGeometry::mSourceGeometry. mSourceGeometry was not adequate to ensure mSourceGeometry would outlive mGeometry because we extend mGeometrys lifetime beyond this lifetime by passing mGeometry to the draw traversal instead of this.
In addition,
We add important comments.
We detect and prevent generally unsafe operations in high level code.
We add a sprinkling of const to help clarify intentions.
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`.
This variable is only used in ShadowsBin constructor and it's initialized each
time before constructor call so required value can be just passed into
ShadowsBin ctor.
Make ShadowsBin default constructor private because it is required by osg even
it's not actually called.
This PR proposes a simple change to `RigGeometry` `dirtyGLObjects` logic.
1. We will avoid dirtying unmodified arrays.
2. We can drop an osg version guard since `Drawable::dirtyGLObjects` is not nearly as harmful as `Geometry::dirtyGLObjects`.
3. We will avoid crashes in an as yet unfinished future PR concerning `Array` sharing improvements.
osg::NodeVisitor is designed to recursively call virtual apply signatures until we find an implemented signature. Encountered nodes that we do not explicitely handle will trigger additional virtual function calls. With this PR we avoid these additional virtual function calls in the particularly costly ComputeLightSpaceBounds by adding some explicit signatures.
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.
We skip this during node path iterations. this is not a node we are interested in.
We avoid allocating a new mGeomToSkelMatrix per frame and avoid a ref_ptr associated with its update.
We speed up a search for the Skeleton node by adding a continue; condition prior to an expensive dynamic_cast.
We can expect marginally improved loading times with this PR. Drawable, Transform and Node counts in stats panels are expected to remain unchanged - this PR does not add new scene graph optimisations, it just increases the speed with which we apply existing ones.
1. We add explicit `NodeVisitor::apply` overrides for commonly encountered node types to avoid additional virtual function calls per node associated with the default `apply` implementation.
2. We skip pushing `StateSet`s when `_mergeAlphaBlending` is enabled or the `StateSet` contains no relevant state.
3. We add a specialised variant of `CollectLowestTransformsVisitor::addTransform` accepting `MatrixTransform` to avoid matrix copies and multiplications.
With this PR we optimise a function that is called quite often when loading new cells.
We remove avoidable dynamic_casts.
We remove an unused pair.second element.
We convert a map to an unordered_map because its ordering is irrelevant in this case.
We avoid adding the root Skeleton node to the bones' node path.
Currently, we create a new ComputeLightSpaceBounds visitor per frame. Within this visitor, we require excessive memory allocations, mainly a new osg::RefMatrix per encountered Transform node.
With this PR we reuse a single ComputeLightSpaceBounds visitor across frames and enable the createOrReuseMatrix functionality to avoid allocating new matrices every frame. osgUtil::CullVisitor internally uses the same approach.
Currently, we run culling tests against all lights in the scene during LightListCallback::pushLightState. We can avoid most of these tests by removing off-screen lights at an earlier stage. We should benchmark the cumulative time spent within LightListCallback::pushLightState before and after this PR.
`handle_stateset` is not needed because `UpdateMatrixTransform` is a `NodeCallback` only allowed to be set on a `Node`. `Geode` and `Drawable` do not need explicit logic because they are both derived from `Node`.
(cherry picked from commit 496b3aef88b8fd867dcdd23a6ca43144573b1b2f)
Stereo friendly water
(cherry picked from commit 0e22c55e48a7f965367d3d430c1bef5357b22748)
Option to disable per view mapping.
Include memory header
De-hardcode settings and buffers.
formatting error
Update water.cpp (whitespace)
Update water.cpp (more whitespace)
include render order
c array -> c++ array
To make sure RecastMesh objects are equal if built with the same data but in
different order. Will be used later when there will be more than one place
building RecasMesh objects.
Instead of explicit work queue stop before any possibly used engine manager
is destructed. Based on an assumption that any engine manager can be destructed
independently from the work queue destruction. This model is already used in
CellPreloader that conflicts with explicit work queue stop.
After the work queue is requested to be stopped, any client waiting for a not
started work item to be done will wait forever because the work item is dropped
from the queue. Therefore either clients should not wait for own work items to
be completed in destructor or the work queue should not drop items before
clients are destructed. Other approaches are possible but are not considered
due to increasing complexity.
CellPreloader already tries to wait for all created work items to be done so
keep it that way and extend the model to AsyncScreenCaptureOperation and Scene.
Additionally abort all scheduled work items when owner is destructed. This
prevents a long exit when multiple screenshots are scheduled right before
exiting the game.
Show message about saved screenshot via schedule message box. Since screenshot
saving happens not in the main thread calling messageBox directly is unsafe.
WindowManager::scheduleMessageBox delays message box showing until next update
in the main thread.
Before this change LightBuffer copy constructor copied only mData pointer into
a new object. Then memcpy was applied to an overlapping source and destination
that is UB.
Replace configureLayout function by a special constructor. That copies all
mData values and a pointer to a buffer object into a newly allocated object.
When game exit is requests when initial loading screen is active LightManager
can be destructed in the main thread before LightManagerStateAttribute::apply
is completed by different thread. Given that it uses raw pointer at some point
it becomes dangling because object is destructed this leads to UB and eventual
SIGSEGV.
Fixes build errors with older OSG builds and some issues with 'shared' layout.
Bring back ambient in inventory through lightmodel instead of sun ambient, mirrors scene ambient/sunlight relationship.
Forces shaders when certain lighting methods are enabled and finalize settings.
Correctly override sun for localmap.
The docs seem to imply this is automatic when the array contains a
class-type, which osg::ref_ptr is, but I got a crash log that doesn't
make sense if that's true.
Previously, it would edit the odd numbered stateset, then regenerate
shaders for the even-numbered one, then edit the even numbered one, and
regenerate shaders for the odd numbered one (or vice versa if it
finished during an even numbered frame). This would leave one of the
shader programs still trying to use the state that had been removed.
As we don't reconfigure all shaders without shadows when we disable them
indoors (as it'd probably add a hitch to transitioning in and out) we
need to set up dummy state so the shaders don't do anything illegal.
This hadn't had symptoms for most objects as when indoors, nearly
everything would be drawn first in one of the water RTTs, which had
dummy state to disable shadows already. This wasn't true of the water
plane itself, though, yet somehow it took until just now for anyone to
report that.
This resolves vtastek's issue where the water would be invisible indoors
Make sure it copies all relevant drawable parent nodes (e.g. including the node with the environment map effect)
Make sure it doesn't copy nodes multiple times
Properly apply transformations to both switch and LOD nodes
Allow both NiSwitchNode and NiLODNode to be the root node
Properly add CollisionSwitch into the scene graph
Previously we always discarded shadow map fragments if the alpha channel of the output would have been low, but there were some (modded) assets that have non-one alpha but have testing or blending disabled so end up opaque anyway. This lets the shadows of those objects match.
/home/elsid/dev/openmw/components/sceneutil/mwshadowtechnique.cpp:3127:9: warning: Call to virtual function during construction [clang-analyzer-optin.cplusplus.VirtualCall]
addAnotherShadowMap();
^
/home/elsid/dev/openmw/components/sceneutil/mwshadowtechnique.cpp:3094:5: note: Loop condition is true. Entering loop body
for (int i = 0; i < 2; ++i)
^
/home/elsid/dev/openmw/components/sceneutil/mwshadowtechnique.cpp:3094:5: note: Loop condition is true. Entering loop body
/home/elsid/dev/openmw/components/sceneutil/mwshadowtechnique.cpp:3094:5: note: Loop condition is false. Execution continues on line 3102
/home/elsid/dev/openmw/components/sceneutil/mwshadowtechnique.cpp:3126:21: note: Assuming 'i' is < 'numberOfShadowMapsPerLight'
for (int i = 0; i < numberOfShadowMapsPerLight; ++i)
^
/home/elsid/dev/openmw/components/sceneutil/mwshadowtechnique.cpp:3126:5: note: Loop condition is true. Entering loop body
for (int i = 0; i < numberOfShadowMapsPerLight; ++i)
^
/home/elsid/dev/openmw/components/sceneutil/mwshadowtechnique.cpp:3127:9: note: This constructor of an object of type 'DebugHUD' has not returned when the virtual method was called
addAnotherShadowMap();
^
/home/elsid/dev/openmw/components/sceneutil/mwshadowtechnique.cpp:3127:9: note: Call to virtual function during construction
/home/elsid/dev/openmw/components/sceneutil/shadow.cpp💯9: warning: Call to virtual function during construction [clang-analyzer-optin.cplusplus.VirtualCall]
setupShadowSettings();
^
/home/elsid/dev/openmw/components/sceneutil/shadow.cpp💯9: note: This constructor of an object of type 'ShadowManager' has not returned when the virtual method was called
/home/elsid/dev/openmw/components/sceneutil/shadow.cpp💯9: note: Call to virtual function during construction
/home/elsid/dev/openmw/components/sceneutil/shadow.cpp:104:9: warning: Call to virtual function during construction [clang-analyzer-optin.cplusplus.VirtualCall]
enableOutdoorMode();
^
/home/elsid/dev/openmw/components/sceneutil/shadow.cpp:104:9: note: This constructor of an object of type 'ShadowManager' has not returned when the virtual method was called
/home/elsid/dev/openmw/components/sceneutil/shadow.cpp:104:9: note: Call to virtual function during construction