Fixing some stuff

This commit is contained in:
Dynamitos
2024-07-19 10:42:59 +02:00
parent 3b6eb3ebcc
commit 819b541ff2
14 changed files with 225 additions and 238 deletions
+1 -9
View File
@@ -72,15 +72,7 @@ void FontLoader::import(FontImportArgs args, PFontAsset asset) {
FT_Done_FreeType(ft);
asset->setUsedTextures(std::move(usedTextures));
auto stream = AssetRegistry::createWriteStream(
(std::filesystem::path(asset->getFolderPath()) / asset->getName()).replace_extension("asset").string(), std::ios::binary);
ArchiveBuffer archive;
Serialization::save(archive, FontAsset::IDENTIFIER);
Serialization::save(archive, asset->getName());
Serialization::save(archive, asset->getFolderPath());
asset->save(archive);
archive.writeToStream(stream);
AssetRegistry::saveAsset(asset, FontAsset::IDENTIFIER, asset->getFolderPath(), asset->getName());
asset->setStatus(Asset::Status::Ready);
}
+3 -10
View File
@@ -24,7 +24,7 @@ MaterialLoader::MaterialLoader(Gfx::PGraphics graphics) : graphics(graphics) {
.importPath = "",
},
placeholderAsset);
AssetRegistry::get().assetRoot->materials[""] = std::move(placeholderAsset);
AssetRegistry::get().registerMaterial(std::move(placeholderAsset));
}
MaterialLoader::~MaterialLoader() {}
@@ -213,16 +213,9 @@ void MaterialLoader::import(MaterialImportArgs args, PMaterialAsset asset) {
return;
}
auto stream = AssetRegistry::createWriteStream((std::filesystem::path(asset->folderPath) / asset->getName()).string().append(".asset"),
std::ios::binary);
AssetRegistry::saveAsset(asset, MaterialAsset::IDENTIFIER, asset->getFolderPath(), asset->getName());
ArchiveBuffer archive;
Serialization::save(archive, MaterialAsset::IDENTIFIER);
Serialization::save(archive, asset->getName());
Serialization::save(archive, asset->getFolderPath());
asset->save(archive);
archive.writeToStream(stream);
////co_return;
asset->setStatus(Asset::Status::Ready);
}
PMaterialAsset MaterialLoader::getPlaceHolderMaterial() { return placeholderMaterial; }
+2 -11
View File
@@ -592,16 +592,7 @@ void MeshLoader::import(MeshImportArgs args, PMeshAsset meshAsset) {
meshAsset->meshes = std::move(meshes);
meshAsset->physicsMesh = std::move(collider);
auto stream = AssetRegistry::createWriteStream(
(std::filesystem::path(meshAsset->getFolderPath()) / meshAsset->getName()).replace_extension("asset").string(), std::ios::binary);
ArchiveBuffer archive;
Serialization::save(archive, MeshAsset::IDENTIFIER);
Serialization::save(archive, meshAsset->getName());
Serialization::save(archive, meshAsset->getFolderPath());
meshAsset->save(archive);
archive.writeToStream(stream);
AssetRegistry::saveAsset(meshAsset, MeshAsset::IDENTIFIER, meshAsset->getFolderPath(), meshAsset->getName());
meshAsset->setStatus(Asset::Status::Ready);
std::cout << "Finished loading " << args.filePath << std::endl;
}
+7 -18
View File
@@ -28,7 +28,7 @@ TextureLoader::TextureLoader(Gfx::PGraphics graphics) : graphics(graphics) {
.importPath = "",
},
placeholderAsset);
AssetRegistry::get().assetRoot->textures[""] = std::move(placeholder);
AssetRegistry::get().registerTexture(std::move(placeholder));
}
TextureLoader::~TextureLoader() {}
@@ -138,25 +138,14 @@ void TextureLoader::import(TextureImportArgs args, PTextureAsset textureAsset) {
return;
}
//textureAsset->setTexture(std::move(serialized));
std::string path = (std::filesystem::path(args.importPath) / textureAsset->getName()).string().append(".asset");
auto assetStream = AssetRegistry::createWriteStream(std::move(path), std::ios::binary);
ArchiveBuffer buffer(graphics);
// write identifier
Serialization::save(buffer, TextureAsset::IDENTIFIER);
// write name
Serialization::save(buffer, textureAsset->getName());
// write folder
Serialization::save(buffer, textureAsset->getFolderPath());
// write asset data
//textureAsset->save(buffer);
Serialization::save(buffer, serialized);
buffer.writeToStream(assetStream);
buffer.rewind();
textureAsset->load(buffer);
std::unique_lock l(AssetRegistry::get().assetLock);
AssetRegistry::get().loadAsset(buffer);
textureAsset->setTexture(std::move(serialized));
AssetRegistry::saveAsset(textureAsset, TextureAsset::IDENTIFIER, textureAsset->getFolderPath(), textureAsset->getName());
textureAsset->setStatus(Asset::Status::Ready);
}