comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:d547009c104c
1 /** This module contains functions called on an event, which may modify the event (adjuster
2 * functions), and finally output to one (or more) of the state tables (the event stream).
3 *
4 * Adjuster and other event functions should have a format to fit the ES_X_Func types, for X is B
5 * (button event), A (axis event) or M (mouse relative motion event or joystick ball event).
6 * Adjusters should call (an) output function(s) of any type with their output(s).
7 *
8 * To control which adjusters get called and pass parameters, a stack is used.
9 */
10 module mde.input.eventstream;
11 import mde.input.core;
12 /+
13 /// Module constructor fills es_*_fcts tables and rehashes them.
14 static this () {
15 es_b_fcts[ES_B_OUT] = &es_b_out;
16
17 // Call rehash following initialisation:
18 es_b_fcts.rehash;
19 es_a_fcts.rehash;
20 es_m_fcts.rehash;
21 }
22
23 /// These aliases are for pointers to the event functions.
24 alias void function (bool, out_stack) ES_B_Func;
25 alias void function (short, out_stack) ES_A_Func; /// ditto
26 alias void function (short, short, out_stack) ES_M_Func; /// ditto
27
28 /// These are the tables for looking up which event function to call.
29 static ES_B_Func[uint] es_b_fcts;
30 static ES_A_Func[uint] es_a_fcts; /// ditto
31 static ES_M_Func[uint] es_m_fcts; /// ditto
32
33 /// These are the codes allowing the config to specify event functions:
34 enum : uint {
35 ES_B_OUT = 0x0000_0100u,
36 ES_A_OUT = 0x0000_0200u,
37 ES_M_OUT = 0x0000_0300u,
38 }
39
40 /// Functions to pass an event to the appropriate event function
41 void bEventOut (bool b, out_stack s)
42 {
43 ES_B_Func* func = (s.pop in es_b_fcts);
44 if (func != null) (*func)(b,s);
45 else throw new InputException ("Input: Invalid configuration: bad event function code");
46 }
47 void aEventOut (short x, out_stack s) /// ditto
48 {
49 ES_A_Func* func = (s.pop in es_a_fcts);
50 if (func != null) (*func)(x,s);
51 else throw new InputException ("Input: Invalid configuration: bad event function code");
52 }
53 void mEventOut (short x, short y, out_stack s) /// ditto
54 {
55 ES_M_Func* func = (s.pop in es_m_fcts);
56 if (func != null) (*func)(x,y,s);
57 else throw new InputException ("Input: Invalid configuration: bad event function code");
58 }
59
60 /// Simple output function
61 void es_b_out (bool b, out_stack s) {
62 b_tbl[cast(index_t) s.pop] = b;
63 }
64 /// Adjuster to check modifier keys
65 void es_b_modifier (bool b, out_stack s);
66
67 /** Simple output function
68
69 Adds 1-2 items on the stack.
70 */
71 void es_a_out (short x, out_stack s) {
72 real y = x;
73 uint conf = s.pop;
74 enum : uint {
75 HALF_RANGE = 0x8000_0000u,
76 SENSITIVITY = 0x0080_0000u,
77 }
78 // Convert ranges into standard intervals (with or without reverse values)
79 if (conf & HALF_RANGE) y = (y + 32767.0) * 1.5259254737998596e-05; // range 0.0 - 1.0
80 else y *= 3.0518509475997192e-05; // range -1.0 - 1.0
81 real a;
82 if (conf & SENSITIVITY) a = s.pop;
83 /+ When a global sensitivity is available (possibly only use if it's enabled)...
84 else a = axis.sensitivity;
85 y = sign(y) * pow(abs(y), a); // sensitivity adjustment by a +/
86 axis_tbl[cast(index_t) s.pop] = y;
87 }
88
89 /// Simple output function
90 void es_m_out (short x, short y, out_stack s) {
91 axis_rel_tbl[cast(index_t) s.pop] = RelPair(x,y);
92 }
93 +/