NateTheGreatt / bitECS

Functional, minimal, data-oriented, ultra-high performance ECS library written in JavaScript
Mozilla Public License 2.0
899 stars 81 forks source link

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

Closed reececomo closed 1 month ago

reececomo commented 1 month 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 1 month 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 1 month 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