From c6b9f83af191797b22c2a07e2046d74802cb2336 Mon Sep 17 00:00:00 2001 From: DeaDDooMER Date: Mon, 17 Jan 2022 20:29:32 +0300 Subject: [PATCH] render: move screenshorts into render --- src/game/g_game.pas | 41 ++++++++++++++---------------------- src/game/opengl/r_render.pas | 24 ++++++++++++++++++--- 2 files changed, 37 insertions(+), 28 deletions(-) diff --git a/src/game/g_game.pas b/src/game/g_game.pas index 17c9fda..f341dab 100644 --- a/src/game/g_game.pas +++ b/src/game/g_game.pas @@ -5737,33 +5737,24 @@ begin end; procedure g_TakeScreenShot(Filename: string = ''); - var s: TStream; t: TDateTime; dir, date, name: String; + var t: TDateTime; dir, date, name: String; begin - if e_NoGraphics then Exit; - try - dir := e_GetWriteableDir(ScreenshotDirs); + if e_NoGraphics then + Exit; - if Filename = '' then - begin - t := Now; - DateTimeToString(date, 'yyyy-mm-dd-hh-nn-ss', t); - Filename := 'screenshot-' + date; - end; - - name := e_CatPath(dir, Filename + '.png'); - s := createDiskFile(name); - try - e_MakeScreenshot(s, gScreenWidth, gScreenHeight); - s.Free; - g_Console_Add(Format(_lc[I_CONSOLE_SCREENSHOT], [name])) - except - g_Console_Add(Format(_lc[I_CONSOLE_ERROR_WRITE], [name])); - s.Free; - DeleteFile(name) - end - except - g_Console_Add('oh shit, i can''t create screenshot!') - end + dir := e_GetWriteableDir(ScreenshotDirs); + if Filename = '' then + begin + t := Now; + DateTimeToString(date, 'yyyy-mm-dd-hh-nn-ss', t); + Filename := 'screenshot-' + date; + end; + + name := e_CatPath(dir, Filename + '.png'); + if r_Render_WriteScreenShot(name) then + g_Console_Add(Format(_lc[I_CONSOLE_SCREENSHOT], [name])) + else + g_Console_Add(Format(_lc[I_CONSOLE_ERROR_WRITE], [name])); end; procedure g_Game_InGameMenu(Show: Boolean); diff --git a/src/game/opengl/r_render.pas b/src/game/opengl/r_render.pas index 90bda3b..76ef595 100644 --- a/src/game/opengl/r_render.pas +++ b/src/game/opengl/r_render.pas @@ -26,18 +26,19 @@ interface procedure r_Render_LoadTextures; procedure r_Render_FreeTextures; - procedure r_Render_Resize (w, h: Integer); - procedure r_Render_Update; + procedure r_Render_Resize (w, h: Integer); procedure r_Render_Apply; + function r_Render_WriteScreenShot (filename: String): Boolean; + implementation uses {$INCLUDE ../../nogl/noGLuses.inc} SysUtils, Classes, Math, - e_log, g_system, + e_log, g_system, utils, g_game, g_options, g_console, 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 @@ -178,4 +179,21 @@ implementation sys_EnableVSync(gVSync) end; + function r_Render_WriteScreenShot (filename: String): Boolean; + var s: TStream; + begin + Result := False; + try + s := CreateDiskFile(filename); + try + e_MakeScreenshot(s, gScreenWidth, gScreenHeight); + Result := True; + except + DeleteFile(filename) + end; + s.Free; + finally + end + end; + end. -- 2.29.2