-
-
Notifications
You must be signed in to change notification settings - Fork 583
Description
Describe the bug
When trying to use order_by in a system builder, it fails with error order_by component '...' is not queried for
Component i've been trying to use is UIFrame, inherited from by 2 other components UIContainer and UIInventory. In systems with only UIFrame or with UIFrame and a singleton it seems to work, but when i add another component (Position) it starts printing error instead
To Reproduce
Made this quick example, it prints error for third system, but first 2 work fine
#include <iostream>
#include "flecs.h"
struct GraphicsState
{
char dummy; // Just so it isn't empty
};
struct UIFrame
{
int last_access_time;
};
struct UIContainer: public UIFrame {};
struct UIInventory: public UIFrame {};
struct Position { int x, y; };
int main()
{
flecs::world world;
world.component<GraphicsState>().add(flecs::Singleton);
world.ensure<GraphicsState>();
world.component<Position>();
world.component<UIFrame>();
world.component<UIContainer>().is_a<UIFrame>();
world.component<UIInventory>().is_a<UIFrame>();
std::cout<<"world.system<UIFrame>()"<<std::endl;
world.system<UIFrame>()
.order_by<UIFrame>([] (flecs::entity_t, const UIFrame *frame1, flecs::entity_t, const UIFrame *frame2)
{
return frame1->last_access_time - frame2->last_access_time;
})
.each([] (UIFrame&)
{
std::cout<<"Matched a UIFrame"<<std::endl;
});
// Works
std::cout<<"world.system<GraphicsState, UIFrame>()"<<std::endl;
world.system<GraphicsState, UIFrame>()
.order_by<UIFrame>([] (flecs::entity_t, const UIFrame *frame1, flecs::entity_t, const UIFrame *frame2)
{
return frame1->last_access_time - frame2->last_access_time;
})
.each([] (GraphicsState&, UIFrame&)
{
std::cout<<"Matched a UIFrame and a singleton"<<std::endl;
});
// Works
std::cout<<"world.system<UIFrame, Position>()"<<std::endl;
world.system<UIFrame, Position>()
.order_by<UIFrame>([] (flecs::entity_t, const UIFrame *frame1, flecs::entity_t, const UIFrame *frame2)
{
return frame1->last_access_time - frame2->last_access_time;
})
.each([] (UIFrame&, Position&)
{
std::cout<<"Matched UIFrame and Position"<<std::endl;
});
// error: flecs.c: 72263: order_by component 'UIFrame' is not queried for
world.entity().add<UIContainer>().add<Position>();
world.progress();
// First 2 systems work properly
}Expected behavior
Docs on order_by don't seem to say anything about inherited components specifically (not that i could find) so i'd expect third system to work as well
Additional context
Tried to put breakpoint in point when flecs prints error, and it seems at that point query has only 1 term
(gdb) print ecs_id_str(world, query->terms[0].id)
$1 = 0x5555558c3a80 "Position"
(gdb) print ecs_id_str(world, query->terms[1].id)
$2 = 0x5555558c3aa0 "#0"
(gdb) print query->term_count
$3 = 1 '\001'
I used flecs version from master branch, commit 9c53ba9
Also i think i can try work around this by moving last_access_time into separate component and use it for order_by (which would probably be better way of doing it anyway, but yeah i'd expect it to work as is too)