From 6a5a13240c80890906dbc2cc4f1e6afc2ba20f84 Mon Sep 17 00:00:00 2001 From: DeaDDooMER Date: Mon, 17 Jan 2022 19:11:35 +0300 Subject: [PATCH] render: load sky in render --- src/game/Doom2DF.lpr | 1 - src/game/g_game.pas | 52 ----------------------------- src/game/g_map.pas | 18 ++-------- src/game/g_saveload.pas | 3 -- src/game/opengl/r_game.pas | 64 +++++++++++++++++++++++++++++++++++- src/game/opengl/r_map.pas | 11 +------ src/game/opengl/r_player.pas | 2 +- src/game/opengl/r_render.pas | 3 +- 8 files changed, 70 insertions(+), 84 deletions(-) diff --git a/src/game/Doom2DF.lpr b/src/game/Doom2DF.lpr index 80bd774..baaa8af 100644 --- a/src/game/Doom2DF.lpr +++ b/src/game/Doom2DF.lpr @@ -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; diff --git a/src/game/g_game.pas b/src/game/g_game.pas index 315f1af..70321dd 100644 --- a/src/game/g_game.pas +++ b/src/game/g_game.pas @@ -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); diff --git a/src/game/g_map.pas b/src/game/g_map.pas index 92da4f4..7bcb5b1 100644 --- a/src/game/g_map.pas +++ b/src/game/g_map.pas @@ -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); diff --git a/src/game/g_saveload.pas b/src/game/g_saveload.pas index e2091c3..003c58b 100644 --- a/src/game/g_saveload.pas +++ b/src/game/g_saveload.pas @@ -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 diff --git a/src/game/opengl/r_game.pas b/src/game/opengl/r_game.pas index 1a50858..213b27e 100644 --- a/src/game/opengl/r_game.pas +++ b/src/game/opengl/r_game.pas @@ -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; diff --git a/src/game/opengl/r_map.pas b/src/game/opengl/r_map.pas index da98c95..587d0da 100644 --- a/src/game/opengl/r_map.pas +++ b/src/game/opengl/r_map.pas @@ -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 diff --git a/src/game/opengl/r_player.pas b/src/game/opengl/r_player.pas index 7d0269c..93f1b23 100644 --- a/src/game/opengl/r_player.pas +++ b/src/game/opengl/r_player.pas @@ -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 diff --git a/src/game/opengl/r_render.pas b/src/game/opengl/r_render.pas index 2eec521..90bda3b 100644 --- a/src/game/opengl/r_render.pas +++ b/src/game/opengl/r_render.pas @@ -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; -- 2.29.2