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

API Design: define entities by archetype directly #29

Closed
Avokadoen opened this issue Aug 3, 2022 · 3 comments
Closed

API Design: define entities by archetype directly #29

Avokadoen opened this issue Aug 3, 2022 · 3 comments
Labels
question Further information is requested

Comments

@Avokadoen
Copy link
Owner

Avokadoen commented Aug 3, 2022

Building on the features made in the comptime branch we can design the API to utilize compile time more and enabling these features to be merged in master. Merging comptime branch in master will resolve issue #27

The user will have to define archetypes i.e:

const Player = struct {
   // Note variable name is not important here
   hp: Health,
   pos: Position,
   vel:  Velocity,
};

const StaticObject = {
   Pos: Position,
};

These archetypes are then stored in a comptime hash map

The API will not allow dynamically adding or removing components from an entity, but changing the entity type will be valid in any direction (or maybe this should be restricted?)

This will like mentioned allow the library to move a lot more over to compile time and hopefully make planned queries mostly compile time based as well and add the functionality for type queries i.e give me all Players

It will also make entity construction very fast since the user will always specify the full component list at creation i.e

world.setEntityType(entity, Player{...});
@Avokadoen Avokadoen added enhancement question Further information is requested labels Aug 3, 2022
@Avokadoen
Copy link
Owner Author

Avokadoen commented Aug 8, 2022

each archetype should implement an interface
we can then have an array of these interfaces and then we can make some operations O(1) i.e hasComponent and getComponent etc...

The std.mem.Allocator is a good place to start for dynamic dispatch: https://github.com/ziglang/zig/blob/master/lib/std/mem/Allocator.zig

@Avokadoen
Copy link
Owner Author

The restriction of only allowing predefined archetypes can be removed by using the interface idea

Queries can be processed on compile time using comptime and itnerfaces can be used to do partial type erasure needed to combine different archetypes!

@Avokadoen
Copy link
Owner Author

Resolved by PR #30

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

No branches or pull requests

1 participant