Add declare_uuid macro to simplify creating ecs component classes
This commit is contained in:
parent
2d2362d85c
commit
fee1f647b2
4 changed files with 18 additions and 32 deletions
6
libs/ecs/include/psemek/ecs/declare_uuid.hpp
Normal file
6
libs/ecs/include/psemek/ecs/declare_uuid.hpp
Normal 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; }
|
||||
|
|
@ -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")
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue