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

This commit is contained in:
Sam Gateau 2015-02-14 02:32:18 -08:00
commit cfec8a31a5
54 changed files with 568 additions and 350 deletions

View file

@ -125,6 +125,8 @@ if (NOT ANDROID)
add_subdirectory(interface)
add_subdirectory(tests)
add_subdirectory(tools)
elseif (ANDROID OR DESKTOP_GVR)
endif ()
if (ANDROID OR DESKTOP_GVR)
add_subdirectory(gvr-interface)
endif ()

View file

@ -208,7 +208,7 @@ void Agent::run() {
_scriptEngine.init(); // must be done before we set up the viewers
_scriptEngine.registerGlobalObject("SoundCache", &SoundCache::getInstance());
_scriptEngine.registerGlobalObject("SoundCache", DependencyManager::get<SoundCache>().data());
_scriptEngine.registerGlobalObject("EntityViewer", &_entityViewer);
_entityViewer.setJurisdictionListener(_scriptEngine.getEntityScriptingInterface()->getJurisdictionListener());

View file

@ -136,7 +136,7 @@ AssignmentClient::AssignmentClient(int &argc, char **argv) :
// Create Singleton objects on main thread
NetworkAccessManager::getInstance();
SoundCache::getInstance();
auto soundCache = DependencyManager::get<SoundCache>();
}
void AssignmentClient::sendAssignmentRequest() {

View file

@ -147,3 +147,14 @@ void EntityServer::pruneDeletedEntities() {
}
}
void EntityServer::readAdditionalConfiguration(const QJsonObject& settingsSectionObject) {
bool wantEditLogging = false;
readOptionBool(QString("wantEditLogging"), settingsSectionObject, wantEditLogging);
qDebug("wantEditLogging=%s", debug::valueOf(wantEditLogging));
EntityTree* tree = static_cast<EntityTree*>(_tree);
tree->setWantEditLogging(wantEditLogging);
}

View file

@ -41,6 +41,7 @@ public:
virtual int sendSpecialPacket(const SharedNodePointer& node, OctreeQueryNode* queryNode, int& packetsSent);
virtual void entityCreated(const EntityItem& newEntity, const SharedNodePointer& senderNode);
virtual void readAdditionalConfiguration(const QJsonObject& settingsSectionObject);
public slots:
void pruneDeletedEntities();

View file

@ -409,6 +409,13 @@
"default": "",
"advanced": true
},
{
"name": "wantEditLogging",
"type": "checkbox",
"help": "Logging of all edits to entities",
"default": true,
"advanced": true
},
{
"name": "verboseDebug",
"type": "checkbox",

View file

@ -32,10 +32,4 @@ Script.update.connect(function() {
injector = Audio.playSound(sound, audioOptions);
print("Playing: " + injector);
}
});
Script.scriptEnding.connect(function() {
if (injector !== null) {
injector.stop();
}
});

View file

