lib.cpp 677 B

123456789101112131415161718192021
  1. #include <entt/core/attribute.h>
  2. #include <entt/entity/registry.hpp>
  3. #include "../common/types.h"
  4. template class entt::basic_registry<entt::entity>;
  5. ENTT_API void update_position(entt::registry &registry) {
  6. registry.view<position, velocity>().each([](auto &pos, auto &vel) {
  7. pos.x += static_cast<int>(16 * vel.dx);
  8. pos.y += static_cast<int>(16 * vel.dy);
  9. });
  10. }
  11. ENTT_API void emplace_velocity(entt::registry &registry) {
  12. // forces the creation of the pool for the velocity component
  13. static_cast<void>(registry.storage<velocity>());
  14. for(auto entity: registry.view<position>()) {
  15. registry.emplace<velocity>(entity, 1., 1.);
  16. }
  17. }