Merge with ios-rus-localization ios-revival
authorantonc27 <antonc27@mail.ru>
Sat, 15 Aug 2015 20:49:06 +0200
branchios-revival
changeset 11134 41cfa8edf02f
parent 11133 fa3d227fb308 (diff)
parent 11131 29d0a5c04b3b (current diff)
child 11135 b34c0e2b546a
Merge with ios-rus-localization
--- a/hedgewars/hwLibrary.pas	Sat Aug 15 17:08:50 2015 +0200
+++ b/hedgewars/hwLibrary.pas	Sat Aug 15 20:49:06 2015 +0200
@@ -120,9 +120,6 @@
 {$ELSE}
 exports
     RunEngine,
-{$IFDEF MOBILE}
-    GenLandPreview,
-{$ENDIF}
     LoadLocaleWrapper,
     HW_versionInfo,
     HW_versionString,
--- a/hedgewars/hwengine.pas	Sat Aug 15 17:08:50 2015 +0200
+++ b/hedgewars/hwengine.pas	Sat Aug 15 20:49:06 2015 +0200
@@ -44,9 +44,6 @@
 procedure preInitEverything();
 procedure initEverything(complete:boolean);
 procedure freeEverything(complete:boolean);
-{$IFDEF MOBILE}
-procedure GenLandPreview; cdecl; export;
-{$ENDIF MOBILE}
 
 implementation
 {$ELSE}
@@ -543,8 +540,12 @@
 end;
 
 ///////////////////////////////////////////////////////////////////////////////
-procedure GenLandPreview;{$IFDEF MOBILE} cdecl; export;{$ENDIF MOBILE}
+procedure GenLandPreview;
+{$IFDEF MOBILE}
+var Preview: TPreview;
+{$ELSE}
 var Preview: TPreviewAlpha;
+{$ENDIF MOBILE}
 begin
     initEverything(false);
 
@@ -553,7 +554,11 @@
     TryDo(InitStepsFlags = cifRandomize, 'Some parameters not set (flags = ' + inttostr(InitStepsFlags) + ')', true);
 
     ScriptOnPreviewInit;
+{$IFDEF MOBILE}
+    GenPreview(Preview);
+{$ELSE}
     GenPreviewAlpha(Preview);
+{$ENDIF MOBILE}
     WriteLnToConsole('Sending preview...');
     SendIPCRaw(@Preview, sizeof(Preview));
     SendIPCRaw(@MaxHedgehogs, sizeof(byte));
--- a/project_files/HedgewarsMobile/Classes/GameConfigViewController.m	Sat Aug 15 17:08:50 2015 +0200
+++ b/project_files/HedgewarsMobile/Classes/GameConfigViewController.m	Sat Aug 15 20:49:06 2015 +0200
@@ -325,7 +325,7 @@
     if (IS_IPAD() == NO)
         return;
 
-    [self updateUIForInterfaceOrientation:toInterfaceOrientation];
+    [self updateiPadUIForInterfaceOrientation:toInterfaceOrientation];
 
     [self.schemeWeaponConfigViewController willAnimateRotationToInterfaceOrientation:toInterfaceOrientation
                                                                             duration:duration];
@@ -335,7 +335,7 @@
     }
 }
 
-- (void)updateUIForInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
+- (void)updateiPadUIForInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
 {
     if ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
          interfaceOrientation == UIInterfaceOrientationLandscapeRight)) {
@@ -363,9 +363,12 @@
 //    if (IS_IPAD())
 //        [NSThread detachNewThreadSelector:@selector(loadNiceHogs) toTarget:self withObject:nil];
     
-    // we assume here what 'statusBarOrientation' will never be changed manually!
-    UIInterfaceOrientation currentOrientation = [[UIApplication sharedApplication] statusBarOrientation];
-    [self updateUIForInterfaceOrientation:currentOrientation];
+    if (IS_IPAD())
+    {
+        // we assume here what 'statusBarOrientation' will never be changed manually!
+        UIInterfaceOrientation currentOrientation = [[UIApplication sharedApplication] statusBarOrientation];
+        [self updateiPadUIForInterfaceOrientation:currentOrientation];
+    }
     
     [self.mapConfigViewController viewWillAppear:animated];
     [self.teamConfigViewController viewWillAppear:animated];
--- a/project_files/HedgewarsMobile/Classes/MapPreviewButtonView.m	Sat Aug 15 17:08:50 2015 +0200
+++ b/project_files/HedgewarsMobile/Classes/MapPreviewButtonView.m	Sat Aug 15 20:49:06 2015 +0200
@@ -83,11 +83,33 @@
         serverQuit = YES;
     }
 
-    // launch the preview here so that we're sure the tcp channel is open
-    pthread_t thread_id;
-    pthread_create(&thread_id, NULL, (void *(*)(void *))GenLandPreview, (void *)port);
-    pthread_detach(thread_id);
-
+    // launch the preview in background here so that we're sure the tcp channel is open
+    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), ^{
+        NSString *ipcString = [[NSString alloc] initWithFormat:@"%d", port];
+        NSString *documentsDirectory = DOCUMENTS_FOLDER();
+        
+        NSMutableArray *gameParameters = [[NSMutableArray alloc] initWithObjects:
+                                          @"--internal",
+                                          @"--port", ipcString,
+                                          @"--user-prefix", documentsDirectory,
+                                          @"--landpreview",
+                                          nil];
+        [ipcString release];
+        
+        int argc = [gameParameters count];
+        const char **argv = (const char **)malloc(sizeof(const char*)*argc);
+        for (int i = 0; i < argc; i++)
+            argv[i] = strdup([[gameParameters objectAtIndex:i] UTF8String]);
+        [gameParameters release];
+        
+        RunEngine(argc, argv);
+        
+        // cleanup
+        for (int i = 0; i < argc; i++)
+            free((void *)argv[i]);
+        free(argv);
+    });
+    
     DLog(@"Waiting for a client on port %d", port);
     while (!serverQuit) {
         /* This check the sd if there is a pending connection.
@@ -135,7 +157,7 @@
 
     // http://developer.apple.com/mac/library/qa/qa2001/qa1037.html
     CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceGray();
-    CGContextRef bitmapImage = CGBitmapContextCreate(unpackedMap, 256, 128, 8, 256, colorspace, kCGImageAlphaNone);
+    CGContextRef bitmapImage = CGBitmapContextCreate(unpackedMap, 256, 128, 8, 256, colorspace, (CGBitmapInfo)kCGImageAlphaNone);
     CGColorSpaceRelease(colorspace);
 
     CGImageRef previewCGImage = CGBitmapContextCreateImage(bitmapImage);
--- a/project_files/HedgewarsMobile/Classes/PascalImports.h	Sat Aug 15 17:08:50 2015 +0200
+++ b/project_files/HedgewarsMobile/Classes/PascalImports.h	Sat Aug 15 20:49:06 2015 +0200
@@ -29,7 +29,6 @@
      */
 
     void RunEngine(const int argc, const char *argv[]);
-    void GenLandPreview(void);
     void LoadLocaleWrapper(const char *filename);
 
     void HW_versionInfo(int *protoNum, char **versionStr);