Skip to content

Implement component inheritance as a storage feature#2113

Open
SanderMertens wants to merge 21 commits into
masterfrom
component_inheritance_storage
Open

Implement component inheritance as a storage feature#2113
SanderMertens wants to merge 21 commits into
masterfrom
component_inheritance_storage

Conversation

@SanderMertens

@SanderMertens SanderMertens commented May 27, 2026

Copy link
Copy Markdown
Owner

This PR makes component inheritance work for most flecs APIs, in addition to queries (which already works):

world.component<Base>();
world.component<Foo>().is_a<Base>();
world.component<Bar>().is_a<Base>();

flecs::entity e = world.entity("e")
  .add<Foo>()
  .add<Bar>();

e.has<Base>(); // true
Base& b = e.get<Base>(); // returns first matching

This PR implements the following changes:

  • sink component inheritance into the storage, so it becomes available for all APIs
  • get, has, owns, each now work with inheritance
  • queries for inherited components are now cacheable
  • queries for inherited components now use the correct stride when matching a derived type
  • inheritance support is added to reflection, so types can inherit from each other

@SanderMertens SanderMertens force-pushed the component_inheritance_storage branch 14 times, most recently from 6230716 to 9dd433c Compare May 28, 2026 06:30
Comment thread src/query/engine/engine.h Outdated
Comment thread include/flecs/addons/cpp/delegate.hpp
Comment thread src/query/engine/eval.c Outdated
Comment thread src/storage/table.c Outdated
Comment thread src/iter.c
Comment thread src/observable.c Outdated
Comment thread test/core/src/ComponentInheritance.c
@SanderMertens SanderMertens force-pushed the component_inheritance_storage branch 2 times, most recently from b4e55ec to 9a70cff Compare May 29, 2026 01:23
@SanderMertens SanderMertens force-pushed the master branch 2 times, most recently from 3ca6d73 to e3f4d11 Compare May 29, 2026 16:32
@SanderMertens SanderMertens force-pushed the component_inheritance_storage branch from 0e37ca0 to 2edca0d Compare May 29, 2026 20:35
@SanderMertens SanderMertens force-pushed the component_inheritance_storage branch 2 times, most recently from 3c16945 to 2958db0 Compare June 12, 2026 00:03
float value;
};

struct HealthBuf : Buf { };

@SanderMertens SanderMertens Jun 12, 2026

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create types that add members on top of the base type (same for C example).

Comment thread src/query/engine/eval.c
if (!redo || (op_ctx->remaining <= 0)) {
repeat: {
bool next_table = !redo;
if (redo) {

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code should not be necessary since flecs_query_next_column uses ecs_search, which supports inheritance.

Comment thread src/bootstrap.c
return;
}

static

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A global observer on IsA pairs is expensive. Move this to component record creation.

@SanderMertens SanderMertens force-pushed the component_inheritance_storage branch from 1860547 to b118d50 Compare June 12, 2026 17:51
@SanderMertens SanderMertens moved this to In progress in Flecs 4.2 Jun 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In progress

Development

Successfully merging this pull request may close these issues.

1 participant