huh? me? nono, don't mind me. I'm just here to clean up.
authorsheepluva
Sat, 14 Jun 2014 02:25:49 +0200
changeset 10302 ea0b0e2efd95
parent 10301 6a225b469eef
child 10303 f726e36c3e24
huh? me? nono, don't mind me. I'm just here to clean up.
hedgewars/hwengine.pas
hedgewars/uRender.pas
hedgewars/uStore.pas
hedgewars/uVisualGears.pas
--- a/hedgewars/hwengine.pas	Sat Jun 14 00:56:11 2014 +0200
+++ b/hedgewars/hwengine.pas	Sat Jun 14 02:25:49 2014 +0200
@@ -86,8 +86,7 @@
                 SetSound(false);
             FinishProgress;
             PlayMusic;
-            SetScale(zoom);
-            updateViewLimits;
+            InitZoom(zoom);
             ScriptCall('onGameStart');
             GameState:= gsGame;
             end;
@@ -276,7 +275,7 @@
             ScriptOnScreenResize();
             InitCameraBorders();
             InitTouchInterface();
-            updateViewLimits();
+            InitZoom(zoomValue);
             SendIPC('W' + IntToStr(cScreenWidth) + 'x' + IntToStr(cScreenHeight));
         end;
 
--- a/hedgewars/uRender.pas	Sat Jun 14 00:56:11 2014 +0200
+++ b/hedgewars/uRender.pas	Sat Jun 14 02:25:49 2014 +0200
@@ -23,7 +23,7 @@
 
 interface
 
-uses SDLh, uTypes, GLunit, uConsts, uStore{$IFDEF GL2}, uMatrix{$ENDIF};
+uses SDLh, uTypes, GLunit, uConsts{$IFDEF GL2}, uMatrix{$ENDIF};
 
 procedure DrawSprite            (Sprite: TSprite; X, Y, Frame: LongInt);
 procedure DrawSprite            (Sprite: TSprite; X, Y, FrameX, FrameY: LongInt);
@@ -64,7 +64,18 @@
 function isDxAreaOffscreen(X, Width: LongInt): LongInt; inline;
 function isDyAreaOffscreen(Y, Height: LongInt): LongInt; inline;
 
+procedure SetScale(f: GLfloat);
+procedure UpdateViewLimits();
 
+procedure EnableTexture(enable:Boolean);
+
+procedure SetTexCoordPointer(p: Pointer;n: Integer);
+procedure SetVertexPointer(p: Pointer;n: Integer);
+procedure SetColorPointer(p: Pointer;n: Integer);
+
+procedure UpdateModelviewProjection(); inline;
+
+procedure openglLoadIdentity    (); inline;
 procedure openglTranslProjMatrix(X, Y, Z: GLFloat); inline;
 procedure openglPushMatrix      (); inline;
 procedure openglPopMatrix       (); inline;
@@ -104,6 +115,15 @@
     isDyAreaOffscreen:= 0;
 end;
 
+procedure openglLoadIdentity(); inline;
+begin
+{$IFDEF GL2}
+    hglLoadIdentity();
+{$ELSE}
+    glLoadIdentity();
+{$ENDIF}
+end;
+
 procedure openglTranslProjMatrix(X, Y, Z: GLfloat); inline;
 begin
 {$IFDEF GL2}
@@ -186,6 +206,112 @@
         end;
 end;
 
