0
|
1 /// This module contains the core (i.e. common part) of the input system.
|
|
2 module mde.input.core;
|
|
3 /+
|
|
4 alias Exception InputException; // this can be expanded to a custom class if needed
|
|
5 typedef uint index_t;
|
|
6 struct RelPair {
|
|
7 real x, y;
|
|
8 static RelPair opCall (real a, real b) {
|
|
9 RelPair ret;
|
|
10 ret.x = a; ret.y = b;
|
|
11 return ret;
|
|
12 }
|
|
13 }
|
|
14
|
|
15 /* Note: We really want an array, not a stack. We cannot edit these lists, so we can either
|
|
16 * copy the stack or just iterate through it as an array.
|
|
17 */
|
|
18 typedef uint[] outQueue; /// This is the type for the out queue config data.
|
|
19 struct readOutQueue { /// A convenient structure for reading an outQueue item by item.
|
|
20 private outQueue _q; // the queue, stored by reference to the original
|
|
21 private uint p = 0; // current read position (start at beginning)
|
|
22
|
|
23 static readOutQueue (outQueue q) { /// Static constructor
|
|
24 readOutQueue ret;
|
|
25 ret._q = q;
|
|
26 return ret;
|
|
27 }
|
|
28 uint next () { /// Get the next element. Throws an exception if there isn't another.
|
|
29 if (p >= _q.length())
|
|
30 throw new InputException ("Input: Invalid configuration: incomplete config stack");
|
|
31 uint ret = _q[p];
|
|
32 ++p;
|
|
33 return ret;
|
|
34 }
|
|
35 }
|
|
36 /+
|
|
37 struct out_stack { // a remove-only stack with exception throwing
|
|
38 uint[] _data;
|
|
39
|
|
40 static out_stack opCall (uint[] d) {
|
|
41 out_stack ret;
|
|
42 ret._data = d;
|
|
43 return ret;
|
|
44 }
|
|
45 uint pop () {
|
|
46 if (_data.length < 1)
|
|
47 throw new InputException ("Input: Invalid configuration: incomplete config stack");
|
|
48 uint a = _data[length - 1];
|
|
49 _data.length = _data.length - 1;
|
|
50 return a;
|
|
51 }
|
|
52 }
|
|
53 +/
|
|
54
|
|
55 bool[index_t] b_tbl; /// Table of button states
|
|
56 real[index_t] axis_tbl; /// Table of axes states
|
|
57 uint mouse_x, mouse_y; /// Current screen coords of the mouse
|
|
58 // FIXME: these need to be reset after every access:
|
|
59 RelPair[index_t] axis_rel_tbl; /// Table of relative mouse / joystick ball motions
|
|
60 +/ |