Add a delay before applying screen resize to cut down on resize events (especially bad on OSes that need texture recreation)
authornemo
Fri, 02 Sep 2011 01:19:37 -0400
changeset 5732 f3f381011728
parent 5730 1ef0027411f4
child 5734 d710db47a1ef
Add a delay before applying screen resize to cut down on resize events (especially bad on OSes that need texture recreation)
hedgewars/hwengine.pas
hedgewars/uVariables.pas
--- a/hedgewars/hwengine.pas	Fri Sep 02 09:04:11 2011 +0400
+++ b/hedgewars/hwengine.pas	Fri Sep 02 01:19:37 2011 -0400
@@ -181,12 +181,9 @@
                         end;
                 SDL_VIDEORESIZE: begin
                     // using lower values causes widget overlap and video issues
-                    cScreenWidth:= max(event.resize.w, cMinScreenWidth);
-                    cScreenHeight:= max(event.resize.h, cMinScreenHeight);
-
-                    ParseCommand('fullscr '+intToStr(LongInt(cFullScreen)), true);
-                    WriteLnToConsole('window resize');
-                    InitCameraBorders();
+                    cNewScreenWidth:= max(event.resize.w, cMinScreenWidth);
+                    cNewScreenHeight:= max(event.resize.h, cMinScreenHeight);
+                    cScreenResizeDelay:= RealTicks+500;
                     end;
 {$ENDIF}
                 SDL_JOYAXISMOTION: ControllerAxisEvent(event.jaxis.which, event.jaxis.axis, event.jaxis.value);
@@ -196,6 +193,16 @@
                 SDL_QUITEV: isTerminated:= true
             end; //end case event.type_ of
         end; //end while SDL_PollEvent(@event) <> 0 do
+        if (cScreenResizeDelay <> 0) and (cScreenResizeDelay < RealTicks) and ((cNewScreenWidth <> cScreenWidth) or (cNewScreenHeight <> cScreenHeight)) then
+            begin
+            cScreenResizeDelay:= 0;
+            cScreenWidth:= cNewScreenWidth;
+            cScreenHeight:= cNewScreenHeight;
+
+            ParseCommand('fullscr '+intToStr(LongInt(cFullScreen)), true);
+            WriteLnToConsole('window resize');
+            InitCameraBorders()
+            end;
 
         if isTerminated = false then
         begin
--- a/hedgewars/uVariables.pas	Fri Sep 02 09:04:11 2011 +0400
+++ b/hedgewars/uVariables.pas	Fri Sep 02 01:19:37 2011 -0400
@@ -25,12 +25,15 @@
 
 var
 /////// init flags ///////
-    cMinScreenWidth   : LongInt     = 480;
-    cMinScreenHeight  : LongInt     = 320;
-    cScreenWidth      : LongInt     = 1024;
-    cScreenHeight     : LongInt     = 768;
-    cOrigScreenWidth  : LongInt     = 1024;
-    cOrigScreenHeight : LongInt     = 768;
+    cMinScreenWidth    : LongInt     = 480;
+    cMinScreenHeight   : LongInt     = 320;
+    cScreenWidth       : LongInt     = 1024;
+    cScreenHeight      : LongInt     = 768;
+    cOrigScreenWidth   : LongInt     = 1024;
+    cOrigScreenHeight  : LongInt     = 768;
+    cNewScreenWidth    : LongInt     = 1024;
+    cNewScreenHeight   : LongInt     = 768;
+    cScreenResizeDelay : LongWord    = 0;
     cBits           : LongInt     = 32;
     ipcPort         : Word        = 0;
     cFullScreen     : boolean     = false;