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>
Mon, 17 Jan 2022 16:11:35 +0000 (19:11 +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 400e77701cc60a5b8e8980913526939a8bfc8644..1be6b0c4e9a3744003c22d5c9605084e349e28e2 100644 (file)
@@ -916,7 +916,6 @@ end;
       fuiScrWdt := w;
       fuiScrHgt := h;
     {$ENDIF}
-    g_Game_SetupScreenSize;
     {$IFNDEF ANDROID}
       (* This will fix menu reset on keyboard showing *)
       g_Menu_Reset;
index 2ce5d95e7107a6b547b0e99670db518ec0335e59..17c9fdafbd775d156abebd401148926d16b8f4a3 100644 (file)
@@ -86,7 +86,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);
@@ -2561,45 +2560,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))
@@ -2761,9 +2721,6 @@ begin
 
   g_Game_ExecuteEvent('ongamestart');
 
-// Установка размеров окон игроков:
-  g_Game_SetupScreenSize();
-
 // Создание первого игрока:
   gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
                                            gPlayer1Settings.Color,
@@ -2845,9 +2802,6 @@ begin
 
   g_Game_ExecuteEvent('ongamestart');
 
-// Установка размеров окон игроков:
-  g_Game_SetupScreenSize();
-
 // Режим наблюдателя:
   if nPlayers = 0 then
   begin
@@ -2949,9 +2903,6 @@ begin
 
   g_Game_ExecuteEvent('ongamestart');
 
-// Установка размеров окна игрока
-  g_Game_SetupScreenSize();
-
 // Режим наблюдателя:
   if nPlayers = 0 then
   begin
@@ -3063,9 +3014,6 @@ begin
 
   g_Game_ExecuteEvent('ongamestart');
 
-// Установка размеров окон игроков:
-  g_Game_SetupScreenSize();
-
   NetState := NET_STATE_AUTH;
 
   g_Game_SetLoadingText(_lc[I_LOAD_CONNECT], 0, False);
index 2ca5bb67c604fc8f1f03c53aa87575eb260524e2..c5afc785818d45c559299ec19bfcbe6fd0e0d0e0 100644 (file)
@@ -31,6 +31,7 @@ type
     Author:        String;
     MusicName:     String;
     SkyName:       String;
+    SkyFullName:   String; // used by render
     Height:        Word;
     Width:         Word;
   end;
@@ -214,11 +215,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;
 
@@ -1869,15 +1868,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;
 
     // Çàãðóçêà ìóçûêè
@@ -2137,14 +2133,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 32f6821770c20af0affaf213d2b5ee23853e6cc2..d603440d839241a9c3513f59140ae34d0ca755ba 100644 (file)
@@ -398,9 +398,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 af6fa38e78d27de654cd04e39e75aa7c394eec5a..a31c4afccf67c14505a4f7ed56a09e9be0ef3380 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 9efb062512f975054c65b7f011fd189132e7a4a2..b3efdc30be82fd2df53e77538f05631c83c185fb 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: Integer; Mirror: TMirrorType; f: PFlag;
   begin
index d4af4b55fdd5b89432ed810c7759a72c8edaa182..1e5dec0edc646393aa95cab7fba5ff2611dfee24 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;