reduce the number of keywords used and switch to BMP format for screenshots
authorkoda
Thu, 22 Jul 2010 12:47:32 +0200
changeset 3663 8c28abf427f5
parent 3662 a44406f4369b
child 3664 f5bdf26c843e
reduce the number of keywords used and switch to BMP format for screenshots fixed a few little things from previous commit
hedgewars/CCHandlers.inc
hedgewars/SDLh.pas
hedgewars/hwengine.pas
hedgewars/uGame.pas
hedgewars/uKeys.pas
hedgewars/uMisc.pas
hedgewars/uStore.pas
hedgewars/uTeams.pas
hedgewars/uWorld.pas
project_files/HedgewarsMobile/Classes/FortsViewController.m
project_files/HedgewarsMobile/Classes/GeneralSettingsViewController.m
project_files/HedgewarsMobile/Classes/SDL_uikitappdelegate.m
project_files/HedgewarsMobile/Hedgewars_Prefix.pch
--- a/hedgewars/CCHandlers.inc	Thu Jul 22 03:08:17 2010 +0200
+++ b/hedgewars/CCHandlers.inc	Thu Jul 22 12:47:32 2010 +0200
@@ -439,10 +439,6 @@
     Message:= Message or gm_Switch
 end;
 
-{$IFDEF IPHONEOS}
-procedure clearView; cdecl; external;
-{$ENDIF}
-
 procedure chNextTurn(var s: shortstring);
 begin
     s:= s; // avoid compiler hint
--- a/hedgewars/SDLh.pas	Thu Jul 22 03:08:17 2010 +0200
+++ b/hedgewars/SDLh.pas	Thu Jul 22 12:47:32 2010 +0200
@@ -840,6 +840,13 @@
 procedure SDLNet_Write32(value: LongWord; buf: pointer);
 function  SDLNet_Read16(buf: pointer): Word;
 function  SDLNet_Read32(buf: pointer): LongWord;
+
+{$IFDEF IPHONEOS}
+(*  iPhone related calls  *)
+procedure clearView; cdecl; external;
+procedure startSpinning; cdecl; external;
+procedure stopSpinning; cdecl; external;
+{$ENDIF}
 implementation
 
 function SDL_MustLock(Surface: PSDL_Surface): Boolean;
--- a/hedgewars/hwengine.pas	Thu Jul 22 03:08:17 2010 +0200
+++ b/hedgewars/hwengine.pas	Thu Jul 22 12:47:32 2010 +0200
@@ -49,9 +49,7 @@
 
 ////////////////////////////////
 procedure DoTimer(Lag: LongInt);
-{$IFNDEF IPHONEOS}
 var s: shortstring;
-{$ENDIF}
 begin
     if not isPaused then inc(RealTicks, Lag);
 
@@ -108,7 +106,6 @@
 {$ELSE}
     SDL_GL_SwapBuffers();
 {$ENDIF}
-{$IFNDEF IPHONEOS}
     // not going to make captures on the iPhone
     if flagMakeCapture then
     begin
@@ -118,7 +115,6 @@
         MakeScreenshot(s);
         //SDL_SaveBMP_RW(SDLPrimSurface, SDL_RWFromFile(Str2PChar(s), 'wb'), 1)
     end;
-{$ENDIF}
 end;
 
 ////////////////////
@@ -157,6 +153,8 @@
                     KeyPressChat(event.key.keysym.sym);
 {$ELSE}
                     KeyPressChat(event.key.keysym.unicode);
+                SDL_MOUSEBUTTONDOWN: if event.button.button = SDL_BUTTON_WHEELDOWN then uKeys.wheelDown:= true;
+                SDL_MOUSEBUTTONUP: if event.button.button = SDL_BUTTON_WHEELUP then uKeys.wheelUp:= true;
 {$ENDIF}
 {$IFDEF SDL13}
                 SDL_WINDOWEVENT:
@@ -167,10 +165,6 @@
                     if (event.active.state and SDL_APPINPUTFOCUS) <> 0 then
                         cHasFocus:= event.active.gain = 1;
 {$ENDIF}
-{$IFNDEF IPHONEOS}
-                SDL_MOUSEBUTTONDOWN: if event.button.button = SDL_BUTTON_WHEELDOWN then uKeys.wheelDown:= true;
-                SDL_MOUSEBUTTONUP: if event.button.button = SDL_BUTTON_WHEELUP then uKeys.wheelUp:= true;
-{$ENDIF}
                 SDL_JOYAXISMOTION: ControllerAxisEvent(event.jaxis.which, event.jaxis.axis, event.jaxis.value);
                 SDL_JOYHATMOTION: ControllerHatEvent(event.jhat.which, event.jhat.hat, event.jhat.value);
                 SDL_JOYBUTTONDOWN: ControllerButtonEvent(event.jbutton.which, event.jbutton.button, true);
