plugin.cpp 1011 B

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