From: DeaDDooMER Date: Mon, 17 Jan 2022 15:16:29 +0000 (+0300) Subject: render: move more texture load code into render X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=bc85322c634955e1d759a0798052fc61e47a599b;p=d2df-sdl.git render: move more texture load code into render --- diff --git a/src/game/g_game.pas b/src/game/g_game.pas index 5f7efda..315f1af 100644 --- a/src/game/g_game.pas +++ b/src/game/g_game.pas @@ -242,7 +242,6 @@ const STATFILE_VERSION = $03; var - gStdFont: DWORD; gGameSettings: TGameSettings; gPlayer1Settings: TPlayerSettings; gPlayer2Settings: TPlayerSettings; @@ -432,7 +431,6 @@ function gPause (): Boolean; inline; StatShotDone: Boolean; StatFilename: string = ''; // used by stat screenshot to save with the same name as the csv SingleStat: TEndSingleGameStat; - hasPBarGfx: Boolean; LoadingStat: TLoadingStat; MessageText: String; IsDrawStat: Boolean; @@ -441,6 +439,7 @@ function gPause (): Boolean; inline; g_playerLight: Boolean; g_dynLights: array of TDynLight = nil; g_dynLightCount: Integer = 0; + EndPicPath: AnsiString; // full path, used by render implementation @@ -448,7 +447,7 @@ uses {$IFDEF ENABLE_HOLMES} g_holmes, {$ENDIF} - e_res, g_window, g_menu, r_render, r_textures, r_animations, r_gfx, r_map, + e_res, g_window, g_menu, r_render, r_gfx, e_input, e_log, g_console, r_console, g_items, g_map, g_panel, g_playermodel, g_gfx, g_options, Math, g_triggers, g_monsters, e_sound, CONFIG, @@ -907,22 +906,7 @@ var info: TMegaWADInfo; endpic: String; endmus: String; - res: record - text: Array of ShortString; - anim: Array of ShortString; - pic: Array of ShortString; - mus: Array of ShortString; - end; - triggers: Array of record - event: ShortString; - actions: Array of record - action, p1, p2: Integer; - end; - end; - cur_trigger: Integer; - cur_action: Integer; end; - //InterPic: String; InterText: record lines: SSArray; img: String; @@ -1123,37 +1107,20 @@ begin FreeMem(p); end; -procedure g_Game_FreeWAD(); -var - a: Integer; -begin - for a := 0 to High(MegaWAD.res.pic) do - if MegaWAD.res.pic[a] <> '' then - g_Texture_Delete(MegaWAD.res.pic[a]); - - for a := 0 to High(MegaWAD.res.mus) do - if MegaWAD.res.mus[a] <> '' then - g_Sound_Delete(MegaWAD.res.mus[a]); - - MegaWAD.res.pic := nil; - MegaWAD.res.text := nil; - MegaWAD.res.anim := nil; - MegaWAD.res.mus := nil; - MegaWAD.triggers := nil; - - g_Texture_Delete('TEXTURE_endpic'); - g_Sound_Delete('MUSIC_endmus'); - - ZeroMemory(@MegaWAD, SizeOf(MegaWAD)); - gGameSettings.WAD := ''; -end; + procedure g_Game_FreeWAD; + begin + EndPicPath := ''; + g_Sound_Delete('MUSIC_endmus'); + ZeroMemory(@MegaWAD, SizeOf(MegaWAD)); + gGameSettings.WAD := ''; + end; procedure g_Game_LoadWAD(WAD: string); var w: TWADFile; cfg: TConfig; p: Pointer; - {b, }len: Integer; + len: Integer; s: AnsiString; begin g_Game_FreeWAD(); @@ -1174,38 +1141,11 @@ begin cfg := TConfig.CreateMem(p, len); - {b := 1; - while True do - begin - s := cfg.ReadStr('pic', 'pic'+IntToStr(b), ''); - if s = '' then Break; - b := b+1; - - SetLength(MegaWAD.res.pic, Length(MegaWAD.res.pic)+1); - MegaWAD.res.pic[High(MegaWAD.res.pic)] := s; - - g_Texture_CreateWADEx(s, s); - end; - - b := 1; - while True do - begin - s := cfg.ReadStr('mus', 'mus'+IntToStr(b), ''); - if s = '' then Break; - b := b+1; - - SetLength(MegaWAD.res.mus, Length(MegaWAD.res.mus)+1); - MegaWAD.res.mus[High(MegaWAD.res.mus)] := s; - - g_Music_CreateWADEx(s, s); - end;} - + EndPicPath := ''; MegaWAD.endpic := cfg.ReadStr('megawad', 'endpic', ''); if MegaWAD.endpic <> '' then - begin - s := e_GetResourcePath(WadDirs, MegaWAD.endpic, WAD); - g_Texture_CreateWADEx('TEXTURE_endpic', s, gTextureFilter); - end; + EndPicPath := e_GetResourcePath(WadDirs, MegaWAD.endpic, WAD); + MegaWAD.endmus := cfg.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\КОНЕЦ'); if MegaWAD.endmus <> '' then begin @@ -1468,15 +1408,6 @@ begin sfsGCDisable(); // temporary disable removing of temporary volumes try - 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); - g_Game_ClearLoading(); g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION]), 0, False); g_Game_SetLoadingText('', 0, False); @@ -2468,54 +2399,11 @@ begin end; procedure g_Game_LoadData(); -var - wl, hl: Integer; - wr, hr: Integer; - wb, hb: Integer; - wm, hm: Integer; begin if DataLoaded then Exit; e_WriteLog('Loading game data...', TMsgType.Notify); - 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'); - - 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 - begin - hasPBarGfx := false; - end; - end; - g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD+':SOUNDS\TELEPORT'); g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD+':SOUNDS\NOTELEPORT'); g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD+':SOUNDS\SECRET'); @@ -2614,8 +2502,6 @@ begin gMusic.Free(); g_Game_FreeData(); g_PlayerModel_FreeData(); - g_Texture_DeleteAll(); - g_Frames_DeleteAll(); {$IFNDEF HEADLESS} //g_Menu_Free(); //k8: this segfaults after resolution change; who cares? {$ENDIF} @@ -2640,18 +2526,6 @@ begin e_WriteLog('Releasing game data...', TMsgType.Notify); - 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'); g_Sound_Delete('SOUND_GAME_TELEPORT'); g_Sound_Delete('SOUND_GAME_NOTELEPORT'); g_Sound_Delete('SOUND_GAME_SECRET'); @@ -3537,7 +3411,7 @@ begin begin //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName); result := g_Map_Load(NewWAD+':\'+ResName); - r_Map_LoadTextures; + r_Render_LoadTextures; end; if Result then begin diff --git a/src/game/opengl/r_console.pas b/src/game/opengl/r_console.pas index 1204fcd..f7ab15f 100644 --- a/src/game/opengl/r_console.pas +++ b/src/game/opengl/r_console.pas @@ -25,7 +25,7 @@ implementation uses SysUtils, Classes, Math, - e_log, r_graphics, g_options, r_textures, + e_log, r_graphics, g_options, r_textures, r_game, conbuf, g_base, g_console, g_game, g_menu ; diff --git a/src/game/opengl/r_game.pas b/src/game/opengl/r_game.pas index ed204cd..1a50858 100644 --- a/src/game/opengl/r_game.pas +++ b/src/game/opengl/r_game.pas @@ -17,10 +17,19 @@ 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); + var + gStdFont: DWORD; + implementation uses @@ -45,6 +54,85 @@ implementation FPS: Word; FPSCounter: Word; FPSTime: LongWord; + hasPBarGfx: Boolean; + + 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_LoadTextures; + begin + g_Texture_CreateWADEx('TEXTURE_endpic', EndPicPath, gTextureFilter); + end; + + procedure r_Game_FreeTextures; + begin + g_Texture_Delete('TEXTURE_endpic') + end; function GetActivePlayer_ByID(ID: Integer): TPlayer; var diff --git a/src/game/opengl/r_map.pas b/src/game/opengl/r_map.pas index d34100d..da98c95 100644 --- a/src/game/opengl/r_map.pas +++ b/src/game/opengl/r_map.pas @@ -26,7 +26,7 @@ interface procedure r_Map_Free; procedure r_Map_LoadTextures; - // TODO procedure r_Map_FreeTextures + procedure r_Map_FreeTextures; procedure r_Map_Update; @@ -185,6 +185,11 @@ implementation end end; + procedure r_Map_FreeTextures; + begin + // TODO + end; + procedure dplClear (); begin if (gDrawPanelList = nil) then gDrawPanelList := TBinHeapPanelDraw.Create() else gDrawPanelList.clear(); diff --git a/src/game/opengl/r_monsters.pas b/src/game/opengl/r_monsters.pas index c9b4ff7..d2f2dfd 100644 --- a/src/game/opengl/r_monsters.pas +++ b/src/game/opengl/r_monsters.pas @@ -26,7 +26,7 @@ implementation uses SysUtils, Classes, Math, e_log, - r_graphics, g_options, r_animations, + r_graphics, g_options, r_animations, r_game, MAPDEF, g_base, g_basic, g_game, g_phys, g_monsters diff --git a/src/game/opengl/r_netmaster.pas b/src/game/opengl/r_netmaster.pas index e82db08..679e85a 100644 --- a/src/game/opengl/r_netmaster.pas +++ b/src/game/opengl/r_netmaster.pas @@ -25,7 +25,7 @@ implementation uses SysUtils, Classes, Math, - r_graphics, + r_graphics, r_game, g_basic, g_language, g_game, g_menu ; diff --git a/src/game/opengl/r_player.pas b/src/game/opengl/r_player.pas index 41c519b..7d0269c 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_playermodel, r_graphics, r_animations, r_textures, r_items, r_game ; var diff --git a/src/game/opengl/r_render.pas b/src/game/opengl/r_render.pas index b6bb016..2eec521 100644 --- a/src/game/opengl/r_render.pas +++ b/src/game/opengl/r_render.pas @@ -20,11 +20,14 @@ interface procedure r_Render_Initialize; procedure r_Render_Finalize; - procedure r_Render_Resize (w, h: Integer); - procedure r_Render_Load; procedure r_Render_Free; + procedure r_Render_LoadTextures; + procedure r_Render_FreeTextures; + + procedure r_Render_Resize (w, h: Integer); + procedure r_Render_Update; procedure r_Render_Apply; @@ -36,8 +39,8 @@ implementation SysUtils, Classes, Math, e_log, g_system, g_game, g_options, g_console, - r_window, r_graphics, r_console, r_playermodel, - r_weapons, r_items, r_gfx, r_monsters, r_map, r_player + r_window, r_graphics, r_console, r_playermodel, r_textures, r_animations, + r_weapons, r_items, r_gfx, r_monsters, r_map, r_player, r_game ; var @@ -76,8 +79,21 @@ implementation end end; + procedure r_Render_LoadTextures; + begin + r_Game_LoadTextures; + r_Map_LoadTextures; + end; + + procedure r_Render_FreeTextures; + begin + r_Map_FreeTextures; + r_Game_FreeTextures; + end; + procedure r_Render_Load; begin + r_Game_Load; // load first! r_Player_Load; r_Map_Load; r_PlayerModel_Load; @@ -96,6 +112,9 @@ implementation r_PlayerModel_Free; r_Map_Free; r_Player_Free; + r_Game_Free; + g_Texture_DeleteAll; + g_Frames_DeleteAll; end; procedure r_Render_Initialize; diff --git a/src/game/sdl2/g_touch.pas b/src/game/sdl2/g_touch.pas index 629ca3a..da6edc8 100644 --- a/src/game/sdl2/g_touch.pas +++ b/src/game/sdl2/g_touch.pas @@ -36,7 +36,7 @@ implementation uses SysUtils, - e_log, r_graphics, e_input, g_options, g_game, g_gui, g_weapons, g_console; + e_log, r_graphics, r_game, e_input, g_options, g_game, g_gui, g_weapons, g_console; var angleFire: Boolean;