mirror of
https://github.com/cpm-cmake/CPM.cmake.git
synced 2025-11-17 14:47:30 -05:00
* apply clang-format and cmake-format and add style check workflow * add declare package definition * add additional public methods and rename internals * change development verison tag to 1.0.0 * rename internal method * rename public method * rename test var * update copyright and fix comment * typo * run fix-format * fix test function names
57 lines
1018 B
C++
57 lines
1018 B
C++
#include <cstdint>
|
|
#include <entt/entt.hpp>
|
|
|
|
struct position {
|
|
float x;
|
|
float y;
|
|
};
|
|
|
|
struct velocity {
|
|
float dx;
|
|
float dy;
|
|
};
|
|
|
|
void update(entt::registry ®istry) {
|
|
auto view = registry.view<position, velocity>();
|
|
|
|
for (auto entity : view) {
|
|
// gets only the components that are going to be used ...
|
|
|
|
auto &vel = view.get<velocity>(entity);
|
|
|
|
vel.dx = 0.;
|
|
vel.dy = 0.;
|
|
|
|
// ...
|
|
}
|
|
}
|
|
|
|
void update(std::uint64_t dt, entt::registry ®istry) {
|
|
registry.view<position, velocity>().each([dt](auto &pos, auto &vel) {
|
|
// gets all the components of the view at once ...
|
|
|
|
pos.x += vel.dx * dt;
|
|
pos.y += vel.dy * dt;
|
|
|
|
// ...
|
|
});
|
|
}
|
|
|
|
int main() {
|
|
entt::registry registry;
|
|
std::uint64_t dt = 16;
|
|
|
|
for (auto i = 0; i < 10; ++i) {
|
|
auto entity = registry.create();
|
|
registry.assign<position>(entity, i * 1.f, i * 1.f);
|
|
if (i % 2 == 0) {
|
|
registry.assign<velocity>(entity, i * .1f, i * .1f);
|
|
}
|
|
}
|
|
|
|
update(dt, registry);
|
|
update(registry);
|
|
|
|
// ...
|
|
}
|