Skip to content
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

Struct Components using Ref<T> #36

Closed
wants to merge 1 commit into from
Closed

Struct Components using Ref<T> #36

wants to merge 1 commit into from

Conversation

Byteron
Copy link
Owner

@Byteron Byteron commented Nov 1, 2022

This PR changes components to be structs again.
I found a way to keep the foreach(var (a, b, c) in query) syntax even when using structs.
though, now, instead of directly being of the respective types, a, b and c would be of the types Ref<A>, Ref<B> and Ref<C> respectively.
That means .Value is required to access the actual component struct.

var query = world.Query<Position, Velocity>().Build();
foreach(var (pos, vel) in query)
{
    pos.Value.X += vel.Value.X;
    pos.Value.Y += vel.Value.Y;
}

It's not ideal, but a fair trade between ergonomics and performance. Using structs nets us significant performance improvements down the line, due to better cache line optimisations.

@Byteron Byteron changed the title ref struct components Struct Components using Ref<T> Nov 1, 2022
@Byteron
Copy link
Owner Author

Byteron commented Nov 4, 2022

THis is not going to be merged here, instead I will release a separate ECS library that focuses on high performance

@Byteron Byteron closed this Nov 4, 2022
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.

1 participant