change when joint cache is copied

This commit is contained in:
Seth Alves 2017-07-06 15:42:24 -07:00
parent 0ac8f6efa3
commit e03b902a15
2 changed files with 41 additions and 12 deletions

View file

@ -1008,17 +1008,48 @@ glm::vec3 Avatar::getAbsoluteJointTranslationInObjectFrame(int index) const {
}
}
int Avatar::getJointIndex(const QString& name) const {
QReadLocker readLock(&_jointIndicesCacheLock);
if (_jointIndicesCache.contains(name)) {
return _jointIndicesCache[name];
void Avatar::cacheJoints() const {
// _jointIndicesCacheLock should be locked for write before calling this.
_jointIndicesCache.clear();
if (_skeletonModel && _skeletonModel->isActive()) {
_jointIndicesCache = _skeletonModel->getFBXGeometry().jointIndices;
_jointsCached = true;
}
return -1;
}
int Avatar::getJointIndex(const QString& name) const {
auto getJointIndexWorker = [&]() {
if (_jointIndicesCache.contains(name)) {
return _jointIndicesCache[name];
}
return -1;
};
QReadLocker readLock(&_jointIndicesCacheLock);
if (!_jointsCached) {
readLock.unlock();
{
QWriteLocker writeLock(&_jointIndicesCacheLock);
Avatar::cacheJoints();
return getJointIndexWorker();
}
}
return getJointIndexWorker();
}
QStringList Avatar::getJointNames() const {
auto getJointNamesWorker = [&]() {
return _jointIndicesCache.keys();
};
QReadLocker readLock(&_jointIndicesCacheLock);
return _jointIndicesCache.keys();
if (!_jointsCached) {
readLock.unlock();
{
QWriteLocker writeLock(&_jointIndicesCacheLock);
Avatar::cacheJoints();
return getJointNamesWorker();
}
}
return getJointNamesWorker();
}
glm::vec3 Avatar::getJointPosition(int index) const {
@ -1050,12 +1081,8 @@ void Avatar::setSkeletonModelURL(const QUrl& skeletonModelURL) {
void Avatar::setModelURLFinished(bool success) {
{
QWriteLocker writeLock(&_jointIndicesCacheLock);
_jointIndicesCache.clear();
if (_skeletonModel && _skeletonModel->isActive()) {
_jointIndicesCache = _skeletonModel->getFBXGeometry().jointIndices;
}
_jointsCached = false;
}
if (!success && _skeletonModelURL != AvatarData::defaultFullAvatarModelUrl()) {
const int MAX_SKELETON_DOWNLOAD_ATTEMPTS = 4; // NOTE: we don't want to be as generous as ResourceCache is, we only want 4 attempts
if (_skeletonModel->getResourceDownloadAttemptsRemaining() <= 0 ||

View file

@ -268,8 +268,10 @@ protected:
SkeletonModelPointer _skeletonModel;
QHash<QString, int> _jointIndicesCache;
void cacheJoints() const;
mutable QHash<QString, int> _jointIndicesCache;
mutable QReadWriteLock _jointIndicesCacheLock;
mutable bool _jointsCached { false };
glm::vec3 _skeletonOffset;
std::vector<std::shared_ptr<Model>> _attachmentModels;