various tweaks
authorsheepluva
Mon, 16 Jun 2014 02:23:37 +0200
changeset 10312 eda8d563f677
parent 10311 30b5fab302f6
child 10313 769061317dc5
various tweaks
hedgewars/uChat.pas
hedgewars/uGearsRender.pas
hedgewars/uRender.pas
hedgewars/uScript.pas
hedgewars/uWorld.pas
--- a/hedgewars/uChat.pas	Sun Jun 15 23:48:06 2014 +0200
+++ b/hedgewars/uChat.pas	Mon Jun 16 02:23:37 2014 +0200
@@ -32,7 +32,7 @@
 procedure SendHogSpeech(s: shortstring);
 
 implementation
-uses SDLh, uInputHandler, uTypes, uVariables, uCommands, uUtils, uTextures, uRender, uIO;
+uses SDLh, uInputHandler, uTypes, uVariables, uCommands, uUtils, uTextures, uRender, uIO, uScript, uConsole;
 
 const MaxStrIndex = 27;
 
@@ -57,6 +57,7 @@
     InputStrL: array[0..260] of char; // for full str + 4-byte utf-8 char
     ChatReady: boolean;
     showAll: boolean;
+    liveLua: boolean;
 
 const
     colors: array[#0..#6] of TSDL_Color = (
@@ -287,6 +288,10 @@
 
 if (s[1] = '/') then
     begin
+    // put in input history
+    localLastStr:= (localLastStr + 1) mod MaxStrIndex;
+    LocalStrs[localLastStr]:= s;
+
     // These 3 are same as above, only are to make the hedgehog say it on next attack
     if (copy(s, 2, 4) = 'hsa ') then
         begin
@@ -335,6 +340,27 @@
         exit
         end;
 
+    if (copy(s, 2, 3) = 'lua') then
+        begin
+        AddFileLog('/lua issued');
+        if gameType <> gmtNet then
+            begin
+            liveLua:= (not liveLua);
+            if liveLua then
+                begin
+                AddFileLog('[Lua] chat input string parsing enabled');
+                AddChatString(#3 + 'Lua parsing: ON');
+                end
+            else
+                begin
+                AddFileLog('[Lua] chat input string parsing disabled');
+                AddChatString(#3 + 'Lua parsing: OFF');
+                end;
+            end;
+        exit
+        end;
+
+    // hedghog animations/taunts and engine commands
     if (not CurrentTeam^.ExtDriven) and (CurrentTeam^.Hedgehogs[0].BotLevel = 0) then
         begin
         for i:= Low(TWave) to High(TWave) do
@@ -352,8 +378,13 @@
                 end;
         end
     end
+else
+    begin
+    if liveLua then
+        LuaParseString(s)
     else
         ParseCommand('/say ' + s, true);
+    end;
 end;
 
 procedure CleanupInput;
@@ -510,6 +541,7 @@
     showAll:= false;
     ChatReady:= false;
     missedCount:= 0;
+    liveLua:= false;
 
     inputStr.Tex := nil;
     for i:= 0 to MaxStrIndex do
--- a/hedgewars/uGearsRender.pas	Sun Jun 15 23:48:06 2014 +0200
+++ b/hedgewars/uGearsRender.pas	Mon Jun 16 02:23:37 2014 +0200
@@ -963,12 +963,20 @@
                 if (cTagsMask and htHealth) <> 0 then
                     ty := ty - HealthTagTex^.h - 2;
                 tx := ox;
-                tx := round(max(((-cScreenWidth + 16) / cScaleFactor) + SpritesData[sprFinger].Width div 2, min(((cScreenWidth - 16) / cScaleFactor) - SpritesData[sprFinger].Width div 2, tx)));
-                ty := round(max(cScreenHeight div 2 - ((cScreenHeight - 16) / cScaleFactor) + SpritesData[sprFinger].Height div 2, min(cScreenHeight div 2 - ((-cScreenHeight + SpritesData[sprFinger].Height) / (cScaleFactor)) - SpritesData[sprFinger].Width div 2 - 96, ty)));
+
+                // don't go offscreen
+                //tx := round(max(((-cScreenWidth + 16) / cScaleFactor) + SpritesData[sprFinger].Width div 2, min(((cScreenWidth - 16) / cScaleFactor) - SpritesData[sprFinger].Width div 2, tx)));
+                //ty := round(max(cScreenHeight div 2 - ((cScreenHeight - 16) / cScaleFactor) + SpritesData[sprFinger].Height div 2, min(cScreenHeight div 2 - ((-cScreenHeight + SpritesData[sprFinger].Height) / (cScaleFactor)) - SpritesData[sprFinger].Width div 2 - 96, ty)));
+                t:= 32;//trunc((SpritesData[sprFinger].Width + t) / cScaleFactor);
+                tx := min(max(tx, ViewLeftX + t), ViewRightX  - t);
+                t:= 32;//trunc((SpritesData[sprFinger].Height + t) / cScaleFactor);
+                ty := min(ty, ViewBottomY - 96);
+                // don't overlap with HH or HH tags
+                if ty < ViewTopY + t then ty:= max(ViewTopY + t, oy + t);
 
                 dAngle := DxDy2Angle(int2hwfloat(ty - oy), int2hwfloat(tx - ox)) + 90;
 
-                DrawSpriteRotatedF(sprFinger, tx, ty, GameTicks div 32 mod 16, 1, dAngle);
+                DrawSpriteRotatedF(sprFinger, tx, ty, RealTicks div 32 mod 16, 1, dAngle);
                 end;
 
 
--- a/hedgewars/uRender.pas	Sun Jun 15 23:48:06 2014 +0200
+++ b/hedgewars/uRender.pas	Mon Jun 16 02:23:37 2014 +0200
@@ -633,11 +633,11 @@
 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
+    ViewRightX:= 1 + round(tmp);
+    ViewLeftX:= round(-tmp);
     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
+    ViewBottomY:= 1 + round(tmp) + cScreenHeight div 2;
+    ViewTopY:= round(-tmp) + cScreenHeight div 2;
 
     // visual debugging fun :D
     if cViewLimitsDebug then
@@ -919,16 +919,34 @@
 procedure DrawSpriteRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real);
 begin
 
+if Angle <> 0  then
+    begin
+    // sized doubled because the sprite might occupy up to 1.4 * of it's
+    // original size in each dimension, because it is rotated
+    if isDxAreaOffscreen(X - SpritesData[Sprite].Width, 2 * SpritesData[Sprite].Width) <> 0 then
+        exit;
+    if isDYAreaOffscreen(Y - SpritesData[Sprite].Height, 2 * SpritesData[Sprite].Height) <> 0 then
+        exit;
+    end
+else
+    begin
+    if isDxAreaOffscreen(X - SpritesData[Sprite].Width div 2, SpritesData[Sprite].Width) <> 0 then
+        exit;
+    if isDYAreaOffscreen(Y - SpritesData[Sprite].Height div 2 , SpritesData[Sprite].Height) <> 0 then
+        exit;
+    end;
+
+
 openglPushMatrix;
 openglTranslatef(X, Y, 0);
 
+// mirror
 if Dir < 0 then
-    begin
-    openglRotatef(Angle, 0, 0, -1);
     openglScalef(-1.0, 1.0, 1.0);
-    end
-else
-    openglRotatef(Angle, 0, 0,  1);
+
+// apply angle after (conditional) mirroring
+if Angle <> 0  then
+    openglRotatef(Angle, 0, 0, 1);
 
 DrawSprite(Sprite, -SpritesData[Sprite].Width div 2, -SpritesData[Sprite].Height div 2, Frame);
 
--- a/hedgewars/uScript.pas	Sun Jun 15 23:48:06 2014 +0200
+++ b/hedgewars/uScript.pas	Mon Jun 16 02:23:37 2014 +0200
@@ -48,6 +48,7 @@
 function ScriptCall(fname : shortstring; par1, par2, par3, par4 : LongInt) : LongInt;
 function ScriptExists(fname : shortstring) : boolean;
 
+procedure LuaParseString(s: shortString);
 
 //function ParseCommandOverride(key, value : shortstring) : shortstring;  This did not work out well
 
@@ -107,6 +108,17 @@
 
 var LuaDebugInfo: lua_Debug;
 
+procedure LuaParseString(s: shortString);
+begin
+    AddFileLog('[Lua] input string: ' + s);
+    AddChatString(#3 + '[Lua] > ' + s);
+    if luaL_dostring(luaState, Str2PChar(s)) <> 0 then
+        begin
+        AddFileLog('[Lua] input string parsing error!');
+        AddChatString(#5 + '[Lua] Error while parsing!');
+        end;
+end;
+
 function LuaUpdateDebugInfo(): Boolean;
 begin
     FillChar(LuaDebugInfo, sizeof(LuaDebugInfo), 0);
@@ -2384,8 +2396,8 @@
 
 if ret <> 0 then
     begin
-    LuaError('Lua: Failed to load ' + name + '(error ' + IntToStr(ret) + ')');
-    LuaError('Lua: ' + lua_tostring(luaState, -1));
+    LuaError('Failed to load ' + name + '(error ' + IntToStr(ret) + ')');
+    LuaError(lua_tostring(luaState, -1));
     end
 else
     begin
@@ -2431,7 +2443,7 @@
 lua_getglobal(luaState, Str2PChar(fname));
 if lua_pcall(luaState, 0, 0, 0) <> 0 then
     begin
-    LuaError('Lua: Error while calling ' + fname + ': ' + lua_tostring(luaState, -1));
+    LuaError('Error while calling ' + fname + ': ' + lua_tostring(luaState, -1));
     lua_pop(luaState, 1)
     end;
 GetGlobals;
@@ -2487,7 +2499,7 @@
 ScriptCall:= 0;
 if lua_pcall(luaState, 4, 1, 0) <> 0 then
     begin
-    LuaError('Lua: Error while calling ' + fname + ': ' + lua_tostring(luaState, -1));
+    LuaError('Error while calling ' + fname + ': ' + lua_tostring(luaState, -1));
     lua_pop(luaState, 1)
     end
 else
--- a/hedgewars/uWorld.pas	Sun Jun 15 23:48:06 2014 +0200
+++ b/hedgewars/uWorld.pas	Mon Jun 16 02:23:37 2014 +0200
@@ -792,9 +792,14 @@
 
 procedure DrawWater(Alpha: byte; OffsetY: LongInt);
 var VertexBuffer : array [0..3] of TVertex2f;
-    r        : TSDL_Rect;
-    lw, lh   : GLfloat;
+    topy: LongInt;
 begin
+    // Water
+topy:= OffsetY + WorldDy + cWaterLine;
+
+if topy > ViewBottomY then
+    exit;
+
 if SuddenDeathDmg then
     begin
     SDWaterColorArray[0].a := Alpha;
@@ -810,41 +815,40 @@
     WaterColorArray[3].a := Alpha
     end;
 
-lw:= cScreenWidth / cScaleFactor;
-lh:= trunc(cScreenHeight / cScaleFactor) + cScreenHeight div 2 + 16;
-
-    // Water
-r.y:= OffsetY + WorldDy + cWaterLine;
-if WorldDy < trunc(cScreenHeight / cScaleFactor) + cScreenHeight div 2 - cWaterLine then
-    begin
-        if r.y < 0 then
-            r.y:= 0;
+if topy < 0 then
+    topy:= 0;
 
-        glDisable(GL_TEXTURE_2D);
-        VertexBuffer[0].X:= -lw;
-        VertexBuffer[0].Y:= r.y;
-        VertexBuffer[1].X:= lw;
-        VertexBuffer[1].Y:= r.y;
-        VertexBuffer[2].X:= lw;
-        VertexBuffer[2].Y:= lh;
-        VertexBuffer[3].X:= -lw;
-        VertexBuffer[3].Y:= lh;
+glDisable(GL_TEXTURE_2D);
+VertexBuffer[0].X:= -ViewWidth;
+VertexBuffer[0].Y:=  topy;
+VertexBuffer[1].X:=  ViewWidth;
+VertexBuffer[1].Y:=  topy;
+VertexBuffer[2].X:=  ViewWidth;
+VertexBuffer[2].Y:=  ViewBottomY;
+VertexBuffer[3].X:= -ViewWidth;
+VertexBuffer[3].Y:=  ViewBottomY;
 
-        DrawWaterBody(@VertexBuffer[0]);
+DrawWaterBody(@VertexBuffer[0]);
 
 {$IFNDEF GL2}
-        // must not be Tint() as color array seems to stay active and color reset is required
-        glColor4ub($FF, $FF, $FF, $FF);
+// must not be Tint() as color array seems to stay active and color reset is required
+glColor4ub($FF, $FF, $FF, $FF);
 {$ENDIF}
-        glEnable(GL_TEXTURE_2D);
-    end;
+glEnable(GL_TEXTURE_2D);
 end;
 
 procedure DrawWaves(Dir, dX, dY: LongInt; tnt: Byte);
 var VertexBuffer, TextureBuffer: array [0..3] of TVertex2f;
     lw, waves, shift: GLfloat;
     sprite: TSprite;
+    topy: LongInt;
 begin
+
+topy:= cWaterLine + WorldDy + dY;
+
+if topY > ViewBottomY then
+    exit;
+
 if SuddenDeathDmg then
     sprite:= sprSDWater
 else
@@ -852,7 +856,7 @@
 
 cWaveWidth:= SpritesData[sprite].Width;
 
-lw:= cScreenWidth / cScaleFactor;
+lw:= ViewWidth;
 waves:= lw * 2 / cWaveWidth;
 
 if SuddenDeathDmg then