--- a/hedgewars/uGame.pas	Thu Jul 22 03:08:17 2010 +0200
+++ b/hedgewars/uGame.pas	Thu Jul 22 12:47:32 2010 +0200
@@ -62,9 +62,7 @@
                         end;
                gmtSave: begin
                         RestoreTeamsFromSave;
-{$IFNDEF IPHONEOS}
                         SetBinds(CurrentTeam^.Binds);
-{$ENDIF}
                         //CurrentHedgehog^.Gear^.Message:= 0; <- produces bugs with further save restoring and demos
                         isSoundEnabled:= isSEBackup;
                         GameType:= gmtLocal
--- a/hedgewars/uKeys.pas	Thu Jul 22 03:08:17 2010 +0200
+++ b/hedgewars/uKeys.pas	Thu Jul 22 12:47:32 2010 +0200
@@ -354,7 +354,11 @@
 
 procedure SetBinds(var binds: TBinds);
 begin
+{$IFDEF IPHONEOS}
+    CurrentBinds:= DefaultBinds;
+{$ELSE}
     CurrentBinds:= binds;
+{$ENDIF}
 end;
 
 procedure SetDefaultBinds;
@@ -408,13 +412,13 @@
 procedure ControllerInit;
 var i, j: Integer;
 begin
-{$IFNDEF IPHONEOS}
-SDL_InitSubSystem(SDL_INIT_JOYSTICK);
+ControllerEnabled:= 0;
+{$IFDEF IPHONEOS}
+exit; // joystick subsystem disabled on iPhone
 {$ENDIF}
 
-ControllerEnabled:= 0;
+SDL_InitSubSystem(SDL_INIT_JOYSTICK);
 ControllerNumControllers:= SDL_NumJoysticks();
-
 if ControllerNumControllers > 6 then ControllerNumControllers:= 6;
 
 WriteLnToConsole('Number of game controllers: ' + inttostr(ControllerNumControllers));
--- a/hedgewars/uMisc.pas	Thu Jul 22 03:08:17 2010 +0200
+++ b/hedgewars/uMisc.pas	Thu Jul 22 12:47:32 2010 +0200
@@ -177,9 +177,7 @@
 procedure AddFileLog(s: shortstring);
 function  RectToStr(Rect: TSDL_Rect): shortstring;
 {$ENDIF}
-{$IFNDEF IPHONEOS}
 procedure MakeScreenshot(filename: shortstring);
-{$ENDIF}
 
 implementation
 uses uConsole, uStore, uIO, uSound, typinfo, sysutils;
@@ -560,15 +558,10 @@
 byte(DecodeBase64[0]):= t - 1
 end;
 
-{$IFNDEF IPHONEOS}
 procedure MakeScreenshot(filename: shortstring);
 var p: Pointer;
     size: Longword;
     f: file;
-{$IFNDEF WIN32}
-    // TGA Header
-    head: array[0..8] of Word = (0, 2, 0, 0, 0, 0, 0, 0, 24);
-{$ELSE}
     // Windows Bitmap Header
     head: array[0..53] of Byte = (
     $42, $4D, // identifier ("BM")
@@ -587,7 +580,6 @@
     0, 0, 0, 0, // number of colors (all)
     0, 0, 0, 0 // number of important colors
     );
-{$ENDIF}
 begin
 playSound(sndShutter);
 
@@ -600,12 +592,7 @@
 p:= GetMem(size);
 
 // update header information and file name
-{$IFNDEF WIN32}
-filename:= ParamStr(1) + '/Screenshots/' + filename + '.tga';
 
-head[6]:= cScreenWidth;
-head[7]:= cScreenHeight;
-{$ELSE}
 filename:= ParamStr(1) + '/Screenshots/' + filename + '.bmp';
 
 head[$02]:= (size + 54) and $ff;
@@ -624,10 +611,9 @@
 head[$23]:= (size shr 8) and $ff;
 head[$24]:= (size shr 16) and $ff;
 head[$25]:= (size shr 24) and $ff;
-{$ENDIF}
 
 //remember that opengles operates on a single surface, so GL_FRONT *should* be implied
-glReadBuffer(GL_FRONT);
+//glReadBuffer(GL_FRONT);
 glReadPixels(0, 0, cScreenWidth, cScreenHeight, GL_BGR, GL_UNSIGNED_BYTE, p);
 
 {$I-}
@@ -643,7 +629,6 @@
 
 FreeMem(p)
 end;
-{$ENDIF}
 
 {$IFDEF DEBUGFILE}
 procedure AddFileLog(s: shortstring);
--- a/hedgewars/uStore.pas	Thu Jul 22 03:08:17 2010 +0200
+++ b/hedgewars/uStore.pas	Thu Jul 22 12:47:32 2010 +0200
@@ -1235,10 +1235,6 @@
 end;
 
 ////////////////////////////////////////////////////////////////////////////////
