plugin.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include <cr.h>
  2. #include <entt/core/type_info.hpp>
  3. #include <entt/entity/registry.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. // forces things to break
  21. auto &registry = *static_cast<entt::registry *>(ctx->userdata);
  22. registry.prepare<velocity>();
  23. const auto view = registry.view<position>();
  24. registry.insert(view.begin(), view.end(), velocity{1., 1.});
  25. registry.view<position, velocity>().each([](position &pos, velocity &vel) {
  26. pos.x += static_cast<int>(16 * vel.dx);
  27. pos.y += static_cast<int>(16 * vel.dy);
  28. });
  29. }
  30. break;
  31. case CR_CLOSE:
  32. case CR_LOAD:
  33. case CR_UNLOAD:
  34. // nothing to do here, this is only a test.
  35. break;
  36. }
  37. return 0;
  38. }