Initial environment loading (not working)
This commit is contained in:
@@ -1,18 +1,14 @@
|
||||
#include "AssetRegistry.h"
|
||||
#include "Asset/FontAsset.h"
|
||||
#include "Asset/MaterialAsset.h"
|
||||
#include "Asset/MaterialInstanceAsset.h"
|
||||
#include "Asset/MeshAsset.h"
|
||||
#include "Asset/EnvironmentMapAsset.h"
|
||||
#include "Asset/SVGAsset.h"
|
||||
#include "Asset/TextureAsset.h"
|
||||
#include "FontAsset.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
#include "Graphics/Mesh.h"
|
||||
#include "MaterialAsset.h"
|
||||
#include "MaterialInstanceAsset.h"
|
||||
#include "MeshAsset.h"
|
||||
#include "SVGAsset.h"
|
||||
#include "TextureAsset.h"
|
||||
#include "Asset/TextureAsset.h"
|
||||
#include "Asset/FontAsset.h"
|
||||
#include "Asset/SVGAsset.h"
|
||||
#include "Asset/MeshAsset.h"
|
||||
#include "Asset/MaterialAsset.h"
|
||||
#include "Asset/MaterialInstanceAsset.h"
|
||||
#include "Window/WindowManager.h"
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
@@ -62,6 +58,15 @@ PSVGAsset AssetRegistry::findSVG(std::string_view folderPath, std::string_view f
|
||||
return folder->svgs.at(std::string(filePath));
|
||||
}
|
||||
|
||||
PEnvironmentMapAsset AssetRegistry::findEnvironmentMap(std::string_view folderPath, std::string_view filePath) {
|
||||
std::unique_lock l(get().assetLock);
|
||||
AssetFolder* folder = get().assetRoot;
|
||||
if (!folderPath.empty()) {
|
||||
folder = get().getOrCreateFolder(folderPath);
|
||||
}
|
||||
return folder->envs.at(std::string(filePath));
|
||||
}
|
||||
|
||||
PMaterialAsset AssetRegistry::findMaterial(std::string_view folderPath, std::string_view filePath) {
|
||||
std::unique_lock l(get().assetLock);
|
||||
AssetFolder* folder = get().assetRoot;
|
||||
@@ -100,6 +105,11 @@ void AssetRegistry::registerSVG(OSVGAsset svg) {
|
||||
get().registerSVGInternal(std::move(svg));
|
||||
}
|
||||
|
||||
void AssetRegistry::registerEnvironmentMap(OEnvironmentMapAsset env) {
|
||||
std::unique_lock l(get().assetLock);
|
||||
get().registerEnvironmentMapInternal(std::move(env));
|
||||
}
|
||||
|
||||
void AssetRegistry::registerMaterial(OMaterialAsset material) {
|
||||
std::unique_lock l(get().assetLock);
|
||||
get().registerMaterialInternal(std::move(material));
|
||||
@@ -152,6 +162,9 @@ void AssetRegistry::loadAsset(ArchiveBuffer& buffer) {
|
||||
case SVGAsset::IDENTIFIER:
|
||||
asset = PSVGAsset(folder->svgs.at(name));
|
||||
break;
|
||||
case EnvironmentMapAsset::IDENTIFIER:
|
||||
asset = PEnvironmentMapAsset(folder->envs.at(name));
|
||||
break;
|
||||
default:
|
||||
throw new std::logic_error("Unknown Identifier");
|
||||
}
|
||||
@@ -182,13 +195,9 @@ AssetRegistry::AssetRegistry() : assetRoot(nullptr) {}
|
||||
|
||||
AssetRegistry* AssetRegistry::getInstance() { return _instance; }
|
||||
|
||||
void AssetRegistry::loadRegistry() {
|
||||
get().loadRegistryInternal();
|
||||
}
|
||||
void AssetRegistry::loadRegistry() { get().loadRegistryInternal(); }
|
||||
|
||||
void AssetRegistry::saveRegistry() {
|
||||
get().saveRegistryInternal();
|
||||
}
|
||||
void AssetRegistry::saveRegistry() { get().saveRegistryInternal(); }
|
||||
|
||||
AssetRegistry::AssetFolder* AssetRegistry::getOrCreateFolder(std::string_view fullPath) {
|
||||
AssetFolder* result = assetRoot;
|
||||
@@ -219,7 +228,7 @@ void AssetRegistry::initialize(const std::filesystem::path& _rootFolder, Gfx::PG
|
||||
}
|
||||
|
||||
void AssetRegistry::loadRegistryInternal() {
|
||||
Array<Pair<PAsset, ArchiveBuffer>> peeked;
|
||||
Array<Pair<PAsset, ArchiveBuffer>> peeked;
|
||||
{
|
||||
std::unique_lock l(get().assetLock);
|
||||
peeked = peekFolder(assetRoot);
|
||||
@@ -301,13 +310,16 @@ Pair<PAsset, ArchiveBuffer> AssetRegistry::peekAsset(ArchiveBuffer& buffer) {
|
||||
folder->svgs[name] = new SVGAsset(folderPath, name);
|
||||
asset = PSVGAsset(folder->svgs[name]);
|
||||
break;
|
||||
case EnvironmentMapAsset::IDENTIFIER:
|
||||
folder->envs[name] = new EnvironmentMapAsset(folderPath, name);
|
||||
asset = PEnvironmentMapAsset(folder->envs[name]);
|
||||
break;
|
||||
default:
|
||||
throw new std::logic_error("Unknown Identifier");
|
||||
}
|
||||
return {asset, std::move(buffer)};
|
||||
}
|
||||
|
||||
|
||||
void AssetRegistry::saveRegistryInternal() { saveFolder("", assetRoot); }
|
||||
|
||||
void AssetRegistry::saveFolder(const std::filesystem::path& folderPath, AssetFolder* folder) {
|
||||
@@ -330,6 +342,9 @@ void AssetRegistry::saveFolder(const std::filesystem::path& folderPath, AssetFol
|
||||
for (const auto& [name, svg] : folder->svgs) {
|
||||
saveAsset(PSVGAsset(svg), SVGAsset::IDENTIFIER, folderPath, name);
|
||||
}
|
||||
for (const auto& [name, env] : folder->envs) {
|
||||
saveAsset(PEnvironmentMapAsset(env), EnvironmentMapAsset::IDENTIFIER, folderPath, name);
|
||||
}
|
||||
for (auto& [name, child] : folder->children) {
|
||||
saveFolder(folderPath / name, child);
|
||||
}
|
||||
@@ -357,6 +372,11 @@ void AssetRegistry::registerSVGInternal(OSVGAsset svg) {
|
||||
folder->svgs[svg->getName()] = std::move(svg);
|
||||
}
|
||||
|
||||
void AssetRegistry::registerEnvironmentMapInternal(OEnvironmentMapAsset env) {
|
||||
AssetFolder* folder = getOrCreateFolder(env->getFolderPath());
|
||||
folder->envs[env->getName()] = std::move(env);
|
||||
}
|
||||
|
||||
void AssetRegistry::registerMaterialInternal(OMaterialAsset material) {
|
||||
AssetFolder* folder = getOrCreateFolder(material->getFolderPath());
|
||||
folder->materials[material->getName()] = std::move(material);
|
||||
|
||||
@@ -12,6 +12,7 @@ DECLARE_REF(TextureAsset)
|
||||
DECLARE_REF(FontAsset)
|
||||
DECLARE_REF(SVGAsset)
|
||||
DECLARE_REF(MeshAsset)
|
||||
DECLARE_REF(EnvironmentMapAsset)
|
||||
DECLARE_REF(MaterialAsset)
|
||||
DECLARE_REF(MaterialInstanceAsset)
|
||||
DECLARE_NAME_REF(Gfx, Graphics)
|
||||
@@ -26,6 +27,7 @@ class AssetRegistry {
|
||||
static PTextureAsset findTexture(std::string_view folderPath, std::string_view filePath);
|
||||
static PFontAsset findFont(std::string_view folderPath, std::string_view name);
|
||||
static PSVGAsset findSVG(std::string_view folderPath, std::string_view name);
|
||||
static PEnvironmentMapAsset findEnvironmentMap(std::string_view folder, std::string_view name);
|
||||
static PMaterialAsset findMaterial(std::string_view folderPath, std::string_view filePath);
|
||||
static PMaterialInstanceAsset findMaterialInstance(std::string_view folderPath, std::string_view filePath);
|
||||
|
||||
@@ -33,6 +35,7 @@ class AssetRegistry {
|
||||
static void registerTexture(OTextureAsset texture);
|
||||
static void registerFont(OFontAsset font);
|
||||
static void registerSVG(OSVGAsset svg);
|
||||
static void registerEnvironmentMap(OEnvironmentMapAsset env);
|
||||
static void registerMaterial(OMaterialAsset material);
|
||||
static void registerMaterialInstance(OMaterialInstanceAsset instance);
|
||||
|
||||
@@ -52,6 +55,7 @@ class AssetRegistry {
|
||||
Map<std::string, OTextureAsset> textures;
|
||||
Map<std::string, OFontAsset> fonts;
|
||||
Map<std::string, OSVGAsset> svgs;
|
||||
Map<std::string, OEnvironmentMapAsset> envs;
|
||||
Map<std::string, OMeshAsset> meshes;
|
||||
Map<std::string, OMaterialAsset> materials;
|
||||
Map<std::string, OMaterialInstanceAsset> instances;
|
||||
@@ -75,6 +79,7 @@ class AssetRegistry {
|
||||
void registerTextureInternal(OTextureAsset texture);
|
||||
void registerFontInternal(OFontAsset font);
|
||||
void registerSVGInternal(OSVGAsset svg);
|
||||
void registerEnvironmentMapInternal(OEnvironmentMapAsset env);
|
||||
void registerMaterialInternal(OMaterialAsset material);
|
||||
void registerMaterialInstanceInternal(OMaterialInstanceAsset instance);
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ target_sources(Engine
|
||||
Asset.cpp
|
||||
AssetRegistry.h
|
||||
AssetRegistry.cpp
|
||||
EnvironmentMapAsset.h
|
||||
EnvironmentMapAsset.cpp
|
||||
FontAsset.h
|
||||
FontAsset.cpp
|
||||
LevelAsset.h
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
#include "EnvironmentMapAsset.h"
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
EnvironmentMapAsset::EnvironmentMapAsset() {}
|
||||
|
||||
EnvironmentMapAsset::EnvironmentMapAsset(std::string_view folderPath, std::string_view name) : Asset(folderPath, name) {}
|
||||
|
||||
EnvironmentMapAsset::~EnvironmentMapAsset() {}
|
||||
|
||||
void EnvironmentMapAsset::save(ArchiveBuffer& buffer) const {}
|
||||
|
||||
void EnvironmentMapAsset::load(ArchiveBuffer& buffer) {}
|
||||
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
#include "Asset.h"
|
||||
#include "Graphics/Texture.h"
|
||||
|
||||
namespace Seele {
|
||||
class EnvironmentMapAsset : public Asset {
|
||||
public:
|
||||
static constexpr uint64 IDENTIFIER = 0x80;
|
||||
EnvironmentMapAsset();
|
||||
EnvironmentMapAsset(std::string_view folderPath, std::string_view name);
|
||||
virtual ~EnvironmentMapAsset();
|
||||
virtual void save(ArchiveBuffer& buffer) const override;
|
||||
virtual void load(ArchiveBuffer& buffer) override;
|
||||
private:
|
||||
Gfx::OTextureCube diffuseMap;
|
||||
Gfx::OTextureCube specularMap;
|
||||
friend class EnvironmentLoader;
|
||||
};
|
||||
} // namespace Seele
|
||||
@@ -5,7 +5,7 @@
|
||||
namespace Seele {
|
||||
class LevelAsset : public Asset {
|
||||
public:
|
||||
static constexpr uint64 IDENTIFIER = 0x20;
|
||||
static constexpr uint64 IDENTIFIER = 0x40;
|
||||
LevelAsset();
|
||||
LevelAsset(std::string_view folderPath, std::string_view name);
|
||||
virtual ~LevelAsset();
|
||||
|
||||
@@ -30,6 +30,6 @@ PMaterialInstanceAsset MaterialAsset::instantiate(const InstantiationParameter&
|
||||
asset->setBase(this);
|
||||
PMaterialInstanceAsset ref = asset;
|
||||
AssetRegistry::registerMaterialInstance(std::move(asset));
|
||||
AssetRegistry::saveAsset(ref, MaterialInstanceAsset::IDENTIFIER, ref->getFolderPath(), ref->getName());
|
||||
AssetRegistry::saveAsset(PAsset(ref), MaterialInstanceAsset::IDENTIFIER, ref->getFolderPath(), ref->getName());
|
||||
return ref;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user