DEADSOFTWARE

Merge branch 'master' of ssh://repo.or.cz/d2df-sdl
[d2df-sdl.git] / src / game / g_game.pas
index f696accdf385baf3a40b56daa97ac22f6f8e678a..4135b5af5794f8f3aeeaf8275e764f08a32f9dfa 100644 (file)
@@ -1538,8 +1538,8 @@ begin
       Exit;
   end;
 
-// ×èòàåì êëàâèàòóðó è äæîéñòèê, åñëè îêíî àêòèâíî:
-  e_PollInput();
+  // ×èòàåì êëàâèàòóðó è äæîéñòèê, åñëè îêíî àêòèâíî
+  // no need to, as we'll do it in event handler
 
 // Îáíîâëÿåì êîíñîëü (äâèæåíèå è ñîîáùåíèÿ):
   g_Console_Update();
@@ -2054,12 +2054,12 @@ begin
   g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD+':TEXTURES\JETBAR');
   g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD+':TEXTURES\HUDBG');
   g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD+':TEXTURES\ARMORHUD');
-  g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD+':TEXTURES\FLAGHUD_RB', GameWAD+':TEXTURES\FLAGHUD_R_BASE');
-  g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD+':TEXTURES\FLAGHUD_RS', GameWAD+':TEXTURES\FLAGHUD_R_STOLEN');
-  g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD+':TEXTURES\FLAGHUD_RD', GameWAD+':TEXTURES\FLAGHUD_R_DROP');
-  g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD+':TEXTURES\FLAGHUD_BB', GameWAD+':TEXTURES\FLAGHUD_B_BASE');
-  g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD+':TEXTURES\FLAGHUD_BS', GameWAD+':TEXTURES\FLAGHUD_B_STOLEN');
-  g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD+':TEXTURES\FLAGHUD_BD', GameWAD+':TEXTURES\FLAGHUD_B_DROP');
+  g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD+':TEXTURES\FLAGHUD_R_BASE');
+  g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD+':TEXTURES\FLAGHUD_R_STOLEN');
+  g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD+':TEXTURES\FLAGHUD_R_DROP');
+  g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD+':TEXTURES\FLAGHUD_B_BASE');
+  g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD+':TEXTURES\FLAGHUD_B_STOLEN');
+  g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD+':TEXTURES\FLAGHUD_B_DROP');
   g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD+':TEXTURES\TALKBUBBLE');
   g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD+':TEXTURES\PENTA');
   g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD+':TEXTURES\TELEPORT', 64, 64, 10, False);
@@ -2182,7 +2182,8 @@ var
 begin
   e_TextureFontGetSize(gStdFont, ww2, hh2);
 
-  e_PollInput();
+  g_ProcessMessages();
+
   if e_KeyPressed(IK_TAB) then
   begin
     if not gStatsPressed then
@@ -2503,13 +2504,60 @@ begin
 end;
 
 procedure DrawLoadingStat();
+  procedure drawRect (x, y, w, h: Integer);
+  begin
+    if (w < 1) or (h < 1) then exit;
+    glBegin(GL_QUADS);
+      glVertex2f(x+0.375, y+0.375);
+      glVertex2f(x+w+0.375, y+0.375);
+      glVertex2f(x+w+0.375, y+h+0.375);
+      glVertex2f(x+0.375, y+h+0.375);
+    glEnd();
+  end;
+
+  procedure drawPBar (cur, total: Integer);
+  var
+    rectW, rectH: Integer;
+    x0, y0: Integer;
+    wdt: Integer;
+  begin
+    if (total < 1) then exit;
+    if (cur < 1) then exit; // don't blink
+    if (cur >= total) then exit; // don't blink
+    //if (cur < 0) then cur := 0;
+    //if (cur > total) then cur := total;
+
+    rectW := gScreenWidth-64;
+    rectH := 16;
+
+    x0 := (gScreenWidth-rectW) div 2;
+    y0 := gScreenHeight-rectH-64;
+    if (y0 < 2) then y0 := 2;
+
+    glDisable(GL_BLEND);
+    glDisable(GL_TEXTURE_2D);
+
+    //glClearColor(0, 0, 0, 0);
+    //glClear(GL_COLOR_BUFFER_BIT);
+
+    glColor4ub(127, 127, 127, 255);
+    drawRect(x0-2, y0-2, rectW+4, rectH+4);
+
+    glColor4ub(0, 0, 0, 255);
+    drawRect(x0-1, y0-1, rectW+2, rectH+2);
+
+    glColor4ub(127, 127, 127, 255);
+    wdt := rectW*cur div total;
+    if (wdt > rectW) then wdt := rectW;
+    drawRect(x0, y0, wdt, rectH);
+  end;
+
 var
   ww, hh: Word;
   xx, yy, i: Integer;
   s: String;
 begin
