Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Don't run the game loop while a messagebox is up
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Nov 25, 2012
1 parent 3254ede commit f143c6a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/video/uikit/SDL_uikitmessagebox.h
Expand Up @@ -22,6 +22,8 @@

#if SDL_VIDEO_DRIVER_UIKIT

extern SDL_bool UIKit_ShowingMessageBox();

extern int UIKit_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid);

#endif /* SDL_VIDEO_DRIVER_UIKIT */
Expand Down
10 changes: 10 additions & 0 deletions src/video/uikit/SDL_uikitmessagebox.m
Expand Up @@ -28,6 +28,7 @@

/* Display a UIKit message box */

static SDL_bool s_showingMessageBox = SDL_FALSE;

@interface UIKit_UIAlertViewDelegate : NSObject <UIAlertViewDelegate> {
@private
Expand Down Expand Up @@ -60,6 +61,12 @@ - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)
@end // UIKit_UIAlertViewDelegate


SDL_bool
UIKit_ShowingMessageBox()
{
return s_showingMessageBox;
}

int
UIKit_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
{
Expand All @@ -86,9 +93,12 @@ - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)

// Run the main event loop until the alert has finished
// Note that this needs to be done on the main thread
s_showingMessageBox = SDL_TRUE;
while (clicked == messageboxdata->numbuttons) {
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
}
s_showingMessageBox = SDL_FALSE;

*buttonid = messageboxdata->buttons[clicked].buttonid;

[pool release];
Expand Down
12 changes: 8 additions & 4 deletions src/video/uikit/SDL_uikitopenglview.m
Expand Up @@ -22,9 +22,10 @@

#if SDL_VIDEO_DRIVER_UIKIT

#import <QuartzCore/QuartzCore.h>
#import <OpenGLES/EAGLDrawable.h>
#import "SDL_uikitopenglview.h"
#include <QuartzCore/QuartzCore.h>
#include <OpenGLES/EAGLDrawable.h>
#include "SDL_uikitopenglview.h"
#include "SDL_uikitmessagebox.h"


@implementation SDL_uikitopenglview
Expand Down Expand Up @@ -180,7 +181,10 @@ - (void)stopAnimation

- (void)doLoop:(id)sender
{
animationCallback(animationCallbackParam);
// Don't run the game loop while a messagebox is up
if (!UIKit_ShowingMessageBox()) {
animationCallback(animationCallbackParam);
}
}

- (void)setCurrentContext
Expand Down

0 comments on commit f143c6a

Please sign in to comment.