annotate mde/input/joystick.d @ 67:108d123238c0

Changes to work with tango r3700 (post 0.99.6). Changes to logging. Replaced many uses of PathView with FilePath.
author Diggory Hardy <diggory.hardy@gmail.com>
date Thu, 03 Jul 2008 12:40:31 +0100
parents baa87e68d7dc
children 56c0ddd90193
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
1885a9080f2a Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
41 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
42 if ((joysticks[i] = SDL_JoystickOpen (i)) is null) { // null on failure
67
108d123238c0 Changes to work with tango r3700 (post 0.99.6).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 31
diff changeset
43 logger.error ("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
44 }
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
67
108d123238c0 Changes to work with tango r3700 (post 0.99.6).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 31
diff changeset
47 logger.info ("Opened {} joysticks via SDL, succesfully unless preceding errors say otherwise.", joysticks.length);
9
1885a9080f2a Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
48 }
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 /// Cleanup fct.
1885a9080f2a Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
51 void closeJoysticks () {
1885a9080f2a Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
52 foreach (js; joysticks) {
29
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
53 // FIXME: this is sometimes causing a SIGSEGV (Address boundary error)
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
54 // FIXME: when init fails
31
baa87e68d7dc GUI now supports basic interactible widgets, widget colour and border are more unified, and some code cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
55 debug logger.trace ("Closing joysticks (this sometimes fails when mde exits prematurely)");
29
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
56 if(js !is null) SDL_JoystickClose(js); // only close if successfully opened
31
baa87e68d7dc GUI now supports basic interactible widgets, widget colour and border are more unified, and some code cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
57 debug logger.trace ("Done closing joysticks");
9
1885a9080f2a Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
58 }
1885a9080f2a Joystick button input now works with config.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
59 }