#include #include // This example shows how to use singleton components in queries. // Singleton component struct Gravity { double value; }; // Entity component struct Velocity { double x; double y; }; int main(int, char *[]) { flecs::world world; // Set singleton world.set({ 9.81 }); // Set Velocity world.entity("e1").set({0, 0}); world.entity("e2").set({0, 1}); world.entity("e3").set({0, 2}); // Create query that matches Gravity as singleton flecs::query q = world.query_builder() .term_at(2).singleton() .build(); // In a query string expression you can use the $ shortcut for singletons: // Velocity, Gravity($) q.each([](flecs::entity e, Velocity& v, const Gravity& g) { v.y += g.value; std::cout << e.path() << " velocity is {" << v.x << ", " << v.y << "}" << std::endl; }); // Output // ::e1 velocity is {0, 9.81} // ::e2 velocity is {0, 10.81} // ::e3 velocity is {0, 11.81} }