Initial engine repository
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
namespace frostbite2D {
|
||||
|
||||
class Noncopyable {
|
||||
protected:
|
||||
Noncopyable() = default;
|
||||
|
||||
private:
|
||||
Noncopyable(const Noncopyable&) = delete;
|
||||
Noncopyable& operator=(const Noncopyable&) = delete;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
#include <frostbite2D/base/Noncopyable.h>
|
||||
|
||||
namespace frostbite2D {
|
||||
|
||||
class RefObject : protected Noncopyable {
|
||||
public:
|
||||
void Retain();
|
||||
void Release();
|
||||
uint32_t GetRefCount() const;
|
||||
|
||||
virtual ~RefObject();
|
||||
|
||||
protected:
|
||||
RefObject();
|
||||
|
||||
private:
|
||||
std::atomic<uint32_t> ref_count_;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
#include <frostbite2D/base/RefObject.h>
|
||||
#include <frostbite2D/core/RefBasePtr.hpp>
|
||||
|
||||
namespace frostbite2D {
|
||||
|
||||
struct DefaultRefPtrPolicy {
|
||||
void Retain(RefObject* ptr) {
|
||||
if (ptr) {
|
||||
ptr->Retain();
|
||||
}
|
||||
}
|
||||
|
||||
void Release(RefObject* ptr) {
|
||||
if (ptr) {
|
||||
ptr->Release();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
using RefPtr = RefBasePtr<T, DefaultRefPtrPolicy>;
|
||||
|
||||
template <typename T, typename... Args>
|
||||
RefPtr<T> MakePtr(Args&&... args) {
|
||||
static_assert(std::is_base_of<RefObject, T>::value,
|
||||
"T must be derived from RefObject");
|
||||
return RefPtr<T>(new T(std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
RefPtr<T> MakePtr(T* ptr) {
|
||||
static_assert(std::is_base_of<RefObject, T>::value,
|
||||
"T must be derived from RefObject");
|
||||
return RefPtr<T>(ptr);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
#include <frostbite2D/base/RefObject.h>
|
||||
#include <frostbite2D/base/RefPtr.h>
|
||||
@@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
#include <frostbite2D/types/type_alias.h>
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
#include <map>
|
||||
|
||||
namespace frostbite2D {
|
||||
|
||||
class Actor;
|
||||
class UUID;
|
||||
|
||||
class ObjectRegistry {
|
||||
public:
|
||||
static ObjectRegistry& get();
|
||||
|
||||
ObjectRegistry(const ObjectRegistry&) = delete;
|
||||
ObjectRegistry& operator=(const ObjectRegistry&) = delete;
|
||||
|
||||
void registerObject(const UUID& uuid, Actor* actor);
|
||||
void unregisterObject(const UUID& uuid);
|
||||
|
||||
Actor* getObject(const UUID& uuid);
|
||||
Actor* getObject(const std::string& uuidStr);
|
||||
|
||||
bool hasObject(const UUID& uuid) const;
|
||||
bool hasObject(const std::string& uuidStr) const;
|
||||
size_t count() const;
|
||||
|
||||
void clear();
|
||||
|
||||
private:
|
||||
ObjectRegistry() = default;
|
||||
~ObjectRegistry() = default;
|
||||
|
||||
std::map<std::string, Actor*> registry_;
|
||||
};
|
||||
|
||||
} // namespace frostbite2D
|
||||
Reference in New Issue
Block a user