From 741f48d34a7922fb846634975ab60282233f0023 Mon Sep 17 00:00:00 2001 From: Jens Ayton Date: Fri, 8 Jun 2007 14:54:21 +0000 Subject: [PATCH] Undid damage to shipdata.plist from last revision. Extended dummy joystick handler for OS X to reduce the number of #ifs in PlayerEntityControls.m. git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@1012 127b21dd-08f5-0310-b4b7-95ae10353056 --- Oolite.xcodeproj/project.pbxproj | 4 + Resources/Config/shipdata.plist | 128 +++++++++++------------ src/Cocoa/JoystickHandler.h | 102 ++++++++++++++++++ src/Cocoa/JoystickHandler.m | 80 ++++++++++++++ src/Cocoa/MyOpenGLView.m | 5 +- src/Core/Entities/PlayerEntityControls.m | 87 ++------------- src/Core/OOQuaternion.m | 13 ++- 7 files changed, 273 insertions(+), 146 deletions(-) create mode 100644 src/Cocoa/JoystickHandler.m diff --git a/Oolite.xcodeproj/project.pbxproj b/Oolite.xcodeproj/project.pbxproj index 6e6c84a1..f79d3b1b 100644 --- a/Oolite.xcodeproj/project.pbxproj +++ b/Oolite.xcodeproj/project.pbxproj @@ -387,6 +387,7 @@ 1ADBA5510BD0F173008FC99C /* OOBasicMaterial.m in Sources */ = {isa = PBXBuildFile; fileRef = 1ADBA54F0BD0F173008FC99C /* OOBasicMaterial.m */; }; 1ADF5CEC0B9DF59A00FDB2A3 /* OOCacheManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A231A170B9D8B1B00EF0852 /* OOCacheManager.m */; }; 1ADF5F130B9E374B00FDB2A3 /* JoystickHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = 1ADF5F110B9E374B00FDB2A3 /* JoystickHandler.h */; }; + 1AE546310C19A2E2005B89F3 /* JoystickHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 1AE546300C19A2E2005B89F3 /* JoystickHandler.m */; }; 1AEAAB8F0BA45248000705D0 /* libjs.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1AEAAB8E0BA45248000705D0 /* libjs.a */; }; 1AEAAC9E0BA457E7000705D0 /* jsarena.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AEAAC6F0BA457E6000705D0 /* jsarena.h */; }; 1AEAAC9F0BA457E7000705D0 /* jsarray.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AEAAC700BA457E6000705D0 /* jsarray.h */; }; @@ -1228,6 +1229,7 @@ 1ADBA54E0BD0F173008FC99C /* OOBasicMaterial.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OOBasicMaterial.h; sourceTree = ""; }; 1ADBA54F0BD0F173008FC99C /* OOBasicMaterial.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OOBasicMaterial.m; sourceTree = ""; }; 1ADF5F110B9E374B00FDB2A3 /* JoystickHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JoystickHandler.h; sourceTree = ""; }; + 1AE546300C19A2E2005B89F3 /* JoystickHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JoystickHandler.m; sourceTree = ""; }; 1AEAAB8E0BA45248000705D0 /* libjs.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libjs.a; path = "deps/Cocoa-deps/js/libjs.a"; sourceTree = ""; }; 1AEAAC6F0BA457E6000705D0 /* jsarena.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = jsarena.h; sourceTree = ""; }; 1AEAAC700BA457E6000705D0 /* jsarray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = jsarray.h; sourceTree = ""; }; @@ -1937,6 +1939,7 @@ 1A8A3D8F0B9B058500AB7625 /* Audio */, 1A8A3D9E0B9B05C400AB7625 /* Groolite */, 1ADF5F110B9E374B00FDB2A3 /* JoystickHandler.h */, + 1AE546300C19A2E2005B89F3 /* JoystickHandler.m */, 1A8071D70C0480AC00BA1935 /* Debug */, ); name = "Mac-specific"; @@ -2632,6 +2635,7 @@ 1AED2DE80C046BA2004A1118 /* OODebugController.m in Sources */, 1A15044C0C12C50D0032F3E8 /* OOSkyDrawable.m in Sources */, 1A15049F0C12CA070032F3E8 /* OOProbabilisticTextureManager.m in Sources */, + 1AE546310C19A2E2005B89F3 /* JoystickHandler.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Resources/Config/shipdata.plist b/Resources/Config/shipdata.plist index 98871027..a435f64b 100644 --- a/Resources/Config/shipdata.plist +++ b/Resources/Config/shipdata.plist @@ -37,7 +37,7 @@ 2 max_flight_roll 2.7999999999999998 - maxFlightSpeed + max_flight_speed 240 max_missiles 1 @@ -93,7 +93,7 @@ 2 max_flight_roll 2.7999999999999998 - maxFlightSpeed + max_flight_speed 240 max_missiles 1 @@ -231,7 +231,7 @@ 0.5 max_flight_roll 0.5 - maxFlightSpeed + max_flight_speed 50 missiles 0 @@ -287,7 +287,7 @@ 0.40000000000000002 max_flight_roll 0.75 - maxFlightSpeed + max_flight_speed 140 max_missiles 7 @@ -335,7 +335,7 @@ 0.40000000000000002 max_flight_roll 0.75 - maxFlightSpeed + max_flight_speed 140 max_missiles 7 @@ -500,7 +500,7 @@ 1 max_flight_roll 2 - maxFlightSpeed + max_flight_speed 400 max_missiles 1 @@ -572,7 +572,7 @@ 1 max_flight_roll 2 - maxFlightSpeed + max_flight_speed 400 max_missiles 1 @@ -623,7 +623,7 @@ 1 max_flight_roll 2 - maxFlightSpeed + max_flight_speed 400 max_missiles 1 @@ -765,7 +765,7 @@ 0.10000000000000001 max_flight_roll 0.10000000000000001 - maxFlightSpeed + max_flight_speed 0.0 missiles 0 @@ -815,7 +815,7 @@ 0.5 max_flight_roll 0.5 - maxFlightSpeed + max_flight_speed 50 missiles 0 @@ -872,7 +872,7 @@ 1 max_flight_roll 2.7999999999999998 - maxFlightSpeed + max_flight_speed 240 max_missiles 4 @@ -946,7 +946,7 @@ 1 max_flight_roll 2.5 - maxFlightSpeed + max_flight_speed 312 max_missiles 5 @@ -1006,7 +1006,7 @@ 1 max_flight_roll 2.5 - maxFlightSpeed + max_flight_speed 312 max_missiles 5 @@ -1144,7 +1144,7 @@ 1 max_flight_roll 2.7999999999999998 - maxFlightSpeed + max_flight_speed 240 max_missiles 4 @@ -1288,7 +1288,7 @@ 0.5 max_flight_roll 0.5 - maxFlightSpeed + max_flight_speed 5 missiles 0 @@ -1340,7 +1340,7 @@ 2 max_flight_roll 2 - maxFlightSpeed + max_flight_speed 0.0 missiles 0 @@ -1381,7 +1381,7 @@ 2 max_flight_roll 2 - maxFlightSpeed + max_flight_speed 0.0 missiles 0 @@ -1427,7 +1427,7 @@ 0.5 max_flight_roll 0.5 - maxFlightSpeed + max_flight_speed 50 model barrel.dat @@ -1503,7 +1503,7 @@ 1 max_flight_roll 2 - maxFlightSpeed + max_flight_speed 320 missile_launch_position 0.0 -4.5 16.5 @@ -1567,7 +1567,7 @@ 1 max_flight_roll 2 - maxFlightSpeed + max_flight_speed 300 missile_launch_position 0.0 -4.5 16.5 @@ -1615,7 +1615,7 @@ 1 max_flight_roll 2 - maxFlightSpeed + max_flight_speed 350 max_missiles 4 @@ -1768,7 +1768,7 @@ 1 max_flight_roll 2 - maxFlightSpeed + max_flight_speed 300 missile_launch_position 0.0 -4.5 16.5 @@ -1824,7 +1824,7 @@ 1.2 max_flight_roll 2 - maxFlightSpeed + max_flight_speed 260 missile_launch_position 0.0 -2.0 14.0 @@ -1884,7 +1884,7 @@ 1.2 max_flight_roll 2 - maxFlightSpeed + max_flight_speed 260 max_missiles 1 @@ -1944,7 +1944,7 @@ 1.2 max_flight_roll 2 - maxFlightSpeed + max_flight_speed 260 missile_launch_position 0.0 -2.0 14.0 @@ -1990,7 +1990,7 @@ 1.2 max_flight_roll 2 - maxFlightSpeed + max_flight_speed 260 max_missiles 1 @@ -2150,7 +2150,7 @@ 1.75 max_flight_roll 2.5 - maxFlightSpeed + max_flight_speed 600 max_missiles 3 @@ -2213,7 +2213,7 @@ 8 max_flight_roll 8 - maxFlightSpeed + max_flight_speed 0.0 max_missiles 0 @@ -2308,7 +2308,7 @@ 8 max_flight_roll 8 - maxFlightSpeed + max_flight_speed 0.0 max_missiles 0 @@ -2377,7 +2377,7 @@ 0.5 max_flight_roll 0.5 - maxFlightSpeed + max_flight_speed 50 max_missiles 0 @@ -2458,7 +2458,7 @@ 1 max_flight_roll 3.6000000000000001 - maxFlightSpeed + max_flight_speed 300 max_missiles 2 @@ -2507,7 +2507,7 @@ 1 max_flight_roll 3.6000000000000001 - maxFlightSpeed + max_flight_speed 300 max_missiles 2 @@ -2655,7 +2655,7 @@ 1.5 max_flight_roll 3 - maxFlightSpeed + max_flight_speed 300 max_missiles 1 @@ -2740,7 +2740,7 @@ 8 max_flight_roll 8 - maxFlightSpeed + max_flight_speed 0.0 max_missiles 0 @@ -2818,7 +2818,7 @@ 1.5 max_flight_roll 2.75 - maxFlightSpeed + max_flight_speed 300 max_missiles 0 @@ -2883,7 +2883,7 @@ 1.4 max_flight_roll 2.1 - maxFlightSpeed + max_flight_speed 320 max_missiles 0 @@ -2944,7 +2944,7 @@ 1.4 max_flight_roll 2.1 - maxFlightSpeed + max_flight_speed 320 max_missiles 0 @@ -3003,7 +3003,7 @@ 8 max_flight_roll 10 - maxFlightSpeed + max_flight_speed 750 max_missiles 0 @@ -3058,7 +3058,7 @@ 1.5 max_flight_roll 2.5 - maxFlightSpeed + max_flight_speed 300 max_missiles 2 @@ -3105,7 +3105,7 @@ 1.5 max_flight_roll 2.5 - maxFlightSpeed + max_flight_speed 300 max_missiles 2 @@ -3253,7 +3253,7 @@ 1.5 max_flight_roll 2.5 - maxFlightSpeed + max_flight_speed 300 max_missiles 2 @@ -3300,7 +3300,7 @@ 1.5 max_flight_roll 2.5 - maxFlightSpeed + max_flight_speed 300 max_missiles 2 @@ -3452,7 +3452,7 @@ 0.80000000000000004 max_flight_roll 2 - maxFlightSpeed + max_flight_speed 200 max_missiles 2 @@ -3517,7 +3517,7 @@ 0.80000000000000004 max_flight_roll 2 - maxFlightSpeed + max_flight_speed 200 max_missiles 2 @@ -3564,7 +3564,7 @@ 0.80000000000000004 max_flight_roll 2 - maxFlightSpeed + max_flight_speed 200 max_missiles 2 @@ -3716,7 +3716,7 @@ 0.80000000000000004 max_flight_roll 2 - maxFlightSpeed + max_flight_speed 200 max_missiles 2 @@ -3753,7 +3753,7 @@ 2 max_flight_roll 2 - maxFlightSpeed + max_flight_speed 1000 model qbomb.dat @@ -3800,7 +3800,7 @@ 8 max_flight_roll 8 - maxFlightSpeed + max_flight_speed 0.0 max_missiles 0 @@ -3856,7 +3856,7 @@ 0.5 max_flight_roll 0.5 - maxFlightSpeed + max_flight_speed 50 missiles 0 @@ -3900,7 +3900,7 @@ 0.90000000000000002 max_flight_roll 2 - maxFlightSpeed + max_flight_speed 80 max_missiles 0 @@ -3961,7 +3961,7 @@ 1.6000000000000001 max_flight_roll 2.7999999999999998 - maxFlightSpeed + max_flight_speed 370 max_missiles 0 @@ -4022,7 +4022,7 @@ 1.8 max_flight_roll 2.7999999999999998 - maxFlightSpeed + max_flight_speed 370 max_missiles 0 @@ -4083,7 +4083,7 @@ 1 max_flight_roll 1 - maxFlightSpeed + max_flight_speed 10 missiles 0 @@ -4146,7 +4146,7 @@ 1 max_flight_roll 2 - maxFlightSpeed + max_flight_speed 450 missiles 0 @@ -4209,7 +4209,7 @@ 1 max_flight_roll 2 - maxFlightSpeed + max_flight_speed 500 max_missiles 5 @@ -4261,7 +4261,7 @@ 1 max_flight_roll 2 - maxFlightSpeed + max_flight_speed 100 max_missiles 0 @@ -4327,7 +4327,7 @@ 1 max_flight_roll 2 - maxFlightSpeed + max_flight_speed 100 max_missiles 0 @@ -4393,7 +4393,7 @@ 1.8 max_flight_roll 2.7999999999999998 - maxFlightSpeed + max_flight_speed 320 max_missiles 1 @@ -4481,7 +4481,7 @@ 2 max_flight_roll 4.2000000000000002 - maxFlightSpeed + max_flight_speed 520 max_missiles 3 @@ -4564,7 +4564,7 @@ 1.8 max_flight_roll 2.7999999999999998 - maxFlightSpeed + max_flight_speed 360 max_missiles 1 @@ -4625,7 +4625,7 @@ 1 max_flight_roll 2 - maxFlightSpeed + max_flight_speed 110 max_missiles 0 @@ -4688,7 +4688,7 @@ 1 max_flight_roll 2 - maxFlightSpeed + max_flight_speed 100 max_missiles 0 @@ -4748,7 +4748,7 @@ 8 max_flight_roll 10 - maxFlightSpeed + max_flight_speed 750 max_missiles 0 @@ -4788,7 +4788,7 @@ 2.0 max_flight_roll 2.0 - maxFlightSpeed + max_flight_speed 500 model wreck1.dat diff --git a/src/Cocoa/JoystickHandler.h b/src/Cocoa/JoystickHandler.h index 88cf9351..62046546 100644 --- a/src/Cocoa/JoystickHandler.h +++ b/src/Cocoa/JoystickHandler.h @@ -5,6 +5,7 @@ JoystickHandler.h Non-functional JoystickHandler. This exists to reduce the amount of #ifdefs and duplicated code. + Oolite Copyright (C) 2004-2007 Giles C Williams and contributors @@ -23,16 +24,117 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +This file may also be distributed under the MIT/X11 license: + +Copyright (C) 2006 Jens Ayton + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + */ #import #define STICK_AXISUNASSIGNED -10.0 +// Enums are used here rather than a more complex ObjC object because +// these are required very frequently (once per frame) so must be light +// on CPU cycles (try and avoid too many objc sendmsgs). +// Controls that can be an axis +enum { + AXIS_ROLL, + AXIS_PITCH, + AXIS_PRECISION, + AXIS_THRUST, + AXIS_VIEW, + AXIS_end +} axfn; + +// Controls that can be a button +enum { + BUTTON_INCTHRUST, + BUTTON_DECTHRUST, + BUTTON_SCANNERZOOM, + BUTTON_JETTISON, + BUTTON_COMPASSMODE, + BUTTON_COMMSLOG, + BUTTON_DOCKCPU, + BUTTON_DOCKCPUFAST, + BUTTON_DOCKCPUTARGET, + BUTTON_FUELINJECT, + BUTTON_HYPERSPEED, + BUTTON_HYPERDRIVE, + BUTTON_GALACTICDRIVE, + BUTTON_FIRE, + BUTTON_ARMMISSILE, + BUTTON_LAUNCHMISSILE, + BUTTON_UNARM, + BUTTON_CYCLEMISSILE, + BUTTON_ENERGYBOMB, + BUTTON_ID, + BUTTON_ECM, + BUTTON_ESCAPE, + BUTTON_CLOAK, + BUTTON_PRECISION, + BUTTON_end +} butfn; + +// Stick constants +#define MAX_STICKS 2 +#define MAX_AXES 10 +#define MAX_BUTTONS 20 +#define STICK_NOFUNCTION -1 +#define STICK_AXISUNASSIGNED -10.0 +#define STICK_PRECISIONDIV 98304 // 3 times more precise +#define STICK_NORMALDIV 32768 +#define STICK_PRECISIONFAC (STICK_PRECISIONDIV/STICK_NORMALDIV) + +// Kind of stick device (these are bits - if any more are added, +// the next one is 4 and so on). +#define HW_AXIS 1 +#define HW_BUTTON 2 + +// The threshold at which an axis can trigger a call back. +// The max of abs(axis) is 32767. +#define AXCBTHRESH 20000 + +// Dictionary keys - used in the defaults file +#define AXIS_SETTINGS @"JoystickAxes" // NSUserDefaults +#define BUTTON_SETTINGS @"JoystickButs" // NSUserDefaults +#define STICK_ISAXIS @"isAxis" // YES=axis NO=button +#define STICK_NUMBER @"stickNum" // Stick number 0 to 4 +#define STICK_AXBUT @"stickAxBt" // Axis or button number +#define STICK_FUNCTION @"stickFunc" // Function of axis/button +// shortcut to make code more readable when using enum as key for +// an NSDictionary +#define ENUMKEY(x) [NSString stringWithFormat: @"%d", x] + @interface JoystickHandler: NSObject +{ + BOOL butstate[BUTTON_end]; +} + ++ (id)sharedStickHandler; - (int) getNumSticks; - (NSPoint) getRollPitchAxis; +- (const BOOL *)getAllButtonStates; @end diff --git a/src/Cocoa/JoystickHandler.m b/src/Cocoa/JoystickHandler.m new file mode 100644 index 00000000..14c74908 --- /dev/null +++ b/src/Cocoa/JoystickHandler.m @@ -0,0 +1,80 @@ +/* + +JoystickHandler.m + +Oolite +Copyright (C) 2004-2007 Giles C Williams and contributors + +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, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +MA 02110-1301, USA. + + +This file may also be distributed under the MIT/X11 license: + +Copyright (C) 2006 Jens Ayton + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +*/ + +#import "JoystickHandler.h" + + +JoystickHandler *sSharedStickHandler = nil; + + +@implementation JoystickHandler + ++ (id)sharedStickHandler +{ + if (sSharedStickHandler == nil) sSharedStickHandler = [[JoystickHandler alloc] init]; + return sSharedStickHandler; +} + + +- (int)getNumSticks +{ + return 0; +} + + +- (NSPoint)getRollPitchAxis +{ + return NSMakePoint(0.0f, 0.0f); +} + + +- (const BOOL *)getAllButtonStates +{ + return butstate; +} + +@end diff --git a/src/Cocoa/MyOpenGLView.m b/src/Cocoa/MyOpenGLView.m index 13e7505d..8a0a4f35 100644 --- a/src/Cocoa/MyOpenGLView.m +++ b/src/Cocoa/MyOpenGLView.m @@ -32,6 +32,7 @@ MA 02110-1301, USA. #import "GuiDisplayGen.h" #import "OODebugController.h" #import +#import "JoystickHandler.h" static NSString * kOOLogKeyCodeOutOfRange = @"input.keyMapping.codeOutOfRange"; @@ -109,7 +110,7 @@ static NSString * kOOLogKeyDown = @"input.keyMapping.keyPress.keyDown"; - (void)awakeFromNib { -#ifndef NDEBUG +#if OO_INCLUDE_DEBUG_CONTROLLER (void)[OODebugController sharedDebugController]; #endif } @@ -590,7 +591,7 @@ static NSString * kOOLogKeyDown = @"input.keyMapping.keyPress.keyDown"; - (JoystickHandler *)getStickHandler { - return nil; + return [JoystickHandler sharedStickHandler]; } diff --git a/src/Core/Entities/PlayerEntityControls.m b/src/Core/Entities/PlayerEntityControls.m index bfd8700c..28bdeac1 100644 --- a/src/Core/Entities/PlayerEntityControls.m +++ b/src/Core/Entities/PlayerEntityControls.m @@ -244,18 +244,16 @@ static NSTimeInterval time_last_frame; { MyOpenGLView *gameView = (MyOpenGLView *)[UNIVERSE gameView]; -#if OOLITE_HAVE_JOYSTICK - // DJS: TODO: Sort where SDL keeps its stuff. - if(!stickHandler) - { - stickHandler=[gameView getStickHandler]; - } - const BOOL *joyButtonState=[stickHandler getAllButtonStates]; -#endif - + // DJS: TODO: Sort where SDL keeps its stuff. + if(!stickHandler) + { + stickHandler=[gameView getStickHandler]; + } + const BOOL *joyButtonState=[stickHandler getAllButtonStates]; + BOOL paused = [[gameView gameController] game_is_paused]; double speed_delta = 5.0 * thrust; - + if (!paused) { // @@ -273,12 +271,7 @@ static NSTimeInterval time_last_frame; //if (![gameView allowingStringInput]) if (![UNIVERSE displayCursor]) { - // -#if OOLITE_HAVE_JOYSTICK if ((joyButtonState[BUTTON_FUELINJECT] || [gameView isDown:key_inject_fuel])&&(has_fuel_injection)&&(!hyperspeed_engaged)) -#else - if (([gameView isDown:key_inject_fuel])&&(has_fuel_injection)&&(!hyperspeed_engaged)) -#endif { if ((fuel > 0)&&(!afterburner_engaged)) { @@ -361,11 +354,7 @@ static NSTimeInterval time_last_frame; // hyperspeed controls // -#if OOLITE_HAVE_JOYSTICK if ([gameView isDown:key_jumpdrive] || joyButtonState[BUTTON_HYPERSPEED]) // 'j' -#else - if ([gameView isDown:key_jumpdrive]) // 'j' -#endif { if (!jump_pressed) { @@ -394,11 +383,7 @@ static NSTimeInterval time_last_frame; // // shoot 'a' // -#if OOLITE_HAVE_JOYSTICK if ((([gameView isDown:key_fire_lasers])||((mouse_control_on)&&([gameView isDown:gvMouseLeftButton]))||joyButtonState[BUTTON_FIRE])&&(shot_time > weapon_reload_time)) -#else - if ((([gameView isDown:key_fire_lasers])||((mouse_control_on)&&([gameView isDown:gvMouseLeftButton])))&&(shot_time > weapon_reload_time)) -#endif { if ([self fireMainWeapon]) @@ -425,11 +410,7 @@ static NSTimeInterval time_last_frame; // // shoot 'm' // launch missile // -#if OOLITE_HAVE_JOYSTICK if ([gameView isDown:key_launch_missile] || joyButtonState[BUTTON_LAUNCHMISSILE]) -#else - if ([gameView isDown:key_launch_missile]) -#endif { // launch here if (!fire_missile_pressed) @@ -447,11 +428,7 @@ static NSTimeInterval time_last_frame; // // shoot 'y' // next missile // -#if OOLITE_HAVE_JOYSTICK if ([gameView isDown:key_next_missile] || joyButtonState[BUTTON_CYCLEMISSILE]) -#else - if ([gameView isDown:key_next_missile]) -#endif { if ((!ident_engaged)&&(!next_missile_pressed)&&([self has_extra_equipment:@"EQ_MULTI_TARGET"])) { @@ -503,11 +480,7 @@ static NSTimeInterval time_last_frame; // // shoot 'r' // switch on ident system // -#if OOLITE_HAVE_JOYSTICK if ([gameView isDown:key_ident_system] || joyButtonState[BUTTON_ID]) -#else - if ([gameView isDown:key_ident_system]) -#endif { // ident 'on' here if (!ident_pressed) @@ -526,11 +499,7 @@ static NSTimeInterval time_last_frame; // // shoot 't' // switch on missile targetting // -#if OOLITE_HAVE_JOYSTICK if (([gameView isDown:key_target_missile] || joyButtonState[BUTTON_ARMMISSILE])&&(missile_entity[activeMissile])) -#else - if ([gameView isDown:key_target_missile] && missile_entity[activeMissile]) -#endif { // targetting 'on' here if (!target_missile_pressed) @@ -574,11 +543,7 @@ static NSTimeInterval time_last_frame; // // shoot 'u' // disarm missile targetting // -#if OOLITE_HAVE_JOYSTICK if ([gameView isDown:key_untarget_missile] || joyButtonState[BUTTON_UNARM]) -#else - if ([gameView isDown:key_untarget_missile]) -#endif { if (!safety_pressed) { @@ -610,11 +575,7 @@ static NSTimeInterval time_last_frame; // // shoot 'e' // ECM // -#if OOLITE_HAVE_JOYSTICK if (([gameView isDown:key_ecm] || joyButtonState[BUTTON_ECM])&&(has_ecm)) -#else - if ([gameView isDown:key_ecm] && has_ecm) -#endif { if (!ecm_in_operation) { @@ -628,11 +589,7 @@ static NSTimeInterval time_last_frame; // // shoot 'tab' // Energy bomb // -#if OOLITE_HAVE_JOYSTICK if (([gameView isDown:key_energy_bomb] || joyButtonState[BUTTON_ENERGYBOMB])&&(has_energy_bomb)) -#else - if ([gameView isDown:key_energy_bomb] && has_energy_bomb) -#endif { // original energy bomb routine [self fireEnergyBomb]; @@ -641,11 +598,7 @@ static NSTimeInterval time_last_frame; // // shoot 'escape' // Escape pod launch // -#if OOLITE_HAVE_JOYSTICK if (([gameView isDown:key_launch_escapepod] || joyButtonState[BUTTON_ESCAPE])&&(has_escape_pod)&&([UNIVERSE station])) -#else - if ([gameView isDown:key_launch_escapepod] && has_escape_pod && [UNIVERSE station]) -#endif { found_target = [self launchEscapeCapsule]; @@ -653,11 +606,7 @@ static NSTimeInterval time_last_frame; // // shoot 'd' // Dump Cargo // -#if OOLITE_HAVE_JOYSTICK if (([gameView isDown:key_dump_cargo] || joyButtonState[BUTTON_JETTISON])&&([cargo count] > 0)) -#else - if ([gameView isDown:key_dump_cargo] && ([cargo count] > 0)) -#endif { if ([self dumpCargo] != CARGO_NOT_CARGO) { @@ -679,11 +628,7 @@ static NSTimeInterval time_last_frame; // // autopilot 'c' // -#if OOLITE_HAVE_JOYSTICK if ([gameView isDown:key_autopilot] || joyButtonState[BUTTON_DOCKCPU]) // look for the 'c' key -#else - if ([gameView isDown:key_autopilot]) // look for the 'c' key -#endif { if (has_docking_computer && (!autopilot_key_pressed)) // look for the 'c' key { @@ -787,11 +732,7 @@ static NSTimeInterval time_last_frame; // // autopilot 'D' // -#if OOLITE_HAVE_JOYSTICK if ([gameView isDown:key_autodock] || joyButtonState[BUTTON_DOCKCPUFAST]) // look for the 'D' key -#else - if ([gameView isDown:key_autodock]) // look for the 'D' key -#endif { if (has_docking_computer && (!fast_autopilot_key_pressed)) // look for the 'D' key { @@ -839,11 +780,7 @@ static NSTimeInterval time_last_frame; // // hyperspace 'h' // -#if OOLITE_HAVE_JOYSTICK if ([gameView isDown:key_hyperspace] || joyButtonState[BUTTON_HYPERDRIVE]) // look for the 'h' key -#else - if ([gameView isDown:key_hyperspace]) // look for the 'h' key -#endif { if (!hyperspace_pressed) { @@ -910,11 +847,7 @@ static NSTimeInterval time_last_frame; // // Galactic hyperspace 'g' // -#if OOLITE_HAVE_JOYSTICK if (([gameView isDown:key_galactic_hyperspace] || joyButtonState[BUTTON_GALACTICDRIVE])&&(has_galactic_hyperdrive))// look for the 'g' key -#else - if ([gameView isDown:key_galactic_hyperspace] &&(has_galactic_hyperdrive))// look for the 'g' key -#endif { if (!galhyperspace_pressed) { @@ -960,11 +893,7 @@ static NSTimeInterval time_last_frame; // // shoot '0' // Cloaking Device // -#if OOLITE_HAVE_JOYSTICK if (([gameView isDown:key_cloaking_device] || joyButtonState[BUTTON_CLOAK]) && has_cloaking_device) -#else - if ([gameView isDown:key_cloaking_device] && has_cloaking_device) -#endif { if (!cloak_pressed) { diff --git a/src/Core/OOQuaternion.m b/src/Core/OOQuaternion.m index 29fda77f..fb77ea41 100644 --- a/src/Core/OOQuaternion.m +++ b/src/Core/OOQuaternion.m @@ -310,5 +310,16 @@ void quaternion_rotate_about_axis(Quaternion *quat, Vector axis, GLfloat angle) NSString *QuaternionDescription(Quaternion quaternion) { - return [NSString stringWithFormat:@"(%g + %gi + %gj + %gk)", quaternion.w, quaternion.x, quaternion.y, quaternion.z]; + float x, y, z; + char xs, ys, zs; + + x = fabsf(quaternion.x); + y = fabsf(quaternion.y); + z = fabsf(quaternion.z); + + xs = (x == quaternion.x) ? '+' : '-'; + ys = (y == quaternion.y) ? '+' : '-'; + zs = (z == quaternion.z) ? '+' : '-'; + + return [NSString stringWithFormat:@"(%g %c %gi %c %gj %c %gk)", quaternion.w, xs, x, ys, y, zs, z]; }