tweak code of DrawTextureFromRectDir a bit, removing issue with different x offset depending on dir. also removing the workaround wrt that issue in the frozen hog code
authorsheepluva
Wed, 18 Jun 2014 01:37:28 +0200
changeset 10324 5d90d8ca9657
parent 10323 72e6df962cb6
child 10325 7315870716f2
tweak code of DrawTextureFromRectDir a bit, removing issue with different x offset depending on dir. also removing the workaround wrt that issue in the frozen hog code
hedgewars/uGearsRender.pas
hedgewars/uRender.pas
--- a/hedgewars/uGearsRender.pas	Wed Jun 18 17:36:46 2014 +0400
+++ b/hedgewars/uGearsRender.pas	Wed Jun 18 01:37:28 2014 +0200
@@ -1019,10 +1019,7 @@
         r.y := 96 - iceOffset;
         r.w := 32;
         r.h := iceOffset;
-        if sign = -1 then
-        DrawTextureFromRectDir(sx + sign*2, sy+16-iceoffset, r.w, r.h, @r, HHTexture, sign)
-        else
-        DrawTextureFromRectDir(sx-16 + sign*2, sy+16-iceoffset, r.w, r.h, @r, HHTexture, sign);
+        DrawTextureFromRectDir(sx - 16 + sign*2, sy + 16 - iceoffset, r.w, r.h, @r, HHTexture, sign);
 
 
         if HH^.Effects[heFrozen] < 150000 then
--- a/hedgewars/uRender.pas	Wed Jun 18 17:36:46 2014 +0400
+++ b/hedgewars/uRender.pas	Wed Jun 18 01:37:28 2014 +0200
@@ -698,9 +698,9 @@
 end;
 
 procedure DrawTextureFromRectDir(X, Y, W, H: LongInt; r: PSDL_Rect; SourceTexture: PTexture; Dir: LongInt);
-var rr: TSDL_Rect;
-    _l, _r, _t, _b: real;
+var _l, _r, _t, _b: real;
     VertexBuffer, TextureBuffer: array [0..3] of TVertex2f;
+    xw, yh: LongInt;
 begin
 if (SourceTexture^.h = 0) or (SourceTexture^.w = 0) then
     exit;
@@ -716,40 +716,33 @@
 if (abs(Y) > H) and ((abs(Y + H / 2 - (0.5 * cScreenHeight)) - H / 2) * 2 > ViewHeight) then
     exit;
 
-rr.x:= X;
-rr.y:= Y;
-rr.w:= W;
-rr.h:= H;
-
 _l:= r^.x / SourceTexture^.w * SourceTexture^.rx;
 _r:= (r^.x + r^.w) / SourceTexture^.w * SourceTexture^.rx;
+
+// if direction is mirrored, switch left and right
+if Dir < 0 then
+    begin
+    _t:= _l;
+    _l:= _r;
+    _r:= _t;
+    end;
+
 _t:= r^.y / SourceTexture^.h * SourceTexture^.ry;
 _b:= (r^.y + r^.h) / SourceTexture^.h * SourceTexture^.ry;
 
 glBindTexture(GL_TEXTURE_2D, SourceTexture^.id);
 
-if Dir < 0 then
-    begin
-    VertexBuffer[0].X:= X + rr.w div 2;
-    VertexBuffer[0].Y:= Y;
-    VertexBuffer[1].X:= X - rr.w div 2;
-    VertexBuffer[1].Y:= Y;
-    VertexBuffer[2].X:= X - rr.w div 2;
-    VertexBuffer[2].Y:= rr.h + Y;
-    VertexBuffer[3].X:= X + rr.w div 2;
-    VertexBuffer[3].Y:= rr.h + Y;
-    end
-else
-    begin
-    VertexBuffer[0].X:= X;
-    VertexBuffer[0].Y:= Y;
-    VertexBuffer[1].X:= rr.w + X;
-    VertexBuffer[1].Y:= Y;
-    VertexBuffer[2].X:= rr.w + X;
-    VertexBuffer[2].Y:= rr.h + Y;
-    VertexBuffer[3].X:= X;
-    VertexBuffer[3].Y:= rr.h + Y;
-    end;
+xw:= X + W;
+yh:= Y + H;
+
+VertexBuffer[0].X:= X;
+VertexBuffer[0].Y:= Y;
+VertexBuffer[1].X:= xw;
+VertexBuffer[1].Y:= Y;
+VertexBuffer[2].X:= xw;
+VertexBuffer[2].Y:= yh;
+VertexBuffer[3].X:= X;
+VertexBuffer[3].Y:= yh;
 
 TextureBuffer[0].X:= _l;
 TextureBuffer[0].Y:= _t;