miniplex icon indicating copy to clipboard operation
miniplex copied to clipboard

RFC: returning/passing numerical IDs instead of entities

Open hmans opened this issue 2 years ago • 1 comments

We've been having this focus on using objects and object identities everywhere, but let's try what it feels like when createEntity returns the entity's numerical ID, and addComponent, removeComponent and destroyEntity all expect numerical IDs (or maybe either a numerical ID or an entity?)

Potential benefits:

  • It might be easier to integrate a miniplex world with non-miniplex systems. A numerical ID would allow you to use this ID in array-based systems (or standalone TypedArrays, etc.).
  • It would probably cut down on a lot of the sanity checks we're currently doing. At the moment, when an entity is passed in, it could theoretically be "any" object, so we need to check a) if it's already been registered as an entity, b) if it's registered with this world, etc.

Potential complications:

  • It might make the entire library a little harder to grok
  • Are IDs "random", or do they represent the position of the entity within the world's entity array? If it's the latter, how will this be affected by entities being removed? Would we need to handle this differently (eg. by, instead of removing an element from the array, just nulling it?)

Checklist:

  • [ ] Refactor World to use numerical IDs
  • [ ] Remove RegisteredEntity type? We probably no longer need it
  • [ ] Adjust/improve tests
  • [ ] Change miniplex-react accordingly

hmans avatar Apr 29 '22 08:04 hmans

https://github.com/hmans/miniplex/pull/50 might factor into this.

hmans avatar Apr 29 '22 10:04 hmans