2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-12-09 17:07:41 +00:00

Initial round of particle runtime implementations

This commit is contained in:
Jack Andersen
2016-02-04 15:27:03 -10:00
parent cf2464a02b
commit 7a35dac972
46 changed files with 885 additions and 146 deletions

View File

@@ -17,69 +17,6 @@ public:
reserved_vector() {this->reserve(N);}
};
/**
* @brief Simple data/refcount pair
*/
class CRefData
{
void* x0_ptr;
int x4_refCount;
public:
CRefData() : x0_ptr(nullptr), x4_refCount(0xffffff) {}
CRefData(void* ptr) : x0_ptr(ptr), x4_refCount(0) {}
void* GetPtr() const {return x0_ptr;}
int AddRef() {return ++x4_refCount;}
int DelRef() {return --x4_refCount;}
static CRefData sNull;
};
template<class T>
class ncrc_ptr;
/**
* @brief Reference-counted shared smart pointer
*/
template<class T>
class rc_ptr
{
CRefData* m_aux;
friend class ncrc_ptr<T>;
public:
rc_ptr() : m_aux(&CRefData::sNull) {m_aux->AddRef();}
rc_ptr(void* ptr) : m_aux(new CRefData(ptr)) {m_aux->AddRef();}
rc_ptr(const rc_ptr<T>& other) : m_aux(other.m_aux) {m_aux->AddRef();}
rc_ptr(rc_ptr<T>&& other) : m_aux(other.m_aux) {other.m_aux = nullptr;}
rc_ptr(const ncrc_ptr<T>& other) : m_aux(other.m_aux) {m_aux->AddRef();}
~rc_ptr()
{
if (m_aux && !m_aux->DelRef())
{
delete static_cast<T*>(m_aux->GetPtr());
delete m_aux;
}
}
T* operator->() const {return static_cast<T*>(m_aux->GetPtr());}
T& operator*() const {return *static_cast<T*>(m_aux->GetPtr());}
T* get() const {return static_cast<T*>(m_aux->GetPtr());}
operator bool() {return m_aux->GetPtr() != nullptr;}
};
/**
* @brief Non-reference-counted shared smart pointer
*/
template<class T>
class ncrc_ptr
{
CRefData* m_aux;
friend class rc_ptr<T>;
public:
ncrc_ptr(const rc_ptr<T>& other) : m_aux(other.m_aux) {}
T* get() const {return static_cast<T*>(m_aux->GetPtr());}
};
}
#endif // __RSTL_HPP__