plugin.cpp 785 B

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