added pause/resume functionality for android, android need the opengl context to be recreated along with textures and whatnot
--- a/hedgewars/hwengine.pas Tue Jan 24 18:11:56 2012 +0100
+++ b/hedgewars/hwengine.pas Thu Jan 26 02:06:16 2012 +0100
@@ -167,6 +167,7 @@
while isTerminated = false do
begin
SDL_PumpEvents();
+
while SDL_PeepEvents(@event, 1, SDL_GETEVENT, {$IFDEF SDL13}SDL_FIRSTEVENT, SDL_LASTEVENT{$ELSE}SDL_ALLEVENTS{$ENDIF}) > 0 do
begin
case event.type_ of
@@ -190,6 +191,9 @@
else if event.window.event = SDL_WINDOWEVENT_RESTORED then
begin
GameState:= previousGameState;
+{$IFDEF ANDROID} //This call is used to reinitialize the glcontext and reload the textures
+ ParseCommand('fullscr '+intToStr(LongInt(cFullScreen)), true);
+{$ENDIF}
end
else if event.window.event = SDL_WINDOWEVENT_RESIZED then
begin
@@ -291,7 +295,7 @@
begin
{$IFDEF HWLIBRARY}
cBits:= 32;
- cFullScreen:= false;
+ cFullScreen:= true;
cTimerInterval:= 8;
cShowFPS:= {$IFDEF DEBUGFILE}true{$ELSE}false{$ENDIF};
val(gameArgs[0], ipcPort);
--- a/hedgewars/uStore.pas Tue Jan 24 18:11:56 2012 +0100
+++ b/hedgewars/uStore.pas Thu Jan 26 02:06:16 2012 +0100
@@ -369,7 +369,7 @@
// This should maybe be flagged. It wastes quite a bit of memory.
if not reload then
begin
-{$IF DEFINED(DARWIN) OR DEFINED(WIN32)}
+{$IF DEFINED(DARWIN) OR DEFINED(WIN32) or DEFINED(ANDROID)}
Surface:= tmpsurf
{$ELSE}
if saveSurf then
@@ -998,7 +998,11 @@
AddFileLog('Preparing to change video parameters...');
{$IFNDEF IPHONEOS}
+ {$IFDEF SDL13}
+ if SDLwindow = nil then
+ {$ELSE}
if SDLPrimSurface = nil then
+ {$ENDIF}
begin
// set window title
SDL_WM_SetCaption('Hedgewars', nil);
@@ -1006,7 +1010,7 @@
SDLTry(IMG_Init(IMG_INIT_PNG) <> 0, true);
WriteLnToConsole(msgOK);
// load engine icon
-{$IFNDEF DARWIN}
+ {$IFNDEF DARWIN}
ico:= LoadImage(UserPathz[ptGraphics] + '/hwengine', ifIgnoreCaps);
if ico = nil then
ico:= LoadImage(Pathz[ptGraphics] + '/hwengine', ifIgnoreCaps);
@@ -1015,18 +1019,18 @@
SDL_WM_SetIcon(ico, 0);
SDL_FreeSurface(ico)
end;
-{$ENDIF}
+ {$ENDIF}
end
else
begin
SetScale(cDefaultZoomLevel);
-{$IF DEFINED(DARWIN) OR DEFINED(WIN32)}
+ {$IF DEFINED(DARWIN) OR DEFINED(WIN32) or DEFINED(ANDROID)}
reinit:= true;
StoreRelease(true);
ResetLand;
ResetWorldTex;
//uTextures.freeModule; //DEBUG ONLY
-{$ENDIF}
+ {$ENDIF}
AddFileLog('Freeing old primary surface...');
SDL_FreeSurface(SDLPrimSurface);
SDLPrimSurface:= nil;
@@ -1047,14 +1051,14 @@
y:= SDL_WINDOWPOS_CENTERED_MASK;
flags:= SDL_WINDOW_OPENGL or SDL_WINDOW_SHOWN;
-{$IFDEF MOBILE}
+ {$IFDEF MOBILE}
// make the sdl window appear on the second monitor when present
x:= x or (SDL_GetNumVideoDisplays() - 1);
y:= y or (SDL_GetNumVideoDisplays() - 1);
SDL_SetHint('SDL_IOS_ORIENTATIONS','LandscapeLeft LandscapeRight');
flags:= flags or SDL_WINDOW_BORDERLESS or SDL_WINDOW_RESIZABLE;
-{$ENDIF}
+ {$ENDIF}
if SDLwindow = nil then
if cFullScreen then
@@ -1069,13 +1073,13 @@
if not cOnlyStats then
begin
-{$IFDEF WIN32}
+ {$IFDEF WIN32}
s:= SDL_getenv('SDL_VIDEO_CENTERED');
SDL_putenv('SDL_VIDEO_CENTERED=1');
-{$ENDIF}
+ {$ENDIF}
SDLPrimSurface:= SDL_SetVideoMode(cScreenWidth, cScreenHeight, cBits, flags);
SDLTry(SDLPrimSurface <> nil, true);
-{$IFDEF WIN32}SDL_putenv(str2pchar('SDL_VIDEO_CENTERED=' + s));{$ENDIF}
+ {$IFDEF WIN32}SDL_putenv(str2pchar('SDL_VIDEO_CENTERED=' + s));{$ENDIF}
end;
{$ENDIF}