Mercurial > projects > mde
annotate mde/input/config.d @ 26:611f7b9063c6
Changed the licensing and removed a few dead files.
Changed licensing to "GPL version 2 or later" to avoid future compatibility issues.
Also a unittest fix to the previous commit.
committer: Diggory Hardy <diggory.hardy@gmail.com>
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Thu, 03 Apr 2008 18:15:02 +0100 |
parents | 32eff0e01c05 |
children |
rev | line source |
---|---|
17
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
1 /* LICENSE BLOCK |
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
2 Part of mde: a Modular D game-oriented Engine |
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
3 Copyright © 2007-2008 Diggory Hardy |
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
4 |
26
611f7b9063c6
Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
24
diff
changeset
|
5 This program is free software: you can redistribute it and/or modify it under the terms |
611f7b9063c6
Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
24
diff
changeset
|
6 of the GNU General Public License as published by the Free Software Foundation, either |
611f7b9063c6
Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
24
diff
changeset
|
7 version 2 of the License, or (at your option) any later version. |
17
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
8 |
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
9 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
10 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
11 See the GNU General Public License for more details. |
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
12 |
26
611f7b9063c6
Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
24
diff
changeset
|
13 You should have received a copy of the GNU General Public License |
611f7b9063c6
Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
24
diff
changeset
|
14 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
17
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
15 |
0 | 16 /// This module contains a class for holding configs and handles saving, loading and editing. |
17 module mde.input.config; | |
2
78eb491bd642
mergetag: partially redesigned dataset and text reader classes. Changed text format.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
0
diff
changeset
|
18 |
10
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
9
diff
changeset
|
19 debug import tango.scrapple.text.convert.parseFrom : parseFrom; |
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
|
20 |
10
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
9
diff
changeset
|
21 import mde.input.exception; |
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 |
14
0047b364b6d9
Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
12
diff
changeset
|
23 import MT = mde.mergetag.Reader; |
15
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
14
diff
changeset
|
24 import mde.resource.paths; |
10
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
9
diff
changeset
|
25 import tango.scrapple.text.convert.parseTo : parseTo; |
2
78eb491bd642
mergetag: partially redesigned dataset and text reader classes. Changed text format.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
0
diff
changeset
|
26 |
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
|
27 import tango.util.log.Log : Log, Logger; |
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 import tango.util.collection.TreeBag : TreeBag; |
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 /** Class to hold the configuration for the input system. Thus loading and switching between |
0 | 31 * multiple configurations should be easy. |
32 * | |
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
|
33 * Class extends DataSection so that it can be loaded by mergetag easily. |
0 | 34 */ |
14
0047b364b6d9
Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
12
diff
changeset
|
35 class Config : MT.IDataSection |
0 | 36 { |
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
|
37 alias uint[] outQueue; // This is the type for the out queue config data. |
0 | 38 /** Button event type bit-codes |
39 * | |
40 * These bitcodes are OR'd to the identifier code for the input device, to indicate which type | |
41 * of input they are for. E.g. when a key event is recieved with code x, look up | |
10
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
9
diff
changeset
|
42 * $(_B _B.SDLKEY) | x in button. Keyboard events are SDL-specific since the codes may differ |
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
9
diff
changeset
|
43 * for other libraries. |
0 | 44 * |
10
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
9
diff
changeset
|
45 * For joystick hat events, a motion is converted into up and down events on separate U,L,D,R |
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
9
diff
changeset
|
46 * positions and up and down events sent to the appropriate outputs (effectively making four |
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
9
diff
changeset
|
47 * buttons, some pairs of which can be pressed simultaneously). For output to axes, see |
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
9
diff
changeset
|
48 * A.JOYHAT_* . |
0 | 49 */ |
50 enum B : uint { | |
10
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
9
diff
changeset
|
51 KEY = 0x8000_0000u, /// 0x8000_0000 |
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
9
diff
changeset
|
52 SDLKEY = 0x8800_0000u, /// 0x8800_0000 |
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
9
diff
changeset
|
53 MOUSE = 0x4000_0000u, /// 0x4000_0000 |
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
9
diff
changeset
|
54 JOYBUTTON = 0x2000_0000u, /// 0x2000_0000 |
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
9
diff
changeset
|
55 JOYHAT = 0x1000_0000u, /// 0x1000_0000 |
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
9
diff
changeset
|
56 JOYHAT_U = 0x1800_0000u, /// 0x1800_0000 |
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
9
diff
changeset
|
57 JOYHAT_D = 0x1400_0000u, /// 0x1400_0000 |
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
9
diff
changeset
|
58 JOYHAT_L = 0x1200_0000u, /// 0x1200_0000 |
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
9
diff
changeset
|
59 JOYHAT_R = 0x1100_0000u, /// 0x1100_0000 |
0 | 60 } |
61 | |
62 /** Axis event type bit-codes | |
63 * | |
10
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
9
diff
changeset
|
64 * SDL only supports one type of axis now, but this could be extended in the future. |
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
9
diff
changeset
|
65 * |
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
9
diff
changeset
|
66 * This can also be used to make joystick hats output to two axes (and can be used in |
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
9
diff
changeset
|
67 * conjuction with B.JOYHAT_* to output as buttons as well). |
0 | 68 */ |
69 enum A : uint { | |
10
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
9
diff
changeset
|
70 JOYAXIS = 0x8000_0000u, /// 0x8000_0000 |
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
9
diff
changeset
|
71 JOYHAT = 0x1000_0000u, /// 0x1000_0000 |
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
9
diff
changeset
|
72 JOYHAT_LR = 0x1300_0000u, /// 0x1300_0000 |
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
9
diff
changeset
|
73 JOYHAT_UD = 0x1C00_0000u, /// 0x1C00_0000 |
0 | 74 } |
75 | |
76 /** Mouse & Joystick ball event type bit-codes | |
77 * | |
78 * Currently, mouse input only comes from the window manager: the code is exactly M.WMMOUSE. | |
79 */ | |
80 enum M : uint { | |
10
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
9
diff
changeset
|
81 MOUSE = 0x8000_0000u, /// 0x8000_0000 |
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
9
diff
changeset
|
82 WMMOUSE = 0x8800_0000u, /// 0x8800_0000 |
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
9
diff
changeset
|
83 JOYBALL = 0x4000_0000u, /// 0x4000_0000 |
0 | 84 } |
85 | |
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
|
86 /** Output queues: the core of the input configuration. |
0 | 87 * |
10
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
9
diff
changeset
|
88 * These are all mapped with a uint key; upon any event outQueues are looked for in the |
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
9
diff
changeset
|
89 * appropriate associative array with a key as follows. |
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
9
diff
changeset
|
90 * |
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
9
diff
changeset
|
91 * The index is split into two parts; |
0 | 92 * the first byte specifies the type of input (given by the above enums), and the last three |
93 * bytes define where the input comes from. | |
94 * | |
10
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
9
diff
changeset
|
95 * For type B.SDLKEY, the last three bytes are for the SDL keysym. |
0 | 96 * For B.MOUSE, B.JOY*, A.JOY* & M.JOY*, the last three bytes are split into two sets of 12 |
97 * bits (with masks 0x00FF_F000 and 0x0000_0FFF), the higher of which specifies the device | |
98 * (which mouse or joystick), and the lower of which specifies the button/axis/ball. | |
99 * | |
10
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
9
diff
changeset
|
100 * For all three types of output, the outQueues are used as follows. The first value in the queue is |
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
9
diff
changeset
|
101 * read, and a function is called with the event details dependant on this; most of the time an |
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
9
diff
changeset
|
102 * output function is called directly. Other functions may be used, however, to allow further |
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
9
diff
changeset
|
103 * functionality such as modifier keys, timed keys, and key sequences. |
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
9
diff
changeset
|
104 * |
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
9
diff
changeset
|
105 * The output functions all have code 0x100; these read a single item from the outQueue which |
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
9
diff
changeset
|
106 * is the inputID the event outputs to (i.e. any callbacks at that ID called and status set for |
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
9
diff
changeset
|
107 * that ID). |
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
9
diff
changeset
|
108 * |
0 | 109 */ |
10
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
9
diff
changeset
|
110 outQueue[][uint] button; |
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
9
diff
changeset
|
111 outQueue[][uint] axis; /// ditto |
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
9
diff
changeset
|
112 outQueue[][uint] relMotion; /// ditto |
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
|
113 |
10
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
9
diff
changeset
|
114 // FIXME: |
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
|
115 char[] name; /// Name for user to save this under. |
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 uint[] inheritants; /// Other profiles to inherit. |
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 |
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
|
118 static Config[char[]] configs; /// All configs loaded by load(). |
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
|
119 private static TreeBag!(char[]) loadedFiles; // all filenames load tried to read |
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 |
12
bff0d802cb7d
Implemented some internationalization support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
10
diff
changeset
|
121 private static Logger logger; |
bff0d802cb7d
Implemented some internationalization support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
10
diff
changeset
|
122 static this() { |
bff0d802cb7d
Implemented some internationalization support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
10
diff
changeset
|
123 logger = Log.getLogger ("mde.input.config.Config"); |
bff0d802cb7d
Implemented some internationalization support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
10
diff
changeset
|
124 } |
bff0d802cb7d
Implemented some internationalization support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
10
diff
changeset
|
125 |
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 //BEGIN File loading/saving code |
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 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
|
128 loadedFiles = new TreeBag!(char[]); |
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 |
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 // Load all configs from a file. |
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
|
132 static void load (char[] filename) { |
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
|
133 if (loadedFiles.contains (filename)) return; // forget it; already done that |
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 loadedFiles.add (filename); |
9
1885a9080f2a
Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
135 |
14
0047b364b6d9
Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
12
diff
changeset
|
136 MT.IReader file; |
9
1885a9080f2a
Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
137 |
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
|
138 try { |
15
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
14
diff
changeset
|
139 // open and read header: |
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
14
diff
changeset
|
140 file = confDir.makeMTReader (filename, PRIORITY.LOW_HIGH, null, true); |
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
|
141 |
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 file.dataSecCreator = |
14
0047b364b6d9
Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
12
diff
changeset
|
143 delegate MT.IDataSection (MT.ID) { return new Config; }; |
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
|
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 // D2.0: enum MT.ID CONFIGS = "Configs"; |
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
|
146 const MT.ID CONFIGS = cast(MT.ID)"Configs"; |
14
0047b364b6d9
Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
12
diff
changeset
|
147 // Restrict config sections if this tag exists: |
0047b364b6d9
Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
12
diff
changeset
|
148 auto file_configs_p = CONFIGS in file.dataset.header._charAA; |
0047b364b6d9
Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
12
diff
changeset
|
149 MT.ID[] file_configs = null; |
0047b364b6d9
Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
12
diff
changeset
|
150 if (file_configs_p) { |
0047b364b6d9
Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
12
diff
changeset
|
151 file_configs = cast(MT.ID[]) *file_configs_p; |
0047b364b6d9
Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
12
diff
changeset
|
152 } |
0047b364b6d9
Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
12
diff
changeset
|
153 |
0047b364b6d9
Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
12
diff
changeset
|
154 if (file_configs) file.read(file_configs); // restrict to this set IF a restriction was given |
9
1885a9080f2a
Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
155 else file.read(); // otherwise read all |
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
|
156 } |
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
|
157 catch (MT.MTException) { |
24
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
158 logger.fatal ("Unable to load configs from: " ~ filename); |
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
|
159 throw new ConfigLoadException; |
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
|
160 } |
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
|
161 |
9
1885a9080f2a
Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
162 // Trying to directly cast dataset.sec to configs resulted in the Configs losing their data. |
1885a9080f2a
Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
163 // Also this is safer since it checks types (and must be done if configs wasn't previously empty). |
1885a9080f2a
Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
164 foreach (i, sec; file.dataset.sec) { |
1885a9080f2a
Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
165 Config c = cast(Config) sec; |
1885a9080f2a
Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
8
diff
changeset
|
166 if (c) configs[i] = c; // Check, because we don't want null entries in configs |
24
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
167 else debug logger.error ("Ended up with DataSection of wrong type; this should never happen."); |
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
|
168 } |
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
|
169 |
20
838577503598
Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
170 debug (MDE_CONFIG_DUMP) { |
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
|
171 char tmp[128] = void; |
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
|
172 logger.trace (logger.format (tmp, "Loaded {} config sections.", configs.length)); |
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
|
173 foreach (id, cfg; configs) { |
10
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
9
diff
changeset
|
174 logger.trace ("Section " ~ id ~ |
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
9
diff
changeset
|
175 ":\n\tbutton:\t\t" ~ parseFrom!(uint[][][uint])(cfg.button) ~ |
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
9
diff
changeset
|
176 "\n\taxis:\t\t" ~ parseFrom!(uint[][][uint])(cfg.axis) ~ |
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
9
diff
changeset
|
177 "\n\trelMotion:\t" ~ parseFrom!(uint[][][uint])(cfg.relMotion) ); |
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
|
178 } |
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 } |
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 } |
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 |
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
|
182 // D2.0: private enum QUEUE : MT.ID { BUTTON = "B", AXIS = "A", MOUSE = "M" } |
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
|
183 private struct QUEUE { |
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
|
184 static const MT.ID BUTTON = cast(MT.ID)"B", AXIS = cast(MT.ID)"A", MOUSE = cast(MT.ID)"M"; |
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
|
185 } |
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
|
186 private this() {} // Private since this class should only be created from here. |
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 |
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
|
188 void addTag (char[] tp, MT.ID id, char[] dt) { |
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
|
189 if (tp == "uint[][uint]") { |
10
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
9
diff
changeset
|
190 if (id == QUEUE.BUTTON) button = cast(outQueue[][uint]) parseTo!(uint[][][uint]) (dt); |
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
9
diff
changeset
|
191 else if (id == QUEUE.AXIS) axis = cast(outQueue[][uint]) parseTo!(uint[][][uint]) (dt); |
4c3575400769
DefaultData largely rewritten with unittest, SDL input event handling completed with unittest, changes to Init threading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
9
diff
changeset
|
192 else if (id == QUEUE.MOUSE) relMotion = cast(outQueue[][uint]) parseTo!(uint[][][uint]) (dt); |
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
|
193 else logger.warn ("Unexpected tag encountered with ID " ~ cast(char[])id); |
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
|
194 } // FIXME: add support for name and inheritants. |
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 } |
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 void writeAll (ItemDelg) { |
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 // FIXME |
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 //END File loading/saving code |
0 | 200 } |