diff --git a/SHADE_Engine/src/Assets/SHAssetMacros.h b/SHADE_Engine/src/Assets/SHAssetMacros.h index b84165fb..0b82a0f0 100644 --- a/SHADE_Engine/src/Assets/SHAssetMacros.h +++ b/SHADE_Engine/src/Assets/SHAssetMacros.h @@ -7,8 +7,8 @@ * or disclosure of this file or its contents without the prior * written consent of Digipen Institute of Technology is prohibited ******************************************************************************/ -#ifndef SH_RESOURCE_MACROS_H -#define SH_RESOURCE_MACROS_H +#ifndef SH_ASSET_MACROS_H +#define SH_ASSET_MACROS_H #include #include @@ -37,11 +37,12 @@ typedef unsigned char AssetTypeMeta; typedef FMOD::Sound* SHSound; // Asset Meta Version -#define RESOURCE_META_VER "1.0" +#define ASSET_META_VER "1.0" // Asset type enum -enum class AssetType : AssetTypeMeta +enum class AssetType : int { + INVALID = -1, AUDIO = 0, SHADER, MATERIAL, @@ -54,7 +55,10 @@ enum class AssetType : AssetTypeMeta AUDIO_WAV }; -// RESOURCE EXTENSIONS +//Directory +#define ASSET_ROOT "./Assets/" + +// ASSET EXTENSIONS #define META_EXTENSION ".shmeta" #define IMAGE_EXTENSION ".png" #define AUDIO_EXTENSION ".ogg" @@ -83,7 +87,7 @@ std::string const EXTENSIONS[] = { // Error flags #define FILE_NOT_FOUND_ERR "FILE NOT FOUND" #define META_NOT_FOUND_ERR "META NOT FOUND" -#define RESOURCE_NOT_FOUND_ERR "RESOURCE NOT FOUND" +#define ASSET_NOT_FOUND_ERR "ASSET NOT FOUND" #define EXT_DOES_NOT_EXIST "TYPE DOES NOT HAVE EXTENSION DEFINED" -#endif // !SH_RESOURCE_MACROS_H +#endif // !SH_ASSET_MACROS_H diff --git a/SHADE_Engine/src/Assets/SHAssetManager.cpp b/SHADE_Engine/src/Assets/SHAssetManager.cpp index 65acc232..aaaa78ab 100644 --- a/SHADE_Engine/src/Assets/SHAssetManager.cpp +++ b/SHADE_Engine/src/Assets/SHAssetManager.cpp @@ -43,72 +43,6 @@ namespace SHADE return result; } - /**************************************************************************** - * Generate path relative to exe - * - * \param p - std::filesystem::path containing file - * \return std::filesystem::path - containing full relative path - ****************************************************************************/ - AssetPath SHAssetManager::GenerateLocalPath(AssetPath path) noexcept - { - if (!IsRecognised(path.extension().string().c_str())) - { - //TODO:ASSERT UNRECOGNISED FILE TYPE - return std::filesystem::path(); - } - - AssetType type = SHAssetMetaHandler::GetTypeFromExtension(path.extension().string().c_str()); - std::string folder; - switch (type) - { - case AssetType::AUDIO: - folder = AUDIO_FOLDER; - break; - case AssetType::AUDIO_WAV: - folder = AUDIO_FOLDER; - break; - case AssetType::IMAGE: - folder = IMAGES_FOLDER; - break; - default: - //TODO:ASSERT UNSUPPORTED FILE TYPE - return std::filesystem::path(); - } - - return std::filesystem::path(RESOURCE_ROOT + folder + path.filename().string()); - } - - /**************************************************************************** - * \brief Deallocates all memory used by image data - ****************************************************************************/ - void SHAssetManager::UnloadImages() noexcept - { - for (auto& [key, value] : imageData) - { - stbi_image_free(value.data); - } - - imageData.clear(); - } - - bool SHAssetManager::UpdateSpriteSetIndices(std::shared_ptr& set) noexcept - { - return SHSpriteSetLibrary::UpdateIndicesAuto(set); - } - - bool SHAssetManager::IsRecognised(char const* ext) noexcept - { - for (auto const& e : EXTENSIONS) - { - if (strcmp(ext, e.c_str()) == 0) - { - return true; - } - } - - return false; - } - /**************************************************************************** * \brief Deallocate all memory used by resource data ****************************************************************************/ @@ -118,7 +52,6 @@ namespace SHADE { SHAssetMetaHandler::WriteMetaData(meta, pathRegistry[meta.GetID()].string().append(META_EXTENSION)); } - UnloadImages(); } /**************************************************************************** @@ -139,6 +72,26 @@ namespace SHADE } } + AssetPath SHAssetManager::GenerateLocalPath(AssetPath path) noexcept + { + if (!IsRecognised(path.extension().string().c_str())) + { + //TODO:ASSERT UNRECOGNISED FILE TYPE + return std::filesystem::path(); + } + + AssetType type = SHAssetMetaHandler::GetTypeFromExtension(path.extension().string().c_str()); + std::string folder; + switch (type) + { + default: + //TODO:ASSERT UNSUPPORTED FILE TYPE + return std::filesystem::path(); + } + + return std::filesystem::path(ASSET_ROOT + folder + path.filename().string()); + } + std::vector SHAssetManager::GetIDFromNames(std::initializer_list const& files) noexcept { std::vector result; @@ -256,7 +209,7 @@ namespace SHADE /**************************************************************************** * \brief Create record for new resource. CAN ONLY CREATE FOR CUSTOM - * RESOURCES CREATED BY THE ENGINE. + * ASSETS CREATED BY THE ENGINE. * * \param type of resource * \param name of resource @@ -268,19 +221,16 @@ namespace SHADE SHAssetMeta meta; meta.SetID(id); meta.SetType(type); - meta.SetVersion(RESOURCE_META_VER); + meta.SetVersion(ASSET_META_VER); std::string folder; switch (type) { - case AssetType::SPRITE_SET: - folder = SPRITE_SET_FOLDER; - break; default: folder = ""; break; } - AssetPath path{ RESOURCE_ROOT + folder + name + SHAssetMetaHandler::GetExtensionFromType(type) }; + AssetPath path{ ASSET_ROOT + folder + name + SHAssetMetaHandler::GetExtensionFromType(type) }; metaCollection.push_back(meta); pathRegistry[id] = path; @@ -340,7 +290,7 @@ namespace SHADE std::vector metaFiles; std::vector resourceFiles; - SHFileSystem::LoadAllFiles(metaFiles, resourceFiles); + //SHFileSystem::LoadAllFiles(metaFiles, resourceFiles); //std::vector resourceFilesVerified; std::vector resourceFilesNew; @@ -378,404 +328,6 @@ namespace SHADE } - /**************************************************************************** - * \param Asset ID to image resource - - * \brief Gets image raw data from provided ID. - ****************************************************************************/ - SHImageRawData const* SHAssetManager::GetImageRawData(AssetID const& id) noexcept - { - if (imageData.find(id) == imageData.end()) - { - // Error resource does not exist - return 0; - } - else - { - return &imageData[id]; - } - } - - /**************************************************************************** - * \param resource ID - - * \brief Gets image dimensions of image file - ****************************************************************************/ - SHUMathVec2i SHAssetManager::GetImageDimensions(AssetID const& image) noexcept - { - SHImageRawData const* const data = GetImageRawData(image); - if (data != nullptr) - { - return SHUMathVec2i{ data->width, data->height }; - } - return SHUMathVec2i(); - } - - /**************************************************************************** - * \param vector containing resource IDs - - * \brief Checks if all images referred to by resource IDs have the same - * dimensions. To be used when checking images in the same batch - ****************************************************************************/ - bool SHAssetManager::MatchImageFiles(std::vector const& files) noexcept - { - if (files.size() == 0) - { - std::cout << "Nothing to compare. Image files list is empty or doesn't contain enough to compare. " << std::endl; - return false; - } - - if (!imageData.contains(*files.begin())) - { - std::cout << "Comparison failed. " << *files.begin() << "does not exist in the image library." << std::endl; - return false; - } - - auto const& firstElement = GetImageRawData(*files.begin()); - for (auto it = files.begin() + 1; it < files.end(); ++it) - { - if (imageData.contains(*it)) - { - if (firstElement->CompareProperties(*GetImageRawData(*it)) == false) - { - std::cout << "Comparison failed. Not all images are the same. " << std::endl; - return false; - } - } - else - { - std::cout << "Comparison failed. " << *files.begin() << "does not exist in the image library." << std::endl; - return false; - } - } - return true; - } - - /**************************************************************************** - * \brief Create sprite set with single image. - * - * \param imageName - file name of image - * \return result of creation - ****************************************************************************/ - bool SHAssetManager::AddSpriteSet(std::string const& imageName) noexcept - { - if (spriteSetNameRegistry.find(imageName) == spriteSetNameRegistry.end()) - { - std::shared_ptr ptr = SHSpriteSetLibrary::AddSpriteSet(imageName); - if (ptr != nullptr) - { - AssetID id{ CreateNewAsset(AssetType::SPRITE_SET, imageName) }; - ptr->SetImageRef(filenameRegistry[imageName]); - spriteSetData[id] = ptr; - spriteSetNameRegistry[imageName] = id; - return true; - } - } - return false; - } - - /**************************************************************************** - * \brief Create sprite set with single image (Asset ID). - * - * \param id - resource id of single image - * \return resource id of sprite set created - ****************************************************************************/ - AssetID SHAssetManager::AddSpriteSet(AssetID id) noexcept - { - AssetName newName{ idNameRegistry[id] }; - newName += "SpriteSet"; - if (spriteSetNameRegistry.find(newName) == spriteSetNameRegistry.end()) - { - AssetID ssID{ CreateEmptySpriteSet(newName) }; - if (ssID) - { - std::shared_ptr ptr = spriteSetData[ssID]; - if (ptr != nullptr) - { - ptr->SetImageRef(id); - UpdateSpriteSetIndices(ptr); - SHSpriteSetLibrary::WriteSpriteSet( - ptr, - pathRegistry[ssID] - ); - return ssID; - } - } - } - - return 0; - } - - /**************************************************************************** - * \brief Create empty sprite set without any image references. - * - * \param setName - std::string sprite set name - * \return resource ID of sprite set created - ****************************************************************************/ - AssetID SHAssetManager::CreateEmptySpriteSet(std::string setName) noexcept - { - if (spriteSetNameRegistry.find(setName) == spriteSetNameRegistry.end()) - { - std::shared_ptr ptr = std::make_shared(setName); - if (ptr != nullptr) - { - AssetID id{ CreateNewAsset(AssetType::SPRITE_SET, setName) }; - spriteSetData[id] = ptr; - spriteSetNameRegistry[setName] = id; - return id; - } - } - return 0; - } - - /**************************************************************************** - * \brief Get ID of sprite set by name. - * - * \param name - name of sprite set std::string - * \return resource iD - ****************************************************************************/ - AssetID SHAssetManager::GetSpriteSet(std::string name) noexcept - { - if (spriteSetNameRegistry.find(name) == spriteSetNameRegistry.end()) - { - return 0; - } - - return spriteSetNameRegistry[name]; - } - - /**************************************************************************** - * \brief Get name of sprite set from resource ID. - * - * \param id - resource id - * \return std::string sprite set name - ****************************************************************************/ - std::string SHAssetManager::GetSpriteSetName(AssetID id) noexcept - { - for (auto const& entry : spriteSetNameRegistry) - { - if (entry.second == id) - { - return entry.first; - } - } - - return std::string("NO SUCH SPRITE SET"); - } - - /**************************************************************************** - * \brief Get data of sprite set with sprite set name. - * - * \param name - std::string sprite set name - * \return pointer to sprite set - ****************************************************************************/ - std::shared_ptr SHAssetManager::GetSpriteSetData(std::string name) noexcept - { - if (spriteSetNameRegistry.find(name) == spriteSetNameRegistry.end()) - { - return nullptr; - } - return spriteSetData[spriteSetNameRegistry[name]]; - } - - /**************************************************************************** - * \brief Get data of sprite set with sprite set resource id. - * - * \param id - sprite set resource id - * \return pointer to sprite set - ****************************************************************************/ - std::shared_ptr SHAssetManager::GetSpriteSetData(AssetID id) noexcept - { - return spriteSetData[id]; - } - - /**************************************************************************** - * \brief Add event to frame in sprite set. - * - * \param spriteSet - sprite set resource ID - * \param evt - pointer to method in script class - * \param soh - script object handle to script instance object - * \param frame - target frame in sprite set - ****************************************************************************/ - void SHAssetManager::AddSpriteEvent(AssetID spriteSet, MonoMethod* evt, uint32_t soh, size_t frame) noexcept - { - SHSpriteSet& set = *spriteSetData[spriteSet]; - set.ModifyFrameEvent(static_cast(frame), evt, soh); - } - - /**************************************************************************** - * \brief Remove event from frame in sprite set. - * - * \param spriteSet - sprite set resource iD - * \param frame - target frame - ****************************************************************************/ - void SHAssetManager::RemoveSpriteEvent(AssetID spriteSet, size_t frame) noexcept - { - SHSpriteSet& set = *spriteSetData[spriteSet]; - set.ModifyFrameEvent(static_cast(frame), nullptr, 0); - } - - /**************************************************************************** - * \brief Write sprite set to memory in system. - * - * \param id - sprite set resource id - ****************************************************************************/ - void SHAssetManager::SaveSpriteSet(AssetID id) noexcept - { - SHAssetMeta meta; - for (auto const& met : metaCollection) - { - if (met.GetID() == id) - { - meta = met; - break; - } - } - SHSpriteSetLibrary::WriteSpriteSet( - spriteSetData[id], - pathRegistry[id] - ); - } - - /**************************************************************************** - * \brief Update all texture layer indices in sprite set. - ****************************************************************************/ - void SHAssetManager::UpdateAllSpriteSets() noexcept - { - for (auto& data : spriteSetData) - { - SHSpriteSetLibrary::UpdateIndicesAuto(data.second); - } - } - - std::shared_ptr SHAssetManager::GetAtlas(AssetID id) noexcept - { - auto const it = spriteSetData.find(id); - if (it == spriteSetData.end()) - { - return nullptr; - } - - return it->second->GetAtlasData(); - } - - bool SHAssetManager::SliceSpriteFixed(AssetID id, uint32_t cols, uint32_t rows) noexcept - { - std::shared_ptr atlas = nullptr; - - auto const it = spriteSetData.find(id); - if (it == spriteSetData.end()) - { - // TODO error log no sprite set found for data - return false; - } - else - { - atlas = std::make_shared(SHAtlasSlicer::FixedSlice(idNameRegistry[id], imageData[id], cols, rows)); - } - - std::vector slices; - slices.reserve(atlas->slices.size()); - for (auto const& slice : atlas->slices) - { - AssetID newID{ GenerateAssetID() }; - typeRegistry[newID] = AssetType::IMAGE; - idNameRegistry[newID] = slice.name; - nameIDRegistry[slice.name] = newID; - spriteSetNameRegistry[slice.name] = newID; - - slices.emplace_back(newID); - } - - auto& spriteSet = spriteSetData[id]; - spriteSet->SetAtlas(true); - spriteSet->SetIsAnimation(true); - spriteSet->SetAtlasData(atlas); - SHSpriteSetLibrary::UpdateIndicesAuto(spriteSet); - - SHSpriteSetLibrary::WriteSpriteSet( - spriteSet, - pathRegistry[id] - ); - - return true; - } - - bool SHAssetManager::SliceSpriteAuto(AssetID id) noexcept - { - std::shared_ptr atlas = nullptr; - auto const it = spriteSetData.find(id); - if (it == spriteSetData.end()) - { - // TODO error log sprite set does not exist - return false; - } - else - { - atlas = std::make_shared(SHAtlasSlicer::AutoSlice(idNameRegistry[id], imageData[id])); - } - - auto& spriteSet = spriteSetData[id]; - spriteSet->SetAtlas(true); - spriteSet->SetIsAnimation(false); - std::vector slices; - slices.reserve(atlas->slices.size()); - for (auto const& slice : atlas->slices) - { - AssetID newID{ GenerateAssetID() }; - - std::shared_ptr newSpriteSet = std::make_shared(slice.name); - newSpriteSet->SetImageRef(id); - SHSpriteSetLibrary::UpdateIndicesAuto(newSpriteSet); - spriteSetData[newID] = newSpriteSet; - typeRegistry[newID] = AssetType::IMAGE; - idNameRegistry[newID] = slice.name; - nameIDRegistry[slice.name] = newID; - spriteSetNameRegistry[slice.name] = newID; - - slices.emplace_back(newID); - } - spriteSet->SetAtlasData(atlas); - spriteSet->SetNonFixedSlicesID(slices); - - return true; - } - - /**************************************************************************** - * \param Pointer to FMOD system - * \param reference to vector containing class holding sound data - - * \brief Loads all audio resource data into memory and fmod system - ****************************************************************************/ - void SHAssetManager::LoadAllAudio(FMOD::System* system, std::unordered_map& soundList) - { - audioSystem = system; - audioSoundList = &soundList; - - for (auto const& meta : metaCollection) - { - if (meta.GetType() == AssetType::AUDIO || meta.GetType() == AssetType::AUDIO_WAV) - { - char name[256], newName[256]; - SHSound sound; - system->createSound(pathRegistry[meta.GetID()].string().c_str(), FMOD_LOOP_NORMAL | FMOD_3D, nullptr, &sound); - - sound->getName(newName, 256); - std::vector::size_type i = 0; - for (auto& snd : soundList) - { - snd.second->getName(name, 256); - if (strcmp(name, newName) == 0) // sound already exists in soundList - { - sound->release(); - } - ++i; - } - soundList.emplace(meta.GetID(),sound); - } - } - } - /**************************************************************************** * \param Path for meta data file * \param Path for resource file @@ -806,7 +358,7 @@ namespace SHADE SHAssetMeta meta; meta.SetID(GenerateAssetID()); meta.SetType(SHAssetMetaHandler::GetTypeFromExtension(resource.extension().string())); - meta.SetVersion(RESOURCE_META_VER); + meta.SetVersion(ASSET_META_VER); metaCollection.push_back(meta); pathRegistry.emplace(meta.GetID(), resource); @@ -829,17 +381,6 @@ namespace SHADE { RetrieveAssets(); LoadAllData(); - - //SHShaderLibrary::Load(); - SHShaderLibrary::Load(); - - // Load all the default meshes - SHMeshLibrary::Load(); - - // Initialize all array textures - SHTexture2DArrayContainer::Init(); - - UpdateAllSpriteSets(); } /**************************************************************************** @@ -849,65 +390,12 @@ namespace SHADE { for (auto const& meta : metaCollection) { - if (meta.GetType() == AssetType::IMAGE) - { - SHImageRawData data; - std::string string{ pathRegistry[meta.GetID()].string() }; - SHImageLibrary::LoadImageFromFile(string, data); - imageData.emplace(meta.GetID(), data); - } - else if (meta.GetType() == AssetType::SPRITE_SET) - { - std::shared_ptr data = SHSpriteSetLibrary::LoadSpriteSet(pathRegistry[meta.GetID()]); - UpdateSpriteSetIndices(data); - spriteSetNameRegistry[data->GetSpriteSetName()] = meta.GetID(); - spriteSetData.emplace(meta.GetID(), data); - } - else if (meta.GetType() == AssetType::WAYPOINTS_C) - { - std::shared_ptr data = SHWaypointLibrary::LoadWaypointCollection(pathRegistry[meta.GetID()]); - waypointData.emplace(meta.GetID(), data); - } } } void SHAssetManager::LoadData(AssetID id) noexcept { AssetType type{ typeRegistry[id] }; - if (type == AssetType::IMAGE) - { - SHImageRawData data; - std::string string{ pathRegistry[id].string() }; - SHImageLibrary::LoadImageFromFile(string, data); - imageData.emplace(id, data); - SHTexture2DArrayContainer::AddImageToTexture(imageData[id], idNameRegistry[id]); - } - else if (type == AssetType::AUDIO || type == AssetType::AUDIO_WAV) - { - char name[256], newName[256]; - SHSound sound; - audioSystem->createSound(pathRegistry[id].string().c_str(), FMOD_LOOP_NORMAL | FMOD_3D, nullptr, &sound); - - sound->getName(newName, 256); - std::vector::size_type i = 0; - for (auto& snd : *audioSoundList) - { - snd.second->getName(name, 256); - if (strcmp(name, newName) == 0) // sound already exists in soundList - { - sound->release(); - } - ++i; - } - audioSoundList->emplace(id,sound); - } - else if (type == AssetType::SPRITE_SET) - { - std::shared_ptr data = SHSpriteSetLibrary::LoadSpriteSet(pathRegistry[id]); - UpdateSpriteSetIndices(data); - spriteSetNameRegistry[data->GetSpriteSetName()] = id; - spriteSetData.emplace(id, data); - } } /**************************************************************************** @@ -918,7 +406,8 @@ namespace SHADE std::vector metaFiles; std::vector resourceFiles; - SHFileSystem::LoadAllFiles(metaFiles, resourceFiles); + //TODO: Write new function for file manager to loop through all files + //SHFileSystem::LoadAllFiles(metaFiles, resourceFiles); for (auto const& meta : metaFiles) { diff --git a/SHADE_Engine/src/Assets/SHAssetManager.h b/SHADE_Engine/src/Assets/SHAssetManager.h index 16375b4b..217c64ec 100644 --- a/SHADE_Engine/src/Assets/SHAssetManager.h +++ b/SHADE_Engine/src/Assets/SHAssetManager.h @@ -30,13 +30,7 @@ namespace SHADE ****************************************************************************/ static AssetID GenerateAssetID() noexcept; - /**************************************************************************** - * Generate path relative to exe - * - * \param p - std::filesystem::path containing file - * \return std::filesystem::path - containing full relative path - ****************************************************************************/ - static AssetPath GenerateLocalPath(AssetPath p) noexcept; + static AssetPath GenerateLocalPath(AssetPath path) noexcept; /**************************************************************************** * \brief Deallocate all memory used by resource data diff --git a/SHADE_Engine/src/Assets/SHAssetMeta.cpp b/SHADE_Engine/src/Assets/SHAssetMeta.cpp index e8608159..60fc45d0 100644 --- a/SHADE_Engine/src/Assets/SHAssetMeta.cpp +++ b/SHADE_Engine/src/Assets/SHAssetMeta.cpp @@ -1,21 +1,21 @@ /****************************************************************************** - * \file SHResourceMeta.cpp + * \file SHAssetMeta.cpp * \author Loh Xiao Qi - * \brief Implementation for SHResourceMeta.h + * \brief Implementation for SHAssetMeta.h * * \copyright Copyright (c) 2021 Digipen Institute of Technology. Reproduction * or disclosure of this file or its contents without the prior * written consent of Digipen Institute of Technology is prohibited ******************************************************************************/ #include "SHpch.h" -#include "SHResourceMeta.h" +#include "SHAssetMeta.h" namespace SHADE { /**************************************************************************** * \brief Default constructor ****************************************************************************/ - SHResourceMeta::SHResourceMeta() noexcept : id{ 0 }, type{ResourceType::INVALID} + SHAssetMeta::SHAssetMeta() noexcept : id{ 0 }, type{AssetType::INVALID} { } @@ -25,7 +25,7 @@ namespace SHADE * \brief copy constructor ****************************************************************************/ - SHResourceMeta::SHResourceMeta(SHResourceMeta const& ref) noexcept + SHAssetMeta::SHAssetMeta(SHAssetMeta const& ref) noexcept { ver = ref.ver; id = ref.id; @@ -37,7 +37,7 @@ namespace SHADE * \brief copy assignment operator overload ****************************************************************************/ - SHResourceMeta& SHResourceMeta::operator=(SHResourceMeta const& ref) noexcept + SHAssetMeta& SHAssetMeta::operator=(SHAssetMeta const& ref) noexcept { ver = ref.ver; id = ref.id; @@ -51,7 +51,7 @@ namespace SHADE * \brief Set meta version for data file ****************************************************************************/ - void SHResourceMeta::SetVersion(ResourceMetaVersion vers) noexcept + void SHAssetMeta::SetVersion(AssetMetaVersion vers) noexcept { ver = vers; } @@ -61,7 +61,7 @@ namespace SHADE * \brief Set ID ****************************************************************************/ - void SHResourceMeta::SetID(ResourceID idin) noexcept + void SHAssetMeta::SetID(AssetID idin) noexcept { this->id = idin; } @@ -69,9 +69,9 @@ namespace SHADE /**************************************************************************** * \param Enum class value - * \brief Set Resource Type + * \brief Set Asset Type ****************************************************************************/ - void SHResourceMeta::SetType(ResourceType rType) noexcept + void SHAssetMeta::SetType(AssetType rType) noexcept { this->type = rType; } @@ -79,7 +79,7 @@ namespace SHADE /**************************************************************************** * \brief Get version ****************************************************************************/ - ResourceMetaVersion SHResourceMeta::GetVersion() const noexcept + AssetMetaVersion SHAssetMeta::GetVersion() const noexcept { return ver; } @@ -87,7 +87,7 @@ namespace SHADE /**************************************************************************** * \brief Get ID ****************************************************************************/ - ResourceID SHResourceMeta::GetID() const noexcept + AssetID SHAssetMeta::GetID() const noexcept { return id; } @@ -95,7 +95,7 @@ namespace SHADE /**************************************************************************** * \brief Get resource type ****************************************************************************/ - ResourceType SHResourceMeta::GetType() const noexcept + AssetType SHAssetMeta::GetType() const noexcept { return type; } diff --git a/SHADE_Engine/src/Assets/SHAssetMetaHandler.cpp b/SHADE_Engine/src/Assets/SHAssetMetaHandler.cpp index 9493f56c..d18869a9 100644 --- a/SHADE_Engine/src/Assets/SHAssetMetaHandler.cpp +++ b/SHADE_Engine/src/Assets/SHAssetMetaHandler.cpp @@ -35,7 +35,13 @@ namespace SHADE ****************************************************************************/ AssetType SHAssetMetaHandler::GetTypeFromExtension(AssetExtension ext) noexcept { - for (int i{0}; i < EXTENSIONS->size()) + for (int i{0}; i < EXTENSIONS->size(); ++i) + { + if (ext == EXTENSIONS[i]) + { + return static_cast(i); + } + } } /**************************************************************************** @@ -45,27 +51,7 @@ namespace SHADE ****************************************************************************/ AssetExtension SHAssetMetaHandler::GetExtensionFromType(AssetType type) noexcept { - switch (type) - { - case AssetType::AUDIO: - return AUDIO_EXTENSION; - case AssetType::AUDIO_WAV: - return AUDIO_WAV_EXTENSION; - case AssetType::IMAGE: - return IMAGE_EXTENSION; - case AssetType::SPRITE_SET: - return SPRITE_SET_EXTENSION; - case AssetType::SCRIPT: - return SCRIPT_EXTENSION; - case AssetType::WAYPOINTS_C: - return WAYPOINT_EXTENSION; - case AssetType::PREFAB: - return PREFAB_EXTENSION; - default: - break; - } - - return EXT_DOES_NOT_EXIST; + return EXTENSIONS[static_cast(type)]; } /**************************************************************************** @@ -100,7 +86,7 @@ namespace SHADE std::stringstream typeStream{ line }; AssetTypeMeta type; typeStream >> type; - meta.SetType(SHAssetMetaHandler::GetTypeFromString(type)); + meta.SetType(static_cast(type)); metaFile.close(); @@ -124,7 +110,7 @@ namespace SHADE metaFile << "Meta Version: " << meta.GetVersion() << "\n"; metaFile << "ID: " << meta.GetID() << "\n"; - metaFile << "Type: " << GetStringFromType(meta.GetType()) << std::endl; + metaFile << "Type: " << static_cast(meta.GetType()) << std::endl; metaFile.close(); }