ios: this should prevent at least one of the crashes zorg spotted; also added some callbacks in SDLh; also polished project file (from -O2 to -Os)
authorkoda
Mon, 01 Aug 2011 00:48:38 +0200
changeset 5486 e75f7c3c6275
parent 5485 e943a005d0e8
child 5487 900b3fe02546
ios: this should prevent at least one of the crashes zorg spotted; also added some callbacks in SDLh; also polished project file (from -O2 to -Os)
hedgewars/SDLh.pas
project_files/HedgewarsMobile/Classes/Appirater.h
project_files/HedgewarsMobile/Classes/CommodityFunctions.m
project_files/HedgewarsMobile/Classes/MainMenuViewController.m
project_files/HedgewarsMobile/Hedgewars.xcodeproj/project.pbxproj
--- a/hedgewars/SDLh.pas	Sun Jul 31 12:07:44 2011 -0400
+++ b/hedgewars/SDLh.pas	Mon Aug 01 00:48:38 2011 +0200
@@ -287,6 +287,7 @@
     PSDL_Window   = Pointer;
     PSDL_Renderer = Pointer;
     PSDL_Texture  = Pointer;
+    PSDL_GLContext= Pointer;
 {$ENDIF}
 
     PSDL_Rect = ^TSDL_Rect;
@@ -765,11 +766,16 @@
 {$IFDEF SDL13}
 function  SDL_CreateWindow(title: PChar; x,y,w,h, flags: LongInt): PSDL_Window; cdecl; external SDLLibName;
 function  SDL_CreateRenderer(window: PSDL_Window; index, flags: LongInt): PSDL_Renderer; cdecl; external SDLLibName;
+function  SDL_DestroyWindow(window: PSDL_Window): LongInt; cdecl; external SDLLibName;
 function  SDL_DestroyRenderer(renderer: PSDL_Renderer): LongInt; cdecl; external SDLLibName;
-function  SDL_DestroyWindow(window: PSDL_Window): LongInt; cdecl; external SDLLibName;
+
+function  SDL_GL_CreateContext(window: PSDL_Window): PSDL_GLContext; cdecl; external SDLLibName;
+procedure SDL_GL_DeleteContext(context: PSDL_GLContext); cdecl; external SDLLibName;
+function  SDL_GL_SwapWindow(window: PSDL_Window): LongInt; cdecl; external SDLLibName;
 
 procedure SDL_VideoQuit; cdecl; external SDLLibName;
 function  SDL_GetNumVideoDisplays: LongInt; cdecl; external SDLLibName;
+procedure SDL_ShowWindow(window: PSDL_Window); cdecl; external SDLLibName;
 
 function  SDL_SetRenderDrawColor(renderer: PSDL_Renderer; r,g,b,a: byte): LongInt; cdecl; external SDLLibName;
 function  SDL_GetRenderer(window: PSDL_Window): PSDL_Renderer; cdecl; external SDLLibName;
--- a/project_files/HedgewarsMobile/Classes/Appirater.h	Sun Jul 31 12:07:44 2011 -0400
+++ b/project_files/HedgewarsMobile/Classes/Appirater.h	Mon Aug 01 00:48:38 2011 +0200
@@ -45,7 +45,7 @@
 /*
  Place your Apple generated software id here.
  */
-#define APPIRATER_APP_ID                 391234866
+#define APPIRATER_APP_ID                391234866
 
 /*
  Your app's name.
@@ -82,13 +82,13 @@
  Users will need to have the same version of your app installed for this many
  days before they will be prompted to rate it.
  */
-#define DAYS_UNTIL_PROMPT               5       // double
+#define DAYS_UNTIL_PROMPT               3       // double
 
 /*
  Users will need to launch the same version of the app this many times before
  they will be prompted to rate it.
  */
