Optimized MyAvatar.getCharacterControllerEnabled()

Instead of doing a blocking queued invokeMethod, it just calls into CharacterController.isEnabled() which is now thread-safe.
This commit is contained in:
Anthony J. Thibault 2016-06-09 09:35:19 -07:00
parent 30d8ae36e8
commit 1aae22f5a5
2 changed files with 7 additions and 10 deletions

View file

@ -1253,13 +1253,13 @@ void MyAvatar::prepareForPhysicsSimulation() {
void MyAvatar::harvestResultsFromPhysicsSimulation(float deltaTime) {
glm::vec3 position = getPosition();
glm::quat orientation = getOrientation();
if (_characterController.isEnabled()) {
if (_characterController.isEnabledAndReady()) {
_characterController.getPositionAndOrientation(position, orientation);
}
nextAttitude(position, orientation);
_bodySensorMatrix = _follow.postPhysicsUpdate(*this, _bodySensorMatrix);
if (_characterController.isEnabled()) {
if (_characterController.isEnabledAndReady()) {
setVelocity(_characterController.getLinearVelocity() + _characterController.getFollowVelocity());
} else {
setVelocity(getVelocity() + _characterController.getFollowVelocity());
@ -1642,7 +1642,7 @@ void MyAvatar::updatePosition(float deltaTime) {
vec3 velocity = getVelocity();
const float MOVING_SPEED_THRESHOLD_SQUARED = 0.0001f; // 0.01 m/s
if (!_characterController.isEnabled()) {
if (!_characterController.isEnabledAndReady()) {
// _characterController is not in physics simulation but it can still compute its target velocity
updateMotors();
_characterController.computeNewVelocity(deltaTime, velocity);
@ -1838,11 +1838,6 @@ void MyAvatar::setCharacterControllerEnabled(bool enabled) {
}
bool MyAvatar::getCharacterControllerEnabled() {
if (QThread::currentThread() != thread()) {
bool result;
QMetaObject::invokeMethod(this, "getCharacterControllerEnabled", Qt::BlockingQueuedConnection, Q_RETURN_ARG(bool, result));
return result;
}
return _characterController.isEnabled();
}

View file

@ -14,6 +14,7 @@
#include <assert.h>
#include <stdint.h>
#include <atomic>
#include <btBulletDynamicsCommon.h>
#include <BulletDynamics/Character/btCharacterControllerInterface.h>
@ -105,8 +106,9 @@ public:
void setLocalBoundingBox(const glm::vec3& corner, const glm::vec3& scale);
bool isEnabled() const { return _enabled; } // thread-safe
void setEnabled(bool enabled);
bool isEnabled() const { return _enabled && _dynamicsWorld; }
bool isEnabledAndReady() const { return _enabled && _dynamicsWorld; }
bool getRigidBodyLocation(glm::vec3& avatarRigidBodyPosition, glm::quat& avatarRigidBodyRotation);
@ -167,7 +169,7 @@ protected:
btQuaternion _followAngularDisplacement;
btVector3 _linearAcceleration;
bool _enabled;
std::atomic_bool _enabled;
State _state;
bool _isPushingUp;