plugin.cpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include <cr.h>
  2. #include <entt/core/hashed_string.hpp>
  3. #include <entt/meta/factory.hpp>
  4. #include <entt/meta/meta.hpp>
  5. #include "types.h"
  6. position create_position(int x, int y) {
  7. return position{x, y};
  8. }
  9. void set_up() {
  10. entt::meta<position>()
  11. .type("position"_hs)
  12. .ctor<&create_position>()
  13. .data<&position::x>("x"_hs)
  14. .data<&position::y>("y"_hs);
  15. entt::meta<velocity>()
  16. .type("velocity"_hs)
  17. .ctor<>()
  18. .data<&velocity::dx>("dx"_hs)
  19. .data<&velocity::dy>("dy"_hs);
  20. }
  21. void tear_down() {
  22. entt::meta<position>().reset();
  23. entt::meta<velocity>().reset();
  24. }
  25. CR_EXPORT int cr_main(cr_plugin *ctx, cr_op operation) {
  26. switch (operation) {
  27. case CR_LOAD:
  28. entt::meta_ctx::bind(static_cast<userdata *>(ctx->userdata)->ctx);
  29. set_up();
  30. break;
  31. case CR_STEP:
  32. static_cast<userdata *>(ctx->userdata)->any = 42;
  33. break;
  34. case CR_UNLOAD:
  35. case CR_CLOSE:
  36. tear_down();
  37. break;
  38. }
  39. return 0;
  40. }