21 class AbstractResourceHandle;
154 if(
mData !=
nullptr) {
160 if(
mData !=
nullptr) {
189 requires(std::is_convertible_v<U*, T*>)
195 requires(std::is_convertible_v<U*, T*>)
209 requires(std::is_convertible_v<U*, T*>)
215 requires(std::is_convertible_v<U*, T*>)
247 return *
static_cast<T*
>(resource);
275 template<
typename U1,
typename U2>
284 template<
typename U1,
typename U2>
310 template<
typename U1,
typename U2>
312 return lhs.mData == rhs.mData;
316 return lhs.mData != rhs.mData;
361 requires(std::is_convertible_v<U*, T*>)
367 requires(std::is_convertible_v<U*, T*>)
381 requires(std::is_convertible_v<U*, T*>)
387 requires(std::is_convertible_v<U*, T*>)
395 requires(std::is_convertible_v<U*, T*>)
401 requires(std::is_convertible_v<U*, T*>)
419 if(
mData ==
nullptr) {
431 if(
mData !=
nullptr) {
437 if(
mData !=
nullptr) {
457template<
typename T>
struct std::hash<
CeresEngine::ResourceHandle<T>> final {
459 size_t operator()(
const HashedType& type)
const {
461 return hash(type.getUUID());
#define CE_ASSERT(...)
Definition Macros.hpp:323
#define CE_EXPLICIT(EXPR)
Definition Macros.hpp:413
Base class for weak and strong resource handle implementation.
Definition ResourceHandle.hpp:118
bool isLoaded() const noexcept
Checks if the resource handle is valid and loaded.
Definition ResourceHandle.hpp:141
AbstractResourceHandle()=default
AbstractResourceHandle(ResourceHandleData *data)
Definition ResourceHandle.hpp:124
AbstractResourceHandle(SPtr< Resource > resource) noexcept
bool isValid() const noexcept
Checks if the resource handle is valid.
Definition ResourceHandle.hpp:135
ResourceHandleData * mData
Definition ResourceHandle.hpp:120
const UUID & getUUID() const noexcept
Definition ResourceHandle.hpp:129
void set(ResourceHandleData *const data) noexcept
Changes the internal resource handle data object of the handle.
Definition ResourceHandle.hpp:153
Async< HResource > load() const
Loads the resource, if not loaded.
void reset()
Resets the resource handle to the default state.
Definition ResourceHandle.hpp:147
Scoped connection class.
Definition Event.hpp:104
A class that implements a simple interface for reference counting.
Definition SmartPtr.hpp:82
Definition ResourceHandle.hpp:23
~ResourceHandleData()
Destroys the resource handle data and notifies the manager that it is being destroyed.
Event< void(const HResource &)> didUnloadResource
An event fired whenever the resource is unloaded.
Definition ResourceHandle.hpp:56
const UUID mUUID
The resource UUID the handle is representing.
Definition ResourceHandle.hpp:35
void notifyStrongRelease()
Notifies the ResourceManager that all strong ResourceHandles have been destroyed and the manager can ...
ResourcePtr mResource
The resource being managed by the resource handle, if any.
Definition ResourceHandle.hpp:40
Event< void(const HResource &)> didLoadResource
An event fired whenever the resource is loaded.
Definition ResourceHandle.hpp:53
void strongRetain()
Retains the strong resource count.
void setResource(ResourcePtr &&resource)
Changes the resource instance.
Resource * getResource() const noexcept
The resource being managed by the resource handle, if any.
Definition ResourceHandle.hpp:80
void weakRelease()
Releases the weak resource count.
ResourceHandleData(ResourceManager &manager, const UUID &uuid, ResourcePtr &&resource=nullptr)
Creates a new resource handle data.
Definition ResourceHandle.hpp:63
RefCounter mReferenceCounter
A reference counter that counts the number of total references (strong + weak) to the resource.
Definition ResourceHandle.hpp:45
RefCounter mStrongReferenceCounter
A reference counter that counts the number of strong references to the resource.
Definition ResourceHandle.hpp:50
const ResourcePtr & getResourcePointer() const noexcept
The resource being managed by the resource handle, if any.
Definition ResourceHandle.hpp:83
ResourceManager * mResourceManager
The resource manager that the handle belongs to.
Definition ResourceHandle.hpp:31
void weakRetain()
Retains the weak resource count.
const UUID & getUUID() const noexcept
The resource UUID the handle is representing.
Definition ResourceHandle.hpp:77
void strongRelease()
Releases the strong resource count.
ResourceHandleData(const UUID &uuid, ResourcePtr &&resource=nullptr)
Creates a new resource handle data.
Definition ResourceHandle.hpp:69
Definition ResourceHandle.hpp:166
ResourceHandle & operator=(ResourceHandle &&other) noexcept
Definition ResourceHandle.hpp:202
ResourceHandle(const ResourceHandle< U > &other) noexcept
Definition ResourceHandle.hpp:190
ResourceHandle(const ResourceHandle &other)
Definition ResourceHandle.hpp:182
friend bool operator!=(std::nullptr_t, const ResourceHandle< U > &rhs) noexcept
Checks if both references not represent the same handle.
Definition ResourceHandle.hpp:322
friend bool operator!=(const ResourceHandle< U1 > &lhs, const ResourceHandle< U2 > &rhs) noexcept
Checks if both references not represent the same handle.
Definition ResourceHandle.hpp:315
ResourceHandle() noexcept=default
friend bool operator==(const ResourceHandle< U > &lhs, std::nullptr_t) noexcept
Checks if the reference lhs is nullptr.
Definition ResourceHandle.hpp:319
T & operator*() const noexcept
Definition ResourceHandle.hpp:243
T * get() const noexcept
Definition ResourceHandle.hpp:231
ResourceHandle & operator=(std::nullptr_t)
Definition ResourceHandle.hpp:177
Async< ResourceHandle< T > > load() const
Loads the resource, if not loaded.
Definition ResourceHandle.hpp:331
friend bool operator==(std::nullptr_t, const ResourceHandle< U > &rhs) noexcept
Checks if both references represent the same handle.
Definition ResourceHandle.hpp:320
SPtr< T > getPointer() const noexcept
Definition ResourceHandle.hpp:234
EventConnection didUnloadResource(Func &&func)
Definition ResourceHandle.hpp:263
ResourceHandle(SPtr< T > resource) noexcept
Definition ResourceHandle.hpp:222
T * operator->() const noexcept
Definition ResourceHandle.hpp:237
ResourceHandle & operator=(const ResourceHandle &other)
Definition ResourceHandle.hpp:183
ResourceHandle(ResourceHandle &&other) noexcept
Definition ResourceHandle.hpp:201
friend bool operator==(const ResourceHandle< U1 > &lhs, const ResourceHandle< U2 > &rhs) noexcept
Checks if both references represent the same handle.
Definition ResourceHandle.hpp:311
friend class AbstractResourceHandle
Definition ResourceHandle.hpp:168
EventConnection didLoadResource(Func &&func)
Attaches a new event that will called whenever the.
Definition ResourceHandle.hpp:258
friend bool operator!=(const ResourceHandle< U > &lhs, std::nullptr_t) noexcept
Checks if the reference lhs is not nullptr.
Definition ResourceHandle.hpp:321
ResourceHandle(ResourceHandle< U > &&other) noexcept
Definition ResourceHandle.hpp:210
ResourceHandle(ResourceHandleData *data)
Definition ResourceHandle.hpp:227
friend ResourceHandle< U > static_resource_cast(const ResourceHandle< V > &handle)
Definition ResourceHandle.hpp:326
~ResourceHandle() noexcept
Definition ResourceHandle.hpp:224
friend ResourceHandle< U > static_resource_cast(ResourceHandle< V > &&handle)
Definition ResourceHandle.hpp:327
A base class that all resources must extend from.
Definition Resource.hpp:186
The ResourceManager is the main class responsible for managing and handling all resources in the engi...
Definition ResourceManager.hpp:47
Base template for the event class.
Definition Event.hpp:27
Definition ResourceHandle.hpp:339
friend WeakResourceHandle< U > static_resource_cast(WeakResourceHandle< V > &&handle)
Definition ResourceHandle.hpp:451
WeakResourceHandle(const ResourceHandle< U > &other) noexcept
Definition ResourceHandle.hpp:396
WeakResourceHandle(ResourceHandleData *data)
Definition ResourceHandle.hpp:410
WeakResourceHandle() noexcept=default
WeakResourceHandle & operator=(const WeakResourceHandle &other)
Definition ResourceHandle.hpp:355
WeakResourceHandle & operator=(std::nullptr_t)
Definition ResourceHandle.hpp:349
void set(ResourceHandleData *data) noexcept
Changes the internal resource handle data object of the handle.
Definition ResourceHandle.hpp:430
WeakResourceHandle(const WeakResourceHandle &other)
Definition ResourceHandle.hpp:354
WeakResourceHandle(const WeakResourceHandle< U > &other) noexcept
Definition ResourceHandle.hpp:362
ResourceHandle< T > lock() const noexcept
Definition ResourceHandle.hpp:413
WeakResourceHandle(WeakResourceHandle< U > &&other) noexcept
Definition ResourceHandle.hpp:382
WeakResourceHandle & operator=(WeakResourceHandle &&other) noexcept
Definition ResourceHandle.hpp:374
const UUID & getUUID() const noexcept
Definition ResourceHandle.hpp:417
~WeakResourceHandle() noexcept
Definition ResourceHandle.hpp:407
ResourceHandleData * mData
Definition ResourceHandle.hpp:343
WeakResourceHandle(WeakResourceHandle &&other) noexcept
Definition ResourceHandle.hpp:373
friend WeakResourceHandle< U > static_resource_cast(const WeakResourceHandle< V > &handle)
Definition ResourceHandle.hpp:447
Definition Application.hpp:19
std::shared_ptr< T > SPtr
SPtr is a smart pointer that retains shared ownership of an object through a pointer.
Definition SmartPtr.hpp:37
cti::continuable< Args... > Async
Defines a non-copyable continuation type which uses the function2 backend for type erasure.
Definition Async.hpp:22
auto move(Vector3 position)
Moves a entity to the given position.
Definition Helpers.hpp:22
bool operator!=(const ShortAllocator< T, N, A1 > &x, const ShortAllocator< U, M, A2 > &y) noexcept
Definition Allocator.hpp:416
SPtr< Resource > ResourcePtr
Definition Forward.hpp:47
bool operator==(const ShortAllocator< T, N, A1 > &x, const ShortAllocator< U, M, A2 > &y) noexcept
Definition Allocator.hpp:411
ResourceHandle< U > static_resource_cast(const ResourceHandle< V > &handle)
Definition ResourceHandle.hpp:326
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
Represents a universally unique identifier (UUID).
Definition UUID.hpp:27