SP3-102 Initial port of 200 resource manager into 300 Asset manager
This commit is contained in:
parent
cc2adcb2ab
commit
1cabcefe0f
|
@ -102,6 +102,10 @@
|
||||||
</Lib>
|
</Lib>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ClInclude Include="src\Assets\SHAssetMacros.h" />
|
||||||
|
<ClInclude Include="src\Assets\SHAssetManager.h" />
|
||||||
|
<ClInclude Include="src\Assets\SHAssetMeta.h" />
|
||||||
|
<ClInclude Include="src\Assets\SHAssetMetaHandler.h" />
|
||||||
<ClInclude Include="src\Engine\ECS_Base\Components\SHComponent.h" />
|
<ClInclude Include="src\Engine\ECS_Base\Components\SHComponent.h" />
|
||||||
<ClInclude Include="src\Engine\ECS_Base\Components\SHComponentGroup.h" />
|
<ClInclude Include="src\Engine\ECS_Base\Components\SHComponentGroup.h" />
|
||||||
<ClInclude Include="src\Engine\ECS_Base\Entity\SHEntity.h" />
|
<ClInclude Include="src\Engine\ECS_Base\Entity\SHEntity.h" />
|
||||||
|
@ -183,9 +187,9 @@
|
||||||
<ClInclude Include="src\Resource\Handle.h" />
|
<ClInclude Include="src\Resource\Handle.h" />
|
||||||
<ClInclude Include="src\Resource\ResourceLibrary.h" />
|
<ClInclude Include="src\Resource\ResourceLibrary.h" />
|
||||||
<ClInclude Include="src\Resource\SparseSet.h" />
|
<ClInclude Include="src\Resource\SparseSet.h" />
|
||||||
<ClInclude Include="src\Scene\SHSceneGraph.h" />
|
|
||||||
<ClInclude Include="src\SHpch.h" />
|
<ClInclude Include="src\SHpch.h" />
|
||||||
<ClInclude Include="src\Scene\SHScene.h" />
|
<ClInclude Include="src\Scene\SHScene.h" />
|
||||||
|
<ClInclude Include="src\Scene\SHSceneGraph.h" />
|
||||||
<ClInclude Include="src\Scene\SHSceneManager.h" />
|
<ClInclude Include="src\Scene\SHSceneManager.h" />
|
||||||
<ClInclude Include="src\Tools\SHException.h" />
|
<ClInclude Include="src\Tools\SHException.h" />
|
||||||
<ClInclude Include="src\Tools\SHExceptionHandler.h" />
|
<ClInclude Include="src\Tools\SHExceptionHandler.h" />
|
||||||
|
@ -193,6 +197,9 @@
|
||||||
<ClInclude Include="src\Tools\SHUtilities.h" />
|
<ClInclude Include="src\Tools\SHUtilities.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ClCompile Include="src\Assets\SHAssetManager.cpp" />
|
||||||
|
<ClCompile Include="src\Assets\SHAssetMeta.cpp" />
|
||||||
|
<ClCompile Include="src\Assets\SHAssetMetaHandler.cpp" />
|
||||||
<ClCompile Include="src\Engine\ECS_Base\Components\SHComponent.cpp" />
|
<ClCompile Include="src\Engine\ECS_Base\Components\SHComponent.cpp" />
|
||||||
<ClCompile Include="src\Engine\ECS_Base\Components\SHComponentGroup.cpp" />
|
<ClCompile Include="src\Engine\ECS_Base\Components\SHComponentGroup.cpp" />
|
||||||
<ClCompile Include="src\Engine\ECS_Base\Entity\SHEntity.cpp" />
|
<ClCompile Include="src\Engine\ECS_Base\Entity\SHEntity.cpp" />
|
||||||
|
@ -253,11 +260,11 @@
|
||||||
<ClCompile Include="src\Math\Vector\SHVec2.cpp" />
|
<ClCompile Include="src\Math\Vector\SHVec2.cpp" />
|
||||||
<ClCompile Include="src\Math\Vector\SHVec3.cpp" />
|
<ClCompile Include="src\Math\Vector\SHVec3.cpp" />
|
||||||
<ClCompile Include="src\Math\Vector\SHVec4.cpp" />
|
<ClCompile Include="src\Math\Vector\SHVec4.cpp" />
|
||||||
<ClCompile Include="src\Scene\SHSceneGraph.cpp" />
|
|
||||||
<ClCompile Include="src\Resource\ResourceLibrary.cpp" />
|
<ClCompile Include="src\Resource\ResourceLibrary.cpp" />
|
||||||
<ClCompile Include="src\SHpch.cpp">
|
<ClCompile Include="src\SHpch.cpp">
|
||||||
<PrecompiledHeader>Create</PrecompiledHeader>
|
<PrecompiledHeader>Create</PrecompiledHeader>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="src\Scene\SHSceneGraph.cpp" />
|
||||||
<ClCompile Include="src\Scene\SHSceneManager.cpp" />
|
<ClCompile Include="src\Scene\SHSceneManager.cpp" />
|
||||||
<ClCompile Include="src\Tools\SHException.cpp" />
|
<ClCompile Include="src\Tools\SHException.cpp" />
|
||||||
<ClCompile Include="src\Tools\SHExceptionHandler.cpp" />
|
<ClCompile Include="src\Tools\SHExceptionHandler.cpp" />
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Filter Include="Assets">
|
||||||
|
<UniqueIdentifier>{3824E0A7-24C6-0A7E-0D81-1ED2F9C191CE}</UniqueIdentifier>
|
||||||
|
</Filter>
|
||||||
<Filter Include="Engine">
|
<Filter Include="Engine">
|
||||||
<UniqueIdentifier>{DBC7D3B0-C769-FE86-B024-12DB9C6585D7}</UniqueIdentifier>
|
<UniqueIdentifier>{DBC7D3B0-C769-FE86-B024-12DB9C6585D7}</UniqueIdentifier>
|
||||||
</Filter>
|
</Filter>
|
||||||
|
@ -117,6 +120,18 @@
|
||||||
</Filter>
|
</Filter>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ClInclude Include="src\Assets\SHAssetMacros.h">
|
||||||
|
<Filter>Assets</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="src\Assets\SHAssetManager.h">
|
||||||
|
<Filter>Assets</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="src\Assets\SHAssetMeta.h">
|
||||||
|
<Filter>Assets</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="src\Assets\SHAssetMetaHandler.h">
|
||||||
|
<Filter>Assets</Filter>
|
||||||
|
</ClInclude>
|
||||||
<ClInclude Include="src\Engine\ECS_Base\Components\SHComponent.h">
|
<ClInclude Include="src\Engine\ECS_Base\Components\SHComponent.h">
|
||||||
<Filter>Engine\ECS_Base\Components</Filter>
|
<Filter>Engine\ECS_Base\Components</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
@ -364,6 +379,9 @@
|
||||||
<ClInclude Include="src\Scene\SHScene.h">
|
<ClInclude Include="src\Scene\SHScene.h">
|
||||||
<Filter>Scene</Filter>
|
<Filter>Scene</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="src\Scene\SHSceneGraph.h">
|
||||||
|
<Filter>Scene</Filter>
|
||||||
|
</ClInclude>
|
||||||
<ClInclude Include="src\Scene\SHSceneManager.h">
|
<ClInclude Include="src\Scene\SHSceneManager.h">
|
||||||
<Filter>Scene</Filter>
|
<Filter>Scene</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
@ -376,22 +394,20 @@
|
||||||
<ClInclude Include="src\Tools\SHLogger.h">
|
<ClInclude Include="src\Tools\SHLogger.h">
|
||||||
<Filter>Tools</Filter>
|
<Filter>Tools</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="src\Tools\SHUtilities.h" />
|
|
||||||
<ClInclude Include="src\Tools\SHUtilities.hpp" />
|
|
||||||
<ClInclude Include="src\Math\SHMath.h" />
|
|
||||||
<ClInclude Include="src\Math\SHMathHelpers.h" />
|
|
||||||
<ClInclude Include="src\Math\SHMathHelpers.hpp" />
|
|
||||||
<ClInclude Include="src\Math\SHMatrix.h" />
|
|
||||||
<ClInclude Include="src\Math\SHQuaternion.h" />
|
|
||||||
<ClInclude Include="src\Math\Vector\SHVec2.h" />
|
|
||||||
<ClInclude Include="src\Math\Vector\SHVec3.h" />
|
|
||||||
<ClInclude Include="src\Math\Vector\SHVec4.h" />
|
|
||||||
<ClInclude Include="src\Scene\SHSceneGraph.h" />
|
|
||||||
<ClInclude Include="src\Tools\SHUtilities.h">
|
<ClInclude Include="src\Tools\SHUtilities.h">
|
||||||
<Filter>Tools</Filter>
|
<Filter>Tools</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ClCompile Include="src\Assets\SHAssetManager.cpp">
|
||||||
|
<Filter>Assets</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="src\Assets\SHAssetMeta.cpp">
|
||||||
|
<Filter>Assets</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="src\Assets\SHAssetMetaHandler.cpp">
|
||||||
|
<Filter>Assets</Filter>
|
||||||
|
</ClCompile>
|
||||||
<ClCompile Include="src\Engine\ECS_Base\Components\SHComponent.cpp">
|
<ClCompile Include="src\Engine\ECS_Base\Components\SHComponent.cpp">
|
||||||
<Filter>Engine\ECS_Base\Components</Filter>
|
<Filter>Engine\ECS_Base\Components</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
@ -576,6 +592,9 @@
|
||||||
<Filter>Resource</Filter>
|
<Filter>Resource</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="src\SHpch.cpp" />
|
<ClCompile Include="src\SHpch.cpp" />
|
||||||
|
<ClCompile Include="src\Scene\SHSceneGraph.cpp">
|
||||||
|
<Filter>Scene</Filter>
|
||||||
|
</ClCompile>
|
||||||
<ClCompile Include="src\Scene\SHSceneManager.cpp">
|
<ClCompile Include="src\Scene\SHSceneManager.cpp">
|
||||||
<Filter>Scene</Filter>
|
<Filter>Scene</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
@ -588,12 +607,5 @@
|
||||||
<ClCompile Include="src\Tools\SHLogger.cpp">
|
<ClCompile Include="src\Tools\SHLogger.cpp">
|
||||||
<Filter>Tools</Filter>
|
<Filter>Tools</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="src\Math\SHMathHelpers.cpp" />
|
|
||||||
<ClCompile Include="src\Math\SHMatrix.cpp" />
|
|
||||||
<ClCompile Include="src\Math\SHQuaternion.cpp" />
|
|
||||||
<ClCompile Include="src\Math\Vector\SHVec2.cpp" />
|
|
||||||
<ClCompile Include="src\Math\Vector\SHVec3.cpp" />
|
|
||||||
<ClCompile Include="src\Math\Vector\SHVec4.cpp" />
|
|
||||||
<ClCompile Include="src\Scene\SHSceneGraph.cpp" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
|
@ -0,0 +1,89 @@
|
||||||
|
/******************************************************************************
|
||||||
|
* \file SHAssetMacros.h
|
||||||
|
* \author Loh Xiao Qi
|
||||||
|
* \brief Macros and typedefs for assets
|
||||||
|
*
|
||||||
|
* \copyright Copyright (c) 2022 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
|
||||||
|
******************************************************************************/
|
||||||
|
#ifndef SH_RESOURCE_MACROS_H
|
||||||
|
#define SH_RESOURCE_MACROS_H
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <string>
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
|
// FMOD Fwd Declare
|
||||||
|
namespace FMOD
|
||||||
|
{
|
||||||
|
class Sound;
|
||||||
|
class System;
|
||||||
|
class ChannelGroup;
|
||||||
|
class Channel;
|
||||||
|
}
|
||||||
|
enum FMOD_RESULT : int;
|
||||||
|
enum FMOD_SPEAKERMODE : int;
|
||||||
|
|
||||||
|
// Typedefs
|
||||||
|
typedef uint32_t AssetID;
|
||||||
|
typedef std::string AssetName;
|
||||||
|
typedef std::filesystem::path AssetPath;
|
||||||
|
typedef unsigned char* AssetData;
|
||||||
|
typedef std::string AssetMetaVersion;
|
||||||
|
typedef std::string AssetExtension;
|
||||||
|
typedef unsigned char AssetTypeMeta;
|
||||||
|
|
||||||
|
typedef FMOD::Sound* SHSound;
|
||||||
|
|
||||||
|
// Asset Meta Version
|
||||||
|
#define RESOURCE_META_VER "1.0"
|
||||||
|
|
||||||
|
// Asset type enum
|
||||||
|
enum class AssetType : AssetTypeMeta
|
||||||
|
{
|
||||||
|
AUDIO = 0,
|
||||||
|
SHADER,
|
||||||
|
MATERIAL,
|
||||||
|
IMAGE,
|
||||||
|
TEXTURE,
|
||||||
|
MESH,
|
||||||
|
SCRIPT,
|
||||||
|
SCENE,
|
||||||
|
PREFAB,
|
||||||
|
AUDIO_WAV
|
||||||
|
};
|
||||||
|
|
||||||
|
// RESOURCE EXTENSIONS
|
||||||
|
#define META_EXTENSION ".shmeta"
|
||||||
|
#define IMAGE_EXTENSION ".png"
|
||||||
|
#define AUDIO_EXTENSION ".ogg"
|
||||||
|
#define AUDIO_WAV_EXTENSION ".wav"
|
||||||
|
#define SHADER_EXTENSION ".glsl"
|
||||||
|
#define SCRIPT_EXTENSION ".cs"
|
||||||
|
#define SCENE_EXTENSION ".SHADE"
|
||||||
|
#define PREFAB_EXTENSION ".SHPrefab"
|
||||||
|
#define MATERIAL_EXTENSION ".SHMat"
|
||||||
|
#define TEXTURE_EXTENSION ".dds"
|
||||||
|
#define MESH_EXTENSION ".gltf"
|
||||||
|
|
||||||
|
std::string const EXTENSIONS[] = {
|
||||||
|
AUDIO_EXTENSION,
|
||||||
|
SHADER_EXTENSION,
|
||||||
|
MATERIAL_EXTENSION,
|
||||||
|
IMAGE_EXTENSION,
|
||||||
|
TEXTURE_EXTENSION,
|
||||||
|
MESH_EXTENSION,
|
||||||
|
SCRIPT_EXTENSION,
|
||||||
|
SCENE_EXTENSION,
|
||||||
|
PREFAB_EXTENSION,
|
||||||
|
AUDIO_WAV_EXTENSION
|
||||||
|
};
|
||||||
|
|
||||||
|
// 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 EXT_DOES_NOT_EXIST "TYPE DOES NOT HAVE EXTENSION DEFINED"
|
||||||
|
|
||||||
|
#endif // !SH_RESOURCE_MACROS_H
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,199 @@
|
||||||
|
/******************************************************************************
|
||||||
|
* \file SHAssetManager.h
|
||||||
|
* \author Loh Xiao Qi
|
||||||
|
* \brief Interface for resource manager, to be used by engine side
|
||||||
|
* operations.
|
||||||
|
*
|
||||||
|
* \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.
|
||||||
|
******************************************************************************/
|
||||||
|
#ifndef SH_RESOURCE_MANAGER_H
|
||||||
|
#define SH_RESOURCE_MANAGER_H
|
||||||
|
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include "SHAssetMeta.h"
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
struct _MonoMethod;
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
class SHAssetManager
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/****************************************************************************
|
||||||
|
* \brief Static function to generate resource ID.
|
||||||
|
****************************************************************************/
|
||||||
|
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;
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* \brief Deallocate all memory used by resource data
|
||||||
|
****************************************************************************/
|
||||||
|
static void Unload() noexcept;
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* \brief Load all resources that are in the folder
|
||||||
|
****************************************************************************/
|
||||||
|
static void Load() noexcept;
|
||||||
|
|
||||||
|
// General------------------------------------------------------------------/
|
||||||
|
/****************************************************************************
|
||||||
|
* \param Name of resource
|
||||||
|
|
||||||
|
* \brief Gets resource ID
|
||||||
|
****************************************************************************/
|
||||||
|
static AssetID GetIDFromName(AssetName const&) noexcept;
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* \param Name of resource
|
||||||
|
|
||||||
|
* \brief Gets resource ID
|
||||||
|
****************************************************************************/
|
||||||
|
static std::vector<AssetID> GetIDFromNames(std::initializer_list<AssetName> const&) noexcept;
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* \brief Get asset name from resource ID.
|
||||||
|
*
|
||||||
|
* \param id - resource id
|
||||||
|
* \return - std::string
|
||||||
|
****************************************************************************/
|
||||||
|
static AssetName GetNameFromID(AssetID) noexcept;
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* \param file name
|
||||||
|
|
||||||
|
* \brief Returns resource ID from provided file name
|
||||||
|
****************************************************************************/
|
||||||
|
static AssetID GetIDFromFilename(std::string const&) noexcept;
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* \brief Get filename from resource ID.
|
||||||
|
*
|
||||||
|
* \param id - id of asset
|
||||||
|
* \return std::string
|
||||||
|
****************************************************************************/
|
||||||
|
static std::string GetFilenameFromID(AssetID id) noexcept;
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* \param list of file names
|
||||||
|
|
||||||
|
* \brief Returns vector of resource IDs
|
||||||
|
****************************************************************************/
|
||||||
|
static std::vector<AssetID> GetIDFromFilenames(std::initializer_list<std::string> const&) noexcept;
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* \brief Get record of all resources currently loaded with name and id.
|
||||||
|
*
|
||||||
|
* \return const& to unordered_map<AssetName, AssetID>
|
||||||
|
****************************************************************************/
|
||||||
|
static std::unordered_map<AssetName, AssetID> const& GetAllAssets() noexcept;
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* \brief Get type of asset from ID
|
||||||
|
*
|
||||||
|
* \param resource id of file
|
||||||
|
* \return AssetType enum class value
|
||||||
|
****************************************************************************/
|
||||||
|
static AssetType GetTypeFromID(AssetID) noexcept;
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* \brief Get registered path of asset.
|
||||||
|
*
|
||||||
|
* \param resource id of file
|
||||||
|
* \return std::filesystem::path
|
||||||
|
****************************************************************************/
|
||||||
|
static AssetPath GetPathFromID(AssetID) noexcept;
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* \brief Create record for new resource. CAN ONLY CREATE FOR CUSTOM
|
||||||
|
* RESOURCES CREATED BY THE ENGINE.
|
||||||
|
*
|
||||||
|
* \param type of resource
|
||||||
|
* \param name of resource
|
||||||
|
* \return resource id generated for new asset
|
||||||
|
****************************************************************************/
|
||||||
|
static AssetID CreateNewAsset(AssetType, AssetName) noexcept;
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* \brief Import new resource from outside editor window.
|
||||||
|
*
|
||||||
|
* \param path - c style string to full path
|
||||||
|
* \return resource if generated for new
|
||||||
|
****************************************************************************/
|
||||||
|
static AssetID ImportNewAsset(char const* path) noexcept;
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* \brief Search through resources folder for new unregistered assets.
|
||||||
|
* Takes in no params and returns nothing. Only updates internally.
|
||||||
|
****************************************************************************/
|
||||||
|
static void RefreshAllAssets() noexcept;
|
||||||
|
// -------------------------------------------------------------------------/
|
||||||
|
|
||||||
|
private:
|
||||||
|
/****************************************************************************
|
||||||
|
* \brief Load resource data into memory
|
||||||
|
****************************************************************************/
|
||||||
|
static void LoadAllData() noexcept;
|
||||||
|
|
||||||
|
static void LoadData(AssetID id) noexcept;
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* \brief Retrieve all resource files and meta files from filesystem
|
||||||
|
****************************************************************************/
|
||||||
|
static void RetrieveAssets() noexcept;
|
||||||
|
|
||||||
|
static AssetID RetrieveAsset(char const* path) noexcept;
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* \param Full path of file
|
||||||
|
|
||||||
|
* \brief Extracts file name from path. Formats file name into readable
|
||||||
|
* with spaces and capitalises first letter of every word
|
||||||
|
****************************************************************************/
|
||||||
|
static AssetName GetNameFromPath(AssetPath) noexcept;
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* \param Path for meta data file
|
||||||
|
* \param Path for resource file
|
||||||
|
|
||||||
|
* \brief Links meta data to resource in registries. Meta data should
|
||||||
|
* already exist
|
||||||
|
****************************************************************************/
|
||||||
|
static void RegisterAsset(AssetPath const&, AssetPath const&) noexcept;
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* \param Path for resource file
|
||||||
|
|
||||||
|
* \brief Creates new meta data for new resource.
|
||||||
|
****************************************************************************/
|
||||||
|
static SHAssetMeta RegisterAssetNew(AssetPath const&) noexcept;
|
||||||
|
|
||||||
|
static bool IsRecognised(char const*) noexcept;
|
||||||
|
|
||||||
|
static FMOD::System* audioSystem;
|
||||||
|
static std::unordered_map<AssetID,SHSound>* audioSoundList;
|
||||||
|
|
||||||
|
// For all resources
|
||||||
|
static std::vector<SHAssetMeta> metaCollection;
|
||||||
|
static std::unordered_map<AssetID, AssetPath> pathRegistry;
|
||||||
|
static std::unordered_map<AssetID, AssetType> typeRegistry;
|
||||||
|
static std::unordered_map<AssetID, AssetName> idNameRegistry;
|
||||||
|
static std::unordered_map<AssetName, AssetID> nameIDRegistry;
|
||||||
|
static std::unordered_map<std::string, AssetID> filenameRegistry;
|
||||||
|
static std::unordered_map<AssetID, std::string> filenameReverse;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // !SH_RESOURCE_MANAGER_H
|
|
@ -0,0 +1,102 @@
|
||||||
|
/******************************************************************************
|
||||||
|
* \file SHResourceMeta.cpp
|
||||||
|
* \author Loh Xiao Qi
|
||||||
|
* \brief Implementation for SHResourceMeta.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"
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
/****************************************************************************
|
||||||
|
* \brief Default constructor
|
||||||
|
****************************************************************************/
|
||||||
|
SHResourceMeta::SHResourceMeta() noexcept : id{ 0 }, type{ResourceType::INVALID}
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* \param copy
|
||||||
|
|
||||||
|
* \brief copy constructor
|
||||||
|
****************************************************************************/
|
||||||
|
SHResourceMeta::SHResourceMeta(SHResourceMeta const& ref) noexcept
|
||||||
|
{
|
||||||
|
ver = ref.ver;
|
||||||
|
id = ref.id;
|
||||||
|
type = ref.type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* \param reference
|
||||||
|
|
||||||
|
* \brief copy assignment operator overload
|
||||||
|
****************************************************************************/
|
||||||
|
SHResourceMeta& SHResourceMeta::operator=(SHResourceMeta const& ref) noexcept
|
||||||
|
{
|
||||||
|
ver = ref.ver;
|
||||||
|
id = ref.id;
|
||||||
|
type = ref.type;
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* \param std::string representation for meta resource file version
|
||||||
|
|
||||||
|
* \brief Set meta version for data file
|
||||||
|
****************************************************************************/
|
||||||
|
void SHResourceMeta::SetVersion(ResourceMetaVersion vers) noexcept
|
||||||
|
{
|
||||||
|
ver = vers;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* \param ID of resource
|
||||||
|
|
||||||
|
* \brief Set ID
|
||||||
|
****************************************************************************/
|
||||||
|
void SHResourceMeta::SetID(ResourceID idin) noexcept
|
||||||
|
{
|
||||||
|
this->id = idin;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* \param Enum class value
|
||||||
|
|
||||||
|
* \brief Set Resource Type
|
||||||
|
****************************************************************************/
|
||||||
|
void SHResourceMeta::SetType(ResourceType rType) noexcept
|
||||||
|
{
|
||||||
|
this->type = rType;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* \brief Get version
|
||||||
|
****************************************************************************/
|
||||||
|
ResourceMetaVersion SHResourceMeta::GetVersion() const noexcept
|
||||||
|
{
|
||||||
|
return ver;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* \brief Get ID
|
||||||
|
****************************************************************************/
|
||||||
|
ResourceID SHResourceMeta::GetID() const noexcept
|
||||||
|
{
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* \brief Get resource type
|
||||||
|
****************************************************************************/
|
||||||
|
ResourceType SHResourceMeta::GetType() const noexcept
|
||||||
|
{
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,82 @@
|
||||||
|
/******************************************************************************
|
||||||
|
* \file SHAssetMeta.h
|
||||||
|
* \author Loh Xiao Qi
|
||||||
|
* \brief Class to hold meta data values for resources
|
||||||
|
*
|
||||||
|
* \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
|
||||||
|
******************************************************************************/
|
||||||
|
#ifndef SH_RESOURCE_META_H
|
||||||
|
#define SH_RESOURCE_META_H
|
||||||
|
|
||||||
|
#include "SHAssetMacros.h"
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
class SHAssetMeta
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/****************************************************************************
|
||||||
|
* \brief Default constructor
|
||||||
|
****************************************************************************/
|
||||||
|
SHAssetMeta() noexcept;
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* \param copy
|
||||||
|
|
||||||
|
* \brief copy constructor
|
||||||
|
****************************************************************************/
|
||||||
|
SHAssetMeta(SHAssetMeta const&) noexcept;
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* \param reference
|
||||||
|
|
||||||
|
* \brief copy assignment operator overload
|
||||||
|
****************************************************************************/
|
||||||
|
SHAssetMeta& operator=(SHAssetMeta const&) noexcept;
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* \param std::string representation for meta resource file version
|
||||||
|
|
||||||
|
* \brief Set meta version for data file
|
||||||
|
****************************************************************************/
|
||||||
|
void SetVersion(AssetMetaVersion) noexcept;
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* \param ID of resource
|
||||||
|
|
||||||
|
* \brief Set ID
|
||||||
|
****************************************************************************/
|
||||||
|
void SetID(AssetID) noexcept;
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* \param Enum class value
|
||||||
|
|
||||||
|
* \brief Set Asset Type
|
||||||
|
****************************************************************************/
|
||||||
|
void SetType(AssetType) noexcept;
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* \brief Get version
|
||||||
|
****************************************************************************/
|
||||||
|
AssetMetaVersion GetVersion() const noexcept;
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* \brief Get ID
|
||||||
|
****************************************************************************/
|
||||||
|
AssetID GetID() const noexcept;
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* \brief Get resouce type
|
||||||
|
****************************************************************************/
|
||||||
|
AssetType GetType() const noexcept;
|
||||||
|
|
||||||
|
private:
|
||||||
|
AssetMetaVersion ver;
|
||||||
|
AssetID id;
|
||||||
|
AssetType type;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // !SH_RESOURCE_META_H
|
|
@ -0,0 +1,131 @@
|
||||||
|
/******************************************************************************
|
||||||
|
* \file SHAssetMetaHandler.cpp
|
||||||
|
* \author Loh Xiao Qi
|
||||||
|
* \brief Implementations for SHAssetMetaHandler.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 "SHAssetMetaHandler.h"
|
||||||
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
/****************************************************************************
|
||||||
|
* \param reference to ifstream file to read line from
|
||||||
|
* \param reference to string to store line into
|
||||||
|
|
||||||
|
* \brief Helper function to retrieve field value from meta data file
|
||||||
|
* for processing
|
||||||
|
****************************************************************************/
|
||||||
|
void GetFieldValue(std::ifstream& file, std::string& line) noexcept
|
||||||
|
{
|
||||||
|
line = "";
|
||||||
|
std::getline(file, line);
|
||||||
|
line = line.substr(line.find_last_of(':') + 2, line.length());
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* \param String containing extension of resource file
|
||||||
|
|
||||||
|
* \brief Get correct resource type from file extension of resource.
|
||||||
|
****************************************************************************/
|
||||||
|
AssetType SHAssetMetaHandler::GetTypeFromExtension(AssetExtension ext) noexcept
|
||||||
|
{
|
||||||
|
for (int i{0}; i < EXTENSIONS->size())
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* \param String containing extension of resource file
|
||||||
|
|
||||||
|
* \brief Get correct resource type from file extension of resource.
|
||||||
|
****************************************************************************/
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* \param Create class containing meta data from meta file
|
||||||
|
|
||||||
|
* \brief path to meta data file
|
||||||
|
****************************************************************************/
|
||||||
|
SHAssetMeta SHAssetMetaHandler::RetrieveMetaData(AssetPath const& path) noexcept
|
||||||
|
{
|
||||||
|
std::ifstream metaFile{ path.string(), std::ios_base::in };
|
||||||
|
if (!metaFile.is_open())
|
||||||
|
{
|
||||||
|
// Error unable to open
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string line;
|
||||||
|
SHAssetMeta meta;
|
||||||
|
|
||||||
|
// Get file version
|
||||||
|
GetFieldValue(metaFile, line);
|
||||||
|
meta.SetVersion(line);
|
||||||
|
|
||||||
|
// Get resource id
|
||||||
|
GetFieldValue(metaFile, line);
|
||||||
|
std::stringstream idStream{ line };
|
||||||
|
AssetID id;
|
||||||
|
idStream >> id;
|
||||||
|
meta.SetID(id);
|
||||||
|
|
||||||
|
// Get resource type
|
||||||
|
GetFieldValue(metaFile, line);
|
||||||
|
std::stringstream typeStream{ line };
|
||||||
|
AssetTypeMeta type;
|
||||||
|
typeStream >> type;
|
||||||
|
meta.SetType(SHAssetMetaHandler::GetTypeFromString(type));
|
||||||
|
|
||||||
|
metaFile.close();
|
||||||
|
|
||||||
|
return meta;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* \param Asset meta data to be written into
|
||||||
|
* \param Path to be written into
|
||||||
|
|
||||||
|
* \brief Writes meta data into text file
|
||||||
|
****************************************************************************/
|
||||||
|
void SHAssetMetaHandler::WriteMetaData(SHAssetMeta const& meta, AssetPath const& path) noexcept
|
||||||
|
{
|
||||||
|
std::ofstream metaFile{ path, std::ios_base::out };
|
||||||
|
|
||||||
|
if (!metaFile.is_open())
|
||||||
|
{
|
||||||
|
// Log error
|
||||||
|
}
|
||||||
|
|
||||||
|
metaFile << "Meta Version: " << meta.GetVersion() << "\n";
|
||||||
|
metaFile << "ID: " << meta.GetID() << "\n";
|
||||||
|
metaFile << "Type: " << GetStringFromType(meta.GetType()) << std::endl;
|
||||||
|
metaFile.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,51 @@
|
||||||
|
/******************************************************************************
|
||||||
|
* \file SHAssetMetaHandler.h
|
||||||
|
* \author Loh Xiao Qi
|
||||||
|
* \brief Handler classes for meta data for all resources
|
||||||
|
*
|
||||||
|
* \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
|
||||||
|
******************************************************************************/
|
||||||
|
#ifndef SH_RESOURCE_META_HANDLER_H
|
||||||
|
#define SH_RESOURCE_META_HANDLER_H
|
||||||
|
|
||||||
|
#include "SHAssetMacros.h"
|
||||||
|
#include "SHAssetMeta.h"
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
struct SHAssetMetaHandler
|
||||||
|
{
|
||||||
|
/****************************************************************************
|
||||||
|
* \param String containing extension of resource file
|
||||||
|
|
||||||
|
* \brief Get correct resource type from file extension of resource.
|
||||||
|
****************************************************************************/
|
||||||
|
static AssetType GetTypeFromExtension(AssetExtension) noexcept;
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* \param String containing extension of resource file
|
||||||
|
|
||||||
|
* \brief Get correct resource type from file extension of resource.
|
||||||
|
****************************************************************************/
|
||||||
|
static AssetExtension GetExtensionFromType(AssetType) noexcept;
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* \param Create class containing meta data from meta file
|
||||||
|
|
||||||
|
* \brief path to meta data file
|
||||||
|
****************************************************************************/
|
||||||
|
static SHAssetMeta RetrieveMetaData(AssetPath const&) noexcept;
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* \param Asset meta data to be written into
|
||||||
|
* \param Path to be written into
|
||||||
|
|
||||||
|
* \brief Writes meta data into text file
|
||||||
|
****************************************************************************/
|
||||||
|
static void WriteMetaData(SHAssetMeta const&, AssetPath const&) noexcept;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // !SH_RESOURCE_META_HANDLER_H
|
Loading…
Reference in New Issue