Add declare_uuid macro to simplify creating ecs component classes

This commit is contained in:
Nikita Lisitsa 2023-08-23 00:04:41 +03:00
parent 2d2362d85c
commit fee1f647b2
4 changed files with 18 additions and 32 deletions

View file

@ -0,0 +1,6 @@
#pragma once
#include <psemek/util/uuid.hpp>
#define psemek_declare_uuid(seed) \
static ::psemek::util::uuid uuid() { static constexpr auto value = ::psemek::util::make_uuid(seed); return value; }

View file

@ -1,6 +1,7 @@
#include <psemek/test/test.hpp>
#include <psemek/ecs/entity_container.hpp>
#include <psemek/ecs/declare_uuid.hpp>
#include <psemek/random/generator.hpp>
#include <psemek/random/uniform.hpp>
@ -14,20 +15,14 @@ namespace
{
int value;
static constexpr util::uuid uuid()
{
return {1, 0};
}
psemek_declare_uuid("component_1")
};
struct component_2
{
int value;
static constexpr util::uuid uuid()
{
return {2, 0};
}
psemek_declare_uuid("component_2")
};
}

View file

@ -1,6 +1,7 @@
#include <psemek/test/test.hpp>
#include <psemek/ecs/entity_container.hpp>
#include <psemek/ecs/declare_uuid.hpp>
#include <psemek/random/generator.hpp>
#include <psemek/random/uniform.hpp>
@ -14,40 +15,28 @@ namespace
{
int value;
static constexpr util::uuid uuid()
{
return {1, 0};
}
psemek_declare_uuid("component_small")
};
struct component_big
{
int values[16];
static constexpr util::uuid uuid()
{
return {2, 0};
}
psemek_declare_uuid("component_big")
};
struct component_noncopyable
{
std::unique_ptr<int> value;
static constexpr util::uuid uuid()
{
return {2, 0};
}
psemek_declare_uuid("component_noncopyable")
};
struct component_counter
{
std::shared_ptr<int> value;
static constexpr util::uuid uuid()
{
return {2, 0};
}
psemek_declare_uuid("component_counter")
};
}

View file

@ -1,8 +1,10 @@
#include <psemek/test/test.hpp>
#include <psemek/ecs/entity_container.hpp>
#include <psemek/ecs/declare_uuid.hpp>
#include <psemek/random/generator.hpp>
#include <psemek/random/uniform.hpp>
#include <psemek/log/log.hpp>
using namespace psemek;
using namespace psemek::ecs;
@ -14,20 +16,14 @@ namespace
{
int value;
static constexpr util::uuid uuid()
{
return {1, 0};
}
psemek_declare_uuid("component_1")
};
struct component_2
{
int value;
static constexpr util::uuid uuid()
{
return {2, 0};
}
psemek_declare_uuid("component_2")
};
}