Mercurial > projects > mde
view mde/input/joystick.d @ 95:2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Fixed a minor bug where layouts with the same id but without shared alignments would be messed up.
Tracked down the "nothing trawn until a resize" bug (see jobs.txt).
If widgets throw during creation they're now replaced by debug widgets.
Function pointers are converted to delegates using a safer method.
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Thu, 06 Nov 2008 11:07:18 +0000 |
parents | 97e6dce08037 |
children |
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 as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version. 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, see <http://www.gnu.org/licenses/>. */ /** 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 mde.setup.exception; // InitStage 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. */ StageState openJoysticks () { joysticks = new SDL_Joystick*[SDL_NumJoysticks ()]; for (int i = 0; i < joysticks.length; ++i) { if ((joysticks[i] = SDL_JoystickOpen (i)) is null) { // null on failure logger.error ("Unable to open joystick {} via SDL", i); return StageState.ERROR; // prevent closeJoysticks running, but don't halt program } } logger.info ("Opened {} joysticks via SDL, succesfully unless preceding errors say otherwise.", joysticks.length); return StageState.ACTIVE; } /// Cleanup fct. StageState closeJoysticks () { foreach (js; joysticks) { // NOTE: This sometimes causes a SIGSEGV (Address boundary error) when init fails. debug logger.trace ("Calling SDL_JoystickClose"); if(js !is null) SDL_JoystickClose(js); // only close if successfully opened } return StageState.INACTIVE; }