From: Ketmar Dark <ketmar@ketmar.no-ip.org>
Date: Sun, 13 Oct 2019 00:41:07 +0000 (+0300)
Subject: game: create/refresh hash databases only when the game is going to conntect to any... 
X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=f9af3a48743f80e9095082f9d8156d60b62f6b29;p=d2df-sdl.git

game: create/refresh hash databases only when the game is going to conntect to any server
---

diff --git a/src/game/g_game.pas b/src/game/g_game.pas
index 4e23826..2b82741 100644
--- a/src/game/g_game.pas
+++ b/src/game/g_game.pas
@@ -4610,6 +4610,10 @@ begin
   NetState := NET_STATE_AUTH;
 
   g_Game_SetLoadingText(_lc[I_LOAD_CONNECT], 0, False);
+
+  // create (or update) map/resource databases
+  g_Res_CreateDatabases(true);
+
 // Ñòàðòóåì êëèåíò
   if not g_Net_Connect(Addr, Port) then
   begin
diff --git a/src/game/g_main.pas b/src/game/g_main.pas
index 5ea72be..3b84f30 100644
--- a/src/game/g_main.pas
+++ b/src/game/g_main.pas
@@ -161,7 +161,7 @@ begin
   g_holmes_imfunctional := not flexloaded;
 {$ENDIF}
 
-  g_Res_CreateDatabases();
+  //g_Res_CreateDatabases(); // it will be done before connecting to the server for the first time
 
   e_WriteLog('Entering SDLMain', TMsgType.Notify);
 
diff --git a/src/game/g_res_downloader.pas b/src/game/g_res_downloader.pas
index 438cd58..85438c4 100644
--- a/src/game/g_res_downloader.pas
+++ b/src/game/g_res_downloader.pas
@@ -30,7 +30,7 @@ function g_Res_DownloadMapWAD (FileName: AnsiString; const mapHash: TMD5Digest):
 function g_Res_FindReplacementWad (oldname: AnsiString): AnsiString;
 
 // call this somewhere in startup sequence
-procedure g_Res_CreateDatabases ();
+procedure g_Res_CreateDatabases (allowRescan: Boolean=false);
 
 
 implementation
@@ -97,40 +97,52 @@ end;
 //  g_Res_CreateDatabases
 //
 //==========================================================================
-procedure g_Res_CreateDatabases ();
+procedure g_Res_CreateDatabases (allowRescan: Boolean=false);
 var
   st: TStream;
+  upmap: Boolean;
+  upres: Boolean;
+  forcesave: Boolean;
 begin
-  // create and load a know map database, if necessary
-  knownMaps.Free;
-  knownMaps := TFileHashDB.Create(GameDir+'/maps/');
-  knownRes := TFileHashDB.Create(GameDir+'/wads/');
-  saveDBsToDiskEnabled := true;
-  // load map database
-  st := nil;
-  try
-    st := openDiskFileRO(GameDir+'/data/maphash.db');
-    knownMaps.loadFrom(st);
-    e_LogWriteln('loaded map database');
-  except
-  end;
-  st.Free;
-  // load resource database
-  st := nil;
-  try
-    st := openDiskFileRO(GameDir+'/data/reshash.db');
-    knownRes.loadFrom(st);
-    e_LogWriteln('loaded resource database');
-  except
+  if not assigned(knownMaps) then
+  begin
+    // create and load a know map database, if necessary
+    knownMaps := TFileHashDB.Create(GameDir+'/maps/');
+    knownRes := TFileHashDB.Create(GameDir+'/wads/');
+    saveDBsToDiskEnabled := true;
+    // load map database
+    st := nil;
+    try
+      st := openDiskFileRO(GameDir+'/data/maphash.db');
+      knownMaps.loadFrom(st);
+      e_LogWriteln('loaded map database');
+    except
+    end;
+    st.Free;
+    // load resource database
+    st := nil;
+    try
+      st := openDiskFileRO(GameDir+'/data/reshash.db');
+      knownRes.loadFrom(st);
+      e_LogWriteln('loaded resource database');
+    except
+    end;
+    st.Free;
+    forcesave := true;
+  end
+  else
+  begin
+    if (not allowRescan) then exit;
+    forcesave := false;
   end;
-  st.Free;
   // rescan dirs
   e_LogWriteln('refreshing map database');
-  knownMaps.scanFiles();
+  upmap := knownMaps.scanFiles();
   e_LogWriteln('refreshing resource database');
-  knownRes.scanFiles();
+  upres := knownRes.scanFiles();
   // save databases
-  saveDatabases(true, true);
+  if (forcesave) then begin upmap := true; upres := true; end;
+  if upmap or upres then saveDatabases(upmap, upres);
 end;
 
 
@@ -346,6 +358,7 @@ var
 begin
   result := '';
   clearReplacementWads();
+  g_Res_CreateDatabases();
 
   try
     g_Res_received_map_start := 1;