17template <
typename Comp>
19 static_assert(std::is_trivially_copyable_v<Comp>,
20 "EcsGpu component must be trivially copyable");
21 static_assert(
sizeof(Comp) %
sizeof(
float) == 0,
22 "EcsGpu component size must be a multiple of float");
23 return int(
sizeof(Comp) /
sizeof(
float));
27template <
typename Base,
typename Comp>
30 auto view = ecs::View<Base, Comp>();
31 for (
auto it =
view.begin(); it !=
view.end(); ++it)
40template <
typename Base,
typename Comp>
42 const int floatsPer = componentFloatCount<Comp>();
45 auto view = ecs::View<Base, Comp>();
46 for (
auto it =
view.begin(); it !=
view.end(); ++it)
51 std::vector<float> tmp(
size_t(
n) *
size_t(floatsPer));
53 auto view = ecs::View<Base, Comp>();
54 for (
auto it =
view.begin(); it !=
view.end(); ++it) {
56 std::memcpy(tmp.data() +
size_t(i) *
size_t(floatsPer),
static_cast<const void *
>(comp),
60 sys.
upload(binding, tmp.data(),
n * floatsPer);
68template <
typename Base,
typename Comp>
70 if (count <= 0)
return;
71 const int floatsPer = componentFloatCount<Comp>();
72 std::vector<float> tmp = sys.
download(binding, count * floatsPer);
74 auto view = ecs::View<Base, Comp>();
75 for (
auto it =
view.begin(); it !=
view.end() && i < count; ++it) {
77 std::memcpy(
static_cast<void *
>(comp), tmp.data() +
size_t(i) *
size_t(floatsPer),
88template <
typename Base,
typename Comp>
90 const int n = packViewComponent<Base, Comp>(sys, binding);
93 unpackViewComponent<Base, Comp>(sys, binding,
n);
void upload(int binding, const float *data, int floatCount)
void dispatch(int entityCount, float dt=0.f)
void download(int binding, float *out, int floatCount) const
int countViewEntities()
Count live entities matching View<Base, Comp>.
int packViewComponent(ShaderSystem &sys, int binding)
Pack View<Base, Comp> into ShaderSystem binding as AoS floats. Returns entity count (0 if empty).
void unpackViewComponent(ShaderSystem &sys, int binding, int count)
Write ShaderSystem binding floats back into View<Base, Comp> (same order as pack)....
constexpr int componentFloatCount()
int runViewComponentSystem(ShaderSystem &sys, int binding, float dt)
Pack + dispatch + unpack a single-component GPU system. Additional bindings must be uploaded by the c...