+procedure UpdateModelviewProjection(); inline;
+{$IFDEF GL2}
+var
+    mvp: TMatrix4x4f;
+{$ENDIF}
+begin
+{$IFDEF GL2}
+    //MatrixMultiply(mvp, mProjection, mModelview);
+{$HINTS OFF}
+    hglMVP(mvp);
+{$HINTS ON}
+    glUniformMatrix4fv(uCurrentMVPLocation, 1, GL_FALSE, @mvp[0, 0]);
+{$ENDIF}
+end;
+
+procedure SetTexCoordPointer(p: Pointer; n: Integer);
+begin
+{$IFDEF GL2}
+    glBindBuffer(GL_ARRAY_BUFFER, tBuffer);
+    glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * n * 2, p, GL_STATIC_DRAW);
+    glEnableVertexAttribArray(aTexCoord);
+    glVertexAttribPointer(aTexCoord, 2, GL_FLOAT, GL_FALSE, 0, pointer(0));
+{$ELSE}
+    n:= n;
+    glTexCoordPointer(2, GL_FLOAT, 0, p);
+{$ENDIF}
+end;
+
+procedure SetVertexPointer(p: Pointer; n: Integer);
+begin
+{$IFDEF GL2}
+    glBindBuffer(GL_ARRAY_BUFFER, vBuffer);
+    glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * n * 2, p, GL_STATIC_DRAW);
+    glEnableVertexAttribArray(aVertex);
+    glVertexAttribPointer(aVertex, 2, GL_FLOAT, GL_FALSE, 0, pointer(0));
+{$ELSE}
+    n:= n;
+    glVertexPointer(2, GL_FLOAT, 0, p);
+{$ENDIF}
+end;
+
+procedure SetColorPointer(p: Pointer; n: Integer);
+begin
+{$IFDEF GL2}
+    glBindBuffer(GL_ARRAY_BUFFER, cBuffer);
+    glBufferData(GL_ARRAY_BUFFER, n * 4, p, GL_STATIC_DRAW);
+    glEnableVertexAttribArray(aColor);
+    glVertexAttribPointer(aColor, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, pointer(0));
+{$ELSE}
+    n:= n;
+    glColorPointer(4, GL_UNSIGNED_BYTE, 0, p);
+{$ENDIF}
+end;
+
+procedure EnableTexture(enable:Boolean);
+begin
+    {$IFDEF GL2}
+    if enable then
+        glUniform1i(glGetUniformLocation(shaderMain, pchar('enableTexture')), 1)
+    else
+        glUniform1i(glGetUniformLocation(shaderMain, pchar('enableTexture')), 0);
+    {$ELSE}
+    if enable then
+        glEnable(GL_TEXTURE_2D)
+    else
+        glDisable(GL_TEXTURE_2D);
+    {$ENDIF}
+end;
+
+procedure UpdateViewLimits();
+var tmp: real;
+begin
+    // cScaleFactor is 2.0 on "no zoom"
+    tmp:= cScreenWidth / cScaleFactor;
+    ViewRightX:= round(tmp); // ceil could make more sense
+    ViewLeftX:= round(-tmp); // floor could make more sense
+    tmp:= cScreenHeight / cScaleFactor;
+    ViewBottomY:= round(tmp) + cScreenHeight div 2; // ceil could make more sense
+    ViewTopY:= round(-tmp) + cScreenHeight div 2; // floor could make more sense
+end;
+
+procedure SetScale(f: GLfloat);
+begin
+// leave immediately if scale factor did not change
+    if f = cScaleFactor then
+        exit;
+
+    // for going back to default scaling just pop matrix
+    if f = cDefaultZoomLevel then
+        begin
+        openglPopMatrix;
+        end
+    else
+        begin
+        openglPushMatrix; // save default scaling in matrix
+        openglLoadIdentity();
+        openglScalef(f / cScreenWidth, -f / cScreenHeight, 1.0);
+        openglTranslatef(0, -cScreenHeight / 2, 0);
+        end;
+
+    cScaleFactor:= f;
+    updateViewLimits();
+
+    UpdateModelviewProjection;
+end;
+
 procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt); inline;
 begin
 r.y:= r.y + Height * Position;
@@ -315,9 +441,7 @@
 SetVertexPointer(@Texture^.vb, Length(Texture^.vb));
 SetTexCoordPointer(@TextureBuffer, Length(Texture^.vb));
 
-{$IFDEF GL2}
 UpdateModelviewProjection;
-{$ENDIF}
 
 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(Texture^.vb));
 openglPopMatrix;
@@ -395,9 +519,7 @@
 SetVertexPointer(@VertexBuffer[0], Length(VertexBuffer));
 SetTexCoordPointer(@TextureBuffer[0], Length(VertexBuffer));
 
-{$IFDEF GL2}
 UpdateModelviewProjection;
-{$ENDIF}
 
 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
 
@@ -467,9 +589,7 @@
 SetVertexPointer(@VertexBuffer[0], Length(VertexBuffer));
 SetTexCoordPointer(@Texture^.tb, Length(VertexBuffer));
 
