Skip to content

Control

Jirka Dell'Oro-Friedl edited this page Jan 11, 2022 · 8 revisions

Control

The class Control in FUDGE supports the implementation of user-interactions. An instance of the class processes input signals of type number and generates an output signal of the same type. Proportional, integral or differential mapping, an amplification factor and a linear damping / delay are used to process the input signal.

Control structure

Control types

The following diagrams display the effects of amplification and delay for the different control types. The input in this example switches only between the three values -1, 0 and 1, though any value is possible.

Input

Proportional

The output simply follows the scaled and delayed input.
Output of the controller of the example. Red without changes, blue with the scaling of 2 and green with a delay of 1 sec (1000ms). Proporional

Integral

The output value changes over time with a rate given by the scaled and delayed input.
Output of the controller of the example. Red without changes, blue with a scale of 0.25 and green with a delay of 1 sec (1000ms). Integral

Differential

The output value reacts to changes of the scaled input and drops to 0 with given delay, if input remains constant.
Output of the controller of the example. Red without changes, blue with the scaling of 2 and green with a delay of 1 sec (1000ms). Differential

Polling vs Events

You may feed input to the controls either in constant intervals e.g. the game loop or when receiving input events from the users interaction. Similarly, you may poll the output of the controls in intervals, which may be the most common use case, or use the event system to call the appropriate functions in your code. Every time an input is set on a control, it dispatches an INPUT and an OUTPUT event with the appropriate values. Additionally, it dispatches output events at a given rate, the default of which is 0.

Axis

Handles multiple controls as inputs and creates an output from that.
Axis calculates the output summing up the inputs and processing the result using its own settings.

Axis structure

Axis can be used to use various input devices to control the same dimension of interaction. Steering a car to the left in a game means turning the virtual steering wheel. This can be controlled by keyboard, mouse, joystick or a wheel controller. Instead of writing code for all this input devices to be used, you may want to create an axis for the virtual steering wheel which uses multiple controls fed by the different input devices.

Keyboard controls

The keyboard class collects the keys pressed on the keyboard and saves their status.
It can be used to assign a value for active and inactive to the status of the buttons.
This value can serve as an input for the control class.

Clone this wiki locally