plugin.cpp 838 B

12345678910111213141516171819202122232425262728293031
  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. for(auto entity: registry->view<position>()) {
  10. registry->assign<velocity>(entity, 1., 1.);
  11. }
  12. registry->view<position, velocity>().each([](auto &pos, auto &vel) {
  13. pos.x += 16 * vel.dx;
  14. pos.y += 16 * vel.dy;
  15. });
  16. }();
  17. break;
  18. case CR_CLOSE:
  19. static_cast<entt::registry *>(ctx->userdata)->discard<velocity>();
  20. break;
  21. case CR_LOAD:
  22. case CR_UNLOAD:
  23. // nothing to do here, this is only a test.
  24. break;
  25. }
  26. return 0;
  27. }