Polyphase Game Engine
Loading...
Searching...
No Matches
AssetRef.h
Go to the documentation of this file.
1#pragma once
2
3#include "PolyphaseAPI.h"
4#include "Asset.h"
5#include "Constants.h"
6#include <vector>
7#include "Assertion.h"
8
9#include <unordered_set>
10
11//class Asset;
12class AssetManager;
13struct AsyncLoadRequest;
14
15POLYPHASE_API MutexObject* GetAssetRefMutex();
16
18{
19public:
20
21 AssetRef();
22 AssetRef(Asset* asset);
23 AssetRef(const AssetRef& src);
24 ~AssetRef();
25 AssetRef& operator=(const AssetRef& src);
26 AssetRef& operator=(const Asset* srcAsset);
27
28 bool operator==(const AssetRef& other) const;
29 bool operator!=(const AssetRef& other) const;
30 bool operator==(const Asset* other) const;
31 bool operator!=(const Asset* other) const;
32
33 Asset* Get() const;
34
35 template<typename T>
36 T* Get() const
37 {
38 OCT_ASSERT(!mAsset || mAsset->GetType() == T::GetStaticType() || mAsset->Is(T::ClassRuntimeId()));
39 return static_cast<T*>(Get());
40 }
41
42 void SetLoadRequest(AsyncLoadRequest* loadRequest);
43 AsyncLoadRequest* GetLoadRequest();
44
45 // Drops mAsset without touching its refcount. The normal `*this = nullptr`
46 // assignment decrements the old asset's refcount, which crashes if the
47 // pointer is already dangling (post-purge cross-project leak). Defensive
48 // call sites that detected the dangling pointer via AssetManager
49 // pointer-validation use this to neutralize the ref so subsequent
50 // accesses (and the eventual ~AssetRef) don't redo the same crash.
51 void ClearDangling();
52
53private:
54
55 void EraseAsyncLoadRef();
56
57 Asset* mAsset = nullptr;
58 AsyncLoadRequest* mLoadRequest = nullptr;
59
60#if ASSET_LIVE_REF_TRACKING
61public:
62 static void ReplaceReferencesToAsset(Asset* oldAsset, Asset* newAsset);
63 static void EraseReferencesToAsset(Asset* asset);
64private:
65 static void AddLiveRef(AssetRef* ref);
66 static void RemoveLiveRef(AssetRef* ref);
67#endif
68
69};
70
#define OCT_ASSERT(expr)
Definition Assertion.h:12
POLYPHASE_API MutexObject * GetAssetRefMutex()
Definition AssetRef.cpp:39
AssetRef SoundWaveRef
Definition AssetRef.h:76
AssetRef BoneMaskRef
Definition AssetRef.h:85
AssetRef SpriteAnimationRef
Definition AssetRef.h:82
AssetRef TextureRef
Definition AssetRef.h:71
AssetRef TimelineRef
Definition AssetRef.h:79
AssetRef SceneRef
Definition AssetRef.h:78
AssetRef SkeletalMeshRef
Definition AssetRef.h:74
AssetRef StaticMeshRef
Definition AssetRef.h:72
AssetRef MaterialRef
Definition AssetRef.h:73
AssetRef TransformAnimationRef
Definition AssetRef.h:80
AssetRef ParticleSystemRef
Definition AssetRef.h:75
AssetRef DataAssetRef
Definition AssetRef.h:81
AssetRef SkeletalAnimationRef
Definition AssetRef.h:83
AssetRef FontRef
Definition AssetRef.h:77
AssetRef HumanoidAvatarRef
Definition AssetRef.h:84
Export macros for Polyphase Engine symbols.
#define POLYPHASE_API
Definition PolyphaseAPI.h:31
Definition AssetManager.h:135
Definition AssetRef.h:18
T * Get() const
Definition AssetRef.h:36
Definition Asset.h:119
Definition AssetManager.h:19