NateTheGreatt / bitECS

Flexible, minimal, data-oriented ECS library for Typescript
Mozilla Public License 2.0
942 stars 84 forks source link

Handling player inputs (e.g. boolean tuples) #159

Closed reececomo closed 3 months ago

reececomo commented 4 months ago

Echoes https://github.com/NateTheGreatt/bitECS/issues/101 (boolean type)

What is the current happy path for a player input component, where the input is a mixture of keypresses and/or analog inputs?

e.g. in something like this:

const SCALAR = Types.f64;
const BOOLEAN = Types.ui8; // gross

const PlayerInput = defineComponent({
  moveX: SCALAR,
  jump: BOOLEAN,
  interact: BOOLEAN,
});
reececomo commented 4 months ago

For production use-cases it would be great to optionally allow all datatypes (booleans, strings, custom structs). With the current architecture we could do some funky type inference to get there for objects.

Here's an example System from Blizzard's Overwatch (source):

Screenshot 2024-07-24 at 5 47 33 PM
reececomo commented 4 months ago

Or heck, even just an any type which uses standard arrays. That way we can easily extend the library for strings and other things as needed (trading some performance on access or serialization). https://github.com/NateTheGreatt/bitECS/issues/47