DEADSOFTWARE

we don't really need microsecond resolution in timer
[d2df-sdl.git] / src / game / g_game.pas
index 265533e11fa49a7f094e3438865f55deb36975ee..3bb18b729d9cff35516f93ecfdc0e0bdf4c66db2 100644 (file)
@@ -244,7 +244,7 @@ var
   gWinPosX, gWinPosY: Integer;
   gWinSizeX, gWinSizeY: Integer;
   gWinFrameX, gWinFrameY, gWinCaption: Integer;
-  gWinActive: Boolean = False;
+  gWinActive: Boolean = True; // by default window is active, lol
   gResolutionChange: Boolean = False;
   gRC_Width, gRC_Height: Word;
   gRC_FullScreen, gRC_Maximized: Boolean;
@@ -294,7 +294,8 @@ uses
   g_playermodel, g_gfx, g_options, g_weapons, Math,
   g_triggers, MAPDEF, g_monsters, e_sound, CONFIG,
   BinEditor, g_language, g_net, SDL,
-  ENet, e_fixedbuffer, g_netmsg, g_netmaster, GL, GLExt;
+  ENet, e_fixedbuffer, g_netmsg, g_netmaster, GL, GLExt,
+  utils, sfs;
 
 type
   TEndCustomGameStat = record
@@ -652,7 +653,7 @@ begin
   gDelayedEvents[n].DENum := Num;
   gDelayedEvents[n].DEStr := Str;
   if DEType = DE_GLOBEVENT then
-    gDelayedEvents[n].Time := (GetTimer() div 1000) + Time
+    gDelayedEvents[n].Time := (GetTimer() {div 1000}) + Time
   else
     gDelayedEvents[n].Time := gTime + Time;
   Result := n;
@@ -1019,66 +1020,86 @@ begin
   gMapToDelete := '';
   gTempDelete := False;
 
