From a256473ac5137e97c3c137b74af61bf1f366f600 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 25 Mar 2014 12:55:50 -0700 Subject: [PATCH 1/6] fixed lookWithTouch.js to not reset --- examples/lookWithTouch.js | 41 ++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/examples/lookWithTouch.js b/examples/lookWithTouch.js index 852573aea6..4406b4567e 100644 --- a/examples/lookWithTouch.js +++ b/examples/lookWithTouch.js @@ -9,6 +9,7 @@ // // +var startedTouching = false; var lastX = 0; var lastY = 0; var yawFromMouse = 0; @@ -21,12 +22,14 @@ function touchBeginEvent(event) { } lastX = event.x; lastY = event.y; + startedTouching = true; } function touchEndEvent(event) { if (wantDebugging) { print("touchEndEvent event.x,y=" + event.x + ", " + event.y); } + startedTouching = false; } function touchUpdateEvent(event) { @@ -44,24 +47,26 @@ function touchUpdateEvent(event) { } function update(deltaTime) { - // rotate body yaw for yaw received from mouse - var newOrientation = Quat.multiply(MyAvatar.orientation, Quat.fromPitchYawRollRadians(0, yawFromMouse, 0)); - if (wantDebugging) { - print("changing orientation" - + " [old]MyAvatar.orientation="+MyAvatar.orientation.x + "," + MyAvatar.orientation.y + "," - + MyAvatar.orientation.z + "," + MyAvatar.orientation.w - + " newOrientation="+newOrientation.x + "," + newOrientation.y + "," + newOrientation.z + "," + newOrientation.w); - } - MyAvatar.orientation = newOrientation; - yawFromMouse = 0; + if (startedTouching) { + // rotate body yaw for yaw received from mouse + var newOrientation = Quat.multiply(MyAvatar.orientation, Quat.fromPitchYawRollRadians(0, yawFromMouse, 0)); + if (wantDebugging) { + print("changing orientation" + + " [old]MyAvatar.orientation="+MyAvatar.orientation.x + "," + MyAvatar.orientation.y + "," + + MyAvatar.orientation.z + "," + MyAvatar.orientation.w + + " newOrientation="+newOrientation.x + "," + newOrientation.y + "," + newOrientation.z + "," + newOrientation.w); + } + MyAvatar.orientation = newOrientation; + yawFromMouse = 0; - // apply pitch from mouse - var newPitch = MyAvatar.headPitch + pitchFromMouse; - if (wantDebugging) { - print("changing pitch [old]MyAvatar.headPitch="+MyAvatar.headPitch+ " newPitch="+newPitch); + // apply pitch from mouse + var newPitch = MyAvatar.headPitch + pitchFromMouse; + if (wantDebugging) { + print("changing pitch [old]MyAvatar.headPitch="+MyAvatar.headPitch+ " newPitch="+newPitch); + } + MyAvatar.headPitch = newPitch; + pitchFromMouse = 0; } - MyAvatar.headPitch = newPitch; - pitchFromMouse = 0; } // Map the mouse events to our functions @@ -77,10 +82,6 @@ function scriptEnding() { Controller.releaseTouchEvents(); } -MyAvatar.bodyYaw = 0; -MyAvatar.bodyPitch = 0; -MyAvatar.bodyRoll = 0; - // would be nice to change to update Script.update.connect(update); Script.scriptEnding.connect(scriptEnding); From 9a3533a38fbbe5affa853330881adb77dd9f395c Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 25 Mar 2014 12:59:57 -0700 Subject: [PATCH 2/6] added inspect.js to defaultScripts.js --- examples/defaultScripts.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/defaultScripts.js b/examples/defaultScripts.js index eae3c2eb8c..722b21844f 100644 --- a/examples/defaultScripts.js +++ b/examples/defaultScripts.js @@ -3,4 +3,5 @@ Script.include("lookWithTouch.js"); Script.include("editVoxels.js"); Script.include("selectAudioDevice.js"); -Script.include("hydraMove.js"); \ No newline at end of file +Script.include("hydraMove.js"); +Script.include("inspect.js"); \ No newline at end of file From f8c479f9c54388b84500206b2259d247345de5b6 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 25 Mar 2014 14:28:26 -0700 Subject: [PATCH 3/6] seed random number generator in ScriptEngine for Math.random use in JS --- libraries/script-engine/src/ScriptEngine.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index 9bd00a0019..e880760a1d 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -235,6 +235,11 @@ void ScriptEngine::init() { // let the VoxelPacketSender know how frequently we plan to call it _voxelsScriptingInterface.getVoxelPacketSender()->setProcessCallIntervalHint(SCRIPT_DATA_CALLBACK_USECS); _particlesScriptingInterface.getParticlePacketSender()->setProcessCallIntervalHint(SCRIPT_DATA_CALLBACK_USECS); + + // call srand to seed the random number generator + srand(QDateTime::currentMSecsSinceEpoch() + + QCoreApplication::applicationPid() + + NodeList::getInstance()->getNodeSocket().localPort()); } From 41e2ce2b1999e5bd8893e2f17c756adfc87f9681 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 25 Mar 2014 14:29:59 -0700 Subject: [PATCH 4/6] remove DS check in debug --- libraries/shared/src/ThreadedAssignment.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/shared/src/ThreadedAssignment.cpp b/libraries/shared/src/ThreadedAssignment.cpp index 642f471cc5..1f443146f8 100644 --- a/libraries/shared/src/ThreadedAssignment.cpp +++ b/libraries/shared/src/ThreadedAssignment.cpp @@ -84,7 +84,6 @@ void ThreadedAssignment::checkInWithDomainServerOrExit() { if (NodeList::getInstance()->getNumNoReplyDomainCheckIns() == MAX_SILENT_DOMAIN_SERVER_CHECK_INS) { setFinished(true); } else { - qDebug() << "Sending DS check in. There are" << NodeList::getInstance()->getNumNoReplyDomainCheckIns() << "unreplied."; NodeList::getInstance()->sendDomainServerCheckIn(); } } From 7190ce9a88fda177eb3cc6b43104ceffd7ac2291 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 25 Mar 2014 14:33:53 -0700 Subject: [PATCH 5/6] remove loadRandomIdentifier for STUN requests, use UUID --- libraries/shared/src/NodeList.cpp | 5 ++--- libraries/shared/src/SharedUtil.cpp | 9 --------- libraries/shared/src/SharedUtil.h | 2 -- 3 files changed, 2 insertions(+), 14 deletions(-) diff --git a/libraries/shared/src/NodeList.cpp b/libraries/shared/src/NodeList.cpp index 95417f4f71..b2a494aa32 100644 --- a/libraries/shared/src/NodeList.cpp +++ b/libraries/shared/src/NodeList.cpp @@ -413,9 +413,8 @@ void NodeList::sendSTUNRequest() { // transaction ID (random 12-byte unsigned integer) const uint NUM_TRANSACTION_ID_BYTES = 12; - unsigned char transactionID[NUM_TRANSACTION_ID_BYTES]; - loadRandomIdentifier(transactionID, NUM_TRANSACTION_ID_BYTES); - memcpy(stunRequestPacket + packetIndex, &transactionID, sizeof(transactionID)); + QUuid randomUUID = QUuid::createUuid(); + memcpy(stunRequestPacket + packetIndex, randomUUID.toRfc4122().data(), NUM_TRANSACTION_ID_BYTES); // lookup the IP for the STUN server static HifiSockAddr stunSockAddr(STUN_SERVER_HOSTNAME, STUN_SERVER_PORT); diff --git a/libraries/shared/src/SharedUtil.cpp b/libraries/shared/src/SharedUtil.cpp index 882d4719c8..efd5180d03 100644 --- a/libraries/shared/src/SharedUtil.cpp +++ b/libraries/shared/src/SharedUtil.cpp @@ -206,15 +206,6 @@ bool isInEnvironment(const char* environment) { } } -void loadRandomIdentifier(unsigned char* identifierBuffer, int numBytes) { - // seed the the random number generator - srand(time(NULL)); - - for (int i = 0; i < numBytes; i++) { - identifierBuffer[i] = rand() % 256; - } -} - ////////////////////////////////////////////////////////////////////////////////////////// // Function: getCmdOption() // Description: Handy little function to tell you if a command line flag and option was diff --git a/libraries/shared/src/SharedUtil.h b/libraries/shared/src/SharedUtil.h index 439b85aa54..d8d686c63b 100644 --- a/libraries/shared/src/SharedUtil.h +++ b/libraries/shared/src/SharedUtil.h @@ -96,8 +96,6 @@ int getNthBit(unsigned char byte, int ordinal); /// determines the bit placement bool isInEnvironment(const char* environment); -void loadRandomIdentifier(unsigned char* identifierBuffer, int numBytes); - const char* getCmdOption(int argc, const char * argv[],const char* option); bool cmdOptionExists(int argc, const char * argv[],const char* option); From f0f3cf7282d763e8e54b08578462cf739079273b Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 25 Mar 2014 14:36:02 -0700 Subject: [PATCH 6/6] remove seed to random number generator that is no longer needed --- libraries/script-engine/src/ScriptEngine.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index e880760a1d..c0834aad9d 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -235,12 +235,6 @@ void ScriptEngine::init() { // let the VoxelPacketSender know how frequently we plan to call it _voxelsScriptingInterface.getVoxelPacketSender()->setProcessCallIntervalHint(SCRIPT_DATA_CALLBACK_USECS); _particlesScriptingInterface.getParticlePacketSender()->setProcessCallIntervalHint(SCRIPT_DATA_CALLBACK_USECS); - - // call srand to seed the random number generator - srand(QDateTime::currentMSecsSinceEpoch() - + QCoreApplication::applicationPid() - + NodeList::getInstance()->getNodeSocket().localPort()); - } void ScriptEngine::registerGlobalObject(const QString& name, QObject* object) {