plugin.cpp 802 B

1234567891011121314151617181920212223242526272829
  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. // forces things to break
  8. auto &registry = *static_cast<entt::registry *>(ctx->userdata);
  9. registry.prepare<velocity>();
  10. const auto view = registry.view<position>();
  11. registry.insert(view.begin(), view.end(), velocity{1., 1.});
  12. registry.view<position, velocity>().each([](position &pos, velocity &vel) {
  13. pos.x += static_cast<int>(16 * vel.dx);
  14. pos.y += static_cast<int>(16 * vel.dy);
  15. });
  16. } break;
  17. case CR_CLOSE:
  18. case CR_LOAD:
  19. case CR_UNLOAD:
  20. // nothing to do here, this is only a test.
  21. break;
  22. }
  23. return 0;
  24. }