-  g_Texture_CreateWADEx('MENU_BACKGROUND', GameWAD+':TEXTURES\TITLE');
-  g_Texture_CreateWADEx('INTER', GameWAD+':TEXTURES\INTER');
-  g_Texture_CreateWADEx('ENDGAME_EN', GameWAD+':TEXTURES\ENDGAME_EN');
-  g_Texture_CreateWADEx('ENDGAME_RU', GameWAD+':TEXTURES\ENDGAME_RU');
-
-  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);
-
-  g_Game_SetLoadingText(_lc[I_LOAD_CONSOLE], 0, False);
-  g_Console_Init();
-
-  g_Game_SetLoadingText(_lc[I_LOAD_MODELS], 0, False);
-  g_PlayerModel_LoadData();
-
-  if FindFirst(ModelsDir+'*.wad', faAnyFile, SR) = 0 then
-    repeat
-      if not g_PlayerModel_Load(ModelsDir+SR.Name) then
-        e_WriteLog(Format('Error loading model %s', [SR.Name]), MSG_WARNING);
-    until FindNext(SR) <> 0;
-  FindClose(SR);
-
-  gGameOn := False;
-  gPause := False;
-  gTime := 0;
-  LastScreenShot := 0;
-
-  {e_MouseInfo.Accel := 1.0;}
-
-  g_Game_SetLoadingText(_lc[I_LOAD_GAME_DATA], 0, False);
-  g_Game_LoadData();
-
-  g_Game_SetLoadingText(_lc[I_LOAD_MUSIC], 0, False);
-  g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD+':MUSIC\INTERMUS', True);
-  g_Sound_CreateWADEx('MUSIC_MENU', GameWAD+':MUSIC\MENU', True);
-  g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD+':MUSIC\ROUNDMUS');
-  g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD+':MUSIC\ENDMUS', True);
-
-  g_Game_SetLoadingText(_lc[I_LOAD_MENUS], 0, False);
-  g_Menu_Init();
-
-  gMusic := TMusic.Create();
-  gMusic.SetByName('MUSIC_MENU');
-  gMusic.Play();
-
-  gGameSettings.WarmupTime := 30;
-
-  gState := STATE_MENU;
-
-  SetLength(gEvents, 6);
-  gEvents[0].Name := 'ongamestart';
-  gEvents[1].Name := 'ongameend';
-  gEvents[2].Name := 'onmapstart';
-  gEvents[3].Name := 'onmapend';
-  gEvents[4].Name := 'oninter';
-  gEvents[5].Name := 'onwadend';
+  sfsGCDisable(); // temporary disable removing of temporary volumes
+
+  try
+    g_Texture_CreateWADEx('MENU_BACKGROUND', GameWAD+':TEXTURES\TITLE');
+    g_Texture_CreateWADEx('INTER', GameWAD+':TEXTURES\INTER');
+    g_Texture_CreateWADEx('ENDGAME_EN', GameWAD+':TEXTURES\ENDGAME_EN');
+    g_Texture_CreateWADEx('ENDGAME_RU', GameWAD+':TEXTURES\ENDGAME_RU');
+
+    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);
+
+    g_Game_SetLoadingText(_lc[I_LOAD_CONSOLE], 0, False);
+    g_Console_Init();
+
+    g_Game_SetLoadingText(_lc[I_LOAD_MODELS], 0, False);
+    g_PlayerModel_LoadData();
+
+    if FindFirst(ModelsDir+'*.wad', faAnyFile, SR) = 0 then
+      repeat
+        if not g_PlayerModel_Load(ModelsDir+SR.Name) then
+          e_WriteLog(Format('Error loading model %s', [SR.Name]), MSG_WARNING);
+      until FindNext(SR) <> 0;
+    FindClose(SR);
+
+    if FindFirst(ModelsDir+'*.pk3', faAnyFile, SR) = 0 then
+      repeat
+        if not g_PlayerModel_Load(ModelsDir+SR.Name) then
+          e_WriteLog(Format('Error loading model %s', [SR.Name]), MSG_WARNING);
+      until FindNext(SR) <> 0;
+    FindClose(SR);
+
+    if FindFirst(ModelsDir+'*.zip', faAnyFile, SR) = 0 then
+      repeat
+        if not g_PlayerModel_Load(ModelsDir+SR.Name) then
+          e_WriteLog(Format('Error loading model %s', [SR.Name]), MSG_WARNING);
+      until FindNext(SR) <> 0;
+    FindClose(SR);
+
+    gGameOn := False;
+    gPause := False;
+    gTime := 0;
+    LastScreenShot := 0;
+
+    {e_MouseInfo.Accel := 1.0;}
+
+    g_Game_SetLoadingText(_lc[I_LOAD_GAME_DATA], 0, False);
+    g_Game_LoadData();
+
+    g_Game_SetLoadingText(_lc[I_LOAD_MUSIC], 0, False);
+    g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD+':MUSIC\INTERMUS', True);
+    g_Sound_CreateWADEx('MUSIC_MENU', GameWAD+':MUSIC\MENU', True);
+    g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD+':MUSIC\ROUNDMUS', True);
+    g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD+':MUSIC\ENDMUS', True);
+
+    g_Game_SetLoadingText(_lc[I_LOAD_MENUS], 0, False);
+    g_Menu_Init();
+
+    gMusic := TMusic.Create();
+    gMusic.SetByName('MUSIC_MENU');
+    gMusic.Play();
+
+    gGameSettings.WarmupTime := 30;
+
+    gState := STATE_MENU;
+
+    SetLength(gEvents, 6);
+    gEvents[0].Name := 'ongamestart';
+    gEvents[1].Name := 'ongameend';
+    gEvents[2].Name := 'onmapstart';
+    gEvents[3].Name := 'onmapend';
+    gEvents[4].Name := 'oninter';
+    gEvents[5].Name := 'onwadend';
+  finally
+    sfsGCEnable(); // enable releasing unused volumes
+  end;
 end;
 
 procedure g_Game_Free();
@@ -1732,7 +1753,7 @@ begin
 
 // Äåëàåì ñêðèíøîò (íå ÷àùå 200 ìèëëèñåêóíä):
   if e_KeyPressed(gGameControls.GameControls.TakeScreenshot) then
-    if (GetTimer()-LastScreenShot) > 200000 then
+    if (GetTimer()-LastScreenShot) > 200000 div 1000 then
     begin
       g_TakeScreenShot();
       LastScreenShot := GetTimer();
@@ -1747,7 +1768,7 @@ begin
     KeyPress(IK_F10);
   end;
 
-  Time := GetTimer() div 1000;
+  Time := GetTimer() {div 1000};
 
 // Îáðàáîòêà îòëîæåííûõ ñîáûòèé:
   if gDelayedEvents <> nil then
@@ -2272,7 +2293,7 @@ begin
       end;
 end;
 
-procedure DrawMinimap(p: TPlayer; RenderRect: TRect);
+procedure DrawMinimap(p: TPlayer; RenderRect: e_graphics.TRect);
 var
   a, aX, aY, aX2, aY2, Scale, ScaleSz: Integer;
 begin
@@ -2645,8 +2666,7 @@ begin
   p.DrawPain();
   p.DrawPickup();
   p.DrawRulez();
-  //if gShowMap then
-    //DrawMinimap(p, _TRect(0, 0, 128, 128));
+  if gShowMap then DrawMinimap(p, _TRect(0, 0, 128, 128));
   if g_Debug_Player then
     g_Player_DrawDebug(p);
   p.DrawGUI();
@@ -2664,7 +2684,7 @@ var
 begin
   if gExit = EXIT_QUIT then Exit;
 
-  Time := GetTimer() div 1000;
+  Time := GetTimer() {div 1000};
   FPSCounter := FPSCounter+1;
   if Time - FPSTime >= 1000 then
   begin
@@ -4045,11 +4065,14 @@ end;
 
 procedure g_Game_DeleteTestMap();
 var
-  WAD: TWADEditor_1;
+  a: Integer;
   MapName: Char16;
-  MapList: SArray;
-  a, time: Integer;
   WadName: string;
+{
+  WAD: TWADEditor_1;
+  MapList: SArray;
+  time: Integer;
+}
 begin
   a := Pos('.wad:\', gMapToDelete);
   if a = 0 then
@@ -4062,6 +4085,7 @@ begin
   MapName := '';
   CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
 
+{
 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
   if MapName <> TEST_MAP_NAME then
     Exit;
@@ -4095,7 +4119,8 @@ begin
     WAD.Free();
     g_SetFileTime(WadName, time);
   end else
-    DeleteFile(WadName);
+}
+  if gTempDelete then DeleteFile(WadName);
 end;
 
 procedure GameCVars(P: SArray);
@@ -5168,9 +5193,7 @@ begin
       Exit;
     end;
     // Èãðà åù¸ íå çàïóùåíà, ñíà÷àëà íàì íàäî çàãðóçèòü êàêîé-òî WAD
-    if Pos('.wad', LowerCase(P[1])) = 0 then
-      P[1] := P[1] + '.wad';
-
+    P[1] := addWadExtension(P[1]);
     if FileExists(MapsDir + P[1]) then
     begin
       // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
@@ -5224,9 +5247,7 @@ begin
       Exit;
     prt := StrToIntDef(P[2], 25666);
 
-    if Pos('.wad', LowerCase(P[3])) = 0 then
-      P[3] := P[3] + '.wad';
-
+    P[3] := addWadExtension(P[3]);
     if FileExists(MapsDir + P[3]) then
     begin
       // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
@@ -5296,9 +5317,7 @@ begin
           begin
             g_Console_Add(Format(_lc[I_MSG_NO_MAP], [s]));
             // Òàêîé êàðòû íåò, èùåì WAD ôàéë
-            if Pos('.wad', LowerCase(P[1])) = 0 then
-              P[1] := P[1] + '.wad';
-
+            P[1] := addWadExtension(P[1]);
             if FileExists(MapsDir + P[1]) then
             begin
               // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
@@ -5328,9 +5347,7 @@ begin
         end else
         begin
           // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
-          if Pos('.wad', LowerCase(P[1])) = 0 then
-            P[1] := P[1] + '.wad';
-
+          P[1] := addWadExtension(P[1]);
           if FileExists(MapsDir + P[1]) then
           begin
             // Íàøëè WAD ôàéë
@@ -5389,9 +5406,7 @@ begin
             begin
               g_Console_Add(Format(_lc[I_MSG_NO_MAP], [s]));
               // Òàêîé êàðòû íåò, èùåì WAD ôàéë
-              if Pos('.wad', LowerCase(P[1])) = 0 then
-                P[1] := P[1] + '.wad';
-
+              P[1] := addWadExtension(P[1]);
               if FileExists(MapsDir + P[1]) then
               begin
                 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
@@ -5416,9 +5431,7 @@ begin
           end else
           begin
             // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
-            if Pos('.wad', LowerCase(P[1])) = 0 then
-              P[1] := P[1] + '.wad';
-
+            P[1] := addWadExtension(P[1]);
             if FileExists(MapsDir + P[1]) then
             begin
               // Íàøëè WAD ôàéë
@@ -6245,7 +6258,7 @@ begin
 
 // Start map when game loads:
   map := LowerCase(Find_Param_Value(pars, '-map'));
-  if (map <> '') and (Pos('.wad:\', map) > 0) then
+  if isWadPath(map) then
   begin
   // Game mode:
     s := Find_Param_Value(pars, '-gm');
@@ -6291,7 +6304,11 @@ begin
   // Delete test map after play:
     s := Find_Param_Value(pars, '--testdelete');
     if (s <> '') then
+    begin
       gMapToDelete := MapsDir + map;
+      e_WriteLog('"--testdelete" argument doesn''t supported anymore!', MSG_FATALERROR);
+      Halt(1);
+    end;
 
   // Delete temporary WAD after play:
     s := Find_Param_Value(pars, '--tempdelete');