mirror of
https://github.com/overte-org/overte.git
synced 2025-08-07 20:35:04 +02:00
Merge branch 'master' of github.com:highfidelity/hifi into finglonger
This commit is contained in:
commit
09f900862b
2 changed files with 21 additions and 10 deletions
|
@ -1111,6 +1111,9 @@ void EntityTreeRenderer::changingEntityID(const EntityItemID& oldEntityID, const
|
||||||
|
|
||||||
void EntityTreeRenderer::playEntityCollisionSound(const QUuid& myNodeID, EntityTree* entityTree, const EntityItemID& id, const Collision& collision) {
|
void EntityTreeRenderer::playEntityCollisionSound(const QUuid& myNodeID, EntityTree* entityTree, const EntityItemID& id, const Collision& collision) {
|
||||||
EntityItem* entity = entityTree->findEntityByEntityItemID(id);
|
EntityItem* entity = entityTree->findEntityByEntityItemID(id);
|
||||||
|
if (!entity) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
QUuid simulatorID = entity->getSimulatorID();
|
QUuid simulatorID = entity->getSimulatorID();
|
||||||
if (simulatorID.isNull() || (simulatorID != myNodeID)) {
|
if (simulatorID.isNull() || (simulatorID != myNodeID)) {
|
||||||
return; // Only one injector per simulation, please.
|
return; // Only one injector per simulation, please.
|
||||||
|
@ -1124,20 +1127,24 @@ void EntityTreeRenderer::playEntityCollisionSound(const QUuid& myNodeID, EntityT
|
||||||
const float linearVelocity = glm::length(collision.penetration) * COLLISION_PENTRATION_TO_VELOCITY;
|
const float linearVelocity = glm::length(collision.penetration) * COLLISION_PENTRATION_TO_VELOCITY;
|
||||||
const float energy = mass * linearVelocity * linearVelocity / 2.0f;
|
const float energy = mass * linearVelocity * linearVelocity / 2.0f;
|
||||||
const glm::vec3 position = collision.contactPoint;
|
const glm::vec3 position = collision.contactPoint;
|
||||||
const float COLLISION_ENERGY_AT_FULL_VOLUME = 1.0f;
|
const float COLLISION_ENERGY_AT_FULL_VOLUME = 0.5f;
|
||||||
const float COLLISION_MINIMUM_VOLUME = 0.001f;
|
const float COLLISION_MINIMUM_VOLUME = 0.001f;
|
||||||
const float energyFactorOfFull = fmin(1.0f, energy / COLLISION_ENERGY_AT_FULL_VOLUME);
|
const float energyFactorOfFull = fmin(1.0f, energy / COLLISION_ENERGY_AT_FULL_VOLUME);
|
||||||
if (energyFactorOfFull < COLLISION_MINIMUM_VOLUME) {
|
if (energyFactorOfFull < COLLISION_MINIMUM_VOLUME) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SharedSoundPointer sound = DependencyManager::get<SoundCache>().data()->getSound(QUrl(collisionSoundURL));
|
auto soundCache = DependencyManager::get<SoundCache>();
|
||||||
if (!sound->isReady()) {
|
if (soundCache.isNull()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
SharedSoundPointer sound = soundCache.data()->getSound(QUrl(collisionSoundURL));
|
||||||
|
if (sound.isNull() || !sound->isReady()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is a hack. Quiet sound aren't really heard at all, so we compress everything to the range [1-c, 1], if we play it all.
|
// This is a hack. Quiet sound aren't really heard at all, so we compress everything to the range [1-c, 1], if we play it all.
|
||||||
const float COLLISION_SOUND_COMPRESSION_RANGE = 0.95f;
|
const float COLLISION_SOUND_COMPRESSION_RANGE = 0.7f;
|
||||||
float volume = energyFactorOfFull;
|
float volume = energyFactorOfFull;
|
||||||
volume = (volume * COLLISION_SOUND_COMPRESSION_RANGE) + (1.0f - COLLISION_SOUND_COMPRESSION_RANGE);
|
volume = (volume * COLLISION_SOUND_COMPRESSION_RANGE) + (1.0f - COLLISION_SOUND_COMPRESSION_RANGE);
|
||||||
|
|
||||||
|
@ -1148,6 +1155,7 @@ void EntityTreeRenderer::playEntityCollisionSound(const QUuid& myNodeID, EntityT
|
||||||
options.volume = volume;
|
options.volume = volume;
|
||||||
AudioInjector* injector = new AudioInjector(sound.data(), options);
|
AudioInjector* injector = new AudioInjector(sound.data(), options);
|
||||||
injector->setLocalAudioInterface(_localAudioInterface);
|
injector->setLocalAudioInterface(_localAudioInterface);
|
||||||
|
injector->triggerDeleteAfterFinish();
|
||||||
QThread* injectorThread = new QThread();
|
QThread* injectorThread = new QThread();
|
||||||
injectorThread->setObjectName("Audio Injector Thread");
|
injectorThread->setObjectName("Audio Injector Thread");
|
||||||
injector->moveToThread(injectorThread);
|
injector->moveToThread(injectorThread);
|
||||||
|
@ -1168,7 +1176,7 @@ void EntityTreeRenderer::entityCollisionWithEntity(const EntityItemID& idA, cons
|
||||||
}
|
}
|
||||||
// Don't respond to small continuous contacts. It causes deadlocks when locking the entityTree.
|
// Don't respond to small continuous contacts. It causes deadlocks when locking the entityTree.
|
||||||
// Note that any entity script is likely to Entities.getEntityProperties(), which locks the tree.
|
// Note that any entity script is likely to Entities.getEntityProperties(), which locks the tree.
|
||||||
const float COLLISION_MINUMUM_PENETRATION = 0.001;
|
const float COLLISION_MINUMUM_PENETRATION = 0.005;
|
||||||
if ((collision.type != CONTACT_EVENT_TYPE_START) && (glm::length(collision.penetration) < COLLISION_MINUMUM_PENETRATION)) {
|
if ((collision.type != CONTACT_EVENT_TYPE_START) && (glm::length(collision.penetration) < COLLISION_MINUMUM_PENETRATION)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QEventLoop>
|
#include <QEventLoop>
|
||||||
#include <QNetworkAccessManager>
|
#include <QNetworkAccessManager>
|
||||||
|
#include <QNetworkConfiguration>
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
|
@ -43,7 +44,7 @@ QString ScriptCache::getScript(const QUrl& url, ScriptUser* scriptUser, bool& is
|
||||||
QNetworkRequest networkRequest = QNetworkRequest(url);
|
QNetworkRequest networkRequest = QNetworkRequest(url);
|
||||||
networkRequest.setHeader(QNetworkRequest::UserAgentHeader, HIGH_FIDELITY_USER_AGENT);
|
networkRequest.setHeader(QNetworkRequest::UserAgentHeader, HIGH_FIDELITY_USER_AGENT);
|
||||||
|
|
||||||
qCDebug(scriptengine) << "Downloading script at:" << url.toString();
|
qCDebug(scriptengine) << "Downloading script at" << url.toString();
|
||||||
QNetworkReply* reply = networkAccessManager.get(networkRequest);
|
QNetworkReply* reply = networkAccessManager.get(networkRequest);
|
||||||
connect(reply, &QNetworkReply::finished, this, &ScriptCache::scriptDownloaded);
|
connect(reply, &QNetworkReply::finished, this, &ScriptCache::scriptDownloaded);
|
||||||
}
|
}
|
||||||
|
@ -65,7 +66,9 @@ void ScriptCache::scriptDownloaded() {
|
||||||
user->scriptContentsAvailable(url, _scriptCache[url]);
|
user->scriptContentsAvailable(url, _scriptCache[url]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
qCDebug(scriptengine) << "ERROR Loading file:" << reply->url().toString();
|
qCWarning(scriptengine) << "Error loading script from URL " << reply->url().toString()
|
||||||
|
<< "- HTTP status code is" << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt()
|
||||||
|
<< "and error from QNetworkReply is" << reply->errorString();
|
||||||
foreach(ScriptUser* user, scriptUsers) {
|
foreach(ScriptUser* user, scriptUsers) {
|
||||||
user->errorInLoadingScript(url);
|
user->errorInLoadingScript(url);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue