added UUID

This commit is contained in:
Erris
2026-03-06 18:07:51 +01:00
parent 5be3c61859
commit 2d3fe57d5a
10 changed files with 111 additions and 23 deletions

View 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

View File

@@ -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()
{

View File

@@ -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; };

View File

@@ -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 {

View File

@@ -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);