Infinity Engine v0.6.20
C++ API Documentation
Loading...
Searching...
No Matches
Infinity::Assets::Asset Class Reference

Type-erased container for loaded asset data. More...

#include <Asset.hpp>

Public Member Functions

 Asset ()
 Default constructor - creates an empty/invalid asset.
 
 Asset (const std::string &text)
 Constructs an asset containing text data.
 
 Asset (const Infinity::Types::Containers::GrayscaleTexture &tex)
 Constructs an asset from a grayscale texture.
 
 Asset (const Infinity::Types::Containers::Array2D< float > &tex)
 Constructs an asset from a 2D array of floats.
 
 Asset (const Infinity::Types::Containers::Array2D< Infinity::Types::Math::Vector3ub > &tex)
 Constructs an asset from a 2D array of unsigned byte RGB vectors.
 
 Asset (const Infinity::Types::Containers::Array2D< Infinity::Types::Math::Vector3 > &tex)
 Constructs an asset from a 2D array of float RGB vectors.
 
 Asset (const Infinity::Types::Containers::Texture &tex)
 Constructs an asset from a standard texture.
 
 Asset (const Infinity::Types::Containers::Array2D< Infinity::Types::Math::Vector4 > &tex)
 Constructs an asset from a 2D array of RGBA vectors.
 
 Asset (const Infinity::Types::Containers::Array3D< uint8_t > &tex)
 Constructs an asset from a 3D array of unsigned bytes.
 
 Asset (const Infinity::Types::Containers::Array3D< float > &tex)
 Constructs an asset from a 3D array of floats.
 
 Asset (const Infinity::Types::Containers::Array3D< Infinity::Types::Math::Vector3ub > &tex)
 Constructs an asset from a 3D array of unsigned byte RGB vectors.
 
 Asset (const Infinity::Types::Containers::Array3D< Infinity::Types::Math::Vector3 > &tex)
 Constructs an asset from a 3D array of float RGB vectors.
 
 Asset (const Infinity::Types::Containers::Texture3D &tex)
 Constructs an asset from a 3D texture.
 
 Asset (const Infinity::Types::Containers::Array3D< Infinity::Types::Math::Vector4 > &tex)
 Constructs an asset from a 3D array of RGBA vectors.
 
 Asset (const Infinity::Types::Rendering::Mesh &mesh)
 Constructs an asset from mesh data.
 
 Asset (const Infinity::Types::Rendering::Material &mat)
 Constructs an asset from material data.
 
 Asset (const Infinity::Types::Rendering::RenderObject &ro)
 Constructs an asset from a render object.
 
 Asset (Asset &&other)
 Move constructor - transfers ownership of asset data.
 
 Asset (std::unique_ptr< Infinity::Types::Core::Base > &&data)
 Constructs an asset from a polymorphic base pointer.
 
 ~Asset ()
 Destructor - releases owned asset data.
 
Assetoperator= (Asset &&other)
 Move assignment operator - transfers ownership of asset data.
 
template<typename T >
const T & get ()
 Retrieves the stored asset data as the specified type.
 
Infinity::Types::Core::Baserelease ()
 Releases ownership of the underlying asset data.
 
 operator bool ()
 Checks if the asset contains valid data.
 

Detailed Description

Type-erased container for loaded asset data.

Asset is a polymorphic wrapper that provides a uniform interface for storing and accessing different types of loaded assets (textures, meshes, materials, etc.).

Assets represent read-only data that has been loaded from external sources (files, network, etc.) rather than generated at runtime. They can be loaded through built-in asset loader plugins or user-provided custom loaders.

Note
Assets use move semantics and cannot be copied, ensuring single ownership of the underlying asset data.

Example usage:

// Create an asset from a texture
Asset textureAsset(myTexture);
// Retrieve the texture data
const auto& texture = textureAsset.get<Infinity::Types::Containers::Texture>();
// Check if asset is valid
if (textureAsset) {
// Use the asset
}
Type-erased container for loaded asset data.
Definition Asset.hpp:40
Two-dimensional array container for grid-based data in procedural generation.
Definition Array2D.hpp:82

Constructor & Destructor Documentation

◆ Asset() [1/19]

Infinity::Assets::Asset::Asset ( )

Default constructor - creates an empty/invalid asset.

◆ Asset() [2/19]

Infinity::Assets::Asset::Asset ( const std::string &  text)

Constructs an asset containing text data.

Parameters
textThe text string to store in the asset.

◆ Asset() [3/19]

Infinity::Assets::Asset::Asset ( const Infinity::Types::Containers::GrayscaleTexture tex)

Constructs an asset from a grayscale texture.

Parameters
texThe grayscale texture data (single-channel).

◆ Asset() [4/19]

Infinity::Assets::Asset::Asset ( const Infinity::Types::Containers::Array2D< float > &  tex)

Constructs an asset from a 2D array of floats.

Parameters
texThe 2D float array (e.g., heightmap, single-channel data).

◆ Asset() [5/19]

Infinity::Assets::Asset::Asset ( const Infinity::Types::Containers::Array2D< Infinity::Types::Math::Vector3ub > &  tex)

Constructs an asset from a 2D array of unsigned byte RGB vectors.

Parameters
texThe 2D RGB texture with 8-bit channels (0-255 per channel).

◆ Asset() [6/19]

Infinity::Assets::Asset::Asset ( const Infinity::Types::Containers::Array2D< Infinity::Types::Math::Vector3 > &  tex)

