DEADSOFTWARE

render: use only r_render to access render
[d2df-sdl.git] / src / game / opengl / r_game.pas
index ec87b29133416e670dcfdd3462df0b489e1d242d..6e587868d4114524cb45887784d91528fdc99a9c 100644 (file)
@@ -17,10 +17,21 @@ unit r_game;
 
 interface
 
+  procedure r_Game_Load;
+  procedure r_Game_Free;
+
+  procedure r_Game_LoadTextures;
+  procedure r_Game_FreeTextures;
+
   procedure r_Game_Draw;
   procedure r_Game_DrawLoadingStat;
   procedure r_Game_DrawMenuBackground (tex: AnsiString);
 
+  procedure r_Game_SetupScreenSize;
+
+  var
+    gStdFont: DWORD;
+
 implementation
 
   uses
@@ -29,7 +40,7 @@ implementation
     g_holmes,
 {$ENDIF}
     SysUtils, Classes, Math,
-    g_base, r_graphics,
+    g_base, g_basic, r_graphics,
     g_system, g_touch,
     MAPDEF, xprofiler, utils, wadreader,
     e_input, e_sound,
@@ -45,6 +56,145 @@ implementation
     FPS: Word;
     FPSCounter: Word;
     FPSTime: LongWord;
+    hasPBarGfx: Boolean;
+
+    BackID: DWORD = DWORD(-1);
+    gBackSize: TDFPoint;
+
+  procedure r_Game_Load;
+    var
+      wl, hl: Integer;
+      wr, hr: Integer;
+      wb, hb: Integer;
+      wm, hm: Integer;
+  begin
+    // early load
+    g_Texture_CreateWADEx('MENU_BACKGROUND', GameWAD + ':TEXTURES\TITLE', gTextureFilter);
+    g_Texture_CreateWADEx('INTER', GameWAD + ':TEXTURES\INTER', gTextureFilter);
+    g_Texture_CreateWADEx('ENDGAME_EN', GameWAD + ':TEXTURES\ENDGAME_EN', gTextureFilter);
+    g_Texture_CreateWADEx('ENDGAME_RU', GameWAD + ':TEXTURES\ENDGAME_RU', gTextureFilter);
+    LoadStdFont('STDTXT', 'STDFONT', gStdFont);
+    LoadFont('MENUTXT', 'MENUFONT', gMenuFont);
+    LoadFont('SMALLTXT', 'SMALLFONT', gMenuSmallFont);
+    // game data
+    g_Texture_CreateWADEx('NOTEXTURE', GameWAD + ':TEXTURES\NOTEXTURE');
+    g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD + ':TEXTURES\HUD');
+    g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD + ':TEXTURES\AIRBAR');
+    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_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_Texture_CreateWADEx('TEXTURE_PLAYER_INDICATOR', GameWAD + ':TEXTURES\PLRIND');
+    // bar
+    hasPBarGfx := true;
+    if not g_Texture_CreateWADEx('UI_GFX_PBAR_LEFT', GameWAD+':TEXTURES\LLEFT') then hasPBarGfx := false;
+    if not g_Texture_CreateWADEx('UI_GFX_PBAR_MARKER', GameWAD+':TEXTURES\LMARKER') then hasPBarGfx := false;
+    if not g_Texture_CreateWADEx('UI_GFX_PBAR_MIDDLE', GameWAD+':TEXTURES\LMIDDLE') then hasPBarGfx := false;
+    if not g_Texture_CreateWADEx('UI_GFX_PBAR_RIGHT', GameWAD+':TEXTURES\LRIGHT') then hasPBarGfx := false;
+    if hasPBarGfx then
+    begin
+      g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl, hl);
+      g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr, hr);
+      g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb, hb);
+      g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm, hm);
+      if (wl > 0) and (hl > 0) and (wr > 0) and (hr = hl) and (wb > 0) and (hb = hl) and (wm > 0) and (hm > 0) and (hm <= hl) then
+      begin
+        // yay!
+      end
+      else
+        hasPBarGfx := false;
+    end;
+  end;
+
+  procedure r_Game_Free;
+  begin
+    g_Texture_Delete('NOTEXTURE');
+    g_Texture_Delete('TEXTURE_PLAYER_HUD');
+    g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
+    g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
+    g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
+    g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
+    g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
+    g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
+    g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
+    g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
+    g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
+    g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
+  end;
+
+procedure r_Game_SetupScreenSize;
+const
+  RES_FACTOR = 4.0 / 3.0;
+var
+  s: Single;
+  rf: Single;
+  bw, bh: Word;
+begin
+// Размер экранов игроков:
+  gPlayerScreenSize.X := gScreenWidth-196;
+  if (gPlayer1 <> nil) and (gPlayer2 <> nil) then
+    gPlayerScreenSize.Y := gScreenHeight div 2
+  else
+    gPlayerScreenSize.Y := gScreenHeight;
+
+// Размер заднего плана:
+  if BackID <> DWORD(-1) then
+  begin
+    s := SKY_STRETCH;
+    if (gScreenWidth*s > gMapInfo.Width) or
+       (gScreenHeight*s > gMapInfo.Height) then
+    begin
+      gBackSize.X := gScreenWidth;
+      gBackSize.Y := gScreenHeight;
+    end
+    else
+    begin
+      e_GetTextureSize(BackID, @bw, @bh);
+      rf := Single(bw) / Single(bh);
+      if (rf > RES_FACTOR) then bw := Round(Single(bh) * RES_FACTOR)
+      else if (rf < RES_FACTOR) then bh := Round(Single(bw) / RES_FACTOR);
+      s := Max(gScreenWidth / bw, gScreenHeight / bh);
+      if (s < 1.0) then s := 1.0;
+      gBackSize.X := Round(bw*s);
+      gBackSize.Y := Round(bh*s);
+    end;
+  end;
+end;
+
+  procedure r_Game_LoadTextures;
+  begin
+    g_Texture_CreateWADEx('TEXTURE_endpic', EndPicPath, gTextureFilter);
+    if gMapInfo.SkyFullName <> '' then
+      g_Texture_CreateWAD(BackID, gMapInfo.SkyFullName, gTextureFilter);
+    r_Game_SetupScreenSize;
+  end;
+
+  procedure r_Game_FreeTextures;
+  begin
+    g_Texture_Delete('TEXTURE_endpic');
+    if BackID <> DWORD(-1) then
+    begin
+      gBackSize.X := 0;
+      gBackSize.Y := 0;
+      e_DeleteTexture(BackID);
+      BackID := DWORD(-1);
+    end
+  end;
+
+procedure r_Map_DrawBack(dx, dy: Integer);
+begin
+  if gDrawBackGround and (BackID <> DWORD(-1)) then
+    e_DrawSize(BackID, dx, dy, 0, False, False, gBackSize.X, gBackSize.Y)
+  else
+    e_Clear(GL_COLOR_BUFFER_BIT, 0, 0, 0);
+end;
 
 function GetActivePlayer_ByID(ID: Integer): TPlayer;
 var
