Work on asset loader and assets

This commit is contained in:
Emil Axelsson
2017-09-15 13:57:45 +02:00
parent bf45937619
commit aaed6ab6d7
12 changed files with 73 additions and 74 deletions
@@ -1,4 +1,4 @@
/*****************************************************************************************
/*****************************************************************************************
* *
* OpenSpace *
* *
@@ -67,8 +67,8 @@ public:
static const std::string KeyDocumentation;
/// The key that stores the factory documentation values
static const std::string KeyFactoryDocumentation;
/// The key that stores the location of the scene file that is initially loaded
static const std::string KeyConfigScene;
/// The key that stores the location of the asset file that is initially loaded
static const std::string KeyConfigAsset;
/// The key that stores the location of the tasks file that is initially loaded
static const std::string KeyConfigTask;
/// The key that stores the subdirectory containing a list of all startup scripts to
+4 -7
View File
@@ -28,9 +28,9 @@
#include <openspace/properties/stringproperty.h>
#include <openspace/util/keys.h>
#include <openspace/util/mouse.h>
#include <ghoul/glm.h>
#include <optional>
#include <functional>
#include <memory>
#include <string>
@@ -53,7 +53,6 @@ class ParallelConnection;
class RenderEngine;
class ResourceSynchronizer;
class Scene;
class SceneLoader;
class SyncEngine;
class SettingsEngine;
class TimeManager;
@@ -102,7 +101,7 @@ public:
void encode();
void decode();
void scheduleLoadScene(std::string scenePath);
void scheduleLoadSingleAsset(std::string assetPath);
void enableBarrier();
void disableBarrier();
@@ -178,7 +177,7 @@ private:
OpenSpaceEngine(std::string programName,
std::unique_ptr<WindowWrapper> windowWrapper);
void loadScene(const std::string& scenePath);
void loadSingleAsset(const std::string& assetPath);
void gatherCommandlineArguments();
void loadFonts();
void configureLogging();
@@ -187,7 +186,6 @@ private:
std::unique_ptr<ConfigurationManager> _configurationManager;
std::unique_ptr<Scene> _scene;
std::unique_ptr<AssetLoader> _assetLoader;
std::unique_ptr<SceneLoader> _sceneLoader;
std::unique_ptr<DownloadManager> _downloadManager;
std::unique_ptr<LuaConsole> _console;
std::unique_ptr<ModuleEngine> _moduleEngine;
@@ -215,8 +213,7 @@ private:
properties::StringProperty sourceControlInformation;
} _versionInformation;
bool _scheduledSceneSwitch;
std::string _scenePath;
std::optional<std::string> _scheduledAssetPathToLoad;
struct {
std::vector<std::function<void()>> initialize;
+5 -6
View File
@@ -39,13 +39,11 @@ class AssetLoader;
class Asset : public properties::PropertyOwner {
public:
class Optional : public properties::PropertyOwner {
public:
struct Optional : public properties::PropertyOwner {
Optional(Asset* asset, Asset* owner, bool enabled = false);
private:
properties::BoolProperty _enabled;
Asset* _asset;
Asset* _owner;
properties::BoolProperty enabled;
Asset* const asset;
Asset* const owner;
};
enum class ReadyState : unsigned int {
@@ -84,6 +82,7 @@ public:
bool hasDependants() const;
bool hasInitializedDependants() const;
std::vector<Asset*> optionals() const;
bool hasOptional(Asset* asset) const;
bool optionalIsEnabled(Asset* asset) const;
void setOptionalEnabled(Asset* asset, bool enabled);
+7
View File
@@ -67,6 +67,13 @@ public:
*/
~AssetLoader() = default;
/**
* Load single asset.
* - Import one asset
* - Unimport all other assets
*/
void loadSingleAsset(const std::string& identifier);
/**
* Import an asset
* Add the asset as an optional on the root asset
+1 -1
View File
@@ -30,7 +30,7 @@ return {
-- Sets the scene that is to be loaded by OpenSpace. A scene file is a description
-- of all entities that will be visible during an instance of OpenSpace
Scene = "${ASSETS}/default.scene",
Asset = "${ASSETS}/solarsystem.asset",
-- Scene = "${ASSETS}/newhorizons.scene",
-- Scene = "${ASSETS}/rosetta.scene",
-- Scene = "${ASSETS}/osirisrex.scene",
+2 -2
View File
@@ -1,4 +1,4 @@
/*****************************************************************************************
/*****************************************************************************************
* *
* OpenSpace *
* *
@@ -58,7 +58,7 @@ const string ConfigurationManager::KeyPropertyDocumentation = "PropertyDocumenta
const string ConfigurationManager::KeyKeyboardShortcuts = "KeyboardShortcuts";
const string ConfigurationManager::KeyDocumentation = "Documentation";
const string ConfigurationManager::KeyFactoryDocumentation = "FactoryDocumentation";
const string ConfigurationManager::KeyConfigScene = "Scene";
const string ConfigurationManager::KeyConfigAsset = "Asset";
const string ConfigurationManager::KeyConfigTask = "Task";
const string ConfigurationManager::KeyLogging = "Logging";
+2 -2
View File
@@ -1,4 +1,4 @@
/*****************************************************************************************
/*****************************************************************************************
* *
* OpenSpace *
* *
@@ -42,7 +42,7 @@ documentation::Documentation ConfigurationManager::Documentation() {
"settings that are being used when OpenSpace is started."
},
{
ConfigurationManager::KeyConfigScene,
ConfigurationManager::KeyConfigAsset,
new StringAnnotationVerifier(
"A valid scene file as described in the Scene documentation"
),
+21 -36
View File
@@ -51,7 +51,6 @@
#include <openspace/scene/rotation.h>
#include <openspace/scene/scale.h>
#include <openspace/scene/translation.h>
#include <openspace/scene/sceneloader.h>
#include <openspace/util/resourcesynchronization.h>
#include <openspace/util/factorymanager.h>
@@ -164,8 +163,6 @@ OpenSpaceEngine::OpenSpaceEngine(std::string programName,
properties::StringProperty(VersionInfo, OPENSPACE_VERSION_STRING_FULL),
properties::StringProperty(SourceControlInfo, OPENSPACE_GIT_FULL)
}
, _scheduledSceneSwitch(false)
, _scenePath("")
, _runTime(0.0)
, _shutdown({false, 0.f, 0.f})
, _isFirstRenderingFirstFrame(true)
@@ -339,7 +336,7 @@ void OpenSpaceEngine::create(int argc, char** argv,
}
if (hasCacheConfiguration) {
std::string scene = _engine->configurationManager().value<std::string>(
ConfigurationManager::KeyConfigScene
ConfigurationManager::KeyConfigAsset
);
cacheFolder += "-" + ghoul::filesystem::File(scene).baseName();
}
@@ -410,10 +407,9 @@ void OpenSpaceEngine::create(int argc, char** argv,
sgctArguments.insert(sgctArguments.begin() + 1, SgctConfigArgumentCommand);
sgctArguments.insert(sgctArguments.begin() + 2, absPath(sgctConfigurationPath));
// Set up asset loader and scene loader
// Set up asset loader
_engine->_assetLoader = std::make_unique<AssetLoader>(
*OsEng.scriptEngine().luaState(), OsEng.resourceSynchronizer(), "${ASSETS}", "${SYNC}");
_engine->_sceneLoader = std::make_unique<SceneLoader>(_engine->_assetLoader.get());
_engine->_globalPropertyNamespace->addPropertySubOwner(_engine->_assetLoader->rootAsset());
}
@@ -543,7 +539,7 @@ void OpenSpaceEngine::initialize() {
if (!commandlineArgumentPlaceholders.sceneName.empty()) {
configurationManager().setValue(
ConfigurationManager::KeyConfigScene,
ConfigurationManager::KeyConfigAsset,
commandlineArgumentPlaceholders.sceneName
);
}
@@ -558,8 +554,6 @@ void OpenSpaceEngine::initialize() {
// Load a light and a monospaced font
loadFonts();
std::string scenePath = "";
configurationManager().getValue(ConfigurationManager::KeyConfigScene, scenePath);
_renderEngine->initialize();
@@ -567,18 +561,19 @@ void OpenSpaceEngine::initialize() {
func();
}
scheduleLoadScene(scenePath);
std::string assetPath = "";
configurationManager().getValue(ConfigurationManager::KeyConfigAsset, assetPath);
scheduleLoadSingleAsset(assetPath);
LTRACE("OpenSpaceEngine::initialize(end)");
}
void OpenSpaceEngine::scheduleLoadScene(std::string scenePath) {
_scheduledSceneSwitch = true;
_scenePath = std::move(scenePath);
void OpenSpaceEngine::scheduleLoadSingleAsset(std::string assetPath) {
_scheduledAssetPathToLoad = assetPath;
}
void OpenSpaceEngine::loadScene(const std::string& scenePath) {
void OpenSpaceEngine::loadSingleAsset(const std::string& assetPath) {
LTRACE("OpenSpaceEngine::loadScene(begin)");
windowWrapper().setBarrier(false);
@@ -589,9 +584,8 @@ void OpenSpaceEngine::loadScene(const std::string& scenePath) {
windowWrapper().setBarrier(true);
}
);
if (scenePath != "") {
if (assetPath != "") {
try {
if (_scene) {
_syncEngine->removeSyncables(_timeManager->getSyncables());
@@ -604,34 +598,25 @@ void OpenSpaceEngine::loadScene(const std::string& scenePath) {
_scene = std::make_unique<Scene>();
_renderEngine->setScene(_scene.get());
_sceneLoader->loadScene(_scene.get(), scenePath);
}
catch (const ghoul::FileNotFoundError& e) {
_assetLoader->loadSingleAsset(assetPath);
} catch (const ghoul::FileNotFoundError& e) {
LERRORC(e.component, e.message);
return;
}
catch (const Scene::InvalidSceneError& e) {
} catch (const Scene::InvalidSceneError& e) {
LERRORC(e.component, e.message);
return;
}
catch (const ghoul::RuntimeError& e) {
} catch (const ghoul::RuntimeError& e) {
LERRORC(e.component, e.message);
return;
}
catch (const std::exception& e) {
} catch (const std::exception& e) {
LERROR(e.what());
return;
}
catch (...) {
} catch (...) {
LERROR("Unknown error loading the scene");
return;
}
}
// Initialize the RenderEngine
_renderEngine->setGlobalBlackOutFactor(0.0);
_renderEngine->startFading(1, 3.0);
@@ -1061,17 +1046,17 @@ void OpenSpaceEngine::preSynchronization() {
LTRACE("OpenSpaceEngine::preSynchronization(begin)");
FileSys.triggerFilesystemEvents();
if (_scheduledSceneSwitch) {
loadScene(_scenePath);
_scheduledSceneSwitch = false;
if (_scheduledAssetPathToLoad.has_value()) {
loadSingleAsset(_scheduledAssetPathToLoad.value());
_scheduledAssetPathToLoad.reset();
}
if (_isFirstRenderingFirstFrame) {
_windowWrapper->setSynchronization(false);
}
bool master = _windowWrapper->isMaster();
_syncEngine->preSynchronization(SyncEngine::IsMaster(master));
if (master) {
double dt = _windowWrapper->averageDeltaTime();
+4 -4
View File
@@ -1,4 +1,4 @@
/*****************************************************************************************
/*****************************************************************************************
* *
* OpenSpace *
* *
@@ -73,12 +73,12 @@ void SettingsEngine::initialize() {
// Set interaction to change ConfigurationManager and schedule the load
_scenes.onChange([this, nScenes, sceneDir]() {
if (_scenes == nScenes) {
OsEng.scheduleLoadScene("");
OsEng.scheduleLoadSingleAsset("");
} else {
std::string sceneFile = _scenes.getDescriptionByValue(_scenes);
OsEng.configurationManager().setValue(
ConfigurationManager::KeyConfigScene, sceneFile);
OsEng.scheduleLoadScene(sceneDir + "/" + sceneFile);
ConfigurationManager::KeyConfigAsset, sceneFile);
OsEng.scheduleLoadSingleAsset(sceneDir + "/" + sceneFile);
}
}
);
+10 -11
View File
@@ -278,20 +278,19 @@ bool Asset::hasInitializedDependants() const {
}
// Dependency toggle
Asset::Optional::Optional(Asset* asset, Asset* owner, bool enabled)
Asset::Optional::Optional(Asset* a, Asset* o, bool enable)
: PropertyOwner({ asset->name(), asset->name() })
, _enabled({ "enabled", "Enabled", "Enable optional" }, enabled)
, _asset(asset)
, _owner(owner)
, enabled({ "enabled", "Enabled", "Enable optional" }, enable)
, asset(a)
, owner(o)
{
addProperty(_enabled);
addPropertySubOwner(asset);
_enabled.onChange([this]() {
_owner->setOptionalEnabled(
_asset,
_enabled
addProperty(enabled);
addPropertySubOwner(a);
enabled.onChange([this]() {
owner->setOptionalEnabled(
asset,
enabled
);
});
}
}
+12
View File
@@ -204,6 +204,18 @@ ghoul::filesystem::Directory AssetLoader::currentDirectory() {
return _assetStack.back()->assetDirectory();
}
void AssetLoader::loadSingleAsset(const std::string& identifier) {
Asset* imported = importOptional(identifier, true);
std::vector<Asset*> optionals = _rootAsset->optionals();
// Remove all other optionals
for (auto& optional : optionals) {
if (optional != imported) {
_rootAsset->removeOptional(optional);
}
}
}
void AssetLoader::importAsset(const std::string & identifier) {
ghoul_assert(_assetStack.size() == 1, "Can only import an asset from the root asset");
try {
+2 -2
View File
@@ -1,4 +1,4 @@
/*****************************************************************************************
/*****************************************************************************************
* *
* OpenSpace *
* *
@@ -337,7 +337,7 @@ int loadScene(lua_State* L) {
std::string sceneFile = luaL_checkstring(L, -1);
OsEng.scheduleLoadScene(sceneFile);
OsEng.scheduleLoadSingleAsset(sceneFile);
return 0;
}