added UUID
This commit is contained in:
36
open_engine/include/open_engine/core/uuid.hpp
Normal file
36
open_engine/include/open_engine/core/uuid.hpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#ifndef UUID_HPP
|
||||
#define UUID_HPP
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace OpenEngine {
|
||||
|
||||
class UUID
|
||||
{
|
||||
public:
|
||||
UUID();
|
||||
UUID(uint64_t uuid);
|
||||
UUID(const UUID&) = default;
|
||||
|
||||
operator uint64_t() const { return uuid; };
|
||||
|
||||
private:
|
||||
uint64_t uuid;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
namespace std {
|
||||
|
||||
template<>
|
||||
struct hash<OpenEngine::UUID>
|
||||
{
|
||||
std::size_t operator()(const OpenEngine::UUID& uuid) const
|
||||
{
|
||||
return hash<uint64_t>()((uint64_t)uuid);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // UUID_HPP
|
||||
@@ -1,12 +1,12 @@
|
||||
#ifndef COMPONENTS_HPP
|
||||
#define COMPONENTS_HPP
|
||||
|
||||
#include "open_engine/scene/native_scriptable_entity.hpp"
|
||||
#include "open_engine/renderer/renderer3d.hpp"
|
||||
#include "open_engine/scene/scene_camera.hpp"
|
||||
#include "open_engine/renderer/texture.hpp"
|
||||
#include "open_engine/renderer/renderer3d.hpp"
|
||||
#include "open_engine/physics.hpp"
|
||||
#include "open_engine/core/uuid.hpp"
|
||||
|
||||
#include <Jolt/Physics/Body/BodyCreationSettings.h>
|
||||
#include <Jolt/Physics/Body/BodyInterface.h>
|
||||
@@ -28,6 +28,15 @@
|
||||
|
||||
namespace OpenEngine {
|
||||
|
||||
struct IDComponent
|
||||
{
|
||||
UUID id;
|
||||
|
||||
IDComponent() = default;
|
||||
IDComponent(const IDComponent&) = default;
|
||||
IDComponent(const UUID& uuid) : id(uuid) {};
|
||||
};
|
||||
|
||||
struct TagComponent
|
||||
{
|
||||
std::string tag;
|
||||
@@ -74,6 +83,8 @@ namespace OpenEngine {
|
||||
CameraComponent(const CameraComponent&) = default;
|
||||
};
|
||||
|
||||
class NativeScriptableEntity;
|
||||
|
||||
struct NativeScriptComponent
|
||||
{
|
||||
NativeScriptableEntity* instance = nullptr;
|
||||
@@ -81,9 +92,6 @@ namespace OpenEngine {
|
||||
NativeScriptableEntity* (*InstanciateScript)();
|
||||
void (*DestroyInstanceScript)(NativeScriptComponent*);
|
||||
|
||||
void OnImGuiRender(Entity& entity)
|
||||
{};
|
||||
|
||||
template <typename T>
|
||||
void Bind()
|
||||
{
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
#include "open_engine/core.hpp"
|
||||
|
||||
#include "open_engine/core/uuid.hpp"
|
||||
#include "open_engine/scene/components.hpp"
|
||||
#include "open_engine/scene/scene.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
@@ -48,6 +50,8 @@ namespace OpenEngine {
|
||||
return scene->registry.all_of<T>(handle);
|
||||
};
|
||||
|
||||
UUID GetUUID() { return GetComponents<IDComponent>().id; };
|
||||
|
||||
operator bool() const { return handle != entt::null; };
|
||||
operator entt::entity() const { return handle; };
|
||||
operator uint32_t() const { return (uint32_t)handle; };
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef NATIVE_SCRIPTABLE_ENTITY_HPP
|
||||
#define NATIVE_SCRIPTABLE_ENTITY_HPP
|
||||
|
||||
#include "open_engine/scene/native_scriptable_entity.hpp"
|
||||
#include "open_engine/scene/entity.hpp"
|
||||
|
||||
namespace OpenEngine {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef SCENE_HPP
|
||||
#define SCENE_HPP
|
||||
|
||||
#include "open_engine/core/uuid.hpp"
|
||||
#include "open_engine/renderer/editor_camera.hpp"
|
||||
#include "open_engine/physics.hpp"
|
||||
|
||||
@@ -24,6 +25,7 @@ namespace OpenEngine {
|
||||
void OnRuntimeStop();
|
||||
|
||||
Entity CreateEntity(const std::string& name = std::string());
|
||||
Entity CreateEntityWithUUID(UUID uuid, const std::string& name = std::string());
|
||||
void DeleteEntity(entt::entity entity);
|
||||
void MarkEntityForDeletion(Entity entity);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user