Mercurial > projects > mde
view mde/input/joystick.d @ 24:32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Options sub-classes are handled more generically and can be added without changing the Options class.
Options changed at run-time are tracked, and on exit merged with user options and saved.
Revised log levels as set out in policies.txt and as used in code.
committer: Diggory Hardy <diggory.hardy@gmail.com>
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Thu, 27 Mar 2008 16:15:21 +0000 |
parents | 5f90774ea1ef |
children | 611f7b9063c6 |
line wrap: on
line source
/* LICENSE BLOCK Part of mde: a Modular D game-oriented Engine Copyright © 2007-2008 Diggory Hardy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ /** Opens SDL joysticks ready for use. * May be extended later to include other input devices and remap devices as per config. */ module mde.input.joystick; import tango.util.log.Log : Log, Logger; import derelict.sdl.joystick; private Logger logger; static this() { logger = Log.getLogger ("mde.input.joystick"); } private SDL_Joystick*[] joysticks; // pointers to all joystick structs, whether successfully opened or not /** Open joysticks ready for use. * * This is simply required for SDL to handle joystick events. It can fail, but won't affect anything * else, except for the controller not working. * * closeJoysticks must be run to cleanup afterwards. */ void openJoysticks () { joysticks = new SDL_Joystick*[SDL_NumJoysticks ()]; char tmp[128] = void; for (int i = 0; i < joysticks.length; ++i) { if ((joysticks[i] = SDL_JoystickOpen (i)) is null) { // null on failure logger.error (logger.format (tmp, "Unable to open joystick {} via SDL", i)); } } logger.info (logger.format (tmp, "Opened {} joysticks via SDL, succesfully unless preceding warnings say otherwise.", joysticks.length)); } /// Cleanup fct. void closeJoysticks () { foreach (js; joysticks) { if(js) SDL_JoystickClose(js); // only close if successfully opened } }