1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-18 13:12:50 +00:00

359 Commits

Author SHA1 Message Date
Frederic Chardon
7b26058fa5 moveObject() has side effects that might invalidate iterators from mActors. Instead of iterating over mActors, make a copy of needed data and iterate over the copies. 2021-09-06 12:51:25 +02:00
fredzio
d20730458d Replace std::map with std::unordered_map for mActors and mObjects.
Use Ptr.mRef as a key instead of Ptr: it is constant for the lifetime of
the object.
2021-09-03 13:14:05 +02:00
Alexei Dobrohotov
7665ebfa67 Merge branch 'another_fix' into 'master'
Fix #6219

Closes #6219

See merge request OpenMW/openmw!1137
2021-08-16 01:15:52 +00:00
elsid
f966fdb65e Merge branch 'noweak' into 'master'
use shared_ptr inside the physics simulation to simplify the code

See merge request OpenMW/openmw!1141
2021-08-15 21:59:47 +00:00
fredzio
ec871e6bf7 Use shared_ptr instead of weak_ptr for actors handle inside the
simulation

The purpose of weak_ptr is to avoid performing the simulation on deleted
Actor by promoting it to a shared_ptr via a lock() call. This clutter
the code with a lot of branches, whereas the overwhelmingly common case is for the call to succeed.
Since the simulation is decoupled from the engine state, we can use a shared_ptr instead of a weak_ptr.
This allow us to ignore (ie not handle) the rarer case where the actor is delete from the scene. This means that the simulation
will run for one frame more than before for each actor, whereas the rest of the engine
will be ignorant of this.
2021-08-15 16:21:16 +02:00
fredzio
713f612bdb Partially revert !1046: the player is added before the scene exists, so we need to check again the grounded state, as it correctly was. 2021-08-13 18:01:16 +02:00
jvoisin
b01ef2629c Fix two Wreorder clang warnings 2021-08-13 13:59:57 +02:00
fredzio
de9ee2f196 Revert "Calls directly MovementSolver::traceDown instead of"
This reverts commit c1e50f530b6b7c229864b20ab26be284e3edec42.
2021-08-11 21:53:04 +02:00
Alexei Dobrohotov
73e83fd3d8 Merge branch 'dontcrash' into 'master'
Fix #6208 (hopefully)

Closes #6208

See merge request OpenMW/openmw!1113
2021-08-09 17:10:11 +00:00
fredzio
8e3984ae5a Clear mActors when reseting the simulation. Otherwise during next run we can try to read past the end of mActorsFrameData. 2021-08-09 14:46:41 +02:00
jvoisin
586d8684d0 Fix two coverity issues about uninitialised variables 2021-08-09 12:43:30 +02:00
psi29a
cb7a4d20dd Merge branch 'killmutex' into 'master'
Remove mutex from PtrHolder

See merge request OpenMW/openmw!1110
2021-08-08 19:45:16 +00:00
psi29a
3afa9829b3 Merge branch 'tracedown' into 'master'
Correct calls to traceDown in addActor

See merge request OpenMW/openmw!1109
2021-08-08 19:41:53 +00:00
fredzio
c1e50f530b Calls directly MovementSolver::traceDown instead of
PhysicsSystem::traceDown before inserting into mActors.

The latter does nothing until the actor is inserted into mActors.
We can't move the call after the insertion either because then
the actor is part of the simulation, and we'd have a race.
2021-08-08 18:26:35 +02:00
fredzio
b4dd9e6b4d Avoid division by zero in movementsolver when an actor is immobile and
in a storm
2021-08-08 17:19:18 +02:00
fredzio
ee09f3095f At last kill PtrHolder mutex 2021-08-08 15:05:07 +02:00
fredzio
07fa1803f7 Use btCollisionObject* instead of MWWorld::Ptr inside of Projectile
collision handling and castRay() to avoid calling getPtr(). It is a step forward
removing the mutex inside of PtrHolder.

Do the same for DeepestNotMeContactTestResultCallback. It is used
only for not-ranged combat for now, but do it anyway for parity with all
other callback. This way, once the PtrHolder mutex is gone one will not
have to worry about wether it is safe to use the callback in a specific
context.

To avoid use-after-free with projectile / projectile collision, defer deletion of projectile.
Since instead of storing a copy of target Ptr we have a pointer to its collision object,
we can't delete projectiles until after we finished iterating over the loops.
2021-08-08 15:05:07 +02:00
fredzio
e88b94d0b0 Move btCollisionObject* into PtrHolder
Remove unused function
2021-08-08 15:05:07 +02:00
fredzio
7dd5e715d7 Compute and store actor half extents. This is faster for 2 reasons:
- half extents changes when actor scale is modified, which is very rare
- we don't need to protect them by the actor mutex.
2021-08-07 13:38:24 +02:00
fredzio
bcd6541d3e Reorganize ActorFrameData members:
- constify all read-only variables
- order them so that all variables modified as aprt of the simulation
  fits in one cache line
2021-08-07 13:38:24 +02:00
fredzio
0c5cf6ec19 Store the btCollisionObject* of the object we're standing on instead of
MWWorld::Ptr:
- they are equivalent
- btCollisionObject* is readily available from the simulation, it saves
  a call to a mutex
