wiremod / wirebox

Wire for S&Box. Early WIP.
MIT License
37 stars 8 forks source link

RegisterInputHandler improvement #2

Closed thegrb93 closed 3 years ago

thegrb93 commented 3 years ago

Instead of generic public void RegisterInputHandler<T>( string inputName, Action<T> handler ) and typechecks, you could define them explicitly.

public void RegisterInputHandler( string inputName, Action<bool> handler ) public void RegisterInputHandler( string inputName, Action<int> handler ) public void RegisterInputHandler( string inputName, Action<float> handler )

thegrb93 commented 3 years ago

Though, I think it would be better to use float (or double) for everything so we're not wasting cycles on casts.

Nebual commented 3 years ago

Yeah true, explicit definitions are probably easier now. I've gone through a number of iterations on this, experimenting with C#'s limitations/features around interfaces/statics... I wonder if I should attempt to store a generic (T? object?) in WireOutput.value, or just list all the explicit types as valueInt, valueString, etc...

As for int vs float vs bool - I'm unsure if we want to expose the distinction to the user (maybe can blur them into "numeric" UI-side), but I figured having support for int-to-int might be faster (with less rounding weirdness) than floats.