From 95639c7ce799483767414eeb942c9de9e14d9dad Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 17 Dec 2013 10:58:36 -0800 Subject: [PATCH] first cut, not working yet --- assignment-client/CMakeLists.txt | 14 ++++ assignment-client/src/Agent.cpp | 73 ++------------------ assignment-client/src/Agent.h | 2 + libraries/scriptengine/src/ScriptEngine.cpp | 16 ++++- libraries/scriptengine/src/ScriptEngine.h | 8 ++- libraries/shared/CMakeLists.txt | 3 + libraries/shared/src/AbstractMenuInterface.h | 7 ++ 7 files changed, 53 insertions(+), 70 deletions(-) diff --git a/assignment-client/CMakeLists.txt b/assignment-client/CMakeLists.txt index 5bc4829117..1d2fb866bb 100644 --- a/assignment-client/CMakeLists.txt +++ b/assignment-client/CMakeLists.txt @@ -8,12 +8,25 @@ set(MACRO_DIR ${ROOT_DIR}/cmake/macros) # setup for find modules set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/../cmake/modules/") +set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} $ENV{QT_CMAKE_PREFIX_PATH}) + +find_package(Qt5Core REQUIRED) +find_package(Qt5Gui REQUIRED) find_package(Qt5Network REQUIRED) +#find_package(Qt5Multimedia REQUIRED) +#find_package(Qt5Network REQUIRED) +#find_package(Qt5OpenGL REQUIRED) +#find_package(Qt5Svg REQUIRED) +#find_package(Qt5WebKit REQUIRED) +#find_package(Qt5WebKitWidgets REQUIRED) + + include(${MACRO_DIR}/SetupHifiProject.cmake) setup_hifi_project(${TARGET_NAME} TRUE) qt5_use_modules(${TARGET_NAME} Network) +qt5_use_modules(${TARGET_NAME} Gui) # include glm include(${MACRO_DIR}/IncludeGLM.cmake) @@ -30,6 +43,7 @@ link_hifi_library(particles ${TARGET_NAME} ${ROOT_DIR}) link_hifi_library(octree-server ${TARGET_NAME} ${ROOT_DIR}) link_hifi_library(particle-server ${TARGET_NAME} ${ROOT_DIR}) link_hifi_library(voxel-server ${TARGET_NAME} ${ROOT_DIR}) +link_hifi_library(scriptengine ${TARGET_NAME} ${ROOT_DIR}) #testing include_directories(${ROOT_DIR}/externals/civetweb/include) diff --git a/assignment-client/src/Agent.cpp b/assignment-client/src/Agent.cpp index 8f02ed9a2e..9fbe464a9e 100644 --- a/assignment-client/src/Agent.cpp +++ b/assignment-client/src/Agent.cpp @@ -76,28 +76,6 @@ void Agent::run() { loop.exec(); QString scriptContents(reply->readAll()); - QScriptEngine engine; - - // register meta-type for glm::vec3 conversions - registerMetaTypes(&engine); - - QScriptValue agentValue = engine.newQObject(this); - engine.globalObject().setProperty("Agent", agentValue); - - QScriptValue voxelScripterValue = engine.newQObject(&_voxelScriptingInterface); - engine.globalObject().setProperty("Voxels", voxelScripterValue); - - QScriptValue particleScripterValue = engine.newQObject(&_particleScriptingInterface); - engine.globalObject().setProperty("Particles", particleScripterValue); - - QScriptValue treeScaleValue = engine.newVariant(QVariant(TREE_SCALE)); - engine.globalObject().setProperty("TREE_SCALE", treeScaleValue); - - const unsigned int VISUAL_DATA_CALLBACK_USECS = (1.0 / 60.0) * 1000 * 1000; - - // let the VoxelPacketSender know how frequently we plan to call it - _voxelScriptingInterface.getVoxelPacketSender()->setProcessCallIntervalHint(VISUAL_DATA_CALLBACK_USECS); - _particleScriptingInterface.getParticlePacketSender()->setProcessCallIntervalHint(VISUAL_DATA_CALLBACK_USECS); qDebug() << "Downloaded script:" << scriptContents << "\n"; QScriptValue result = engine.evaluate(scriptContents); @@ -124,50 +102,13 @@ void Agent::run() { QTimer* pingNodesTimer = new QTimer(this); connect(pingNodesTimer, SIGNAL(timeout()), nodeList, SLOT(pingInactiveNodes())); pingNodesTimer->start(PING_INACTIVE_NODE_INTERVAL_USECS / 1000); + + const unsigned int VISUAL_DATA_CALLBACK_USECS = (1.0 / 60.0) * 1000 * 1000; + // let the VoxelPacketSender know how frequently we plan to call it + _voxelScriptingInterface.getVoxelPacketSender()->setProcessCallIntervalHint(VISUAL_DATA_CALLBACK_USECS); + _particleScriptingInterface.getParticlePacketSender()->setProcessCallIntervalHint(VISUAL_DATA_CALLBACK_USECS); - while (!_isFinished) { - - int usecToSleep = usecTimestamp(&startTime) + (thisFrame++ * VISUAL_DATA_CALLBACK_USECS) - usecTimestampNow(); - if (usecToSleep > 0) { - usleep(usecToSleep); - } - - QCoreApplication::processEvents(); - - bool willSendVisualDataCallBack = false; - - if (_voxelScriptingInterface.getVoxelPacketSender()->voxelServersExist()) { - // 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(); - } + _scriptEngine.setScriptContents(scriptContents); - 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) { - emit willSendVisualDataCallback(); - } - - - if (engine.hasUncaughtException()) { - int line = engine.uncaughtExceptionLineNumber(); - qDebug() << "Uncaught exception at line" << line << ":" << engine.uncaughtException().toString() << "\n"; - } - - - } + _scriptEngine.run(); } diff --git a/assignment-client/src/Agent.h b/assignment-client/src/Agent.h index 1c2be08662..e6e7eb84b1 100644 --- a/assignment-client/src/Agent.h +++ b/assignment-client/src/Agent.h @@ -15,6 +15,7 @@ #include #include +#include #include #include @@ -35,6 +36,7 @@ signals: private: VoxelScriptingInterface _voxelScriptingInterface; ParticleScriptingInterface _particleScriptingInterface; + ScriptEngine _scriptEngine; }; #endif /* defined(__hifi__Agent__) */ diff --git a/libraries/scriptengine/src/ScriptEngine.cpp b/libraries/scriptengine/src/ScriptEngine.cpp index 7e5f414dee..7d34a4edf6 100644 --- a/libraries/scriptengine/src/ScriptEngine.cpp +++ b/libraries/scriptengine/src/ScriptEngine.cpp @@ -28,6 +28,9 @@ ScriptEngine::ScriptEngine(QString scriptContents, bool wantMenuItems, const char* scriptMenuName, AbstractMenuInterface* menu) { _scriptContents = scriptContents; _isFinished = false; + _isRunning = false; + + // some clients will use these menu features _wantMenuItems = wantMenuItems; if (scriptMenuName) { _scriptMenuName = "Stop "; @@ -57,10 +60,16 @@ void ScriptEngine::cleanMenuItems() { } } -void ScriptEngine::run() { +bool ScriptEngine::setScriptContents(QString scriptContents) { + if (_isRunning) { + return false; + } + _scriptContents = scriptContents; + return true; +} - //setupMenuItems(); - +void ScriptEngine::run() { + _isRunning = true; QScriptEngine engine; _voxelScriptingInterface.init(); @@ -161,6 +170,7 @@ void ScriptEngine::run() { } emit finished(); + _isRunning = false; } void ScriptEngine::stop() { diff --git a/libraries/scriptengine/src/ScriptEngine.h b/libraries/scriptengine/src/ScriptEngine.h index 772b0a146f..605c4ce7e8 100644 --- a/libraries/scriptengine/src/ScriptEngine.h +++ b/libraries/scriptengine/src/ScriptEngine.h @@ -19,10 +19,12 @@ #include #include +const QString NO_SCRIPT(""); + class ScriptEngine : public QObject { Q_OBJECT public: - ScriptEngine(QString scriptContents, bool wantMenuItems = false, + ScriptEngine(QString scriptContents = NO_SCRIPT, bool wantMenuItems = false, const char* scriptMenuName = NULL, AbstractMenuInterface* menu = NULL); ~ScriptEngine(); @@ -33,6 +35,9 @@ public: /// Access the ParticleScriptingInterface in order to initialize it with a custom packet sender and jurisdiction listener ParticleScriptingInterface* getParticleScriptingInterface() { return &_particleScriptingInterface; } + /// sets the script contents, will return false if failed, will fail if script is already running + bool setScriptContents(QString scriptContents); + void setupMenuItems(); void cleanMenuItems(); @@ -47,6 +52,7 @@ signals: protected: QString _scriptContents; bool _isFinished; + bool _isRunning; private: diff --git a/libraries/shared/CMakeLists.txt b/libraries/shared/CMakeLists.txt index 8c05b1ff8f..8de7e3f594 100644 --- a/libraries/shared/CMakeLists.txt +++ b/libraries/shared/CMakeLists.txt @@ -6,12 +6,15 @@ set(MACRO_DIR ${ROOT_DIR}/cmake/macros) set(TARGET_NAME shared) project(${TARGET_NAME}) +find_package(Qt5Core REQUIRED) +find_package(Qt5Gui REQUIRED) find_package(Qt5Network REQUIRED) include(${MACRO_DIR}/SetupHifiLibrary.cmake) setup_hifi_library(${TARGET_NAME}) qt5_use_modules(${TARGET_NAME} Network) +qt5_use_modules(${TARGET_NAME} Gui) # include GLM include(${MACRO_DIR}/IncludeGLM.cmake) diff --git a/libraries/shared/src/AbstractMenuInterface.h b/libraries/shared/src/AbstractMenuInterface.h index 6af0ea2d00..c3857c456a 100644 --- a/libraries/shared/src/AbstractMenuInterface.h +++ b/libraries/shared/src/AbstractMenuInterface.h @@ -14,6 +14,13 @@ //#include //#include +//class QMenu; +//class QString; +//class QObject; +//class QKeySequence; +//class QAction; +//extern enum QAction::MenuRole; + class AbstractMenuInterface { public: virtual QMenu* getActiveScriptsMenu() = 0;