From 8b9f6813ca085246564a3d6e5557bc3bebb6b48b Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 30 Jan 2014 12:26:50 -0800 Subject: [PATCH 01/14] add easier support for key codes in JS by adding text property and auto-detecting isShifted --- examples/controllerExample.js | 101 +++++++++++++- libraries/script-engine/src/EventTypes.cpp | 155 ++++++++++++++++++++- libraries/script-engine/src/EventTypes.h | 11 +- 3 files changed, 260 insertions(+), 7 deletions(-) diff --git a/examples/controllerExample.js b/examples/controllerExample.js index c1b33b24a5..95561dc9dc 100644 --- a/examples/controllerExample.js +++ b/examples/controllerExample.js @@ -48,6 +48,15 @@ function checkController() { function keyPressEvent(event) { print("keyPressEvent event.key=" + event.key); + print("keyPressEvent event.text=" + event.text); + + print("keyPressEvent event.isShifted=" + event.isShifted); + print("keyPressEvent event.isControl=" + event.isControl); + print("keyPressEvent event.isMeta=" + event.isMeta); + print("keyPressEvent event.isAlt=" + event.isAlt); + print("keyPressEvent event.isKeypad=" + event.isKeypad); + + if (event.key == "A".charCodeAt(0)) { print("the A key was pressed"); } @@ -77,14 +86,102 @@ Agent.willSendVisualDataCallback.connect(checkController); // Map keyPress and mouse move events to our callbacks Controller.keyPressEvent.connect(keyPressEvent); -var AKeyEvent = { +var KeyEvent_A = { key: "A".charCodeAt(0), + text: "A", isShifted: false, isMeta: false }; +var KeyEvent_a = { + text: "a", + isShifted: false, + isMeta: false +}; + +var KeyEvent_a2 = { + key: "a".charCodeAt(0), + isShifted: false, + isMeta: false +}; + +var KeyEvent_a3 = { + text: "a" +}; + +var KeyEvent_A2 = { + text: "A" +}; + + +var KeyEvent_9 = { + text: "9" +}; + +var KeyEvent_Num = { + text: "#" +}; + +var KeyEvent_At = { + text: "@" +}; + +var KeyEvent_MetaAt = { + text: "@", + isMeta: true +}; + +var KeyEvent_Up = { + text: "up" +}; +var KeyEvent_Down = { + text: "down" +}; +var KeyEvent_Left = { + text: "left" +}; +var KeyEvent_Right = { + text: "right" +}; + // prevent the A key from going through to the application -Controller.captureKeyEvents(AKeyEvent); +print("KeyEvent_A"); +Controller.captureKeyEvents(KeyEvent_A); + +print("KeyEvent_A2"); +Controller.captureKeyEvents(KeyEvent_A2); + +print("KeyEvent_a"); +Controller.captureKeyEvents(KeyEvent_a); + +print("KeyEvent_a2"); +Controller.captureKeyEvents(KeyEvent_a2); + +print("KeyEvent_a3"); +Controller.captureKeyEvents(KeyEvent_a3); + +print("KeyEvent_9"); +Controller.captureKeyEvents(KeyEvent_9); + +print("KeyEvent_Num"); +Controller.captureKeyEvents(KeyEvent_Num); + +print("KeyEvent_At"); +Controller.captureKeyEvents(KeyEvent_At); + +print("KeyEvent_MetaAt"); +Controller.captureKeyEvents(KeyEvent_MetaAt); + +print("KeyEvent_Up"); +Controller.captureKeyEvents(KeyEvent_Up); +print("KeyEvent_Down"); +Controller.captureKeyEvents(KeyEvent_Down); +print("KeyEvent_Left"); +Controller.captureKeyEvents(KeyEvent_Left); +print("KeyEvent_Right"); +Controller.captureKeyEvents(KeyEvent_Right); + + Controller.mouseMoveEvent.connect(mouseMoveEvent); diff --git a/libraries/script-engine/src/EventTypes.cpp b/libraries/script-engine/src/EventTypes.cpp index 5c4ab7f2a7..ff27282b73 100644 --- a/libraries/script-engine/src/EventTypes.cpp +++ b/libraries/script-engine/src/EventTypes.cpp @@ -8,22 +8,72 @@ // Used to register meta-types with Qt for very various event types so that they can be exposed to our // scripting engine +#include #include "EventTypes.h" KeyEvent::KeyEvent() { key = 0; + text = QString(""); isShifted = false; isMeta = false; + isControl = false; isValid = false; } KeyEvent::KeyEvent(const QKeyEvent& event) { key = event.key(); + text = event.text(); isShifted = event.modifiers().testFlag(Qt::ShiftModifier); - isMeta = event.modifiers().testFlag(Qt::ControlModifier); + isMeta = event.modifiers().testFlag(Qt::MetaModifier); + isControl = event.modifiers().testFlag(Qt::ControlModifier); + isAlt = event.modifiers().testFlag(Qt::AltModifier); + isKeypad = event.modifiers().testFlag(Qt::KeypadModifier); isValid = true; + + // handle special text for special characters... + if (key == Qt::Key_F1) { + text = "F1"; + } else if (key == Qt::Key_F2) { + text = "F2"; + } else if (key == Qt::Key_F3) { + text = "F3"; + } else if (key == Qt::Key_F4) { + text = "F4"; + } else if (key == Qt::Key_F5) { + text = "F5"; + } else if (key == Qt::Key_F6) { + text = "F6"; + } else if (key == Qt::Key_F7) { + text = "F7"; + } else if (key == Qt::Key_F8) { + text = "F8"; + } else if (key == Qt::Key_F9) { + text = "F9"; + } else if (key == Qt::Key_F10) { + text = "F10"; + } else if (key == Qt::Key_F11) { + text = "F11"; + } else if (key == Qt::Key_F12) { + text = "F12"; + } else if (key == Qt::Key_Up) { + text = "UP"; + } else if (key == Qt::Key_Down) { + text = "DOWN"; + } else if (key == Qt::Key_Left) { + text = "LEFT"; + } else if (key == Qt::Key_Right) { + text = "RIGHT"; + } else if (key == Qt::Key_Escape) { + text = "ESC"; + } else if (key == Qt::Key_Tab) { + text = "TAB"; + } else if (key == Qt::Key_Delete) { + text = "DELETE"; + } else if (key == Qt::Key_Backspace) { + text = "BACKSPACE"; + } } MouseEvent::MouseEvent(const QMouseEvent& event) { @@ -65,16 +115,113 @@ void registerEventTypes(QScriptEngine* engine) { QScriptValue keyEventToScriptValue(QScriptEngine* engine, const KeyEvent& event) { QScriptValue obj = engine->newObject(); obj.setProperty("key", event.key); + obj.setProperty("text", event.text); obj.setProperty("isShifted", event.isShifted); obj.setProperty("isMeta", event.isMeta); + obj.setProperty("isControl", event.isControl); + obj.setProperty("isAlt", event.isAlt); + obj.setProperty("isKeypad", event.isKeypad); return obj; } void keyEventFromScriptValue(const QScriptValue &object, KeyEvent& event) { - event.key = object.property("key").toVariant().toInt(); - event.isShifted = object.property("isShifted").toVariant().toBool(); + + event.isValid = false; // assume the worst event.isMeta = object.property("isMeta").toVariant().toBool(); - event.isValid = object.property("key").isValid(); + event.isControl = object.property("isControl").toVariant().toBool(); + event.isAlt = object.property("isAlt").toVariant().toBool(); + event.isKeypad = object.property("isKeypad").toVariant().toBool(); + + QScriptValue key = object.property("key"); + if (key.isValid()) { + event.key = key.toVariant().toInt(); + event.text = QString(QChar(event.key)); + event.isValid = true; + } else { + QScriptValue text = object.property("text"); + if (text.isValid()) { + event.text = object.property("text").toVariant().toString(); + + // if the text is a special command, then map it here... + // TODO: come up with more elegant solution here, a map? is there a Qt function that gives nice names for keys? + if (event.text.toUpper() == "F1") { + event.key = Qt::Key_F1; + } else if (event.text.toUpper() == "F2") { + event.key = Qt::Key_F2; + } else if (event.text.toUpper() == "F3") { + event.key = Qt::Key_F3; + } else if (event.text.toUpper() == "F4") { + event.key = Qt::Key_F4; + } else if (event.text.toUpper() == "F5") { + event.key = Qt::Key_F5; + } else if (event.text.toUpper() == "F6") { + event.key = Qt::Key_F6; + } else if (event.text.toUpper() == "F7") { + event.key = Qt::Key_F7; + } else if (event.text.toUpper() == "F8") { + event.key = Qt::Key_F8; + } else if (event.text.toUpper() == "F9") { + event.key = Qt::Key_F9; + } else if (event.text.toUpper() == "F10") { + event.key = Qt::Key_F10; + } else if (event.text.toUpper() == "F11") { + event.key = Qt::Key_F11; + } else if (event.text.toUpper() == "F12") { + event.key = Qt::Key_F12; + } else if (event.text.toUpper() == "UP") { + event.key = Qt::Key_Up; + event.isKeypad = true; + } else if (event.text.toUpper() == "DOWN") { + event.key = Qt::Key_Down; + event.isKeypad = true; + } else if (event.text.toUpper() == "LEFT") { + event.key = Qt::Key_Left; + event.isKeypad = true; + } else if (event.text.toUpper() == "RIGHT") { + event.key = Qt::Key_Right; + event.isKeypad = true; + } else if (event.text.toUpper() == "ESC") { + event.key = Qt::Key_Escape; + } else if (event.text.toUpper() == "TAB") { + event.key = Qt::Key_Tab; + } else if (event.text.toUpper() == "DELETE") { + event.key = Qt::Key_Delete; + } else if (event.text.toUpper() == "BACKSPACE") { + event.key = Qt::Key_Backspace; + } else { + event.key = event.text.at(0).unicode(); + } + event.isValid = true; + } + } + + QScriptValue isShifted = object.property("isShifted"); + if (isShifted.isValid()) { + event.isShifted = isShifted.toVariant().toBool(); + } else { + // if no isShifted was included, get it from the text + QChar character = event.text.at(0); + if (character.isLetter() && character.isUpper()) { + event.isShifted = true; + } else { + // if it's a symbol, then attempt to detect shifted-ness + if (QString("~!@#$%^&*()_+{}|:\"<>?").contains(character)) { + event.isShifted = true; + } + } + } + + + const bool wantDebug = false; + if (wantDebug) { + qDebug() << "event.key=" << event.key + << " event.text=" << event.text + << " event.isShifted=" << event.isShifted + << " event.isControl=" << event.isControl + << " event.isMeta=" << event.isMeta + << " event.isAlt=" << event.isAlt + << " event.isKeypad=" << event.isKeypad; + } } QScriptValue mouseEventToScriptValue(QScriptEngine* engine, const MouseEvent& event) { diff --git a/libraries/script-engine/src/EventTypes.h b/libraries/script-engine/src/EventTypes.h index c3764b2619..81cba03cea 100644 --- a/libraries/script-engine/src/EventTypes.h +++ b/libraries/script-engine/src/EventTypes.h @@ -24,10 +24,19 @@ public: KeyEvent(); KeyEvent(const QKeyEvent& event); inline bool operator==(const KeyEvent& other) const { - return other.key == key && other.isShifted == isShifted && other.isMeta == isMeta; } + return other.key == key + && other.isShifted == isShifted + && other.isControl == isControl + && other.isMeta == isMeta + && other.isAlt == isAlt + && other.isKeypad == isKeypad; } int key; + QString text; bool isShifted; + bool isControl; bool isMeta; + bool isAlt; + bool isKeypad; bool isValid; }; From a6934605a456bd261e3196256428742045a56581 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 29 Jan 2014 20:55:12 -0800 Subject: [PATCH 02/14] implement a basic exampple of ride along with a particle --- examples/rideAlongWithAParticleExample.js | 50 +++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 examples/rideAlongWithAParticleExample.js diff --git a/examples/rideAlongWithAParticleExample.js b/examples/rideAlongWithAParticleExample.js new file mode 100644 index 0000000000..eca9fe7f4c --- /dev/null +++ b/examples/rideAlongWithAParticleExample.js @@ -0,0 +1,50 @@ +// +// rideAlongWithAParticleExample.js +// hifi +// +// Created by Brad Hefta-Gaub on 1/24/14. +// Copyright (c) 2014 HighFidelity, Inc. All rights reserved. +// +// This is an example script that demonstrates "finding" particles +// + +var iteration = 0; +var lengthOfRide = 2000; // in iterations + +var particleA = Particles.addParticle( + { + position: { x: 10, y: 0, z: 10 }, + velocity: { x: 5, y: 0, z: 5 }, + gravity: { x: 0, y: 0, z: 0 }, + radius : 0.1, + color: { red: 0, green: 255, blue: 0 }, + damping: 0, + lifetime: (lengthOfRide * 60) + 1 + }); + +function rideWithParticle() { + + if (iteration <= lengthOfRide) { + + // Check to see if we've been notified of the actual identity of the particles we created + if (!particleA.isKnownID) { + particleA = Particles.identifyParticle(particleA); + } + + var propertiesA = Particles.getParticleProperties(particleA); + var newPosition = propertiesA.position; + MyAvatar.position = { x: propertiesA.position.x, + y: propertiesA.position.y + 2, + z: propertiesA.position.z }; + } else { + Agent.stop(); + } + + iteration++; + print("iteration="+iteration); +} + + +// register the call back so it fires before each data send +Agent.willSendVisualDataCallback.connect(rideWithParticle); + From 3b17550d92594c48fbe84e4ca1b8210517487cf2 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 30 Jan 2014 16:36:26 -0800 Subject: [PATCH 03/14] make sure to flush edit queue on script shutdown --- libraries/particles/src/Particle.cpp | 14 +------------ .../src/ParticlesScriptingInterface.cpp | 19 +++++++---------- libraries/script-engine/src/ScriptEngine.cpp | 21 +++++++++++++++++++ 3 files changed, 30 insertions(+), 24 deletions(-) diff --git a/libraries/particles/src/Particle.cpp b/libraries/particles/src/Particle.cpp index 557d4ca87f..c7afc49668 100644 --- a/libraries/particles/src/Particle.cpp +++ b/libraries/particles/src/Particle.cpp @@ -60,8 +60,6 @@ void Particle::handleAddParticleResponse(unsigned char* packetData , int packetL memcpy(&particleID, dataAt, sizeof(particleID)); dataAt += sizeof(particleID); - //qDebug() << "handleAddParticleResponse()... particleID=" << particleID << " creatorTokenID=" << creatorTokenID; - // add our token to id mapping _tokenIDsToIDs[creatorTokenID] = particleID; } @@ -362,8 +360,6 @@ Particle Particle::fromEditPacket(unsigned char* data, int length, int& processe dataAt += sizeof(editID); processedBytes += sizeof(editID); - //qDebug() << "editID:" << editID; - bool isNewParticle = (editID == NEW_PARTICLE); // special case for handling "new" particles @@ -412,7 +408,6 @@ Particle Particle::fromEditPacket(unsigned char* data, int length, int& processe memcpy(&packetContainsBits, dataAt, sizeof(packetContainsBits)); dataAt += sizeof(packetContainsBits); processedBytes += sizeof(packetContainsBits); - //qDebug() << "packetContainsBits:" << packetContainsBits; } @@ -529,7 +524,6 @@ Particle Particle::fromEditPacket(unsigned char* data, int length, int& processe if (wantDebugging) { qDebug("Particle::fromEditPacket()..."); qDebug() << " Particle id in packet:" << editID; - //qDebug() << " position: " << newParticle._position; newParticle.debugDump(); } @@ -736,8 +730,6 @@ bool Particle::encodeParticleEditMessageDetails(PACKET_TYPE command, ParticleID // cleanup delete[] octcode; - //qDebug() << "encoding... sizeOut:" << sizeOut; - return success; } @@ -825,12 +817,8 @@ void Particle::update(const uint64_t& now) { _lastUpdated = now; // calculate our default shouldDie state... then allow script to change it if it wants... - float speed = glm::length(_velocity); - bool isStopped = (speed < MIN_VALID_SPEED); - const uint64_t REALLY_OLD = 30 * USECS_PER_SECOND; // 30 seconds - bool isReallyOld = ((now - _created) > REALLY_OLD); bool isInHand = getInHand(); - bool shouldDie = (getAge() > getLifetime()) || getShouldDie() || (!isInHand && isStopped && isReallyOld); + bool shouldDie = (getAge() > getLifetime()) || getShouldDie(); setShouldDie(shouldDie); executeUpdateScripts(); // allow the javascript to alter our state diff --git a/libraries/particles/src/ParticlesScriptingInterface.cpp b/libraries/particles/src/ParticlesScriptingInterface.cpp index 0ef8f82b00..7f4c29cb55 100644 --- a/libraries/particles/src/ParticlesScriptingInterface.cpp +++ b/libraries/particles/src/ParticlesScriptingInterface.cpp @@ -112,22 +112,19 @@ void ParticlesScriptingInterface::deleteParticle(ParticleID particleID) { properties.setShouldDie(true); uint32_t actualID = particleID.id; + + // if the particle is unknown, attempt to look it up if (!particleID.isKnownID) { actualID = Particle::getIDfromCreatorTokenID(particleID.creatorTokenID); - - // hmmm... we kind of want to bail if someone attempts to edit an unknown - if (actualID == UNKNOWN_PARTICLE_ID) { - //qDebug() << "ParticlesScriptingInterface::deleteParticle(), bailing - unknown particle..."; - return; // bailing early - } } - particleID.id = actualID; - particleID.isKnownID = true; + // if at this point, we know the id, send the update to the particle server + if (actualID != UNKNOWN_PARTICLE_ID) { + particleID.id = actualID; + particleID.isKnownID = true; + queueParticleMessage(PACKET_TYPE_PARTICLE_ADD_OR_EDIT, particleID, properties); + } - //qDebug() << "ParticlesScriptingInterface::deleteParticle(), queueParticleMessage......"; - queueParticleMessage(PACKET_TYPE_PARTICLE_ADD_OR_EDIT, particleID, properties); - // If we have a local particle tree set, then also update it. if (_particleTree) { _particleTree->lockForWrite(); diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index 9db1254f80..b69f69f5f9 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -261,6 +261,27 @@ void ScriptEngine::run() { } } emit scriptEnding(); + + if (_voxelsScriptingInterface.getVoxelPacketSender()->serversExist()) { + // release the queue of edit voxel messages. + _voxelsScriptingInterface.getVoxelPacketSender()->releaseQueuedMessages(); + + // since we're in non-threaded mode, call process so that the packets are sent + if (!_voxelsScriptingInterface.getVoxelPacketSender()->isThreaded()) { + _voxelsScriptingInterface.getVoxelPacketSender()->process(); + } + } + + if (_particlesScriptingInterface.getParticlePacketSender()->serversExist()) { + // release the queue of edit voxel messages. + _particlesScriptingInterface.getParticlePacketSender()->releaseQueuedMessages(); + + // since we're in non-threaded mode, call process so that the packets are sent + if (!_particlesScriptingInterface.getParticlePacketSender()->isThreaded()) { + _particlesScriptingInterface.getParticlePacketSender()->process(); + } + } + cleanMenuItems(); // If we were on a thread, then wait till it's done From dd83ff05380277fb3398984f7d00fa0c1a2b5ce4 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 31 Jan 2014 14:36:50 -0800 Subject: [PATCH 04/14] move isAvatar property access to Agent object --- assignment-client/src/Agent.cpp | 3 +++ assignment-client/src/Agent.h | 5 +++++ libraries/script-engine/src/ScriptEngine.cpp | 2 +- libraries/script-engine/src/ScriptEngine.h | 2 -- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/assignment-client/src/Agent.cpp b/assignment-client/src/Agent.cpp index 84714259e5..2694bf83e2 100644 --- a/assignment-client/src/Agent.cpp +++ b/assignment-client/src/Agent.cpp @@ -101,6 +101,9 @@ void Agent::run() { // give this AvatarData object to the script engine _scriptEngine.setAvatarData(&scriptedAvatar, "Avatar"); + + // register ourselves to the script engine + _scriptEngine.registerGlobalObject("Agent", this); _scriptEngine.setScriptContents(scriptContents); _scriptEngine.run(); diff --git a/assignment-client/src/Agent.h b/assignment-client/src/Agent.h index 146cb71df4..8b2038a8b0 100644 --- a/assignment-client/src/Agent.h +++ b/assignment-client/src/Agent.h @@ -21,9 +21,14 @@ class Agent : public ThreadedAssignment { Q_OBJECT + + Q_PROPERTY(bool isAvatar READ isAvatar WRITE setIsAvatar) public: Agent(const QByteArray& packet); + void setIsAvatar(bool isAvatar) { _scriptEngine.setIsAvatar(isAvatar); } + bool isAvatar() const { return _scriptEngine.isAvatar(); } + public slots: void run(); diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index 6ea3742592..9a7a9197b0 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -133,7 +133,7 @@ void ScriptEngine::init() { QScriptValue injectionOptionValue = _engine.scriptValueFromQMetaObject(); _engine.globalObject().setProperty("AudioInjectionOptions", injectionOptionValue); - registerGlobalObject("Agent", this); + registerGlobalObject("Script", this); registerGlobalObject("Audio", &_audioScriptingInterface); registerGlobalObject("Controller", _controllerScriptingInterface); registerGlobalObject("Data", &_dataServerScriptingInterface); diff --git a/libraries/script-engine/src/ScriptEngine.h b/libraries/script-engine/src/ScriptEngine.h index c2188cca63..8f29379266 100644 --- a/libraries/script-engine/src/ScriptEngine.h +++ b/libraries/script-engine/src/ScriptEngine.h @@ -31,8 +31,6 @@ const QString NO_SCRIPT(""); class ScriptEngine : public QObject { Q_OBJECT - - Q_PROPERTY(bool isAvatar READ isAvatar WRITE setIsAvatar) public: ScriptEngine(const QString& scriptContents = NO_SCRIPT, bool wantMenuItems = false, const QString& scriptMenuName = QString(""), AbstractMenuInterface* menu = NULL, From 9015b24aa5ec5af9da0508aa5c831c6e3a4399a2 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 31 Jan 2014 14:41:24 -0800 Subject: [PATCH 05/14] update the script examples for new nomenclature --- examples/clap.js | 2 +- examples/collidingParticles.js | 6 +++--- examples/controllerExample.js | 4 ++-- examples/count.js | 4 ++-- examples/drumStick.js | 2 +- examples/editParticleExample.js | 8 ++++---- examples/findParticleExample.js | 8 ++++---- examples/fountain.js | 4 ++-- examples/gameoflife.js | 2 +- examples/gun.js | 2 +- examples/lookWithMouse.js | 4 ++-- examples/movingVoxel.js | 2 +- examples/paintGun.js | 2 +- examples/particleBird.js | 4 ++-- examples/particleModelExample.js | 6 +++--- examples/playSound.js | 2 +- examples/rideAlongWithAParticleExample.js | 4 ++-- examples/toyball.js | 2 +- examples/voxelBird.js | 2 +- 19 files changed, 35 insertions(+), 35 deletions(-) diff --git a/examples/clap.js b/examples/clap.js index fdd2b29aa2..81ccda64b7 100644 --- a/examples/clap.js +++ b/examples/clap.js @@ -62,4 +62,4 @@ function maybePlaySound() { } // Connect a call back that happens every frame -Agent.willSendVisualDataCallback.connect(maybePlaySound); \ No newline at end of file +Script.willSendVisualDataCallback.connect(maybePlaySound); \ No newline at end of file diff --git a/examples/collidingParticles.js b/examples/collidingParticles.js index cf1fce5660..d202b31d97 100644 --- a/examples/collidingParticles.js +++ b/examples/collidingParticles.js @@ -1,4 +1,4 @@ -// +Script// // collidingParticles.js // hifi // @@ -132,7 +132,7 @@ function draw() { print(scriptB); numberParticlesAdded++; } else { - Agent.stop(); + Script.stop(); } print("Particles Stats: " + Particles.getLifetimeInSeconds() + " seconds," + @@ -150,5 +150,5 @@ function draw() { // register the call back so it fires before each data send print("here...\n"); Particles.setPacketsPerSecond(40000); -Agent.willSendVisualDataCallback.connect(draw); +Script.willSendVisualDataCallback.connect(draw); print("and here...\n"); diff --git a/examples/controllerExample.js b/examples/controllerExample.js index 95561dc9dc..43eb516cee 100644 --- a/examples/controllerExample.js +++ b/examples/controllerExample.js @@ -82,7 +82,7 @@ function touchEndEvent(event) { } // register the call back so it fires before each data send -Agent.willSendVisualDataCallback.connect(checkController); +Script.willSendVisualDataCallback.connect(checkController); // Map keyPress and mouse move events to our callbacks Controller.keyPressEvent.connect(keyPressEvent); @@ -199,4 +199,4 @@ function scriptEnding() { Controller.releaseTouchEvents(); } -Agent.scriptEnding.connect(scriptEnding); +Script.scriptEnding.connect(scriptEnding); diff --git a/examples/count.js b/examples/count.js index 917bec342d..29799a8271 100644 --- a/examples/count.js +++ b/examples/count.js @@ -20,7 +20,7 @@ function scriptEnding() { } // register the call back so it fires before each data send -Agent.willSendVisualDataCallback.connect(displayCount); +Script.willSendVisualDataCallback.connect(displayCount); // register our scriptEnding callback -Agent.scriptEnding.connect(scriptEnding); +Script.scriptEnding.connect(scriptEnding); diff --git a/examples/drumStick.js b/examples/drumStick.js index 955fddbdee..78de8351db 100644 --- a/examples/drumStick.js +++ b/examples/drumStick.js @@ -69,4 +69,4 @@ function checkSticks() { } // Connect a call back that happens every frame -Agent.willSendVisualDataCallback.connect(checkSticks); \ No newline at end of file +Script.willSendVisualDataCallback.connect(checkSticks); \ No newline at end of file diff --git a/examples/editParticleExample.js b/examples/editParticleExample.js index 61e32c4d55..5774eda689 100644 --- a/examples/editParticleExample.js +++ b/examples/editParticleExample.js @@ -44,7 +44,7 @@ var particleID = Particles.addParticle(originalProperties); function moveParticle() { if (count >= moveUntil) { - //Agent.stop(); + //Script.stop(); // delete it... if (count == moveUntil) { @@ -54,8 +54,8 @@ function moveParticle() { // stop it... if (count >= stopAfter) { - print("calling Agent.stop()"); - Agent.stop(); + print("calling Script.stop()"); + Script.stop(); } count++; @@ -86,5 +86,5 @@ function moveParticle() { // register the call back so it fires before each data send -Agent.willSendVisualDataCallback.connect(moveParticle); +Script.willSendVisualDataCallback.connect(moveParticle); diff --git a/examples/findParticleExample.js b/examples/findParticleExample.js index bd20e6ded7..5eb257d502 100644 --- a/examples/findParticleExample.js +++ b/examples/findParticleExample.js @@ -65,8 +65,8 @@ function findParticles() { // run for a while, then clean up // stop it... if (iteration >= 100) { - print("calling Agent.stop()"); - Agent.stop(); + print("calling Script.stop()"); + Script.stop(); } print("--------------------------"); @@ -122,7 +122,7 @@ function findParticles() { // register the call back so it fires before each data send -Agent.willSendVisualDataCallback.connect(findParticles); +Script.willSendVisualDataCallback.connect(findParticles); // register our scriptEnding callback -Agent.scriptEnding.connect(scriptEnding); +Script.scriptEnding.connect(scriptEnding); diff --git a/examples/fountain.js b/examples/fountain.js index a095f91ed3..3c943d72a0 100644 --- a/examples/fountain.js +++ b/examples/fountain.js @@ -60,8 +60,8 @@ function makeFountain() { totalParticles++; } if (totalParticles > 100) { - Agent.stop(); + Script.stop(); } } // register the call back so it fires before each data send -Agent.willSendVisualDataCallback.connect(makeFountain); \ No newline at end of file +Script.willSendVisualDataCallback.connect(makeFountain); \ No newline at end of file diff --git a/examples/gameoflife.js b/examples/gameoflife.js index 09fae07204..6779941dc7 100644 --- a/examples/gameoflife.js +++ b/examples/gameoflife.js @@ -128,6 +128,6 @@ print("step()..."); } print("here"); -Agent.willSendVisualDataCallback.connect(step); +Script.willSendVisualDataCallback.connect(step); Voxels.setPacketsPerSecond(200); print("now here"); diff --git a/examples/gun.js b/examples/gun.js index 3f8eefe3e2..e7cd2973e2 100644 --- a/examples/gun.js +++ b/examples/gun.js @@ -99,4 +99,4 @@ function checkController() { // register the call back so it fires before each data send -Agent.willSendVisualDataCallback.connect(checkController); +Script.willSendVisualDataCallback.connect(checkController); diff --git a/examples/lookWithMouse.js b/examples/lookWithMouse.js index 79fad76a1b..f404019bc1 100644 --- a/examples/lookWithMouse.js +++ b/examples/lookWithMouse.js @@ -70,5 +70,5 @@ MyAvatar.bodyPitch = 0; MyAvatar.bodyRoll = 0; // would be nice to change to update -Agent.willSendVisualDataCallback.connect(update); -Agent.scriptEnding.connect(scriptEnding); +Script.willSendVisualDataCallback.connect(update); +Script.scriptEnding.connect(scriptEnding); diff --git a/examples/movingVoxel.js b/examples/movingVoxel.js index 0aadf7b30c..14a7e671c6 100644 --- a/examples/movingVoxel.js +++ b/examples/movingVoxel.js @@ -41,4 +41,4 @@ function moveVoxel() { Voxels.setPacketsPerSecond(300); // Connect a call back that happens every frame -Agent.willSendVisualDataCallback.connect(moveVoxel); \ No newline at end of file +Script.willSendVisualDataCallback.connect(moveVoxel); \ No newline at end of file diff --git a/examples/paintGun.js b/examples/paintGun.js index b78e6abb0b..56e916a183 100644 --- a/examples/paintGun.js +++ b/examples/paintGun.js @@ -93,4 +93,4 @@ function checkController() { // register the call back so it fires before each data send -Agent.willSendVisualDataCallback.connect(checkController); +Script.willSendVisualDataCallback.connect(checkController); diff --git a/examples/particleBird.js b/examples/particleBird.js index 6a4cf79a40..c1c26058e6 100644 --- a/examples/particleBird.js +++ b/examples/particleBird.js @@ -95,7 +95,7 @@ function moveBird() { var nowTimeInSeconds = new Date().getTime() / 1000; if ((nowTimeInSeconds - startTimeInSeconds) >= birdLifetime) { print("our bird is dying, stop our script"); - Agent.stop(); + Script.stop(); return; } @@ -171,4 +171,4 @@ function moveBird() { } } // register the call back so it fires before each data send -Agent.willSendVisualDataCallback.connect(moveBird); +Script.willSendVisualDataCallback.connect(moveBird); diff --git a/examples/particleModelExample.js b/examples/particleModelExample.js index 9f19069ee9..e95cc0c2bf 100644 --- a/examples/particleModelExample.js +++ b/examples/particleModelExample.js @@ -37,8 +37,8 @@ var ballParticleID = Particles.addParticle(ballProperties); function endAfterAWhile() { // stop it... if (count >= stopAfter) { - print("calling Agent.stop()"); - Agent.stop(); + print("calling Script.stop()"); + Script.stop(); } print("count =" + count); @@ -47,5 +47,5 @@ function endAfterAWhile() { // register the call back so it fires before each data send -Agent.willSendVisualDataCallback.connect(endAfterAWhile); +Script.willSendVisualDataCallback.connect(endAfterAWhile); diff --git a/examples/playSound.js b/examples/playSound.js index 6631d5526a..657f052aa5 100644 --- a/examples/playSound.js +++ b/examples/playSound.js @@ -17,4 +17,4 @@ function maybePlaySound() { } // Connect a call back that happens every frame -Agent.willSendVisualDataCallback.connect(maybePlaySound); \ No newline at end of file +Script.willSendVisualDataCallback.connect(maybePlaySound); \ No newline at end of file diff --git a/examples/rideAlongWithAParticleExample.js b/examples/rideAlongWithAParticleExample.js index eca9fe7f4c..b2b6627063 100644 --- a/examples/rideAlongWithAParticleExample.js +++ b/examples/rideAlongWithAParticleExample.js @@ -37,7 +37,7 @@ function rideWithParticle() { y: propertiesA.position.y + 2, z: propertiesA.position.z }; } else { - Agent.stop(); + Script.stop(); } iteration++; @@ -46,5 +46,5 @@ function rideWithParticle() { // register the call back so it fires before each data send -Agent.willSendVisualDataCallback.connect(rideWithParticle); +Script.willSendVisualDataCallback.connect(rideWithParticle); diff --git a/examples/toyball.js b/examples/toyball.js index 6c40fc2932..c5672877f7 100644 --- a/examples/toyball.js +++ b/examples/toyball.js @@ -226,4 +226,4 @@ function checkController() { // register the call back so it fires before each data send -Agent.willSendVisualDataCallback.connect(checkController); +Script.willSendVisualDataCallback.connect(checkController); diff --git a/examples/voxelBird.js b/examples/voxelBird.js index 54c0129045..254f93c21e 100644 --- a/examples/voxelBird.js +++ b/examples/voxelBird.js @@ -130,4 +130,4 @@ function moveBird() { Voxels.setPacketsPerSecond(10000); // Connect a call back that happens every frame -Agent.willSendVisualDataCallback.connect(moveBird); \ No newline at end of file +Script.willSendVisualDataCallback.connect(moveBird); \ No newline at end of file From 8fc55bd196fa8b70fdc4da7d4cacf4ef1fae2391 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 31 Jan 2014 14:56:04 -0800 Subject: [PATCH 06/14] add user UUID to application window title --- interface/src/Application.cpp | 16 +++++----------- interface/src/avatar/Profile.cpp | 5 ++++- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 4947fb008f..bf17736368 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -4003,18 +4003,12 @@ void Application::setMenuShortcutsEnabled(bool enabled) { } void Application::updateWindowTitle(){ - QString title = ""; - - QString buildVersion = " (build " + applicationVersion() + ")"; - - QString username = _profile.getUsername(); - if(!username.isEmpty()){ - title += username; - title += " @ "; - } - title += NodeList::getInstance()->getDomainHostname(); - title += buildVersion; + QString buildVersion = " (build " + applicationVersion() + ")"; + NodeList* nodeList = NodeList::getInstance(); + + QString title = QString() + _profile.getUsername() + " " + nodeList->getOwnerUUID().toString() + + " @ " + nodeList->getDomainHostname() + buildVersion; qDebug("Application title set to: %s", title.toStdString().c_str()); _window->setWindowTitle(title); diff --git a/interface/src/avatar/Profile.cpp b/interface/src/avatar/Profile.cpp index 74f47bd658..902a0ea12a 100644 --- a/interface/src/avatar/Profile.cpp +++ b/interface/src/avatar/Profile.cpp @@ -53,7 +53,10 @@ void Profile::setUUID(const QUuid& uuid) { // when the UUID is changed we need set it appropriately on the NodeList instance NodeList::getInstance()->setOwnerUUID(uuid); - } + + // ask for a window title update so the new UUID is presented + Application::getInstance()->updateWindowTitle(); + } } void Profile::setFaceModelURL(const QUrl& faceModelURL) { From dba7fbceac46799b4e9495158cd6e307ead97038 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 31 Jan 2014 15:00:35 -0800 Subject: [PATCH 07/14] remove extra Script and commented out line --- examples/collidingParticles.js | 2 +- examples/editParticleExample.js | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/collidingParticles.js b/examples/collidingParticles.js index d202b31d97..81ccfe108b 100644 --- a/examples/collidingParticles.js +++ b/examples/collidingParticles.js @@ -1,4 +1,4 @@ -Script// +// // collidingParticles.js // hifi // diff --git a/examples/editParticleExample.js b/examples/editParticleExample.js index 5774eda689..152bb18fca 100644 --- a/examples/editParticleExample.js +++ b/examples/editParticleExample.js @@ -44,7 +44,6 @@ var particleID = Particles.addParticle(originalProperties); function moveParticle() { if (count >= moveUntil) { - //Script.stop(); // delete it... if (count == moveUntil) { From 00e98ee42b9c278cfc04d147e10b803324bd8d94 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 31 Jan 2014 15:44:48 -0800 Subject: [PATCH 08/14] make tryLock actually return a bool --- libraries/octree/src/Octree.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/octree/src/Octree.h b/libraries/octree/src/Octree.h index 94acf90ab7..9b8921208b 100644 --- a/libraries/octree/src/Octree.h +++ b/libraries/octree/src/Octree.h @@ -240,9 +240,9 @@ public: // Octree does not currently handle its own locking, caller must use these to lock/unlock void lockForRead() { lock.lockForRead(); } - void tryLockForRead() { lock.tryLockForRead(); } + bool tryLockForRead() { return lock.tryLockForRead(); } void lockForWrite() { lock.lockForWrite(); } - void tryLockForWrite() { lock.tryLockForWrite(); } + bool tryLockForWrite() { return lock.tryLockForWrite(); } void unlock() { lock.unlock(); } unsigned long getOctreeElementsCount(); From 19f218f37c3683a8449744b5b0a399bc0c63d176 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 31 Jan 2014 15:45:31 -0800 Subject: [PATCH 09/14] fix typo --- libraries/particles/src/ParticleCollisionSystem.cpp | 8 ++++---- libraries/particles/src/ParticleCollisionSystem.h | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libraries/particles/src/ParticleCollisionSystem.cpp b/libraries/particles/src/ParticleCollisionSystem.cpp index b5fe827ebb..e69632f379 100644 --- a/libraries/particles/src/ParticleCollisionSystem.cpp +++ b/libraries/particles/src/ParticleCollisionSystem.cpp @@ -68,12 +68,12 @@ void ParticleCollisionSystem::checkParticle(Particle* particle) { updateCollisionWithAvatars(particle); } -void ParticleCollisionSystem::emitGlobalParicleCollisionWithVoxel(Particle* particle, VoxelDetail* voxelDetails) { +void ParticleCollisionSystem::emitGlobalParticleCollisionWithVoxel(Particle* particle, VoxelDetail* voxelDetails) { ParticleID particleID = particle->getParticleID(); emit particleCollisionWithVoxel(particleID, *voxelDetails); } -void ParticleCollisionSystem::emitGlobalParicleCollisionWithParticle(Particle* particleA, Particle* particleB) { +void ParticleCollisionSystem::emitGlobalParticleCollisionWithParticle(Particle* particleA, Particle* particleB) { ParticleID idA = particleA->getParticleID(); ParticleID idB = particleB->getParticleID(); emit particleCollisionWithParticle(idA, idB); @@ -95,7 +95,7 @@ void ParticleCollisionSystem::updateCollisionWithVoxels(Particle* particle) { particle->collisionWithVoxel(voxelDetails); // let the global script run their collision scripts for particles if they have them - emitGlobalParicleCollisionWithVoxel(particle, voxelDetails); + emitGlobalParticleCollisionWithVoxel(particle, voxelDetails); updateCollisionSound(particle, collisionInfo._penetration, COLLISION_FREQUENCY); collisionInfo._penetration /= (float)(TREE_SCALE); @@ -124,7 +124,7 @@ void ParticleCollisionSystem::updateCollisionWithParticles(Particle* particleA) if (glm::dot(relativeVelocity, penetration) > 0.0f) { particleA->collisionWithParticle(particleB); particleB->collisionWithParticle(particleA); - emitGlobalParicleCollisionWithParticle(particleA, particleB); + emitGlobalParticleCollisionWithParticle(particleA, particleB); glm::vec3 axis = glm::normalize(penetration); glm::vec3 axialVelocity = glm::dot(relativeVelocity, axis) * axis; diff --git a/libraries/particles/src/ParticleCollisionSystem.h b/libraries/particles/src/ParticleCollisionSystem.h index 9baf9bfd05..c525d3ddfc 100644 --- a/libraries/particles/src/ParticleCollisionSystem.h +++ b/libraries/particles/src/ParticleCollisionSystem.h @@ -58,8 +58,8 @@ signals: private: static bool updateOperation(OctreeElement* element, void* extraData); - void emitGlobalParicleCollisionWithVoxel(Particle* particle, VoxelDetail* voxelDetails); - void emitGlobalParicleCollisionWithParticle(Particle* particleA, Particle* particleB); + void emitGlobalParticleCollisionWithVoxel(Particle* particle, VoxelDetail* voxelDetails); + void emitGlobalParticleCollisionWithParticle(Particle* particleA, Particle* particleB); ParticleEditPacketSender* _packetSender; ParticleTree* _particles; From 5b825ecd5b02ffe5999f0e1f448b85536b2570c7 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 31 Jan 2014 15:46:19 -0800 Subject: [PATCH 10/14] fix isKnownID --- libraries/particles/src/Particle.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/particles/src/Particle.cpp b/libraries/particles/src/Particle.cpp index a5ee38072f..12b59d28c9 100644 --- a/libraries/particles/src/Particle.cpp +++ b/libraries/particles/src/Particle.cpp @@ -1056,7 +1056,7 @@ QScriptValue ParticleProperties::copyToScriptValue(QScriptEngine* engine) const if (_idSet) { properties.setProperty("id", _id); - properties.setProperty("isKnownID", (_id == UNKNOWN_PARTICLE_ID)); + properties.setProperty("isKnownID", (_id != UNKNOWN_PARTICLE_ID)); } return properties; From c754663582609b2c3ac15eaa1f67195fb78b04cc Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 31 Jan 2014 17:09:08 -0800 Subject: [PATCH 11/14] force queued connection for readyRead on node socket in case it moves, closes #1685 --- assignment-client/src/AssignmentClient.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/assignment-client/src/AssignmentClient.cpp b/assignment-client/src/AssignmentClient.cpp index cdf0da43de..b2a5555e36 100644 --- a/assignment-client/src/AssignmentClient.cpp +++ b/assignment-client/src/AssignmentClient.cpp @@ -90,7 +90,8 @@ AssignmentClient::AssignmentClient(int &argc, char **argv) : timer->start(ASSIGNMENT_REQUEST_INTERVAL_MSECS); // connect our readPendingDatagrams method to the readyRead() signal of the socket - connect(&nodeList->getNodeSocket(), SIGNAL(readyRead()), this, SLOT(readPendingDatagrams())); + connect(&nodeList->getNodeSocket(), &QUdpSocket::readyRead, this, &AssignmentClient::readPendingDatagrams, + Qt::QueuedConnection); } void AssignmentClient::sendAssignmentRequest() { From 289be04f0f7fb58fd79a31454e2f300f9b29f1bc Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 31 Jan 2014 17:12:50 -0800 Subject: [PATCH 12/14] use tryLock in some cases where we don't want to block and pass already locked to the findParticleByID() in scripting interface --- interface/src/ParticleTreeRenderer.cpp | 9 +++++---- libraries/particles/src/ParticleCollisionSystem.cpp | 7 ++++--- .../particles/src/ParticlesScriptingInterface.cpp | 11 ++++++++--- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/interface/src/ParticleTreeRenderer.cpp b/interface/src/ParticleTreeRenderer.cpp index 7c82f76aab..d96ac2beaa 100644 --- a/interface/src/ParticleTreeRenderer.cpp +++ b/interface/src/ParticleTreeRenderer.cpp @@ -32,10 +32,11 @@ void ParticleTreeRenderer::init() { void ParticleTreeRenderer::update() { if (_tree) { - ParticleTree* tree = (ParticleTree*)_tree; - _tree->lockForWrite(); - tree->update(); - _tree->unlock(); + ParticleTree* tree = static_cast(_tree); + if (tree->tryLockForWrite()) { + tree->update(); + tree->unlock(); + } } } diff --git a/libraries/particles/src/ParticleCollisionSystem.cpp b/libraries/particles/src/ParticleCollisionSystem.cpp index e69632f379..c718ab3ddc 100644 --- a/libraries/particles/src/ParticleCollisionSystem.cpp +++ b/libraries/particles/src/ParticleCollisionSystem.cpp @@ -56,9 +56,10 @@ bool ParticleCollisionSystem::updateOperation(OctreeElement* element, void* extr void ParticleCollisionSystem::update() { // update all particles - _particles->lockForWrite(); - _particles->recurseTreeWithOperation(updateOperation, this); - _particles->unlock(); + if (_particles->tryLockForWrite()) { + _particles->recurseTreeWithOperation(updateOperation, this); + _particles->unlock(); + } } diff --git a/libraries/particles/src/ParticlesScriptingInterface.cpp b/libraries/particles/src/ParticlesScriptingInterface.cpp index 73aaad4cc5..a25dde1b9e 100644 --- a/libraries/particles/src/ParticlesScriptingInterface.cpp +++ b/libraries/particles/src/ParticlesScriptingInterface.cpp @@ -43,6 +43,7 @@ ParticleID ParticlesScriptingInterface::addParticle(const ParticleProperties& pr ParticleID ParticlesScriptingInterface::identifyParticle(ParticleID particleID) { uint32_t actualID = particleID.id; + if (!particleID.isKnownID) { actualID = Particle::getIDfromCreatorTokenID(particleID.creatorTokenID); if (actualID == UNKNOWN_PARTICLE_ID) { @@ -65,8 +66,12 @@ ParticleProperties ParticlesScriptingInterface::getParticleProperties(ParticleID } if (_particleTree) { _particleTree->lockForRead(); - const Particle* particle = _particleTree->findParticleByID(identity.id); - results.copyFromParticle(*particle); + const Particle* particle = _particleTree->findParticleByID(identity.id, true); + if (particle) { + results.copyFromParticle(*particle); + } else { + results.setIsUnknownID(); + } _particleTree->unlock(); } @@ -123,7 +128,7 @@ void ParticlesScriptingInterface::deleteParticle(ParticleID particleID) { if (actualID != UNKNOWN_PARTICLE_ID) { particleID.id = actualID; particleID.isKnownID = true; - queueParticleMessage(PACKET_TYPE_PARTICLE_ADD_OR_EDIT, particleID, properties); + queueParticleMessage(PacketTypeParticleAddOrEdit, particleID, properties); } // If we have a local particle tree set, then also update it. From d65a3ee1747b160805e45bda12131f7b1e23c38b Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 31 Jan 2014 17:38:53 -0800 Subject: [PATCH 13/14] spacing cleanup in Application and ScriptEngine --- interface/src/Application.cpp | 51 ++++++++++---------- libraries/script-engine/src/ScriptEngine.cpp | 3 +- libraries/script-engine/src/ScriptEngine.h | 4 +- 3 files changed, 30 insertions(+), 28 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index bf17736368..289e7e2430 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -321,7 +321,7 @@ Application::~Application() { _persistThread->deleteLater(); _persistThread = NULL; } - + storeSizeAndPosition(); saveScripts(); _sharedVoxelSystem.changeTree(new VoxelTree); @@ -4186,33 +4186,33 @@ void Application::packetSent(quint64 length) { _bandwidthMeter.outputStream(BandwidthMeter::VOXELS).updateValue(length); } -void Application::loadScripts(){ - // loads all saved scripts - QSettings* settings = new QSettings(this); - int size = settings->beginReadArray("Settings"); - for(int i=0; isetArrayIndex(i); - QString string = settings->value("script").toString(); - loadScript(string); - } - settings->endArray(); - +void Application::loadScripts() { + // loads all saved scripts + QSettings* settings = new QSettings(this); + int size = settings->beginReadArray("Settings"); + + for (int i = 0; i < size; ++i){ + settings->setArrayIndex(i); + QString string = settings->value("script").toString(); + loadScript(string); + } + + settings->endArray(); } -void Application::saveScripts(){ - // saves all current running scripts - QSettings* settings = new QSettings(this); - settings->beginWriteArray("Settings"); - for(int i=0; i<_activeScripts.size(); ++i){ - settings->setArrayIndex(i); - settings->setValue("script", _activeScripts.at(i)); - } - settings->endArray(); - +void Application::saveScripts() { + // saves all current running scripts + QSettings* settings = new QSettings(this); + settings->beginWriteArray("Settings"); + for (int i = 0; i < _activeScripts.size(); ++i){ + settings->setArrayIndex(i); + settings->setValue("script", _activeScripts.at(i)); + } + + settings->endArray(); } -void Application::removeScriptName(const QString& fileNameString) -{ +void Application::removeScriptName(const QString& fileNameString) { _activeScripts.removeOne(fileNameString); } @@ -4244,7 +4244,8 @@ void Application::loadScript(const QString& fileNameString) { // start the script on a new thread... bool wantMenuItems = true; // tells the ScriptEngine object to add menu items for itself - ScriptEngine* scriptEngine = new ScriptEngine(script, wantMenuItems, fileName, Menu::getInstance(), &_controllerScriptingInterface); + ScriptEngine* scriptEngine = new ScriptEngine(script, wantMenuItems, fileName, Menu::getInstance(), + &_controllerScriptingInterface); scriptEngine->setupMenuItems(); // setup the packet senders and jurisdiction listeners of the script engine's scripting interfaces so diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index 9a7a9197b0..a18fb58531 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -40,7 +40,8 @@ static QScriptValue soundConstructor(QScriptContext* context, QScriptEngine* eng } -ScriptEngine::ScriptEngine(const QString& scriptContents, bool wantMenuItems, const QString& fileNameString, AbstractMenuInterface* menu, +ScriptEngine::ScriptEngine(const QString& scriptContents, bool wantMenuItems, const QString& fileNameString, + AbstractMenuInterface* menu, AbstractControllerScriptingInterface* controllerScriptingInterface) : _isAvatar(false), _dataServerScriptingInterface(), diff --git a/libraries/script-engine/src/ScriptEngine.h b/libraries/script-engine/src/ScriptEngine.h index 8f29379266..a07f18f5f7 100644 --- a/libraries/script-engine/src/ScriptEngine.h +++ b/libraries/script-engine/src/ScriptEngine.h @@ -33,8 +33,8 @@ class ScriptEngine : public QObject { Q_OBJECT public: ScriptEngine(const QString& scriptContents = NO_SCRIPT, bool wantMenuItems = false, - const QString& scriptMenuName = QString(""), AbstractMenuInterface* menu = NULL, - AbstractControllerScriptingInterface* controllerScriptingInterface = NULL); + const QString& scriptMenuName = QString(""), AbstractMenuInterface* menu = NULL, + AbstractControllerScriptingInterface* controllerScriptingInterface = NULL); ~ScriptEngine(); From 40a963cf927500ab371918ba672cc1038b475ad1 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 31 Jan 2014 17:50:51 -0800 Subject: [PATCH 14/14] some application destructor cleanup --- interface/src/AbstractLoggerInterface.h | 1 + interface/src/Application.cpp | 9 ++------- interface/src/FileLogger.cpp | 5 ++++- interface/src/FileLogger.h | 2 +- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/interface/src/AbstractLoggerInterface.h b/interface/src/AbstractLoggerInterface.h index d8a48fc2fd..cedab1fad2 100644 --- a/interface/src/AbstractLoggerInterface.h +++ b/interface/src/AbstractLoggerInterface.h @@ -17,6 +17,7 @@ class AbstractLoggerInterface : public QObject { Q_OBJECT public: + AbstractLoggerInterface(QObject* parent = NULL) : QObject(parent) {}; inline bool extraDebugging() { return _extraDebugging; }; inline void setExtraDebugging(bool debugging) { _extraDebugging = debugging; }; diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 289e7e2430..d0d0fc4c40 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -154,7 +154,7 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : _resetRecentMaxPacketsSoon(true), _swatch(NULL), _pasteMode(false), - _logger(new FileLogger()), + _logger(new FileLogger(this)), _persistThread(NULL) { _myAvatar = _avatarManager.getMyAvatar(); @@ -328,12 +328,7 @@ Application::~Application() { VoxelTreeElement::removeDeleteHook(&_voxels); // we don't need to do this processing on shutdown Menu::getInstance()->deleteLater(); - - _avatarManager.clear(); - _myAvatar = NULL; - - delete _logger; - delete _settings; + delete _glWidget; } diff --git a/interface/src/FileLogger.cpp b/interface/src/FileLogger.cpp index 3c98b285a3..81c626a46e 100644 --- a/interface/src/FileLogger.cpp +++ b/interface/src/FileLogger.cpp @@ -18,7 +18,10 @@ const QString FILENAME_FORMAT = "hifi-log_%1_%2.txt"; const QString DATETIME_FORMAT = "yyyy-MM-dd_hh.mm.ss"; const QString LOGS_DIRECTORY = "Logs"; -FileLogger::FileLogger() : _logData(NULL) { +FileLogger::FileLogger(QObject* parent) : + AbstractLoggerInterface(parent), + _logData(NULL) +{ setExtraDebugging(false); _fileName = FileUtils::standardPath(LOGS_DIRECTORY); diff --git a/interface/src/FileLogger.h b/interface/src/FileLogger.h index 6a17032ae2..35cafa4db7 100644 --- a/interface/src/FileLogger.h +++ b/interface/src/FileLogger.h @@ -16,7 +16,7 @@ class FileLogger : public AbstractLoggerInterface { Q_OBJECT public: - FileLogger(); + FileLogger(QObject* parent = NULL); virtual void addMessage(QString); virtual QStringList getLogData() { return _logData; };