diff --git a/include/openspace/engine/openspaceengine.h b/include/openspace/engine/openspaceengine.h index 80ea8a7626..1e0d41a50b 100644 --- a/include/openspace/engine/openspaceengine.h +++ b/include/openspace/engine/openspaceengine.h @@ -25,6 +25,10 @@ #ifndef __OPENSPACEENGINE_H__ #define __OPENSPACEENGINE_H__ +// sgct header has to be included before all others due to Windows header +#define SGCT_WINDOWS_INCLUDE +#include "sgct.h" + #include #include #include diff --git a/include/openspace/flare/flare.h b/include/openspace/flare/flare.h index 5016a3fd50..f0a76100d8 100644 --- a/include/openspace/flare/flare.h +++ b/include/openspace/flare/flare.h @@ -22,71 +22,73 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#ifndef __FLARE_H__ -#define __FLARE_H__ +// Source is still in here to cannibalize later (ab) -#include -#include -#define SGCT_WINDOWS_INCLUDE -#include -#include -#include -#include -#include - -namespace openspace { - -class Flare: public Renderable { -public: - Flare(); - ~Flare(); - - bool initialize(); - bool deinitialize(); - - virtual void render(const Camera *camera, const psc& thisPosition, RuntimeData* runtimeData); - virtual void update(); - - void render(); - void initNavigation(); - - void keyboard(int key, int action); - void mouse(int button, int action); - void preSync(); - void postSyncPreDraw(); - void postDraw(); - void encode(); - void decode(); - -private: - void init(); - - osp::Config* _config; - osp::Raycaster* _raycaster; - osp::Animator* _animator; - - sgct::SharedInt _timeStep; - sgct::SharedBool _animationPaused; - sgct::SharedBool _fpsMode; - sgct::SharedFloat _elapsedTime; - sgct::SharedInt _manualTimestep; - sgct::SharedFloat _pitch; - sgct::SharedFloat _yaw; - sgct::SharedFloat _roll; - sgct::SharedFloat _translateX; - sgct::SharedFloat _translateY; - sgct::SharedFloat _translateZ; - sgct::SharedBool _reloadFlag; - - float _oldTime; - float _currentTime; - bool _leftMouseButton; - double _currentMouseX; - double _currentMouseY; - double _lastMouseX; - double _lastMouseY; -}; - -} // namespace openspace - -#endif // __FLARE_H__ +//#ifndef __FLARE_H__ +//#define __FLARE_H__ +// +//#include +//#include +//#define SGCT_WINDOWS_INCLUDE +//#include +//#include +//#include +//#include +//#include +// +//namespace openspace { +// +//class Flare: public Renderable { +//public: +// Flare(); +// ~Flare(); +// +// bool initialize(); +// bool deinitialize(); +// +// virtual void render(const Camera *camera, const psc& thisPosition, RuntimeData* runtimeData); +// virtual void update(); +// +// void render(); +// void initNavigation(); +// +// void keyboard(int key, int action); +// void mouse(int button, int action); +// void preSync(); +// void postSyncPreDraw(); +// void postDraw(); +// void encode(); +// void decode(); +// +//private: +// void init(); +// +// osp::Config* _config; +// osp::Raycaster* _raycaster; +// osp::Animator* _animator; +// +// sgct::SharedInt _timeStep; +// sgct::SharedBool _animationPaused; +// sgct::SharedBool _fpsMode; +// sgct::SharedFloat _elapsedTime; +// sgct::SharedInt _manualTimestep; +// sgct::SharedFloat _pitch; +// sgct::SharedFloat _yaw; +// sgct::SharedFloat _roll; +// sgct::SharedFloat _translateX; +// sgct::SharedFloat _translateY; +// sgct::SharedFloat _translateZ; +// sgct::SharedBool _reloadFlag; +// +// float _oldTime; +// float _currentTime; +// bool _leftMouseButton; +// double _currentMouseX; +// double _currentMouseY; +// double _lastMouseX; +// double _lastMouseY; +//}; +// +//} // namespace openspace +// +//#endif // __FLARE_H__ diff --git a/include/openspace/properties/propertyowner.h b/include/openspace/properties/propertyowner.h index 7e29af385b..b2030f9951 100644 --- a/include/openspace/properties/propertyowner.h +++ b/include/openspace/properties/propertyowner.h @@ -200,7 +200,7 @@ protected: private: /// The name of this PropertyOwner std::string _name; - /// A list of all owned Property's + /// A list of all registered Property's std::vector _properties; /// A list of all sub-owners std::vector _subOwners; diff --git a/include/openspace/rendering/planets/renderableplanet.h b/include/openspace/rendering/planets/renderableplanet.h index 9ecc4aa2f1..668f16e10f 100644 --- a/include/openspace/rendering/planets/renderableplanet.h +++ b/include/openspace/rendering/planets/renderableplanet.h @@ -29,11 +29,11 @@ #include #include +#include // ghoul includes #include #include -#include namespace openspace { @@ -49,8 +49,8 @@ public: bool initialize() override; bool deinitialize() override; - void render(const Camera* camera, const psc& thisPosition, RuntimeData* runtimeData) override; - void update() override; + void render(const RenderData& data) override; + void update(const UpdateData& data) override; protected: void loadTexture(); @@ -62,6 +62,8 @@ private: ghoul::opengl::Texture* _texture; planetgeometry::PlanetGeometry* _geometry; + glm::dmat3 _stateMatrix; + std::string _target; }; diff --git a/include/openspace/rendering/renderable.h b/include/openspace/rendering/renderable.h index a272fb2c50..81bb33967c 100644 --- a/include/openspace/rendering/renderable.h +++ b/include/openspace/rendering/renderable.h @@ -34,7 +34,7 @@ #include #include #include -#include +#include namespace openspace { @@ -52,8 +52,8 @@ public: void setBoundingSphere(const PowerScaledScalar& boundingSphere); const PowerScaledScalar& getBoundingSphere(); - virtual void render(const Camera* camera, const psc& thisPosition, RuntimeData* runtimeData) = 0; - virtual void update(); + virtual void render(const RenderData& data) = 0; + virtual void update(const UpdateData& data); bool isVisible() const; @@ -65,7 +65,6 @@ private: properties::BoolProperty _enabled; PowerScaledScalar boundingSphere_; - RuntimeData* _runtimeData; std::string _relativePath; }; diff --git a/include/openspace/rendering/renderablefieldlines.h b/include/openspace/rendering/renderablefieldlines.h index b730345076..c0b54c0f16 100644 --- a/include/openspace/rendering/renderablefieldlines.h +++ b/include/openspace/rendering/renderablefieldlines.h @@ -27,6 +27,7 @@ // open space includes #include +#include // ghoul includes #include @@ -43,8 +44,8 @@ public: bool initialize(); bool deinitialize(); - virtual void render(const Camera *camera, const psc& thisPosition, RuntimeData* runtimeData); - virtual void update(); + void render(const RenderData& data) override; + void update(const UpdateData& data) override; private: std::vector > getFieldlinesData(std::string filename, ghoul::Dictionary hintsDictionary); diff --git a/include/openspace/rendering/renderablesphericalgrid.h b/include/openspace/rendering/renderablesphericalgrid.h index 29f5622131..d2de735960 100644 --- a/include/openspace/rendering/renderablesphericalgrid.h +++ b/include/openspace/rendering/renderablesphericalgrid.h @@ -30,6 +30,7 @@ // open space includes #include #include + // ghoul includes #include #include @@ -43,8 +44,8 @@ public: bool initialize() override; bool deinitialize() override; - void render(const Camera* camera, const psc& position, RuntimeData* runtimeData) override; - void update() override; + void render(const RenderData& data) override; + void update(const UpdateData& data) override; private: protected: typedef struct { diff --git a/include/openspace/rendering/renderablevolumegl.h b/include/openspace/rendering/renderablevolumegl.h index b67b7e52f2..d7885b1aa0 100644 --- a/include/openspace/rendering/renderablevolumegl.h +++ b/include/openspace/rendering/renderablevolumegl.h @@ -44,8 +44,8 @@ public: bool initialize(); bool deinitialize(); - virtual void render(const Camera *camera, const psc& thisPosition, RuntimeData* runtimeData); - virtual void update(); + virtual void render(const RenderData& data) override; + virtual void update(const UpdateData& data) override; private: ghoul::Dictionary _hintsDictionary; @@ -69,7 +69,6 @@ private: float _w; GLint _MVPLocation, _modelTransformLocation, _typeLocation; - RuntimeData* _runtimeData; bool _updateTransferfunction; int _id; }; diff --git a/include/openspace/rendering/renderengine.h b/include/openspace/rendering/renderengine.h index 4eda44fb85..6ae5056338 100644 --- a/include/openspace/rendering/renderengine.h +++ b/include/openspace/rendering/renderengine.h @@ -26,7 +26,6 @@ #define __RENDERENGINE_H__ #include -#include #include #include @@ -44,7 +43,6 @@ public: bool initialize(); - void setRuntimeData(RuntimeData* runtimeData); void setSceneGraph(SceneGraph* sceneGraph); SceneGraph* sceneGraph(); @@ -63,7 +61,6 @@ public: private: Camera* _mainCamera; SceneGraph* _sceneGraph; - RuntimeData* _runtimeData; ABuffer* _abuffer; }; diff --git a/include/openspace/rendering/stars/renderablestars.h b/include/openspace/rendering/stars/renderablestars.h index 75878f01a3..dc63c335d8 100644 --- a/include/openspace/rendering/stars/renderablestars.h +++ b/include/openspace/rendering/stars/renderablestars.h @@ -28,6 +28,7 @@ // open space includes #include #include + // ghoul includes #include #include @@ -43,8 +44,8 @@ public: bool initialize() override; bool deinitialize() override; - void render(const Camera* camera, const psc& position, RuntimeData* runtimeData) override; - void update() override; + void render(const RenderData& data) override; + void update(const UpdateData& data) override; protected: void loadTexture(); @@ -72,8 +73,6 @@ private: int v_size; int v_stride; int v_total; - - RuntimeData* _runtimeData; }; } // namespace openspace diff --git a/include/openspace/scenegraph/ephemeris.h b/include/openspace/scenegraph/ephemeris.h index 9a8baef1e8..28483e6a31 100644 --- a/include/openspace/scenegraph/ephemeris.h +++ b/include/openspace/scenegraph/ephemeris.h @@ -27,8 +27,7 @@ #include #include -#include - +#include namespace openspace { @@ -40,14 +39,10 @@ public: virtual ~Ephemeris(); virtual bool initialize(); virtual const psc& position() const = 0; - virtual void update(RuntimeData* runtimeData) = 0; - virtual void update(); + virtual void update(const UpdateData& data); protected: Ephemeris(); - -private: - RuntimeData* _runtimeData; }; } // namespace openspace diff --git a/include/openspace/scenegraph/scenegraph.h b/include/openspace/scenegraph/scenegraph.h index a245041dd4..07544bbd99 100644 --- a/include/openspace/scenegraph/scenegraph.h +++ b/include/openspace/scenegraph/scenegraph.h @@ -30,13 +30,12 @@ #include #include - +#include #include // ghoul includes #include #include -#include namespace openspace { @@ -49,8 +48,6 @@ public: SceneGraph(); ~SceneGraph(); - void setRuntimeData(RuntimeData* runtimeData); - /** * Initalizes the SceneGraph by loading modules from the ${SCENEPATH} directory */ @@ -64,15 +61,15 @@ public: /* * Load the scenegraph from the provided folder */ - bool loadScene(const std::string& sceneDescriptionFilePath, - const std::string& defaultModulePath); + void scheduleLoadSceneFile(const std::string& sceneDescriptionFilePath); + void clearSceneGraph(); void loadModule(const std::string& modulePath); /* * Updates all SceneGraphNodes relative positions */ - void update(); + void update(const UpdateData& data); /* * Evaluates if the SceneGraphNodes are visible to the provided camera @@ -82,7 +79,7 @@ public: /* * Render visible SceneGraphNodes using the provided camera */ - void render(Camera* camera); + void render(const RenderData& data); /* * Prints the SceneGraph tree. For debugging purposes @@ -111,13 +108,16 @@ public: static scripting::ScriptEngine::LuaLibrary luaLibrary(); private: + bool loadSceneInternal(const std::string& sceneDescriptionFilePath); + std::string _focus, _position; // actual scenegraph SceneGraphNode* _root; std::vector _nodes; std::map _allNodes; - RuntimeData* _runtimeData; + + std::string _sceneGraphToLoad; }; } // namespace openspace diff --git a/include/openspace/scenegraph/scenegraphnode.h b/include/openspace/scenegraph/scenegraphnode.h index f7f4dfba0c..2dade38bb6 100644 --- a/include/openspace/scenegraph/scenegraphnode.h +++ b/include/openspace/scenegraph/scenegraphnode.h @@ -32,7 +32,7 @@ #include #include -#include +#include // std includes #include @@ -52,13 +52,13 @@ public: static SceneGraphNode* createFromDictionary(const ghoul::Dictionary& dictionary); - bool initialize(RuntimeData* runtimeData); + bool initialize(); bool deinitialize(); // essential - void update(); + void update(const UpdateData& data); void evaluate(const Camera* camera, const psc& parentPosition = psc()); - void render(const Camera* camera, const psc& parentPosition = psc()); + void render(const RenderData& data); // set & get void addNode(SceneGraphNode* child); @@ -88,7 +88,6 @@ private: std::vector _children; SceneGraphNode* _parent; Ephemeris* _ephemeris; - RuntimeData* _runtimeData; // renderable Renderable* _renderable; diff --git a/include/openspace/scenegraph/spiceephemeris.h b/include/openspace/scenegraph/spiceephemeris.h index 80780a66de..1d454cbc01 100644 --- a/include/openspace/scenegraph/spiceephemeris.h +++ b/include/openspace/scenegraph/spiceephemeris.h @@ -34,10 +34,10 @@ namespace openspace { class SpiceEphemeris : public Ephemeris { public: SpiceEphemeris(const ghoul::Dictionary& dictionary); - virtual ~SpiceEphemeris(); - virtual bool initialize(); - virtual const psc& position() const; - virtual void update(RuntimeData* runtimeData); + ~SpiceEphemeris(); + bool initialize(); + const psc& position() const; + void update(const UpdateData& data) override; private: std::string _targetName; @@ -45,8 +45,6 @@ private: int _target; int _origin; psc _position; - double _currentEphemerisTime = -1; - }; } // namespace openspace diff --git a/include/openspace/scenegraph/staticephemeris.h b/include/openspace/scenegraph/staticephemeris.h index 401fd1a329..82ed4f5710 100644 --- a/include/openspace/scenegraph/staticephemeris.h +++ b/include/openspace/scenegraph/staticephemeris.h @@ -35,7 +35,7 @@ public: = ghoul::Dictionary()); virtual ~StaticEphemeris(); virtual const psc& position() const; - virtual void update(RuntimeData* runtimeData); + virtual void update(const UpdateData& data) override; private: psc _position; }; diff --git a/include/openspace/util/constants.h b/include/openspace/util/constants.h index b34d6504c2..ee5035cc66 100644 --- a/include/openspace/util/constants.h +++ b/include/openspace/util/constants.h @@ -31,7 +31,6 @@ namespace openspace { namespace constants { namespace openspaceengine { const std::string keyPaths = "Paths"; - const std::string keyPathScene = "Paths.SCENEPATH"; const std::string keyConfigSgct = "SGCTConfig"; const std::string keyConfigScene = "Scene"; const std::string keyStartupScript = "StartupScripts"; @@ -39,6 +38,7 @@ namespace openspaceengine { } // namespace openspaceengine namespace scenegraph { + const std::string keyPathScene = "ScenePath"; const std::string keyModules = "Modules"; const std::string keyCamera = "Camera"; const std::string keyFocusObject = "Focus"; @@ -59,6 +59,7 @@ namespace renderable { namespace renderableplanet { const std::string keyGeometry = "Geometry"; + const std::string keyFrame = "Frame"; } // namespace renderableplanet namespace renderablestars { diff --git a/include/openspace/util/runtimedata.h b/include/openspace/util/runtimedata.h deleted file mode 100644 index 099b4424e0..0000000000 --- a/include/openspace/util/runtimedata.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef __RUNTIMEDATA_H__ -#define __RUNTIMEDATA_H__ - -enum increment{ - YEAR, MONTH, DAY, HOUR, MINUTE, SECOND, MILLISECOND -}; - -struct RuntimeData{ -public: - RuntimeData() :_openspaceTime(0.0){ - }; - void setTime(double time) { _openspaceTime = time; } - double getTime() { return _openspaceTime; } - - // cant come up with proper user friendly-method, this will do. - void advanceTimeBy(double nr, increment incr){ - switch (incr){ - case YEAR: _openspaceTime += (nr * year); break; - case MONTH: _openspaceTime += (nr * month); break; - case DAY: _openspaceTime += (nr * day); break; - case HOUR: _openspaceTime += (nr * hour); break; - case MINUTE: _openspaceTime += (nr * minute); break; - case MILLISECOND: _openspaceTime += (nr * millisec); break; - default : _openspaceTime += (nr); - } - } - -private: - double _openspaceTime; - - double year = 3.154*pow(10, 7); - double month = 2.628*pow(10, 6); - double day = 86400; - double hour = 3600; - double minute = 60; - double millisec = 0.001; -}; - -#endif // __RUNTIMEDATA_H__ diff --git a/include/openspace/util/updatestructures.h b/include/openspace/util/updatestructures.h new file mode 100644 index 0000000000..11590154d2 --- /dev/null +++ b/include/openspace/util/updatestructures.h @@ -0,0 +1,45 @@ +/***************************************************************************************** +* * +* OpenSpace * +* * +* Copyright (c) 2014 * +* * +* Permission is hereby granted, free of charge, to any person obtaining a copy of this * +* software and associated documentation files (the "Software"), to deal in the Software * +* without restriction, including without limitation the rights to use, copy, modify, * +* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * +* permit persons to whom the Software is furnished to do so, subject to the following * +* conditions: * +* * +* The above copyright notice and this permission notice shall be included in all copies * +* or substantial portions of the Software. * +* * +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * +* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * +* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * +* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * +* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * +* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * +****************************************************************************************/ + +#ifndef __UPDATESTRUCTURES_H__ +#define __UPDATESTRUCTURES_H__ + +#include +#include + +namespace openspace { + +struct UpdateData { + double time; +}; + +struct RenderData { + const Camera& camera; + psc position; + +}; + +} + +#endif // __UPDATESTRUCTURES_H__ diff --git a/openspace.cfg b/openspace.cfg index a476eed479..3a580bc567 100644 --- a/openspace.cfg +++ b/openspace.cfg @@ -6,14 +6,12 @@ return { SHADERS = "${BASE_PATH}/shaders", OPENSPACE_DATA = "${BASE_PATH}/openspace-data", TESTDIR = "${BASE_PATH}/src/tests", - SCENEPATH = "${OPENSPACE_DATA}/scene", - -- SCENEPATH = "${OPENSPACE_DATA}/ABufferVolumes", CONFIG = "${BASE_PATH}/config" }, SGCTConfig = "${SGCT}/single.xml", --SGCTConfig = "${SGCT}/two_nodes.xml", --SGCTConfig = "${SGCT}/single_sbs_stereo.xml", - Scene = "${SCENEPATH}/default.scene", + Scene = "${OPENSPACE_DATA}/scene/default.scene", SpiceTimeKernel = "${OPENSPACE_DATA}/spice/naif0010.tls", StartupScripts = { "${SCRIPTS}/default_startup.lua" diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index b9f68561ed..494b95039b 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -24,10 +24,6 @@ #include -// sgct header has to be included before all others due to Windows header -#define SGCT_WINDOWS_INCLUDE -#include "sgct.h" - #include #include #include @@ -37,7 +33,6 @@ #include #include #include -#include #include #include @@ -324,26 +319,11 @@ bool OpenSpaceEngine::initialize() OsEng.configurationManager().getValueSafe(constants::openspaceengine::keyConfigTimekernel, timeKernel); // initialize OpenSpace helpers - //Time::init(); - //Time::ref().setTime("2007 feb 26 17:41:00"); - //Time::ref().setTime("2010 jun 13 13:50:00"); - - - //std::cout <<"Initial time : " << initialData->getTime() << std::endl; - SpiceManager::initialize(); Time::initialize(timeKernel); Spice::init(); Spice::ref().loadDefaultKernels(); // changeto: instantiate spicemanager, load kernels. - RuntimeData* initialData = new RuntimeData; - initialData->setTime(Time::ref().currentTime()); - - //SpiceManager::ref().loadKernel(absPath("${OPENSPACE_DATA}/spice/de431_part-1.bsp"), "SPK_LARGE1"); - //SpiceManager::ref().loadKernel(absPath("${OPENSPACE_DATA}/spice/de431_part-2.bsp"), "SPK_LARGE2"); - - //SpiceManager::ref().loadKernel(absPath("${OPENSPACE_DATA}/spice/981005_PLTEPH-DE405S.bsp"), "JUPITER"); - SpiceManager::ref().loadKernel(absPath("${OPENSPACE_DATA}/spice/de430_1850-2150.bsp"), "SPK_EARTH"); SpiceManager::ref().loadKernel(absPath("${OPENSPACE_DATA}/spice/MAR063.bsp") , "SPK_MARS"); SpiceManager::ref().loadKernel(absPath("${OPENSPACE_DATA}/spice/pck00010.tpc") , "PCK"); @@ -363,36 +343,18 @@ bool OpenSpaceEngine::initialize() SceneGraph* sceneGraph = new SceneGraph; _renderEngine->setSceneGraph(sceneGraph); - std::string sceneDescriptionPath; - bool success = OsEng.configurationManager().getValueSafe( - constants::openspaceengine::keyConfigScene, sceneDescriptionPath); - if (!success) { - LFATAL("The configuration does not contain a scene file under key '" << - constants::openspaceengine::keyConfigScene << "'"); - return false; - } - - if (!FileSys.fileExists(sceneDescriptionPath)) { - LFATAL("Could not find scene description '" << sceneDescriptionPath << "'"); - return false; - } - - std::string scenePath; - success = _configurationManager->getValueSafe( - constants::openspaceengine::keyPathScene, scenePath); - if (!success) { - LFATAL("Could not find key '" << constants::openspaceengine::keyPathScene << - "' in configuration file '" << sceneDescriptionPath << "'"); - return false; - } // initialize the RenderEngine, needs ${SCENEPATH} to be set _renderEngine->initialize(); - _renderEngine->setRuntimeData(initialData); - sceneGraph->setRuntimeData(initialData); - sceneGraph->loadScene(sceneDescriptionPath, scenePath); sceneGraph->initialize(); + + std::string sceneDescriptionPath; + bool success = OsEng.configurationManager().getValueSafe( + constants::openspaceengine::keyConfigScene, sceneDescriptionPath); + if (success) + sceneGraph->scheduleLoadSceneFile(sceneDescriptionPath); + _renderEngine->setSceneGraph(sceneGraph); #ifdef FLARE_ONLY @@ -406,28 +368,24 @@ bool OpenSpaceEngine::initialize() _engine->_interactionHandler->connectDevices(); // Run start up scripts - //using ghoul::Dictionary; - //using constants::openspaceengine::keyStartupScript; ghoul::Dictionary scripts; success = _engine->configurationManager().getValueSafe( constants::openspaceengine::keyStartupScript, scripts); - if (success) { - for (size_t i = 0; i < scripts.size(); ++i) { - std::stringstream stream; - // Dictionary-size is 0-based; script numbers are 1-based - stream << (i + 1); - const std::string& key = stream.str(); - const bool hasKey = scripts.hasKeyAndValue(key); - if (!hasKey) { - LERROR("The startup scripts have to be declared in a simple array format"); - break; - } - - std::string scriptPath; - scripts.getValue(key, scriptPath); - std::string&& absoluteScriptPath = absPath(scriptPath); - _engine->scriptEngine().runScriptFile(absoluteScriptPath); + for (size_t i = 1; i <= scripts.size(); ++i) { + std::stringstream stream; + stream << i; + const std::string& key = stream.str(); + const bool hasKey = scripts.hasKeyAndValue(key); + if (!hasKey) { + LERROR("The startup scripts have to be declared in a simple array format." + " Startup scripts did not contain the key '" << key << "'"); + break; } + + std::string scriptPath; + scripts.getValue(key, scriptPath); + std::string&& absoluteScriptPath = absPath(scriptPath); + _engine->scriptEngine().runScriptFile(absoluteScriptPath); } #ifdef OPENSPACE_VIDEO_EXPORT @@ -545,8 +503,6 @@ void OpenSpaceEngine::keyboardCallback(int key, int action) _interactionHandler->keyboardCallback(key, action); } #ifdef OPENSPACE_VIDEO_EXPORT - // LDEBUG("key: " << key); - // LDEBUG("SGCT_KEY_PRINT_SCREEN: " << SGCT_KEY_PRINT_SCREEN); if(action == SGCT_PRESS && key == SGCT_KEY_PRINT_SCREEN) _doVideoExport = !_doVideoExport; #endif @@ -577,32 +533,32 @@ void OpenSpaceEngine::mouseScrollWheelCallback(int pos) void OpenSpaceEngine::encode() { -#ifdef FLARE_ONLY - _flare->encode(); -#else - std::vector dataStream(1024); - - size_t offset = 0; - // serialization - _renderEngine->serialize(dataStream, offset); - - _synchronizationBuffer.setVal(dataStream); - sgct::SharedData::instance()->writeVector(&_synchronizationBuffer); -#endif +//#ifdef FLARE_ONLY +// _flare->encode(); +//#else +// std::vector dataStream(1024); +// +// size_t offset = 0; +// // serialization +// _renderEngine->serialize(dataStream, offset); +// +// _synchronizationBuffer.setVal(dataStream); +// sgct::SharedData::instance()->writeVector(&_synchronizationBuffer); +//#endif } void OpenSpaceEngine::decode() { -#ifdef FLARE_ONLY - _flare->decode(); -#else - sgct::SharedData::instance()->readVector(&_synchronizationBuffer); - std::vector dataStream = std::move(_synchronizationBuffer.getVal()); - size_t offset = 0; - - // deserialize in the same order as done in serialization - _renderEngine->deserialize(dataStream, offset); -#endif +//#ifdef FLARE_ONLY +// _flare->decode(); +//#else +// sgct::SharedData::instance()->readVector(&_synchronizationBuffer); +// std::vector dataStream = std::move(_synchronizationBuffer.getVal()); +// size_t offset = 0; +// +// // deserialize in the same order as done in serialization +// _renderEngine->deserialize(dataStream, offset); +//#endif } void OpenSpaceEngine::externalControlCallback(const char* receivedChars, diff --git a/src/flare/flare.cpp b/src/flare/flare.cpp index fba50f8095..73bd2f8fc6 100644 --- a/src/flare/flare.cpp +++ b/src/flare/flare.cpp @@ -1,449 +1,452 @@ -#include - -#include - -#include -#include -#include -#include -#include -#include - -#include - -#include - -#include -#include -#include -#include - -namespace { - std::string _loggerCat = "Flare"; -} - -namespace openspace { -using namespace osp; - -Flare::Flare() - : Renderable(ghoul::Dictionary()) - , _oldTime(0.f) - , _currentTime(0.f) - , _leftMouseButton(false) - , _currentMouseX(0) - , _currentMouseY(0) - , _lastMouseX(0) - , _lastMouseY(0) -{ - setBoundingSphere(PowerScaledScalar::CreatePSS(sqrt(3.0f))); -} - -Flare::~Flare() { - // Clean up like a good citizen - delete _config; - delete _raycaster; - delete _animator; -} - -void exit_msg(std::string m) { - LDEBUG(m); - exit(1); -} - - -bool Flare::initialize() { - init(); - return true; -} -bool Flare::deinitialize() { - return true; -} - -void Flare::render(const Camera *camera, const psc& thisPosition, RuntimeData* runtimeData) { - render(); -} -void Flare::update() { - -} - -void Flare::render() { - // Sync timestep - //unsigned int ts = static_cast(_timeStep.getVal()); - //LDEBUG("ts: " << ts); - // Reload config if flag is set - if (_reloadFlag.getVal()) _raycaster->Reload(); - - // Set model and view params - _raycaster->SetModelParams(_pitch.getVal(), - _yaw.getVal(), - _roll.getVal()); - _raycaster->SetViewParams(_translateX.getVal(), - _translateY.getVal(), - _translateZ.getVal()); - // Render - if (!_raycaster->Render(_elapsedTime.getVal())) { - LDEBUG("!_raycaster->Render(_elapsedTime.getVal())"); - exit(1); - } - - // Save screenshot - if (_config->TakeScreenshot()) sgct::Engine::instance()->takeScreenshot(); - - // Update animator with synchronized time - _animator->SetPaused(_animationPaused.getVal()); - _animator->SetFPSMode(_fpsMode.getVal()); - _animator->Update(_elapsedTime.getVal()); - _animator->ManualTimestep(_manualTimestep.getVal()); -} - -void Flare::initNavigation() { - _animationPaused.setVal(false); - _reloadFlag.setVal(false); - - // FPS mode should be OFF for cluster syncing - _fpsMode.setVal(true); - _manualTimestep.setVal(0); - - // Read initial values from config - _pitch.setVal(_config->StartPitch()); - _yaw.setVal(_config->StartYaw()); - _roll.setVal(_config->StartRoll()); - - _translateX.setVal(_config->TranslateX()); - _translateY.setVal(_config->TranslateY()); - _translateZ.setVal(_config->TranslateZ()); -} - -void Flare::init() { - // Start with reading a config file - _config = Config::New(absPath("${CONFIG}/flareConfig.txt")); - if (!_config) { - LDEBUG("!_Config"); - exit(1); - } - - initNavigation(); - _reloadFlag.setVal(false); - - // Get the viewport coordinates from OpenGL - GLint currentViewPort[4]; - glGetIntegerv( GL_VIEWPORT, currentViewPort); - - // Make sure texture width/height and global kernel worksizes are - // multiples of the local worksize - - // Window dimensions - unsigned int width = currentViewPort[2] - currentViewPort[0]; - unsigned int height = currentViewPort[3] - currentViewPort[1]; - unsigned int xFactor = width/_config->LocalWorkSizeX(); - unsigned int yFactor = height/_config->LocalWorkSizeY(); - width = xFactor * _config->LocalWorkSizeX(); - height = yFactor * _config->LocalWorkSizeY(); - width /= _config->TextureDivisionFactor(); - height /= _config->TextureDivisionFactor(); - - - // Create TSP structure from file - TSP *tsp = TSP::New(_config); - if (!tsp->ReadHeader()) { - LDEBUG("!tsp->ReadHeader()"); - exit(1); - } - // Read cache if it exists, calculate otherwise - if (tsp->ReadCache()) { - INFO("\nUsing cached TSP file"); - } else { - INFO("\nNo cached TSP file found"); - if (!tsp->Construct()) { - LDEBUG("!tsp->Construct()"); - exit(1); - } - if (_config->CalculateError() == 0) { - INFO("Not calculating errors"); - } else { - if (!tsp->CalculateSpatialError()) { - LDEBUG("!tsp->CalculateSpatialError()"); - exit(1); - } - if (!tsp->CalculateTemporalError()) { - LDEBUG("!tsp->CalculateTemporalError()"); - exit(1); - } - if (!tsp->WriteCache()) { - LDEBUG("!tsp->WriteCache()"); - exit(1); - } - } - } - - // Create brick manager and init (has to be done after init OpenGL!) - BrickManager *brickManager= BrickManager::New(_config); - if (!brickManager->ReadHeader()) { - LDEBUG("!brickManager->ReadHeader()"); - exit(1); - } - if (!brickManager->InitAtlas()) { - LDEBUG("!brickManager->InitAtlas()"); - exit(1); - } - - using ghoul::opengl::ShaderObject; - using ghoul::opengl::ProgramObject; - - ProgramObject* cubeShaderProgram = nullptr; - ShaderObject* cubeShaderProgram_vs = new ShaderObject(ShaderObject::ShaderType::ShaderTypeVertex, - _config->CubeShaderVertFilename(), - "cubeShaderProgram_vs" - ); - ShaderObject* cubeShaderProgram_fs = new ShaderObject(ShaderObject::ShaderType::ShaderTypeFragment, - _config->CubeShaderFragFilename(), - "cubeShaderProgram_fs" - ); - - cubeShaderProgram = new ProgramObject; - cubeShaderProgram->attachObject(cubeShaderProgram_vs); - cubeShaderProgram->attachObject(cubeShaderProgram_fs); - - if( ! cubeShaderProgram->compileShaderObjects()) - LDEBUG("Could not compile cubeShaderProgram"); - if( ! cubeShaderProgram->linkProgramObject()) - LDEBUG("Could not link cubeShaderProgram"); - - ProgramObject* quadShaderProgram = nullptr; - ShaderObject* quadShaderProgram_vs = new ShaderObject(ShaderObject::ShaderType::ShaderTypeVertex, - _config->QuadShaderVertFilename(), - "quadShaderProgram_vs" - ); - ShaderObject* quadShaderProgram_fs = new ShaderObject(ShaderObject::ShaderType::ShaderTypeFragment, - _config->QuadShaderFragFilename(), - "quadShaderProgram_fs" - ); - - quadShaderProgram = new ProgramObject; - quadShaderProgram->attachObject(quadShaderProgram_vs); - quadShaderProgram->attachObject(quadShaderProgram_fs); - - if( ! quadShaderProgram->compileShaderObjects()) - LDEBUG("Could not compile quadShaderProgram"); - if( ! quadShaderProgram->linkProgramObject()) - LDEBUG("Could not link quadShaderProgram"); - - // Create shaders for color cube and output textured quad - /* - ShaderProgram *cubeShaderProgram = ShaderProgram::New(); - cubeShaderProgram->CreateShader(ShaderProgram::VERTEX, - _config->CubeShaderVertFilename()); - cubeShaderProgram->CreateShader(ShaderProgram::FRAGMENT, - _config->CubeShaderFragFilename()); - cubeShaderProgram->CreateProgram(); - - ShaderProgram *quadShaderProgram = ShaderProgram::New(); - quadShaderProgram->CreateShader(ShaderProgram::VERTEX, - _config->QuadShaderVertFilename()); - quadShaderProgram->CreateShader(ShaderProgram::FRAGMENT, - _config->QuadShaderFragFilename()); - quadShaderProgram->CreateProgram(); - */ - - // Create two textures to hold the color cube - std::vector dimensions(2); - dimensions[0] = width; - dimensions[1] = height; - ghoul::opengl::Texture* cubeFrontTex = new ghoul::opengl::Texture(glm::size3_t(width, height, 1), - ghoul::opengl::Texture::Format::RGBA, GL_RGBA, GL_FLOAT); - cubeFrontTex->uploadTexture(); - ghoul::opengl::Texture* cubeBackTex = new ghoul::opengl::Texture(glm::size3_t(width, height, 1), - ghoul::opengl::Texture::Format::RGBA, GL_RGBA, GL_FLOAT); - cubeBackTex->uploadTexture(); - /* - Texture2D *cubeFrontTex = Texture2D::New(dimensions); - Texture2D *cubeBackTex = Texture2D::New(dimensions); - cubeFrontTex->Init(); - cubeBackTex->Init(); -*/ - // Create an output texture to write to - ghoul::opengl::Texture* quadTex = new ghoul::opengl::Texture(glm::size3_t(width, height, 1), - ghoul::opengl::Texture::Format::RGBA, GL_RGBA, GL_FLOAT); - quadTex->uploadTexture(); - - //Texture2D *quadTex = Texture2D::New(dimensions); - //quadTex->Init(); - - // Create transfer functions - TransferFunction *transferFunction = TransferFunction::New(); - transferFunction->SetInFilename(_config->TFFilename()); - if (!transferFunction->ReadFile()) exit_msg("!transferFunction->ReadFile()"); - if (!transferFunction->ConstructTexture()) exit_msg("!transferFunction->ConstructTexture()"); - - - // Create animator - _animator = Animator::New(_config); - // Use original (not adjusted) number of timesteps for animator - _animator->SetNumTimesteps(brickManager->NumOrigTimesteps()); - - // Create CL manager - CLManager *clManager = CLManager::New(); - - // Set up the raycaster - _raycaster = Raycaster::New(_config); - _raycaster->SetWinWidth(width); - _raycaster->SetWinHeight(height); - if (!_raycaster->InitCube()) exit_msg("!_raycaster->InitCube()"); - if (!_raycaster->InitQuad()) exit_msg("!_raycaster->InitQuad()"); - _raycaster->SetBrickManager(brickManager); - _raycaster->SetCubeFrontTexture(cubeFrontTex); - _raycaster->SetCubeBackTexture(cubeBackTex); - _raycaster->SetQuadTexture(quadTex); - _raycaster->SetCubeShaderProgram(cubeShaderProgram); - _raycaster->SetQuadShaderProgram(quadShaderProgram); - if (!_raycaster->InitFramebuffers()) exit_msg("!_raycaster->InitFramebuffers()"); - _raycaster->SetAnimator(_animator); - _raycaster->AddTransferFunction(transferFunction); - - // Tie CL manager to renderer - _raycaster->SetCLManager(clManager); - _raycaster->SetTSP(tsp); - - if (!_raycaster->InitCL()) exit_msg("!_raycaster->InitCL()"); - if (!_raycaster->InitPipeline()) exit_msg("!_raycaster->InitCL()"); -} - -void Flare::keyboard(int key, int action) { - if (action == GLFW_PRESS) { - switch(key) { - case 32: // space bar - // Toggle animation paused - INFO("Pausing"); - _animationPaused.setVal(!_animationPaused.getVal()); - break; - case 'Z': - case 'z': - // Decrease timestep - // NOTE: Can't decrease timestep with double buffered approach atm - //manualTimestep_.setVal(-1); - break; - case 'X': - case 'x': - // Increase timestep - _manualTimestep.setVal(1); - break; - case 'D': - case 'd': - _translateX.setVal(_translateX.getVal() + _config->ZoomFactor()); - break; - case 'A': - case 'a': - _translateX.setVal(_translateX.getVal() - _config->ZoomFactor()); - break; - case 'W': - case 'w': - _translateY.setVal(_translateY.getVal() + _config->ZoomFactor()); - break; - case 'S': - case 's': - _translateY.setVal(_translateY.getVal() - _config->ZoomFactor()); - break; - case 'Q': - case 'q': - _translateZ.setVal(_translateZ.getVal() + _config->ZoomFactor()); - break; - case 'E': - case 'e': - _translateZ.setVal(_translateZ.getVal() - _config->ZoomFactor()); - break; - case 'R': - case 'r': - _reloadFlag.setVal(true); - break; - case 'F': - case 'f': - _fpsMode.setVal(!_fpsMode.getVal()); - if (_fpsMode.getVal()) { - INFO("Updating animation ASAP"); - } else { - INFO("Using refresh interval variable"); - } - break; - } - } -} - -void Flare::mouse(int button, int action) { - switch (button) { - case GLFW_MOUSE_BUTTON_LEFT: - _leftMouseButton = (action == GLFW_PRESS) ? true : false; - std::size_t winId = sgct::Engine::instance()->getActiveWindowPtr()->getId(); - sgct::Engine::getMousePos(winId, &_lastMouseX, &_lastMouseY); - } -} - -void Flare::preSync() { - // Update time - _oldTime = _currentTime; - _currentTime = static_cast(sgct::Engine::getTime()); - _elapsedTime.setVal(_currentTime - _oldTime); - _timeStep.setVal(_animator->CurrentTimestep()); - - // Update automatic model transform - if (!_animationPaused.getVal()) { - _pitch.setVal(_pitch.getVal() + _config->PitchSpeed()); - _roll.setVal(_roll.getVal() + _config->RollSpeed()); - _yaw.setVal(_yaw.getVal() + _config->YawSpeed()); - } - - // Update mouse - if (_leftMouseButton) { - std::size_t winId = sgct::Engine::instance()->getActiveWindowPtr()->getId(); - sgct::Engine::getMousePos(winId ,&_currentMouseX, &_currentMouseY); - _pitch.setVal(_pitch.getVal() + _config->MousePitchFactor() * - static_cast(_currentMouseX-_lastMouseX)); - _roll.setVal(_roll.getVal() + _config->MouseRollFactor() * - static_cast(_currentMouseY-_lastMouseY)); - } -} - -void Flare::postSyncPreDraw() { - _animator->SetCurrentTimestep(static_cast(_timeStep.getVal())); -} - -void Flare::postDraw() { - // Reset manual timestep - _manualTimestep.setVal(0); - - // Reset reload flag - _reloadFlag.setVal(false); -} - -void Flare::encode() { - sgct::SharedData::instance()->writeInt(&_timeStep); - sgct::SharedData::instance()->writeBool(&_animationPaused); - sgct::SharedData::instance()->writeBool(&_fpsMode); - sgct::SharedData::instance()->writeFloat(&_elapsedTime); - sgct::SharedData::instance()->writeInt(&_manualTimestep); - sgct::SharedData::instance()->writeFloat(&_pitch); - sgct::SharedData::instance()->writeFloat(&_yaw); - sgct::SharedData::instance()->writeFloat(&_roll); - sgct::SharedData::instance()->writeFloat(&_translateX); - sgct::SharedData::instance()->writeFloat(&_translateY); - sgct::SharedData::instance()->writeFloat(&_translateZ); - sgct::SharedData::instance()->writeBool(&_reloadFlag); -} - -void Flare::decode() { - sgct::SharedData::instance()->readInt(&_timeStep); - sgct::SharedData::instance()->readBool(&_animationPaused); - sgct::SharedData::instance()->readBool(&_fpsMode); - sgct::SharedData::instance()->readFloat(&_elapsedTime); - sgct::SharedData::instance()->readInt(&_manualTimestep); - sgct::SharedData::instance()->readFloat(&_pitch); - sgct::SharedData::instance()->readFloat(&_yaw); - sgct::SharedData::instance()->readFloat(&_roll); - sgct::SharedData::instance()->readFloat(&_translateX); - sgct::SharedData::instance()->readFloat(&_translateY); - sgct::SharedData::instance()->readFloat(&_translateZ); - sgct::SharedData::instance()->readBool(&_reloadFlag); -} - -} // namespace openspace +// The source is still in here to be cannibalized later (ab) +//#include +// +//#include +// +//#include +//#include +//#include +//#include +//#include +//#include +// +//#include +// +//#include +// +//#include +//#include +//#include +//#include +// +//namespace { +// std::string _loggerCat = "Flare"; +//} +// +//namespace openspace { +//using namespace osp; +// +//Flare::Flare() +// : Renderable(ghoul::Dictionary()) +// , _oldTime(0.f) +// , _currentTime(0.f) +// , _leftMouseButton(false) +// , _currentMouseX(0) +// , _currentMouseY(0) +// , _lastMouseX(0) +// , _lastMouseY(0) +//{ +// setBoundingSphere(PowerScaledScalar::CreatePSS(sqrt(3.0f))); +//} +// +//Flare::~Flare() { +// // Clean up like a good citizen +// delete _config; +// delete _raycaster; +// delete _animator; +//} +// +//void exit_msg(std::string m) { +// LDEBUG(m); +// exit(1); +//} +// +// +//bool Flare::initialize() { +// init(); +// return true; +//} +//bool Flare::deinitialize() { +// return true; +//} +// +//void Flare::render(const Camera *camera, const psc& thisPosition, RuntimeData* runtimeData) { +// render(); +//} +//void Flare::update() { +// +//} +// +//void Flare::render() { +// // Sync timestep +// //unsigned int ts = static_cast(_timeStep.getVal()); +// //LDEBUG("ts: " << ts); +// // Reload config if flag is set +// if (_reloadFlag.getVal()) _raycaster->Reload(); +// +// // Set model and view params +// _raycaster->SetModelParams(_pitch.getVal(), +// _yaw.getVal(), +// _roll.getVal()); +// _raycaster->SetViewParams(_translateX.getVal(), +// _translateY.getVal(), +// _translateZ.getVal()); +// // Render +// if (!_raycaster->Render(_elapsedTime.getVal())) { +// LDEBUG("!_raycaster->Render(_elapsedTime.getVal())"); +// exit(1); +// } +// +// // Save screenshot +// if (_config->TakeScreenshot()) sgct::Engine::instance()->takeScreenshot(); +// +// // Update animator with synchronized time +// _animator->SetPaused(_animationPaused.getVal()); +// _animator->SetFPSMode(_fpsMode.getVal()); +// _animator->Update(_elapsedTime.getVal()); +// _animator->ManualTimestep(_manualTimestep.getVal()); +//} +// +//void Flare::initNavigation() { +// _animationPaused.setVal(false); +// _reloadFlag.setVal(false); +// +// // FPS mode should be OFF for cluster syncing +// _fpsMode.setVal(true); +// _manualTimestep.setVal(0); +// +// // Read initial values from config +// _pitch.setVal(_config->StartPitch()); +// _yaw.setVal(_config->StartYaw()); +// _roll.setVal(_config->StartRoll()); +// +// _translateX.setVal(_config->TranslateX()); +// _translateY.setVal(_config->TranslateY()); +// _translateZ.setVal(_config->TranslateZ()); +//} +// +//void Flare::init() { +// // Start with reading a config file +// _config = Config::New(absPath("${CONFIG}/flareConfig.txt")); +// if (!_config) { +// LDEBUG("!_Config"); +// exit(1); +// } +// +// initNavigation(); +// _reloadFlag.setVal(false); +// +// // Get the viewport coordinates from OpenGL +// GLint currentViewPort[4]; +// glGetIntegerv( GL_VIEWPORT, currentViewPort); +// +// // Make sure texture width/height and global kernel worksizes are +// // multiples of the local worksize +// +// // Window dimensions +// unsigned int width = currentViewPort[2] - currentViewPort[0]; +// unsigned int height = currentViewPort[3] - currentViewPort[1]; +// unsigned int xFactor = width/_config->LocalWorkSizeX(); +// unsigned int yFactor = height/_config->LocalWorkSizeY(); +// width = xFactor * _config->LocalWorkSizeX(); +// height = yFactor * _config->LocalWorkSizeY(); +// width /= _config->TextureDivisionFactor(); +// height /= _config->TextureDivisionFactor(); +// +// +// // Create TSP structure from file +// TSP *tsp = TSP::New(_config); +// if (!tsp->ReadHeader()) { +// LDEBUG("!tsp->ReadHeader()"); +// exit(1); +// } +// // Read cache if it exists, calculate otherwise +// if (tsp->ReadCache()) { +// INFO("\nUsing cached TSP file"); +// } else { +// INFO("\nNo cached TSP file found"); +// if (!tsp->Construct()) { +// LDEBUG("!tsp->Construct()"); +// exit(1); +// } +// if (_config->CalculateError() == 0) { +// INFO("Not calculating errors"); +// } else { +// if (!tsp->CalculateSpatialError()) { +// LDEBUG("!tsp->CalculateSpatialError()"); +// exit(1); +// } +// if (!tsp->CalculateTemporalError()) { +// LDEBUG("!tsp->CalculateTemporalError()"); +// exit(1); +// } +// if (!tsp->WriteCache()) { +// LDEBUG("!tsp->WriteCache()"); +// exit(1); +// } +// } +// } +// +// // Create brick manager and init (has to be done after init OpenGL!) +// BrickManager *brickManager= BrickManager::New(_config); +// if (!brickManager->ReadHeader()) { +// LDEBUG("!brickManager->ReadHeader()"); +// exit(1); +// } +// if (!brickManager->InitAtlas()) { +// LDEBUG("!brickManager->InitAtlas()"); +// exit(1); +// } +// +// using ghoul::opengl::ShaderObject; +// using ghoul::opengl::ProgramObject; +// +// ProgramObject* cubeShaderProgram = nullptr; +// ShaderObject* cubeShaderProgram_vs = new ShaderObject(ShaderObject::ShaderType::ShaderTypeVertex, +// _config->CubeShaderVertFilename(), +// "cubeShaderProgram_vs" +// ); +// ShaderObject* cubeShaderProgram_fs = new ShaderObject(ShaderObject::ShaderType::ShaderTypeFragment, +// _config->CubeShaderFragFilename(), +// "cubeShaderProgram_fs" +// ); +// +// cubeShaderProgram = new ProgramObject; +// cubeShaderProgram->attachObject(cubeShaderProgram_vs); +// cubeShaderProgram->attachObject(cubeShaderProgram_fs); +// +// if( ! cubeShaderProgram->compileShaderObjects()) +// LDEBUG("Could not compile cubeShaderProgram"); +// if( ! cubeShaderProgram->linkProgramObject()) +// LDEBUG("Could not link cubeShaderProgram"); +// +// ProgramObject* quadShaderProgram = nullptr; +// ShaderObject* quadShaderProgram_vs = new ShaderObject(ShaderObject::ShaderType::ShaderTypeVertex, +// _config->QuadShaderVertFilename(), +// "quadShaderProgram_vs" +// ); +// ShaderObject* quadShaderProgram_fs = new ShaderObject(ShaderObject::ShaderType::ShaderTypeFragment, +// _config->QuadShaderFragFilename(), +// "quadShaderProgram_fs" +// ); +// +// quadShaderProgram = new ProgramObject; +// quadShaderProgram->attachObject(quadShaderProgram_vs); +// quadShaderProgram->attachObject(quadShaderProgram_fs); +// +// if( ! quadShaderProgram->compileShaderObjects()) +// LDEBUG("Could not compile quadShaderProgram"); +// if( ! quadShaderProgram->linkProgramObject()) +// LDEBUG("Could not link quadShaderProgram"); +// +// // Create shaders for color cube and output textured quad +// /* +// ShaderProgram *cubeShaderProgram = ShaderProgram::New(); +// cubeShaderProgram->CreateShader(ShaderProgram::VERTEX, +// _config->CubeShaderVertFilename()); +// cubeShaderProgram->CreateShader(ShaderProgram::FRAGMENT, +// _config->CubeShaderFragFilename()); +// cubeShaderProgram->CreateProgram(); +// +// ShaderProgram *quadShaderProgram = ShaderProgram::New(); +// quadShaderProgram->CreateShader(ShaderProgram::VERTEX, +// _config->QuadShaderVertFilename()); +// quadShaderProgram->CreateShader(ShaderProgram::FRAGMENT, +// _config->QuadShaderFragFilename()); +// quadShaderProgram->CreateProgram(); +// */ +// +// // Create two textures to hold the color cube +// std::vector dimensions(2); +// dimensions[0] = width; +// dimensions[1] = height; +// ghoul::opengl::Texture* cubeFrontTex = new ghoul::opengl::Texture(glm::size3_t(width, height, 1), +// ghoul::opengl::Texture::Format::RGBA, GL_RGBA, GL_FLOAT); +// cubeFrontTex->uploadTexture(); +// ghoul::opengl::Texture* cubeBackTex = new ghoul::opengl::Texture(glm::size3_t(width, height, 1), +// ghoul::opengl::Texture::Format::RGBA, GL_RGBA, GL_FLOAT); +// cubeBackTex->uploadTexture(); +// /* +// Texture2D *cubeFrontTex = Texture2D::New(dimensions); +// Texture2D *cubeBackTex = Texture2D::New(dimensions); +// cubeFrontTex->Init(); +// cubeBackTex->Init(); +//*/ +// // Create an output texture to write to +// ghoul::opengl::Texture* quadTex = new ghoul::opengl::Texture(glm::size3_t(width, height, 1), +// ghoul::opengl::Texture::Format::RGBA, GL_RGBA, GL_FLOAT); +// quadTex->uploadTexture(); +// +// //Texture2D *quadTex = Texture2D::New(dimensions); +// //quadTex->Init(); +// +// // Create transfer functions +// TransferFunction *transferFunction = TransferFunction::New(); +// transferFunction->SetInFilename(_config->TFFilename()); +// if (!transferFunction->ReadFile()) exit_msg("!transferFunction->ReadFile()"); +// if (!transferFunction->ConstructTexture()) exit_msg("!transferFunction->ConstructTexture()"); +// +// +// // Create animator +// _animator = Animator::New(_config); +// // Use original (not adjusted) number of timesteps for animator +// _animator->SetNumTimesteps(brickManager->NumOrigTimesteps()); +// +// // Create CL manager +// CLManager *clManager = CLManager::New(); +// +// // Set up the raycaster +// _raycaster = Raycaster::New(_config); +// _raycaster->SetWinWidth(width); +// _raycaster->SetWinHeight(height); +// if (!_raycaster->InitCube()) exit_msg("!_raycaster->InitCube()"); +// if (!_raycaster->InitQuad()) exit_msg("!_raycaster->InitQuad()"); +// _raycaster->SetBrickManager(brickManager); +// _raycaster->SetCubeFrontTexture(cubeFrontTex); +// _raycaster->SetCubeBackTexture(cubeBackTex); +// _raycaster->SetQuadTexture(quadTex); +// _raycaster->SetCubeShaderProgram(cubeShaderProgram); +// _raycaster->SetQuadShaderProgram(quadShaderProgram); +// if (!_raycaster->InitFramebuffers()) exit_msg("!_raycaster->InitFramebuffers()"); +// _raycaster->SetAnimator(_animator); +// _raycaster->AddTransferFunction(transferFunction); +// +// // Tie CL manager to renderer +// _raycaster->SetCLManager(clManager); +// _raycaster->SetTSP(tsp); +// +// if (!_raycaster->InitCL()) exit_msg("!_raycaster->InitCL()"); +// if (!_raycaster->InitPipeline()) exit_msg("!_raycaster->InitCL()"); +//} +// +//void Flare::keyboard(int key, int action) { +// if (action == GLFW_PRESS) { +// switch(key) { +// case 32: // space bar +// // Toggle animation paused +// INFO("Pausing"); +// _animationPaused.setVal(!_animationPaused.getVal()); +// break; +// case 'Z': +// case 'z': +// // Decrease timestep +// // NOTE: Can't decrease timestep with double buffered approach atm +// //manualTimestep_.setVal(-1); +// break; +// case 'X': +// case 'x': +// // Increase timestep +// _manualTimestep.setVal(1); +// break; +// case 'D': +// case 'd': +// _translateX.setVal(_translateX.getVal() + _config->ZoomFactor()); +// break; +// case 'A': +// case 'a': +// _translateX.setVal(_translateX.getVal() - _config->ZoomFactor()); +// break; +// case 'W': +// case 'w': +// _translateY.setVal(_translateY.getVal() + _config->ZoomFactor()); +// break; +// case 'S': +// case 's': +// _translateY.setVal(_translateY.getVal() - _config->ZoomFactor()); +// break; +// case 'Q': +// case 'q': +// _translateZ.setVal(_translateZ.getVal() + _config->ZoomFactor()); +// break; +// case 'E': +// case 'e': +// _translateZ.setVal(_translateZ.getVal() - _config->ZoomFactor()); +// break; +// case 'R': +// case 'r': +// _reloadFlag.setVal(true); +// break; +// case 'F': +// case 'f': +// _fpsMode.setVal(!_fpsMode.getVal()); +// if (_fpsMode.getVal()) { +// INFO("Updating animation ASAP"); +// } else { +// INFO("Using refresh interval variable"); +// } +// break; +// } +// } +//} +// +//void Flare::mouse(int button, int action) { +// switch (button) { +// case GLFW_MOUSE_BUTTON_LEFT: +// _leftMouseButton = (action == GLFW_PRESS) ? true : false; +// std::size_t winId = sgct::Engine::instance()->getActiveWindowPtr()->getId(); +// sgct::Engine::getMousePos(winId, &_lastMouseX, &_lastMouseY); +// } +//} +// +//void Flare::preSync() { +// // Update time +// _oldTime = _currentTime; +// _currentTime = static_cast(sgct::Engine::getTime()); +// _elapsedTime.setVal(_currentTime - _oldTime); +// _timeStep.setVal(_animator->CurrentTimestep()); +// +// // Update automatic model transform +// if (!_animationPaused.getVal()) { +// _pitch.setVal(_pitch.getVal() + _config->PitchSpeed()); +// _roll.setVal(_roll.getVal() + _config->RollSpeed()); +// _yaw.setVal(_yaw.getVal() + _config->YawSpeed()); +// } +// +// // Update mouse +// if (_leftMouseButton) { +// std::size_t winId = sgct::Engine::instance()->getActiveWindowPtr()->getId(); +// sgct::Engine::getMousePos(winId ,&_currentMouseX, &_currentMouseY); +// _pitch.setVal(_pitch.getVal() + _config->MousePitchFactor() * +// static_cast(_currentMouseX-_lastMouseX)); +// _roll.setVal(_roll.getVal() + _config->MouseRollFactor() * +// static_cast(_currentMouseY-_lastMouseY)); +// } +//} +// +//void Flare::postSyncPreDraw() { +// _animator->SetCurrentTimestep(static_cast(_timeStep.getVal())); +//} +// +//void Flare::postDraw() { +// // Reset manual timestep +// _manualTimestep.setVal(0); +// +// // Reset reload flag +// _reloadFlag.setVal(false); +//} +// +//void Flare::encode() { +// sgct::SharedData::instance()->writeInt(&_timeStep); +// sgct::SharedData::instance()->writeBool(&_animationPaused); +// sgct::SharedData::instance()->writeBool(&_fpsMode); +// sgct::SharedData::instance()->writeFloat(&_elapsedTime); +// sgct::SharedData::instance()->writeInt(&_manualTimestep); +// sgct::SharedData::instance()->writeFloat(&_pitch); +// sgct::SharedData::instance()->writeFloat(&_yaw); +// sgct::SharedData::instance()->writeFloat(&_roll); +// sgct::SharedData::instance()->writeFloat(&_translateX); +// sgct::SharedData::instance()->writeFloat(&_translateY); +// sgct::SharedData::instance()->writeFloat(&_translateZ); +// sgct::SharedData::instance()->writeBool(&_reloadFlag); +//} +// +//void Flare::decode() { +// sgct::SharedData::instance()->readInt(&_timeStep); +// sgct::SharedData::instance()->readBool(&_animationPaused); +// sgct::SharedData::instance()->readBool(&_fpsMode); +// sgct::SharedData::instance()->readFloat(&_elapsedTime); +// sgct::SharedData::instance()->readInt(&_manualTimestep); +// sgct::SharedData::instance()->readFloat(&_pitch); +// sgct::SharedData::instance()->readFloat(&_yaw); +// sgct::SharedData::instance()->readFloat(&_roll); +// sgct::SharedData::instance()->readFloat(&_translateX); +// sgct::SharedData::instance()->readFloat(&_translateY); +// sgct::SharedData::instance()->readFloat(&_translateZ); +// sgct::SharedData::instance()->readBool(&_reloadFlag); +//} +// +//} // namespace openspace +// +// diff --git a/src/properties/propertyowner.cpp b/src/properties/propertyowner.cpp index 2b1986ce1d..6c626c035e 100644 --- a/src/properties/propertyowner.cpp +++ b/src/properties/propertyowner.cpp @@ -51,11 +51,7 @@ PropertyOwner::PropertyOwner() PropertyOwner::~PropertyOwner() { - for (Property* p : _properties) - delete p; _properties.clear(); - for (PropertyOwner* s : _subOwners) - delete s; _subOwners.clear(); } diff --git a/src/rendering/planets/renderableplanet.cpp b/src/rendering/planets/renderableplanet.cpp index 6677563d8e..8b6cc755e1 100644 --- a/src/rendering/planets/renderableplanet.cpp +++ b/src/rendering/planets/renderableplanet.cpp @@ -68,7 +68,7 @@ RenderablePlanet::RenderablePlanet(const ghoul::Dictionary& dictionary) = planetgeometry::PlanetGeometry::createFromDictionary(geometryDictionary); } - dictionary.getValue("Frame", _target); + dictionary.getValue(constants::renderableplanet::keyFrame, _target); // TODO: textures need to be replaced by a good system similar to the geometry as soon // as the requirements are fixed (ab) @@ -113,7 +113,7 @@ bool RenderablePlanet::deinitialize() return true; } -void RenderablePlanet::render(const Camera* camera, const psc& thisPosition, RuntimeData* runtimeData) +void RenderablePlanet::render(const RenderData& data) { if (!_programObject) return; @@ -124,9 +124,9 @@ void RenderablePlanet::render(const Camera* camera, const psc& thisPosition, Run _programObject->activate(); // fetch data - psc currentPosition = thisPosition; - psc campos = camera->position(); - glm::mat4 camrot = camera->viewRotationMatrix(); + psc currentPosition = data.position; + psc campos = data.camera.position(); + glm::mat4 camrot = data.camera.viewRotationMatrix(); // PowerScaledScalar scaling = camera->scaling(); PowerScaledScalar scaling = glm::vec2(1, -6); @@ -134,25 +134,21 @@ void RenderablePlanet::render(const Camera* camera, const psc& thisPosition, Run // scale the planet to appropriate size since the planet is a unit sphere glm::mat4 transform = glm::mat4(1); - // set spice-orientation in accordance to timestamp - glm::dmat3 stateMatrix; - openspace::SpiceManager::ref().getPositionTransformMatrixGLM("GALACTIC", "IAU_EARTH", runtimeData->getTime(), stateMatrix); - //earth needs to be rotated for that to work. glm::mat4 rot = glm::rotate(transform, 90.f, glm::vec3(1, 0, 0)); for (int i = 0; i < 3; i++){ for (int j = 0; j < 3; j++){ - transform[i][j] = stateMatrix[i][j]; + transform[i][j] = _stateMatrix[i][j]; } } transform = transform* rot; // setup the data to the shader - _programObject->setUniform("ViewProjection", camera->viewProjectionMatrix()); + _programObject->setUniform("ViewProjection", data.camera.viewProjectionMatrix()); _programObject->setUniform("ModelTransform", transform); - setPscUniforms(_programObject, camera, currentPosition); + setPscUniforms(_programObject, &data.camera, data.position); // Bind texture ghoul::opengl::TextureUnit unit; @@ -168,8 +164,11 @@ void RenderablePlanet::render(const Camera* camera, const psc& thisPosition, Run } -void RenderablePlanet::update() +void RenderablePlanet::update(const UpdateData& data) { + // set spice-orientation in accordance to timestamp + openspace::SpiceManager::ref().getPositionTransformMatrixGLM("GALACTIC", "IAU_EARTH", data.time, _stateMatrix); + } void RenderablePlanet::loadTexture() diff --git a/src/rendering/renderable.cpp b/src/rendering/renderable.cpp index 70620d763b..c789148cb7 100644 --- a/src/rendering/renderable.cpp +++ b/src/rendering/renderable.cpp @@ -88,7 +88,7 @@ const PowerScaledScalar& Renderable::getBoundingSphere() return boundingSphere_; } -void Renderable::update() +void Renderable::update(const UpdateData&) { } diff --git a/src/rendering/renderablefieldlines.cpp b/src/rendering/renderablefieldlines.cpp index a1fdfc11bd..4c25ab73d5 100644 --- a/src/rendering/renderablefieldlines.cpp +++ b/src/rendering/renderablefieldlines.cpp @@ -211,15 +211,15 @@ bool RenderableFieldlines::deinitialize() { return true; } -void RenderableFieldlines::render(const Camera* camera, const psc& thisPosition, RuntimeData* runtimeData) { +void RenderableFieldlines::render(const RenderData& data) { if(_update) { _update = false; safeShaderCompilation(); } - glm::mat4 transform = camera->viewProjectionMatrix(); - glm::mat4 camTransform = camera->viewRotationMatrix(); - psc relative = thisPosition-camera->position(); + glm::mat4 transform = data.camera.viewProjectionMatrix(); + glm::mat4 camTransform = data.camera.viewRotationMatrix(); + psc relative = data.position - data.camera.position(); transform = transform*camTransform; transform = glm::mat4(1.0); @@ -228,9 +228,9 @@ void RenderableFieldlines::render(const Camera* camera, const psc& thisPosition, // Activate shader _fieldlinesProgram->activate(); - _fieldlinesProgram->setUniform("modelViewProjection", camera->viewProjectionMatrix()); + _fieldlinesProgram->setUniform("modelViewProjection", data.camera.viewProjectionMatrix()); _fieldlinesProgram->setUniform("modelTransform", transform); - setPscUniforms(_fieldlinesProgram, camera, thisPosition); + setPscUniforms(_fieldlinesProgram, &data.camera, data.position); // ------ FIELDLINES ----------------- glBindVertexArray(_VAO); @@ -245,7 +245,7 @@ void RenderableFieldlines::render(const Camera* camera, const psc& thisPosition, _fieldlinesProgram->deactivate(); } -void RenderableFieldlines::update() { +void RenderableFieldlines::update(const UpdateData& data) { } void RenderableFieldlines::safeShaderCompilation() { diff --git a/src/rendering/renderablesphericalgrid.cpp b/src/rendering/renderablesphericalgrid.cpp index 318119c88c..eaa4460274 100644 --- a/src/rendering/renderablesphericalgrid.cpp +++ b/src/rendering/renderablesphericalgrid.cpp @@ -181,21 +181,21 @@ bool RenderableSphericalGrid::initialize(){ return completeSuccess; } -void RenderableSphericalGrid::render(const Camera* camera, const psc& thisPosition, RuntimeData* runtimeData){ +void RenderableSphericalGrid::render(const RenderData& data){ assert(_gridProgram); _gridProgram->activate(); // fetch data - psc currentPosition = thisPosition; - psc campos = camera->position(); - glm::mat4 camrot = camera->viewRotationMatrix(); + psc currentPosition = data.position; + psc campos = data.camera.position(); + glm::mat4 camrot = data.camera.viewRotationMatrix(); // PowerScaledScalar scaling = camera->scaling(); PowerScaledScalar scaling = glm::vec2(1, -6); glm::mat4 transform = glm::mat4(1); // setup the data to the shader - _gridProgram->setUniform("ViewProjection", camera->viewProjectionMatrix()); + _gridProgram->setUniform("ViewProjection", data.camera.viewProjectionMatrix()); _gridProgram->setUniform("ModelTransform", transform); _gridProgram->setUniform("campos", campos.vec4()); _gridProgram->setUniform("objpos", currentPosition.vec4()); @@ -216,7 +216,7 @@ void RenderableSphericalGrid::render(const Camera* camera, const psc& thisPositi _gridProgram->deactivate(); } -void RenderableSphericalGrid::update(){ - +void RenderableSphericalGrid::update(const UpdateData& data){ } + } \ No newline at end of file diff --git a/src/rendering/renderablevolumegl.cpp b/src/rendering/renderablevolumegl.cpp index a7850a3805..f602384b47 100644 --- a/src/rendering/renderablevolumegl.cpp +++ b/src/rendering/renderablevolumegl.cpp @@ -228,7 +228,7 @@ bool RenderableVolumeGL::deinitialize() { return true; } -void RenderableVolumeGL::render(const Camera *camera, const psc &thisPosition, RuntimeData* runtimeData) { +void RenderableVolumeGL::render(const RenderData& data) { if(_updateTransferfunction) { _updateTransferfunction = false; ghoul::opengl::Texture* transferFunction = loadTransferFunction(_transferFunctionPath); @@ -248,7 +248,7 @@ void RenderableVolumeGL::render(const Camera *camera, const psc &thisPosition, R transform = glm::scale(transform, _boxScaling); // fetch data - psc currentPosition = thisPosition; + psc currentPosition = data.position; // psc addon(-1.1,0.0,0.0,0.0); // currentPosition += addon; @@ -257,9 +257,9 @@ void RenderableVolumeGL::render(const Camera *camera, const psc &thisPosition, R _boxProgram->activate(); _boxProgram->setUniform(_typeLocation, _id); - _boxProgram->setUniform("modelViewProjection", camera->viewProjectionMatrix()); + _boxProgram->setUniform("modelViewProjection", data.camera.viewProjectionMatrix()); _boxProgram->setUniform("modelTransform", transform); - setPscUniforms(_boxProgram, camera, currentPosition); + setPscUniforms(_boxProgram, &data.camera, currentPosition); // make sure GL_CULL_FACE is enabled (it should be) glEnable(GL_CULL_FACE); @@ -276,7 +276,7 @@ void RenderableVolumeGL::render(const Camera *camera, const psc &thisPosition, R _boxProgram->deactivate(); } -void RenderableVolumeGL::update() { +void RenderableVolumeGL::update(const UpdateData& data) { } } // namespace openspace diff --git a/src/rendering/renderengine.cpp b/src/rendering/renderengine.cpp index 1f0cca415d..c352f2dac9 100644 --- a/src/rendering/renderengine.cpp +++ b/src/rendering/renderengine.cpp @@ -51,7 +51,6 @@ namespace openspace { RenderEngine::RenderEngine() : _mainCamera(nullptr) , _sceneGraph(nullptr) - , _runtimeData(nullptr) , _abuffer(nullptr) { } @@ -82,10 +81,6 @@ bool RenderEngine::initialize() return true; } -void RenderEngine::setRuntimeData(RuntimeData* runtimeData){ - _runtimeData = runtimeData; -} - bool RenderEngine::initializeGL() { // LDEBUG("RenderEngine::initializeGL()"); @@ -177,7 +172,7 @@ void RenderEngine::postSynchronizationPreDraw() _mainCamera->compileViewRotationMatrix(); // update and evaluate the scene starting from the root node - _sceneGraph->update(); + _sceneGraph->update({Time::ref().currentTime()}); _mainCamera->setCameraDirection(glm::vec3(0, 0, -1)); _sceneGraph->evaluate(_mainCamera); } @@ -212,7 +207,7 @@ void RenderEngine::render() // render the scene starting from the root node _abuffer->clear(); _abuffer->preRender(); - _sceneGraph->render(_mainCamera); + _sceneGraph->render({*_mainCamera, psc()}); _abuffer->postRender(); _abuffer->resolve(); @@ -227,21 +222,15 @@ void RenderEngine::render() #endif - std::string timeGUI = SpiceManager::ref().ephemerisTimeToString(_runtimeData->getTime()); - - if (timeGUI == "") _runtimeData->setTime(0); // if time ends -> reset time to julian date 0. - const glm::vec2 scaling = _mainCamera->scaling(); const glm::vec3 viewdirection = _mainCamera->viewDirection(); const psc position = _mainCamera->position(); const psc origin = OsEng.interactionHandler().getOrigin(); const PowerScaledScalar pssl = (position - origin).length(); + /* GUI PRINT */ - Freetype::print( - sgct_text::FontManager::instance()->getFont("SGCTFont", FONT_SIZE), - FONT_SIZE, FONT_SIZE * 20, "OpenSpace Time: (%s)", timeGUI.c_str()); - const std::string time = Time::ref().currentTimeUTC().c_str(); + std::string&& time = Time::ref().currentTimeUTC().c_str(); Freetype::print( sgct_text::FontManager::instance()->getFont("SGCTFont", FONT_SIZE), FONT_SIZE, FONT_SIZE * 18, "Date: %s", time.c_str() @@ -306,164 +295,164 @@ void RenderEngine::serialize(std::vector& dataStream, size_t& offset) { // camera->scaling - const glm::vec2 scaling = _mainCamera->scaling(); - const psc position = _mainCamera->position(); - //const psc origin = OsEng.interactionHandler().getOrigin(); - //const pss pssl = (position - origin).length(); - //_mainCamera->cameraDirection() + //const glm::vec2 scaling = _mainCamera->scaling(); + //const psc position = _mainCamera->position(); + ////const psc origin = OsEng.interactionHandler().getOrigin(); + ////const pss pssl = (position - origin).length(); + ////_mainCamera->cameraDirection() - union storage { - float value; - std::array representation; - } s; + //union storage { + // float value; + // std::array representation; + //} s; - s.value = _mainCamera->cameraDirection().x; - dataStream[offset++] = s.representation[0]; - dataStream[offset++] = s.representation[1]; - dataStream[offset++] = s.representation[2]; - dataStream[offset++] = s.representation[3]; + //s.value = _mainCamera->cameraDirection().x; + //dataStream[offset++] = s.representation[0]; + //dataStream[offset++] = s.representation[1]; + //dataStream[offset++] = s.representation[2]; + //dataStream[offset++] = s.representation[3]; - s.value = _mainCamera->cameraDirection().y; - dataStream[offset++] = s.representation[0]; - dataStream[offset++] = s.representation[1]; - dataStream[offset++] = s.representation[2]; - dataStream[offset++] = s.representation[3]; + //s.value = _mainCamera->cameraDirection().y; + //dataStream[offset++] = s.representation[0]; + //dataStream[offset++] = s.representation[1]; + //dataStream[offset++] = s.representation[2]; + //dataStream[offset++] = s.representation[3]; - s.value = _mainCamera->cameraDirection().z; - dataStream[offset++] = s.representation[0]; - dataStream[offset++] = s.representation[1]; - dataStream[offset++] = s.representation[2]; - dataStream[offset++] = s.representation[3]; + //s.value = _mainCamera->cameraDirection().z; + //dataStream[offset++] = s.representation[0]; + //dataStream[offset++] = s.representation[1]; + //dataStream[offset++] = s.representation[2]; + //dataStream[offset++] = s.representation[3]; - s.value = _mainCamera->rotation().x; - dataStream[offset++] = s.representation[0]; - dataStream[offset++] = s.representation[1]; - dataStream[offset++] = s.representation[2]; - dataStream[offset++] = s.representation[3]; + //s.value = _mainCamera->rotation().x; + //dataStream[offset++] = s.representation[0]; + //dataStream[offset++] = s.representation[1]; + //dataStream[offset++] = s.representation[2]; + //dataStream[offset++] = s.representation[3]; - s.value = _mainCamera->rotation().y; - dataStream[offset++] = s.representation[0]; - dataStream[offset++] = s.representation[1]; - dataStream[offset++] = s.representation[2]; - dataStream[offset++] = s.representation[3]; + //s.value = _mainCamera->rotation().y; + //dataStream[offset++] = s.representation[0]; + //dataStream[offset++] = s.representation[1]; + //dataStream[offset++] = s.representation[2]; + //dataStream[offset++] = s.representation[3]; - s.value = _mainCamera->rotation().z; - dataStream[offset++] = s.representation[0]; - dataStream[offset++] = s.representation[1]; - dataStream[offset++] = s.representation[2]; - dataStream[offset++] = s.representation[3]; + //s.value = _mainCamera->rotation().z; + //dataStream[offset++] = s.representation[0]; + //dataStream[offset++] = s.representation[1]; + //dataStream[offset++] = s.representation[2]; + //dataStream[offset++] = s.representation[3]; - s.value = _mainCamera->rotation().w; - dataStream[offset++] = s.representation[0]; - dataStream[offset++] = s.representation[1]; - dataStream[offset++] = s.representation[2]; - dataStream[offset++] = s.representation[3]; + //s.value = _mainCamera->rotation().w; + //dataStream[offset++] = s.representation[0]; + //dataStream[offset++] = s.representation[1]; + //dataStream[offset++] = s.representation[2]; + //dataStream[offset++] = s.representation[3]; - s.value = _mainCamera->position().vec4().x; - dataStream[offset++] = s.representation[0]; - dataStream[offset++] = s.representation[1]; - dataStream[offset++] = s.representation[2]; - dataStream[offset++] = s.representation[3]; + //s.value = _mainCamera->position().vec4().x; + //dataStream[offset++] = s.representation[0]; + //dataStream[offset++] = s.representation[1]; + //dataStream[offset++] = s.representation[2]; + //dataStream[offset++] = s.representation[3]; - s.value = _mainCamera->position().vec4().y; - dataStream[offset++] = s.representation[0]; - dataStream[offset++] = s.representation[1]; - dataStream[offset++] = s.representation[2]; - dataStream[offset++] = s.representation[3]; + //s.value = _mainCamera->position().vec4().y; + //dataStream[offset++] = s.representation[0]; + //dataStream[offset++] = s.representation[1]; + //dataStream[offset++] = s.representation[2]; + //dataStream[offset++] = s.representation[3]; - s.value = _mainCamera->position().vec4().z; - dataStream[offset++] = s.representation[0]; - dataStream[offset++] = s.representation[1]; - dataStream[offset++] = s.representation[2]; - dataStream[offset++] = s.representation[3]; + //s.value = _mainCamera->position().vec4().z; + //dataStream[offset++] = s.representation[0]; + //dataStream[offset++] = s.representation[1]; + //dataStream[offset++] = s.representation[2]; + //dataStream[offset++] = s.representation[3]; - s.value = _mainCamera->position().vec4().w; - dataStream[offset++] = s.representation[0]; - dataStream[offset++] = s.representation[1]; - dataStream[offset++] = s.representation[2]; - dataStream[offset++] = s.representation[3]; + //s.value = _mainCamera->position().vec4().w; + //dataStream[offset++] = s.representation[0]; + //dataStream[offset++] = s.representation[1]; + //dataStream[offset++] = s.representation[2]; + //dataStream[offset++] = s.representation[3]; } void RenderEngine::deserialize(const std::vector& dataStream, size_t& offset) { // TODO: This has to be redone properly (ab) - union storage { - float value; - std::array representation; - } s; + // union storage { + // float value; + // std::array representation; + // } s; - glm::vec3 cameraDirection; - s.representation[0] = dataStream[offset++]; - s.representation[1] = dataStream[offset++]; - s.representation[2] = dataStream[offset++]; - s.representation[3] = dataStream[offset++]; - cameraDirection.x = s.value; + // glm::vec3 cameraDirection; + // s.representation[0] = dataStream[offset++]; + // s.representation[1] = dataStream[offset++]; + // s.representation[2] = dataStream[offset++]; + // s.representation[3] = dataStream[offset++]; + // cameraDirection.x = s.value; - s.representation[0] = dataStream[offset++]; - s.representation[1] = dataStream[offset++]; - s.representation[2] = dataStream[offset++]; - s.representation[3] = dataStream[offset++]; - cameraDirection.y = s.value; + // s.representation[0] = dataStream[offset++]; + // s.representation[1] = dataStream[offset++]; + // s.representation[2] = dataStream[offset++]; + // s.representation[3] = dataStream[offset++]; + // cameraDirection.y = s.value; - s.representation[0] = dataStream[offset++]; - s.representation[1] = dataStream[offset++]; - s.representation[2] = dataStream[offset++]; - s.representation[3] = dataStream[offset++]; - cameraDirection.z = s.value; - _mainCamera->setCameraDirection(cameraDirection); + // s.representation[0] = dataStream[offset++]; + // s.representation[1] = dataStream[offset++]; + // s.representation[2] = dataStream[offset++]; + // s.representation[3] = dataStream[offset++]; + // cameraDirection.z = s.value; + // _mainCamera->setCameraDirection(cameraDirection); - glm::quat rotation; - s.representation[0] = dataStream[offset++]; - s.representation[1] = dataStream[offset++]; - s.representation[2] = dataStream[offset++]; - s.representation[3] = dataStream[offset++]; - rotation.x = s.value; + // glm::quat rotation; + // s.representation[0] = dataStream[offset++]; + // s.representation[1] = dataStream[offset++]; + // s.representation[2] = dataStream[offset++]; + // s.representation[3] = dataStream[offset++]; + // rotation.x = s.value; - s.representation[0] = dataStream[offset++]; - s.representation[1] = dataStream[offset++]; - s.representation[2] = dataStream[offset++]; - s.representation[3] = dataStream[offset++]; - rotation.y = s.value; + // s.representation[0] = dataStream[offset++]; + // s.representation[1] = dataStream[offset++]; + // s.representation[2] = dataStream[offset++]; + // s.representation[3] = dataStream[offset++]; + // rotation.y = s.value; - s.representation[0] = dataStream[offset++]; - s.representation[1] = dataStream[offset++]; - s.representation[2] = dataStream[offset++]; - s.representation[3] = dataStream[offset++]; - rotation.z = s.value; + // s.representation[0] = dataStream[offset++]; + // s.representation[1] = dataStream[offset++]; + // s.representation[2] = dataStream[offset++]; + // s.representation[3] = dataStream[offset++]; + // rotation.z = s.value; - s.representation[0] = dataStream[offset++]; - s.representation[1] = dataStream[offset++]; - s.representation[2] = dataStream[offset++]; - s.representation[3] = dataStream[offset++]; - rotation.w = s.value; - _mainCamera->setRotation(rotation); + // s.representation[0] = dataStream[offset++]; + // s.representation[1] = dataStream[offset++]; + // s.representation[2] = dataStream[offset++]; + // s.representation[3] = dataStream[offset++]; + // rotation.w = s.value; + // _mainCamera->setRotation(rotation); - glm::vec4 position; - s.representation[0] = dataStream[offset++]; - s.representation[1] = dataStream[offset++]; - s.representation[2] = dataStream[offset++]; - s.representation[3] = dataStream[offset++]; - position.x = s.value; + // glm::vec4 position; + // s.representation[0] = dataStream[offset++]; + // s.representation[1] = dataStream[offset++]; + // s.representation[2] = dataStream[offset++]; + // s.representation[3] = dataStream[offset++]; + // position.x = s.value; - s.representation[0] = dataStream[offset++]; - s.representation[1] = dataStream[offset++]; - s.representation[2] = dataStream[offset++]; - s.representation[3] = dataStream[offset++]; - position.y = s.value; + // s.representation[0] = dataStream[offset++]; + // s.representation[1] = dataStream[offset++]; + // s.representation[2] = dataStream[offset++]; + // s.representation[3] = dataStream[offset++]; + // position.y = s.value; - s.representation[0] = dataStream[offset++]; - s.representation[1] = dataStream[offset++]; - s.representation[2] = dataStream[offset++]; - s.representation[3] = dataStream[offset++]; - position.z = s.value; + // s.representation[0] = dataStream[offset++]; + // s.representation[1] = dataStream[offset++]; + // s.representation[2] = dataStream[offset++]; + // s.representation[3] = dataStream[offset++]; + // position.z = s.value; - s.representation[0] = dataStream[offset++]; - s.representation[1] = dataStream[offset++]; - s.representation[2] = dataStream[offset++]; - s.representation[3] = dataStream[offset++]; - position.w = s.value; + // s.representation[0] = dataStream[offset++]; + // s.representation[1] = dataStream[offset++]; + // s.representation[2] = dataStream[offset++]; + // s.representation[3] = dataStream[offset++]; + // position.w = s.value; - _mainCamera->setPosition(position); + //_mainCamera->setPosition(position); } Camera* RenderEngine::camera() const { diff --git a/src/rendering/stars/renderablestars.cpp b/src/rendering/stars/renderablestars.cpp index 85a0088e09..e34e6aa8cf 100644 --- a/src/rendering/stars/renderablestars.cpp +++ b/src/rendering/stars/renderablestars.cpp @@ -28,7 +28,7 @@ #include #include #include - +#include // openspace includes #include @@ -306,7 +306,7 @@ bool RenderableStars::deinitialize(){ } //#define TMAT -void RenderableStars::render(const Camera* camera, const psc& thisPosition, RuntimeData* runtimeData){ +void RenderableStars::render(const RenderData& data){ assert(_haloProgram); printOpenGLError(); // activate shader @@ -327,9 +327,9 @@ void RenderableStars::render(const Camera* camera, const psc& thisPosition, Runt //glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ONE); #ifdef GLSPRITES - glm::mat4 modelMatrix = camera->modelMatrix(); - glm::mat4 viewMatrix = camera->viewMatrix(); - glm::mat4 projectionMatrix = camera->projectionMatrix(); + glm::mat4 modelMatrix = data.camera.modelMatrix(); + glm::mat4 viewMatrix = data.camera.viewMatrix(); + glm::mat4 projectionMatrix = data.camera.projectionMatrix(); // ---------------------- RENDER HALOS ----------------------------- _haloProgram->setUniform("model", modelMatrix); @@ -338,7 +338,7 @@ void RenderableStars::render(const Camera* camera, const psc& thisPosition, Runt //_haloProgram->setUniform("ViewProjection", camera->viewProjectionMatrix()); _haloProgram->setUniform("ModelTransform", glm::mat4(1)); - setPscUniforms(_haloProgram, camera, thisPosition); + setPscUniforms(_haloProgram, &data.camera, data.position); _haloProgram->setUniform("scaling", scaling); // Bind texure @@ -397,7 +397,7 @@ void RenderableStars::loadTexture(){ } } -void RenderableStars::update() +void RenderableStars::update(const UpdateData& data) { } diff --git a/src/scenegraph/ephemeris.cpp b/src/scenegraph/ephemeris.cpp index ae2d5080d8..b764190cf7 100644 --- a/src/scenegraph/ephemeris.cpp +++ b/src/scenegraph/ephemeris.cpp @@ -68,6 +68,6 @@ bool Ephemeris::initialize() { return true; } -void Ephemeris::update() {} +void Ephemeris::update(const UpdateData& data) {} } // namespace openspace \ No newline at end of file diff --git a/src/scenegraph/scenegraph.cpp b/src/scenegraph/scenegraph.cpp index fcf25d9b5e..0142f19b83 100644 --- a/src/scenegraph/scenegraph.cpp +++ b/src/scenegraph/scenegraph.cpp @@ -32,6 +32,7 @@ #include #include #include +#include // ghoul includes #include "ghoul/opengl/programobject.h" @@ -173,13 +174,29 @@ int property_getValue(lua_State* L) { return 1; } +/** + * \ingroup LuaScripts + * getPropertyValue(string): + * Returns the value of the property identified by the passed URI as a Lua object that can + * be passed to the setPropertyValue method. + */ +int loadScene(lua_State* L) { + const std::string _loggerCat = "loadScene"; + + // TODO Check for argument number (ab) + std::string sceneFile = luaL_checkstring(L, -1); + + OsEng.renderEngine().sceneGraph()->scheduleLoadSceneFile(sceneFile); + + return 0; +} + } // namespace luascriptfunctions SceneGraph::SceneGraph() : _focus(SceneGraphNode::RootNodeName) , _position(SceneGraphNode::RootNodeName) , _root(nullptr) - , _runtimeData(nullptr) { } @@ -188,10 +205,6 @@ SceneGraph::~SceneGraph() deinitialize(); } -void SceneGraph::setRuntimeData(RuntimeData* runtimeData){ - _runtimeData = runtimeData; -} - bool SceneGraph::initialize() { LDEBUG("Initializing SceneGraph"); @@ -206,8 +219,7 @@ bool SceneGraph::initialize() typedef std::chrono::high_resolution_clock clock_; typedef std::chrono::duration > second_; - std::chrono::time_point beg_(clock_::now()); - + std::chrono::time_point beginning(clock_::now()); // pscstandard tmpProgram = sc.buildShader("pscstandard", @@ -267,8 +279,8 @@ bool SceneGraph::initialize() - double elapsed = std::chrono::duration_cast(clock_::now() - beg_).count(); - LERROR("Time to load shaders: " << elapsed); + double elapsed = std::chrono::duration_cast(clock_::now()-beginning).count(); + LINFO("Time to load shaders: " << elapsed); /* @@ -432,9 +444,147 @@ bool SceneGraph::initialize() */ //>>>>>>> develop + return true; +} + +bool SceneGraph::deinitialize() +{ + clearSceneGraph(); + return true; +} + +void SceneGraph::update(const UpdateData& data) +{ + if (!_sceneGraphToLoad.empty()) { + OsEng.renderEngine().sceneGraph()->clearSceneGraph(); + bool success = loadSceneInternal(_sceneGraphToLoad); + _sceneGraphToLoad = ""; + if (!success) + return; + } + + for (auto node : _nodes) + node->update(data); +} + +void SceneGraph::evaluate(Camera* camera) +{ + if (_root) + _root->evaluate(camera); +} + +void SceneGraph::render(const RenderData& data) +{ + if (_root) + _root->render(data); +} + +void SceneGraph::scheduleLoadSceneFile(const std::string& sceneDescriptionFilePath) { + _sceneGraphToLoad = sceneDescriptionFilePath; +} + +void SceneGraph::clearSceneGraph() { + // deallocate the scene graph. Recursive deallocation will occur + delete _root; + _root = nullptr; + + _nodes.erase(_nodes.begin(), _nodes.end()); + _allNodes.erase(_allNodes.begin(), _allNodes.end()); + + _focus.clear(); + _position.clear(); +} + +bool SceneGraph::loadSceneInternal(const std::string& sceneDescriptionFilePath) +{ + using ghoul::Dictionary; + using ghoul::lua::loadDictionaryFromFile; + + if (!FileSys.fileExists(sceneDescriptionFilePath)) { + LFATAL("Scene description file '" << sceneDescriptionFilePath << "' not found"); + return false; + } + + LDEBUG("Loading scenegraph nodes"); + if (_root != nullptr) { + LFATAL("Scenegraph already loaded"); + return false; + } + + // initialize the root node + _root = new SceneGraphNode(); + _root->setName(SceneGraphNode::RootNodeName); + _nodes.push_back(_root); + _allNodes.emplace(SceneGraphNode::RootNodeName, _root); + + Dictionary dictionary; + //load default.scene + loadDictionaryFromFile(sceneDescriptionFilePath, dictionary); + + std::string&& sceneDescriptionDirectory = + ghoul::filesystem::File(sceneDescriptionFilePath).directoryName(); + std::string moduleDirectory("."); + dictionary.getValueSafe(constants::scenegraph::keyPathScene, moduleDirectory); + + // The scene path could either be an absolute or relative path to the description + // paths directory + std::string&& relativeCandidate = sceneDescriptionDirectory + + ghoul::filesystem::FileSystem::PathSeparator + moduleDirectory; + std::string&& absoluteCandidate = absPath(moduleDirectory); + + if (FileSys.directoryExists(relativeCandidate)) + moduleDirectory = relativeCandidate; + else if (FileSys.directoryExists(absoluteCandidate)) + moduleDirectory = absoluteCandidate; + else { + LFATAL("The '" << constants::scenegraph::keyPathScene << "' pointed to a " + "path '" << moduleDirectory << "' that did not exist"); + return false; + } + + Dictionary moduleDictionary; + if (dictionary.getValue(constants::scenegraph::keyModules, moduleDictionary)) { + std::vector keys = moduleDictionary.keys(); + std::sort(keys.begin(), keys.end()); + for (const std::string& key : keys) { + std::string moduleFolder; + if (moduleDictionary.getValue(key, moduleFolder)) + loadModule(moduleDirectory + "/" + moduleFolder); + } + } + + // TODO: Make it less hard-coded and more flexible when nodes are not found + Dictionary cameraDictionary; + if (dictionary.getValue(constants::scenegraph::keyCamera, cameraDictionary)) { + LDEBUG("Camera dictionary found"); + std::string focus; + std::string position; + + if (cameraDictionary.hasKey(constants::scenegraph::keyFocusObject) + && cameraDictionary.getValue(constants::scenegraph::keyFocusObject, focus)) { + auto focusIterator = _allNodes.find(focus); + if (focusIterator != _allNodes.end()) { + _focus = focus; + LDEBUG("Setting camera focus to '" << _focus << "'"); + } + else + LERROR("Could not find focus object '" << focus << "'"); + } + if (cameraDictionary.hasKey(constants::scenegraph::keyPositionObject) + && cameraDictionary.getValue(constants::scenegraph::keyPositionObject, position)) { + auto positionIterator = _allNodes.find(position); + if (positionIterator != _allNodes.end()) { + _position = position; + LDEBUG("Setting camera position to '" << _position << "'"); + } + else + LERROR("Could not find object '" << position << "' to position camera"); + } + } + // Initialize all nodes for (auto node : _nodes) { - bool success = node->initialize(_runtimeData); + bool success = node->initialize(); if (success) LDEBUG(node->name() << " initialized successfully!"); else @@ -442,7 +592,9 @@ bool SceneGraph::initialize() } // update the position of all nodes - update(); + // TODO need to check this; unnecessary? (ab) + for (auto node : _nodes) + node->update({Time::ref().currentTime()}); // Calculate the bounding sphere for the scenegraph _root->calculateBoundingSphere(); @@ -484,102 +636,6 @@ bool SceneGraph::initialize() return true; } -bool SceneGraph::deinitialize() -{ - // deallocate the scene graph. Recursive deallocation will occur - delete _root; - _root = nullptr; - - _nodes.erase(_nodes.begin(), _nodes.end()); - _allNodes.erase(_allNodes.begin(), _allNodes.end()); - - _focus.clear(); - _position.clear(); - - return true; -} - -void SceneGraph::update() -{ - for (auto node : _nodes) - node->update(); -} - -void SceneGraph::evaluate(Camera* camera) -{ - _root->evaluate(camera); -} - -void SceneGraph::render(Camera* camera) -{ - _root->render(camera); -} - -bool SceneGraph::loadScene(const std::string& sceneDescriptionFilePath, - const std::string& defaultModulePath) -{ - using ghoul::Dictionary; - using ghoul::lua::loadDictionaryFromFile; - - LDEBUG("Loading scenegraph nodes"); - if (_root != nullptr) { - LFATAL("Scenegraph already loaded"); - return false; - } - - - // initialize the root node - _root = new SceneGraphNode(); - _root->setName(SceneGraphNode::RootNodeName); - _nodes.push_back(_root); - _allNodes.emplace(SceneGraphNode::RootNodeName, _root); - - Dictionary dictionary; - //load default.scene - loadDictionaryFromFile(sceneDescriptionFilePath, dictionary); - Dictionary moduleDictionary; - if (dictionary.getValue(constants::scenegraph::keyModules, moduleDictionary)) { - std::vector keys = moduleDictionary.keys(); - std::sort(keys.begin(), keys.end()); - for (const std::string& key : keys) { - std::string moduleFolder; - if (moduleDictionary.getValue(key, moduleFolder)) - loadModule(defaultModulePath + "/" + moduleFolder); - } - } - - // TODO: Make it less hard-coded and more flexible when nodes are not found - Dictionary cameraDictionary; - if (dictionary.getValue(constants::scenegraph::keyCamera, cameraDictionary)) { - LDEBUG("Camera dictionary found"); - std::string focus; - std::string position; - - if (cameraDictionary.hasKey(constants::scenegraph::keyFocusObject) - && cameraDictionary.getValue(constants::scenegraph::keyFocusObject, focus)) { - auto focusIterator = _allNodes.find(focus); - if (focusIterator != _allNodes.end()) { - _focus = focus; - LDEBUG("Setting camera focus to '" << _focus << "'"); - } - else - LERROR("Could not find focus object '" << focus << "'"); - } - if (cameraDictionary.hasKey(constants::scenegraph::keyPositionObject) - && cameraDictionary.getValue(constants::scenegraph::keyPositionObject, position)) { - auto positionIterator = _allNodes.find(position); - if (positionIterator != _allNodes.end()) { - _position = position; - LDEBUG("Setting camera position to '" << _position << "'"); - } - else - LERROR("Could not find object '" << position << "' to position camera"); - } - } - - return true; -} - void SceneGraph::loadModule(const std::string& modulePath) { auto pos = modulePath.find_last_of("/"); @@ -650,7 +706,13 @@ scripting::ScriptEngine::LuaLibrary SceneGraph::luaLibrary() { "getPropertyValue", &luascriptfunctions::property_getValue, "getPropertyValue(string): Returns the value the property, identified by " - "the provided URI, has" + "the provided URI." + }, + { + "loadScene", + &luascriptfunctions::loadScene, + "loadScene(string): Loads the scene found at the file passed as an " + "argument. If a scene is already loaded, it is unloaded first" } } }; diff --git a/src/scenegraph/scenegraphnode.cpp b/src/scenegraph/scenegraphnode.cpp index afdb3bf5d2..6966db4035 100644 --- a/src/scenegraph/scenegraphnode.cpp +++ b/src/scenegraph/scenegraphnode.cpp @@ -128,7 +128,6 @@ SceneGraphNode::SceneGraphNode() , _renderable(nullptr) , _renderableVisible(false) , _boundingSphereVisible(false) - , _runtimeData(nullptr) { } @@ -137,7 +136,7 @@ SceneGraphNode::~SceneGraphNode() deinitialize(); } -bool SceneGraphNode::initialize(RuntimeData* runtimeData) +bool SceneGraphNode::initialize() { if (_renderable != nullptr) _renderable->initialize(); @@ -145,7 +144,6 @@ bool SceneGraphNode::initialize(RuntimeData* runtimeData) if (_ephemeris != nullptr) _ephemeris->initialize(); - _runtimeData = runtimeData; return true; } @@ -173,9 +171,12 @@ bool SceneGraphNode::deinitialize() } // essential -void SceneGraphNode::update() +void SceneGraphNode::update(const UpdateData& data) { - _ephemeris->update(_runtimeData); + if (_ephemeris) + _ephemeris->update(data); + if (_renderable) + _renderable->update(data); } void SceneGraphNode::evaluate(const Camera* camera, const psc& parentPosition) @@ -220,9 +221,11 @@ void SceneGraphNode::evaluate(const Camera* camera, const psc& parentPosition) } } -void SceneGraphNode::render(const Camera* camera, const psc& parentPosition) +void SceneGraphNode::render(const RenderData& data) { - const psc thisPosition = parentPosition + _ephemeris->position(); + const psc thisPosition = data.position + _ephemeris->position(); + + RenderData newData = {data.camera, thisPosition}; // check if camera is outside the node boundingsphere /*if (!_boundingSphereVisible) { @@ -231,13 +234,13 @@ void SceneGraphNode::render(const Camera* camera, const psc& parentPosition) if (_renderableVisible && _renderable->isVisible()) { // LDEBUG("Render"); - _renderable->render(camera, thisPosition, _runtimeData); + _renderable->render(newData); } // evaluate all the children, tail-recursive function(?) for (auto& child : _children) { - child->render(camera, thisPosition); + child->render(newData); } } @@ -317,7 +320,6 @@ PowerScaledScalar SceneGraphNode::boundingSphere() const{ // renderable void SceneGraphNode::setRenderable(Renderable* renderable) { _renderable = renderable; - update(); } const Renderable* SceneGraphNode::renderable() const diff --git a/src/scenegraph/spiceephemeris.cpp b/src/scenegraph/spiceephemeris.cpp index 816a11be18..4a3100488b 100644 --- a/src/scenegraph/spiceephemeris.cpp +++ b/src/scenegraph/spiceephemeris.cpp @@ -78,15 +78,13 @@ const psc& SpiceEphemeris::position() const { return _position; } -void SpiceEphemeris::update(RuntimeData* runtimeData) { +void SpiceEphemeris::update(const UpdateData& data) { double state[3]; - _currentEphemerisTime = runtimeData->getTime(); - glm::dvec3 position(0,0,0); double lightTime = 0.0; - SpiceManager::ref().getTargetPosition(_targetName, _currentEphemerisTime, "GALACTIC", "LT+S", _originName, position, lightTime); + SpiceManager::ref().getTargetPosition(_targetName, data.time, "GALACTIC", "LT+S", _originName, position, lightTime); /* std::cout << _targetName << " ("; diff --git a/src/scenegraph/staticephemeris.cpp b/src/scenegraph/staticephemeris.cpp index 2c7bee2345..a38ab47c3b 100644 --- a/src/scenegraph/staticephemeris.cpp +++ b/src/scenegraph/staticephemeris.cpp @@ -47,7 +47,7 @@ const psc& StaticEphemeris::position() const { return _position; } -void StaticEphemeris::update(RuntimeData* runtimeData) { +void StaticEphemeris::update(const UpdateData&) { } diff --git a/src/scripting/scriptengine.cpp b/src/scripting/scriptengine.cpp index 6e64d380c2..5b7148ec3c 100644 --- a/src/scripting/scriptengine.cpp +++ b/src/scripting/scriptengine.cpp @@ -122,6 +122,20 @@ namespace luascriptfunctions { return 0; } + /** + * \ingroup LuaScripts + * absPath(string): + * Passes the argument to FileSystem::absolutePath, which resolves occuring path + * tokens and returns the absolute path. + */ + int absolutePath(lua_State* L) { + // TODO check number of arguments (ab) + std::string path = luaL_checkstring(L, -1); + path = absPath(path); + lua_pushstring(L, path.c_str()); + return 1; + } + } // namespace luascriptfunctions namespace scripting { @@ -371,6 +385,12 @@ void ScriptEngine::addBaseLibrary() { &luascriptfunctions::printFatal, "printFatal(*): Logs the passed value to the installed LogManager with a " "LogLevel of 'Fatal'" + }, + { + "absPath", + &luascriptfunctions::absolutePath, + "absPath(string): Returns the absolute path to the passed path, resolving" + " path tokens as well as resolving relative paths" } } }; diff --git a/src/util/kameleonwrapper.cpp b/src/util/kameleonwrapper.cpp index ce0acd5376..c9e856c92d 100644 --- a/src/util/kameleonwrapper.cpp +++ b/src/util/kameleonwrapper.cpp @@ -599,7 +599,7 @@ void KameleonWrapper::progressBar(int current, int end) { int spWidth = barWidth - pos + 2; std::cout << "[" << std::setfill('=') << std::setw(eqWidth) << ">" << std::setfill(' ') << std::setw(spWidth) - << "] " << iprogress << " % \r" << std::flush; + << "] " << std::setfill(' ') << std::setw(3) << iprogress << " % \r" << std::flush; } _lastiProgress = iprogress; }