plugin.cpp 1.1 KB

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