plugin.cpp 955 B

123456789101112131415161718192021222324252627282930313233
  1. #include <cr.h>
  2. #include <entt/entity/registry.hpp>
  3. #include "types.h"
  4. CR_EXPORT int cr_main(cr_plugin *ctx, cr_op operation) {
  5. switch (operation) {
  6. case CR_STEP:
  7. [ctx]() {
  8. auto *registry = static_cast<entt::registry *>(ctx->userdata);
  9. // forces the creation of the pool for the velocity component
  10. registry->prepare<velocity>();
  11. for(auto entity: registry->view<position>()) {
  12. registry->assign<velocity>(entity, 1., 1.);
  13. }
  14. registry->view<position, velocity>().each([](auto &pos, auto &vel) {
  15. pos.x += 16 * vel.dx;
  16. pos.y += 16 * vel.dy;
  17. });
  18. }();
  19. break;
  20. case CR_CLOSE:
  21. static_cast<entt::registry *>(ctx->userdata)->discard<velocity>();
  22. break;
  23. case CR_LOAD:
  24. case CR_UNLOAD:
  25. // nothing to do here, this is only a test.
  26. break;
  27. }
  28. return 0;
  29. }