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

Rename World.Mask #39

Closed
stasm opened this issue Jul 14, 2020 · 5 comments · Fixed by #40
Closed

Rename World.Mask #39

stasm opened this issue Jul 14, 2020 · 5 comments · Fixed by #40

Comments

@stasm
Copy link
Member

stasm commented Jul 14, 2020

This is a cosmetic change intended to establish a better vocabulary for describing ECS concepts. I think mask is very close and I don't want to change it if there isn't a significantly better name.

The problem that I see with mask is that the values of the World.Mask array are not used as masks. They're bitfields (or bitsets) but they're not used to mask other bitfields in Goodluck. Instead, systems define their masks (QUERY) to filter entities to run on. The semantic difference is marginal, but I'd like to spend some effort and try to find a better name which would better describe how these values are used.

@stasm
Copy link
Member Author

stasm commented Jul 14, 2020

I filed #32 and #38 to experiment with two alternatives: World.Get and World.Components. It's easier for me to evaluate a name if I can see it used in the code. I then realized I'd like to test many more naming ideas and that it wouldn't be practical to file PRs for all of them. So I created https://jsbin.com/jolowav/1/edit?output :)

Here are the ideas I'm considering, some much worse than Mask, but I'm including them for completeness:

  • Short: All, Get, Has, With, For, Of
  • Related to bits: Bits, Bitset, Bitfield, Flags, ComponentMask
  • Related to ECS: Entity, Entities, Components
  • Adjectives: Active, Enabled, Alive
  • Other: Query, Filter, Config, Pattern

@stasm
Copy link
Member Author

stasm commented Jul 14, 2020

I'm going to discard all short ideas. They don't describe how the values are used and even if they may look attractive to some (I liked Get myself), I recognize that they can also be confusing. Also, they fall into the category of "cute" API design, which is something I try to avoid. On a side note, it's really hard to notice and resist the cuteness sometimes, but I'm learning :)

The related to bits group tells us what the values are technically, but not what they represent. I think they share the same problems as the current Mask and none is strictly better.

The related to ECS group is interesting. I think Entity looks good in code, e.g. if (game.World.Entity[collision.Other] & Has.RigidBody), but the problem I see is that the values of the World.Entity array are not, well, entities. Entities are the indices into this array, while the values hold information about the component composition of an entity. This is also the reason why I quite like Components (I even filed #38 about it). However, Components has its own problems: it's the only proposal in plural which used as a name of an array suggests that the array holds the component classes or the component data. for (let i = 0; i < game.World.Components.length; i++) looks like it was iterating over the components rather than entities. In the similar spirit, game.World.Components[entity] might suggest that the value is the actual component data for the entity. On the upside, I do like the expressiveness of game.World.Components[collision.Other] & Has.RigidBody.

The adjectives group doesn't look too bad when written down, but I'd prefer a noun so that the name can be used easily when talking about the code. This critique also applies to all short names, as well as the related to ECS group.

Finally, in the other group, Query and Filter are probably off-topic. Config and Pattern are nice and I think they describe the values of the array well, but they sound too generic to me.

@stasm
Copy link
Member Author

stasm commented Jul 14, 2020

I'm going to leave this open for a few more days in case I have more ideas. So far, I don't think any of the alternatives is significantly better than Mask.

@stasm
Copy link
Member Author

stasm commented Jul 16, 2020

I was reading up on ECS design in languages with manual memory managment, and I came across an article by Austin Morlan in which he used the term signature to describe exactly what the values of World.Mask are:

Since an entity is simply an ID, we need a way to track which components an entity “has”, and we also need a way to track which components a system cares about. I chose the very simple approach of using a std::bitset (modern C++ equivalent of a bitfield), called a Signature. Each component type has a unique ID (starting from 0), which is used to represent a bit in the signature.

I really like this name. It gives us a single word to precisely describe a concept in Goodluck. Instead of saying a bit mask describing the component composition of an entity, we can say: the entity's signature.

@stasm
Copy link
Member Author

stasm commented Jul 18, 2020

I've just merged #40. World.Mask is now called World.Signature.

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 a pull request may close this issue.

1 participant