- Fix for retrieving 'Maze' preview genration
Note: We use now GCD instead of pthread for launch preview generation from engine side (it is now done with RunEngine, not direct call to GenLandPreview)
Note 2: For a moment LandPreview without Alpha used
--- a/hedgewars/hwLibrary.pas Sat Aug 15 20:38:07 2015 +0200
+++ b/hedgewars/hwLibrary.pas Sat Aug 15 20:48:13 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 20:38:07 2015 +0200
+++ b/hedgewars/hwengine.pas Sat Aug 15 20:48:13 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/MapPreviewButtonView.m Sat Aug 15 20:38:07 2015 +0200
+++ b/project_files/HedgewarsMobile/Classes/MapPreviewButtonView.m Sat Aug 15 20:48:13 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 20:38:07 2015 +0200
+++ b/project_files/HedgewarsMobile/Classes/PascalImports.h Sat Aug 15 20:48:13 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);