-{$IFDEF GL2}
 UpdateModelviewProjection;
-{$ENDIF}
 
 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
 
@@ -551,9 +671,7 @@
     openglTranslatef(WorldDx, WorldDy, 0);
     glLineWidth(Width);
 
-    {$IFDEF GL2}
     UpdateModelviewProjection;
-    {$ENDIF}
 
     Tint(r, g, b, a);
     VertexBuffer[0].X:= X0;
@@ -680,9 +798,7 @@
     SetVertexPointer(@VertexBuffer[0], Length(VertexBuffer));
     SetTexCoordPointer(@TextureBuffer[0], Length(VertexBuffer));
 
-{$IFDEF GL2}
     UpdateModelviewProjection;
-{$ENDIF}
 
     glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
 
@@ -764,11 +880,10 @@
 
 procedure DrawWaterBody(pVertexBuffer: Pointer);
 begin
-{$IFDEF GL2}
         UpdateModelviewProjection;
-{$ENDIF}
 
         BeginWater;
+
         if SuddenDeathDmg then
             SetColorPointer(@SDWaterColorArray[0], 4)
         else
--- a/hedgewars/uStore.pas	Sat Jun 14 00:56:11 2014 +0200
+++ b/hedgewars/uStore.pas	Sat Jun 14 02:25:49 2014 +0200
@@ -44,8 +44,9 @@
 procedure LoadHedgehogHat(var HH: THedgehog; newHat: shortstring);
 procedure LoadHedgehogHat2(var HH: THedgehog; newHat: shortstring; allowSurfReuse: boolean);
 
+procedure InitZoom(zoom: real);
+
 procedure SetupOpenGL;
-procedure SetScale(f: GLfloat);
 function  RenderHelpWindow(caption, subcaption, description, extra: ansistring; extracolor: LongInt; iconsurf: PSDL_Surface; iconrect: PSDL_Rect): PTexture;
 procedure RenderWeaponTooltip(atype: TAmmoType);
 procedure ShowWeaponTooltip(x, y: LongInt);
@@ -62,18 +63,6 @@
 procedure SetSkyColor(r, g, b: real);
 
 {$IFDEF GL2}
-procedure UpdateModelviewProjection;
-{$ENDIF}
-
-procedure EnableTexture(enable:Boolean);
-
-procedure SetTexCoordPointer(p: Pointer;n: Integer);
-procedure SetVertexPointer(p: Pointer;n: Integer);
-procedure SetColorPointer(p: Pointer;n: Integer);
-
-procedure updateViewLimits();
-
-{$IFDEF GL2}
 var
     shaderMain: GLuint;
     shaderWater: GLuint;
@@ -112,6 +101,12 @@
     prevHat:= 'NoHat';
 end;
 
+procedure InitZoom(zoom: real);
+begin
+    SetScale(zoom);
+    UpdateViewLimits();
+end;
+
 function WriteInRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: PChar): TSDL_Rect;
 var w, h: LongInt;
     tmpsurf: PSDL_Surface;
@@ -1092,73 +1087,6 @@
     // disable/lower perspective correction (will not need it anyway)
 end;
 
