Merge branch 'master' of https://github.com/highfidelity/hifi into orange

This commit is contained in:
Sam Cake 2015-05-13 16:00:42 -07:00
commit d13106f4c9
9 changed files with 282 additions and 231 deletions

View file

@ -232,9 +232,11 @@ void AssignmentClient::readPendingDatagrams() {
connect(workerThread, &QThread::started, _currentAssignment.data(), &ThreadedAssignment::run); connect(workerThread, &QThread::started, _currentAssignment.data(), &ThreadedAssignment::run);
// once the ThreadedAssignment says it is finished - we ask it to deleteLater // Once the ThreadedAssignment says it is finished - we ask it to deleteLater
// This is a queued connection so that it is put into the event loop to be processed by the worker
// thread when it is ready.
connect(_currentAssignment.data(), &ThreadedAssignment::finished, _currentAssignment.data(), connect(_currentAssignment.data(), &ThreadedAssignment::finished, _currentAssignment.data(),
&ThreadedAssignment::deleteLater); &ThreadedAssignment::deleteLater, Qt::QueuedConnection);
// once it is deleted, we quit the worker thread // once it is deleted, we quit the worker thread
connect(_currentAssignment.data(), &ThreadedAssignment::destroyed, workerThread, &QThread::quit); connect(_currentAssignment.data(), &ThreadedAssignment::destroyed, workerThread, &QThread::quit);

View file

@ -29,6 +29,8 @@ class AudioMixer : public ThreadedAssignment {
Q_OBJECT Q_OBJECT
public: public:
AudioMixer(const QByteArray& packet); AudioMixer(const QByteArray& packet);
void deleteLater() { qDebug() << "DELETE LATER CALLED?"; QObject::deleteLater(); }
public slots: public slots:
/// threaded run of assignment /// threaded run of assignment
void run(); void run();

View file

@ -254,6 +254,7 @@ QJsonObject DomainServerSettingsManager::responseObjectForType(const QString& ty
void DomainServerSettingsManager::updateSetting(const QString& key, const QJsonValue& newValue, QVariantMap& settingMap, void DomainServerSettingsManager::updateSetting(const QString& key, const QJsonValue& newValue, QVariantMap& settingMap,
const QJsonObject& settingDescription) { const QJsonObject& settingDescription) {
if (newValue.isString()) { if (newValue.isString()) {
if (newValue.toString().isEmpty()) { if (newValue.toString().isEmpty()) {
// this is an empty value, clear it in settings variant so the default is sent // this is an empty value, clear it in settings variant so the default is sent
@ -288,7 +289,16 @@ void DomainServerSettingsManager::updateSetting(const QString& key, const QJsonV
settingMap[key] = QVariantMap(); settingMap[key] = QVariantMap();
} }
QVariantMap& thisMap = *reinterpret_cast<QVariantMap*>(settingMap[key].data()); QVariant& possibleMap = settingMap[key];
if (!possibleMap.canConvert(QMetaType::QVariantMap)) {
// if this isn't a map then we need to make it one, otherwise we're about to crash
qDebug() << "Value at" << key << "was not the expected QVariantMap while updating DS settings"
<< "- removing existing value and making it a QVariantMap";
possibleMap = QVariantMap();
}
QVariantMap& thisMap = *reinterpret_cast<QVariantMap*>(possibleMap.data());
foreach(const QString childKey, newValue.toObject().keys()) { foreach(const QString childKey, newValue.toObject().keys()) {
QJsonObject childDescriptionObject = settingDescription; QJsonObject childDescriptionObject = settingDescription;
@ -351,7 +361,7 @@ void DomainServerSettingsManager::recurseJSONObjectAndOverwriteSettings(const QJ
settingsVariant[rootKey] = QVariantMap(); settingsVariant[rootKey] = QVariantMap();
} }
QVariantMap& thisMap = settingsVariant; QVariantMap* thisMap = &settingsVariant;
QJsonObject groupDescriptionObject; QJsonObject groupDescriptionObject;
@ -362,7 +372,7 @@ void DomainServerSettingsManager::recurseJSONObjectAndOverwriteSettings(const QJ
groupDescriptionObject = groupValue.toObject(); groupDescriptionObject = groupValue.toObject();
// change the map we will update to be the map for this group // change the map we will update to be the map for this group
thisMap = *reinterpret_cast<QVariantMap*>(settingsVariant[rootKey].data()); thisMap = reinterpret_cast<QVariantMap*>(settingsVariant[rootKey].data());
break; break;
} }
@ -388,7 +398,7 @@ void DomainServerSettingsManager::recurseJSONObjectAndOverwriteSettings(const QJ
} }
if (!matchingDescriptionObject.isEmpty()) { if (!matchingDescriptionObject.isEmpty()) {
updateSetting(rootKey, rootValue, thisMap, matchingDescriptionObject); updateSetting(rootKey, rootValue, *thisMap, matchingDescriptionObject);
} else { } else {
qDebug() << "Setting for root key" << rootKey << "does not exist - cannot update setting."; qDebug() << "Setting for root key" << rootKey << "does not exist - cannot update setting.";
} }
@ -401,7 +411,7 @@ void DomainServerSettingsManager::recurseJSONObjectAndOverwriteSettings(const QJ
// if we matched the setting then update the value // if we matched the setting then update the value
if (!matchingDescriptionObject.isEmpty()) { if (!matchingDescriptionObject.isEmpty()) {
QJsonValue settingValue = rootValue.toObject()[settingKey]; QJsonValue settingValue = rootValue.toObject()[settingKey];
updateSetting(settingKey, settingValue, thisMap, matchingDescriptionObject); updateSetting(settingKey, settingValue, *thisMap, matchingDescriptionObject);
} else { } else {
qDebug() << "Could not find description for setting" << settingKey << "in group" << rootKey << qDebug() << "Could not find description for setting" << settingKey << "in group" << rootKey <<
"- cannot update setting."; "- cannot update setting.";

View file

@ -603,9 +603,11 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
auto faceshiftTracker = DependencyManager::get<Faceshift>(); auto faceshiftTracker = DependencyManager::get<Faceshift>();
faceshiftTracker->init(); faceshiftTracker->init();
connect(faceshiftTracker.data(), &FaceTracker::muteToggled, this, &Application::faceTrackerMuteToggled); connect(faceshiftTracker.data(), &FaceTracker::muteToggled, this, &Application::faceTrackerMuteToggled);
#ifdef HAVE_DDE
auto ddeTracker = DependencyManager::get<DdeFaceTracker>(); auto ddeTracker = DependencyManager::get<DdeFaceTracker>();
ddeTracker->init(); ddeTracker->init();
connect(ddeTracker.data(), &FaceTracker::muteToggled, this, &Application::faceTrackerMuteToggled); connect(ddeTracker.data(), &FaceTracker::muteToggled, this, &Application::faceTrackerMuteToggled);
#endif
} }

View file

@ -53,6 +53,7 @@ void ThreadedAssignment::setFinished(bool isFinished) {
// if we have a datagram processing thread, quit it and wait on it to make sure that // if we have a datagram processing thread, quit it and wait on it to make sure that
// the node socket is back on the same thread as the NodeList // the node socket is back on the same thread as the NodeList
if (_datagramProcessingThread) { if (_datagramProcessingThread) {
// tell the datagram processing thread to quit and wait until it is done, // tell the datagram processing thread to quit and wait until it is done,
// then return the node socket to the NodeList // then return the node socket to the NodeList

View file

@ -15,6 +15,36 @@
#include "BulletUtil.h" #include "BulletUtil.h"
// find the average point on a convex shape
glm::vec3 findCenter(const QVector<glm::vec3>& points) {
glm::vec3 result = glm::vec3(0);
for (int i = 0; i < points.size(); i++) {
result += points[i];
}
return result * (1.0f / points.size());
}
// bullet puts "margins" around all the collision shapes. This can cause shapes will hulls
// to float a bit above what they are sitting on, etc. One option is to call:
//
// compound->setMargin(0.01);
//
// to reduce the size of the margin, but this has some consequences for the
// performance and stability of the simulation. Instead, we clench in all the points of
// the hull by the margin. These clenched points + bullets margin will but the actual
// collision hull fairly close to the visual edge of the object.
QVector<glm::vec3> shrinkByMargin(const QVector<glm::vec3>& points, const glm::vec3 center, float margin) {
QVector<glm::vec3> result(points.size());
for (int i = 0; i < points.size(); i++) {
glm::vec3 pVec = points[ i ] - center;
glm::vec3 pVecNorm = glm::normalize(pVec);
result[ i ] = center + pVec - (pVecNorm * margin);
}
return result;
}
btCollisionShape* ShapeInfoUtil::createShapeFromInfo(const ShapeInfo& info) { btCollisionShape* ShapeInfoUtil::createShapeFromInfo(const ShapeInfo& info) {
btCollisionShape* shape = NULL; btCollisionShape* shape = NULL;
switch(info.getType()) { switch(info.getType()) {
@ -40,7 +70,9 @@ btCollisionShape* ShapeInfoUtil::createShapeFromInfo(const ShapeInfo& info) {
if (numSubShapes == 1) { if (numSubShapes == 1) {
auto hull = new btConvexHullShape(); auto hull = new btConvexHullShape();
const QVector<QVector<glm::vec3>>& points = info.getPoints(); const QVector<QVector<glm::vec3>>& points = info.getPoints();
foreach (glm::vec3 point, points[0]) { glm::vec3 center = findCenter(points[0]);
QVector<glm::vec3> shrunken = shrinkByMargin(points[0], center, hull->getMargin());
foreach (glm::vec3 point, shrunken) {
btVector3 btPoint(point[0], point[1], point[2]); btVector3 btPoint(point[0], point[1], point[2]);
hull->addPoint(btPoint, false); hull->addPoint(btPoint, false);
} }
@ -53,7 +85,9 @@ btCollisionShape* ShapeInfoUtil::createShapeFromInfo(const ShapeInfo& info) {
trans.setIdentity(); trans.setIdentity();
foreach (QVector<glm::vec3> hullPoints, points) { foreach (QVector<glm::vec3> hullPoints, points) {
auto hull = new btConvexHullShape(); auto hull = new btConvexHullShape();
foreach (glm::vec3 point, hullPoints) { glm::vec3 center = findCenter(points[0]);
QVector<glm::vec3> shrunken = shrinkByMargin(hullPoints, center, hull->getMargin());
foreach (glm::vec3 point, shrunken) {
btVector3 btPoint(point[0], point[1], point[2]); btVector3 btPoint(point[0], point[1], point[2]);
hull->addPoint(btPoint, false); hull->addPoint(btPoint, false);
} }