plugin.cpp 1.2 KB

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