plugin.cpp 964 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #include <cr.h>
  2. #include <entt/core/type_info.hpp>
  3. #include <entt/signal/dispatcher.hpp>
  4. #include "type_context.h"
  5. #include "types.h"
  6. struct ctx {
  7. inline static type_context *ref;
  8. };
  9. template<typename Type>
  10. struct entt::type_seq<Type> {
  11. [[nodiscard]] static id_type value() ENTT_NOEXCEPT {
  12. static const entt::id_type value = ctx::ref->value(entt::type_hash<Type>::value());
  13. return value;
  14. }
  15. };
  16. CR_EXPORT int cr_main(cr_plugin *ctx, cr_op operation) {
  17. switch (operation) {
  18. case CR_STEP:
  19. if(!ctx::ref) {
  20. ctx::ref = static_cast<type_context *>(ctx->userdata);
  21. } else {
  22. static_cast<entt::dispatcher *>(ctx->userdata)->trigger<event>();
  23. static_cast<entt::dispatcher *>(ctx->userdata)->trigger<message>(42);
  24. }
  25. break;
  26. case CR_CLOSE:
  27. case CR_LOAD:
  28. case CR_UNLOAD:
  29. // nothing to do here, this is only a test.
  30. break;
  31. }
  32. return 0;
  33. }