Skip to content

Commit

Permalink
WIP editor preloading model assets
Browse files Browse the repository at this point in the history
  • Loading branch information
enginmanap committed Nov 16, 2024
1 parent 796e70a commit 7f59e0a
Show file tree
Hide file tree
Showing 6 changed files with 354 additions and 325 deletions.
2 changes: 2 additions & 0 deletions src/Assets/Asset.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class Asset {
return assetID;
}

const LoadState& getLoadState() {return loadState;}

virtual ~Asset() = default;
};

Expand Down
56 changes: 30 additions & 26 deletions src/Assets/AssetManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,45 +255,44 @@ class AssetManager {

template<class T>
std::shared_ptr<T> partialLoadAssetAsync(const std::vector<std::string> files) {
std::vector<std::shared_ptr<T>> loadedAssets;
if (assets.count(files) == 0) {
bool loaded = false;
//check if asset is cereal deserialize file.
if(files.size() == 1) {
std::string extension = files[0].substr(files[0].find_last_of(".") + 1);
if (extension == "limonmodel") {

if (assets.count(files) == 0) {
bool loaded = false;
//check if asset is cereal deserialize file.
if(files.size() == 1) {
std::string extension = files[0].substr(files[0].find_last_of(".") + 1);
if (extension == "limonmodel") {
#ifdef CEREAL_SUPPORT
std::ifstream is(files[0], std::ios::binary);
cereal::BinaryInputArchive archive(is);
assets[files] = std::make_pair(std::make_shared<T>(this, nextAssetIndex, files, archive), 0);
nextAssetIndex++;
std::ifstream is(files[0], std::ios::binary);
cereal::BinaryInputArchive archive(is);
assets[files] = std::make_pair(std::make_shared<T>(this, nextAssetIndex, files, archive), 0);
nextAssetIndex++;
#else
std::cerr << "Limon compiled without limonmodel support. Please acquire a release version. Exiting..." << std::endl;
std::cerr << "Compile should define \"CEREAL_SUPPORT\"." << std::endl;
exit(-1);
std::cerr << "Limon compiled without limonmodel support. Please acquire a release version. Exiting..." << std::endl;
std::cerr << "Compile should define \"CEREAL_SUPPORT\"." << std::endl;
exit(-1);
#endif
loaded = true;
}
}
if(!loaded) {
assets[files] = std::make_pair(std::make_shared<T>(this, nextAssetIndex, files), 0);
nextAssetIndex++;
assetLoadCpuQueue.pushBack(assets[files].first);
loaded = true;
}
}
assets[files].second++;
loadedAssets.emplace_back(std::dynamic_pointer_cast<T>(assets[files].first));
if(!loaded) {
assets[files] = std::make_pair(std::make_shared<T>(this, nextAssetIndex, files), 0);
nextAssetIndex++;
assetLoadCpuQueue.pushBack(assets[files].first);
}
}
assets[files].second++;
return std::dynamic_pointer_cast<T>(assets[files].first);

//now load the assets to GPU on main thread
return loadedAssets;
}

bool partialLoadGPUSize(Asset* asset) {
bool partialLoadGPUSide(std::shared_ptr<Asset> asset) {
if(asset->loadState != Asset::LoadState::CPU_LOAD_DONE) {
return false;
}
asset->loadGPUPart();
//now load the assets to GPU on main thread
asset->setLoadState(Asset::LoadState::DONE);
return true;
}

Expand Down Expand Up @@ -327,6 +326,7 @@ class AssetManager {
if(assets[files].first->loadState != Asset::LoadState::DONE) {
//some other thread is working on this, we should block.
while (assets[files].first->loadState != Asset::LoadState::DONE) {
std::cerr << "Partial load and full load clashing, please fix. Will busy wait" << std::endl;
std::this_thread::sleep_for(std::chrono::milliseconds(15));
}
}
Expand Down Expand Up @@ -362,6 +362,10 @@ class AssetManager {
}
}

bool isLoaded(std::vector<std::string> filename) {
return this->assets.find(filename) != this->assets.end();
}

const AvailableAssetsNode* getAvailableAssetsTree() {
return availableAssetsRootNode;
};
Expand Down
Loading

0 comments on commit 7f59e0a

Please sign in to comment.