Added C# Assets System and Serialization of Script Enabled State #247
|
@ -49,7 +49,8 @@ namespace SHADE
|
||||||
template<> struct SHResourceLoader<SHMaterialSpec> { using AssetType = SHMaterialAsset; };
|
template<> struct SHResourceLoader<SHMaterialSpec> { using AssetType = SHMaterialAsset; };
|
||||||
template<> struct SHResourceLoader<SHMaterial> { using AssetType = SHMaterialSpec; };
|
template<> struct SHResourceLoader<SHMaterial> { using AssetType = SHMaterialSpec; };
|
||||||
template<> struct SHResourceLoader<SHFont> { using AssetType = SHFontAsset; };
|
template<> struct SHResourceLoader<SHFont> { using AssetType = SHFontAsset; };
|
||||||
/// <summary>
|
|
||||||
|
/// <summary>
|
||||||
/// Static class responsible for loading and caching runtime resources from their
|
/// Static class responsible for loading and caching runtime resources from their
|
||||||
/// serialised Asset IDs.
|
/// serialised Asset IDs.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
/************************************************************************************//*!
|
||||||
|
\file SHResourceManagerWrapper.cpp
|
||||||
|
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||||
|
\par email: kahwei.tng\@digipen.edu
|
||||||
|
\date Nov 22, 2022
|
||||||
|
\brief Contains the definition of the functions of the SHResourceManagerWraper
|
||||||
|
static class.
|
||||||
|
|
||||||
|
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.
|
||||||
|
*//*************************************************************************************/
|
||||||
|
// Precompiled Header
|
||||||
|
#include "SHpch.h"
|
||||||
|
// Primary Include
|
||||||
|
#include "SHResourceManagerWrapper.h"
|
||||||
|
// Project Includes
|
||||||
|
#include "SHResourceManager.h"
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
/* Query Functions */
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
std::optional<AssetID> SHResourceManagerWrapper::GetAssetID(Handle<void> handle)
|
||||||
|
{
|
||||||
|
return SHResourceManager::GetAssetID(handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<std::string> SHResourceManagerWrapper::GetAssetName(Handle<void> handle)
|
||||||
|
{
|
||||||
|
return SHResourceManager::GetAssetName(handle);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,57 @@
|
||||||
|
/************************************************************************************//*!
|
||||||
|
\file SHResourceManagerWrapper.h
|
||||||
|
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||||
|
\par email: kahwei.tng\@digipen.edu
|
||||||
|
\date Nov 22, 2022
|
||||||
|
\brief Contains the definition of the SHResourceManagerWrapper static class.
|
||||||
|
|
||||||
|
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.
|
||||||
|
*//*************************************************************************************/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
// STL Includes
|
||||||
|
#include <optional>
|
||||||
|
// Project Includes
|
||||||
|
#include "SH_API.h"
|
||||||
|
#include "Resource/SHHandle.h"
|
||||||
|
#include "Assets/SHAssetMacros.h"
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Static class providing access to non-templated functions of SHResourceManager for
|
||||||
|
/// SHADE_Managed.
|
||||||
|
/// </summary>
|
||||||
|
class SH_API SHResourceManagerWrapper
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Query Functions */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieves the AssetID associated with a specified Handle.
|
||||||
|
/// Compared to the templated version, this function is slower as it requires
|
||||||
|
/// searching through the storage of all resource types.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="handle">Handle to get the AssetID of.</param>
|
||||||
|
/// <return>
|
||||||
|
/// AssetID for the specified Handle. If the Handle is invalid, there will be no
|
||||||
|
/// value.
|
||||||
|
/// </return>
|
||||||
|
static std::optional<AssetID> GetAssetID(Handle<void> handle);
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieves the name associated with the AssetID that is associated with the
|
||||||
|
/// specified Handle.
|
||||||
|
/// Compared to the templated version, this function is slower as it requires
|
||||||
|
/// searching through the storage of all resource types.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="handle">Handle to get the name of.</param>
|
||||||
|
/// <return>
|
||||||
|
/// Name for the specified Handle. If the Handle is invalid, there will be no
|
||||||
|
/// value.
|
||||||
|
/// </return>
|
||||||
|
static std::optional<std::string> GetAssetName(Handle<void> handle);
|
||||||
|
};
|
||||||
|
}
|
|
@ -15,18 +15,57 @@ of DigiPen Institute of Technology is prohibited.
|
||||||
#include "SHpch.h"
|
#include "SHpch.h"
|
||||||
// Primary Header
|
// Primary Header
|
||||||
#include "Font.hxx"
|
#include "Font.hxx"
|
||||||
|
// Project Headers
|
||||||
|
#include "Utility/Convert.hxx"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
/* Explicit Template Instantiation */
|
/* Properties */
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
template ref class NativeAsset<SHFont>;
|
Handle<SHFont> Font::NativeObject::get()
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return Handle<SHFont>(Convert::ToNative(asset.NativeObjectHandle));
|
||||||
|
}
|
||||||
|
catch (const BadHandleCastException&)
|
||||||
|
{
|
||||||
|
return Handle<SHFont>();
|
||||||
|
}
|
||||||
|
GenericHandle Font::NativeObjectHandle::get()
|
||||||
|
{
|
||||||
|
return asset.NativeObjectHandle;
|
||||||
|
}
|
||||||
|
AssetID Font::NativeAssetID::get()
|
||||||
|
{
|
||||||
|
return asset.NativeAssetID;
|
||||||
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
/* Constructors/Destructor */
|
/* Constructors/Destructor */
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
Font::Font(Handle<SHFont> font)
|
Font::Font(Handle<SHFont> font)
|
||||||
: NativeAsset<SHFont> { font }
|
: asset { Handle<void>(font) }
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Operator Overloads */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
Font::operator bool(Font asset)
|
||||||
|
{
|
||||||
|
return asset;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Conversion Operators */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
Font::operator Asset(Font nativeAsset)
|
||||||
|
{
|
||||||
|
return nativeAsset.asset;
|
||||||
|
}
|
||||||
|
|
||||||
|
Font::operator Font(Asset asset)
|
||||||
|
{
|
||||||
|
return Font(Handle<SHFont>(Convert::ToNative(asset.NativeObjectHandle)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,9 +26,34 @@ namespace SHADE
|
||||||
/// Managed counterpart of the native Font object that can be fed to TextRenderables
|
/// Managed counterpart of the native Font object that can be fed to TextRenderables
|
||||||
/// for rendering.
|
/// for rendering.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ref class Font : public NativeAsset<SHFont>
|
public value struct Font
|
||||||
{
|
{
|
||||||
internal:
|
internal:
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Properties */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/// <summary>
|
||||||
|
/// Copy of the Handle to the native object.
|
||||||
|
/// </summary>
|
||||||
|
property Handle<SHFont> NativeObject
|
||||||
|
{
|
||||||
|
Handle<SHFont> get();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Generic handle for the native object
|
||||||
|
/// </summary>
|
||||||
|
property GenericHandle NativeObjectHandle
|
||||||
|
{
|
||||||
|
GenericHandle get();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// The raw asset ID of the asset.
|
||||||
|
/// </summary>
|
||||||
|
property AssetID NativeAssetID
|
||||||
|
{
|
||||||
|
AssetID get();
|
||||||
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
/* Constructors/Destructor */
|
/* Constructors/Destructor */
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
@ -37,5 +62,35 @@ namespace SHADE
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="font">Handle to the font object.</param>
|
/// <param name="font">Handle to the font object.</param>
|
||||||
Font(Handle<SHFont> font);
|
Font(Handle<SHFont> font);
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Operator Overloads */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/// <summary>
|
||||||
|
/// Implicit conversion operator to enable checking if a Font is valid.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="gameObj">Asset to check.</param>
|
||||||
|
/// <returns>True if the Asset is valid.</returns>
|
||||||
|
static operator bool(Font asset);
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Conversion Operators */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/// <summary>
|
||||||
|
/// Conversion operator to enable casting from a Font to an Asset.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="vec">Vector3 to convert from.</param>
|
||||||
|
static explicit operator Asset(Font nativeAsset);
|
||||||
|
/// <summary>
|
||||||
|
/// Conversion operator to enable casting from a Asset to a Font.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="vec">Vector2 to convert from.</param>
|
||||||
|
static explicit operator Font(Asset vec);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Data Members */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
Asset asset;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,15 +53,31 @@ namespace SHADE
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
/* Explicit Template Instantiation */
|
/* Properties */
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
template ref class NativeAsset<SHMaterialInstance>;
|
Handle<SHMaterialInstance> Material::NativeObject::get()
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return Handle<SHMaterialInstance>(Convert::ToNative(asset.NativeObjectHandle));
|
||||||
|
}
|
||||||
|
catch (const BadHandleCastException&)
|
||||||
|
{
|
||||||
|
return Handle<SHMaterialInstance>();
|
||||||
|
}
|
||||||
|
GenericHandle Material::NativeObjectHandle::get()
|
||||||
|
{
|
||||||
|
return asset.NativeObjectHandle;
|
||||||
|
}
|
||||||
|
AssetID Material::NativeAssetID::get()
|
||||||
|
{
|
||||||
|
return asset.NativeAssetID;
|
||||||
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
/* Constructors/Destructor */
|
/* Constructors/Destructor */
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
Material::Material(Handle<SHMaterialInstance> material)
|
Material::Material(Handle<SHMaterialInstance> material)
|
||||||
: NativeAsset<SHMaterialInstance>{ material }
|
: asset { Handle<void>(material) }
|
||||||
{}
|
{}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
@ -116,4 +132,25 @@ namespace SHADE
|
||||||
|
|
||||||
throw gcnew System::ArgumentException("Attempted to retrieve an invalid property on a material.");
|
throw gcnew System::ArgumentException("Attempted to retrieve an invalid property on a material.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Operator Overloads */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
Material::operator bool(Material asset)
|
||||||
|
{
|
||||||
|
return asset;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Conversion Operators */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
Material::operator Asset(Material nativeAsset)
|
||||||
|
{
|
||||||
|
return nativeAsset.asset;
|
||||||
|
}
|
||||||
|
|
||||||
|
Material::operator Material(Asset asset)
|
||||||
|
{
|
||||||
|
return Material(Handle<SHMaterialInstance>(Convert::ToNative(asset.NativeObjectHandle)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,9 +26,34 @@ namespace SHADE
|
||||||
/// Managed counterpart of the native MaterialInstance object containing material
|
/// Managed counterpart of the native MaterialInstance object containing material
|
||||||
/// data that can be fed to Renderables for rendering.
|
/// data that can be fed to Renderables for rendering.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ref class Material : public NativeAsset<SHMaterialInstance>
|
public value struct Material
|
||||||
{
|
{
|
||||||
internal:
|
internal:
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Properties */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/// <summary>
|
||||||
|
/// Copy of the Handle to the native object.
|
||||||
|
/// </summary>
|
||||||
|
property Handle<SHMaterialInstance> NativeObject
|
||||||
|
{
|
||||||
|
Handle<SHMaterialInstance> get();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Generic handle for the native object
|
||||||
|
/// </summary>
|
||||||
|
property GenericHandle NativeObjectHandle
|
||||||
|
{
|
||||||
|
GenericHandle get();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// The raw asset ID of the asset.
|
||||||
|
/// </summary>
|
||||||
|
property AssetID NativeAssetID
|
||||||
|
{
|
||||||
|
AssetID get();
|
||||||
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
/* Constructors/Destructor */
|
/* Constructors/Destructor */
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
@ -77,5 +102,35 @@ namespace SHADE
|
||||||
/// </exception>
|
/// </exception>
|
||||||
generic<typename T>
|
generic<typename T>
|
||||||
T GetProperty(System::String^ name);
|
T GetProperty(System::String^ name);
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Operator Overloads */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/// <summary>
|
||||||
|
/// Implicit conversion operator to enable checking if a Material is valid.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="gameObj">Asset to check.</param>
|
||||||
|
/// <returns>True if the Asset is valid.</returns>
|
||||||
|
static operator bool(Material asset);
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Conversion Operators */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/// <summary>
|
||||||
|
/// Conversion operator to enable casting from a Material to an Asset.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="vec">Vector3 to convert from.</param>
|
||||||
|
static explicit operator Asset(Material nativeAsset);
|
||||||
|
/// <summary>
|
||||||
|
/// Conversion operator to enable casting from a Asset to a Material.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="vec">Vector2 to convert from.</param>
|
||||||
|
static explicit operator Material(Asset vec);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Data Members */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
Asset asset;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,14 +21,51 @@ of DigiPen Institute of Technology is prohibited.
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
/* Explicit Template Instantiation */
|
/* Properties */
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
template ref class NativeAsset<SHMesh>;
|
Handle<SHMesh> Mesh::NativeObject::get()
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return Handle<SHMesh>(Convert::ToNative(asset.NativeObjectHandle));
|
||||||
|
}
|
||||||
|
catch (const BadHandleCastException&)
|
||||||
|
{
|
||||||
|
return Handle<SHMesh>();
|
||||||
|
}
|
||||||
|
GenericHandle Mesh::NativeObjectHandle::get()
|
||||||
|
{
|
||||||
|
return asset.NativeObjectHandle;
|
||||||
|
}
|
||||||
|
AssetID Mesh::NativeAssetID::get()
|
||||||
|
{
|
||||||
|
return asset.NativeAssetID;
|
||||||
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
/* Constructors/Destructor */
|
/* Constructors/Destructor */
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
Mesh::Mesh(Handle<SHMesh> mesh)
|
Mesh::Mesh(Handle<SHMesh> Mesh)
|
||||||
: NativeAsset<SHMesh> { mesh }
|
: asset{ Handle<void>(Mesh) }
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Operator Overloads */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
Mesh::operator bool(Mesh asset)
|
||||||
|
{
|
||||||
|
return asset;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Conversion Operators */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
Mesh::operator Asset(Mesh nativeAsset)
|
||||||
|
{
|
||||||
|
return nativeAsset.asset;
|
||||||
|
}
|
||||||
|
|
||||||
|
Mesh::operator Mesh(Asset asset)
|
||||||
|
{
|
||||||
|
return Mesh(Handle<SHMesh>(Convert::ToNative(asset.NativeObjectHandle)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,16 +26,71 @@ namespace SHADE
|
||||||
/// Managed counterpart of the native Mesh object containing vertex data that can
|
/// Managed counterpart of the native Mesh object containing vertex data that can
|
||||||
/// be fed to Renderables for rendering.
|
/// be fed to Renderables for rendering.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ref class Mesh : public NativeAsset<SHMesh>
|
public value struct Mesh
|
||||||
{
|
{
|
||||||
internal:
|
internal:
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Properties */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/// <summary>
|
||||||
|
/// Copy of the Handle to the native object.
|
||||||
|
/// </summary>
|
||||||
|
property Handle<SHMesh> NativeObject
|
||||||
|
{
|
||||||
|
Handle<SHMesh> get();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Generic handle for the native object
|
||||||
|
/// </summary>
|
||||||
|
property GenericHandle NativeObjectHandle
|
||||||
|
{
|
||||||
|
GenericHandle get();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// The raw asset ID of the asset.
|
||||||
|
/// </summary>
|
||||||
|
property AssetID NativeAssetID
|
||||||
|
{
|
||||||
|
AssetID get();
|
||||||
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
/* Constructors/Destructor */
|
/* Constructors/Destructor */
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructor for the Mesh
|
/// Constructor for the Mesh.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="mesh">Handle to the mesh object.</param>
|
/// <param name="Mesh">Handle to the Mesh object.</param>
|
||||||
Mesh(Handle<SHMesh> mesh);
|
Mesh(Handle<SHMesh> Mesh);
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Operator Overloads */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/// <summary>
|
||||||
|
/// Implicit conversion operator to enable checking if a Mesh is valid.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="gameObj">Asset to check.</param>
|
||||||
|
/// <returns>True if the Asset is valid.</returns>
|
||||||
|
static operator bool(Mesh asset);
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Conversion Operators */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/// <summary>
|
||||||
|
/// Conversion operator to enable casting from a Mesh to an Asset.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="vec">Vector3 to convert from.</param>
|
||||||
|
static explicit operator Asset(Mesh nativeAsset);
|
||||||
|
/// <summary>
|
||||||
|
/// Conversion operator to enable casting from a Asset to a Mesh.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="vec">Vector2 to convert from.</param>
|
||||||
|
static explicit operator Mesh(Asset vec);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Data Members */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
Asset asset;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,8 @@ of DigiPen Institute of Technology is prohibited.
|
||||||
#include "NativeAsset.hxx"
|
#include "NativeAsset.hxx"
|
||||||
// Project Includes
|
// Project Includes
|
||||||
#include "Engine/GenericHandle.hxx"
|
#include "Engine/GenericHandle.hxx"
|
||||||
|
#include "Utility/Convert.hxx"
|
||||||
|
#include "Resource/SHResourceManagerWrapper.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
@ -27,6 +29,10 @@ namespace SHADE
|
||||||
{
|
{
|
||||||
return nativeObjHandle;
|
return nativeObjHandle;
|
||||||
}
|
}
|
||||||
|
AssetID Asset::NativeAssetID::get()
|
||||||
|
{
|
||||||
|
return SHResourceManagerWrapper::GetAssetID(Convert::ToNative(nativeObjHandle)).value_or(INVALID_ASSET_ID);
|
||||||
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
/* Constructors */
|
/* Constructors */
|
||||||
|
@ -34,4 +40,12 @@ namespace SHADE
|
||||||
Asset::Asset(Handle<void> nativeHandle)
|
Asset::Asset(Handle<void> nativeHandle)
|
||||||
: nativeObjHandle { Convert::ToCLI(Handle<void>(nativeHandle)) }
|
: nativeObjHandle { Convert::ToCLI(Handle<void>(nativeHandle)) }
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Operator Overloads */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
Asset::operator bool(Asset asset)
|
||||||
|
{
|
||||||
|
return asset.nativeObjHandle && asset.NativeAssetID != INVALID_ASSET_ID;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1,44 +0,0 @@
|
||||||
/************************************************************************************//*!
|
|
||||||
\file NativeAsset.h++
|
|
||||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
|
||||||
\par email: kahwei.tng\@digipen.edu
|
|
||||||
\date Oct 28, 2022
|
|
||||||
\brief Contains the definition of templated functions for the managed
|
|
||||||
NativeAsset classes.
|
|
||||||
|
|
||||||
Note: This file is written in C++17/CLI.
|
|
||||||
|
|
||||||
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.
|
|
||||||
*//*************************************************************************************/
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
// Primary Include
|
|
||||||
#include "NativeAsset.hxx"
|
|
||||||
#include "Utility/Convert.hxx"
|
|
||||||
|
|
||||||
namespace SHADE
|
|
||||||
{
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
|
||||||
/* Properties */
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
|
||||||
template <typename NativeAssetType>
|
|
||||||
Handle<NativeAssetType> NativeAsset<NativeAssetType>::NativeObject::get()
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return Handle<NativeAssetType>(Convert::ToNative(nativeObjHandle));
|
|
||||||
}
|
|
||||||
catch (const BadHandleCastException&)
|
|
||||||
{
|
|
||||||
return Handle<NativeAssetType>(); // Null handle
|
|
||||||
}
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
|
||||||
/* Constructors */
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
|
||||||
template <typename NativeAssetType>
|
|
||||||
NativeAsset<NativeAssetType>::NativeAsset(Handle<NativeAssetType> nativeObj)
|
|
||||||
: Asset { Handle<void>(nativeObj) }
|
|
||||||
{}
|
|
||||||
}
|
|
|
@ -14,14 +14,17 @@ of DigiPen Institute of Technology is prohibited.
|
||||||
*//*************************************************************************************/
|
*//*************************************************************************************/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
// External Dependencies
|
||||||
|
#include "Assets/SHAssetMacros.h"
|
||||||
|
// Project Includes
|
||||||
#include "Engine/GenericHandle.hxx"
|
#include "Engine/GenericHandle.hxx"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Abstract base class that all Native Assets will inherit from.
|
/// Struct that contains native asset information.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ref class Asset abstract
|
public value struct Asset
|
||||||
{
|
{
|
||||||
internal:
|
internal:
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
@ -34,6 +37,13 @@ namespace SHADE
|
||||||
{
|
{
|
||||||
GenericHandle get();
|
GenericHandle get();
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// The raw asset ID of the asset.
|
||||||
|
/// </summary>
|
||||||
|
property AssetID NativeAssetID
|
||||||
|
{
|
||||||
|
AssetID get();
|
||||||
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
/* Constructors/Destructor */
|
/* Constructors/Destructor */
|
||||||
|
@ -44,43 +54,20 @@ namespace SHADE
|
||||||
/// <param name="ptr">Native asset object handle.</param>
|
/// <param name="ptr">Native asset object handle.</param>
|
||||||
Asset(Handle<void> nativeHandle);
|
Asset(Handle<void> nativeHandle);
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Operator Overloads */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/// <summary>
|
||||||
|
/// Implicit conversion operator to enable checking if a Asset is valid.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="gameObj">Asset to check.</param>
|
||||||
|
/// <returns>True if the Asset is valid.</returns>
|
||||||
|
static operator bool(Asset asset);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
/* Data Members */
|
/* Data Members */
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
GenericHandle nativeObjHandle;
|
GenericHandle nativeObjHandle;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Generalised template class for a managed representation of a native asset
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="NativeAssetType">
|
|
||||||
/// The type of the asset's native representation.
|
|
||||||
/// </typeparam>
|
|
||||||
template<typename NativeAssetType>
|
|
||||||
public ref class NativeAsset abstract : Asset
|
|
||||||
{
|
|
||||||
internal:
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
|
||||||
/* Properties */
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
|
||||||
/// <summary>
|
|
||||||
/// Copy of the Handle to the native object.
|
|
||||||
/// </summary>
|
|
||||||
property Handle<NativeAssetType> NativeObject
|
|
||||||
{
|
|
||||||
Handle<NativeAssetType> get();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
|
||||||
/* Constructors/Destructor */
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
|
||||||
/// <summary>
|
|
||||||
/// Constructor for the native asset
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="ptr">Native asset object handle.</param>
|
|
||||||
NativeAsset(Handle<NativeAssetType> ptr);
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "NativeAsset.h++"
|
|
||||||
|
|
Loading…
Reference in New Issue