@@ -561,7 +711,9 @@ begin
   // HACK: take stats screenshot immediately after the first frame of the stats showing
   if gScreenshotStats and (not StatShotDone) and (Length(CustomStat.PlayerStat) > 1) then
   begin
+{$IFNDEF HEADLESS}
     g_TakeScreenShot('stats/' + StatFilename);
+{$ENDIF}
     StatShotDone := True;
   end;
 end;
@@ -1562,6 +1714,8 @@ var
   back: string;
   plView1, plView2: TPlayer;
   Split: Boolean;
+  MsgLineLength: Integer;
+  MsgText: String;
 begin
   if gExit = EXIT_QUIT then Exit;
 
@@ -1709,12 +1863,14 @@ begin
       w := 0;
       h := 0;
       e_CharFont_GetSizeFmt(gMenuFont, MessageText, w, h);
+      MsgLineLength := (gScreenWidth - 204) div e_CharFont_GetMaxWidth(gMenuFont);
+      MsgText := b_Text_Wrap(b_Text_Format(MessageText), MsgLineLength);
       if Split then
         e_CharFont_PrintFmt(gMenuFont, (gScreenWidth div 2)-(w div 2),
-                        (gScreenHeight div 2)-(h div 2), MessageText)
+                        (gScreenHeight div 2)-(h div 2), MsgText)
       else
         e_CharFont_PrintFmt(gMenuFont, (gScreenWidth div 2)-(w div 2),
-                  Round(gScreenHeight / 2.75)-(h div 2), MessageText);
+                  Round(gScreenHeight / 2.75)-(h div 2), MsgText);
     end;
 
     if IsDrawStat or (gSpectMode = SPECT_STATS) then