Add ecs ComponentListener

- Add ecs ComponentListener which listens to Component addition and
  removal
- Add RefCounter class used to keep track of moves and copies
This commit is contained in:
Thraix
2023-05-29 17:49:37 +02:00
parent 5a615ecc4e
commit 3ec9bcd152
24 changed files with 351 additions and 70 deletions
+2 -36
View File
@@ -5,51 +5,17 @@
namespace Copium
{
AssetRef::AssetRef(AssetHandle handle)
: handle{handle}, refCounter{new int{1}}
: handle{handle}
{}
AssetRef::~AssetRef()
{
if (refCounter == nullptr)
return;
(*refCounter)--;
if (*refCounter == 0)
if (refCounter.LastRef())
{
AssetManager::UnloadAsset(handle);
delete refCounter;
}
}
AssetRef::AssetRef(const AssetRef& other)
: handle{other.handle}, refCounter{other.refCounter}
{
(*refCounter)++;
}
AssetRef::AssetRef(AssetRef&& other)
: handle{other.handle}, refCounter{other.refCounter}
{
other.refCounter = nullptr;
}
AssetRef& AssetRef::operator=(const AssetRef& rhs)
{
handle = rhs.handle;
refCounter = rhs.refCounter;
(*refCounter)++;
return *this;
}
AssetRef& AssetRef::operator=(AssetRef&& rhs)
{
handle = rhs.handle;
refCounter = rhs.refCounter;
rhs.refCounter = nullptr;
return *this;
}
AssetRef::operator AssetHandle() const
{
return handle;