project_files/HedgewarsMobile/Classes/MapPreviewButtonView.m
branchios-revival
changeset 11148 064a53861759
parent 11138 05853b1df2a2
child 11240 57891137ffef
equal deleted inserted replaced
11147:f9c460720e02 11148:064a53861759
    23 
    23 
    24 
    24 
    25 #define INDICATOR_TAG 7654
    25 #define INDICATOR_TAG 7654
    26 
    26 
    27 @interface MapPreviewButtonView ()
    27 @interface MapPreviewButtonView ()
    28 @property (nonatomic) int port;
    28 @property (nonatomic) NSInteger port;
    29 @end
    29 @end
    30 
    30 
    31 @implementation MapPreviewButtonView
    31 @implementation MapPreviewButtonView
    32 @synthesize delegate;
    32 @synthesize delegate;
    33 
    33 
    81         serverQuit = YES;
    81         serverQuit = YES;
    82     }
    82     }
    83 
    83 
    84     // Open a connection with the IP provided (listen on the host's port)
    84     // Open a connection with the IP provided (listen on the host's port)
    85     if (!(sd = SDLNet_TCP_Open(&ip))) {
    85     if (!(sd = SDLNet_TCP_Open(&ip))) {
    86         DLog(@"SDLNet_TCP_Open: %s %d\n", SDLNet_GetError(), self.port);
    86         DLog(@"SDLNet_TCP_Open: %s %ld\n", SDLNet_GetError(), (long)self.port);
    87         serverQuit = YES;
    87         serverQuit = YES;
    88     }
    88     }
    89 
    89 
    90     // launch the preview in background here so that we're sure the tcp channel is open
    90     // launch the preview in background here so that we're sure the tcp channel is open
    91     dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), ^{
    91     dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), ^{
    92         NSString *ipcString = [[NSString alloc] initWithFormat:@"%d", self.port];
    92         NSString *ipcString = [[NSString alloc] initWithFormat:@"%ld", (long)self.port];
    93         NSString *documentsDirectory = DOCUMENTS_FOLDER();
    93         NSString *documentsDirectory = DOCUMENTS_FOLDER();
    94         
    94         
    95         NSMutableArray *gameParameters = [[NSMutableArray alloc] initWithObjects:
    95         NSMutableArray *gameParameters = [[NSMutableArray alloc] initWithObjects:
    96                                           @"--internal",
    96                                           @"--internal",
    97                                           @"--port", ipcString,
    97                                           @"--port", ipcString,
   112         for (int i = 0; i < argc; i++)
   112         for (int i = 0; i < argc; i++)
   113             free((void *)argv[i]);
   113             free((void *)argv[i]);
   114         free(argv);
   114         free(argv);
   115     });
   115     });
   116     
   116     
   117     DLog(@"Waiting for a client on port %d", self.port);
   117     DLog(@"Waiting for a client on port %ld", (long)self.port);
   118     while (!serverQuit) {
   118     while (!serverQuit) {
   119         /* This check the sd if there is a pending connection.
   119         /* This check the sd if there is a pending connection.
   120          * If there is one, accept that, and open a new socket for communicating */
   120          * If there is one, accept that, and open a new socket for communicating */
   121         csd = SDLNet_TCP_Accept(sd);
   121         csd = SDLNet_TCP_Accept(sd);
   122         if (NULL != csd) {
   122         if (NULL != csd) {
   174     [self performSelectorOnMainThread:@selector(setImageRounded:)
   174     [self performSelectorOnMainThread:@selector(setImageRounded:)
   175                            withObject:previewImage
   175                            withObject:previewImage
   176                         waitUntilDone:NO];
   176                         waitUntilDone:NO];
   177     [previewImage release];
   177     [previewImage release];
   178     [self performSelectorOnMainThread:@selector(setLabelText:)
   178     [self performSelectorOnMainThread:@selector(setLabelText:)
   179                            withObject:[NSString stringWithFormat:@"%d", maxHogs]
   179                            withObject:[NSString stringWithFormat:@"%ld", (long)maxHogs]
   180                         waitUntilDone:NO];
   180                         waitUntilDone:NO];
   181     [self performSelectorOnMainThread:@selector(turnOnWidgets)
   181     [self performSelectorOnMainThread:@selector(turnOnWidgets)
   182                            withObject:nil
   182                            withObject:nil
   183                         waitUntilDone:NO];
   183                         waitUntilDone:NO];
   184     [self performSelectorOnMainThread:@selector(removeIndicator)
   184     [self performSelectorOnMainThread:@selector(removeIndicator)