- btCollisionObject* is smaller
2021-08-07 13:38:24 +02:00
fredzio
26d9052b8c Move the weak_ptr<Actor> outside of ActorFrameData. 2021-08-07 13:38:24 +02:00
fredzio
f68273c3c0 Remove Actor* from ActorFrameData 2021-08-07 13:38:24 +02:00
fredzio
9e911cc8b5 Introduce helper function to write back updated values inside parent Actor class 2021-08-07 13:38:24 +02:00
fredzio
b04c958410 Modify the way swimming is handled:
- compute the swimming state instead of storing it, it changes as part of the simulation and was not updated, so it was wrong anyway.
- store the swim level in ActorFrameData, it is constant per Actor so no need to compute it inside the simulation
2021-08-07 13:38:24 +02:00
fredzio
6e51a9a512 Simplify a bit the solver 2021-08-07 13:38:24 +02:00
fredzio
51514e44cc Handle jump as part of the simulation preparation (inside of
PhysicsSystem) instead of inside the simulaiton.
For mechanics, we don't care how the jump is handled, just that it will be.
2021-08-07 13:38:24 +02:00
fredzio
1bfaf353be Explicitely store all the potential states an Actor can have into the
ActActorFrameData structure. It makes it easier to reason about the
simulation (and hopefully simplify it).
Remove atomics from Actor class as a side effect.

Rename mFloatToSurface to mInert to make is explicit what it represent, not what it is used for
Store the Actor rotation (1 Vec2) instead of the whole ESM::Position (2 Vec3)
2021-08-07 13:38:24 +02:00
fredzio
9472728fa4 Do not generate data for immobile actors instead of early out from the solver 2021-08-07 13:38:24 +02:00
fredzio
bc738c5640 Use extract/insert instead of erase/emplace
When we call moveObject(), we might trigger a change of cell for the
actor, which in turn triggers updatePtr(). The erase/emplace
construct invalidate references, whereas extract/insert do not.

The reason is was working before !1075 is because we were always
"refreshing" the reference by a call to getActor().
2021-08-03 07:00:42 +02:00
psi29a
547bc4a252 Merge branch 'notonlyactors' into 'master'
Refactor the physics simulation to make it not actor centric.

See merge request OpenMW/openmw!1075
2021-07-31 23:39:22 +00:00
psi29a
a3a079acc1 Merge branch 'projstats' into 'master'
Add projectiles number to the resources stats

See merge request OpenMW/openmw!1074
2021-07-31 23:12:14 +00:00
psi29a
4c5e6beb75 Merge branch 'canyouseeme' into 'master'
Solve actor awareness check without async physics

See merge request OpenMW/openmw!1071
2021-07-31 22:18:35 +00:00
fredzio
35928cf4d3 Refactor a bit the physics simulation to make it not actor centric:
- inline PhysicsSystem::applyQueuedMovements() into PhysicsSystem::stepSimulation()
- rename PhysicsTaskScheduler::moveActors() to PhysicsTaskScheduler::applyQueuedMovements()
- move the actor movement code from World::doPhysics() to
  PhysicsSystem::moveActors() (analogically to the projectile manager)
2021-07-31 23:39:04 +02:00
fredzio
c76387162b Add projectiles number to the resources stats 2021-07-31 23:08:50 +02:00
fredzio
88a5ca440b Change moveObject() to take a osg::Vec3f argument instead of 3 floats
for readability.
2021-07-30 23:24:49 +02:00
fredzio
4e7c128d25 The LOS cache is now unconditionally used without async physics as well
with a TTL of 0 frame. It helps performance when several subsystems
request the same LOS in the same frame (combat, headtracking, etc).
Except it doesn't work if the cache is never trimmed.
2021-07-30 22:23:42 +02:00
fredzio
7145ef4ce0 Update AABB also in sync cases 2021-07-25 18:00:48 +02:00
psi29a
2eea590762 Merge branch 'spawn_fix' into 'master'
Fix #6173

Closes #6173

See merge request OpenMW/openmw!1046
2021-07-24 12:04:20 +00:00
fredzio
f348b70733 Set mCanWaterWalk and mOnGround when adding Actor to the scene.
mCanWaterWalk was set to false and updated during next frame's simulation
mOnGround is set to true but then was updated as part of the scene
loading logic.
2021-07-23 18:04:58 +02:00
psi29a
469cc44ef7 Merge branch 'tweaks' into 'master'
Change settings for async physics

See merge request OpenMW/openmw!778
2021-07-22 07:18:41 +00:00
fredzio
44f822da56 Do not store a btTransform into Projectile class: reduce its size by 112 bytes 2021-07-17 13:11:41 +02:00
fredzio
f02d01ef0c Do not store btTransform into Object class: reduce its size by 104 bytes 2021-07-17 13:11:41 +02:00
fredzio
62ef708910 Do not store a btTransform into Actor class: reduce its size by 128 bytes 2021-07-17 13:11:39 +02:00
psi29a
6d08a1d731 Merge branch 'skip_async' into 'master'
Don't put player in the air after going out of tcl

See merge request OpenMW/openmw!1009
2021-07-16 07:50:26 +00:00
fredzio
1650dabed8 Assign the return value of weak_ptr::lock() to a variable, so that the
shared object lifetime is properly extended. Otherwise there is a
possibility that the Actor gets destroyed during call to unstuck().
2021-07-11 18:01:20 +02:00
fredzio
643a64cb2f Change some settings for async physics:
- default to 1 thread
- default to always use defered aabb update, remove option
- always keep a cache of LOS request for at least the current frame.
This decreases number of raycast, especially when a lot of actors are
involved and "NPCs avoid collisions" is on
2021-07-11 17:07:39 +02:00
fredzio
6ad2cf8e4f Skip simulation result after calling Actor::updatePosition(). Otherwise
when going out of tcl the player would go back to previous position for
one frame.
2021-07-11 16:42:45 +02:00
Evil Eye
0a15d7740a Delay physics for objects created by scripts 2021-07-05 18:34:06 +02:00
Evil Eye
4f264af5a9 Merge branch 'staticsload' into 'master'
Loads statics before actors II (#5379)

See merge request OpenMW/openmw!588
2021-06-28 20:25:51 +00:00