DEADSOFTWARE

Added new OpenGL ES wrapper
[d2df-sdl.git] / src / game / g_game.pas
index 80fb0531df35051f2b53f7eef73719392ca9460d..bb112696f83a22627358153f194e37ab0719d729 100644 (file)
@@ -137,7 +137,7 @@ procedure GameCheats(P: SSArray);
 procedure DebugCommands(P: SSArray);
 procedure g_Game_Process_Params;
 procedure g_Game_SetLoadingText(Text: String; Max: Integer; reWrite: Boolean);
-procedure g_Game_StepLoading();
+procedure g_Game_StepLoading(Value: Integer = -1);
 procedure g_Game_ClearLoading();
 procedure g_Game_SetDebugMode();
 procedure DrawLoadingStat();
@@ -315,6 +315,8 @@ var
   gChatSounds: Array of TChatSound;
 
   g_dbg_ignore_bounds: Boolean = false;
+  r_smallmap_h: Integer = 0; // 0: left; 1: center; 2: right
+  r_smallmap_v: Integer = 2; // 0: top; 1: center; 2: bottom
 
   // move button values:
   // bits 0-1: l/r state:
@@ -352,10 +354,9 @@ function gPause (): Boolean; inline;
 implementation
 
 uses
-{$IFDEF USE_NANOGL}
-  nanoGL,
-{$ELSE}
-  GL, GLExt,
+{$INCLUDE ../nogl/noGLuses.inc}
+{$IFDEF ENABLE_HOLMES}
+  g_holmes,
 {$ENDIF}
   e_texture, g_textures, g_main, g_window, g_menu,
   e_input, e_log, g_console, g_items, g_map, g_panel,
@@ -363,7 +364,7 @@ uses
   g_triggers, g_monsters, e_sound, CONFIG,
   g_language, g_net,
   ENet, e_msg, g_netmsg, g_netmaster,
-  sfs, wadreader, g_holmes;
+  sfs, wadreader;
 
 
 var
@@ -1013,6 +1014,7 @@ begin
             gMusic.SetByName('MUSIC_INTERMUS');
             gMusic.Play();
             gState := STATE_INTERSINGLE;
+            e_UnpressAllKeys();
 
             g_Game_ExecuteEvent('oninter');
           end
@@ -1663,12 +1665,14 @@ begin
 
                 gMusic.Play();
                 gState := STATE_INTERCUSTOM;
+                e_UnpressAllKeys();
               end
             else // Çàêîí÷èëàñü ïîñëåäíÿÿ êàðòà â Îäèíî÷íîé èãðå
               begin
                 gMusic.SetByName('MUSIC_INTERMUS');
                 gMusic.Play();
                 gState := STATE_INTERSINGLE;
+                e_UnpressAllKeys();
               end;
             g_Game_ExecuteEvent('oninter');
           end
@@ -1695,23 +1699,25 @@ begin
       begin
         if g_ActiveWindow = nil then
         begin
-          if e_KeyPressed(gGameControls.GameControls.Chat) then
+          if e_KeyPressed(gGameControls.GameControls.Chat) or e_KeyPressed(VK_CHAT) then
             g_Console_Chat_Switch(False)
