- Start chat implementation: chat strings are on the screen
authorunc0rr
Sat, 24 May 2008 17:34:06 +0000 (2008-05-24)
changeset 945 4ead9cde4e14
parent 944 9299c0ebfdbc
child 946 42c5cc87cbd1
- Start chat implementation: chat strings are on the screen - Fix teleportation on water regression
hedgewars/GSHandlers.inc
hedgewars/SDLh.pas
hedgewars/uChat.pas
hedgewars/uIO.pas
hedgewars/uMisc.pas
hedgewars/uVisualGears.pas
--- a/hedgewars/GSHandlers.inc	Thu May 22 17:25:12 2008 +0000
+++ b/hedgewars/GSHandlers.inc	Sat May 24 17:34:06 2008 +0000
@@ -1235,7 +1235,8 @@
 HHGear:= PHedgehog(Gear^.Hedgehog)^.Gear;
 HHGear^.Y:= HHGear^.Y + HHGear^.dY; // hedgehog falling to collect cases
 HHGear^.dY:= HHGear^.dY + cGravity;
-if TestCollisionYwithGear(HHGear, 1) then
+if TestCollisionYwithGear(HHGear, 1)
+   or CheckGearDrowning(HHGear) then
    begin
    DeleteGear(Gear);
    AfterAttack
--- a/hedgewars/SDLh.pas	Thu May 22 17:25:12 2008 +0000
+++ b/hedgewars/SDLh.pas	Sat May 24 17:34:06 2008 +0000
@@ -51,7 +51,7 @@
       SDL_HWACCEL     = $00000100;
       SDL_SRCCOLORKEY = $00001000;
       SDL_RLEACCEL    = $00004000;
-      
+
       SDL_NOEVENT     = 0;
       SDL_ACTIVEEVENT = 1;
       SDL_KEYDOWN     = 2;
@@ -197,7 +197,7 @@
 
      PSDL_Thread = Pointer;
      PSDL_mutex = Pointer;
-     
+
 function  SDL_Init(flags: Longword): LongInt; cdecl; external SDLLibName;
 procedure SDL_Quit; cdecl; external SDLLibName;
 function  SDL_VideoDriverName(var namebuf; maxlen: LongInt): PChar; cdecl; external SDLLibName;
@@ -276,6 +276,7 @@
    See http://www.freepascal.org/mantis/view.php?id=7613 for details *)
 function TTF_RenderUTF8_Solid(font: PTTF_Font; const text: PChar; fg: Longword): PSDL_Surface; cdecl; external SDL_TTFLibName;
 function TTF_RenderUTF8_Blended(font: PTTF_Font; const text: PChar; fg: Longword): PSDL_Surface; cdecl; external SDL_TTFLibName;
+function TTF_RenderUTF8_Shaded(font: PTTF_Font; const text: PChar; fg, bg: Longword): PSDL_Surface; cdecl; external SDL_TTFLibName;
 
 function TTF_OpenFont(const filename: PChar; size: LongInt): PTTF_Font; cdecl; external SDL_TTFLibName;
 procedure TTF_SetFontStyle(font: PTTF_Font; style: LongInt); cdecl; external SDL_TTFLibName;
--- a/hedgewars/uChat.pas	Thu May 22 17:25:12 2008 +0000
+++ b/hedgewars/uChat.pas	Sat May 24 17:34:06 2008 +0000
@@ -24,7 +24,7 @@
 procedure DrawChat;
 
 implementation
-uses uMisc, uStore, uConsts;
+uses uMisc, uStore, uConsts, SDLh;
 
 const MaxStrIndex = 7;
 
@@ -35,18 +35,58 @@
 
 var Strs: array[0 .. MaxStrIndex] of TStr;
 	lastStr: Longword = 0;
+	visibleCount: Longword = 0;
 
 procedure AddChatString(s: shortstring);
+var strSurface, resSurface: PSDL_Surface;
+    r: TSDL_Rect;
+    w, h: LongInt;
 begin
 lastStr:= (lastStr + 1) mod (MaxStrIndex + 1);
 
