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/test/test.hpp>
|
||||||
|
|
||||||
#include <psemek/ecs/entity_container.hpp>
|
#include <psemek/ecs/entity_container.hpp>
|
||||||
|
#include <psemek/ecs/declare_uuid.hpp>
|
||||||
#include <psemek/random/generator.hpp>
|
#include <psemek/random/generator.hpp>
|
||||||
#include <psemek/random/uniform.hpp>
|
#include <psemek/random/uniform.hpp>
|
||||||
|
|
||||||
|
|
@ -14,20 +15,14 @@ namespace
|
||||||
{
|
{
|
||||||
int value;
|
int value;
|
||||||
|
|
||||||
static constexpr util::uuid uuid()
|
psemek_declare_uuid("component_1")
|
||||||
{
|
|
||||||
return {1, 0};
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct component_2
|
struct component_2
|
||||||
{
|
{
|
||||||
int value;
|
int value;
|
||||||
|
|
||||||
static constexpr util::uuid uuid()
|
psemek_declare_uuid("component_2")
|
||||||
{
|
|
||||||
return {2, 0};
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#include <psemek/test/test.hpp>
|
#include <psemek/test/test.hpp>
|
||||||
|
|
||||||
#include <psemek/ecs/entity_container.hpp>
|
#include <psemek/ecs/entity_container.hpp>
|
||||||
|
#include <psemek/ecs/declare_uuid.hpp>
|
||||||
#include <psemek/random/generator.hpp>
|
#include <psemek/random/generator.hpp>
|
||||||
#include <psemek/random/uniform.hpp>
|
#include <psemek/random/uniform.hpp>
|
||||||
|
|
||||||
|
|
@ -14,40 +15,28 @@ namespace
|
||||||
{
|
{
|
||||||
int value;
|
int value;
|
||||||
|
|
||||||
static constexpr util::uuid uuid()
|
psemek_declare_uuid("component_small")
|
||||||
{
|
|
||||||
return {1, 0};
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct component_big
|
struct component_big
|
||||||
{
|
{
|
||||||
int values[16];
|
int values[16];
|
||||||
|
|
||||||
static constexpr util::uuid uuid()
|
psemek_declare_uuid("component_big")
|
||||||
{
|
|
||||||
return {2, 0};
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct component_noncopyable
|
struct component_noncopyable
|
||||||
{
|
{
|
||||||
std::unique_ptr<int> value;
|
std::unique_ptr<int> value;
|
||||||
|
|
||||||
static constexpr util::uuid uuid()
|
psemek_declare_uuid("component_noncopyable")
|
||||||
{
|
|
||||||
return {2, 0};
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct component_counter
|
struct component_counter
|
||||||
{
|
{
|
||||||
std::shared_ptr<int> value;
|
std::shared_ptr<int> value;
|
||||||
|
|
||||||
static constexpr util::uuid uuid()
|
psemek_declare_uuid("component_counter")
|
||||||
{
|
|
||||||
return {2, 0};
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,10 @@
|
||||||
#include <psemek/test/test.hpp>
|
#include <psemek/test/test.hpp>
|
||||||
|
|
||||||
#include <psemek/ecs/entity_container.hpp>
|
#include <psemek/ecs/entity_container.hpp>
|
||||||
|
#include <psemek/ecs/declare_uuid.hpp>
|
||||||
#include <psemek/random/generator.hpp>
|
#include <psemek/random/generator.hpp>
|
||||||
#include <psemek/random/uniform.hpp>
|
#include <psemek/random/uniform.hpp>
|
||||||
|
#include <psemek/log/log.hpp>
|
||||||
|
|
||||||
using namespace psemek;
|
using namespace psemek;
|
||||||
using namespace psemek::ecs;
|
using namespace psemek::ecs;
|
||||||
|
|
@ -14,20 +16,14 @@ namespace
|
||||||
{
|
{
|
||||||
int value;
|
int value;
|
||||||
|
|
||||||
static constexpr util::uuid uuid()
|
psemek_declare_uuid("component_1")
|
||||||
{
|
|
||||||
return {1, 0};
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct component_2
|
struct component_2
|
||||||
{
|
{
|
||||||
int value;
|
int value;
|
||||||
|
|
||||||
static constexpr util::uuid uuid()
|
psemek_declare_uuid("component_2")
|
||||||
{
|
|
||||||
return {2, 0};
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue