test: use common types for lib tests (registry)

This commit is contained in:
Michele Caini
2024-02-13 08:26:04 +01:00
parent 1962027c80
commit a0a2ad4404
5 changed files with 43 additions and 53 deletions

View File

@@ -1,22 +1,24 @@
#include <common/boxed_type.h>
#include <common/empty.h>
#include <cr.h>
#include <entt/entity/registry.hpp>
#include "../common/types.h"
CR_EXPORT int cr_main(cr_plugin *ctx, cr_op operation) {
constexpr auto count = 3;
switch(operation) {
case CR_STEP: {
// forces things to break
auto &registry = *static_cast<entt::registry *>(ctx->userdata);
// forces the creation of the pool for the velocity component
static_cast<void>(registry.storage<velocity>());
// forces the creation of the pool for the empty component
static_cast<void>(registry.storage<test::empty>());
const auto view = registry.view<position>();
registry.insert(view.begin(), view.end(), velocity{1., 1.});
const auto view = registry.view<test::boxed_int>();
registry.insert(view.begin(), view.end(), test::empty{});
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);
registry.view<test::boxed_int, test::empty>().each([count](test::boxed_int &elem) {
elem.value += count;
});
} break;
case CR_CLOSE: