DEADSOFTWARE

render: move screenshorts into render
authorDeaDDooMER <deaddoomer@deadsoftware.ru>
Mon, 17 Jan 2022 17:29:32 +0000 (20:29 +0300)
committerDeaDDooMER <deaddoomer@deadsoftware.ru>
Mon, 17 Jan 2022 17:29:32 +0000 (20:29 +0300)
src/game/g_game.pas
src/game/opengl/r_render.pas

index 17c9fdafbd775d156abebd401148926d16b8f4a3..f341dab77d3be947924e6ec0592c0ef444e8aa42 100644 (file)
@@ -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);
index 90bda3b04a230a27abceb3ad4e651b518a5fad7e..76ef595268ff0ee9640d7d49ce70eb2ae84b0f42 100644 (file)
@@ -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.