2015-05-12 01:02:15 +00:00
|
|
|
#include "actor.hpp"
|
|
|
|
|
2017-02-06 04:39:56 +00:00
|
|
|
#include <BulletCollision/CollisionShapes/btCapsuleShape.h>
|
2015-05-27 20:32:11 +00:00
|
|
|
#include <BulletCollision/CollisionShapes/btBoxShape.h>
|
2015-05-27 21:09:38 +00:00
|
|
|
#include <BulletCollision/CollisionDispatch/btCollisionWorld.h>
|
2015-05-12 01:02:15 +00:00
|
|
|
|
2015-11-20 20:57:04 +00:00
|
|
|
#include <components/sceneutil/positionattitudetransform.hpp>
|
2015-11-16 22:30:10 +00:00
|
|
|
#include <components/resource/bulletshape.hpp>
|
2018-10-22 11:14:25 +00:00
|
|
|
#include <components/debug/debuglog.hpp>
|
2019-02-28 20:03:42 +00:00
|
|
|
#include <components/misc/convert.hpp>
|
2015-05-12 01:02:15 +00:00
|
|
|
|
2015-05-27 20:32:11 +00:00
|
|
|
#include "../mwworld/class.hpp"
|
|
|
|
|
2015-05-12 01:02:15 +00:00
|
|
|
#include "collisiontype.hpp"
|
Process movement queue in one or several background threads
Before movement calculation, the main thread prepare a
vector of ActorFrameData, which contains all data necessary to perform
the simulation, and feed it to the solver. At the same time it fetches
the result from the previous background simulation, which in turn is
used by the game mechanics.
Other functions of the physics system (weapon hit for instance)
interrupt the background simulation, with some exceptions described
below.
The number of threads is controlled by the numeric setting
[Physics]
async num threads
In case 'async num threads' > 1 and Bullet doesn't support multiple threads,
1 async thread will be used. 0 means synchronous solver.
Additional settings (will be silently switched off if async num threads = 0)
[Physics]
defer aabb update
Update AABBs of actors and objects in the background thread(s). It is not an especially
costly operation, but it needs exclusive access to the collision world, which blocks
other operations. Since AABB needs to be updated for collision detection, one can queue
them to defer update before start of the movement solver. Extensive tests on as much
as one installation (mine) show no drawback having that switched on.
[Physics]
lineofsight keep inactive cache
Control for how long (how many frames) the line of sight (LOS) request will be kept updated.
When a request for LOS is made for the first time, the background threads are stopped to
service it. From now on, the LOS will be refreshed preemptively as part of the background
routine until it is not required for lineofsight keep inactive cache frames. This mean
that subsequent request will not interrupt the background computation.
2020-10-15 04:11:44 +00:00
|
|
|
#include "mtphysics.hpp"
|
2015-05-12 01:02:15 +00:00
|
|
|
|
|
|
|
namespace MWPhysics
|
|
|
|
{
|
|
|
|
|
|
|
|
|
Process movement queue in one or several background threads
Before movement calculation, the main thread prepare a
vector of ActorFrameData, which contains all data necessary to perform
the simulation, and feed it to the solver. At the same time it fetches
the result from the previous background simulation, which in turn is
used by the game mechanics.
Other functions of the physics system (weapon hit for instance)
interrupt the background simulation, with some exceptions described
below.
The number of threads is controlled by the numeric setting
[Physics]
async num threads
In case 'async num threads' > 1 and Bullet doesn't support multiple threads,
1 async thread will be used. 0 means synchronous solver.
Additional settings (will be silently switched off if async num threads = 0)
[Physics]
defer aabb update
Update AABBs of actors and objects in the background thread(s). It is not an especially
costly operation, but it needs exclusive access to the collision world, which blocks
other operations. Since AABB needs to be updated for collision detection, one can queue
them to defer update before start of the movement solver. Extensive tests on as much
as one installation (mine) show no drawback having that switched on.
[Physics]
lineofsight keep inactive cache
Control for how long (how many frames) the line of sight (LOS) request will be kept updated.
When a request for LOS is made for the first time, the background threads are stopped to
service it. From now on, the LOS will be refreshed preemptively as part of the background
routine until it is not required for lineofsight keep inactive cache frames. This mean
that subsequent request will not interrupt the background computation.
2020-10-15 04:11:44 +00:00
|
|
|
Actor::Actor(const MWWorld::Ptr& ptr, const Resource::BulletShape* shape, PhysicsTaskScheduler* scheduler)
|
2020-11-07 17:30:52 +00:00
|
|
|
: mStandingOnPtr(nullptr), mCanWaterWalk(false), mWalkingOnWater(false)
|
2020-10-14 09:32:12 +00:00
|
|
|
, mCollisionObject(nullptr), mMeshTranslation(shape->mCollisionBoxTranslate), mHalfExtents(shape->mCollisionBoxHalfExtents)
|
|
|
|
, mForce(0.f, 0.f, 0.f), mOnGround(true), mOnSlope(false)
|
2015-05-12 01:02:15 +00:00
|
|
|
, mInternalCollisionMode(true)
|
|
|
|
, mExternalCollisionMode(true)
|
Process movement queue in one or several background threads
Before movement calculation, the main thread prepare a
vector of ActorFrameData, which contains all data necessary to perform
the simulation, and feed it to the solver. At the same time it fetches
the result from the previous background simulation, which in turn is
used by the game mechanics.
Other functions of the physics system (weapon hit for instance)
interrupt the background simulation, with some exceptions described
below.
The number of threads is controlled by the numeric setting
[Physics]
async num threads
In case 'async num threads' > 1 and Bullet doesn't support multiple threads,
1 async thread will be used. 0 means synchronous solver.
Additional settings (will be silently switched off if async num threads = 0)
[Physics]
defer aabb update
Update AABBs of actors and objects in the background thread(s). It is not an especially
costly operation, but it needs exclusive access to the collision world, which blocks
other operations. Since AABB needs to be updated for collision detection, one can queue
them to defer update before start of the movement solver. Extensive tests on as much
as one installation (mine) show no drawback having that switched on.
[Physics]
lineofsight keep inactive cache
Control for how long (how many frames) the line of sight (LOS) request will be kept updated.
When a request for LOS is made for the first time, the background threads are stopped to
service it. From now on, the LOS will be refreshed preemptively as part of the background
routine until it is not required for lineofsight keep inactive cache frames. This mean
that subsequent request will not interrupt the background computation.
2020-10-15 04:11:44 +00:00
|
|
|
, mTaskScheduler(scheduler)
|
2015-05-12 01:02:15 +00:00
|
|
|
{
|
|
|
|
mPtr = ptr;
|
|
|
|
|
2018-10-22 11:14:25 +00:00
|
|
|
// We can not create actor without collisions - he will fall through the ground.
|
|
|
|
// In this case we should autogenerate collision box based on mesh shape
|
|
|
|
// (NPCs have bodyparts and use a different approach)
|
|
|
|
if (!ptr.getClass().isNpc() && mHalfExtents.length2() == 0.f)
|
|
|
|
{
|
2020-10-14 09:32:12 +00:00
|
|
|
if (shape->mCollisionShape)
|
2018-10-22 11:14:25 +00:00
|
|
|
{
|
|
|
|
btTransform transform;
|
|
|
|
transform.setIdentity();
|
|
|
|
btVector3 min;
|
|
|
|
btVector3 max;
|
|
|
|
|
2020-10-14 09:32:12 +00:00
|
|
|
shape->mCollisionShape->getAabb(transform, min, max);
|
2018-10-22 11:14:25 +00:00
|
|
|
mHalfExtents.x() = (max[0] - min[0])/2.f;
|
|
|
|
mHalfExtents.y() = (max[1] - min[1])/2.f;
|
|
|
|
mHalfExtents.z() = (max[2] - min[2])/2.f;
|
|
|
|
|
|
|
|
mMeshTranslation = osg::Vec3f(0.f, 0.f, mHalfExtents.z());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mHalfExtents.length2() == 0.f)
|
|
|
|
Log(Debug::Error) << "Error: Failed to calculate bounding box for actor \"" << ptr.getCellRef().getRefId() << "\".";
|
|
|
|
}
|
|
|
|
|
2015-05-12 01:02:15 +00:00
|
|
|
// Use capsule shape only if base is square (nonuniform scaling apparently doesn't work on it)
|
|
|
|
if (std::abs(mHalfExtents.x()-mHalfExtents.y())<mHalfExtents.x()*0.05 && mHalfExtents.z() >= mHalfExtents.x())
|
|
|
|
{
|
2017-02-06 04:39:56 +00:00
|
|
|
mShape.reset(new btCapsuleShapeZ(mHalfExtents.x(), 2*mHalfExtents.z() - 2*mHalfExtents.x()));
|
2017-02-23 21:34:42 +00:00
|
|
|
mRotationallyInvariant = true;
|
2015-05-12 01:02:15 +00:00
|
|
|
}
|
|
|
|
else
|
2017-02-23 21:34:42 +00:00
|
|
|
{
|
2019-02-28 20:03:42 +00:00
|
|
|
mShape.reset(new btBoxShape(Misc::Convert::toBullet(mHalfExtents)));
|
2017-02-23 21:34:42 +00:00
|
|
|
mRotationallyInvariant = false;
|
|
|
|
}
|
|
|
|
|
2017-02-10 00:58:27 +00:00
|
|
|
mConvexShape = static_cast<btConvexShape*>(mShape.get());
|
2015-05-12 01:02:15 +00:00
|
|
|
|
|
|
|
mCollisionObject.reset(new btCollisionObject);
|
|
|
|
mCollisionObject->setCollisionFlags(btCollisionObject::CF_KINEMATIC_OBJECT);
|
|
|
|
mCollisionObject->setActivationState(DISABLE_DEACTIVATION);
|
|
|
|
mCollisionObject->setCollisionShape(mShape.get());
|
2019-02-13 07:30:16 +00:00
|
|
|
mCollisionObject->setUserPointer(this);
|
2015-05-12 01:02:15 +00:00
|
|
|
|
|
|
|
updateRotation();
|
|
|
|
updateScale();
|
2020-11-16 10:09:08 +00:00
|
|
|
resetPosition();
|
2016-12-16 19:22:07 +00:00
|
|
|
addCollisionMask(getCollisionMask());
|
2015-05-12 01:02:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Actor::~Actor()
|
|
|
|
{
|
2020-10-14 09:32:12 +00:00
|
|
|
if (mCollisionObject)
|
Process movement queue in one or several background threads
Before movement calculation, the main thread prepare a
vector of ActorFrameData, which contains all data necessary to perform
the simulation, and feed it to the solver. At the same time it fetches
the result from the previous background simulation, which in turn is
used by the game mechanics.
Other functions of the physics system (weapon hit for instance)
interrupt the background simulation, with some exceptions described
below.
The number of threads is controlled by the numeric setting
[Physics]
async num threads
In case 'async num threads' > 1 and Bullet doesn't support multiple threads,
1 async thread will be used. 0 means synchronous solver.
Additional settings (will be silently switched off if async num threads = 0)
[Physics]
defer aabb update
Update AABBs of actors and objects in the background thread(s). It is not an especially
costly operation, but it needs exclusive access to the collision world, which blocks
other operations. Since AABB needs to be updated for collision detection, one can queue
them to defer update before start of the movement solver. Extensive tests on as much
as one installation (mine) show no drawback having that switched on.
[Physics]
lineofsight keep inactive cache
Control for how long (how many frames) the line of sight (LOS) request will be kept updated.
When a request for LOS is made for the first time, the background threads are stopped to
service it. From now on, the LOS will be refreshed preemptively as part of the background
routine until it is not required for lineofsight keep inactive cache frames. This mean
that subsequent request will not interrupt the background computation.
2020-10-15 04:11:44 +00:00
|
|
|
mTaskScheduler->removeCollisionObject(mCollisionObject.get());
|
2015-05-12 01:02:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Actor::enableCollisionMode(bool collision)
|
|
|
|
{
|
Process movement queue in one or several background threads
Before movement calculation, the main thread prepare a
vector of ActorFrameData, which contains all data necessary to perform
the simulation, and feed it to the solver. At the same time it fetches
the result from the previous background simulation, which in turn is
used by the game mechanics.
Other functions of the physics system (weapon hit for instance)
interrupt the background simulation, with some exceptions described
below.
The number of threads is controlled by the numeric setting
[Physics]
async num threads
In case 'async num threads' > 1 and Bullet doesn't support multiple threads,
1 async thread will be used. 0 means synchronous solver.
Additional settings (will be silently switched off if async num threads = 0)
[Physics]
defer aabb update
Update AABBs of actors and objects in the background thread(s). It is not an especially
costly operation, but it needs exclusive access to the collision world, which blocks
other operations. Since AABB needs to be updated for collision detection, one can queue
them to defer update before start of the movement solver. Extensive tests on as much
as one installation (mine) show no drawback having that switched on.
[Physics]
lineofsight keep inactive cache
Control for how long (how many frames) the line of sight (LOS) request will be kept updated.
When a request for LOS is made for the first time, the background threads are stopped to
service it. From now on, the LOS will be refreshed preemptively as part of the background
routine until it is not required for lineofsight keep inactive cache frames. This mean
that subsequent request will not interrupt the background computation.
2020-10-15 04:11:44 +00:00
|
|
|
mInternalCollisionMode.store(collision, std::memory_order_release);
|
2015-05-12 01:02:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Actor::enableCollisionBody(bool collision)
|
|
|
|
{
|
|
|
|
if (mExternalCollisionMode != collision)
|
|
|
|
{
|
|
|
|
mExternalCollisionMode = collision;
|
|
|
|
updateCollisionMask();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-16 19:22:07 +00:00
|
|
|
void Actor::addCollisionMask(int collisionMask)
|
|
|
|
{
|
Process movement queue in one or several background threads
Before movement calculation, the main thread prepare a
vector of ActorFrameData, which contains all data necessary to perform
the simulation, and feed it to the solver. At the same time it fetches
the result from the previous background simulation, which in turn is
used by the game mechanics.
Other functions of the physics system (weapon hit for instance)
interrupt the background simulation, with some exceptions described
below.
The number of threads is controlled by the numeric setting
[Physics]
async num threads
In case 'async num threads' > 1 and Bullet doesn't support multiple threads,
1 async thread will be used. 0 means synchronous solver.
Additional settings (will be silently switched off if async num threads = 0)
[Physics]
defer aabb update
Update AABBs of actors and objects in the background thread(s). It is not an especially
costly operation, but it needs exclusive access to the collision world, which blocks
other operations. Since AABB needs to be updated for collision detection, one can queue
them to defer update before start of the movement solver. Extensive tests on as much
as one installation (mine) show no drawback having that switched on.
[Physics]
lineofsight keep inactive cache
Control for how long (how many frames) the line of sight (LOS) request will be kept updated.
When a request for LOS is made for the first time, the background threads are stopped to
service it. From now on, the LOS will be refreshed preemptively as part of the background
routine until it is not required for lineofsight keep inactive cache frames. This mean
that subsequent request will not interrupt the background computation.
2020-10-15 04:11:44 +00:00
|
|
|
mTaskScheduler->addCollisionObject(mCollisionObject.get(), CollisionType_Actor, collisionMask);
|
2016-12-16 19:22:07 +00:00
|
|
|
}
|
|
|
|
|
2015-05-12 01:02:15 +00:00
|
|
|
void Actor::updateCollisionMask()
|
|
|
|
{
|
Process movement queue in one or several background threads
Before movement calculation, the main thread prepare a
vector of ActorFrameData, which contains all data necessary to perform
the simulation, and feed it to the solver. At the same time it fetches
the result from the previous background simulation, which in turn is
used by the game mechanics.
Other functions of the physics system (weapon hit for instance)
interrupt the background simulation, with some exceptions described
below.
The number of threads is controlled by the numeric setting
[Physics]
async num threads
In case 'async num threads' > 1 and Bullet doesn't support multiple threads,
1 async thread will be used. 0 means synchronous solver.
Additional settings (will be silently switched off if async num threads = 0)
[Physics]
defer aabb update
Update AABBs of actors and objects in the background thread(s). It is not an especially
costly operation, but it needs exclusive access to the collision world, which blocks
other operations. Since AABB needs to be updated for collision detection, one can queue
them to defer update before start of the movement solver. Extensive tests on as much
as one installation (mine) show no drawback having that switched on.
[Physics]
lineofsight keep inactive cache
Control for how long (how many frames) the line of sight (LOS) request will be kept updated.
When a request for LOS is made for the first time, the background threads are stopped to
service it. From now on, the LOS will be refreshed preemptively as part of the background
routine until it is not required for lineofsight keep inactive cache frames. This mean
that subsequent request will not interrupt the background computation.
2020-10-15 04:11:44 +00:00
|
|
|
mTaskScheduler->setCollisionFilterMask(mCollisionObject.get(), getCollisionMask());
|
2016-12-16 19:22:07 +00:00
|
|
|
}
|
|
|
|
|
2020-10-14 09:32:12 +00:00
|
|
|
int Actor::getCollisionMask() const
|
2016-12-16 19:22:07 +00:00
|
|
|
{
|
2015-05-12 01:02:15 +00:00
|
|
|
int collisionMask = CollisionType_World | CollisionType_HeightMap;
|
|
|
|
if (mExternalCollisionMode)
|
2015-12-18 17:32:42 +00:00
|
|
|
collisionMask |= CollisionType_Actor | CollisionType_Projectile | CollisionType_Door;
|
2015-05-12 01:02:15 +00:00
|
|
|
if (mCanWaterWalk)
|
|
|
|
collisionMask |= CollisionType_Water;
|
2016-12-16 19:22:07 +00:00
|
|
|
return collisionMask;
|
2015-05-12 01:02:15 +00:00
|
|
|
}
|
|
|
|
|
2020-11-28 19:45:23 +00:00
|
|
|
void Actor::updatePositionUnsafe()
|
|
|
|
{
|
|
|
|
mWorldPosition = mPtr.getRefData().getPosition().asVec3();
|
|
|
|
}
|
|
|
|
|
2015-05-12 01:02:15 +00:00
|
|
|
void Actor::updatePosition()
|
|
|
|
{
|
2020-11-01 16:14:59 +00:00
|
|
|
std::scoped_lock lock(mPositionMutex);
|
2020-11-28 19:45:23 +00:00
|
|
|
updatePositionUnsafe();
|
2020-11-01 16:14:59 +00:00
|
|
|
}
|
2015-05-12 01:02:15 +00:00
|
|
|
|
2020-11-01 16:14:59 +00:00
|
|
|
osg::Vec3f Actor::getWorldPosition() const
|
|
|
|
{
|
|
|
|
std::scoped_lock lock(mPositionMutex);
|
|
|
|
return mWorldPosition;
|
|
|
|
}
|
2016-02-13 01:56:41 +00:00
|
|
|
|
2020-11-28 19:45:23 +00:00
|
|
|
void Actor::setSimulationPosition(const osg::Vec3f& position)
|
2020-11-01 16:14:59 +00:00
|
|
|
{
|
2020-11-28 19:45:23 +00:00
|
|
|
mSimulationPosition = position;
|
2020-11-01 16:14:59 +00:00
|
|
|
}
|
|
|
|
|
2020-11-28 19:45:23 +00:00
|
|
|
osg::Vec3f Actor::getSimulationPosition() const
|
2020-11-01 16:14:59 +00:00
|
|
|
{
|
2020-11-28 19:45:23 +00:00
|
|
|
return mSimulationPosition;
|
2016-02-13 01:56:41 +00:00
|
|
|
}
|
|
|
|
|
2020-11-28 19:45:23 +00:00
|
|
|
void Actor::updateCollisionObjectPositionUnsafe()
|
2016-02-13 01:56:41 +00:00
|
|
|
{
|
2020-11-01 16:14:59 +00:00
|
|
|
mShape->setLocalScaling(Misc::Convert::toBullet(mScale));
|
2015-05-12 14:49:21 +00:00
|
|
|
osg::Vec3f scaledTranslation = mRotation * osg::componentMultiply(mMeshTranslation, mScale);
|
2016-02-13 01:56:41 +00:00
|
|
|
osg::Vec3f newPosition = scaledTranslation + mPosition;
|
2020-10-14 13:47:50 +00:00
|
|
|
mLocalTransform.setOrigin(Misc::Convert::toBullet(newPosition));
|
|
|
|
mLocalTransform.setRotation(Misc::Convert::toBullet(mRotation));
|
2020-11-01 16:14:59 +00:00
|
|
|
mCollisionObject->setWorldTransform(mLocalTransform);
|
2015-05-12 01:02:15 +00:00
|
|
|
}
|
|
|
|
|
2020-11-28 19:45:23 +00:00
|
|
|
void Actor::updateCollisionObjectPosition()
|
|
|
|
{
|
|
|
|
std::scoped_lock lock(mPositionMutex);
|
|
|
|
updateCollisionObjectPositionUnsafe();
|
|
|
|
}
|
|
|
|
|
2016-02-13 01:56:41 +00:00
|
|
|
osg::Vec3f Actor::getCollisionObjectPosition() const
|
2015-11-03 17:15:47 +00:00
|
|
|
{
|
2020-11-01 16:14:59 +00:00
|
|
|
std::scoped_lock lock(mPositionMutex);
|
2020-10-14 13:47:50 +00:00
|
|
|
return Misc::Convert::toOsg(mLocalTransform.getOrigin());
|
2015-11-03 17:15:47 +00:00
|
|
|
}
|
|
|
|
|
2020-11-16 10:09:08 +00:00
|
|
|
void Actor::setPosition(const osg::Vec3f& position)
|
2016-02-13 01:56:41 +00:00
|
|
|
{
|
2020-11-28 19:45:23 +00:00
|
|
|
std::scoped_lock lock(mPositionMutex);
|
2020-11-16 10:09:08 +00:00
|
|
|
mPreviousPosition = mPosition;
|
2020-11-01 16:14:59 +00:00
|
|
|
mPosition = position;
|
|
|
|
}
|
2016-02-13 01:56:41 +00:00
|
|
|
|
2020-11-01 16:14:59 +00:00
|
|
|
void Actor::adjustPosition(const osg::Vec3f& offset)
|
|
|
|
{
|
2020-11-28 19:45:23 +00:00
|
|
|
std::scoped_lock lock(mPositionMutex);
|
2020-11-01 16:14:59 +00:00
|
|
|
mPosition += offset;
|
|
|
|
mPreviousPosition += offset;
|
2016-02-13 01:56:41 +00:00
|
|
|
}
|
|
|
|
|
2020-11-16 10:09:08 +00:00
|
|
|
void Actor::resetPosition()
|
|
|
|
{
|
2020-11-28 19:45:23 +00:00
|
|
|
std::scoped_lock lock(mPositionMutex);
|
|
|
|
updatePositionUnsafe();
|
2020-11-16 10:09:08 +00:00
|
|
|
mPreviousPosition = mWorldPosition;
|
|
|
|
mPosition = mWorldPosition;
|
2020-11-28 19:45:23 +00:00
|
|
|
mSimulationPosition = mWorldPosition;
|
|
|
|
updateCollisionObjectPositionUnsafe();
|
2020-11-16 10:09:08 +00:00
|
|
|
}
|
|
|
|
|
2016-02-13 01:56:41 +00:00
|
|
|
osg::Vec3f Actor::getPosition() const
|
|
|
|
{
|
|
|
|
return mPosition;
|
|
|
|
}
|
|
|
|
|
|
|
|
osg::Vec3f Actor::getPreviousPosition() const
|
|
|
|
{
|
|
|
|
return mPreviousPosition;
|
|
|
|
}
|
|
|
|
|
2015-05-12 01:02:15 +00:00
|
|
|
void Actor::updateRotation ()
|
|
|
|
{
|
2020-11-01 16:14:59 +00:00
|
|
|
std::scoped_lock lock(mPositionMutex);
|
2020-10-14 13:47:50 +00:00
|
|
|
if (mRotation == mPtr.getRefData().getBaseNode()->getAttitude())
|
|
|
|
return;
|
2015-05-12 14:49:21 +00:00
|
|
|
mRotation = mPtr.getRefData().getBaseNode()->getAttitude();
|
2015-05-12 01:02:15 +00:00
|
|
|
}
|
|
|
|
|
2017-02-23 21:34:42 +00:00
|
|
|
bool Actor::isRotationallyInvariant() const
|
|
|
|
{
|
|
|
|
return mRotationallyInvariant;
|
|
|
|
}
|
|
|
|
|
2015-05-12 01:02:15 +00:00
|
|
|
void Actor::updateScale()
|
|
|
|
{
|
2020-11-01 16:14:59 +00:00
|
|
|
std::scoped_lock lock(mPositionMutex);
|
2015-05-12 01:02:15 +00:00
|
|
|
float scale = mPtr.getCellRef().getScale();
|
|
|
|
osg::Vec3f scaleVec(scale,scale,scale);
|
|
|
|
|
2015-11-01 20:45:58 +00:00
|
|
|
mPtr.getClass().adjustScale(mPtr, scaleVec, false);
|
2015-05-12 01:02:15 +00:00
|
|
|
mScale = scaleVec;
|
|
|
|
|
2015-11-01 20:45:58 +00:00
|
|
|
scaleVec = osg::Vec3f(scale,scale,scale);
|
|
|
|
mPtr.getClass().adjustScale(mPtr, scaleVec, true);
|
|
|
|
mRenderingScale = scaleVec;
|
2015-05-12 01:02:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
osg::Vec3f Actor::getHalfExtents() const
|
|
|
|
{
|
2020-11-01 16:14:59 +00:00
|
|
|
std::scoped_lock lock(mPositionMutex);
|
2015-05-12 01:02:15 +00:00
|
|
|
return osg::componentMultiply(mHalfExtents, mScale);
|
|
|
|
}
|
|
|
|
|
2019-03-03 11:45:36 +00:00
|
|
|
osg::Vec3f Actor::getOriginalHalfExtents() const
|
|
|
|
{
|
2020-11-01 16:14:59 +00:00
|
|
|
std::scoped_lock lock(mPositionMutex);
|
2019-03-03 11:45:36 +00:00
|
|
|
return mHalfExtents;
|
|
|
|
}
|
|
|
|
|
2015-11-01 20:45:58 +00:00
|
|
|
osg::Vec3f Actor::getRenderingHalfExtents() const
|
|
|
|
{
|
2020-11-01 16:14:59 +00:00
|
|
|
std::scoped_lock lock(mPositionMutex);
|
2015-11-01 20:45:58 +00:00
|
|
|
return osg::componentMultiply(mHalfExtents, mRenderingScale);
|
|
|
|
}
|
|
|
|
|
2015-05-12 01:02:15 +00:00
|
|
|
void Actor::setInertialForce(const osg::Vec3f &force)
|
|
|
|
{
|
|
|
|
mForce = force;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Actor::setOnGround(bool grounded)
|
|
|
|
{
|
Process movement queue in one or several background threads
Before movement calculation, the main thread prepare a
vector of ActorFrameData, which contains all data necessary to perform
the simulation, and feed it to the solver. At the same time it fetches
the result from the previous background simulation, which in turn is
used by the game mechanics.
Other functions of the physics system (weapon hit for instance)
interrupt the background simulation, with some exceptions described
below.
The number of threads is controlled by the numeric setting
[Physics]
async num threads
In case 'async num threads' > 1 and Bullet doesn't support multiple threads,
1 async thread will be used. 0 means synchronous solver.
Additional settings (will be silently switched off if async num threads = 0)
[Physics]
defer aabb update
Update AABBs of actors and objects in the background thread(s). It is not an especially
costly operation, but it needs exclusive access to the collision world, which blocks
other operations. Since AABB needs to be updated for collision detection, one can queue
them to defer update before start of the movement solver. Extensive tests on as much
as one installation (mine) show no drawback having that switched on.
[Physics]
lineofsight keep inactive cache
Control for how long (how many frames) the line of sight (LOS) request will be kept updated.
When a request for LOS is made for the first time, the background threads are stopped to
service it. From now on, the LOS will be refreshed preemptively as part of the background
routine until it is not required for lineofsight keep inactive cache frames. This mean
that subsequent request will not interrupt the background computation.
2020-10-15 04:11:44 +00:00
|
|
|
mOnGround.store(grounded, std::memory_order_release);
|
2015-05-12 01:02:15 +00:00
|
|
|
}
|
|
|
|
|
2017-02-06 03:46:44 +00:00
|
|
|
void Actor::setOnSlope(bool slope)
|
|
|
|
{
|
Process movement queue in one or several background threads
Before movement calculation, the main thread prepare a
vector of ActorFrameData, which contains all data necessary to perform
the simulation, and feed it to the solver. At the same time it fetches
the result from the previous background simulation, which in turn is
used by the game mechanics.
Other functions of the physics system (weapon hit for instance)
interrupt the background simulation, with some exceptions described
below.
The number of threads is controlled by the numeric setting
[Physics]
async num threads
In case 'async num threads' > 1 and Bullet doesn't support multiple threads,
1 async thread will be used. 0 means synchronous solver.
Additional settings (will be silently switched off if async num threads = 0)
[Physics]
defer aabb update
Update AABBs of actors and objects in the background thread(s). It is not an especially
costly operation, but it needs exclusive access to the collision world, which blocks
other operations. Since AABB needs to be updated for collision detection, one can queue
them to defer update before start of the movement solver. Extensive tests on as much
as one installation (mine) show no drawback having that switched on.
[Physics]
lineofsight keep inactive cache
Control for how long (how many frames) the line of sight (LOS) request will be kept updated.
When a request for LOS is made for the first time, the background threads are stopped to
service it. From now on, the LOS will be refreshed preemptively as part of the background
routine until it is not required for lineofsight keep inactive cache frames. This mean
that subsequent request will not interrupt the background computation.
2020-10-15 04:11:44 +00:00
|
|
|
mOnSlope.store(slope, std::memory_order_release);
|
2017-02-06 03:46:44 +00:00
|
|
|
}
|
|
|
|
|
2015-05-12 01:02:15 +00:00
|
|
|
bool Actor::isWalkingOnWater() const
|
|
|
|
{
|
Process movement queue in one or several background threads
Before movement calculation, the main thread prepare a
vector of ActorFrameData, which contains all data necessary to perform
the simulation, and feed it to the solver. At the same time it fetches
the result from the previous background simulation, which in turn is
used by the game mechanics.
Other functions of the physics system (weapon hit for instance)
interrupt the background simulation, with some exceptions described
below.
The number of threads is controlled by the numeric setting
[Physics]
async num threads
In case 'async num threads' > 1 and Bullet doesn't support multiple threads,
1 async thread will be used. 0 means synchronous solver.
Additional settings (will be silently switched off if async num threads = 0)
[Physics]
defer aabb update
Update AABBs of actors and objects in the background thread(s). It is not an especially
costly operation, but it needs exclusive access to the collision world, which blocks
other operations. Since AABB needs to be updated for collision detection, one can queue
them to defer update before start of the movement solver. Extensive tests on as much
as one installation (mine) show no drawback having that switched on.
[Physics]
lineofsight keep inactive cache
Control for how long (how many frames) the line of sight (LOS) request will be kept updated.
When a request for LOS is made for the first time, the background threads are stopped to
service it. From now on, the LOS will be refreshed preemptively as part of the background
routine until it is not required for lineofsight keep inactive cache frames. This mean
that subsequent request will not interrupt the background computation.
2020-10-15 04:11:44 +00:00
|
|
|
return mWalkingOnWater.load(std::memory_order_acquire);
|
2015-05-12 01:02:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Actor::setWalkingOnWater(bool walkingOnWater)
|
|
|
|
{
|
Process movement queue in one or several background threads
Before movement calculation, the main thread prepare a
vector of ActorFrameData, which contains all data necessary to perform
the simulation, and feed it to the solver. At the same time it fetches
the result from the previous background simulation, which in turn is
used by the game mechanics.
Other functions of the physics system (weapon hit for instance)
interrupt the background simulation, with some exceptions described
below.
The number of threads is controlled by the numeric setting
[Physics]
async num threads
In case 'async num threads' > 1 and Bullet doesn't support multiple threads,
1 async thread will be used. 0 means synchronous solver.
Additional settings (will be silently switched off if async num threads = 0)
[Physics]
defer aabb update
Update AABBs of actors and objects in the background thread(s). It is not an especially
costly operation, but it needs exclusive access to the collision world, which blocks
other operations. Since AABB needs to be updated for collision detection, one can queue
them to defer update before start of the movement solver. Extensive tests on as much
as one installation (mine) show no drawback having that switched on.
[Physics]
lineofsight keep inactive cache
Control for how long (how many frames) the line of sight (LOS) request will be kept updated.
When a request for LOS is made for the first time, the background threads are stopped to
service it. From now on, the LOS will be refreshed preemptively as part of the background
routine until it is not required for lineofsight keep inactive cache frames. This mean
that subsequent request will not interrupt the background computation.
2020-10-15 04:11:44 +00:00
|
|
|
mWalkingOnWater.store(walkingOnWater, std::memory_order_release);
|
2015-05-12 01:02:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Actor::setCanWaterWalk(bool waterWalk)
|
|
|
|
{
|
2020-11-01 16:14:59 +00:00
|
|
|
std::scoped_lock lock(mPositionMutex);
|
2015-05-12 01:02:15 +00:00
|
|
|
if (waterWalk != mCanWaterWalk)
|
|
|
|
{
|
|
|
|
mCanWaterWalk = waterWalk;
|
|
|
|
updateCollisionMask();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-07 17:30:52 +00:00
|
|
|
MWWorld::Ptr Actor::getStandingOnPtr() const
|
|
|
|
{
|
|
|
|
std::scoped_lock lock(mPositionMutex);
|
|
|
|
return mStandingOnPtr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Actor::setStandingOnPtr(const MWWorld::Ptr& ptr)
|
|
|
|
{
|
|
|
|
std::scoped_lock lock(mPositionMutex);
|
|
|
|
mStandingOnPtr = ptr;
|
|
|
|
}
|
|
|
|
|
2015-05-12 01:02:15 +00:00
|
|
|
}
|