-          else if (e_KeyPressed(gGameControls.GameControls.TeamChat)) and
+          else if (e_KeyPressed(gGameControls.GameControls.TeamChat) or e_KeyPressed(VK_TEAM)) and
                   (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
             g_Console_Chat_Switch(True);
         end;
       end else
         if not gChatEnter then
           if (not e_KeyPressed(gGameControls.GameControls.Chat))
-             and (not e_KeyPressed(gGameControls.GameControls.TeamChat)) then
+             and (not e_KeyPressed(gGameControls.GameControls.TeamChat))
+             and (not e_KeyPressed(VK_CHAT))
+             and (not e_KeyPressed(VK_TEAM)) then
             gChatEnter := True;
 
 // Ñòàòèñòèêà ïî Tab:
   if gGameOn then
     IsDrawStat := (not gConsoleShow) and (not gChatShow) and
                   (gGameSettings.GameType <> GT_SINGLE) and
-                  e_KeyPressed(gGameControls.GameControls.Stat);
+                  (e_KeyPressed(gGameControls.GameControls.Stat) or e_KeyPressed(VK_STATUS));
 
 // Èãðà èäåò:
   if gGameOn and not gPause and (gState <> STATE_FOLD) then
@@ -2011,7 +2017,7 @@ begin
   end;
 
 // Äåëàåì ñêðèíøîò (íå ÷àùå 200 ìèëëèñåêóíä):
-  if e_KeyPressed(gGameControls.GameControls.TakeScreenshot) then
+  if e_KeyPressed(gGameControls.GameControls.TakeScreenshot) or e_KeyPressed(VK_PRINTSCR) then
     if (GetTimer()-LastScreenShot) > 200000 div 1000 then
     begin
       g_TakeScreenShot();
@@ -3116,7 +3122,7 @@ var
     tagmask: Integer;
     pan: TPanel;
   begin
-    profileFrameDraw.sectionBegin(profname);
+    if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin(profname);
     if gdbg_map_use_accel_render then
     begin
       tagmask := panelTypeToTag(panType);
@@ -3132,31 +3138,31 @@ var
     begin
       if doDraw then g_Map_DrawPanels(panType, hasAmbient, ambColor);
     end;
-    profileFrameDraw.sectionEnd();
+    if (profileFrameDraw <> nil) then profileFrameDraw.sectionEnd();
   end;
 
   procedure drawOther (profname: AnsiString; cb: TDrawCB);
   begin
-    profileFrameDraw.sectionBegin(profname);
+    if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin(profname);
     if assigned(cb) then cb();
-    profileFrameDraw.sectionEnd();
+    if (profileFrameDraw <> nil) then profileFrameDraw.sectionEnd();
   end;
 
 begin
-  profileFrameDraw.sectionBegin('total');
+  if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin('total');
 
   // our accelerated renderer will collect all panels to gDrawPanelList
   // we can use panel tag to render level parts (see GridTagXXX in g_map.pas)
-  profileFrameDraw.sectionBegin('collect');
+  if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin('collect');
   if gdbg_map_use_accel_render then
   begin
     g_Map_CollectDrawPanels(sX, sY, sWidth, sHeight);
   end;
-  profileFrameDraw.sectionEnd();
+  if (profileFrameDraw <> nil) then profileFrameDraw.sectionEnd();
 
-  profileFrameDraw.sectionBegin('skyback');
+  if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin('skyback');
   g_Map_DrawBack(backXOfs, backYOfs);
-  profileFrameDraw.sectionEnd();
+  if (profileFrameDraw <> nil) then profileFrameDraw.sectionEnd();
 
   if setTransMatrix then
   begin
@@ -3213,7 +3219,7 @@ begin
     g_Player_DrawHealth();
   end;
 
-  profileFrameDraw.mainEnd(); // map rendering
+  if (profileFrameDraw <> nil) then profileFrameDraw.mainEnd(); // map rendering
 end;
 
 
@@ -3253,7 +3259,7 @@ begin
   end;
 
   if (profileFrameDraw = nil) then profileFrameDraw := TProfiler.Create('RENDER', g_profile_history_size);
-  profileFrameDraw.mainBegin(g_profile_frame_draw);
+  if (profileFrameDraw <> nil) then profileFrameDraw.mainBegin(g_profile_frame_draw);
 
   gPlayerDrawn := p;
 
@@ -3340,6 +3346,7 @@ begin
   //conwritefln('OLD: (%s,%s)-(%s,%s)', [sX, sY, sWidth, sHeight]);
   fixViewportForScale();
   //conwritefln('     (%s,%s)-(%s,%s)', [sX, sY, sWidth, sHeight]);
+
   if (g_dbg_scale <> 1.0) and (not g_dbg_ignore_bounds) then
   begin
     if (sX+sWidth > gMapInfo.Width) then sX := gMapInfo.Width-sWidth;
@@ -3350,16 +3357,48 @@ begin
     if (gBackSize.X <= gPlayerScreenSize.X) or (gMapInfo.Width <= sWidth) then c := 0 else c := trunc((gBackSize.X-gPlayerScreenSize.X)*sX/(gMapInfo.Width-sWidth));
     if (gBackSize.Y <= gPlayerScreenSize.Y) or (gMapInfo.Height <= sHeight) then d := 0 else d := trunc((gBackSize.Y-gPlayerScreenSize.Y)*sY/(gMapInfo.Height-sHeight));
   end;
+
+  //r_smallmap_h: 0: left; 1: center; 2: right
+  //r_smallmap_v: 0: top; 1: center; 2: bottom
+  // horiz small map?
+  if (gMapInfo.Width = sWidth) then
+  begin
+    sX := 0;
+  end
+  else if (gMapInfo.Width < sWidth) then
+  begin
+    case r_smallmap_h of
+      1: sX := -((sWidth-gMapInfo.Width) div 2); // center
+      2: sX := -(sWidth-gMapInfo.Width); // right
+      else sX := 0; // left
+    end;
+  end;
+  // vert small map?
+  if (gMapInfo.Height = sHeight) then
+  begin
+    sY := 0;
+  end
+  else if (gMapInfo.Height < sHeight) then
+  begin
+    case r_smallmap_v of
+      1: sY := -((sHeight-gMapInfo.Height) div 2); // center
+      2: sY := -(sHeight-gMapInfo.Height); // bottom
+      else sY := 0; // top
+    end;
+  end;
+
   p.viewPortX := sX;
   p.viewPortY := sY;
   p.viewPortW := sWidth;
   p.viewPortH := sHeight;
 
+{$IFDEF ENABLE_HOLMES}
   if (p = gPlayer1) then
   begin
     g_Holmes_plrViewPos(sX, sY);
     g_Holmes_plrViewSize(sWidth, sHeight);
   end;
+{$ENDIF}
 
   renderMapInternal(-c, -d, true);
 
@@ -3401,9 +3440,9 @@ var
   px: Integer = -1;
   py: Integer = -1;
 begin
-  if g_profile_frame_draw then px := px-drawProfiles(px, py, profileFrameDraw);
-  if g_profile_collision then begin px := px-drawProfiles(px, py, profMapCollision); py -= calcProfilesHeight(profMonsLOS); end;
-  if g_profile_los then begin px := px-drawProfiles(px, py, profMonsLOS); py -= calcProfilesHeight(profMonsLOS); end;
+  if g_profile_frame_draw and (profileFrameDraw <> nil) then px := px-drawProfiles(px, py, profileFrameDraw);
+  if g_profile_collision and (profMapCollision <> nil) then begin px := px-drawProfiles(px, py, profMapCollision); py -= calcProfilesHeight(profMonsLOS); end;
+  if g_profile_los and (profMonsLOS <> nil) then begin px := px-drawProfiles(px, py, profMonsLOS); py -= calcProfilesHeight(profMonsLOS); end;
 end;
 
 procedure g_Game_Draw();
@@ -3549,8 +3588,10 @@ begin
         e_DrawLine(2, 0, gScreenHeight div 2, gScreenWidth, gScreenHeight div 2, 0, 0, 0);
     end;
 
+{$IFDEF ENABLE_HOLMES}
     // draw inspector
     if (g_holmes_enabled) then g_Holmes_Draw();
+{$ENDIF}
 
     if MessageText <> '' then
     begin
@@ -3762,7 +3803,9 @@ begin
 
   if gGameOn then drawProfilers();
 
+{$IFDEF ENABLE_HOLMES}
   g_Holmes_DrawUI();
+{$ENDIF}
 
   g_Touch_Draw;
 end;
@@ -4492,7 +4535,7 @@ begin
       gWADHash := MD5File(MapsDir + NewWAD);
       g_Game_LoadWAD(NewWAD);
     end else
-      // hash recieved in MC_RECV_GameEvent -> NET_EV_MAPSTART
+      // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
       g_Game_ClientWAD(NewWAD, gWADHash);
   end else
     ResName := Map;
@@ -7277,13 +7320,18 @@ begin
   ProcessLoading(true);
 end;
 
-procedure g_Game_StepLoading();
+procedure g_Game_StepLoading(Value: Integer = -1);
 begin
   with LoadingStat do
   begin
-    Inc(CurValue);
-    Inc(ShowCount);
-    if (ShowCount > LOADING_SHOW_STEP) then
+    if Value = -1 then
+    begin
+      Inc(CurValue);
+      Inc(ShowCount);
+    end
+    else
+      CurValue := Value;
+    if (ShowCount > LOADING_SHOW_STEP) or (Value > -1) then
     begin
       ShowCount := 0;
       ProcessLoading();
@@ -7553,7 +7601,9 @@ begin
   conRegVar('los_enabled', @gmon_dbg_los_enabled, 'enable/disable monster LOS calculations', 'monster LOS', true);
   conRegVar('mon_think', @gmon_debug_think, 'enable/disable monster thinking', 'monster thinking', true);
 
+{$IFDEF ENABLE_HOLMES}
   conRegVar('dbg_holmes', @g_holmes_enabled, 'enable/disable Holmes', 'Holmes', true);
+{$ENDIF}
 
   conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds, 'ignore level bounds', '',  false);
 
@@ -7561,4 +7611,7 @@ begin
 
   conRegVar('light_enabled', @gwin_k8_enable_light_experiments, 'enable/disable dynamic lighting', 'lighting');
   conRegVar('light_player_halo', @g_playerLight, 'enable/disable player halo', 'player light halo');
+
+  conRegVar('r_smallmap_align_h', @r_smallmap_h, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
+  conRegVar('r_smallmap_align_v', @r_smallmap_v, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
 end.