Constructs an asset from a 2D array of float RGB vectors.

Parameters
texThe 2D RGB texture with floating-point channels.

◆ Asset() [7/19]

Infinity::Assets::Asset::Asset ( const Infinity::Types::Containers::Texture tex)

Constructs an asset from a standard texture.

Parameters
texThe texture data (typically RGBA format).

◆ Asset() [8/19]

Infinity::Assets::Asset::Asset ( const Infinity::Types::Containers::Array2D< Infinity::Types::Math::Vector4 > &  tex)

Constructs an asset from a 2D array of RGBA vectors.

Parameters
texThe 2D RGBA texture with floating-point channels.

◆ Asset() [9/19]

Infinity::Assets::Asset::Asset ( const Infinity::Types::Containers::Array3D< uint8_t > &  tex)

Constructs an asset from a 3D array of unsigned bytes.

Parameters
texThe 3D volumetric data with 8-bit values (e.g., voxel data).

◆ Asset() [10/19]

Infinity::Assets::Asset::Asset ( const Infinity::Types::Containers::Array3D< float > &  tex)

Constructs an asset from a 3D array of floats.

Parameters
texThe 3D volumetric data with floating-point values.

◆ Asset() [11/19]

Infinity::Assets::Asset::Asset ( const Infinity::Types::Containers::Array3D< Infinity::Types::Math::Vector3ub > &  tex)

Constructs an asset from a 3D array of unsigned byte RGB vectors.

Parameters
texThe 3D volumetric RGB data with 8-bit channels.

◆ Asset() [12/19]

Infinity::Assets::Asset::Asset ( const Infinity::Types::Containers::Array3D< Infinity::Types::Math::Vector3 > &  tex)

Constructs an asset from a 3D array of float RGB vectors.

Parameters
texThe 3D volumetric RGB data with floating-point channels.

◆ Asset() [13/19]

Infinity::Assets::Asset::Asset ( const Infinity::Types::Containers::Texture3D tex)

Constructs an asset from a 3D texture.

Parameters
texThe 3D/volumetric texture data (typically RGBA format).

◆ Asset() [14/19]

Infinity::Assets::Asset::Asset ( const Infinity::Types::Containers::Array3D< Infinity::Types::Math::Vector4 > &  tex)

Constructs an asset from a 3D array of RGBA vectors.

Parameters
texThe 3D volumetric RGBA data with floating-point channels.

◆ Asset() [15/19]

Infinity::Assets::Asset::Asset ( const Infinity::Types::Rendering::Mesh mesh)

Constructs an asset from mesh data.

Parameters
meshThe 3D mesh containing vertices, normals, UVs, etc.

◆ Asset() [16/19]

Infinity::Assets::Asset::Asset ( const Infinity::Types::Rendering::Material mat)

Constructs an asset from material data.

Parameters
matThe material containing shading properties and texture references.

◆ Asset() [17/19]

Infinity::Assets::Asset::Asset ( const Infinity::Types::Rendering::RenderObject ro)

Constructs an asset from a render object.

Parameters
roThe complete renderable object (mesh + material + transform).

◆ Asset() [18/19]

Infinity::Assets::Asset::Asset ( Asset &&  other)

Move constructor - transfers ownership of asset data.

Parameters
otherThe asset to move from (left in valid but unspecified state).

◆ Asset() [19/19]

Infinity::Assets::Asset::Asset ( std::unique_ptr< Infinity::Types::Core::Base > &&  data)

Constructs an asset from a polymorphic base pointer.

Parameters
dataUnique pointer to asset data (ownership is transferred).
Note
This is primarily for internal use or advanced scenarios.

◆ ~Asset()

Infinity::Assets::Asset::~Asset ( )

Destructor - releases owned asset data.

Member Function Documentation

◆ get()

template<typename T >
const T & Infinity::Assets::Asset::get ( )
inline

Retrieves the stored asset data as the specified type.

This template method performs runtime type checking and returns a reference to the underlying data. The behavior depends on whether T derives from Infinity::Types::Core::Data or is wrapped in a Value<T>.

Template Parameters
TThe expected type of the asset data.
Returns
Const reference to the asset data of type T.
Warning
This method performs a dynamic_cast. If the asset does not contain data of type T, the behavior is undefined (likely a crash). Consider checking the asset type before calling this method.

Example usage:

Asset asset(myTexture);
const auto& texture = asset.get<Infinity::Types::Containers::Texture>();

◆ operator bool()

Infinity::Assets::Asset::operator bool ( )
inline

Checks if the asset contains valid data.

Returns
true if the asset contains data, false if empty/invalid.

Example usage:

Asset asset;
if (!asset) {
std::cout << "Asset is empty" << std::endl;
}

◆ operator=()

Asset & Infinity::Assets::Asset::operator= ( Asset &&  other)

Move assignment operator - transfers ownership of asset data.

Parameters
otherThe asset to move from (left in valid but unspecified state).
Returns
Reference to this asset.

◆ release()

Infinity::Types::Core::Base * Infinity::Assets::Asset::release ( )

Releases ownership of the underlying asset data.

After calling this method, the Asset object will be in an empty state (equivalent to default-constructed). The caller assumes ownership of the returned pointer and is responsible for its deletion.

Returns
Raw pointer to the asset data (caller owns this pointer).
Warning
The returned pointer must be manually deleted or transferred to a smart pointer to avoid memory leaks.