DEADSOFTWARE

render: load sky in render
authorDeaDDooMER <deaddoomer@deadsoftware.ru>
Mon, 17 Jan 2022 16:11:35 +0000 (19:11 +0300)
committerDeaDDooMER <deaddoomer@deadsoftware.ru>
Fri, 9 Jun 2023 07:53:30 +0000 (10:53 +0300)
src/game/Doom2DF.lpr
src/game/g_game.pas
src/game/g_map.pas
src/game/g_saveload.pas
src/game/opengl/r_game.pas
src/game/opengl/r_map.pas
src/game/opengl/r_player.pas
src/game/opengl/r_render.pas

index 80bd7746acb5896668c4fbd526058d30d4343b80..baaa8affc2ca527d388e37aaa82195c5c39e02e2 100644 (file)
@@ -953,7 +953,6 @@ end;
       fuiScrWdt := w;
       fuiScrHgt := h;
     {$ENDIF}
-    g_Game_SetupScreenSize;
     {$IFNDEF ANDROID}
       (* This will fix menu reset on keyboard showing *)
       g_Menu_Reset;
index 315f1afc2d9c6b50693dc5daa804e99e6fc3fe6a..70321ddf707b89127dca6ab97bf6eaaa7e4cf719 100644 (file)
@@ -91,7 +91,6 @@ procedure g_Game_FreeData();
 procedure g_Game_Update();
 procedure g_Game_PreUpdate();
 procedure g_Game_Quit();
-procedure g_Game_SetupScreenSize();
 function  g_Game_ModeToText(Mode: Byte): string;
 function  g_Game_TextToMode(Mode: string): Byte;
 procedure g_Game_ExecuteEvent(Name: String);
@@ -2605,45 +2604,6 @@ begin
   e_WriteLog(Format(_lc[I_SIMPLE_ERROR], [Text]), TMsgType.Warning);
 end;
 
-procedure g_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 g_Game_AddPlayer(Team: Byte = TEAM_NONE);
 begin
   if ((not gGameOn) and (gState <> STATE_INTERCUSTOM))
@@ -2813,9 +2773,6 @@ begin
 
   g_Game_ExecuteEvent('ongamestart');
 
-// Установка размеров окон игроков:
-  g_Game_SetupScreenSize();
-
 // Создание первого игрока:
   gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
                                            gPlayer1Settings.Color,
@@ -2905,9 +2862,6 @@ begin
 
   g_Game_ExecuteEvent('ongamestart');
 
-// Установка размеров окон игроков:
-  g_Game_SetupScreenSize();
-
 // Режим наблюдателя:
   if nPlayers = 0 then
   begin
@@ -3019,9 +2973,6 @@ begin
 
   g_Game_ExecuteEvent('ongamestart');
 
-// Установка размеров окна игрока
-  g_Game_SetupScreenSize();
-
 // Режим наблюдателя:
   if nPlayers = 0 then
   begin
@@ -3143,9 +3094,6 @@ begin
 
   g_Game_ExecuteEvent('ongamestart');
 
-// Установка размеров окон игроков:
-  g_Game_SetupScreenSize();
-
   NetState := NET_STATE_AUTH;
 
   g_Game_SetLoadingText(_lc[I_LOAD_CONNECT], 0, False);
index 92da4f4b9121206d5dd0d0576735be5ed5746bcf..7bcb5b1379320f5d773760219db4c69085ece639 100644 (file)
@@ -31,6 +31,7 @@ type
     Author:        String;
     MusicName:     String;
     SkyName:       String;
+    SkyFullName:   String; // used by render
     Height:        Word;
     Width:         Word;
   end;
@@ -215,11 +216,9 @@ var
   gFlags: array [FLAG_RED..FLAG_BLUE] of TFlag;
   //gDOMFlags: array of TFlag;
   gMapInfo: TMapInfo;
-  gBackSize: TDFPoint;
   gDoorMap: array of array of DWORD;
   gLiftMap: array of array of DWORD;
   gWADHash: TMD5Digest;
-  BackID:  DWORD = DWORD(-1);
   gExternalResources: array of TDiskFileInfo = nil;
   gMovingWallIds: array of Integer = nil;
 
@@ -1870,15 +1869,12 @@ begin
     //mapReader := nil;
 
     // Çàãðóçêà íåáà
+    gMapInfo.SkyFullName := '';
     if (gMapInfo.SkyName <> '') then
     begin
       e_WriteLog('  Loading sky: ' + gMapInfo.SkyName, TMsgType.Notify);
       g_Game_SetLoadingText(_lc[I_LOAD_SKY], 0, False);
