view mde/input/eventstream.d @ 0:d547009c104c

Repository creation. committer: Diggory Hardy <diggory.hardy@gmail.com>
author Diggory Hardy <diggory.hardy@gmail.com>
date Sat, 27 Oct 2007 18:05:39 +0100
parents
children 78eb491bd642
line wrap: on
line source

/** This module contains functions called on an event, which may modify the event (adjuster
 *	functions), and finally output to one (or more) of the state tables (the event stream).
 *	
 *	Adjuster and other event functions should have a format to fit the ES_X_Func types, for X is B
 *	(button event), A (axis event) or M (mouse relative motion event or joystick ball event).
 *	Adjusters should call (an) output function(s) of any type with their output(s).
 *
 *	To control which adjusters get called and pass parameters, a stack is used.
 */
module mde.input.eventstream;
import mde.input.core;
/+
/// Module constructor fills es_*_fcts tables and rehashes them.
static this () {
	es_b_fcts[ES_B_OUT] = &es_b_out;
	
	// Call rehash following initialisation:
	es_b_fcts.rehash;
	es_a_fcts.rehash;
	es_m_fcts.rehash;
}

/// These aliases are for pointers to the event functions.
alias void function (bool, out_stack) ES_B_Func;
alias void function (short, out_stack) ES_A_Func;			/// ditto
alias void function (short, short, out_stack) ES_M_Func;	/// ditto

/// These are the tables for looking up which event function to call.
static ES_B_Func[uint] es_b_fcts;
static ES_A_Func[uint] es_a_fcts;	/// ditto
static ES_M_Func[uint] es_m_fcts;	/// ditto

/// These are the codes allowing the config to specify event functions:
enum : uint {
    ES_B_OUT	= 0x0000_0100u,
    ES_A_OUT	= 0x0000_0200u,
    ES_M_OUT	= 0x0000_0300u,
}

/// Functions to pass an event to the appropriate event function
void bEventOut (bool b, out_stack s)
{
	ES_B_Func* func = (s.pop in es_b_fcts);
	if (func != null) (*func)(b,s);
	else throw new InputException ("Input: Invalid configuration: bad event function code");
}
void aEventOut (short x, out_stack s)	/// ditto
{
	ES_A_Func* func = (s.pop in es_a_fcts);
	if (func != null) (*func)(x,s);
	else throw new InputException ("Input: Invalid configuration: bad event function code");
}
void mEventOut (short x, short y, out_stack s)	/// ditto
{
	ES_M_Func* func = (s.pop in es_m_fcts);
	if (func != null) (*func)(x,y,s);
	else throw new InputException ("Input: Invalid configuration: bad event function code");
}

/// Simple output function
void es_b_out (bool b, out_stack s) {
	b_tbl[cast(index_t) s.pop] = b;
}
/// Adjuster to check modifier keys
void es_b_modifier (bool b, out_stack s);

/** Simple output function

Adds 1-2 items on the stack.
*/
void es_a_out (short x, out_stack s) {
	real y = x;
	uint conf = s.pop;
        enum : uint {
            HALF_RANGE	= 0x8000_0000u,
            SENSITIVITY	= 0x0080_0000u,
        }
        // Convert ranges into standard intervals (with or without reverse values)
	if (conf & HALF_RANGE) y = (y + 32767.0) * 1.5259254737998596e-05;	// range  0.0 - 1.0
	else y *= 3.0518509475997192e-05;					// range -1.0 - 1.0
	real a;
	if (conf & SENSITIVITY) a = s.pop;
        /+ When a global sensitivity is available (possibly only use if it's enabled)...
        else a = axis.sensitivity;
	y = sign(y) * pow(abs(y), a);		// sensitivity adjustment by a +/
	axis_tbl[cast(index_t) s.pop] = y;
}

/// Simple output function
void es_m_out (short x, short y, out_stack s) {
	axis_rel_tbl[cast(index_t) s.pop] = RelPair(x,y);
}
+/