-
Notifications
You must be signed in to change notification settings - Fork 42
Impl IRenderObject & TRenderPtr
#194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 8 commits
204c0e7
d79207d
c01b49f
28cbf7e
e25f17c
5ad913f
9f3945b
6925a3c
1a401b1
b7a6e02
948dc4b
089d321
d9cc9c0
3cf99b5
ccb241e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| #pragma once | ||
|
|
||
| #include <RED4ext/Memory/Utils.hpp> | ||
|
|
||
| namespace RED4ext | ||
| { | ||
| struct IRenderObject | ||
wopss marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| template<std::derived_from<IRenderObject> T> | ||
| friend class TRenderPtr; | ||
wopss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| using AllocatorType = Memory::RenderDataAllocator; | ||
|
|
||
| virtual Memory::IAllocator* GetAllocator() | ||
| { | ||
| return AllocatorType::Get(); | ||
| } | ||
|
|
||
| virtual void Destroy() | ||
| { | ||
| if (this) | ||
wopss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| Memory::Delete(this); | ||
| } | ||
| } | ||
|
|
||
| virtual ~IRenderObject() = default; | ||
wopss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| protected: | ||
wopss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| void Release() | ||
| { | ||
| if (--m_refCount < 1) | ||
| Destroy(); | ||
wopss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| void AddRef() | ||
| { | ||
| m_refCount++; | ||
| } | ||
|
|
||
| std::atomic<int32_t> m_refCount = 1; | ||
|
||
| }; | ||
| RED4EXT_ASSERT_SIZE(IRenderObject, 0x10); | ||
|
|
||
| template<std::derived_from<IRenderObject> T = IRenderObject> | ||
wopss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| class TRenderPtr | ||
| { | ||
| public: | ||
| TRenderPtr() = default; | ||
|
|
||
| ~TRenderPtr() | ||
| { | ||
| Release(); | ||
| } | ||
|
|
||
| TRenderPtr(std::nullptr_t) noexcept | ||
| { | ||
| } | ||
|
|
||
| explicit TRenderPtr(T* aPointer) noexcept | ||
| : m_instance(aPointer) | ||
| { | ||
| } | ||
|
|
||
| TRenderPtr(const TRenderPtr& aOther) noexcept | ||
| : m_instance(aOther.m_instance) | ||
| { | ||
| if (m_instance) | ||
| m_instance->AddRef(); | ||
wopss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| TRenderPtr(TRenderPtr&& aOther) noexcept | ||
| { | ||
| Swap(aOther); | ||
| } | ||
wopss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| explicit operator bool() const noexcept | ||
| { | ||
| return m_instance != nullptr; | ||
| } | ||
|
|
||
| TRenderPtr& operator=(const TRenderPtr& aRhs) noexcept | ||
| { | ||
| TRenderPtr(aRhs).Swap(*this); | ||
| return *this; | ||
| } | ||
|
|
||
| TRenderPtr& operator=(TRenderPtr&& aRhs) noexcept | ||
| { | ||
| Swap(aRhs); | ||
| return *this; | ||
| } | ||
|
|
||
| T* operator->() const noexcept | ||
| { | ||
| return m_instance; | ||
| } | ||
|
|
||
| T& operator*() const noexcept | ||
| { | ||
| return *m_instance; | ||
| } | ||
|
|
||
| void Swap(TRenderPtr& aOther) noexcept | ||
| { | ||
| std::swap(m_instance, aOther.m_instance); | ||
| } | ||
|
|
||
| T* GetPtr() const noexcept | ||
| { | ||
| return m_instance; | ||
| } | ||
|
|
||
| private: | ||
| void Release() | ||
| { | ||
| if (m_instance) | ||
| m_instance->Release(); | ||
wopss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| T* m_instance = nullptr; | ||
wopss marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }; | ||
| RED4EXT_ASSERT_SIZE(TRenderPtr<>, 0x08); | ||
wopss marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } // namespace RED4ext | ||
Uh oh!
There was an error while loading. Please reload this page.