From 8ec9bc6705bfafff63783ab4b6ae41755aa7c1b1 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Wed, 17 Sep 2014 01:10:52 +0200 Subject: [PATCH] Cleaned up main.cpp Added functionality to send Lua scripts over the network --- include/openspace/engine/openspaceengine.h | 1 + src/engine/openspaceengine.cpp | 20 ++++++++++++ src/main.cpp | 38 +++++++++------------- 3 files changed, 37 insertions(+), 22 deletions(-) diff --git a/include/openspace/engine/openspaceengine.h b/include/openspace/engine/openspaceengine.h index c3c3c0022e..80ea8a7626 100644 --- a/include/openspace/engine/openspaceengine.h +++ b/include/openspace/engine/openspaceengine.h @@ -89,6 +89,7 @@ public: void mouseButtonCallback(int key, int action); void mousePositionCallback(int x, int y); void mouseScrollWheelCallback(int pos); + void externalControlCallback(const char* receivedChars, int size, int clientId); void encode(); void decode(); diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 7bf0f04ceb..b1571563fe 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -585,4 +585,24 @@ void OpenSpaceEngine::decode() #endif } +void OpenSpaceEngine::externalControlCallback(const char* receivedChars, + int size, int clientId) +{ + if (size == 0) + return; + + // The first byte determines the type of message + const char type = receivedChars[0]; + switch (type) { + case '0': // LuaScript + { + std::string script = std::string(receivedChars + 1); + LINFO("Received Lua Script: '" << script << "'"); + _scriptEngine->runScript(script); + } + } + + +} + } // namespace openspace diff --git a/src/main.cpp b/src/main.cpp index b5ca354f46..0808327683 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -24,20 +24,18 @@ // open space includes #include -#include // sgct includes #include sgct::Engine* _sgctEngine; -openspace::Interface* _interface; // function pointer declarations -void mainInitFunc(void); -void mainPreSyncFunc(void); -void mainPostSyncPreDrawFunc(void); -void mainRenderFunc(void); -void mainPostDrawFunc(void); +void mainInitFunc(); +void mainPreSyncFunc(); +void mainPostSyncPreDrawFunc(); +void mainRenderFunc(); +void mainPostDrawFunc(); void mainKeyboardCallback(int key, int action); void mainMouseButtonCallback(int key, int action); void mainMousePosCallback(double x, double y); @@ -89,10 +87,6 @@ int main(int argc, char** argv) sgct::SharedData::instance()->setEncodeFunction(mainEncodeFun); sgct::SharedData::instance()->setDecodeFunction(mainDecodeFun); - // init the interface which will handle callbacks from an external gui - LDEBUG("Creating Interface module"); - _interface = new openspace::Interface(&OsEng); - // try to open a window LDEBUG("Initialize SGCT Engine"); const bool initSuccess = _sgctEngine->init(sgct::Engine::OpenGL_4_0_Core_Profile); @@ -119,38 +113,38 @@ int main(int argc, char** argv) exit(EXIT_SUCCESS); } -void mainExternalControlCallback(const char* receivedChars, int size, int clientId) -{ - if (_sgctEngine->isMaster()) - _interface->callback(receivedChars); -} - -void mainInitFunc(void) +void mainInitFunc() { OsEng.initialize(); OsEng.initializeGL(); } -void mainPreSyncFunc(void) +void mainPreSyncFunc() { OsEng.preSynchronization(); } -void mainPostSyncPreDrawFunc(void) +void mainPostSyncPreDrawFunc() { OsEng.postSynchronizationPreDraw(); } -void mainRenderFunc(void) +void mainRenderFunc() { OsEng.render(); } -void mainPostDrawFunc(void) +void mainPostDrawFunc() { OsEng.postDraw(); } +void mainExternalControlCallback(const char* receivedChars, int size, int clientId) +{ + if (_sgctEngine->isMaster()) + OsEng.externalControlCallback(receivedChars, size, clientId); +} + void mainKeyboardCallback(int key, int action) { if (_sgctEngine->isMaster())