From dacaade9ed45eae5cc306b1a85369a422720be4f Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Sat, 14 Dec 2013 13:54:25 -0800 Subject: [PATCH] first cut at client scripts working --- interface/src/Application.cpp | 16 +++++++++---- libraries/scriptengine/src/ScriptEngine.cpp | 26 ++++++++++++++++++++- libraries/scriptengine/src/ScriptEngine.h | 6 +++++ 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index a93ba820dc..89170f94a6 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -4426,14 +4426,22 @@ void Application::loadScript() { // start the script on a new thread... _scriptEngine = new ScriptEngine(script); + // setup the packet senders and jurisdiction listeners of the script engine's scripting interfaces so + // we can use the same ones from the application. + _scriptEngine->getVoxelScriptingInterface()->setPacketSender(&_voxelEditSender); + _scriptEngine->getParticleScriptingInterface()->setPacketSender(&_particleEditSender); + + //_scriptEngine->getVoxelScriptingInterface()->setJurisdictionListener(); + //_scriptEngine->getParticleScriptingInterface()->setJurisdictionListener(); + QThread* workerThread = new QThread(this); connect(workerThread, SIGNAL(started()), _scriptEngine, SLOT(run())); - connect(_scriptEngine, SIGNAL(finished()), this, SLOT(assignmentCompleted())); - connect(_scriptEngine, SIGNAL(finished()), workerThread, SLOT(quit())); - connect(_scriptEngine, SIGNAL(finished()), _scriptEngine, SLOT(deleteLater())); - connect(_scriptEngine, SIGNAL(finished()), workerThread, SLOT(deleteLater())); + //connect(_scriptEngine, SIGNAL(finished()), this, SLOT(assignmentCompleted())); + //connect(_scriptEngine, SIGNAL(finished()), workerThread, SLOT(quit())); + //connect(_scriptEngine, SIGNAL(finished()), _scriptEngine, SLOT(deleteLater())); + //connect(_scriptEngine, SIGNAL(finished()), workerThread, SLOT(deleteLater())); _scriptEngine->moveToThread(workerThread); diff --git a/libraries/scriptengine/src/ScriptEngine.cpp b/libraries/scriptengine/src/ScriptEngine.cpp index 2768dd1ab5..d601ba6287 100644 --- a/libraries/scriptengine/src/ScriptEngine.cpp +++ b/libraries/scriptengine/src/ScriptEngine.cpp @@ -29,6 +29,9 @@ ScriptEngine::ScriptEngine(QString scriptContents) { void ScriptEngine::run() { QScriptEngine engine; + _voxelScriptingInterface.init(); + _particleScriptingInterface.init(); + // register meta-type for glm::vec3 conversions registerMetaTypes(&engine); @@ -76,7 +79,28 @@ void ScriptEngine::run() { QCoreApplication::processEvents(); - bool willSendVisualDataCallBack = true; + bool willSendVisualDataCallBack = false; + if (_voxelScriptingInterface.getVoxelPacketSender()->serversExist()) { + // allow the scripter's call back to setup visual data + willSendVisualDataCallBack = true; + + // release the queue of edit voxel messages. + _voxelScriptingInterface.getVoxelPacketSender()->releaseQueuedMessages(); + + // since we're in non-threaded mode, call process so that the packets are sent + //_voxelScriptingInterface.getVoxelPacketSender()->process(); + } + + if (_particleScriptingInterface.getParticlePacketSender()->serversExist()) { + // allow the scripter's call back to setup visual data + willSendVisualDataCallBack = true; + + // release the queue of edit voxel messages. + _particleScriptingInterface.getParticlePacketSender()->releaseQueuedMessages(); + + // since we're in non-threaded mode, call process so that the packets are sent + //_particleScriptingInterface.getParticlePacketSender()->process(); + } if (willSendVisualDataCallBack) { qDebug() << "willSendVisualDataCallback thisFrame:" << thisFrame << "\n"; diff --git a/libraries/scriptengine/src/ScriptEngine.h b/libraries/scriptengine/src/ScriptEngine.h index 21e9c9485c..725c920a8a 100644 --- a/libraries/scriptengine/src/ScriptEngine.h +++ b/libraries/scriptengine/src/ScriptEngine.h @@ -23,6 +23,12 @@ class ScriptEngine : public QObject { public: ScriptEngine(QString scriptContents); + /// Access the VoxelScriptingInterface in order to initialize it with a custom packet sender and jurisdiction listener + VoxelScriptingInterface* getVoxelScriptingInterface() { return &_voxelScriptingInterface; } + + /// Access the ParticleScriptingInterface in order to initialize it with a custom packet sender and jurisdiction listener + ParticleScriptingInterface* getParticleScriptingInterface() { return &_particleScriptingInterface; } + public slots: void run(); void stop() {