Clean up scene loading

This commit is contained in:
Emil Axelsson
2017-03-14 13:40:18 +01:00
parent 92df9caf5a
commit ca6348194e
9 changed files with 45 additions and 53 deletions
+2 -3
View File
@@ -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> 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<std::function<void()>> initialize;
std::vector<std::function<void()>> deinitialize;
+32 -3
View File
@@ -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<Scene> loadScene(const std::string& path);
/**
* Import a directory of scene contents into an existing scene.
*/
std::vector<SceneGraphNode*> 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<SceneLoader::LoadedNode> loadModule(const std::string& path, lua_State* luaState);
/**
* Load a directory.
*/
std::vector<SceneLoader::LoadedNode> loadDirectory(const std::string& path, lua_State* luaState);
/**
* Load a camera from a dictionary
*/
SceneLoader::LoadedCamera loadCamera(const ghoul::Dictionary& dictionary);
std::vector<SceneGraphNode*> addLoadedNodes(Scene& scene, std::vector<SceneLoader::LoadedNode> nodes);
/**
* Add loaded nodes to an existing scene
*/
std::vector<SceneGraphNode*> addLoadedNodes(Scene& scene, std::vector<SceneLoader::LoadedNode>&& nodes);
};
}
+1 -3
View File
@@ -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());
+1 -29
View File
@@ -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<std::string> 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
+1 -1
View File
@@ -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<Syncable*>& syncables) {
-11
View File
@@ -37,19 +37,8 @@
#include <openspace/rendering/abufferrenderer.h>
#include <openspace/rendering/framebufferrenderer.h>
#include <openspace/rendering/raycastermanager.h>
//#include <modules/base/rendering/screenspaceimage.h>
//#include <modules/base/rendering/screenspaceframebuffer.h>
//#include <openspace/engine/wrapper/windowwrapper.h>
//#include <openspace/performance/performancemanager.h>
//#include <openspace/documentation/documentationengine.h>
//#include <openspace/engine/openspaceengine.h>
#include <openspace/scene/scene.h>
//#include <openspace/scene/scenegraphnode.h>
#include <openspace/util/camera.h>
#include <openspace/util/time.h>
#include <openspace/util/screenlog.h>
+6 -1
View File
@@ -127,6 +127,11 @@ std::unique_ptr<Scene> 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::LoadedNode> SceneLoader::loadModule(const std::string&
return loadedNodes;
};
std::vector<SceneGraphNode*> SceneLoader::addLoadedNodes(Scene& scene, std::vector<SceneLoader::LoadedNode> loadedNodes) {
std::vector<SceneGraphNode*> SceneLoader::addLoadedNodes(Scene& scene, std::vector<SceneLoader::LoadedNode>&& loadedNodes) {
std::map<std::string, SceneGraphNode*> existingNodes = scene.nodesByName();
std::map<std::string, SceneGraphNode*> addedNodes;
+1 -1
View File
@@ -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 *
+1 -1
View File
@@ -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 *