@ -85,10 +85,10 @@ function checkHands(deltaTime) {
var chord = Controller.getTriggerValue(chordHand);
if (volume > 1.0) volume = 1.0;
if ((chord > 0.1) && Audio.isInjectorPlaying(soundPlaying)) {
if ((chord > 0.1) && soundPlaying.isPlaying) {
// If chord finger trigger pulled, stop current chord
print("stopped sound");
Audio.stopInjector(soundPlaying);
soundPlaying.stop();
}
var BUTTON_COUNT = 6;
@ -132,16 +132,21 @@ function checkHands(deltaTime) {
}
function playChord(position, volume) {
if (Audio.isInjectorPlaying(soundPlaying)) {
if (soundPlaying.isPlaying) {
print("stopped sound");
Audio.stopInjector(soundPlaying);
soundPlaying.stop();
}
print("Played sound: " + whichChord + " at volume " + options.volume);
soundPlaying = Audio.playSound(chords[guitarSelector + whichChord], {
position: position,
volume: volume
});
if (!soundPlaying) {
soundPlaying = Audio.playSound(chords[guitarSelector + whichChord], {
position: position,
volume: volume
});
} else {
soundPlaying.restart();
}
}
function keyPressEvent(event) {

View file

@ -534,7 +534,9 @@ function highlightEntityUnderCursor(position, accurateRay) {
function mouseReleaseEvent(event) {
if (placingEntityID) {
selectionManager.setSelections([placingEntityID]);
if (isActive) {
selectionManager.setSelections([placingEntityID]);
}
placingEntityID = null;
}
if (isActive && selectionManager.hasSelection()) {
@ -957,9 +959,18 @@ PropertiesTool = function(opts) {
selectionManager.saveProperties();
for (var i = 0; i < selectionManager.selections.length; i++) {
var properties = selectionManager.savedProperties[selectionManager.selections[i].id];
Entities.editEntity(selectionManager.selections[i], {
dimensions: properties.naturalDimensions,
});
var naturalDimensions = properties.naturalDimensions;
// If any of the natural dimensions are not 0, resize
if (properties.type == "Model" && naturalDimensions.x == 0
&& naturalDimensions.y == 0 && naturalDimensions.z == 0) {
Window.alert("Cannot reset entity to its natural dimensions: Model URL"
+ " is invalid or the model has not yet been loaded.");
} else {
Entities.editEntity(selectionManager.selections[i], {
dimensions: properties.naturalDimensions,
});
}
}
pushCommandForSelections();
selectionManager._update();

View file

@ -48,7 +48,8 @@
this.turnSounds = new Array();
this.moveSound = null;
this.turnSound = null;
this.injector = null;
this.moveInjector = null;
this.turnInjector = null;
var debug = false;
var displayRotateTargets = true; // change to false if you don't want the rotate targets
@ -92,9 +93,14 @@
}
if (this.moveSound && this.moveSound.downloaded) {
if (debug) {
print("playMoveSound() --- calling this.injector = Audio.playSound(this.moveSound...)");
print("playMoveSound() --- calling this.moveInjector = Audio.playSound(this.moveSound...)");
}
if (!this.moveInjector) {
this.moveInjector = Audio.playSound(this.moveSound, { position: this.properties.position, loop: true, volume: 0.1 });
} else {
this.moveInjector.restart();
}
this.injector = Audio.playSound(this.moveSound, { position: this.properties.position, loop: true, volume: 0.1 });
}
}
@ -105,9 +111,13 @@
}
if (this.turnSound && this.turnSound.downloaded) {
if (debug) {
print("playTurnSound() --- calling this.injector = Audio.playSound(this.turnSound...)");
print("playTurnSound() --- calling this.turnInjector = Audio.playSound(this.turnSound...)");
}
if (!this.turnInjector) {
this.turnInjector = Audio.playSound(this.turnSound, { position: this.properties.position, loop: true, volume: 0.1 });
} else {
this.turnInjector.restart();
}
this.injector = Audio.playSound(this.turnSound, { position: this.properties.position, loop: true, volume: 0.1 });
}
}
@ -116,9 +126,11 @@
if (debug) {
print("stopSound()");
}
if (this.injector) {
Audio.stopInjector(this.injector);
this.injector = null;
if (this.turnInjector) {
this.turnInjector.stop();
}
if (this.moveInjector) {
this.moveInjector.stop();
}
}
@ -174,7 +186,7 @@
this.move = function(mouseEvent) {
this.updatePosition(mouseEvent);
if (this.injector === null) {
if (this.moveInjector === null || !this.moveInjector.isPlaying) {
this.playMoveSound();
}
};
@ -233,7 +245,7 @@
}
}
if (this.injector === null) {
if (this.turnInjector === null || !this.turnInjector.isPlaying) {
this.playTurnSound();
}
};

View file

@ -75,14 +75,14 @@ function maybePlaySound(deltaTime) {
//print("number playing = " + numPlaying);
}
for (var i = 0; i < playing.length; i++) {
if (!Audio.isInjectorPlaying(playing[i].audioId)) {
if (!playing[i].audioId.isPlaying) {
Entities.deleteEntity(playing[i].entityId);
if (useLights) {
Entities.deleteEntity(playing[i].lightId);
}
playing.splice(i, 1);
} else {
var loudness = Audio.getLoudness(playing[i].audioId);
var loudness = playing[i].audioId.loudness;
var newColor = { red: playing[i].color.red, green: playing[i].color.green, blue: playing[i].color.blue };
if (loudness > 0.05) {
newColor.red *= (1.0 - loudness);

View file

@ -76,9 +76,6 @@ function scriptEnding() {
if (entity != null) {
Entities.deleteEntity(entity);
}
if (injector != null) {
injector.stop();
}
}
Script.update.connect(update);

View file

@ -13,6 +13,9 @@
//
print("BUTTERFLIES START");
var numButterflies = 25;
@ -109,7 +112,7 @@ function updateButterflies(deltaTime) {
var properties = Entities.getEntityProperties(butterflies[i]);
if (Vec3.length(Vec3.subtract(properties.position, flockPosition)) > range) {
Entities.editEntity(butterflies[i], { position: flockPosition } );
} else if (properties.velocity.y < 0.0) {
} else if (properties.velocity.y <= 0.0) {
// If falling, Create a new direction and impulse
var HORIZ_SCALE = 0.50;
var VERT_SCALE = 0.50;
@ -139,3 +142,5 @@ Script.scriptEnding.connect(function() {
Entities.deleteEntity(butterflies[i]);
}
});
print("BUTTERFLIES END");

View file

@ -55,7 +55,9 @@ var droneSound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Lobby/drone.st
var currentDrone = null;
var latinSound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Lobby/latin.stereo.raw")
var latinInjector = null;
var elevatorSound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Lobby/elevator.stereo.raw")
var elevatorInjector = null;
var currentMuzakInjector = null;
var currentSound = null;
@ -140,7 +142,11 @@ function drawLobby() {
if (droneSound.downloaded) {
// start the drone sound
currentDrone = Audio.playSound(droneSound, { stereo: true, loop: true, localOnly: true, volume: DRONE_VOLUME });
if (!currentDrone) {
currentDrone = Audio.playSound(droneSound, { stereo: true, loop: true, localOnly: true, volume: DRONE_VOLUME });
} else {
currentDrone.restart();
}
}
// start one of our muzak sounds
@ -173,6 +179,26 @@ function changeLobbyTextures() {
var MUZAK_VOLUME = 0.1;
function playCurrentSound(secondOffset) {
if (currentSound == latinSound) {
if (!latinInjector) {
latinInjector = Audio.playSound(latinSound, { localOnly: true, secondOffset: secondOffset, volume: MUZAK_VOLUME });
} else {
latinInjector.restart();
}
currentMuzakInjector = latinInjector;
} else if (currentSound == elevatorSound) {
if (!elevatorInjector) {
elevatorInjector = Audio.playSound(elevatorSound, { localOnly: true, secondOffset: secondOffset, volume: MUZAK_VOLUME });
} else {
elevatorInjector.restart();
}
currentMuzakInjector = elevatorInjector;
}
}
function playNextMuzak() {
if (panelWall) {
if (currentSound == latinSound) {
@ -184,8 +210,8 @@ function playNextMuzak() {
currentSound = latinSound;
}
}
currentMuzakInjector = Audio.playSound(currentSound, { localOnly: true, volume: MUZAK_VOLUME });
playCurrentSound(0);
}
}
@ -200,10 +226,11 @@ function playRandomMuzak() {
currentSound = elevatorSound;
}
if (currentSound) {
if (currentSound) {
// pick a random number of seconds from 0-10 to offset the muzak
var secondOffset = Math.random() * 10;
currentMuzakInjector = Audio.playSound(currentSound, { localOnly: true, secondOffset: secondOffset, volume: MUZAK_VOLUME });
playCurrentSound(secondOffset);
} else {
currentMuzakInjector = null;
}
@ -227,10 +254,9 @@ function cleanupLobby() {
panelWall = false;
orbShell = false;
Audio.stopInjector(currentDrone);
currentDrone = null;
currentDrone.stop();
currentMuzakInjector.stop();
Audio.stopInjector(currentMuzakInjector);
currentMuzakInjector = null;
places = {};
@ -354,7 +380,7 @@ function update(deltaTime) {
Overlays.editOverlay(descriptionText, { position: textOverlayPosition() });
// if the reticle is up then we may need to play the next muzak
if (currentMuzakInjector && !Audio.isInjectorPlaying(currentMuzakInjector)) {
if (currentMuzakInjector && !currentMuzakInjector.isPlaying) {
playNextMuzak();
}
}

View file

@ -21,20 +21,13 @@ var offset = Vec3.normalize(Quat.getFront(MyAvatar.orientation));
var position = Vec3.sum(MyAvatar.position, offset);
function update(deltaTime) {
if (!Audio.isInjectorPlaying(soundPlaying)) {
soundPlaying = Audio.playSound(sound, {
position: position,
loop: true
});
print("Started sound loop");
}
}
function scriptEnding() {
if (Audio.isInjectorPlaying(soundPlaying)) {
Audio.stopInjector(soundPlaying);
print("Stopped sound loop");
}
if (sound.downloaded && !soundPlaying) {
print("Started sound loop");
soundPlaying = Audio.playSound(sound, {
position: position,
loop: true
});
}
}
Script.update.connect(update);

View file

@ -32,14 +32,13 @@ var sound = Audio.playSound(soundClip, { position: orbitCenter, loop: true, volu
function update(deltaTime) {
time += deltaTime;
currentPosition = { x: orbitCenter.x + Math.cos(time * SPEED) * RADIUS, y: orbitCenter.y, z: orbitCenter.z + Math.sin(time * SPEED) * RADIUS };
trailingLoudness = 0.9 * trailingLoudness + 0.1 * Audio.getLoudness(sound);
trailingLoudness = 0.9 * trailingLoudness + 0.1 * sound.loudness;
Entities.editEntity( objectId, { position: currentPosition, color: { red: Math.min(trailingLoudness * 2000, 255), green: 0, blue: 0 } } );
Audio.setInjectorOptions(sound, { position: currentPosition });
sound.setOptions({ position: currentPosition });
}
Script.scriptEnding.connect(function() {
Entities.deleteEntity(objectId);
Audio.stopInjector(sound);
});
Script.update.connect(update);

View file

@ -30,7 +30,7 @@ var playing = false;
var ball = false;
function maybePlaySound(deltaTime) {
if (sound.downloaded) {
if (sound.downloaded && !soundPlaying) {
var properties = {
type: "Sphere",
position: options.position,
@ -45,11 +45,9 @@ function maybePlaySound(deltaTime) {
}
function scriptEnding() {
if (Audio.isInjectorPlaying(soundPlaying)) {
Audio.stopInjector(soundPlaying);
Entities.deleteEntity(ball);
print("Stopped sound.");
}
if (ball) {
Entities.deleteEntity(ball);
}
}
// Connect a call back that happens every frame

View file

@ -9,8 +9,6 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include <QtCore/QThread>
#include <AccountManager.h>
#include <AddressManager.h>
#include <HifiSockAddr.h>

View file

@ -16,13 +16,14 @@
#include <HifiSockAddr.h>
class QThread;
class Client : public QObject {
Q_OBJECT
public:
Client(QObject* parent = 0);
virtual void cleanupBeforeQuit() = 0;
protected:
void setupNetworking();
virtual void processVerifiedPacket(const HifiSockAddr& senderSockAddr, const QByteArray& incomingPacket);
private slots:

View file

@ -86,6 +86,13 @@ GVRInterface::GVRInterface(int argc, char* argv[]) :
QTimer* idleTimer = new QTimer(this);
connect(idleTimer, &QTimer::timeout, this, &GVRInterface::idle);
idleTimer->start(0);
// call our quit handler before we go down
connect(this, &QCoreApplication::aboutToQuit, this, &GVRInterface::handleApplicationQuit);
}
void GVRInterface::handleApplicationQuit() {
_client->cleanupBeforeQuit();
}
void GVRInterface::idle() {

View file

@ -53,6 +53,7 @@ private slots:
void handleApplicationStateChange(Qt::ApplicationState state);
void idle();
private:
void handleApplicationQuit();
void enterVRMode();
void leaveVRMode();

View file

@ -37,7 +37,7 @@ RenderingClient::RenderingClient(QObject *parent, const QString& launchURLString
DependencyManager::set<AvatarHashMap>();
// get our audio client setup on its own thread
QThread* audioThread = new QThread(this);
QThread* audioThread = new QThread();
auto audioClient = DependencyManager::set<AudioClient>();
audioClient->setPositionGetter(getPositionForAudio);
@ -45,6 +45,8 @@ RenderingClient::RenderingClient(QObject *parent, const QString& launchURLString
audioClient->moveToThread(audioThread);
connect(audioThread, &QThread::started, audioClient.data(), &AudioClient::start);
connect(audioClient.data(), &AudioClient::destroyed, audioThread, &QThread::quit);
connect(audioThread, &QThread::finished, audioThread, &QThread::deleteLater);
audioThread->start();
@ -68,15 +70,13 @@ void RenderingClient::sendAvatarPacket() {
_fakeAvatar.sendIdentityPacket();
}
RenderingClient::~RenderingClient() {
auto audioClient = DependencyManager::get<AudioClient>();
// stop the audio client
QMetaObject::invokeMethod(audioClient.data(), "stop", Qt::BlockingQueuedConnection);
void RenderingClient::cleanupBeforeQuit() {
// ask the audio thread to quit and wait until it is done
audioClient->thread()->quit();
audioClient->thread()->wait();
QMetaObject::invokeMethod(DependencyManager::get<AudioClient>().data(),
"stop", Qt::BlockingQueuedConnection);
// destroy the AudioClient so it and its thread will safely go down
DependencyManager::destroy<AudioClient>();
}
void RenderingClient::processVerifiedPacket(const HifiSockAddr& senderSockAddr, const QByteArray& incomingPacket) {

View file

@ -26,7 +26,6 @@ class RenderingClient : public Client {
Q_OBJECT
public:
RenderingClient(QObject* parent = 0, const QString& launchURLString = QString());
~RenderingClient();
const glm::vec3& getPosition() const { return _position; }
const glm::quat& getOrientation() const { return _orientation; }
@ -35,6 +34,8 @@ public:
static glm::vec3 getPositionForAudio() { return _instance->getPosition(); }
static glm::quat getOrientationForAudio() { return _instance->getOrientation(); }
virtual void cleanupBeforeQuit();
private slots:
void goToLocation(const glm::vec3& newPosition,
bool hasOrientationChange, const glm::quat& newOrientation,

View file

@ -65,6 +65,7 @@
#include <HFBackEvent.h>
#include <LogHandler.h>
#include <MainWindow.h>
#include <ModelEntityItem.h>
#include <NetworkAccessManager.h>
#include <OctalCode.h>
#include <OctreeSceneStats.h>
@ -211,6 +212,8 @@ bool setupEssentials(int& argc, char** argv) {
auto addressManager = DependencyManager::set<AddressManager>();
auto nodeList = DependencyManager::set<NodeList>(NodeType::Agent, listenPort);
auto geometryCache = DependencyManager::set<GeometryCache>();
auto scriptCache = DependencyManager::set<ScriptCache>();
auto soundCache = DependencyManager::set<SoundCache>();
auto glowEffect = DependencyManager::set<GlowEffect>();
auto faceshift = DependencyManager::set<Faceshift>();
auto audio = DependencyManager::set<AudioClient>();
@ -328,7 +331,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
connect(&nodeList->getNodeSocket(), SIGNAL(readyRead()), &_datagramProcessor, SLOT(processDatagrams()));
// put the audio processing on a separate thread
QThread* audioThread = new QThread(this);
QThread* audioThread = new QThread();
audioThread->setObjectName("Audio Thread");
auto audioIO = DependencyManager::get<AudioClient>();
@ -338,7 +341,9 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
audioIO->moveToThread(audioThread);
connect(audioThread, &QThread::started, audioIO.data(), &AudioClient::start);
connect(audioIO.data(), SIGNAL(muteToggled()), this, SLOT(audioMuteToggled()));
connect(audioIO.data(), &AudioClient::destroyed, audioThread, &QThread::quit);
connect(audioThread, &QThread::finished, audioThread, &QThread::deleteLater);
connect(audioIO.data(), &AudioClient::muteToggled, this, &Application::audioMuteToggled);
audioThread->start();
@ -516,56 +521,65 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
void Application::aboutToQuit() {
_aboutToQuit = true;
cleanupBeforeQuit();
}
Application::~Application() {
void Application::cleanupBeforeQuit() {
// make sure we don't call the idle timer any more
delete idleTimer;
// save state
QMetaObject::invokeMethod(&_settingsTimer, "stop", Qt::BlockingQueuedConnection);
_settingsThread.quit();
saveSettings();
_entities.getTree()->setSimulation(NULL);
qInstallMessageHandler(NULL);
_window->saveGeometry();
int DELAY_TIME = 1000;
UserActivityLogger::getInstance().close(DELAY_TIME);
// make sure we don't call the idle timer any more
delete idleTimer;
// TODO: now that this is in cleanupBeforeQuit do we really need it to stop and force
// an event loop to send the packet?
UserActivityLogger::getInstance().close();
// let the avatar mixer know we're out
MyAvatar::sendKillAvatar();
// stop the AudioClient
QMetaObject::invokeMethod(DependencyManager::get<AudioClient>().data(),
"stop", Qt::BlockingQueuedConnection);
// destroy the AudioClient so it and its thread have a chance to go down safely
DependencyManager::destroy<AudioClient>();
}
Application::~Application() {
EntityTree* tree = _entities.getTree();
tree->lockForWrite();
_entities.getTree()->setSimulation(NULL);
tree->unlock();
qInstallMessageHandler(NULL);
// ask the datagram processing thread to quit and wait until it is done
_nodeThread->quit();
_nodeThread->wait();
// kill any audio injectors that are still around
AudioScriptingInterface::getInstance().stopAllInjectors();
auto audioIO = DependencyManager::get<AudioClient>();
// stop the audio process
QMetaObject::invokeMethod(audioIO.data(), "stop", Qt::BlockingQueuedConnection);
// ask the audio thread to quit and wait until it is done
audioIO->thread()->quit();
audioIO->thread()->wait();
_octreeProcessor.terminate();
_entityEditSender.terminate();
Menu::getInstance()->deleteLater();
_myAvatar = NULL;
ModelEntityItem::cleanupLoadedAnimations() ;
DependencyManager::destroy<GLCanvas>();
qDebug() << "start destroying ResourceCaches Application::~Application() line:" << __LINE__;
DependencyManager::destroy<AnimationCache>();
DependencyManager::destroy<TextureCache>();
DependencyManager::destroy<GeometryCache>();
DependencyManager::destroy<ScriptCache>();
DependencyManager::destroy<SoundCache>();
qDebug() << "done destroying ResourceCaches Application::~Application() line:" << __LINE__;
}
void Application::initializeGL() {
@ -3464,7 +3478,7 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri
scriptEngine->registerGlobalObject("Settings", SettingsScriptingInterface::getInstance());
scriptEngine->registerGlobalObject("AudioDevice", AudioDeviceScriptingInterface::getInstance());
scriptEngine->registerGlobalObject("AnimationCache", DependencyManager::get<AnimationCache>().data());
scriptEngine->registerGlobalObject("SoundCache", &SoundCache::getInstance());
scriptEngine->registerGlobalObject("SoundCache", DependencyManager::get<SoundCache>().data());
scriptEngine->registerGlobalObject("Account", AccountScriptingInterface::getInstance());
scriptEngine->registerGlobalObject("Metavoxels", &_metavoxels);

View file

@ -410,6 +410,8 @@ private:
void initDisplay();
void init();
void cleanupBeforeQuit();
void update(float deltaTime);

View file

@ -59,8 +59,8 @@ CachesSizeDialog::CachesSizeDialog(QWidget* parent) :
void CachesSizeDialog::confirmClicked(bool checked) {
DependencyManager::get<AnimationCache>()->setUnusedResourceCacheSize(_animations->value() * BYTES_PER_MEGABYTES);
DependencyManager::get<GeometryCache>()->setUnusedResourceCacheSize(_geometries->value() * BYTES_PER_MEGABYTES);
ScriptCache::getInstance()->setUnusedResourceCacheSize(_scripts->value() * BYTES_PER_MEGABYTES);
SoundCache::getInstance().setUnusedResourceCacheSize(_sounds->value() * BYTES_PER_MEGABYTES);
DependencyManager::get<ScriptCache>()->setUnusedResourceCacheSize(_scripts->value() * BYTES_PER_MEGABYTES);
DependencyManager::get<SoundCache>()->setUnusedResourceCacheSize(_sounds->value() * BYTES_PER_MEGABYTES);
DependencyManager::get<TextureCache>()->setUnusedResourceCacheSize(_textures->value() * BYTES_PER_MEGABYTES);
QDialog::close();
@ -69,8 +69,8 @@ void CachesSizeDialog::confirmClicked(bool checked) {
void CachesSizeDialog::resetClicked(bool checked) {
_animations->setValue(DependencyManager::get<AnimationCache>()->getUnusedResourceCacheSize() / BYTES_PER_MEGABYTES);
_geometries->setValue(DependencyManager::get<GeometryCache>()->getUnusedResourceCacheSize() / BYTES_PER_MEGABYTES);
_scripts->setValue(ScriptCache::getInstance()->getUnusedResourceCacheSize() / BYTES_PER_MEGABYTES);
_sounds->setValue(SoundCache::getInstance().getUnusedResourceCacheSize() / BYTES_PER_MEGABYTES);
_scripts->setValue(DependencyManager::get<ScriptCache>()->getUnusedResourceCacheSize() / BYTES_PER_MEGABYTES);
_sounds->setValue(DependencyManager::get<SoundCache>()->getUnusedResourceCacheSize() / BYTES_PER_MEGABYTES);
_textures->setValue(DependencyManager::get<TextureCache>()->getUnusedResourceCacheSize() / BYTES_PER_MEGABYTES);
}

View file

@ -19,7 +19,9 @@
#include "Rectangle3DOverlay.h"
Rectangle3DOverlay::Rectangle3DOverlay() {
Rectangle3DOverlay::Rectangle3DOverlay() :
_geometryCacheID(DependencyManager::get<GeometryCache>()->allocateID())
{
}
Rectangle3DOverlay::Rectangle3DOverlay(const Rectangle3DOverlay* rectangle3DOverlay) :

View file

@ -136,6 +136,8 @@ AudioClient::AudioClient() :
}
AudioClient::~AudioClient() {
stop();
if (_gverbLocal) {
gverb_free(_gverbLocal);
}
@ -489,7 +491,6 @@ void AudioClient::start() {
}
void AudioClient::stop() {
_inputFrameBuffer.finalize();
_inputGain.finalize();
_sourceGain.finalize();
@ -974,14 +975,16 @@ bool AudioClient::outputLocalInjector(bool isStereo, qreal volume, AudioInjector
QAudioOutput* localOutput = new QAudioOutput(getNamedAudioDeviceForMode(QAudio::AudioOutput, _outputAudioDeviceName),
localFormat,
injector);
injector->getLocalBuffer());
localOutput->setVolume(volume);
// move the localOutput to the same thread as the local injector buffer
localOutput->moveToThread(injector->getLocalBuffer()->thread());
// have it be cleaned up when that injector is done
connect(injector, &AudioInjector::finished, localOutput, &QAudioOutput::stop);
// have it be stopped when that local buffer is about to close
connect(injector->getLocalBuffer(), &AudioInjectorLocalBuffer::bufferEmpty, localOutput, &QAudioOutput::stop);
connect(injector->getLocalBuffer(), &QIODevice::aboutToClose, localOutput, &QAudioOutput::stop);
qDebug() << "Starting QAudioOutput for local injector" << localOutput;
@ -992,7 +995,6 @@ bool AudioClient::outputLocalInjector(bool isStereo, qreal volume, AudioInjector
return false;
}
void AudioClient::outputFormatChanged() {
int outputFormatChannelCountTimesSampleRate = _outputFormat.channelCount() * _outputFormat.sampleRate();
_outputFrameSize = AudioConstants::NETWORK_FRAME_SAMPLES_PER_CHANNEL * outputFormatChannelCountTimesSampleRate / _desiredOutputFormat.sampleRate();

View file

@ -188,6 +188,10 @@ protected:
AudioClient();
~AudioClient();
virtual void customDeleter() {
deleteLater();
}
private:
void outputFormatChanged();

View file

@ -9,6 +9,7 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include <QtCore/QCoreApplication>
#include <QtCore/QDataStream>
#include <NodeList.h>
@ -21,79 +22,77 @@
#include "AudioInjector.h"
QScriptValue injectorToScriptValue(QScriptEngine* engine, AudioInjector* const& in) {
return engine->newQObject(in);
}
void injectorFromScriptValue(const QScriptValue& object, AudioInjector*& out) {
out = qobject_cast<AudioInjector*>(object.toQObject());
}
AudioInjector::AudioInjector(QObject* parent) :
QObject(parent),
_options(),
_shouldStop(false),
_loudness(0.0f),
_isFinished(false),
_currentSendPosition(0),
_localBuffer(NULL)
QObject(parent)
{
}
AudioInjector::AudioInjector(Sound* sound, const AudioInjectorOptions& injectorOptions) :
_audioData(sound->getByteArray()),
_options(injectorOptions),
_shouldStop(false),
_loudness(0.0f),
_isFinished(false),
_currentSendPosition(0),
_localBuffer(NULL)
_options(injectorOptions)
{
}
AudioInjector::AudioInjector(const QByteArray& audioData, const AudioInjectorOptions& injectorOptions) :
_audioData(audioData),
_options(injectorOptions),
_shouldStop(false),
_loudness(0.0f),
_isFinished(false),
_currentSendPosition(0),
_localBuffer(NULL)
_options(injectorOptions)
{
}
AudioInjector::~AudioInjector() {
if (_localBuffer) {
_localBuffer->stop();
void AudioInjector::setIsFinished(bool isFinished) {
_isFinished = isFinished;
if (_isFinished) {
emit finished();
if (_localBuffer) {
_localBuffer->stop();
_localBuffer->deleteLater();
_localBuffer = NULL;
}
_isStarted = false;
_shouldStop = false;
if (_shouldDeleteAfterFinish) {
// we've been asked to delete after finishing, trigger a queued deleteLater here
qDebug() << "AudioInjector triggering delete from setIsFinished";
QMetaObject::invokeMethod(this, "deleteLater", Qt::QueuedConnection);
}
}
}
void AudioInjector::setOptions(AudioInjectorOptions& options) {
_options = options;
}
float AudioInjector::getLoudness() {
return _loudness;
}
void AudioInjector::injectAudio() {
// check if we need to offset the sound by some number of seconds
if (_options.secondOffset > 0.0f) {
if (!_isStarted) {
// check if we need to offset the sound by some number of seconds
if (_options.secondOffset > 0.0f) {
// convert the offset into a number of bytes
int byteOffset = (int) floorf(AudioConstants::SAMPLE_RATE * _options.secondOffset * (_options.stereo ? 2.0f : 1.0f));
byteOffset *= sizeof(int16_t);
_currentSendPosition = byteOffset;
} else {
_currentSendPosition = 0;
}
// convert the offset into a number of bytes
int byteOffset = (int) floorf(AudioConstants::SAMPLE_RATE * _options.secondOffset * (_options.stereo ? 2.0f : 1.0f));
byteOffset *= sizeof(int16_t);
_currentSendPosition = byteOffset;
}
if (_options.localOnly) {
injectLocally();
if (_options.localOnly) {
injectLocally();
} else {
injectToMixer();
}
} else {
injectToMixer();
}
qDebug() << "AudioInjector::injectAudio called but already started.";
}
}
void AudioInjector::restart() {
qDebug() << "Restarting an AudioInjector by stopping and starting over.";
stop();
setIsFinished(false);
QMetaObject::invokeMethod(this, "injectAudio", Qt::QueuedConnection);
}
void AudioInjector::injectLocally() {
@ -102,6 +101,7 @@ void AudioInjector::injectLocally() {
if (_audioData.size() > 0) {
_localBuffer = new AudioInjectorLocalBuffer(_audioData, this);
_localBuffer->open(QIODevice::ReadOnly);
_localBuffer->setShouldLoop(_options.loop);
@ -236,6 +236,14 @@ void AudioInjector::injectToMixer() {
// send two packets before the first sleep so the mixer can start playback right away
if (_currentSendPosition != bytesToCopy && _currentSendPosition < _audioData.size()) {
// process events in case we have been told to stop and be deleted
QCoreApplication::processEvents();
if (_shouldStop) {
break;
}
// not the first packet and not done
// sleep for the appropriate time
int usecToSleep = (++nextFrame * AudioConstants::NETWORK_FRAME_USECS) - timer.nsecsElapsed() / 1000;
@ -251,8 +259,7 @@ void AudioInjector::injectToMixer() {
}
}
_isFinished = true;
emit finished();
setIsFinished(true);
}
void AudioInjector::stop() {
@ -260,7 +267,11 @@ void AudioInjector::stop() {
if (_options.localOnly) {
// we're only a local injector, so we can say we are finished right away too
_isFinished = true;
emit finished();
setIsFinished(true);
}
}
void AudioInjector::stopAndDeleteLater() {
stop();
QMetaObject::invokeMethod(this, "deleteLater", Qt::QueuedConnection);
}

View file

@ -13,6 +13,7 @@
#define hifi_AudioInjector_h
#include <QtCore/QObject>
#include <QtCore/QSharedPointer>
#include <QtCore/QThread>
#include <glm/glm.hpp>
@ -24,15 +25,18 @@
class AbstractAudioInterface;
// In order to make scripting cleaner for the AudioInjector, the script now holds on to the AudioInjector object
// until it dies.
class AudioInjector : public QObject {
Q_OBJECT
public:
AudioInjector(QObject* parent);
AudioInjector(Sound* sound, const AudioInjectorOptions& injectorOptions);
AudioInjector(const QByteArray& audioData, const AudioInjectorOptions& injectorOptions);
~AudioInjector();
bool isFinished() const { return _isFinished; }
int getCurrentSendPosition() const { return _currentSendPosition; }
AudioInjectorLocalBuffer* getLocalBuffer() const { return _localBuffer; }
@ -41,30 +45,37 @@ public:
void setLocalAudioInterface(AbstractAudioInterface* localAudioInterface) { _localAudioInterface = localAudioInterface; }
public slots:
void injectAudio();
void restart();
void stop();
void setOptions(AudioInjectorOptions& options);
void triggerDeleteAfterFinish() { _shouldDeleteAfterFinish = true; }
void stopAndDeleteLater();
void setOptions(AudioInjectorOptions& options) { _options = options; }
void setCurrentSendPosition(int currentSendPosition) { _currentSendPosition = currentSendPosition; }
float getLoudness();
float getLoudness() const { return _loudness; }
bool isPlaying() const { return !_isFinished; }
signals:
void finished();
private:
void injectToMixer();
void injectLocally();
void setIsFinished(bool isFinished);
QByteArray _audioData;
AudioInjectorOptions _options;
bool _shouldStop;
float _loudness;
bool _isFinished;
int _currentSendPosition;
AbstractAudioInterface* _localAudioInterface;
AudioInjectorLocalBuffer* _localBuffer;
bool _shouldStop = false;
float _loudness = 0.0f;
bool _isStarted = false;
bool _isFinished = false;
bool _shouldDeleteAfterFinish = false;
int _currentSendPosition = 0;
AbstractAudioInterface* _localAudioInterface = NULL;
AudioInjectorLocalBuffer* _localBuffer = NULL;
};
Q_DECLARE_METATYPE(AudioInjector*)
QScriptValue injectorToScriptValue(QScriptEngine* engine, AudioInjector* const& in);
void injectorFromScriptValue(const QScriptValue& object, AudioInjector*& out);
#endif // hifi_AudioInjector_h

View file

@ -23,9 +23,18 @@ AudioInjectorLocalBuffer::AudioInjectorLocalBuffer(const QByteArray& rawAudioArr
void AudioInjectorLocalBuffer::stop() {
_isStopped = true;
QIODevice::close();
}
bool AudioInjectorLocalBuffer::seek(qint64 pos) {
if (_isStopped) {
return false;
} else {
return QIODevice::seek(pos);
}
}
qint64 AudioInjectorLocalBuffer::readData(char* data, qint64 maxSize) {
if (!_isStopped) {

View file

@ -21,6 +21,8 @@ public:
void stop();
bool seek(qint64 pos);
qint64 readData(char* data, qint64 maxSize);
qint64 writeData(const char* data, qint64 maxSize) { return 0; }

View file

@ -15,11 +15,6 @@
static int soundPointerMetaTypeId = qRegisterMetaType<SharedSoundPointer>();
SoundCache& SoundCache::getInstance() {
static SoundCache staticInstance;
return staticInstance;
}
SoundCache::SoundCache(QObject* parent) :
ResourceCache(parent)
{

View file

@ -17,11 +17,11 @@
#include "Sound.h"
/// Scriptable interface for sound loading.
class SoundCache : public ResourceCache {
class SoundCache : public ResourceCache, public Dependency {
Q_OBJECT
SINGLETON_DEPENDENCY
public:
static SoundCache& getInstance();
Q_INVOKABLE SharedSoundPointer getSound(const QUrl& url);
protected:

View file

@ -194,6 +194,7 @@ public:
bool containsBoundsProperties() const { return (_positionChanged || _dimensionsChanged); }
bool containsPositionChange() const { return _positionChanged; }
bool containsDimensionsChange() const { return _dimensionsChanged; }
bool containsAnimationSettingsChange() const { return _animationSettingsChanged; }
float getGlowLevel() const { return _glowLevel; }
float getLocalRenderAlpha() const { return _localRenderAlpha; }
@ -256,12 +257,57 @@ inline void EntityItemProperties::setPosition(const glm::vec3& value)
inline QDebug operator<<(QDebug debug, const EntityItemProperties& properties) {
debug << "EntityItemProperties[" << "\n"
<< " position:" << properties.getPosition() << "in meters" << "\n"
<< " velocity:" << properties.getVelocity() << "in meters" << "\n"
<< " last edited:" << properties.getLastEdited() << "\n"
<< " edited ago:" << properties.getEditedAgo() << "\n"
<< "]";
debug << "EntityItemProperties[" << "\n";
// TODO: figure out why position and animationSettings don't seem to like the macro approach
if (properties.containsPositionChange()) {
debug << " position:" << properties.getPosition() << "in meters" << "\n";
}
if (properties.containsAnimationSettingsChange()) {
debug << " animationSettings:" << properties.getAnimationSettings() << "\n";
}
DEBUG_PROPERTY_IF_CHANGED(debug, properties, Dimensions, dimensions, "in meters");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, Velocity, velocity, "in meters");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, Visible, visible, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, Rotation, rotation, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, Density, density, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, Gravity, gravity, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, Damping, damping, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, Lifetime, lifetime, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, Script, script, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, Color, color, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, ModelURL, modelURL, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, AnimationURL, animationURL, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, AnimationFPS, animationFPS, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, AnimationFrameIndex, animationFrameIndex, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, AnimationIsPlaying, animationIsPlaying, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, RegistrationPoint, registrationPoint, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, AngularVelocity, angularVelocity, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, AngularDamping, angularDamping, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, IgnoreForCollisions, ignoreForCollisions, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, CollisionsWillMove, collisionsWillMove, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, IsSpotlight, isSpotlight, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, DiffuseColor, diffuseColor, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, AmbientColor, ambientColor, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, SpecularColor, specularColor, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, ConstantAttenuation, constantAttenuation, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, LinearAttenuation, linearAttenuation, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, QuadraticAttenuation, quadraticAttenuation, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, Exponent, exponent, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, Cutoff, cutoff, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, Locked, locked, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, Textures, textures, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, UserData, userData, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, Text, text, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, LineHeight, lineHeight, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, TextColor, textColor, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, BackgroundColor, backgroundColor, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, ShapeType, shapeType, "");
debug << " last edited:" << properties.getLastEdited() << "\n";
debug << " edited ago:" << properties.getEditedAgo() << "\n";
debug << "]";
return debug;
}

View file

@ -321,6 +321,10 @@
T _##n; \
bool _##n##Changed;
#define DEBUG_PROPERTY_IF_CHANGED(D, P, N, n, x) \
if (P.n##Changed()) { \
D << " " << #n << ":" << P.get##N() << x << "\n"; \
}
#endif // hifi_EntityItemPropertiesMacros_h

View file

@ -592,6 +592,10 @@ int EntityTree::processEditPacketData(PacketType packetType, const unsigned char
// if the EntityItem exists, then update it
if (existingEntity) {
if (wantEditLogging()) {
qDebug() << "User [" << senderNode->getUUID() << "] editing entity. ID:" << entityItemID;
qDebug() << " properties:" << properties;
}
updateEntity(entityItemID, properties, senderNode->getCanAdjustLocks());
existingEntity->markAsChangedOnServer();
} else {

View file

@ -151,6 +151,9 @@ public:
void emitEntityScriptChanging(const EntityItemID& entityItemID);
void setSimulation(EntitySimulation* simulation);
bool wantEditLogging() const { return _wantEditLogging; }
void setWantEditLogging(bool value) { _wantEditLogging = value; }
signals:
void deletingEntity(const EntityItemID& entityID);
@ -180,6 +183,8 @@ private:
QHash<EntityItemID, EntityTreeElement*> _entityToElementMap;
EntitySimulation* _simulation;
bool _wantEditLogging = false;
};
#endif // hifi_EntityTree_h

View file

@ -163,16 +163,6 @@ void ModelEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBit
QMap<QString, AnimationPointer> ModelEntityItem::_loadedAnimations; // TODO: improve cleanup by leveraging the AnimationPointer(s)
// This class/instance will cleanup the animations once unloaded.
class EntityAnimationsBookkeeper {
public:
~EntityAnimationsBookkeeper() {
ModelEntityItem::cleanupLoadedAnimations();
}
};
EntityAnimationsBookkeeper modelAnimationsBookkeeperInstance;
void ModelEntityItem::cleanupLoadedAnimations() {
foreach(AnimationPointer animation, _loadedAnimations) {
animation.clear();

View file

@ -465,9 +465,9 @@ void Bitstream::writeRawDelta(const QScriptValue& value, const QScriptValue& ref
} else if (reference.isArray()) {
if (value.isArray()) {
*this << false;
int length = value.property(ScriptCache::getInstance()->getLengthString()).toInt32();
int length = value.property(DependencyManager::get<ScriptCache>()->getLengthString()).toInt32();
*this << length;
int referenceLength = reference.property(ScriptCache::getInstance()->getLengthString()).toInt32();
int referenceLength = reference.property(DependencyManager::get<ScriptCache>()->getLengthString()).toInt32();
for (int i = 0; i < length; i++) {
if (i < referenceLength) {
writeDelta(value.property(i), reference.property(i));
@ -555,7 +555,7 @@ void Bitstream::readRawDelta(QScriptValue& value, const QScriptValue& reference)
} else {
QVariant variant;
readRawDelta(variant, reference.toVariant());
value = ScriptCache::getInstance()->getEngine()->newVariant(variant);
value = DependencyManager::get<ScriptCache>()->getEngine()->newVariant(variant);
}
} else if (reference.isQObject()) {
bool typeChanged;
@ -566,7 +566,7 @@ void Bitstream::readRawDelta(QScriptValue& value, const QScriptValue& reference)
} else {
QObject* object;
readRawDelta(object, reference.toQObject());
value = ScriptCache::getInstance()->getEngine()->newQObject(object, QScriptEngine::ScriptOwnership);
value = DependencyManager::get<ScriptCache>()->getEngine()->newQObject(object, QScriptEngine::ScriptOwnership);
}
} else if (reference.isQMetaObject()) {
bool typeChanged;
@ -577,7 +577,7 @@ void Bitstream::readRawDelta(QScriptValue& value, const QScriptValue& reference)
} else {
const QMetaObject* metaObject;
*this >> metaObject;
value = ScriptCache::getInstance()->getEngine()->newQMetaObject(metaObject);
value = DependencyManager::get<ScriptCache>()->getEngine()->newQMetaObject(metaObject);
}
} else if (reference.isDate()) {
bool typeChanged;
@ -588,7 +588,7 @@ void Bitstream::readRawDelta(QScriptValue& value, const QScriptValue& reference)
} else {
QDateTime dateTime;
*this >> dateTime;
value = ScriptCache::getInstance()->getEngine()->newDate(dateTime);
value = DependencyManager::get<ScriptCache>()->getEngine()->newDate(dateTime);
}
} else if (reference.isRegExp()) {
bool typeChanged;
@ -599,7 +599,7 @@ void Bitstream::readRawDelta(QScriptValue& value, const QScriptValue& reference)
} else {
QRegExp regExp;
*this >> regExp;
value = ScriptCache::getInstance()->getEngine()->newRegExp(regExp);
value = DependencyManager::get<ScriptCache>()->getEngine()->newRegExp(regExp);
}
} else if (reference.isArray()) {
bool typeChanged;
@ -610,8 +610,8 @@ void Bitstream::readRawDelta(QScriptValue& value, const QScriptValue& reference)
} else {
int length;
*this >> length;
value = ScriptCache::getInstance()->getEngine()->newArray(length);
int referenceLength = reference.property(ScriptCache::getInstance()->getLengthString()).toInt32();
value = DependencyManager::get<ScriptCache>()->getEngine()->newArray(length);
int referenceLength = reference.property(DependencyManager::get<ScriptCache>()->getLengthString()).toInt32();
for (int i = 0; i < length; i++) {
QScriptValue element;
if (i < referenceLength) {
@ -630,7 +630,7 @@ void Bitstream::readRawDelta(QScriptValue& value, const QScriptValue& reference)
} else {
// start by shallow-copying the reference
value = ScriptCache::getInstance()->getEngine()->newObject();
value = DependencyManager::get<ScriptCache>()->getEngine()->newObject();
for (QScriptValueIterator it(reference); it.hasNext(); ) {
it.next();
value.setProperty(it.scriptName(), it.value());
@ -1036,7 +1036,7 @@ Bitstream& Bitstream::operator<<(const QScriptValue& value) {
} else if (value.isArray()) {
writeScriptValueType(*this, ARRAY_SCRIPT_VALUE);
int length = value.property(ScriptCache::getInstance()->getLengthString()).toInt32();
int length = value.property(DependencyManager::get<ScriptCache>()->getLengthString()).toInt32();
*this << length;
for (int i = 0; i < length; i++) {
*this << value.property(i);
@ -1087,37 +1087,37 @@ Bitstream& Bitstream::operator>>(QScriptValue& value) {
case VARIANT_SCRIPT_VALUE: {
QVariant variantValue;
*this >> variantValue;
value = ScriptCache::getInstance()->getEngine()->newVariant(variantValue);
value = DependencyManager::get<ScriptCache>()->getEngine()->newVariant(variantValue);
break;
}
case QOBJECT_SCRIPT_VALUE: {
QObject* object;
*this >> object;
ScriptCache::getInstance()->getEngine()->newQObject(object, QScriptEngine::ScriptOwnership);
DependencyManager::get<ScriptCache>()->getEngine()->newQObject(object, QScriptEngine::ScriptOwnership);
break;
}
case QMETAOBJECT_SCRIPT_VALUE: {
const QMetaObject* metaObject;
*this >> metaObject;
ScriptCache::getInstance()->getEngine()->newQMetaObject(metaObject);
DependencyManager::get<ScriptCache>()->getEngine()->newQMetaObject(metaObject);
break;
}
case DATE_SCRIPT_VALUE: {
QDateTime dateTime;
*this >> dateTime;
value = ScriptCache::getInstance()->getEngine()->newDate(dateTime);
value = DependencyManager::get<ScriptCache>()->getEngine()->newDate(dateTime);
break;
}
case REGEXP_SCRIPT_VALUE: {
QRegExp regExp;
*this >> regExp;
value = ScriptCache::getInstance()->getEngine()->newRegExp(regExp);
value = DependencyManager::get<ScriptCache>()->getEngine()->newRegExp(regExp);
break;
}
case ARRAY_SCRIPT_VALUE: {
int length;
*this >> length;
value = ScriptCache::getInstance()->getEngine()->newArray(length);
value = DependencyManager::get<ScriptCache>()->getEngine()->newArray(length);
for (int i = 0; i < length; i++) {
QScriptValue element;
*this >> element;
@ -1126,7 +1126,7 @@ Bitstream& Bitstream::operator>>(QScriptValue& value) {
break;
}
case OBJECT_SCRIPT_VALUE: {
value = ScriptCache::getInstance()->getEngine()->newObject();
value = DependencyManager::get<ScriptCache>()->getEngine()->newObject();
forever {
QScriptString name;
*this >> name;
@ -1477,7 +1477,7 @@ Bitstream& Bitstream::operator>(QScriptString& string) {
QString rawString;
*this >> rawString;
string = (rawString == INVALID_STRING) ? QScriptString() :
ScriptCache::getInstance()->getEngine()->toStringHandle(rawString);
DependencyManager::get<ScriptCache>()->getEngine()->toStringHandle(rawString);
return *this;
}
@ -1828,7 +1828,7 @@ QJsonValue JSONWriter::getData(const QScriptValue& value) {
} else if (value.isArray()) {
object.insert("type", QString("ARRAY"));
QJsonArray array;
int length = value.property(ScriptCache::getInstance()->getLengthString()).toInt32();
int length = value.property(DependencyManager::get<ScriptCache>()->getLengthString()).toInt32();
for (int i = 0; i < length; i++) {
array.append(getData(value.property(i)));
}
@ -2209,31 +2209,31 @@ void JSONReader::putData(const QJsonValue& data, QScriptValue& value) {
} else if (type == "VARIANT") {
QVariant variant;
putData(object.value("value"), variant);
value = ScriptCache::getInstance()->getEngine()->newVariant(variant);
value = DependencyManager::get<ScriptCache>()->getEngine()->newVariant(variant);
} else if (type == "QOBJECT") {
QObject* qObject;
putData(object.value("value"), qObject);
value = ScriptCache::getInstance()->getEngine()->newQObject(qObject, QScriptEngine::ScriptOwnership);
value = DependencyManager::get<ScriptCache>()->getEngine()->newQObject(qObject, QScriptEngine::ScriptOwnership);
} else if (type == "QMETAOBJECT") {
const QMetaObject* metaObject;
putData(object.value("value"), metaObject);
value = ScriptCache::getInstance()->getEngine()->newQMetaObject(metaObject);
value = DependencyManager::get<ScriptCache>()->getEngine()->newQMetaObject(metaObject);
} else if (type == "DATE") {
QDateTime dateTime;
putData(object.value("value"), dateTime);
value = ScriptCache::getInstance()->getEngine()->newDate(dateTime);
value = DependencyManager::get<ScriptCache>()->getEngine()->newDate(dateTime);
} else if (type == "REGEXP") {
QRegExp regExp;
putData(object.value("value"), regExp);
value = ScriptCache::getInstance()->getEngine()->newRegExp(regExp);
value = DependencyManager::get<ScriptCache>()->getEngine()->newRegExp(regExp);
} else if (type == "ARRAY") {
QJsonArray array = object.value("value").toArray();
value = ScriptCache::getInstance()->getEngine()->newArray(array.size());
value = DependencyManager::get<ScriptCache>()->getEngine()->newArray(array.size());
for (int i = 0; i < array.size(); i++) {
QScriptValue element;
putData(array.at(i), element);
@ -2241,7 +2241,7 @@ void JSONReader::putData(const QJsonValue& data, QScriptValue& value) {
}
} else if (type == "OBJECT") {
QJsonObject jsonObject = object.value("value").toObject();
value = ScriptCache::getInstance()->getEngine()->newObject();
value = DependencyManager::get<ScriptCache>()->getEngine()->newObject();
for (QJsonObject::const_iterator it = jsonObject.constBegin(); it != jsonObject.constEnd(); it++) {
QScriptValue element;
putData(it.value(), element);

View file

@ -663,7 +663,7 @@ void ParameterizedURLEditor::updateURL() {
QByteArray valuePropertyName = widget->property("valuePropertyName").toByteArray();
const QMetaObject* widgetMetaObject = widget->metaObject();
QMetaProperty widgetProperty = widgetMetaObject->property(widgetMetaObject->indexOfProperty(valuePropertyName));
parameters.insert(ScriptCache::getInstance()->getEngine()->toStringHandle(
parameters.insert(DependencyManager::get<ScriptCache>()->getEngine()->toStringHandle(
widget->property("parameterName").toString()), widgetProperty.read(widget));
}
}
@ -677,7 +677,7 @@ void ParameterizedURLEditor::updateParameters() {
if (_program) {
_program->disconnect(this);
}
_program = ScriptCache::getInstance()->getProgram(_url.getURL());
_program = DependencyManager::get<ScriptCache>()->getProgram(_url.getURL());
if (_program->isLoaded()) {
continueUpdatingParameters();
} else {
@ -698,7 +698,7 @@ void ParameterizedURLEditor::continueUpdatingParameters() {
}
delete form;
}
QSharedPointer<NetworkValue> value = ScriptCache::getInstance()->getValue(_url.getURL());
QSharedPointer<NetworkValue> value = DependencyManager::get<ScriptCache>()->getValue(_url.getURL());
const QList<ParameterInfo>& parameters = static_cast<RootNetworkValue*>(value.data())->getParameterInfo();
if (parameters.isEmpty()) {
return;

View file

@ -57,8 +57,8 @@ bool operator==(const QScriptValue& first, const QScriptValue& second) {
if (!second.isArray()) {
return false;
}
int length = first.property(ScriptCache::getInstance()->getLengthString()).toInt32();
if (second.property(ScriptCache::getInstance()->getLengthString()).toInt32() != length) {
int length = first.property(DependencyManager::get<ScriptCache>()->getLengthString()).toInt32();
if (second.property(DependencyManager::get<ScriptCache>()->getLengthString()).toInt32() != length) {
return false;
}
for (int i = 0; i < length; i++) {
@ -103,11 +103,6 @@ bool operator<(const QScriptValue& first, const QScriptValue& second) {
return first.lessThan(second);
}
ScriptCache* ScriptCache::getInstance() {
static ScriptCache cache;
return &cache;
}
ScriptCache::ScriptCache() :
_engine(NULL)
{

View file

@ -25,13 +25,11 @@ class NetworkProgram;
class NetworkValue;
/// Maintains a cache of loaded scripts.
class ScriptCache : public ResourceCache {
class ScriptCache : public ResourceCache, public Dependency {
Q_OBJECT
SINGLETON_DEPENDENCY
public:
static ScriptCache* getInstance();
ScriptCache();
void setEngine(QScriptEngine* engine);

View file

@ -86,17 +86,9 @@ void UserActivityLogger::launch(QString applicationVersion) {
logAction(ACTION_NAME, actionDetails);
}
void UserActivityLogger::close(int delayTime) {
void UserActivityLogger::close() {
const QString ACTION_NAME = "close";
// In order to get the end of the session, we need to give the account manager enough time to send the packet.
QEventLoop loop;
QTimer timer;
connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
// Now we can log it
logAction(ACTION_NAME, QJsonObject());
timer.start(delayTime);
loop.exec();
}
void UserActivityLogger::changedDisplayName(QString displayName) {

View file

@ -30,7 +30,7 @@ public slots:
void logAction(QString action, QJsonObject details = QJsonObject(), JSONCallbackParameters params = JSONCallbackParameters());
void launch(QString applicationVersion);
void close(int delayTime);
void close();
void changedDisplayName(QString displayName);
void changedModel(QString typeOfModel, QString modelURL);
void changedDomain(QString domainURL);

View file

@ -213,7 +213,9 @@ void OctreePersistThread::persist() {
}
_tree->unlock();
qDebug() << "persist operation calling backup...";
backup(); // handle backup if requested
qDebug() << "persist operation DONE with backup...";
// create our "lock" file to indicate we're saving.
@ -347,6 +349,7 @@ void OctreePersistThread::rollOldBackupVersions(const BackupRule& rule) {
void OctreePersistThread::backup() {
qDebug() << "backup operation wantBackup:" << _wantBackup;
if (_wantBackup) {
quint64 now = usecTimestampNow();
@ -354,10 +357,12 @@ void OctreePersistThread::backup() {
BackupRule& rule = _backupRules[i];
quint64 sinceLastBackup = now - rule.lastBackup;
quint64 SECS_TO_USECS = 1000 * 1000;
quint64 intervalToBackup = rule.interval * SECS_TO_USECS;
qDebug() << "Checking [" << rule.name << "] - Time since last backup [" << sinceLastBackup << "] " <<
"compared to backup interval [" << intervalToBackup << "]...";
if (sinceLastBackup > intervalToBackup) {
qDebug() << "Time since last backup [" << sinceLastBackup << "] for rule [" << rule.name
<< "] exceeds backup interval [" << intervalToBackup << "] doing backup now...";
@ -379,15 +384,22 @@ void OctreePersistThread::backup() {
}
qDebug() << "backing up persist file " << _filename << "to" << backupFileName << "...";
bool result = QFile::copy(_filename, backupFileName);
if (result) {
qDebug() << "DONE backing up persist file...";
QFile persistFile(_filename);
if (persistFile.exists()) {
qDebug() << "backing up persist file " << _filename << "to" << backupFileName << "...";
bool result = QFile::copy(_filename, backupFileName);
if (result) {
qDebug() << "DONE backing up persist file...";
rule.lastBackup = now; // only record successful backup in this case.
} else {
qDebug() << "ERROR in backing up persist file...";
}
} else {
qDebug() << "ERROR in backing up persist file...";
qDebug() << "persist file " << _filename << " does not exist. " <<
"nothing to backup for this rule ["<< rule.name << "]...";
}
rule.lastBackup = now;
} else {
qDebug() << "Backup not needed for this rule ["<< rule.name << "]...";
}
}
}

View file

@ -9,6 +9,8 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "ScriptAudioInjector.h"
#include "AudioScriptingInterface.h"
void registerAudioMetaTypes(QScriptEngine* engine) {
@ -28,80 +30,45 @@ AudioScriptingInterface::AudioScriptingInterface() :
}
void AudioScriptingInterface::stopAllInjectors() {
QList<QPointer<AudioInjector> >::iterator injector = _activeInjectors.begin();
while (injector != _activeInjectors.end()) {
if (!injector->isNull()) {
injector->data()->stop();
while (injector->data() && !injector->data()->isFinished()) {
// wait for this injector to go down
}
}
injector = _activeInjectors.erase(injector);
ScriptAudioInjector* AudioScriptingInterface::playSound(Sound* sound, const AudioInjectorOptions& injectorOptions) {
AudioInjector* injector = NULL;
QMetaObject::invokeMethod(this, "invokedPlaySound", Qt::BlockingQueuedConnection,
Q_RETURN_ARG(AudioInjector*, injector),
Q_ARG(Sound*, sound), Q_ARG(const AudioInjectorOptions&, injectorOptions));
if (injector) {
return new ScriptAudioInjector(injector);
} else {
return NULL;
}
}
AudioInjector* AudioScriptingInterface::playSound(Sound* sound, const AudioInjectorOptions& injectorOptions) {
AudioInjector* AudioScriptingInterface::invokedPlaySound(Sound* sound, const AudioInjectorOptions& injectorOptions) {
if (sound) {
// stereo option isn't set from script, this comes from sound metadata or filename
AudioInjectorOptions optionsCopy = injectorOptions;
optionsCopy.stereo = sound->isStereo();
AudioInjector* injector = new AudioInjector(sound, optionsCopy);
injector->setLocalAudioInterface(_localAudioInterface);
QThread* injectorThread = new QThread();
injectorThread->setObjectName("Audio Injector Thread");
AudioInjector* injector = new AudioInjector(sound, optionsCopy);
injector->setLocalAudioInterface(_localAudioInterface);
injector->moveToThread(injectorThread);
// start injecting when the injector thread starts
connect(injectorThread, &QThread::started, injector, &AudioInjector::injectAudio);
// connect the right slots and signals so that the AudioInjector is killed once the injection is complete
connect(injector, &AudioInjector::finished, injector, &AudioInjector::deleteLater);
connect(injector, &AudioInjector::finished, injectorThread, &QThread::quit);
connect(injector, &AudioInjector::finished, this, &AudioScriptingInterface::injectorStopped);
// connect the right slots and signals for AudioInjector and thread cleanup
connect(injector, &AudioInjector::destroyed, injectorThread, &QThread::quit);
connect(injectorThread, &QThread::finished, injectorThread, &QThread::deleteLater);
injectorThread->start();
_activeInjectors.append(QPointer<AudioInjector>(injector));
return injector;
} else {
qDebug() << "AudioScriptingInterface::playSound called with null Sound object.";
return NULL;
}
}
void AudioScriptingInterface::stopInjector(AudioInjector* injector) {
if (injector) {
injector->stop();
}
}
bool AudioScriptingInterface::isInjectorPlaying(AudioInjector* injector) {
return (injector != NULL);
}
void AudioScriptingInterface::setInjectorOptions(AudioInjector* injector, const AudioInjectorOptions& injectorOptions) {
AudioInjectorOptions optionsCopy = injectorOptions;
if (injector) {
injector->setOptions(optionsCopy);
}
}
float AudioScriptingInterface::getLoudness(AudioInjector* injector) {
if (injector) {
return injector->getLoudness();
} else {
return 0.0f;
}
}
void AudioScriptingInterface::injectorStopped() {
_activeInjectors.removeAll(QPointer<AudioInjector>(reinterpret_cast<AudioInjector*>(sender())));
}

View file

@ -12,40 +12,32 @@
#ifndef hifi_AudioScriptingInterface_h
#define hifi_AudioScriptingInterface_h
#include <qpointer.h>
#include <AbstractAudioInterface.h>
#include <AudioInjector.h>
#include <Sound.h>
#include "AbstractAudioInterface.h"
#include "AudioInjector.h"
#include "Sound.h"
class ScriptAudioInjector;
class AudioScriptingInterface : public QObject {
Q_OBJECT
public:
static AudioScriptingInterface& getInstance();
void stopAllInjectors();
void setLocalAudioInterface(AbstractAudioInterface* audioInterface) { _localAudioInterface = audioInterface; }
public slots:
static float getLoudness(AudioInjector* injector);
AudioInjector* playSound(Sound* sound, const AudioInjectorOptions& injectorOptions = AudioInjectorOptions());
void stopInjector(AudioInjector* injector);
bool isInjectorPlaying(AudioInjector* injector);
void setInjectorOptions(AudioInjector* injector, const AudioInjectorOptions& injectorOptions);
void injectorStopped();
protected:
// this method is protected to stop C++ callers from calling, but invokable from script
Q_INVOKABLE ScriptAudioInjector* playSound(Sound* sound, const AudioInjectorOptions& injectorOptions = AudioInjectorOptions());
signals:
void mutedByMixer();
void environmentMuted();
private slots:
AudioInjector* invokedPlaySound(Sound* sound, const AudioInjectorOptions& injectorOptions);
private:
AudioScriptingInterface();
QList< QPointer<AudioInjector> > _activeInjectors;
AbstractAudioInterface* _localAudioInterface;
};

View file

@ -0,0 +1,40 @@
//
// ScriptAudioInjector.cpp
// libraries/script-engine/src
//
// Created by Stephen Birarda on 2015-02-11.
// Copyright 2015 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "ScriptAudioInjector.h"
QScriptValue injectorToScriptValue(QScriptEngine* engine, ScriptAudioInjector* const& in) {
// when the script goes down we want to cleanup the injector
QObject::connect(engine, &QScriptEngine::destroyed, in, &ScriptAudioInjector::stopInjectorImmediately);
return engine->newQObject(in, QScriptEngine::ScriptOwnership);
}
void injectorFromScriptValue(const QScriptValue& object, ScriptAudioInjector*& out) {
out = qobject_cast<ScriptAudioInjector*>(object.toQObject());
}
ScriptAudioInjector::ScriptAudioInjector(AudioInjector* injector) :
_injector(injector)
{
}
ScriptAudioInjector::~ScriptAudioInjector() {
if (!_injector.isNull()) {
// we've been asked to delete after finishing, trigger a queued deleteLater here
_injector->triggerDeleteAfterFinish();
}
}
void ScriptAudioInjector::stopInjectorImmediately() {
_injector->stopAndDeleteLater();
}

View file

@ -0,0 +1,52 @@
//
// ScriptAudioInjector.h
// libraries/script-engine/src
//
// Created by Stephen Birarda on 2015-02-11.
// Copyright 2015 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#ifndef hifi_ScriptAudioInjector_h
#define hifi_ScriptAudioInjector_h
#include <QtCore/QObject>
#include <AudioInjector.h>
class ScriptAudioInjector : public QObject {
Q_OBJECT
Q_PROPERTY(bool isPlaying READ isPlaying)
Q_PROPERTY(float loudness READ getLoudness)
public:
ScriptAudioInjector(AudioInjector* injector);
~ScriptAudioInjector();
public slots:
void restart() { _injector->restart(); }
void stop() { _injector->stop(); }
void setOptions(AudioInjectorOptions& options) { _injector->setOptions(options); }
float getLoudness() const { return _injector->getLoudness(); }
bool isPlaying() const { return _injector->isPlaying(); }
signals:
void finished();
protected slots:
void stopInjectorImmediately();
private:
QPointer<AudioInjector> _injector;
friend QScriptValue injectorToScriptValue(QScriptEngine* engine, ScriptAudioInjector* const& in);
};
Q_DECLARE_METATYPE(ScriptAudioInjector*)
QScriptValue injectorToScriptValue(QScriptEngine* engine, ScriptAudioInjector* const& in);
void injectorFromScriptValue(const QScriptValue& object, ScriptAudioInjector*& out);
#endif // hifi_ScriptAudioInjector_h

View file

@ -19,7 +19,6 @@
#include <AudioConstants.h>
#include <AudioEffectOptions.h>
#include <AudioInjector.h>
#include <AvatarData.h>
#include <Bitstream.h>
#include <CollisionInfo.h>
@ -35,6 +34,7 @@
#include "DataViewClass.h"
#include "EventTypes.h"
#include "MenuItemProperties.h"
#include "ScriptAudioInjector.h"
#include "ScriptEngine.h"
#include "TypedArrays.h"
#include "XMLHttpRequestClass.h"

View file

@ -19,13 +19,13 @@
#include <QtScript/QScriptEngine>
#include <AnimationCache.h>
#include <AudioScriptingInterface.h>
#include <AvatarData.h>
#include <AvatarHashMap.h>
#include <LimitedNodeList.h>
#include "AbstractControllerScriptingInterface.h"
#include "ArrayBufferClass.h"
#include "AudioScriptingInterface.h"
#include "Quat.h"
#include "ScriptUUID.h"
#include "Vec3.h"

View file

@ -219,14 +219,14 @@ static QScriptValue createRandomScriptValue(bool complex = false, bool ensureHas
case 4: {
int length = randIntInRange(2, 6);
QScriptValue value = ScriptCache::getInstance()->getEngine()->newArray(length);
QScriptValue value = DependencyManager::get<ScriptCache>()->getEngine()->newArray(length);
for (int i = 0; i < length; i++) {
value.setProperty(i, createRandomScriptValue());
}
return value;
}
default: {
QScriptValue value = ScriptCache::getInstance()->getEngine()->newObject();
QScriptValue value = DependencyManager::get<ScriptCache>()->getEngine()->newObject();
if (ensureHashOrder) {
// we can't depend on the iteration order, so if we need it to be the same (as when comparing bytes), we
// can only have one property
@ -747,7 +747,7 @@ static SharedObjectPointer mutate(const SharedObjectPointer& state) {
case 3: {
SharedObjectPointer newState = state->clone(true);
QScriptValue oldValue = static_cast<TestSharedObjectA*>(newState.data())->getBizzle();
QScriptValue newValue = ScriptCache::getInstance()->getEngine()->newObject();
QScriptValue newValue = DependencyManager::get<ScriptCache>()->getEngine()->newObject();
for (QScriptValueIterator it(oldValue); it.hasNext(); ) {
it.next();
newValue.setProperty(it.scriptName(), it.value());
@ -755,8 +755,8 @@ static SharedObjectPointer mutate(const SharedObjectPointer& state) {
switch (randIntInRange(0, 2)) {
case 0: {
QScriptValue oldArray = oldValue.property("foo");
int oldLength = oldArray.property(ScriptCache::getInstance()->getLengthString()).toInt32();
QScriptValue newArray = ScriptCache::getInstance()->getEngine()->newArray(oldLength);
int oldLength = oldArray.property(DependencyManager::get<ScriptCache>()->getLengthString()).toInt32();
QScriptValue newArray = DependencyManager::get<ScriptCache>()->getEngine()->newArray(oldLength);
for (int i = 0; i < oldLength; i++) {
newArray.setProperty(i, oldArray.property(i));
}
@ -1203,8 +1203,8 @@ TestSharedObjectA::TestSharedObjectA(float foo, TestEnum baz, TestFlags bong) :
_bong(bong) {
sharedObjectsCreated++;
_bizzle = ScriptCache::getInstance()->getEngine()->newObject();
_bizzle.setProperty("foo", ScriptCache::getInstance()->getEngine()->newArray(4));
_bizzle = DependencyManager::get<ScriptCache>()->getEngine()->newObject();
_bizzle.setProperty("foo", DependencyManager::get<ScriptCache>()->getEngine()->newArray(4));
}
TestSharedObjectA::~TestSharedObjectA() {