annotate mde/input/joystick.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 f985c28c0ec9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17
5f90774ea1ef Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 10
diff changeset
1 /* LICENSE BLOCK
5f90774ea1ef Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 10
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: 10
diff changeset
3 Copyright © 2007-2008 Diggory Hardy
5f90774ea1ef Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 10
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: 10
diff changeset
8
5f90774ea1ef Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 10
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: 10
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: 10
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: 10
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: 10
diff changeset
15
9
1885a9080f2a Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
16 /** Opens SDL joysticks ready for use.
1885a9080f2a Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
17 * May be extended later to include other input devices and remap devices as per config.
1885a9080f2a Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
18 */
1885a9080f2a Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
19 module mde.input.joystick;
1885a9080f2a Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
20
1885a9080f2a Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
21 import tango.util.log.Log : Log, Logger;
1885a9080f2a Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
22
1885a9080f2a Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
23 import derelict.sdl.joystick;
1885a9080f2a Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
24
1885a9080f2a Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
25 private Logger logger;
1885a9080f2a Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
26 static this() {
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
27 logger = Log.getLogger ("mde.input.joystick");
9
1885a9080f2a Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
28 }
1885a9080f2a Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
29 private SDL_Joystick*[] joysticks; // pointers to all joystick structs, whether successfully opened or not
1885a9080f2a Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
30
1885a9080f2a Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
31 /** Open joysticks ready for use.
1885a9080f2a Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
32 *
1885a9080f2a Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
33 * This is simply required for SDL to handle joystick events. It can fail, but won't affect anything
1885a9080f2a Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
34 * else, except for the controller not working.
1885a9080f2a Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
35 *
1885a9080f2a Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
36 * closeJoysticks must be run to cleanup afterwards.
1885a9080f2a Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
37 */
1885a9080f2a Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
38 void openJoysticks () {
1885a9080f2a Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
39 joysticks = new SDL_Joystick*[SDL_NumJoysticks ()];
1885a9080f2a Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
40 char tmp[128] = void;
1885a9080f2a Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
41
1885a9080f2a Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
42 for (int i = 0; i < joysticks.length; ++i) {
1885a9080f2a Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
43 if ((joysticks[i] = SDL_JoystickOpen (i)) is null) { // null on failure
24
32eff0e01c05 Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 17
diff changeset
44 logger.error (logger.format (tmp, "Unable to open joystick {} via SDL", i));
9
1885a9080f2a Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
45 }
1885a9080f2a Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
46 }
1885a9080f2a Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
47
1885a9080f2a Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
48 logger.info (logger.format (tmp, "Opened {} joysticks via SDL, succesfully unless preceding warnings say otherwise.", joysticks.length));
1885a9080f2a Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
49 }
1885a9080f2a Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
50
1885a9080f2a Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
51 /// Cleanup fct.
1885a9080f2a Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
52 void closeJoysticks () {
1885a9080f2a Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
53 foreach (js; joysticks) {
1885a9080f2a Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
54 if(js) SDL_JoystickClose(js); // only close if successfully opened
1885a9080f2a Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
55 }
1885a9080f2a Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
56 }