diff --git a/include/openspace/engine/openspaceengine.h b/include/openspace/engine/openspaceengine.h index 6e94d69a3c..33a2437b5a 100644 --- a/include/openspace/engine/openspaceengine.h +++ b/include/openspace/engine/openspaceengine.h @@ -80,7 +80,6 @@ public: double runTime(); void setRunTime(double t); - void loadScene(const std::string& scenePath); // callbacks void initialize(); @@ -98,6 +97,7 @@ public: void externalControlCallback(const char* receivedChars, int size, int clientId); void encode(); void decode(); + void scheduleLoadScene(const std::string& scenePath); void enableBarrier(); @@ -171,6 +171,7 @@ private: std::unique_ptr windowWrapper); ~OpenSpaceEngine() = default; + void loadScene(const std::string& scenePath); void gatherCommandlineArguments(); void loadFonts(); void runPreInitializationScripts(const std::string& sceneDescription); @@ -201,8 +202,6 @@ private: bool _switchScene; std::string _scenePath; - bool _isMaster; - struct { std::vector> initialize; std::vector> deinitialize; diff --git a/include/openspace/scene/sceneloader.h b/include/openspace/scene/sceneloader.h index 181413fe46..f939b5d2dc 100644 --- a/include/openspace/scene/sceneloader.h +++ b/include/openspace/scene/sceneloader.h @@ -2,7 +2,7 @@ * * * OpenSpace * * * -* Copyright (c) 2014-2016 * +* Copyright (c) 2014-2017 * * * * 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 * @@ -73,18 +73,47 @@ public: SceneLoader() = default; ~SceneLoader() = default; - + + /** + * Load a scene file. + */ std::unique_ptr loadScene(const std::string& path); + + /** + * Import a directory of scene contents into an existing scene. + */ std::vector importDirectory(Scene& scene, const std::string& directory); + + /** + * Import a scene graph node from a dictionary into an existing scene. + */ SceneGraphNode* importNodeDictionary(Scene& scene, const ghoul::Dictionary& dictionary); private: + /** + * Load a scene graph node from a dictionary + */ SceneLoader::LoadedNode loadNode(const ghoul::Dictionary& dictionary); + + /** + * Load a mod file. + */ std::vector loadModule(const std::string& path, lua_State* luaState); + + /** + * Load a directory. + */ std::vector loadDirectory(const std::string& path, lua_State* luaState); + /** + * Load a camera from a dictionary + */ SceneLoader::LoadedCamera loadCamera(const ghoul::Dictionary& dictionary); - std::vector addLoadedNodes(Scene& scene, std::vector nodes); + + /** + * Add loaded nodes to an existing scene + */ + std::vector addLoadedNodes(Scene& scene, std::vector&& nodes); }; } diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 43d3389a5d..95b546db03 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -137,7 +137,6 @@ OpenSpaceEngine::OpenSpaceEngine( , _globalPropertyNamespace(new properties::PropertyOwner("")) , _switchScene(false) , _scenePath("") - , _isMaster(false) , _runTime(0.0) , _shutdown({false, 0.f, 0.f}) , _isFirstRenderingFirstFrame(true) @@ -305,7 +304,7 @@ void OpenSpaceEngine::create(int argc, char** argv, "${CACHE}", cacheFolder, ghoul::filesystem::FileSystem::Override::Yes - ); + ); } // Initialize the requested logs from the configuration file @@ -557,7 +556,6 @@ void OpenSpaceEngine::loadScene(const std::string& scenePath) { _renderEngine->setGlobalBlackOutFactor(0.0); _renderEngine->startFading(1, 3.0); - scene->initialize(); _interactionHandler->setCamera(scene->camera()); diff --git a/src/engine/settingsengine.cpp b/src/engine/settingsengine.cpp index a0596ea49b..4e42bd89d7 100644 --- a/src/engine/settingsengine.cpp +++ b/src/engine/settingsengine.cpp @@ -83,7 +83,7 @@ void SettingsEngine::initialize() { std::string sceneFile = _scenes.getDescriptionByValue(_scenes); OsEng.configurationManager().setValue( ConfigurationManager::KeyConfigScene, sceneFile); - OsEng.loadScene(sceneFile); + OsEng.scheduleLoadScene("${SCENE}/" + sceneFile); } ); } @@ -106,32 +106,4 @@ bool SettingsEngine::useDoubleBuffering() { return _useDoubleBuffering.value(); } -/* -void SettingsEngine::initSceneFiles() { - addProperty(_scenes); - - // Load all matching files in the Scene - // TODO: match regex with either with new ghoul readFiles or local code - std::string sceneDir = "${SCENE}"; - std::string pathSep(1, ghoul::filesystem::FileSystem::PathSeparator); - - std::vector scenes = ghoul::filesystem::Directory(sceneDir).readFiles(); - for (std::size_t i = 0; i < scenes.size(); ++i) { - std::size_t found = scenes[i].find_last_of(pathSep); - _scenes.addOption(i, scenes[i].substr(found+1)); - } - - // Set interaction to change ConfigurationManager and schedule the load - _scenes.onChange( - [sceneDir, pathSep]() { - std::string sceneFile = _scenes.getDescriptionByValue(_scenes); - OsEng.configurationManager().setValue( - ConfigurationManager::KeyConfigScene, sceneFile); - std::string fullPath = - sceneDir + pathSep + sceneFile; - OsEng.loadScene(sceneFile); - } - ); -}*/ - } // namespace openspace diff --git a/src/engine/syncengine.cpp b/src/engine/syncengine.cpp index 1690e0852d..fc4635b2ba 100644 --- a/src/engine/syncengine.cpp +++ b/src/engine/syncengine.cpp @@ -83,7 +83,7 @@ void SyncEngine::removeSyncable(Syncable* syncable) { _syncables.erase( std::remove(_syncables.begin(), _syncables.end(), syncable), _syncables.end() - ); + ); } void SyncEngine::removeSyncables(const std::vector& syncables) { diff --git a/src/rendering/renderengine.cpp b/src/rendering/renderengine.cpp index a2b3867fb2..7faed68359 100644 --- a/src/rendering/renderengine.cpp +++ b/src/rendering/renderengine.cpp @@ -37,19 +37,8 @@ #include #include #include - -//#include -//#include -//#include - -//#include - -//#include -//#include #include -//#include - #include #include #include diff --git a/src/scene/sceneloader.cpp b/src/scene/sceneloader.cpp index 06c2a1fbd6..d6caba13dd 100644 --- a/src/scene/sceneloader.cpp +++ b/src/scene/sceneloader.cpp @@ -127,6 +127,11 @@ std::unique_ptr SceneLoader::loadScene(const std::string& path) { auto it = nodeMap.find(loadedCamera.parent); if (it != nodeMap.end()) { loadedCamera.camera->setParent(it->second); + } else { + LWARNING( + "Could not find the camera parent '" + loadedCamera.parent + + "'. Attaching camera to root node."); + loadedCamera.camera->setParent(scene->root()); } scene->setCamera(std::move(loadedCamera.camera)); @@ -273,7 +278,7 @@ std::vector SceneLoader::loadModule(const std::string& return loadedNodes; }; -std::vector SceneLoader::addLoadedNodes(Scene& scene, std::vector loadedNodes) { +std::vector SceneLoader::addLoadedNodes(Scene& scene, std::vector&& loadedNodes) { std::map existingNodes = scene.nodesByName(); std::map addedNodes; diff --git a/src/scene/scenemanager.cpp b/src/scene/scenemanager.cpp index 943f2ae55c..201c5a9862 100644 --- a/src/scene/scenemanager.cpp +++ b/src/scene/scenemanager.cpp @@ -2,7 +2,7 @@ * * * OpenSpace * * * - * Copyright (c) 2014-2016 * + * Copyright (c) 2014-2017 * * * * 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 * diff --git a/tests/test_sceneloader.inl b/tests/test_sceneloader.inl index 89cf0ac446..8291958824 100644 --- a/tests/test_sceneloader.inl +++ b/tests/test_sceneloader.inl @@ -2,7 +2,7 @@ * * * OpenSpace * * * - * Copyright (c) 2014-2016 * + * Copyright (c) 2014-2017 * * * * 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 *