rotation ftw!!! (engine part)
authorkoda
Sun, 29 Jan 2012 02:45:12 +0100
changeset 6611 d9d00e537010
parent 6610 84b0bc1bf399
child 6612 8fd6bb239a1e
rotation ftw!!! (engine part)
hedgewars/hwengine.pas
hedgewars/uStore.pas
hedgewars/uVariables.pas
--- a/hedgewars/hwengine.pas	Sun Jan 29 00:48:39 2012 +0100
+++ b/hedgewars/hwengine.pas	Sun Jan 29 02:45:12 2012 +0100
@@ -191,18 +191,16 @@
                     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
+{$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
-                        // way too broken right now
-                        (*
                         cNewScreenWidth:= max(2 * (event.window.data1 div 2), cMinScreenWidth);
                         cNewScreenHeight:= max(2 * (event.window.data2 div 2), cMinScreenHeight);
-                        cScreenResizeDelay:= RealTicks+500;
-                        *)
+                        cScreenResizeDelay:= RealTicks + 500{$IFDEF IPHONEOS}div 2{$ENDIF};
                         end;
                         
                 SDL_FINGERMOTION:
--- a/hedgewars/uStore.pas	Sun Jan 29 00:48:39 2012 +0100
+++ b/hedgewars/uStore.pas	Sun Jan 29 02:45:12 2012 +0100
@@ -625,7 +625,8 @@
 {$IFDEF SDL13}
     // this function creates an opengles1.1 context by default on mobile devices
     // use SDL_GL_SetAttribute to change this behaviour
-    SDLGLcontext:=SDL_GL_CreateContext(SDLwindow);
+    if SDLGLcontext = nil then
+        SDLGLcontext:= SDL_GL_CreateContext(SDLwindow);
     SDLTry(SDLGLcontext <> nil, true);
     SDL_GL_SetSwapInterval(1);
 {$ENDIF}
@@ -710,15 +711,11 @@
 {$ENDIF}
 
     // set view port to whole window
-    if (rotationQt = 0) or (rotationQt = 180) then
-        glViewport(0, 0, cScreenWidth, cScreenHeight)
-    else
-        glViewport(0, 0, cScreenHeight, cScreenWidth);
+    glViewport(0, 0, cScreenWidth, cScreenHeight)
 
     glMatrixMode(GL_MODELVIEW);
     // prepare default translation/scaling
     glLoadIdentity();
-    glRotatef(rotationQt, 0, 0, 1);
     glScalef(2.0 / cScreenWidth, -2.0 / cScreenHeight, 1.0);
     glTranslatef(0, -cScreenHeight / 2, 0);
 
@@ -747,7 +744,6 @@
         begin
         glPushMatrix;       // save default scaling
         glLoadIdentity;
-        glRotatef(rotationQt, 0, 0, 1);
         glScalef(f / cScreenWidth, -f / cScreenHeight, 1.0);
         glTranslatef(0, -cScreenHeight / 2, 0);
         end;
@@ -997,15 +993,14 @@
         cFullScreen:= s = '1';
 
     AddFileLog('Preparing to change video parameters...');
-{$IFNDEF IPHONEOS}
-    {$IFDEF SDL13}
+{$IFDEF SDL13}
     if SDLwindow = nil then
-    {$ELSE}
+{$ELSE}
     if SDLPrimSurface = nil then
-    {$ENDIF}
+{$ENDIF}
         begin
         // set window title
-        SDL_WM_SetCaption('Hedgewars', nil);
+        {$IFNDEF SDL13}SDL_WM_SetCaption('Hedgewars', nil);{$ENDIF}
         WriteToConsole('Init SDL_image... ');
         SDLTry(IMG_Init(IMG_INIT_PNG) <> 0, true);
         WriteLnToConsole(msgOK);
@@ -1023,6 +1018,17 @@
         end
     else
         begin
+{$IFDEF IPHONEOS}
+        // chFullScr is called when there is a rotation event and needs the SetScale and SetupOpenGL to set up the new resolution
+        // this 6 gl functions are the relevant ones and are hacked together here for optimisation
+        glMatrixMode(GL_MODELVIEW);
+        glPopMatrix;
+        glLoadIdentity();
+        glScalef(2.0 / cScreenWidth, -2.0 / cScreenHeight, 1.0);
+        glTranslatef(0, -cScreenHeight / 2, 0);
+        glViewport(0, 0, cScreenWidth, cScreenHeight);
+        exit;
+{$ELSE}
         SetScale(cDefaultZoomLevel);
      {$IF DEFINED(DARWIN) OR DEFINED(WIN32) or DEFINED(ANDROID)}
         reinit:= true;
@@ -1034,8 +1040,8 @@
         AddFileLog('Freeing old primary surface...');
         SDL_FreeSurface(SDLPrimSurface);
         SDLPrimSurface:= nil;
+{$ENDIF}
         end;
-{$ENDIF}
 
     // these attributes must be set up before creating the sdl window
 {$IFNDEF WIN32}
@@ -1056,7 +1062,10 @@
     x:= x or (SDL_GetNumVideoDisplays() - 1);
     y:= y or (SDL_GetNumVideoDisplays() - 1);
 
-    SDL_SetHint('SDL_IOS_ORIENTATIONS','LandscapeLeft LandscapeRight');
+    if isPhone() then
+        SDL_SetHint('SDL_IOS_ORIENTATIONS','LandscapeLeft LandscapeRight');
+
+    // on mobile the SDL_WINDOW_RESIZABLE makes the window respond to rotation events
     flags:= flags or SDL_WINDOW_BORDERLESS or SDL_WINDOW_RESIZABLE;
     {$ENDIF}
 
@@ -1112,7 +1121,6 @@
 
     SDLPrimSurface:= nil;
 
-    rotationQt:= 0;
     cScaleFactor:= 2.0;
     Step:= 0;
     ProgrTex:= nil;
--- a/hedgewars/uVariables.pas	Sun Jan 29 00:48:39 2012 +0100
+++ b/hedgewars/uVariables.pas	Sun Jan 29 02:45:12 2012 +0100
@@ -2334,8 +2334,7 @@
     ProgrTex: PTexture;
     MissionIcons: PSDL_Surface;
     ropeIconTex: PTexture;
-    // orientation of the viewport
-    rotationQt: GLfloat;
+
     // stereoscopic framebuffer and textures
     framel, framer, depthl, depthr: GLuint;
     texl, texr: GLuint;