Mercurial > projects > mde
annotate mde/input/eventstream.d @ 2:78eb491bd642
mergetag: partially redesigned dataset and text reader classes. Changed text format.
committer: Diggory Hardy <diggory.hardy@gmail.com>
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Sat, 03 Nov 2007 15:15:43 +0000 |
parents | d547009c104c |
children |
rev | line source |
---|---|
0 | 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; | |
2
78eb491bd642
mergetag: partially redesigned dataset and text reader classes. Changed text format.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
0
diff
changeset
|
11 |
78eb491bd642
mergetag: partially redesigned dataset and text reader classes. Changed text format.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
0
diff
changeset
|
12 // package imports |
0 | 13 import mde.input.core; |
2
78eb491bd642
mergetag: partially redesigned dataset and text reader classes. Changed text format.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
0
diff
changeset
|
14 |
0 | 15 /// Module constructor fills es_*_fcts tables and rehashes them. |
16 static this () { | |
17 es_b_fcts[ES_B_OUT] = &es_b_out; | |
18 | |
19 // Call rehash following initialisation: | |
20 es_b_fcts.rehash; | |
21 es_a_fcts.rehash; | |
22 es_m_fcts.rehash; | |
23 } | |
24 | |
25 /// These aliases are for pointers to the event functions. | |
2
78eb491bd642
mergetag: partially redesigned dataset and text reader classes. Changed text format.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
0
diff
changeset
|
26 alias void function (bool, readOutQueue) ES_B_Func; |
78eb491bd642
mergetag: partially redesigned dataset and text reader classes. Changed text format.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
0
diff
changeset
|
27 alias void function (short, readOutQueue) ES_A_Func; /// ditto |
78eb491bd642
mergetag: partially redesigned dataset and text reader classes. Changed text format.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
0
diff
changeset
|
28 alias void function (short, short, readOutQueue) ES_M_Func; /// ditto |
0 | 29 |
30 /// These are the tables for looking up which event function to call. | |
31 static ES_B_Func[uint] es_b_fcts; | |
32 static ES_A_Func[uint] es_a_fcts; /// ditto | |
33 static ES_M_Func[uint] es_m_fcts; /// ditto | |
34 | |
35 /// These are the codes allowing the config to specify event functions: | |
36 enum : uint { | |
37 ES_B_OUT = 0x0000_0100u, | |
38 ES_A_OUT = 0x0000_0200u, | |
39 ES_M_OUT = 0x0000_0300u, | |
40 } | |
41 | |
42 /// Functions to pass an event to the appropriate event function | |
2
78eb491bd642
mergetag: partially redesigned dataset and text reader classes. Changed text format.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
0
diff
changeset
|
43 void bEventOut (bool b, readOutQueue s) |
0 | 44 { |
2
78eb491bd642
mergetag: partially redesigned dataset and text reader classes. Changed text format.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
0
diff
changeset
|
45 ES_B_Func* func = (s.next() in es_b_fcts); |
0 | 46 if (func != null) (*func)(b,s); |
47 else throw new InputException ("Input: Invalid configuration: bad event function code"); | |
48 } | |
2
78eb491bd642
mergetag: partially redesigned dataset and text reader classes. Changed text format.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
0
diff
changeset
|
49 void aEventOut (short x, readOutQueue s) /// ditto |
0 | 50 { |
2
78eb491bd642
mergetag: partially redesigned dataset and text reader classes. Changed text format.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
0
diff
changeset
|
51 ES_A_Func* func = (s.next() in es_a_fcts); |
0 | 52 if (func != null) (*func)(x,s); |
53 else throw new InputException ("Input: Invalid configuration: bad event function code"); | |
54 } | |
2
78eb491bd642
mergetag: partially redesigned dataset and text reader classes. Changed text format.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
0
diff
changeset
|
55 void mEventOut (short x, short y, readOutQueue s) /// ditto |
0 | 56 { |
2
78eb491bd642
mergetag: partially redesigned dataset and text reader classes. Changed text format.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
0
diff
changeset
|
57 ES_M_Func* func = (s.next() in es_m_fcts); |
0 | 58 if (func != null) (*func)(x,y,s); |
59 else throw new InputException ("Input: Invalid configuration: bad event function code"); | |
60 } | |
61 | |
62 /// Simple output function | |
2
78eb491bd642
mergetag: partially redesigned dataset and text reader classes. Changed text format.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
0
diff
changeset
|
63 void es_b_out (bool b, readOutQueue s) { |
78eb491bd642
mergetag: partially redesigned dataset and text reader classes. Changed text format.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
0
diff
changeset
|
64 b_tbl[cast(index_t) s.next()] = b; |
0 | 65 } |
66 /// Adjuster to check modifier keys | |
2
78eb491bd642
mergetag: partially redesigned dataset and text reader classes. Changed text format.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
0
diff
changeset
|
67 void es_b_modifier (bool b, readOutQueue s); |
0 | 68 |
69 /** Simple output function | |
70 | |
71 Adds 1-2 items on the stack. | |
72 */ | |
2
78eb491bd642
mergetag: partially redesigned dataset and text reader classes. Changed text format.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
0
diff
changeset
|
73 void es_a_out (short x, readOutQueue s) { |
0 | 74 real y = x; |
2
78eb491bd642
mergetag: partially redesigned dataset and text reader classes. Changed text format.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
0
diff
changeset
|
75 uint conf = s.next(); |
0 | 76 enum : uint { |
77 HALF_RANGE = 0x8000_0000u, | |
78 SENSITIVITY = 0x0080_0000u, | |
79 } | |
80 // Convert ranges into standard intervals (with or without reverse values) | |
81 if (conf & HALF_RANGE) y = (y + 32767.0) * 1.5259254737998596e-05; // range 0.0 - 1.0 | |
82 else y *= 3.0518509475997192e-05; // range -1.0 - 1.0 | |
83 real a; | |
2
78eb491bd642
mergetag: partially redesigned dataset and text reader classes. Changed text format.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
0
diff
changeset
|
84 if (conf & SENSITIVITY) a = s.next(); |
0 | 85 /+ When a global sensitivity is available (possibly only use if it's enabled)... |
86 else a = axis.sensitivity; | |
87 y = sign(y) * pow(abs(y), a); // sensitivity adjustment by a +/ | |
2
78eb491bd642
mergetag: partially redesigned dataset and text reader classes. Changed text format.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
0
diff
changeset
|
88 axis_tbl[cast(index_t) s.next()] = y; |
0 | 89 } |
90 | |
91 /// Simple output function | |
2
78eb491bd642
mergetag: partially redesigned dataset and text reader classes. Changed text format.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
0
diff
changeset
|
92 void es_m_out (short x, short y, readOutQueue s) { |
78eb491bd642
mergetag: partially redesigned dataset and text reader classes. Changed text format.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
0
diff
changeset
|
93 axis_rel_tbl[cast(index_t) s.next()] = RelPair(x,y); |
0 | 94 } |