-{$IFDEF IPHONEOS}
-procedure startSpinning; cdecl; external;
-procedure stopSpinning; cdecl; external;
-{$ENDIF}
 procedure AddProgress;
 var r: TSDL_Rect;
     texsurf: PSDL_Surface;
--- a/hedgewars/uTeams.pas	Thu Jul 22 03:08:17 2010 +0200
+++ b/hedgewars/uTeams.pas	Thu Jul 22 12:47:32 2010 +0200
@@ -268,9 +268,7 @@
 {$IFDEF DEBUGFILE}AddFileLog('Wind = '+FloatToStr(cWindSpeed));{$ENDIF}
 ApplyAmmoChanges(CurrentHedgehog^);
 
-{$IFNDEF IPHONEOS}
 if not CurrentTeam^.ExtDriven then SetBinds(CurrentTeam^.Binds);
-{$ENDIF}
 
 bShowFinger:= true;
 
--- a/hedgewars/uWorld.pas	Thu Jul 22 03:08:17 2010 +0200
+++ b/hedgewars/uWorld.pas	Thu Jul 22 12:47:32 2010 +0200
@@ -379,11 +379,10 @@
     end
 else
     FreeWeaponTooltip;
+if (WeaponTooltipTex <> nil) and (AMxShift = 0) then
 {$IFDEF IPHONEOS}
-if (WeaponTooltipTex <> nil) and (AMxShift = 0) then
     ShowWeaponTooltip(x - WeaponTooltipTex^.w - 3, AMyOffset - 1);
 {$ELSE}
-if (WeaponTooltipTex <> nil) and (AMxShift = 0) then
     ShowWeaponTooltip(x - WeaponTooltipTex^.w - 3, min(y + 1, cScreenHeight - WeaponTooltipTex^.h - 40));
 {$ENDIF}
 
--- a/project_files/HedgewarsMobile/Classes/FortsViewController.m	Thu Jul 22 03:08:17 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/FortsViewController.m	Thu Jul 22 12:47:32 2010 +0200
@@ -150,7 +150,7 @@
 }
 
 
--(void) ealloc {
+-(void) dealloc {
     [teamDictionary release];
     [lastIndexPath release];
     [fortArray release];
--- a/project_files/HedgewarsMobile/Classes/GeneralSettingsViewController.m	Thu Jul 22 03:08:17 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/GeneralSettingsViewController.m	Thu Jul 22 12:47:32 2010 +0200
@@ -21,15 +21,15 @@
 #pragma mark View Lifecycle
 -(void) viewDidLoad {
     [super viewDidLoad];
-    
-    NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] initWithContentsOfFile:SETTINGS_FILE()];
-    self.settingsDictionary = dictionary;
-    [dictionary release];
 }
 
 -(void) viewWillAppear:(BOOL)animated {
     [self.tableView setContentOffset:CGPointMake(0,0) animated:NO];
     
+    NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] initWithContentsOfFile:SETTINGS_FILE()];
+    self.settingsDictionary = dictionary;
+    [dictionary release];
+
     [super viewWillAppear:animated];
 }
 
--- a/project_files/HedgewarsMobile/Classes/SDL_uikitappdelegate.m	Thu Jul 22 03:08:17 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/SDL_uikitappdelegate.m	Thu Jul 22 12:47:32 2010 +0200
@@ -140,8 +140,7 @@
 }
 
 -(void) applicationDidReceiveMemoryWarning:(UIApplication *)application {
-    //if (self.mainViewController.view.superview == nil)
-    //     self.mainViewController = nil;
+    // don't clean mainMenuViewController here!!!
     MSG_MEMCLEAN();
     print_free_memory();
 }
--- a/project_files/HedgewarsMobile/Hedgewars_Prefix.pch	Thu Jul 22 03:08:17 2010 +0200
+++ b/project_files/HedgewarsMobile/Hedgewars_Prefix.pch	Thu Jul 22 12:47:32 2010 +0200
@@ -22,6 +22,13 @@
  
 #define ZAssert(condition, ...) do { if (!(condition)) { ALog(__VA_ARGS__); }} while(0)
 
+// by http://blog.coriolis.ch/2009/01/05/macros-for-xcode/
+#define START_TIMER NSTimeInterval start = [NSDate timeIntervalSinceReferenceDate];
+#define END_TIMER(msg) 	NSTimeInterval stop = [NSDate timeIntervalSinceReferenceDate]; CMLog([NSString stringWithFormat:@"%@ Time = %f", msg, stop-start]);
+
+#define releaseAndNil(x) [x release], x = nil;
+
+
 #if !__IPHONE_3_2
 typedef enum {
     UIUserInterfaceIdiomPhone,           // iPhone and iPod touch style UI