plugin.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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_index<Type> {
  9. [[nodiscard]] static id_type value() ENTT_NOEXCEPT {
  10. static const entt::id_type value = context->value(type_info<Type>::id());
  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. static_cast<entt::registry *>(ctx->userdata)->prepare<velocity>();
  22. const auto view = static_cast<entt::registry *>(ctx->userdata)->view<position>();
  23. static_cast<entt::registry *>(ctx->userdata)->insert(view.begin(), view.end(), velocity{1., 1.});
  24. static_cast<entt::registry *>(ctx->userdata)->view<position, velocity>().each([](auto &pos, auto &vel) {
  25. pos.x += static_cast<int>(16 * vel.dx);
  26. pos.y += static_cast<int>(16 * vel.dy);
  27. });
  28. }
  29. break;
  30. case CR_CLOSE:
  31. case CR_LOAD:
  32. case CR_UNLOAD:
  33. // nothing to do here, this is only a test.
  34. break;
  35. }
  36. return 0;
  37. }