2015-08-21 00:06:39 +00:00
|
|
|
#ifndef __RETRO_CTOKEN_HPP__
|
|
|
|
#define __RETRO_CTOKEN_HPP__
|
|
|
|
|
2015-08-22 01:58:41 +00:00
|
|
|
#include <memory>
|
2015-08-23 06:42:29 +00:00
|
|
|
#include "IObj.hpp"
|
2015-08-22 01:58:41 +00:00
|
|
|
#include "RetroTypes.hpp"
|
2015-08-23 06:42:29 +00:00
|
|
|
#include "IVParamObj.hpp"
|
2015-08-22 01:58:41 +00:00
|
|
|
#include "IObjectStore.hpp"
|
2015-08-23 06:42:29 +00:00
|
|
|
#include "IFactory.hpp"
|
2015-08-22 01:58:41 +00:00
|
|
|
|
2015-08-21 00:06:39 +00:00
|
|
|
namespace Retro
|
|
|
|
{
|
2015-08-22 01:58:41 +00:00
|
|
|
class IObjectStore;
|
|
|
|
class IObj;
|
|
|
|
|
|
|
|
class CObjectReference
|
|
|
|
{
|
|
|
|
u16 x0_refCount = 0;
|
|
|
|
bool x3_loading = false;
|
|
|
|
SObjectTag x4_objTag;
|
|
|
|
IObjectStore* xC_objectStore = nullptr;
|
|
|
|
std::unique_ptr<IObj> x10_object;
|
|
|
|
CVParamTransfer x14_params;
|
|
|
|
public:
|
|
|
|
CObjectReference(IObjectStore& objStore, std::unique_ptr<IObj>&& obj,
|
|
|
|
const SObjectTag& objTag, CVParamTransfer buildParams)
|
|
|
|
: x4_objTag(objTag), xC_objectStore(&objStore),
|
|
|
|
x10_object(std::move(obj)), x14_params(buildParams) {}
|
|
|
|
CObjectReference(std::unique_ptr<IObj>&& obj);
|
|
|
|
|
|
|
|
bool IsLoading() const {return x3_loading;}
|
|
|
|
void Unlock() {}
|
2015-08-23 06:42:29 +00:00
|
|
|
void Lock() {}
|
|
|
|
u32 RemoveReference()
|
|
|
|
{
|
|
|
|
--x0_refCount;
|
|
|
|
if (x0_refCount == 0)
|
|
|
|
{
|
|
|
|
if (x10_object)
|
|
|
|
Unload();
|
|
|
|
if (IsLoading())
|
|
|
|
CancelLoad();
|
|
|
|
xC_objectStore->ObjectUnreferenced(x4_objTag);
|
|
|
|
}
|
|
|
|
}
|
2015-08-22 01:58:41 +00:00
|
|
|
void CancelLoad() {}
|
2015-08-23 06:42:29 +00:00
|
|
|
void Unload()
|
|
|
|
{
|
|
|
|
x10_object.reset(nullptr);
|
|
|
|
x3_loading = false;
|
|
|
|
}
|
|
|
|
IObj& GetObject()
|
|
|
|
{
|
|
|
|
IFactory& factory = xC_objectStore->GetFactory();
|
|
|
|
factory.Build(x4_objTag, x14_params);
|
|
|
|
}
|
2015-08-22 01:58:41 +00:00
|
|
|
|
|
|
|
};
|
2015-08-21 00:06:39 +00:00
|
|
|
|
|
|
|
class CToken
|
|
|
|
{
|
2015-08-23 06:42:29 +00:00
|
|
|
CObjectReference& x0_objRef;
|
2015-08-22 01:58:41 +00:00
|
|
|
bool x4_lockHeld = false;
|
|
|
|
public:
|
2015-08-23 06:42:29 +00:00
|
|
|
void Unlock()
|
2015-08-22 01:58:41 +00:00
|
|
|
{
|
|
|
|
if (x4_lockHeld)
|
2015-08-23 06:42:29 +00:00
|
|
|
{
|
|
|
|
x0_objRef.Unlock();
|
|
|
|
x4_lockHeld = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void Lock()
|
|
|
|
{
|
|
|
|
if (!x4_lockHeld)
|
|
|
|
{
|
|
|
|
x0_objRef.Lock();
|
|
|
|
x4_lockHeld = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void RemoveRef()
|
|
|
|
{
|
2015-08-22 01:58:41 +00:00
|
|
|
|
|
|
|
}
|
2015-08-23 06:42:29 +00:00
|
|
|
IObj& GetObj()
|
|
|
|
{
|
|
|
|
Lock();
|
|
|
|
return x0_objRef.GetObject();
|
|
|
|
}
|
|
|
|
CToken& operator=(CToken&& other)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
~CToken()
|
|
|
|
{
|
|
|
|
if (x0_objRef && x4_lockHeld)
|
|
|
|
x0_objRef->Unlock();
|
|
|
|
}
|
2015-08-21 00:06:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
class TLockedToken
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // __RETRO_CTOKEN_HPP__
|