+TTF_SizeUTF8(Fontz[fnt16].Handle, Str2PChar(s), w, h);
+
+resSurface:= SDL_CreateRGBSurface(0,
+		toPowerOf2(w + 2),
+		toPowerOf2(h + 2),
+		32,
+		RMask, GMask, BMask, AMask);
+
+strSurface:= TTF_RenderUTF8_Solid(Fontz[fnt16].Handle, Str2PChar(s), $202020);
+r.x:= 1;
+r.y:= 1;
+SDL_UpperBlit(strSurface, nil, resSurface, @r);
+
+strSurface:= TTF_RenderUTF8_Solid(Fontz[fnt16].Handle, Str2PChar(s), $FFFFFF);
+SDL_UpperBlit(strSurface, nil, resSurface, nil);
+
+SDL_FreeSurface(strSurface);
+
+
 Strs[lastStr].Time:= RealTicks + 7500;
-Strs[lastStr].Tex:= RenderStringTex(s, $FFFFFF, fnt16)
+Strs[lastStr].Tex:= Surface2Tex(resSurface);
+SDL_FreeSurface(resSurface);
+
+inc(visibleCount)
 end;
 
 procedure DrawChat;
+var i, t, cnt: Longword;
 begin
-if Strs[lastStr].Tex <> nil then DrawTexture(10, 10, Strs[lastStr].Tex)
+cnt:= 0;
+t:= 0;
+i:= lastStr;
+while (t <= MaxStrIndex)
+	and (Strs[i].Tex <> nil)
+	and (Strs[i].Time > RealTicks) do
+	begin
+	DrawTexture(8, (visibleCount - t) * 16 - 8, Strs[i].Tex);
+	if i = 0 then i:= MaxStrIndex else dec(i);
+	inc(cnt);
+	inc(t)
+	end;
+
+visibleCount:= cnt
 end;
 
 end.
--- a/hedgewars/uIO.pas	Thu May 22 17:25:12 2008 +0000
+++ b/hedgewars/uIO.pas	Sat May 24 17:34:06 2008 +0000
@@ -37,7 +37,7 @@
 var hiTicks: Word = 0;
 
 implementation
-uses uConsole, uConsts, uWorld, uMisc, uLand;
+uses uConsole, uConsts, uWorld, uMisc, uLand, uChat;
 const isPonged: boolean = false;
 
 type PCmd = ^TCmd;
@@ -212,11 +212,14 @@
 
 procedure NetGetNextCmd;
 var tmpflag: boolean;
+    s: shortstring;
 begin
 while (headcmd <> nil) and (headcmd^.cmd = 's') do
       begin
-      WriteLnToConsole('> ' + copy(headcmd^.str, 2, Pred(headcmd^.len)));
-      AddCaption('> ' + copy(headcmd^.str, 2, Pred(headcmd^.len)), $FFFFFF, capgrpNetSay);
+      s:= '> ' + copy(headcmd^.str, 2, Pred(headcmd^.len));
+      AddChatString(s);
+      WriteLnToConsole(s);
+      //AddCaption('> ' + copy(headcmd^.str, 2, Pred(headcmd^.len)), $FFFFFF, capgrpNetSay);
       RemoveCmd
       end;
 
--- a/hedgewars/uMisc.pas	Thu May 22 17:25:12 2008 +0000
+++ b/hedgewars/uMisc.pas	Sat May 24 17:34:06 2008 +0000
@@ -117,6 +117,7 @@
 function  Str2PChar(const s: shortstring): PChar;
 function  Surface2Tex(surf: PSDL_Surface): PTexture;
 procedure FreeTexture(tex: PTexture);
+function  toPowerOf2(i: Longword): Longword;
 
 var CursorPoint: TPoint;
     TargetPoint: TPoint = (X: NoPointX; Y: 0);
--- a/hedgewars/uVisualGears.pas	Thu May 22 17:25:12 2008 +0000
+++ b/hedgewars/uVisualGears.pas	Sat May 24 17:34:06 2008 +0000
@@ -32,6 +32,7 @@
              Y : hwFloat;
              dX: hwFloat;
              dY: hwFloat;
+             mdY: QWord;
              Angle, dAngle: real;
              Kind: TVisualGearType;
              doStep: TVGearStepProcedure;
@@ -119,7 +120,8 @@
                dx.isNegative:= random(2) = 0;
                dx.QWordValue:= random(214748364);
                dy.isNegative:= random(2) = 0;
-               dy.QWordValue:= 21474836 + random(64424509)
+               dy.QWordValue:= 21474836 + random(64424509);
+               mdY:= dy.QWordValue
                end;
      end;