-  if Length(LoadingStat.Msgs) = 0 then
-    Exit;
+  if (Length(LoadingStat.Msgs) = 0) then exit;
 
   e_CharFont_GetSize(gMenuFont, _lc[I_MENU_LOADING], ww, hh);
   yy := (gScreenHeight div 3);
@@ -2517,16 +2565,19 @@ begin
   xx := (gScreenWidth div 3);
 
   with LoadingStat do
+  begin
     for i := 0 to NextMsg-1 do
-      begin
-        if (i = (NextMsg-1)) and (MaxValue > 0) then
-          s := Format('%s:  %d/%d', [Msgs[i], CurValue, MaxValue])
-        else
-          s := Msgs[i];
+    begin
+      if (i = (NextMsg-1)) and (MaxValue > 0) then
+        s := Format('%s:  %d/%d', [Msgs[i], CurValue, MaxValue])
+      else
+        s := Msgs[i];
 
-        e_CharFont_PrintEx(gMenuSmallFont, xx, yy, s, _RGB(255, 0, 0));
-        yy := yy + LOADING_INTERLINE;
-      end;
+      e_CharFont_PrintEx(gMenuSmallFont, xx, yy, s, _RGB(255, 0, 0));
+      yy := yy + LOADING_INTERLINE;
+      drawPBar(CurValue, MaxValue);
+    end;
+  end;
 end;
 
 procedure DrawMinimap(p: TPlayer; RenderRect: e_graphics.TRect);
@@ -4136,6 +4187,7 @@ begin
           enet_packet_destroy(NetEvent.packet);
       end
       else
+      begin
         if (NetEvent.kind = ENET_EVENT_TYPE_DISCONNECT) then
         begin
           State := 0;
@@ -4145,12 +4197,11 @@ begin
           OuterLoop := False;
           Break;
         end;
+      end;
     end;
 
     ProcessLoading(true);
 
-    e_PollInput();
-
     if e_KeyPressed(IK_ESCAPE) or e_KeyPressed(IK_SPACE) then
     begin
       State := 0;
@@ -6008,7 +6059,7 @@ begin
         if P[2] = '' then
           g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
         else
-          g_Console_Add(Format(_lc[I_MSG_NO_MAP], [UpperCase(P[2])]));
+          g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [UpperCase(P[2]), P[1]]));
     end else
       g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
   end
@@ -6062,7 +6113,7 @@ begin
         if P[4] = '' then
           g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[3]]))
         else
-          g_Console_Add(Format(_lc[I_MSG_NO_MAP], [UpperCase(P[4])]));
+          g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [UpperCase(P[4]), P[3]]));
     end else
       g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[3]]));
   end
@@ -6096,9 +6147,9 @@ begin
               g_Game_ChangeMap(s);
           end else
           begin
-            g_Console_Add(Format(_lc[I_MSG_NO_MAP], [s]));
             // Òàêîé êàðòû íåò, èùåì WAD ôàéë
             P[1] := addWadExtension(P[1]);
+            g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [s, P[1]]));
             if FileExists(MapsDir + P[1]) then
             begin
               // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
@@ -6185,9 +6236,9 @@ begin
               nm := True;
             end else
             begin
-              g_Console_Add(Format(_lc[I_MSG_NO_MAP], [s]));
               // Òàêîé êàðòû íåò, èùåì WAD ôàéë
               P[1] := addWadExtension(P[1]);
+              g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [s, P[1]]));
               if FileExists(MapsDir + P[1]) then
               begin
                 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
@@ -7138,6 +7189,11 @@ begin
     if (s <> '') then
       gMapOnce := True;
 
+  // Override map to test:
+    s := LowerCase(Find_Param_Value(pars, '-testmap'));
+    if s <> '' then
+      gTestMap := MapsDir + s;
+
   // Delete test map after play:
     s := Find_Param_Value(pars, '--testdelete');
     if (s <> '') then
@@ -7149,9 +7205,9 @@ begin
 
   // Delete temporary WAD after play:
     s := Find_Param_Value(pars, '--tempdelete');
-    if (s <> '') then
+    if (s <> '') and (gTestMap <> '') then
     begin
-      gMapToDelete := MapsDir + map;
+      gMapToDelete := gTestMap;
       gTempDelete := True;
     end;