-procedure EnableTexture(enable:Boolean);
-begin
-    {$IFDEF GL2}
-    if enable then
-        glUniform1i(glGetUniformLocation(shaderMain, pchar('enableTexture')), 1)
-    else
-        glUniform1i(glGetUniformLocation(shaderMain, pchar('enableTexture')), 0);
-    {$ELSE}
-    if enable then
-        glEnable(GL_TEXTURE_2D)
-    else
-        glDisable(GL_TEXTURE_2D);
-    {$ENDIF}
-end;
-
-procedure SetTexCoordPointer(p: Pointer; n: Integer);
-begin
-{$IFDEF GL2}
-    glBindBuffer(GL_ARRAY_BUFFER, tBuffer);
-    glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * n * 2, p, GL_STATIC_DRAW);
-    glEnableVertexAttribArray(aTexCoord);
-    glVertexAttribPointer(aTexCoord, 2, GL_FLOAT, GL_FALSE, 0, pointer(0));
-{$ELSE}
-    n:= n;
-    glTexCoordPointer(2, GL_FLOAT, 0, p);
-{$ENDIF}
-end;
-
-procedure SetVertexPointer(p: Pointer; n: Integer);
-begin
-{$IFDEF GL2}
-    glBindBuffer(GL_ARRAY_BUFFER, vBuffer);
-    glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * n * 2, p, GL_STATIC_DRAW);
-    glEnableVertexAttribArray(aVertex);
-    glVertexAttribPointer(aVertex, 2, GL_FLOAT, GL_FALSE, 0, pointer(0));
-{$ELSE}
-    n:= n;
-    glVertexPointer(2, GL_FLOAT, 0, p);
-{$ENDIF}
-end;
-
-procedure SetColorPointer(p: Pointer; n: Integer);
-begin
-{$IFDEF GL2}
-    glBindBuffer(GL_ARRAY_BUFFER, cBuffer);
-    glBufferData(GL_ARRAY_BUFFER, n * 4, p, GL_STATIC_DRAW);
-    glEnableVertexAttribArray(aColor);
-    glVertexAttribPointer(aColor, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, pointer(0));
-{$ELSE}
-    n:= n;
-    glColorPointer(4, GL_UNSIGNED_BYTE, 0, p);
-{$ENDIF}
-end;
-
-{$IFDEF GL2}
-procedure UpdateModelviewProjection;
-var
-    mvp: TMatrix4x4f;
-begin
-    //MatrixMultiply(mvp, mProjection, mModelview);
-{$HINTS OFF}
-    hglMVP(mvp);
-{$HINTS ON}
-    glUniformMatrix4fv(uCurrentMVPLocation, 1, GL_FALSE, @mvp[0, 0]);
-end;
-{$ENDIF}
-
 (*
 procedure UpdateProjection;
 var
@@ -1180,55 +1108,6 @@
 end;
 *)
 
-
-procedure updateViewLimits();
-var tmp: real;
-begin
-    // cScaleFactor is 2.0 on "no zoom"
-    tmp:= cScreenWidth / cScaleFactor;
-    ViewRightX:= round(tmp); // ceil could make more sense
-    ViewLeftX:= round(-tmp); // floor could make more sense
-    tmp:= cScreenHeight / cScaleFactor;
-    ViewBottomY:= round(tmp) + cScreenHeight div 2; // ceil could make more sense
-    ViewTopY:= round(-tmp) + cScreenHeight div 2; // floor could make more sense
-end;
-
-procedure SetScale(f: GLfloat);
-begin
-// leave immediately if scale factor did not change
-    if f = cScaleFactor then
-        exit;
-
-    if f = cDefaultZoomLevel then
-{$IFDEF GL2}
-        hglPopMatrix         // "return" to default scaling
-{$ELSE}
-        glPopMatrix
-{$ENDIF}
-    else                    // other scaling
-        begin
-{$IFDEF GL2}
-        hglPushMatrix;       // save default scaling
-        hglLoadIdentity;
-        hglScalef(f / cScreenWidth, -f / cScreenHeight, 1.0);
-        hglTranslatef(0, -cScreenHeight / 2, 0);
-{$ELSE}
-        glPushMatrix;       // save default scaling
-        glLoadIdentity;
-        glScalef(f / cScreenWidth, -f / cScreenHeight, 1.0);
-        glTranslatef(0, -cScreenHeight / 2, 0);
-{$ENDIF}
-        end;
-
-    cScaleFactor:= f;
-    updateViewLimits();
-
-{$IFDEF GL2}
-    UpdateModelviewProjection;
-{$ENDIF}
-end;
-
-
 ////////////////////////////////////////////////////////////////////////////////
 procedure AddProgress;
 var r: TSDL_Rect;
--- a/hedgewars/uVisualGears.pas	Sat Jun 14 00:56:11 2014 +0200
+++ b/hedgewars/uVisualGears.pas	Sat Jun 14 02:25:49 2014 +0200
@@ -47,7 +47,7 @@
 procedure KickFlakes(Radius, X, Y: LongInt);
 
 implementation
-uses uVariables, uRender, Math, uRenderUtils, uStore, uUtils
+uses uVariables, uRender, Math, uRenderUtils, uUtils
     , uVisualGearsList;
 
 procedure AddDamageTag(X, Y, Damage, Color: LongWord);