plugin.cpp 1.1 KB

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