Example #1
0
        protected unsafe void AccumulateDelta(void *oldStatePtr, void *newStatePtr, InputControl <float> control)
        {
            ////FIXME: if there's processors on the delta, this is junk
            var oldDelta = control.ReadValueFromState(oldStatePtr);
            var newDelta = control.ReadValueFromState(newStatePtr);

            control.WriteValueIntoState(oldDelta + newDelta, newStatePtr);
        }
Example #2
0
        protected unsafe bool ResetDelta(void *statePtr, InputControl <float> control)
        {
            ////FIXME: this should compare to default *state* (not value) and write default *state* (not value)
            var value = control.ReadValueFromState(statePtr);

            if (Mathf.Approximately(0f, value))
            {
                return(false);
            }
            control.WriteValueIntoState(0f, statePtr);
            return(true);
        }
        /// <summary>
        /// Read the value of the given control from an event.
        /// </summary>
        /// <param name="control"></param>
        /// <param name="inputEvent">Input event. This must be a <see cref="StateEvent"/> or <seealso cref="DeltaStateEvent"/>.
        /// Note that in the case of a <see cref="DeltaStateEvent"/>, the control may not actually be part of the event. In this
        /// case, the method returns false and stores <c>default(TValue)</c> in <paramref name="value"/>.</param>
        /// <param name="value">Variable that receives the control value.</param>
        /// <typeparam name="TValue"></typeparam>
        /// <returns>True if the value has been successfully read from the event, false otherwise.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="control"/> is null.</exception>
        /// <seealso cref="ReadUnprocessedValueFromEvent{TValue}(InputControl{TValue},InputEventPtr)"/>
        public static unsafe bool ReadValueFromEvent <TValue>(this InputControl <TValue> control, InputEventPtr inputEvent, out TValue value)
            where TValue : struct
        {
            if (control == null)
            {
                throw new ArgumentNullException(nameof(control));
            }

            var statePtr = control.GetStatePtrFromStateEvent(inputEvent);

            if (statePtr == null)
            {
                value = control.ReadDefaultValue();
                return(false);
            }

            value = control.ReadValueFromState(statePtr);
            return(true);
        }