-      s := e_GetResourcePath(WadDirs, gMapInfo.SkyName, g_ExtractWadName(Res));
-      if g_Texture_CreateWAD(BackID, s, gTextureFilter) then
-        g_Game_SetupScreenSize
-      else
-        g_FatalError(Format(_lc[I_GAME_ERROR_SKY], [s]))
+      gMapInfo.SkyFullName := e_GetResourcePath(WadDirs, gMapInfo.SkyName, g_ExtractWadName(Res));
     end;
 
     // Çàãðóçêà ìóçûêè
@@ -2138,14 +2134,6 @@ begin
   FreePanelArray(gBlockMon);
   gMovingWallIds := nil;
 
-  if BackID <> DWORD(-1) then
-  begin
-    gBackSize.X := 0;
-    gBackSize.Y := 0;
-    e_DeleteTexture(BackID);
-    BackID := DWORD(-1);
-  end;
-
   g_Game_StopAllSounds(False);
   gMusic.FreeSound();
   g_Sound_Delete(gMapInfo.MusicName);
index e2091c39137ac2a277705ac1c33ff9b08316b7be..003c58b4df7f5be2923be888ebe0bdb3881ded3f 100644 (file)
@@ -400,9 +400,6 @@ begin
         end;
         g_Game_ExecuteEvent('ongamestart');
 
-        // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ
-        g_Game_SetupScreenSize();
-
         // Çàãðóçêà è çàïóñê êàðòû
         //FIXME: save/load `asMegawad`
         if not g_Game_StartMap(false{asMegawad}, WAD_Path+':\'+Map_Name, True, curmapfile) then
index 1a5085831d7b5892ffad6f4ffec4fda0a6d42b00..213b27e471f090def65d8f4a9a272191f84a5fea 100644 (file)
@@ -27,6 +27,8 @@ interface
   procedure r_Game_DrawLoadingStat;
   procedure r_Game_DrawMenuBackground (tex: AnsiString);
 
+  procedure r_Game_SetupScreenSize;
+
   var
     gStdFont: DWORD;
 
@@ -56,6 +58,9 @@ implementation
     FPSTime: LongWord;
     hasPBarGfx: Boolean;
 
+    BackID: DWORD = DWORD(-1);
+    gBackSize: TDFPoint;
+
   procedure r_Game_Load;
     var
       wl, hl: Integer;
@@ -124,16 +129,73 @@ implementation
     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')
+    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
   a: Integer;
index da98c9582c511414a33812fb85381adaa168d503..587d0daa531341671fd6e87ecfdf8162d5ecc71b 100644 (file)
@@ -30,7 +30,6 @@ interface
 
   procedure r_Map_Update;
 
-  procedure r_Map_DrawBack (dx, dy: Integer);
   procedure r_Map_DrawPanels (PanelType: Word; hasAmbient: Boolean; constref ambColor: TDFColor); // unaccelerated
   procedure r_Map_CollectDrawPanels (x0, y0, wdt, hgt: Integer);
   procedure r_Map_DrawPanelShadowVolumes (lightX: Integer; lightY: Integer; radius: Integer);
@@ -43,7 +42,7 @@ implementation
 
   uses
     {$INCLUDE ../nogl/noGLuses.inc}
-    SysUtils, Classes, Math, e_log, wadreader, CONFIG, utils,
+    SysUtils, Classes, Math, e_log, wadreader, CONFIG, utils, g_language,
     r_graphics, r_animations, r_textures, g_textures,
     g_base, g_basic, g_game, g_options,
     g_map
@@ -249,14 +248,6 @@ begin
   it.release();
 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;
-
   procedure r_Map_DrawFlags;
     var i, dx, tx, ty: Integer; Mirror: TMirrorType; f: PFlag;
   begin
index 7d0269c08a631ae2fc03c42dfbd35eef517c42ce..93f1b2398a32e7bc4eb3ed7ed19b8a5630230327 100644 (file)
@@ -47,7 +47,7 @@ implementation
 {$IFDEF ENABLE_HOLMES}
     g_holmes,
 {$ENDIF}
-    r_playermodel, r_graphics, r_animations, r_textures, r_items, r_game
+    r_playermodel, r_graphics, r_animations, r_textures, r_items, r_game, r_map
   ;
 
   var
index 2eec521475ec4c7806fa08c8d63a59538c1da293..90bda3b04a230a27abceb3ad4e651b518a5fad7e 100644 (file)
@@ -165,7 +165,8 @@ implementation
     gScreenWidth := w;
     gScreenHeight := h;
     e_ResizeWindow(w, h);
-    e_InitGL
+    e_InitGL;
+    r_Game_SetupScreenSize;
   end;
 
   procedure r_Render_Apply;