Commit Graph

121 Commits (a854a6e04a8437d74078906d1d1720c0649e4e6f)

Author SHA1 Message Date
Bo Svensson a854a6e04a
removes UnrefQueue (#3181)
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`.
3 years ago
elsid 7c5a590890
Replace float type for arguments to create heightfield with int
To reduce amount of computations on the caller side and restrict possible
values.

* verts can't be non-int because it's a number of things.
* worldsize is initially defined as int by ESM::Land::REAL_SIZE.
* Put function to calculate heightfied shift into components to be able to
  reuse by other binaries.
3 years ago
Frederic Chardon 499b161e7b Merge handleFall() and updateMechanics() into updateActor(). It remove gratuitious differences between sync and async cases. Also, it will make the after simulation update logic easier to follow when projectiles move into the simulation thread. 3 years ago
psi29a bd866cf210 Merge branch 'fix_infidelities' into 'master'
Fix Infidelities quest from Tribunal (#6307)

Closes #6307

See merge request OpenMW/openmw!1248
3 years ago
Bret Curtis 8309910d9d Restore the cell grid to its former non-exorbitant size, reducing stutter and also threw in a simple alternative fix for the actor position adjustment issue. 3 years ago
elsid c0ef4417c3
Check AiTravel destination for other actors presence
Use faster aabbTest but without destance filter. To avoid dependency on a
specific constant and correctly handle situations when there is a big
difference between actors sizes.
3 years ago
Petr Mikheev e760a6c7e6 Merge branch 'forlua' into 'master'
Simple Physics API modification for Lua

See merge request OpenMW/openmw!1216

(cherry picked from commit d88494c90b501d0832ae0330a0ca81d8b8e5aa50)

02dd055a Save hitObject in castSphere() just like in castRay()
0793d0bf Allow to override collision mask and group for castSphere() as for castRay()
3 years ago
psi29a 2cee222e73 Merge branch 'explosion_at_impact' into 'master'
Bring arrow behaviour in line with vanilla (#6233 and other change)

See merge request OpenMW/openmw!1188
3 years ago
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.
3 years ago
fredzio 0bce6c09e1 Change projectile behaviour to be like in vanilla wrt. water plane:
- enchanted arrow explode upon hit the water plane
- non enchanted arrow disappear (or more accurately, they hit nothingness)
- enchanted arrow shot underwater explode immediately
- non enchanted arrow disappear immediately

Also, solve a bug that occured previously and could theoritically still happens where we use the last tested collision position for instead of the last registered hit:
Use the hit position as saved inside Projectile::hit() instead of the last position saved inside the callback.
If a projectile collides with several objects (bottom of the sea and water surface for instance), the last collision tested won't necessarily be the impact position as we have no control over the order in which the tests are performed.
3 years ago
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.
3 years ago
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
3 years ago
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
3 years ago
fredzio 26d9052b8c Move the weak_ptr<Actor> outside of ActorFrameData. 3 years ago
fredzio f68273c3c0 Remove Actor* from ActorFrameData 3 years ago
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
3 years ago
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.
3 years ago
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)
3 years ago
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)
3 years ago
Evil Eye 4f264af5a9 Merge branch 'staticsload' into 'master'
Loads statics before actors II (#5379)

See merge request OpenMW/openmw!588
3 years ago
fredzio c795e0bce6 Some actors are supposed to spawn on an object that belongs to an adjacent cell.
Since actors can be active in 3x3 grid around the player, we need to
first load all objects in a 5x5 grid around the player.

Split load and unloading in 2 phases. Add an mInactiveCells set into the
scene, which contains all cells inside the aforementioned 5x5 grid.
These cells contains only heightfields and non-animated physics objects.

Animated objects are tied to the scene graph, which doesn't exists yet
in these cells, so we skip them.
3 years ago
jvoisin 1123dc46ee Add a ton of const refs 3 years ago
fredzio 5b63019719 Embed actor velocity inside its class. It makes the code simpler. 3 years ago
fredzio 4fa0972b2d Tone down actor's skip simulation flag to an optional skip collision
detection flag.
3 years ago
fredzio 6e1c67a9ae Account for waterwalking when updating position. Otherwise we might
trace down the actor at waterlevel at the wrong coordinate.

Triggered by multimark mod with waterwalking effect.
3 years ago
fredzio dbd6e3bfee Replace pointless usage of shared_ptr by unique_ptr / non-owning raw
pointer for btCollisionWorld.
3 years ago
wareya 63f01d8c5f Prevent physics death spiral by falling back to true delta time when needed 3 years ago
Alexei Dobrohotov 2bfee281fd Merge branch 'restore_caster' into 'master'
Restore projectile caster from savegame (#5860)

See merge request OpenMW/openmw!616

(cherry picked from commit d595c7adb0fb45eafed6d3d0403ad640a91411ed)

c5426bec In the savegame, projectile caster is identified by its actor id. When
3 years ago
psi29a 59e09cba5b Merge branch 'boltsize' into 'master'
Use projectile mesh size (#5829)

See merge request OpenMW/openmw!587
3 years ago
fredzio 6e969ca3fa Use mesh collision box instead of node bounding sphere for projectile
size. The bounding sphere is much bigger than the mesh.
3 years ago
Andrei Kortunov 7b727e4d70 Revert "Remove physics dependency on basenode"
This reverts commit 165c731492.
3 years ago
Andrei Kortunov 165af1c365 Revert "Some actors are supposed to spawn on a static object that belong to an adjacent cell."
This reverts commit f031a191b8.
3 years ago
fredzio f031a191b8 Some actors are supposed to spawn on a static object that belong to an adjacent cell.
Since actors can be active in 3x3 grid around the player, we need to
first load all statics in a 5x5 grid around the player.

Split load and unloading in 2 phases. Add an mInactiveCells set into the
scene, which contains all cells inside the aforementioned 5x5 grid.
These cells contains only heightfields and physics objects of static
class.
3 years ago
fredzio 165c731492 Remove physics dependency on basenode
Necessary to be able to load physics objects from inactive cells.
3 years ago
fredzio 1f4c85520f Use convexSweepTest for projectile movement to solve any
imprecision issue with projectile collision detection.
Simplify the mechanics: manage hits in one spot.
Give magic projectiles a collision shape similar in size to their visible
model.

Rename the 2 convex result callback to clearly state their purpose.
3 years ago
fredzio d015f17a6c Make all physics object manage their own resources
Use smart pointer for heightfields and their members.
Move collision object addition inside of Object's ctor, as for Actors and HeightFields
3 years ago
Alexei Dobrohotov 22476281da Fix paralyze for swimming actors 3 years ago
fredzio 5bd921fa3a Restore pre-async handling of absolute actors positionning
One of the issue since the introduction of async physics is the quirky
handling of scripted moves. Previous attempt to account for them was
based on detecting changes in actor position while the physics thread is
running. To this end, semantics of Actor::updatePosition() (which is
responsible for set the absolute position of an actor in the world) was
toned down to merely store the desired position, with the physics system
actually responsible for moving the actor. For the cases were complete
override of the physics simulation was needed, I introduced
Actor::resetPosition(), which actually have same semantics as
original updatePosition(). This in turn introduced a loads of new bugs
when the weakened semantics broke key assumptions inside the engine
(spawning, summoning, teleport, etc).
Instead of tracking them down, count on the newly introduced support for
object relative movements in the engine (World::moveObjectBy) to
register relative movements and restore original handling of absolute positionning.

Changes are relatively small:
- move resetPosition() content into updatePosition()
- call updatePosition() everywhere it was called before
- remove all added calls to the now non-existing resetPosition()

tldr; ditch last month worth of bug introduction and eradication and redo
it properly
3 years ago
fredzio 8e084dea2e Don't cache Ptr, it can be updated while the simulation is running. 3 years ago
fredzio 4e7c9b6696 Embed physics simulation results inside of actor class.
This gives finer control over reseting positions (switch off tcl is no
longer glitchy) and solve most of the erroneous usage of stale World::Ptr
indicated by:
"Error in frame: moveTo: object is not in this cell"
3 years ago
fredzio 4fbe1ed12c Ignore caster collision shape. Sometimes the magic bolt get launched
inside too near its caster.
3 years ago
fredzio 66fe3b0d38 Modify projectile collision to work with async physics 3 years ago
Andrei Kortunov dc7b48e92e Generate physics collisions for projectiles (bug #3372)
Remove redundant now mHit field
3 years ago
fredzio 7843dad35d Don't let the actor "nowhere" after a teleport but move them in their
place.
This solve the problem where after loading, an empty frame was rendered
because the player is "nowhere".
4 years ago
fredzio ea2ba27084 Move the moment when the actor origin is saved before simulation so to
be sure the simulation is over. Otherwise, if the simulation is too slow
the position is wrong, and the actors would jump back and forth between
old and new position instead of actually moving.
4 years ago
Frederic Chardon 9aba55a21a Add the async physics worker to the profiler overlay. 4 years ago
fredzio d64ed6cf53 Get rid of the StandingActorsMap. Just embed the necessary info into
Actor class.
4 years ago
fredzio e5fa457fe7 Properly account for interleaved move of actors.
Before this change, if an actor position was changed while the physics
simulation was running, the simulation result would be discarded. It is
fine in case of one off event such as teleport, but in the case of
scripts making use of this functionality to make lifts or conveyor (such
as Sotha Sil Expanded mod) it broke actor movement.

To alleviate this issue, at the end of the simulation, the position of the Actor
in the world is compared to the position it had at the beginning of the
simulation. A difference indicate a force move occured. In this case,
the Actor mPosition and mPreviousPosition are translated by the difference of position.

Since the Actor position will be really set while the next simulation runs, we
save it in the mNextPosition field.
4 years ago
fredzio 18e38d8810 Do not block a door when it turns away. 4 years ago
fredzio 435b2e37f8 Allow to display collision points in the debug viewer 4 years ago