-#define LAUNCHES_UNTIL_PROMPT           10      // integer
+#define LAUNCHES_UNTIL_PROMPT           5      // integer
 
 /*
  'YES' will show the Appirater alert everytime. Useful for testing how your message
--- a/project_files/HedgewarsMobile/Classes/CommodityFunctions.m	Sun Jul 31 12:07:44 2011 -0400
+++ b/project_files/HedgewarsMobile/Classes/CommodityFunctions.m	Mon Aug 01 00:48:38 2011 +0200
@@ -41,6 +41,7 @@
 
 // by http://landonf.bikemonkey.org/code/iphone/Determining_Available_Memory.20081203.html
 void print_free_memory () {
+#ifdef DEBUG
     mach_port_t host_port;
     mach_msg_type_number_t host_size;
     vm_size_t pagesize;
@@ -59,6 +60,7 @@
     natural_t mem_free = vm_stat.free_count * pagesize;
     natural_t mem_total = mem_used + mem_free;
     DLog(@"used: %u free: %u total: %u", mem_used, mem_free, mem_total);
+#endif
 }
 
 BOOL inline isApplePhone () {
--- a/project_files/HedgewarsMobile/Classes/MainMenuViewController.m	Sun Jul 31 12:07:44 2011 -0400
+++ b/project_files/HedgewarsMobile/Classes/MainMenuViewController.m	Mon Aug 01 00:48:38 2011 +0200
@@ -102,26 +102,31 @@
     NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
     NSString *trackingVersion = [userDefaults stringForKey:@"HedgeVersion"];
 
+    if ([[userDefaults objectForKey:@"music"] boolValue])
+        [HedgewarsAppDelegate playBackgroundMusic];
+
     if (trackingVersion == nil || [trackingVersion isEqualToString:version] == NO) {
+        // remove any reminder of previous games as saves are going to be wiped out
+        [userDefaults setObject:@"" forKey:@"savedGamePath"];
+        // update the tracking version with the new one
         [userDefaults setObject:version forKey:@"HedgeVersion"];
+
         [userDefaults synchronize];
         [self createNecessaryFiles];
     }
 
-    if ([[userDefaults objectForKey:@"music"] boolValue])
-        [HedgewarsAppDelegate playBackgroundMusic];
-
-    NSString *saveString = [[NSUserDefaults standardUserDefaults] objectForKey:@"savedGamePath"];
+    // prompt for restoring any previous game
+    NSString *saveString = [userDefaults objectForKey:@"savedGamePath"];
     if (saveString != nil && [saveString isEqualToString:@""] == NO) {
         if (self.restoreViewController == nil) {
-            NSString *xibName = [@"RestoreViewController-" stringByAppendingString:(IS_IPAD() ? @"iPad" : @"iPhone")]; 
+            NSString *xibName = [@"RestoreViewController-" stringByAppendingString:(IS_IPAD() ? @"iPad" : @"iPhone")];
             RestoreViewController *restored = [[RestoreViewController alloc] initWithNibName:xibName bundle:nil];
             if ([restored respondsToSelector:@selector(setModalPresentationStyle:)])
                 restored.modalPresentationStyle = UIModalPresentationFormSheet;
             self.restoreViewController = restored;
             [restored release];
         }
-        [self performSelector:@selector(presentModalViewController:animated:) withObject:self.restoreViewController afterDelay:0.35];
+        [self performSelector:@selector(presentModalViewController:animated:) withObject:self.restoreViewController afterDelay:0.3];
     } else {
         // let's not prompt for rating when app crashed >_>
         [Appirater appLaunched];
@@ -152,11 +157,8 @@
     switch (button.tag) {
         case 0:
             if (nil == self.gameConfigViewController) {
-                if (IS_IPAD())
-                    xib = nil;
-                else
-                    xib = @"GameConfigViewController";
-                
+                xib = IS_IPAD() ? nil : @"GameConfigViewController";
+
                 GameConfigViewController *gcvc = [[GameConfigViewController alloc] initWithNibName:xib bundle:nil];
                 gcvc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
                 self.gameConfigViewController = gcvc;
@@ -177,7 +179,10 @@
             break;
         case 3:
 #ifdef DEBUG
-            debugStr = [[NSString alloc] initWithContentsOfFile:DEBUG_FILE()];
+            if ([[NSFileManager defaultManager] fileExistsAtPath:DEBUG_FILE()])
+                debugStr = [[NSString alloc] initWithContentsOfFile:DEBUG_FILE()];
+            else
+                debugStr = [[NSString alloc] initWithString:@"Here be log"];
             UITextView *scroll = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.height, self.view.frame.size.width)];
             scroll.text = debugStr;
             [debugStr release];
@@ -191,6 +196,7 @@
             [self.view addSubview:scroll];
             [scroll release];
 #else
+            debugStr = debugStr; // prevent compiler warning
             if (nil == self.aboutViewController) {
                 AboutViewController *about = [[AboutViewController alloc] initWithNibName:@"AboutViewController" bundle:nil];
                 about.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
--- a/project_files/HedgewarsMobile/Hedgewars.xcodeproj/project.pbxproj	Sun Jul 31 12:07:44 2011 -0400
+++ b/project_files/HedgewarsMobile/Hedgewars.xcodeproj/project.pbxproj	Mon Aug 01 00:48:38 2011 +0200
@@ -1584,7 +1584,7 @@
 				GCC_C_LANGUAGE_STANDARD = c99;
 				GCC_DEBUGGING_SYMBOLS = default;
 				GCC_FAST_MATH = YES;
-				GCC_OPTIMIZATION_LEVEL = 2;
+				GCC_OPTIMIZATION_LEVEL = s;
 				GCC_PREPROCESSOR_DEFINITIONS = "";
 				GCC_STRICT_ALIASING = YES;
 				GCC_THUMB_SUPPORT = NO;
@@ -1599,6 +1599,7 @@
 					"\"$(SRCROOT)/../../../Library/SDL_mixer/\"",
 				);
 				IPHONEOS_DEPLOYMENT_TARGET = 3.1;
+				LLVM_LTO = YES;
 				ONLY_ACTIVE_ARCH = NO;
 				OTHER_CODE_SIGN_FLAGS = "";
 				OTHER_LDFLAGS = (
@@ -1674,12 +1675,12 @@
 				FPC_COMPILER_BINARY_DIR = /usr/local/lib/fpc/2.5.1;
 				FPC_MAIN_FILE = "$(PROJECT_DIR)/../../hedgewars/hwLibrary.pas";
 				FPC_RTL_UNITS_BASE = /usr/local/lib/fpc;
-				FPC_SPECIFIC_OPTIONS = "-dDEBUGFILE -Ci- -Cr- -Co- -O-2 -Xs  -Cfvfpv2";
+				FPC_SPECIFIC_OPTIONS = "-dDEBUGFILE -O- -g -gl -gw2 -gt -ghttt -Xs- -Cfvfpv2";
 				FPC_UNITS_PATH = "-Fu\"$(PROJECT_DIR)\"";
 				GCC_C_LANGUAGE_STANDARD = c99;
-				GCC_DEBUGGING_SYMBOLS = default;
+				GCC_DEBUGGING_SYMBOLS = full;
 				GCC_FAST_MATH = YES;
-				GCC_OPTIMIZATION_LEVEL = 2;
+				GCC_OPTIMIZATION_LEVEL = 0;
 				GCC_PREPROCESSOR_DEFINITIONS = DEBUG;
 				GCC_STRICT_ALIASING = YES;
 				GCC_THUMB_SUPPORT = NO;
@@ -1816,7 +1817,7 @@
 				FPC_UNITS_PATH = "-Fu\"$(PROJECT_DIR)\"";
 				GCC_C_LANGUAGE_STANDARD = c99;
 				GCC_DEBUGGING_SYMBOLS = full;
-				GCC_FAST_MATH = NO;
+				GCC_FAST_MATH = YES;
 				GCC_OPTIMIZATION_LEVEL = 0;
 				GCC_PREPROCESSOR_DEFINITIONS = DEBUG;
 				GCC_STRICT_ALIASING = YES;
@@ -1863,7 +1864,7 @@
 				GCC_C_LANGUAGE_STANDARD = c99;
 				GCC_DEBUGGING_SYMBOLS = default;
 				GCC_FAST_MATH = YES;
-				GCC_OPTIMIZATION_LEVEL = 2;
+				GCC_OPTIMIZATION_LEVEL = s;
 				GCC_PREPROCESSOR_DEFINITIONS = DEBUG;
 				GCC_STRICT_ALIASING = YES;
 				GCC_THUMB_SUPPORT = NO;
@@ -1878,6 +1879,7 @@
 					"\"$(SRCROOT)/../../../Library/SDL_mixer/\"",
 				);
 				IPHONEOS_DEPLOYMENT_TARGET = 3.1;
+				LLVM_LTO = YES;
 				ONLY_ACTIVE_ARCH = NO;
 				OTHER_LDFLAGS = (
 					"-lz",