Mercurial > projects > mde
annotate mde/input/input.d @ 9:1885a9080f2a
Joystick button input now works with config.
committer: Diggory Hardy <diggory.hardy@gmail.com>
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Wed, 30 Jan 2008 11:33:56 +0000 |
parents | f63f4f41a2dc |
children | 4c3575400769 |
rev | line source |
---|---|
4
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
1 /** |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
2 * This module contains the interface to the input system; it should be the only module of the |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
3 * input package imported from outside this package. |
0 | 4 */ |
5 module mde.input.input; | |
2
78eb491bd642
mergetag: partially redesigned dataset and text reader classes. Changed text format.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
0
diff
changeset
|
6 |
78eb491bd642
mergetag: partially redesigned dataset and text reader classes. Changed text format.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
0
diff
changeset
|
7 // package imports |
0 | 8 import mde.input.config; |
8
f63f4f41a2dc
Big changes to init; got some way towards input event support; changed mergetag ID to char[] from uint.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
7
diff
changeset
|
9 public import mde.input.exception; |
0 | 10 |
2
78eb491bd642
mergetag: partially redesigned dataset and text reader classes. Changed text format.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
0
diff
changeset
|
11 // sdl imports |
78eb491bd642
mergetag: partially redesigned dataset and text reader classes. Changed text format.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
0
diff
changeset
|
12 import derelict.sdl.events; |
78eb491bd642
mergetag: partially redesigned dataset and text reader classes. Changed text format.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
0
diff
changeset
|
13 |
8
f63f4f41a2dc
Big changes to init; got some way towards input event support; changed mergetag ID to char[] from uint.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
7
diff
changeset
|
14 import tango.util.log.Log : Log, Logger; |
f63f4f41a2dc
Big changes to init; got some way towards input event support; changed mergetag ID to char[] from uint.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
7
diff
changeset
|
15 |
9
1885a9080f2a
Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
16 public Input input; /// Global instance of input. |
8
f63f4f41a2dc
Big changes to init; got some way towards input event support; changed mergetag ID to char[] from uint.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
7
diff
changeset
|
17 static this() { |
9
1885a9080f2a
Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
18 input = new Input(); |
8
f63f4f41a2dc
Big changes to init; got some way towards input event support; changed mergetag ID to char[] from uint.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
7
diff
changeset
|
19 } |
f63f4f41a2dc
Big changes to init; got some way towards input event support; changed mergetag ID to char[] from uint.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
7
diff
changeset
|
20 |
f63f4f41a2dc
Big changes to init; got some way towards input event support; changed mergetag ID to char[] from uint.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
7
diff
changeset
|
21 /// Class encapsulating all input functionality. |
4
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
22 class Input |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
23 { |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
24 /// Typedef for all indexes (type is uint). |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
25 typedef uint inputID; |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
26 alias void delegate(inputID, bool) ButtonCallback; |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
27 alias void delegate(inputID, real) AxisCallback; |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
28 alias void delegate(inputID, real,real) MouseCallback; |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
29 |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
30 /** Get key status at this ID. |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
31 * |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
32 * Returns: value (true = down, false = up) or false if no value at this ID. */ |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
33 bool getButton (inputID id) { |
9
1885a9080f2a
Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
34 assert (this is input); |
1885a9080f2a
Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
35 bool* retp = id in button; |
4
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
36 if (retp) return *retp; |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
37 else return false; |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
38 } |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
39 /** Get axis status at this ID. |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
40 * |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
41 * Returns: value (range -1.0 .. 1.0) or 0.0 if no value at this ID. */ |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
42 real getAxis (inputID id) { |
9
1885a9080f2a
Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
43 real* retp = id in axis; |
4
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
44 if (retp) return *retp; |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
45 else return 0.0; |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
46 } |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
47 /** Get mouse pointer position in screen coordinates. |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
48 * |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
49 * Window managers only support one mouse, so there will only be one screen coordinate. |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
50 * Unlike everything else, this is not configurable. |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
51 */ |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
52 void mouseScreenPos (out uint x, out uint y) { |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
53 x = mouse_x; y = mouse_y; |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
54 } |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
55 /** Get relative mouse position (also for joystick balls). |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
56 * |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
57 * Future: Converts to a real via sensitivity settings (defaults may be set and overriden per item). |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
58 * |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
59 * To avoid confusion over the ID here, the idea is for the input-layer upward to support |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
60 * multiple mice, in case future platforms do. |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
61 * Also joystick balls (supported by SDL) can be used in the same way as a mouse for relative |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
62 * positions. |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
63 */ |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
64 void mouseRelativePos (inputID id, out real x = 0.0, out real y = 0.0) { |
9
1885a9080f2a
Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
65 RelPair* rp = id in axis_rel; |
4
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
66 if (rp) { |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
67 x = rp.x; y = rp.y; |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
68 } |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
69 } |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
70 // /// Is this modifier on? |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
71 //bool modifierStatus (inputID id); |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
72 |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
73 /** Adds a callback delegate for key events (both DOWN and UP) with this ID. |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
74 * |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
75 * Delegate receives event status. |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
76 */ |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
77 void addButtonCallback (inputID id, ButtonCallback dg) { |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
78 buttonCallbacks[id] = dg; |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
79 } |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
80 |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
81 /** Adds a callback delegate for axis events with this ID. |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
82 * |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
83 * Delegate receives event status. |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
84 */ |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
85 void addAxisCallback (inputID id, AxisCallback dg) { |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
86 axisCallbacks[id] = dg; |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
87 } |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
88 |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
89 /** Adds a callback delegate for mouse motion/joystick ball events with this ID. |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
90 * |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
91 * Delegate receives event status. (A separate callback for mouse pointer position changes is not |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
92 * necessary since this will be triggered by the same event - use mouseScreenPos from within the |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
93 * function to get new screen coordinates.) |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
94 */ |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
95 void addMouseCallback (inputID id, MouseCallback dg) { |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
96 mouseCallbacks[id] = dg; |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
97 } |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
98 |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
99 /** Feed an SDL_Event struct (only uses if it's a key, mouse or joystick event). |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
100 * |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
101 * Other types of event functions may be added. Returns true if the event was used, false if not. |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
102 */ |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
103 bool opCall (ref SDL_Event event) { |
9
1885a9080f2a
Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
104 assert (this is input); |
4
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
105 switch (event.type) { |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
106 case SDL_JOYBUTTONDOWN: |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
107 case SDL_JOYBUTTONUP: |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
108 outQueue* p = (Config.B.JOYBUTTON | (event.jbutton.which << 12) | event.jbutton.button) in config.button; |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
109 if (p) bEventOut (event.jbutton.state == 0x1, readOutQueue(*p)); |
8
f63f4f41a2dc
Big changes to init; got some way towards input event support; changed mergetag ID to char[] from uint.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
7
diff
changeset
|
110 break; |
9
1885a9080f2a
Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
111 |
4
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
112 /+ |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
113 case SDL_KEYDOWN: |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
114 case SDL_KEYUP: |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
115 outQueue* p = (Config.B.SDLKEY | event.key.keysym.sym) in config.button; |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
116 if (p) eventstream.bEventOut (event.key.state == SDL_PRESSED, readOutQueue(*p)); |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
117 break; |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
118 case SDL_MOUSEMOTION: |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
119 mouse_x = event.motion.x; |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
120 mouse_y = event.motion.y; |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
121 outQueue* p = (Config.M.WMMOUSE) in config.mouse; |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
122 if (p) eventstream.mEventOut (event.motion.xrel, event.motion.yrel, readOutQueue(*p)); |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
123 +/ |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
124 default: |
8
f63f4f41a2dc
Big changes to init; got some way towards input event support; changed mergetag ID to char[] from uint.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
7
diff
changeset
|
125 return false; |
4
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
126 } |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
127 return true; |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
128 } |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
129 |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
130 /** Resets relative movement of mice / joystick balls to zero. |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
131 * |
8
f63f4f41a2dc
Big changes to init; got some way towards input event support; changed mergetag ID to char[] from uint.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
7
diff
changeset
|
132 * Should be called once-per-frame if these are used, but must be called after their state has |
f63f4f41a2dc
Big changes to init; got some way towards input event support; changed mergetag ID to char[] from uint.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
7
diff
changeset
|
133 * been read (e.g. just before updating the input). |
4
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
134 */ |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
135 void frameReset () { |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
136 foreach (rp; axis_rel) { |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
137 rp.x = rp.y = 0.0; |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
138 } |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
139 } |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
140 |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
141 /** Loads all configs, activating the requested id. |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
142 * |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
143 * Returns: true if the requested config id wasn't found. |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
144 */ |
8
f63f4f41a2dc
Big changes to init; got some way towards input event support; changed mergetag ID to char[] from uint.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
7
diff
changeset
|
145 bool loadConfig () { |
4
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
146 Config.load("conf/input.mtt"); // FIXME: filename |
8
f63f4f41a2dc
Big changes to init; got some way towards input event support; changed mergetag ID to char[] from uint.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
7
diff
changeset
|
147 Config* c_p = "Default" in Config.configs; |
4
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
148 if (c_p) { |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
149 config = *c_p; |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
150 return false; |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
151 } |
8
f63f4f41a2dc
Big changes to init; got some way towards input event support; changed mergetag ID to char[] from uint.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
7
diff
changeset
|
152 debug logger.warn ("Config \"Default\" not found."); |
4
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
153 return true; |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
154 } |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
155 |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
156 private: |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
157 // Static constructor for event stream (fills es_*_fcts tables). |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
158 static this () { |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
159 es_b_fcts = [ ES_B_OUT : &es_b_out ]; |
9
1885a9080f2a
Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
160 |
1885a9080f2a
Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
161 logger = Log.getLogger ("mde.input.input.Input"); |
4
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
162 } |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
163 |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
164 struct RelPair { // for mouse/joystick ball motion |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
165 real x, y; |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
166 static RelPair opCall (real a, real b) { |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
167 RelPair ret; |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
168 ret.x = a; ret.y = b; |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
169 return ret; |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
170 } |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
171 } |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
172 |
9
1885a9080f2a
Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
173 static Logger logger; |
1885a9080f2a
Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
174 |
4
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
175 Config config; // Configuration |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
176 |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
177 bool[inputID] button; // Table of button states |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
178 real[inputID] axis; // Table of axes states |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
179 ushort mouse_x, mouse_y; // Current screen coords of the mouse |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
180 // FIXME: might need a bit of work... at any rate defining a default ID. |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
181 RelPair[inputID] axis_rel; // Table of relative mouse / joystick ball motions |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
182 |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
183 // FIXME: these need to be more like multimaps, supporting multiple dgs (also some means of removal?) |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
184 ButtonCallback[inputID] buttonCallbacks; |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
185 AxisCallback[inputID] axisCallbacks; |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
186 MouseCallback[inputID] mouseCallbacks; |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
187 |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
188 //BEGIN Event stream functionality |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
189 /* This section contains functions called on an event, which may modify the event (adjuster |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
190 * functions), and finally output to one (or more) of the state tables (the event stream). |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
191 * |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
192 * Adjuster and other event functions should have a format to fit the ES_X_Func types, for X is B |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
193 * (button event), A (axis event) or M (mouse relative motion event or joystick ball event). |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
194 * Adjusters should call one of the xEventOut() functions with their output and the remainder of |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
195 * the readOutQueue. |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
196 * |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
197 * To control which adjusters get called and pass parameters, a stack of sorts is used: outQueue. |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
198 */ |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
199 //BEGIN ES Definitions |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
200 /* Note: We really want an array, not a stack. We cannot edit the lists, so we can either |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
201 * copy to a stack or just iterate through it as an array. |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
202 */ |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
203 alias Config.outQueue outQueue; |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
204 struct readOutQueue { // A convenient structure for reading an outQueue item by item. |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
205 private Config.outQueue _q; // the queue, stored by reference to the original |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
206 private uint p = 0; // current read position (start at beginning) |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
207 |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
208 static readOutQueue opCall (Config.outQueue q) { // Static constructor |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
209 readOutQueue ret; |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
210 ret._q = q; |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
211 return ret; |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
212 } |
9
1885a9080f2a
Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
213 uint pop () { // Get the next element and advance. Throws an exception if there isn't another. |
4
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
214 if (p >= _q.length) |
7
b544c3a7c9ca
Some changes to exceptions and a few more debug commands.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
4
diff
changeset
|
215 throw new InputClassException ("Input: Invalid configuration: incomplete config stack"); |
4
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
216 uint ret = _q[p]; |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
217 ++p; |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
218 return ret; |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
219 } |
9
1885a9080f2a
Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
220 debug uint next () { // Get the next element. No checks; for debug use only. |
1885a9080f2a
Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
221 return _q[p]; |
1885a9080f2a
Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
222 } |
4
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
223 } |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
224 |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
225 // These aliases are for pointers to the event functions. |
9
1885a9080f2a
Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
226 // These need to use "this", but cannot be delegates because they musn't be bound to a |
1885a9080f2a
Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
227 // particular instance of Input, hence this must be passed when called. |
1885a9080f2a
Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
228 alias void function (Input, bool, readOutQueue) ES_B_Func; |
1885a9080f2a
Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
229 alias void function (Input, short, readOutQueue) ES_A_Func; |
1885a9080f2a
Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
230 alias void function (Input, short, short, readOutQueue) ES_M_Func; |
4
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
231 |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
232 // These are the codes allowing the config to specify event functions: |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
233 enum : uint { |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
234 ES_B_OUT = 0x0000_0100u, |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
235 ES_A_OUT = 0x0000_0200u, |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
236 ES_M_OUT = 0x0000_0300u, |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
237 } |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
238 //END ES Definitions |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
239 |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
240 // ES Data: |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
241 // These are the tables for looking up which event function to call. |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
242 static ES_B_Func[uint] es_b_fcts; |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
243 static ES_A_Func[uint] es_a_fcts; |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
244 static ES_M_Func[uint] es_m_fcts; |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
245 |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
246 //BEGIN ES Functions |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
247 // These 3 functions pass an event to the appropriate event function (adjuster or output func). |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
248 // They are used to start and continue an event stream. |
9
1885a9080f2a
Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
249 const EVCONF_ERR = "Input: Invalid configuration: bad event function code"; |
4
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
250 void bEventOut (bool b, readOutQueue s) |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
251 { |
9
1885a9080f2a
Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
252 ES_B_Func* func = (s.pop() in es_b_fcts); |
1885a9080f2a
Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
253 if (func != null) (*func)(this, b, s); |
1885a9080f2a
Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
254 else throw new InputClassException (EVCONF_ERR); |
4
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
255 } |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
256 void aEventOut (short x, readOutQueue s) |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
257 { |
9
1885a9080f2a
Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
258 ES_A_Func* func = (s.pop() in es_a_fcts); |
1885a9080f2a
Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
259 if (func != null) (*func)(this, x, s); |
1885a9080f2a
Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
260 else throw new InputClassException (EVCONF_ERR); |
4
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
261 } |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
262 void mEventOut (short x, short y, readOutQueue s) |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
263 { |
9
1885a9080f2a
Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
264 ES_M_Func* func = (s.pop() in es_m_fcts); |
1885a9080f2a
Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
265 if (func != null) (*func)(this, x, y, s); |
1885a9080f2a
Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
266 else throw new InputClassException (EVCONF_ERR); |
4
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
267 } |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
268 |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
269 // The remaining functions are the stream functions, for adjusting and outputting an event. |
9
1885a9080f2a
Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
270 // They need to work like non-static functions, but are called via a function pointer, hencne |
1885a9080f2a
Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
271 // should be static with their first parameter being instead of this. |
4
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
272 |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
273 // Simple output function |
9
1885a9080f2a
Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
274 static void es_b_out (Input myThis, bool b, readOutQueue s) { |
1885a9080f2a
Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
275 inputID id = cast(inputID) s.pop(); |
1885a9080f2a
Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
276 |
1885a9080f2a
Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
277 myThis.button[id] = b; |
1885a9080f2a
Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
278 |
1885a9080f2a
Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
279 ButtonCallback* cb_p = id in myThis.buttonCallbacks; |
4
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
280 if (cb_p) (*cb_p) (id, b); |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
281 } |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
282 // Adjuster to check modifier keys |
9
1885a9080f2a
Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
283 void es_b_modifier (Input myThis, bool b, readOutQueue s); |
4
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
284 |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
285 /* Simple output function |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
286 |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
287 Adds 1-2 items on the stack. |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
288 */ |
9
1885a9080f2a
Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
289 void es_a_out (Input myThis, short x, readOutQueue s) { |
4
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
290 real y = x; |
9
1885a9080f2a
Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
291 uint conf = s.pop(); |
4
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
292 enum : uint { |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
293 HALF_RANGE = 0x8000_0000u, |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
294 SENSITIVITY = 0x0080_0000u, |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
295 } |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
296 // Convert ranges into standard intervals (with or without reverse values) |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
297 if (conf & HALF_RANGE) y = (y + 32767.0) * 1.5259254737998596e-05; // range 0.0 - 1.0 |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
298 else y *= 3.0518509475997192e-05; // range -1.0 - 1.0 |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
299 real a; |
9
1885a9080f2a
Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
300 if (conf & SENSITIVITY) a = s.pop(); |
4
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
301 /+ When a global sensitivity is available (possibly only use if it's enabled)... |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
302 else a = axis.sensitivity; |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
303 y = sign(y) * pow(abs(y), a); // sensitivity adjustment by a +/ |
9
1885a9080f2a
Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
304 myThis.axis[cast(inputID) s.pop()] = y; |
4
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
305 } |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
306 |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
307 // Simple output function |
9
1885a9080f2a
Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
308 void es_m_out (Input myThis, short x, short y, readOutQueue s) { |
1885a9080f2a
Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
309 myThis.axis_rel[cast(inputID) s.pop()] = RelPair(x,y); |
4
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
310 } |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
311 //END ES Functions |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
2
diff
changeset
|
312 //END Event stream functionality |
0 | 313 } |