lib.cpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include <entt/entity/registry.hpp>
  2. #include "types.h"
  3. #ifndef LIB_EXPORT
  4. #if defined _WIN32 || defined __CYGWIN__
  5. #define LIB_EXPORT __declspec(dllexport)
  6. #elif defined __GNUC__
  7. #define LIB_EXPORT __attribute__((visibility("default")))
  8. #else
  9. #define LIB_EXPORT
  10. #endif
  11. #endif
  12. LIB_EXPORT typename entt::component int_type() {
  13. entt::registry registry;
  14. (void)registry.type<double>();
  15. (void)registry.type<float>();
  16. return registry.type<int>();
  17. }
  18. LIB_EXPORT typename entt::component char_type() {
  19. entt::registry registry;
  20. (void)registry.type<double>();
  21. (void)registry.type<float>();
  22. return registry.type<char>();
  23. }
  24. LIB_EXPORT void update_position(int delta, entt::registry &registry) {
  25. registry.view<position, velocity>().each([delta](auto &pos, auto &vel) {
  26. pos.x += delta * vel.dx;
  27. pos.y += delta * vel.dy;
  28. });
  29. }
  30. LIB_EXPORT void assign_velocity(int vel, entt::registry &registry) {
  31. for(auto entity: registry.view<position>()) {
  32. registry.assign<velocity>(entity, vel, vel);
  33. }
  34. }