Squashed 'external/entt/entt/' content from commit fef92113
git-subtree-dir: external/entt/entt git-subtree-split: fef921132cae7588213d0f9bcd2fb9c8ffd8b7fc
This commit is contained in:
31
test/lib/registry_plugin/main.cpp
Normal file
31
test/lib/registry_plugin/main.cpp
Normal file
@ -0,0 +1,31 @@
|
||||
#define CR_HOST
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <cr.h>
|
||||
#include <entt/entity/registry.hpp>
|
||||
#include "types.h"
|
||||
|
||||
TEST(Lib, Registry) {
|
||||
entt::registry registry;
|
||||
|
||||
for(auto i = 0; i < 3; ++i) {
|
||||
registry.emplace<position>(registry.create(), i, i);
|
||||
}
|
||||
|
||||
cr_plugin ctx;
|
||||
cr_plugin_load(ctx, PLUGIN);
|
||||
|
||||
ctx.userdata = ®istry;
|
||||
cr_plugin_update(ctx);
|
||||
|
||||
ASSERT_EQ(registry.storage<position>().size(), registry.storage<velocity>().size());
|
||||
ASSERT_EQ(registry.storage<position>().size(), registry.size());
|
||||
|
||||
registry.view<position>().each([](auto entity, auto &position) {
|
||||
ASSERT_EQ(position.x, static_cast<int>(entt::to_integral(entity) + 16u));
|
||||
ASSERT_EQ(position.y, static_cast<int>(entt::to_integral(entity) + 16u));
|
||||
});
|
||||
|
||||
registry = {};
|
||||
cr_plugin_close(ctx);
|
||||
}
|
30
test/lib/registry_plugin/plugin.cpp
Normal file
30
test/lib/registry_plugin/plugin.cpp
Normal file
@ -0,0 +1,30 @@
|
||||
#include <cr.h>
|
||||
#include <entt/entity/registry.hpp>
|
||||
#include "types.h"
|
||||
|
||||
CR_EXPORT int cr_main(cr_plugin *ctx, cr_op operation) {
|
||||
switch(operation) {
|
||||
case CR_STEP: {
|
||||
// forces things to break
|
||||
auto ®istry = *static_cast<entt::registry *>(ctx->userdata);
|
||||
|
||||
// forces the creation of the pool for the velocity component
|
||||
static_cast<void>(registry.storage<velocity>());
|
||||
|
||||
const auto view = registry.view<position>();
|
||||
registry.insert(view.begin(), view.end(), velocity{1., 1.});
|
||||
|
||||
registry.view<position, velocity>().each([](position &pos, velocity &vel) {
|
||||
pos.x += static_cast<int>(16 * vel.dx);
|
||||
pos.y += static_cast<int>(16 * vel.dy);
|
||||
});
|
||||
} break;
|
||||
case CR_CLOSE:
|
||||
case CR_LOAD:
|
||||
case CR_UNLOAD:
|
||||
// nothing to do here, this is only a test.
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
14
test/lib/registry_plugin/types.h
Normal file
14
test/lib/registry_plugin/types.h
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef ENTT_LIB_REGISTRY_PLUGIN_TYPES_H
|
||||
#define ENTT_LIB_REGISTRY_PLUGIN_TYPES_H
|
||||
|
||||
struct position {
|
||||
int x;
|
||||
int y;
|
||||
};
|
||||
|
||||
struct velocity {
|
||||
double dx;
|
||||
double dy;
|
||||
};
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user