mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-07 04:00:37 -06:00
Remove experimental code
This commit is contained in:
@@ -65,36 +65,15 @@ public:
|
||||
std::shared_ptr<Asset> rootAsset();
|
||||
|
||||
bool update();
|
||||
|
||||
//void setTargetAssetState(const std::string& path, Asset::State targetState);
|
||||
//void setTargetAssetState(Asset* asset, Asset::State targetState);
|
||||
//Asset::State currentAssetState(Asset* asset);
|
||||
//Asset::State currentAssetState(const std::string& path);
|
||||
//void clearAllTargetAssets();
|
||||
//std::vector<std::shared_ptr<Asset>> loadedAssets();
|
||||
scripting::LuaLibrary luaLibrary();
|
||||
bool isDone();
|
||||
private:
|
||||
std::shared_ptr<Asset> tryAddAsset(const std::string& path);
|
||||
bool tryRemoveAsset(const std::string& path);
|
||||
void unloadAsset(Asset* asset);
|
||||
bool tryInitializeAsset(Asset& asset);
|
||||
bool tryDeinitializeAsset(Asset& asset);
|
||||
void startSynchronization(Asset& asset);
|
||||
void cancelSynchronization(Asset& asset);
|
||||
|
||||
void assetStateChanged(Asset& asset, Asset::State state);
|
||||
|
||||
std::unordered_map<std::string, bool> _pendingStateChangeCommands;
|
||||
//std::unordered_map<Asset*, AssetState> _stateChangesInProgress;
|
||||
std::unordered_set<Asset*> _pendingInitializations;
|
||||
|
||||
std::unordered_map<Asset*, std::unordered_set<Asset*>> _syncAncestors;
|
||||
std::unordered_map<Asset*, std::unordered_set<Asset*>> _syncDependencies;
|
||||
|
||||
std::unique_ptr<AssetLoader> _assetLoader;
|
||||
AssetLoader::CallbackHandle _addAssetCallbackHandle;
|
||||
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -1141,10 +1141,6 @@ void OpenSpaceEngine::postSynchronizationPreDraw() {
|
||||
writeDocumentations();
|
||||
}
|
||||
|
||||
if (_loadingScreen && _assetManager->isDone()) {
|
||||
_loadingScreen = nullptr;
|
||||
}
|
||||
|
||||
_renderEngine->updateScene();
|
||||
_renderEngine->updateFade();
|
||||
_renderEngine->updateRenderer();
|
||||
|
||||
@@ -58,15 +58,10 @@ void AssetManager::initialize() {
|
||||
|
||||
void AssetManager::deinitialize() {
|
||||
_assetLoader->rootAsset()->deinitialize();
|
||||
|
||||
_assetLoader->removeAssetLoadCallback(_addAssetCallbackHandle);
|
||||
}
|
||||
|
||||
bool AssetManager::update() {
|
||||
// 1. Load assets.
|
||||
// 2. Start/cancel synchronizations
|
||||
// 3. Unload assets.
|
||||
|
||||
// Add assets
|
||||
for (const auto& c : _pendingStateChangeCommands) {
|
||||
const std::string& path = c.first;
|
||||
@@ -76,43 +71,6 @@ bool AssetManager::update() {
|
||||
}
|
||||
}
|
||||
|
||||
// Start/cancel synchronizations and/or deinitialize
|
||||
/*for (const auto& c : _pendingStateChangeCommands) {
|
||||
const std::string& path = c.first;
|
||||
const Asset::State targetState = c.second;
|
||||
|
||||
std::shared_ptr<Asset> asset = _assetLoader->has(path);
|
||||
if (!asset) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Asset::State assetState = asset->state();
|
||||
|
||||
const bool syncedOrSyncing =
|
||||
(assetState == Asset::State::SyncResolved ||
|
||||
assetState == Asset::State::Synchronizing);
|
||||
|
||||
const bool shouldBeSynced =
|
||||
(targetState == Asset::State::SyncResolved ||
|
||||
targetState == Asset::State::Initialized);
|
||||
|
||||
if (shouldBeSynced && !syncedOrSyncing) {
|
||||
startSynchronization(*asset);
|
||||
} else if (!shouldBeSynced && syncedOrSyncing) {
|
||||
cancelSynchronization(*asset);
|
||||
}
|
||||
|
||||
const bool shouldBeInitialized = targetState == Asset::State::Initialized;
|
||||
const bool isInitialized = asset->state() == Asset::State::Initialized;
|
||||
|
||||
if (shouldBeInitialized && !isInitialized) {
|
||||
_pendingInitializations.insert(asset.get());
|
||||
} else {
|
||||
_pendingInitializations.erase(asset.get());
|
||||
tryDeinitializeAsset(*asset);
|
||||
}
|
||||
}*/
|
||||
|
||||
// Remove assets
|
||||
for (const auto& c : _pendingStateChangeCommands) {
|
||||
const std::string& path = c.first;
|
||||
@@ -122,37 +80,10 @@ bool AssetManager::update() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// TODO: Handle state changes
|
||||
/*std::vector<AssetSynchronizer::StateChange> stateChanges =
|
||||
_assetSynchronizer->getStateChanges();
|
||||
|
||||
for (AssetSynchronizer::StateChange& stateChange : stateChanges) {
|
||||
Asset* a = stateChange.asset.get();
|
||||
auto it = _pendingInitializations.find(a);
|
||||
if (it == _pendingInitializations.end()) {
|
||||
continue;
|
||||
}
|
||||
Asset::ReadyState currentState = a->readyState();
|
||||
if (currentState != Asset::ReadyState::Initialized)
|
||||
{
|
||||
_pendingInitializations.erase(it);
|
||||
tryInitializeAsset(*a);
|
||||
}
|
||||
}*/
|
||||
|
||||
_pendingStateChangeCommands.clear();
|
||||
return false;
|
||||
}
|
||||
|
||||
void AssetManager::startSynchronization(Asset&) {
|
||||
// todo: implement
|
||||
}
|
||||
|
||||
void AssetManager::cancelSynchronization(Asset&) {
|
||||
// todo: implement this
|
||||
}
|
||||
|
||||
void AssetManager::assetStateChanged(Asset& asset, Asset::State state) {
|
||||
if (rootAsset()->state() == Asset::State::Initialized) {
|
||||
if (state == Asset::State::Loaded) {
|
||||
@@ -164,109 +95,9 @@ void AssetManager::assetStateChanged(Asset& asset, Asset::State state) {
|
||||
} else {
|
||||
asset.deinitialize();
|
||||
}
|
||||
|
||||
// Todo: Check if assets should start syncing or if they should init.
|
||||
// flags: autoSync, autoInit ?
|
||||
}
|
||||
|
||||
/**
|
||||
* Load or unload asset depening on target state
|
||||
* Return shared pointer to asset if this loads the asset
|
||||
*/
|
||||
/*std::shared_ptr<Asset> AssetManager::updateLoadState(std::string path, AssetState targetState) {
|
||||
const bool shouldBeLoaded = targetState != AssetState::Unloaded;
|
||||
|
||||
const std::shared_ptr<Asset> asset = _assetLoader->loadedAsset(path);
|
||||
const bool isLoaded = asset != nullptr;
|
||||
|
||||
if (isLoaded && !shouldBeLoaded) {
|
||||
_managedAssets.erase(asset.get());
|
||||
_assetLoader->unloadAsset(asset.get());
|
||||
}
|
||||
else if (!isLoaded && shouldBeLoaded) {
|
||||
std::shared_ptr<Asset> loadedAsset = tryLoadAsset(path);
|
||||
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start or cancel synchronizations depending on target state
|
||||
*/
|
||||
/*void AssetManager::updateSyncState(Asset* asset, AssetState targetState) {
|
||||
const bool shouldSync =
|
||||
targetState == AssetState::Synchronized ||
|
||||
targetState == AssetState::Initialized;
|
||||
|
||||
if (shouldSync) {
|
||||
std::vector<std::shared_ptr<Asset>> importedAssets =
|
||||
asset->allAssets();
|
||||
|
||||
for (const auto& a : importedAssets) {
|
||||
_assetSynchronizer->startSync(a);
|
||||
_syncAncestors[a.get()].insert(asset);
|
||||
if (a.get() != asset) {
|
||||
_syncDependencies[asset].insert(a.get());
|
||||
}
|
||||
}
|
||||
_stateChangesInProgress.emplace(
|
||||
asset,
|
||||
_pendingStateChangeCommands[asset->assetFilePath()]
|
||||
);
|
||||
} else {
|
||||
_assetSynchronizer->cancelSync(asset);
|
||||
_syncDependencies[asset].
|
||||
|
||||
// Todo: Also cancel syncing of dependendencies
|
||||
}
|
||||
}
|
||||
|
||||
void AssetManager::handleSyncStateChange(AssetSynchronizer::StateChange stateChange) {
|
||||
|
||||
// Retrieve ancestors that were waiting for this asset to sync
|
||||
const auto it = _syncAncestors.find(stateChange.asset.get());
|
||||
if (it == _syncAncestors.end()) {
|
||||
return; // Should not happen. (No ancestor to this synchronization)
|
||||
}
|
||||
std::unordered_set<Asset*>& ancestors = it->second;
|
||||
|
||||
if (stateChange.state ==
|
||||
AssetSynchronizer::SynchronizationState::Resolved)
|
||||
{
|
||||
|
||||
for (const auto& ancestor : ancestors) {
|
||||
const bool initReady = ancestor->isInitReady();
|
||||
const bool shouldInit =
|
||||
_stateChangesInProgress[ancestor] == AssetState::Initialized;
|
||||
|
||||
if (initReady) {
|
||||
_stateChangesInProgress.erase(ancestor);
|
||||
if (shouldInit) {
|
||||
if (tryInitializeAsset(*ancestor)) {
|
||||
//changedInititializations = true;
|
||||
_managedAssets[ancestor].state = AssetState::Initialized;
|
||||
}
|
||||
else {
|
||||
_managedAssets[ancestor].state = AssetState::InitializationFailed;
|
||||
}
|
||||
}
|
||||
else {
|
||||
_managedAssets[ancestor].state = AssetState::Synchronized;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else if (stateChange.state ==
|
||||
AssetSynchronizer::SynchronizationState::Rejected)
|
||||
{
|
||||
for (const auto& ancestor : ancestors) {
|
||||
_managedAssets[ancestor].state = AssetState::SynchronizationFailed;
|
||||
}
|
||||
}
|
||||
|
||||
_syncAncestors.erase(stateChange.asset.get());
|
||||
}*/
|
||||
|
||||
void AssetManager::add(const std::string& path) {
|
||||
_pendingStateChangeCommands[path] = true;
|
||||
@@ -308,47 +139,10 @@ scripting::LuaLibrary AssetManager::luaLibrary() {
|
||||
{this},
|
||||
"string",
|
||||
""
|
||||
},
|
||||
// Functions for managing assets
|
||||
{
|
||||
"reload",
|
||||
&luascriptfunctions::asset::reload,
|
||||
{this},
|
||||
"string",
|
||||
""
|
||||
},
|
||||
{
|
||||
"synchronize",
|
||||
&luascriptfunctions::asset::synchronize,
|
||||
{this},
|
||||
"string",
|
||||
""
|
||||
},
|
||||
{
|
||||
"resynchronize",
|
||||
&luascriptfunctions::asset::resynchronize,
|
||||
{this},
|
||||
"string",
|
||||
""
|
||||
},
|
||||
{
|
||||
"cancelSynchronization",
|
||||
&luascriptfunctions::asset::cancelSynchronization,
|
||||
{this},
|
||||
"string",
|
||||
""
|
||||
},
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
bool AssetManager::isDone() {
|
||||
return _pendingStateChangeCommands.size() == 0 && _pendingInitializations.size() == 0;
|
||||
}
|
||||
|
||||
void AssetManager::unloadAsset(Asset* asset) {
|
||||
|
||||
}
|
||||
|
||||
std::shared_ptr<Asset> AssetManager::tryAddAsset(const std::string& path) {
|
||||
try {
|
||||
@@ -369,24 +163,4 @@ bool AssetManager::tryRemoveAsset(const std::string& path) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AssetManager::tryInitializeAsset(Asset& asset) {
|
||||
try {
|
||||
asset.initialize();
|
||||
} catch (const ghoul::RuntimeError& e) {
|
||||
LERROR("Error when initializing asset. " << e.component << ": " << e.message);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AssetManager::tryDeinitializeAsset(Asset& asset) {
|
||||
try {
|
||||
asset.deinitialize();
|
||||
} catch (const ghoul::RuntimeError& e) {
|
||||
LERROR("Error when deinitializing asset. " << e.component << ": " << e.message);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -56,24 +56,4 @@ int removeAll(lua_State* state) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int reload(lua_State* state) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int synchronize(lua_State* state) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int resynchronize(lua_State* state) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int initialize(lua_State* state) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cancelSynchronization(lua_State* state) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace openspace::luascriptfunctions
|
||||
|
||||
Reference in New Issue
Block a user