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

More generic overloads for world. and entity. methods #20

Closed
genaray opened this issue Nov 25, 2022 · 3 comments
Closed

More generic overloads for world. and entity. methods #20

genaray opened this issue Nov 25, 2022 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@genaray
Copy link
Owner

genaray commented Nov 25, 2022

Would be probably a cool addition to the existing API to allow some generic methods to have more generic overloads...

var entity = world.Create<Health,Transform>();
var entity = world.Create(in Health(), in Transform(), ...);

entity.Set(new Health(), new Transform(),...);
entity.Get<Health, Transform>(out var health, out var transform);
entity.Add<Stats,AI>();
entity.Remove<Stats,AI>();

// The same required for world. since entity. relies on them
world.Set(new Health(), new Transform(),...);
world.Get<Health, Transform>(out var health, out var transform);
world.Add<Stats,AI>();
world.Remove<Stats,AI>();

This would reduce boilerplate code and would also speed up some stuff :)
Probably #19 needed, since the generic overloads would likely need to target the fitting archetype ( atleast for creating, adding and removing ).

@genaray genaray added the enhancement New feature or request label Nov 25, 2022
@genaray genaray changed the title More generics for world.Create, entity.Set, èntity.Get, entity.Remove and entity.Add More generic overloads for world. and entity. methods Nov 25, 2022
@andreakarasho
Copy link
Contributor

If im fine with all of thse, i completely disagree with:

entity.Get<Health, Transform>(out var health, out var transform);
world.Get<Health, Transform>(out var health, out var transform);

These will create a copy of the components all the time, so you will need to call ref var k = ref entity.Get<K>() anyway.

Also, probably OT, maybe this needs a different issue:
operations like Add/Set can be merged together imho.

@genaray
Copy link
Owner Author

genaray commented Nov 25, 2022

If im fine with all of thse, i completely disagree with:

entity.Get<Health, Transform>(out var health, out var transform);
world.Get<Health, Transform>(out var health, out var transform);

These will create a copy of the components all the time, so you will need to call ref var k = ref entity.Get<K>() anyway.

Also, probably OT, maybe this needs a different issue: operations like Add/Set can be merged together imho.

Thanks for the feedback and i totally forgot the copy mechanic in that place :D

I just wonder if its possible to return multiple references... single entity operations are still slow since each operation needs to search the archetype for acessing its content, would be cool to be able to batch .Get operations for the same purpose ( of course you can do the same by just doing entity.GetArchetype() to acess the internals yourself but thats not every user friendly ).

public ref References<T,...N>{ ref T first, ref T second, ref T third... }
var referencesStruct = entity.Get<...>();

That could probably work and speed up things ^^

@genaray
Copy link
Owner Author

genaray commented Nov 27, 2022

Implemented in db51cb9.
There dozends of new generic overloads to ease the development and to batch calls to be more efficient.

Parts of this feature could also act as #21 .

var entity = world.Create(new Transform(), new Velocity(),...);
var has = entity.Has<Transform, Velocity>();
var refs = entity.Get<Transform, Velocity>(); // Returns a ref struct with ref fields in it. 
entity.Set(new Transform(), new Velocity());

entity.Add<PowerUp, AI>(new PowerUp(), new AI()); // Changes archetype;
entity.Add<Alive, AdditionalStrength, Flying>();
entity.Remove<Dead, Frozen>();

World, Archetype and Chunk also received the same methods and overloads. Add and Remove are also now more efficient since they can be batched.

@genaray genaray closed this as completed Nov 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

No branches or pull requests

2 participants