Skip to content

Implement exclusive relationships #212

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

lolmanurfunny
Copy link
Contributor

This PR implements exclusive relationships following flecs' implementation.

For some unknown reason the "#repro2" test now fails. Removing the world:set(entity, pair(4, 5), 6) call at line 145 fixes it.

@Ukendio
Copy link
Owner

Ukendio commented Apr 4, 2025

This could be more optimal if you just pass the entity into where the archetype graph is involved and invoke an on_remove hook when necessary.

@lolmanurfunny
Copy link
Contributor Author

lolmanurfunny commented Apr 4, 2025

Good idea.

Copy link
Owner

@Ukendio Ukendio left a comment

Choose a reason for hiding this comment

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

You have to resolve the merge conflicts

on_remove(entity)
end
end

-- If there was a previous archetype, then the entity needs to move the archetype
entity_move(entity_index, entity, record, to)
Copy link
Owner

Choose a reason for hiding this comment

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

It has to be record.archetype since on_remove can change the archetype it is destined for.

@@ -945,6 +975,13 @@ local function world_set(world: ecs_world_t, entity: i53, id: i53, data: unknown
end

if from then
if ECS_IS_PAIR(id) and bit32.band(idr.flags, ECS_ID_EXCLUSIVE) ~= 0 then
Copy link
Owner

Choose a reason for hiding this comment

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

it is probably cheap enough to just check the flags, you can benchmark and confirm.

But if you want to check if it is a pair first, you should only look up the id_record if the id is a pair.

on_remove(entity)
end
end

entity_move(entity_index, entity, record, to)
Copy link
Owner

Choose a reason for hiding this comment

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

has to be record.archetype not to because on_remove can cause the entity to move

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants