# HG changeset patch
# User koda
# Date 1291449177 -3600
# Node ID 42bfc1a7096870d17ba5336178024b3087c0313b
# Parent 15a483b2558a8e45df418af0fa85d49d9dac4ab5
more retina support and multitasking support
diff -r 15a483b2558a -r 42bfc1a70968 hedgewars/PascalExports.pas
--- a/hedgewars/PascalExports.pas Thu Dec 02 20:40:30 2010 -0500
+++ b/hedgewars/PascalExports.pas Sat Dec 04 08:52:57 2010 +0100
@@ -31,6 +31,7 @@
implementation
{$IFDEF HWLIBRARY}
var cZoomVal: GLfloat;
+ previousGameState: TGameState;
// retrieve protocol information
procedure HW_versionInfo(netProto: PShortInt; versionStr: PPChar); cdecl; export;
@@ -167,9 +168,31 @@
procedure HW_pause; cdecl; export;
begin
+ if isPaused = false then
+ pauseAction:= true;
+end;
+
+procedure HW_pauseToggle; cdecl; export;
+begin
pauseAction:= true;
end;
+function HW_isPaused: boolean; cdecl; export;
+begin
+ exit( isPaused );
+end;
+
+procedure HW_suspend; cdecl; export;
+begin
+ previousGameState:= GameState;
+ GameState:= gsSuspend;
+end;
+
+procedure HW_resume; cdecl; export;
+begin
+ GameState:= previousGameState;
+end;
+
procedure HW_terminate(closeFrontend: boolean); cdecl; export;
begin
isTerminated:= true;
@@ -199,11 +222,6 @@
((Ammoz[CurAmmoGear^.AmmoType].Ammo.Propz and ammoprop_AltAttack) = 0)) and hideAmmoMenu)) );
end;
-function HW_isPaused: boolean; cdecl; export;
-begin
- exit( isPaused );
-end;
-
function HW_isWaiting: boolean; cdecl; export;
begin
exit( ReadyTimeLeft > 0 );
diff -r 15a483b2558a -r 42bfc1a70968 hedgewars/SDLh.pas
--- a/hedgewars/SDLh.pas Thu Dec 02 20:40:30 2010 -0500
+++ b/hedgewars/SDLh.pas Sat Dec 04 08:52:57 2010 +0100
@@ -511,6 +511,17 @@
{$ENDIF}
end;
+ TSDL_UserEvent = record
+{$IFDEF SDL13}
+ type_: LongInt;
+ windowID: LongInt;
+{$ELSE}
+ type_: Byte;
+{$ENDIF}
+ code: LongInt;
+ data1, data2: Pointer;
+ end;
+
PSDL_Event = ^TSDL_Event;
TSDL_Event = record
{$IFDEF SDL13}
@@ -531,6 +542,7 @@
SDL_JOYBALLMOTION: (jball: TSDL_JoyBallEvent);
SDL_JOYBUTTONDOWN,
SDL_JOYBUTTONUP: (jbutton: TSDL_JoyButtonEvent);
+ SDL_USEREVENT: (user: TSDL_UserEvent);
{$ELSE}
case Byte of
SDL_NOEVENT: (type_: byte);
diff -r 15a483b2558a -r 42bfc1a70968 hedgewars/hwengine.pas
--- a/hedgewars/hwengine.pas Thu Dec 02 20:40:30 2010 -0500
+++ b/hedgewars/hwengine.pas Sat Dec 04 08:52:57 2010 +0100
@@ -48,7 +48,8 @@
procedure DoTimer(Lag: LongInt);
var s: shortstring;
begin
- if not isPaused then inc(RealTicks, Lag);
+ if isPaused = false then
+ inc(RealTicks, Lag);
case GameState of
gsLandGen: begin
@@ -97,6 +98,7 @@
gsExit: begin
isTerminated:= true;
end;
+ gsSuspend: exit;
end;
{$IFDEF SDL13}
@@ -104,7 +106,7 @@
{$ELSE}
SDL_GL_SwapBuffers();
{$ENDIF}
- // not going to make captures on the iPhone
+
if flagMakeCapture then
begin
flagMakeCapture:= false;
@@ -146,19 +148,16 @@
begin
case event.type_ of
SDL_KEYDOWN: if GameState = gsChat then
-{$IFDEF IPHONEOS}
+{$IFDEF SDL13}
// sdl on iphone supports only ashii keyboards and the unicode field is deprecated in sdl 1.3
KeyPressChat(event.key.keysym.sym);
+ SDL_WINDOWEVENT:
+ if event.wevent.event = SDL_WINDOWEVENT_SHOWN then
+ cHasFocus:= true;
{$ELSE}
KeyPressChat(event.key.keysym.unicode);
SDL_MOUSEBUTTONDOWN: if event.button.button = SDL_BUTTON_WHEELDOWN then uKeys.wheelDown:= true;
SDL_MOUSEBUTTONUP: if event.button.button = SDL_BUTTON_WHEELUP then uKeys.wheelUp:= true;
-{$ENDIF}
-{$IFDEF SDL13}
- SDL_WINDOWEVENT:
- if event.wevent.event = SDL_WINDOWEVENT_SHOWN then
- cHasFocus:= true;
-{$ELSE}
SDL_ACTIVEEVENT:
if (event.active.state and SDL_APPINPUTFOCUS) <> 0 then
cHasFocus:= event.active.gain = 1;
@@ -168,8 +167,8 @@
SDL_JOYBUTTONDOWN: ControllerButtonEvent(event.jbutton.which, event.jbutton.button, true);
SDL_JOYBUTTONUP: ControllerButtonEvent(event.jbutton.which, event.jbutton.button, false);
SDL_QUITEV: isTerminated:= true
- end; // end case event.type_
- end; // end while SDL_PollEvent(@event) <> 0
+ end; //end case event.type_ of
+ end; //end while SDL_PollEvent(@event) <> 0 do
if isTerminated = false then
begin
diff -r 15a483b2558a -r 42bfc1a70968 hedgewars/uTypes.pas
--- a/hedgewars/uTypes.pas Thu Dec 02 20:40:30 2010 -0500
+++ b/hedgewars/uTypes.pas Sat Dec 04 08:52:57 2010 +0100
@@ -10,7 +10,7 @@
r, g, b, a: byte
end;
- TGameState = (gsLandGen, gsStart, gsGame, gsChat, gsConfirm, gsExit);
+ TGameState = (gsLandGen, gsStart, gsGame, gsChat, gsConfirm, gsExit, gsSuspend);
TGameType = (gmtLocal, gmtDemo, gmtNet, gmtSave, gmtLandPreview, gmtSyntax);
diff -r 15a483b2558a -r 42bfc1a70968 project_files/HedgewarsMobile/Classes/OverlayViewController.h
--- a/project_files/HedgewarsMobile/Classes/OverlayViewController.h Thu Dec 02 20:40:30 2010 -0500
+++ b/project_files/HedgewarsMobile/Classes/OverlayViewController.h Sat Dec 04 08:52:57 2010 +0100
@@ -53,6 +53,9 @@
BOOL useClassicMenu;
NSInteger initialOrientation;
+ // the containing window
+ UIWindow *containerWindow;
+
// dual head support
NSInteger initialScreenCount;
NSInteger a, b;
@@ -65,6 +68,7 @@
@property (assign) BOOL isNetGame;
@property (assign) BOOL useClassicMenu;
@property (assign) NSInteger initialOrientation;
+@property (assign) UIWindow *containerWindow;
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
diff -r 15a483b2558a -r 42bfc1a70968 project_files/HedgewarsMobile/Classes/OverlayViewController.m
--- a/project_files/HedgewarsMobile/Classes/OverlayViewController.m Thu Dec 02 20:40:30 2010 -0500
+++ b/project_files/HedgewarsMobile/Classes/OverlayViewController.m Sat Dec 04 08:52:57 2010 +0100
@@ -38,7 +38,7 @@
#define removeConfirmationInput() [[self.view viewWithTag:CONFIRMATION_TAG] removeFromSuperview];
@implementation OverlayViewController
-@synthesize popoverController, popupMenu, helpPage, amvc, isNetGame, useClassicMenu, initialOrientation;
+@synthesize popoverController, popupMenu, helpPage, amvc, isNetGame, useClassicMenu, initialOrientation, containerWindow;
#pragma mark -
#pragma mark rotation
@@ -54,9 +54,9 @@
if (isGameRunning() == NO)
return;
+ HW_pause();
[self dismissPopover];
- if (HW_isPaused() == NO)
- HW_pause();
+
if (self.amvc.isVisible && IS_DUALHEAD() == NO) {
[self.amvc disappear];
wasVisible = YES;
@@ -86,8 +86,7 @@
if (wasVisible || IS_DUALHEAD())
[self.amvc appearInView:self.view];
- if (HW_isPaused() == YES)
- HW_pause();
+ HW_pauseToggle();
[super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
}
@@ -203,6 +202,8 @@
name:UIScreenDidDisconnectNotification
object:nil];
}
+
+ self.containerWindow = [[UIApplication sharedApplication] keyWindow];
// present the overlay
[UIView beginAnimations:@"showing overlay" context:NULL];
@@ -220,8 +221,7 @@
otherButtonTitles:nil];
[alert show];
[alert release];
- if (HW_isPaused() == NO)
- HW_pause();
+ HW_pause();
}
}
@@ -493,7 +493,7 @@
if (YES == isPopoverVisible) {
isPopoverVisible = NO;
if (HW_isPaused())
- HW_pause();
+ HW_pauseToggle();
if (IS_IPAD()) {
[(InGameMenuViewController *)[[self popoverController] contentViewController] removeChat];
diff -r 15a483b2558a -r 42bfc1a70968 project_files/HedgewarsMobile/Classes/PascalImports.h
--- a/project_files/HedgewarsMobile/Classes/PascalImports.h Thu Dec 02 20:40:30 2010 -0500
+++ b/project_files/HedgewarsMobile/Classes/PascalImports.h Sat Dec 04 08:52:57 2010 +0100
@@ -63,16 +63,20 @@
void HW_chat(void);
void HW_chatEnd(void);
void HW_tab(void);
+
void HW_pause(void);
+ void HW_pauseToggle(void);
+ BOOL HW_isPaused(void);
void HW_terminate(BOOL andCloseFrontend);
+ void HW_suspend(void);
+ void HW_resume(void);
void HW_setCursor(int x, int y);
void HW_getCursor(int *x, int *y);
BOOL HW_isAmmoMenuOpen(void);
BOOL HW_isAmmoMenuNotAllowed(void);
- BOOL HW_isPaused(void);
BOOL HW_isWeaponRequiringClick(void);
BOOL HW_isWeaponTimerable(void);
BOOL HW_isWeaponSwitch(void);
diff -r 15a483b2558a -r 42bfc1a70968 project_files/HedgewarsMobile/Classes/SDL_uikitappdelegate.m
--- a/project_files/HedgewarsMobile/Classes/SDL_uikitappdelegate.m Thu Dec 02 20:40:30 2010 -0500
+++ b/project_files/HedgewarsMobile/Classes/SDL_uikitappdelegate.m Sat Dec 04 08:52:57 2010 +0100
@@ -29,6 +29,7 @@
#import "SDL_video.h"
#import "SDL_mixer.h"
#import "PascalImports.h"
+#import "ObjcExports.h"
#import "CommodityFunctions.h"
#import "GameSetup.h"
#import "MainMenuViewController.h"
@@ -222,40 +223,33 @@
}
-(void) applicationWillResignActive:(UIApplication *)application {
- if (self.isInGame) {
- HW_pause();
-
- // Send every window on every screen a MINIMIZED event.
- SDL_VideoDevice *_this = SDL_GetVideoDevice();
- if (!_this)
- return;
-
- int i;
- for (i = 0; i < _this->num_displays; i++) {
- const SDL_VideoDisplay *display = &_this->displays[i];
- SDL_Window *window;
- for (window = display->windows; window != nil; window = window->next)
- SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
+ UIDevice* device = [UIDevice currentDevice];
+ if ([device respondsToSelector:@selector(isMultitaskingSupported)] &&
+ device.multitaskingSupported &&
+ self.isInGame) {
+ // there is a bug on iphone that presents a sdl view with a black screen, so it returns to frontend
+ if (IS_IPAD())
+ HW_suspend();
+ else {
+ // while screen is loading you can't call HW_terminate() so we close the app
+ if (isGameRunning())
+ HW_terminate(NO);
+ else {
+ // force app closure
+ SDL_SendQuit();
+ HW_terminate(YES);
+ longjmp(*(jump_env()), 1);
+ }
}
}
}
-(void) applicationDidBecomeActive:(UIApplication *)application {
- if (self.isInGame) {
- HW_pause();
-
- // Send every window on every screen a RESTORED event.
- SDL_VideoDevice *_this = SDL_GetVideoDevice();
- if (!_this)
- return;
-
- int i;
- for (i = 0; i < _this->num_displays; i++) {
- const SDL_VideoDisplay *display = &_this->displays[i];
- SDL_Window *window;
- for (window = display->windows; window != nil; window = window->next)
- SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESTORED, 0, 0);
- }
+ UIDevice* device = [UIDevice currentDevice];
+ if ([device respondsToSelector:@selector(isMultitaskingSupported)] &&
+ device.multitaskingSupported &&
+ self.isInGame) {
+ HW_resume();
}
}
diff -r 15a483b2558a -r 42bfc1a70968 project_files/HedgewarsMobile/Info.plist
--- a/project_files/HedgewarsMobile/Info.plist Thu Dec 02 20:40:30 2010 -0500
+++ b/project_files/HedgewarsMobile/Info.plist Sat Dec 04 08:52:57 2010 +0100
@@ -31,8 +31,6 @@
1.2
LSRequiresIPhoneOS
- UIApplicationExitsOnSuspend
-
UILaunchImageFile~ipad
Default-ipad
UIStatusBarHidden
diff -r 15a483b2558a -r 42bfc1a70968 project_files/HedgewarsMobile/SDL.patch
--- a/project_files/HedgewarsMobile/SDL.patch Thu Dec 02 20:40:30 2010 -0500
+++ b/project_files/HedgewarsMobile/SDL.patch Sat Dec 04 08:52:57 2010 +0100
@@ -1,6 +1,6 @@
-diff -r 834ce48a19c2 Xcode-iPhoneOS/SDL/SDLiPhoneOS.xcodeproj/project.pbxproj
---- a/Xcode-iPhoneOS/SDL/SDLiPhoneOS.xcodeproj/project.pbxproj Sun May 09 12:58:58 2010 +0800
-+++ b/Xcode-iPhoneOS/SDL/SDLiPhoneOS.xcodeproj/project.pbxproj Sun Nov 28 18:14:58 2010 +0100
+diff -r d716dff4b13e Xcode-iPhoneOS/SDL/SDLiPhoneOS.xcodeproj/project.pbxproj
+--- a/Xcode-iPhoneOS/SDL/SDLiPhoneOS.xcodeproj/project.pbxproj Thu Dec 02 11:56:23 2010 -0800
++++ b/Xcode-iPhoneOS/SDL/SDLiPhoneOS.xcodeproj/project.pbxproj Thu Dec 02 22:38:57 2010 +0100
@@ -1262,7 +1262,14 @@
isa = PBXProject;
buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "SDLiPhoneOS" */;
@@ -59,9 +59,9 @@
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
-diff -r 834ce48a19c2 Xcode-iPhoneOS/SDL/testsdl-Info.plist
---- a/Xcode-iPhoneOS/SDL/testsdl-Info.plist Sun May 09 12:58:58 2010 +0800
-+++ b/Xcode-iPhoneOS/SDL/testsdl-Info.plist Sun Nov 28 18:14:58 2010 +0100
+diff -r d716dff4b13e Xcode-iPhoneOS/SDL/testsdl-Info.plist
+--- a/Xcode-iPhoneOS/SDL/testsdl-Info.plist Thu Dec 02 11:56:23 2010 -0800
++++ b/Xcode-iPhoneOS/SDL/testsdl-Info.plist Thu Dec 02 22:38:57 2010 +0100
@@ -16,7 +16,5 @@
????
CFBundleVersion
@@ -70,9 +70,9 @@
- MainWindow
-diff -r 834ce48a19c2 include/SDL_config_iphoneos.h
---- a/include/SDL_config_iphoneos.h Sun May 09 12:58:58 2010 +0800
-+++ b/include/SDL_config_iphoneos.h Sun Nov 28 18:14:58 2010 +0100
+diff -r d716dff4b13e include/SDL_config_iphoneos.h
+--- a/include/SDL_config_iphoneos.h Thu Dec 02 11:56:23 2010 -0800
++++ b/include/SDL_config_iphoneos.h Thu Dec 02 22:38:57 2010 +0100
@@ -98,6 +98,8 @@
#define HAVE_COS 1
#define HAVE_COSF 1
@@ -108,9 +108,9 @@
+#define SDL_VIEW_TAG 456987
+
#endif /* _SDL_config_iphoneos_h */
-diff -r 834ce48a19c2 src/SDL_fatal.c
---- a/src/SDL_fatal.c Sun May 09 12:58:58 2010 +0800
-+++ b/src/SDL_fatal.c Sun Nov 28 18:14:58 2010 +0100
+diff -r d716dff4b13e src/SDL_fatal.c
+--- a/src/SDL_fatal.c Thu Dec 02 11:56:23 2010 -0800
++++ b/src/SDL_fatal.c Thu Dec 02 22:38:57 2010 +0100
@@ -38,9 +38,9 @@
static void
SDL_Parachute(int sig)
@@ -123,9 +123,9 @@
}
static const int SDL_fatal_signals[] = {
-diff -r 834ce48a19c2 src/video/SDL_renderer_gles.c
---- a/src/video/SDL_renderer_gles.c Sun May 09 12:58:58 2010 +0800
-+++ b/src/video/SDL_renderer_gles.c Sun Nov 28 18:14:58 2010 +0100
+diff -r d716dff4b13e src/video/SDL_renderer_gles.c
+--- a/src/video/SDL_renderer_gles.c Thu Dec 02 11:56:23 2010 -0800
++++ b/src/video/SDL_renderer_gles.c Thu Dec 02 22:38:57 2010 +0100
@@ -324,6 +324,9 @@
data->glDisable(GL_CULL_FACE);
data->updateSize = SDL_TRUE;
@@ -207,9 +207,9 @@
}
data->glDisable(GL_TEXTURE_2D);
-diff -r 834ce48a19c2 src/video/SDL_video.c
---- a/src/video/SDL_video.c Sun May 09 12:58:58 2010 +0800
-+++ b/src/video/SDL_video.c Sun Nov 28 18:14:58 2010 +0100
+diff -r d716dff4b13e src/video/SDL_video.c
+--- a/src/video/SDL_video.c Thu Dec 02 11:56:23 2010 -0800
++++ b/src/video/SDL_video.c Thu Dec 02 22:38:57 2010 +0100
@@ -1421,9 +1421,9 @@
SDL_MinimizeWindow(window);
}
@@ -222,9 +222,9 @@
if ((window->flags & (SDL_WINDOW_INPUT_GRABBED | SDL_WINDOW_FULLSCREEN))
&& _this->SetWindowGrab) {
_this->SetWindowGrab(_this, window);
-diff -r 834ce48a19c2 src/video/uikit/SDL_uikitopengles.m
---- a/src/video/uikit/SDL_uikitopengles.m Sun May 09 12:58:58 2010 +0800
-+++ b/src/video/uikit/SDL_uikitopengles.m Sun Nov 28 18:14:58 2010 +0100
+diff -r d716dff4b13e src/video/uikit/SDL_uikitopengles.m
+--- a/src/video/uikit/SDL_uikitopengles.m Thu Dec 02 11:56:23 2010 -0800
++++ b/src/video/uikit/SDL_uikitopengles.m Thu Dec 02 22:38:57 2010 +0100
@@ -114,8 +114,8 @@
bBits: _this->gl_config.blue_size \
aBits: _this->gl_config.alpha_size \
@@ -236,9 +236,21 @@
/* add the view to our window */
[uiwindow addSubview: view ];
-diff -r 834ce48a19c2 src/video/uikit/SDL_uikitview.h
---- a/src/video/uikit/SDL_uikitview.h Sun May 09 12:58:58 2010 +0800
-+++ b/src/video/uikit/SDL_uikitview.h Sun Nov 28 18:14:58 2010 +0100
+diff -r d716dff4b13e src/video/uikit/SDL_uikitopenglview.m
+--- a/src/video/uikit/SDL_uikitopenglview.m Thu Dec 02 11:56:23 2010 -0800
++++ b/src/video/uikit/SDL_uikitopenglview.m Thu Dec 02 22:38:57 2010 +0100
+@@ -117,6 +117,8 @@
+ return NO;
+ }
+ /* end create buffers */
++ if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
++ self.contentScaleFactor = [UIScreen mainScreen].scale;
+ }
+ return self;
+ }
+diff -r d716dff4b13e src/video/uikit/SDL_uikitview.h
+--- a/src/video/uikit/SDL_uikitview.h Thu Dec 02 11:56:23 2010 -0800
++++ b/src/video/uikit/SDL_uikitview.h Thu Dec 02 22:38:57 2010 +0100
@@ -23,11 +23,11 @@
#include "SDL_stdinc.h"
#include "SDL_events.h"
@@ -254,9 +266,9 @@
#endif
/* *INDENT-OFF* */
-diff -r 834ce48a19c2 src/video/uikit/SDL_uikitview.m
---- a/src/video/uikit/SDL_uikitview.m Sun May 09 12:58:58 2010 +0800
-+++ b/src/video/uikit/SDL_uikitview.m Sun Nov 28 18:14:58 2010 +0100
+diff -r d716dff4b13e src/video/uikit/SDL_uikitview.m
+--- a/src/video/uikit/SDL_uikitview.m Thu Dec 02 11:56:23 2010 -0800
++++ b/src/video/uikit/SDL_uikitview.m Thu Dec 02 22:38:57 2010 +0100
@@ -35,9 +35,6 @@
@implementation SDL_uikitview
@@ -368,9 +380,9 @@
if (NULL == view) {
SDL_SetError("Window has no view");
-diff -r 834ce48a19c2 src/video/uikit/SDL_uikitwindow.m
---- a/src/video/uikit/SDL_uikitwindow.m Sun May 09 12:58:58 2010 +0800
-+++ b/src/video/uikit/SDL_uikitwindow.m Sun Nov 28 18:14:58 2010 +0100
+diff -r d716dff4b13e src/video/uikit/SDL_uikitwindow.m
+--- a/src/video/uikit/SDL_uikitwindow.m Thu Dec 02 11:56:23 2010 -0800
++++ b/src/video/uikit/SDL_uikitwindow.m Thu Dec 02 22:38:57 2010 +0100
@@ -144,7 +144,10 @@
if (SDL_UIKit_supports_multiple_displays) {
[uiwindow setScreen:uiscreen];
@@ -383,9 +395,9 @@
if (SetupWindowData(_this, window, uiwindow, SDL_TRUE) < 0) {
[uiwindow release];
return -1;
-diff -r 834ce48a19c2 src/video/uikit/keyinfotable.h
---- a/src/video/uikit/keyinfotable.h Sun May 09 12:58:58 2010 +0800
-+++ b/src/video/uikit/keyinfotable.h Sun Nov 28 18:14:58 2010 +0100
+diff -r d716dff4b13e src/video/uikit/keyinfotable.h
+--- a/src/video/uikit/keyinfotable.h Thu Dec 02 11:56:23 2010 -0800
++++ b/src/video/uikit/keyinfotable.h Thu Dec 02 22:38:57 2010 +0100
@@ -54,7 +54,7 @@
/* 10 */ { SDL_SCANCODE_UNKNOWN, 0 },
/* 11 */ { SDL_SCANCODE_UNKNOWN, 0 },