From: Ketmar Dark Date: Mon, 11 Sep 2017 22:20:04 +0000 (+0300) Subject: slightly faster map reloading on restart; enabled "--game-scale" cli arg in non-debug... X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=816a013e42b930a34a1e231c1620bb0dd65bf609;p=d2df-sdl.git slightly faster map reloading on restart; enabled "--game-scale" cli arg in non-debug builds --- diff --git a/src/game/g_map.pas b/src/game/g_map.pas index 1b92a96..ad9c68d 100644 --- a/src/game/g_map.pas +++ b/src/game/g_map.pas @@ -1597,7 +1597,7 @@ type end; var WAD: TWADFile; - mapReader: TDynRecord = nil; + //mapReader: TDynRecord = nil; mapTextureList: TDynField = nil; //TTexturesRec1Array; tagInt: texture index panels: TDynField = nil; //TPanelsRec1Array; items: TDynField = nil; //TItemsRec1Array; @@ -1625,82 +1625,91 @@ begin mapGrid.Free(); mapGrid := nil; - gCurrentMap.Free(); - gCurrentMap := nil; + //gCurrentMap.Free(); + //gCurrentMap := nil; panByGUID := nil; Result := False; gMapInfo.Map := Res; TriggersTable := nil; - mapReader := nil; + //mapReader := nil; sfsGCDisable(); // temporary disable removing of temporary volumes try - // Çàãðóçêà WAD: - FileName := g_ExtractWadName(Res); - e_WriteLog('Loading map WAD: '+FileName, MSG_NOTIFY); - g_Game_SetLoadingText(_lc[I_LOAD_WAD_FILE], 0, False); - - WAD := TWADFile.Create(); - if not WAD.ReadFile(FileName) then + // Çàãðóçêà WAD (åñëè ó íàñ íåò óæå çàãðóæåíîé êàðòû) + if (gCurrentMap = nil) then begin - g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [FileName])); - WAD.Free(); - Exit; - end; + FileName := g_ExtractWadName(Res); + e_WriteLog('Loading map WAD: '+FileName, MSG_NOTIFY); + g_Game_SetLoadingText(_lc[I_LOAD_WAD_FILE], 0, False); + + WAD := TWADFile.Create(); + if not WAD.ReadFile(FileName) then + begin + g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [FileName])); + WAD.Free(); + Exit; + end; + + //k8: why loader ignores path here? + mapResName := g_ExtractFileName(Res); + if not WAD.GetMapResource(mapResName, Data, Len) then + begin + g_FatalError(Format(_lc[I_GAME_ERROR_MAP_RES], [mapResName])); + WAD.Free(); + Exit; + end; - //k8: why loader ignores path here? - mapResName := g_ExtractFileName(Res); - if not WAD.GetMapResource(mapResName, Data, Len) then - begin - g_FatalError(Format(_lc[I_GAME_ERROR_MAP_RES], [mapResName])); WAD.Free(); - Exit; - end; - WAD.Free(); + if (Len < 4) then + begin + e_LogWritefln('invalid map file: ''%s''', [mapResName]); + FreeMem(Data); + exit; + end; - if (Len < 4) then - begin - e_LogWritefln('invalid map file: ''%s''', [mapResName]); - FreeMem(Data); - exit; - end; + // Çàãðóçêà êàðòû: + e_LogWritefln('Loading map: %s', [mapResName], MSG_NOTIFY); + g_Game_SetLoadingText(_lc[I_LOAD_MAP], 0, False); - // Çàãðóçêà êàðòû: - e_LogWritefln('Loading map: %s', [mapResName], MSG_NOTIFY); - g_Game_SetLoadingText(_lc[I_LOAD_MAP], 0, False); + stt := getTimeMicro(); - stt := getTimeMicro(); + try + gCurrentMap := g_Map_ParseMap(Data, Len); + except + gCurrentMap.Free(); + g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Res])); + FreeMem(Data); + gCurrentMapFileName := ''; + Exit; + end; - try - mapReader := g_Map_ParseMap(Data, Len); - except - mapReader.Free(); - g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Res])); FreeMem(Data); - Exit; - end; - FreeMem(Data); - - if (mapReader = nil) then + if (gCurrentMap = nil) then + begin + e_LogWritefln('invalid map file: ''%s''', [mapResName]); + gCurrentMapFileName := ''; + exit; + end; + end + else begin - e_LogWritefln('invalid map file: ''%s''', [mapResName]); - exit; + stt := getTimeMicro(); end; - gCurrentMap := mapReader; + //gCurrentMap := mapReader; - generateExternalResourcesList(mapReader); - mapTextureList := mapReader['texture']; + generateExternalResourcesList(gCurrentMap); + mapTextureList := gCurrentMap['texture']; // get all other lists here too - panels := mapReader['panel']; - triggers := mapReader['trigger']; - items := mapReader['item']; - areas := mapReader['area']; - monsters := mapReader['monster']; + panels := gCurrentMap['panel']; + triggers := gCurrentMap['trigger']; + items := gCurrentMap['item']; + areas := gCurrentMap['area']; + monsters := gCurrentMap['monster']; // Çàãðóçêà îïèñàíèÿ êàðòû: e_WriteLog(' Reading map info...', MSG_NOTIFY); @@ -1708,13 +1717,13 @@ begin with gMapInfo do begin - Name := mapReader.MapName; - Description := mapReader.MapDesc; - Author := mapReader.MapAuthor; - MusicName := mapReader.MusicName; - SkyName := mapReader.SkyName; - Height := mapReader.Height; - Width := mapReader.Width; + Name := gCurrentMap.MapName; + Description := gCurrentMap.MapDesc; + Author := gCurrentMap.MapAuthor; + MusicName := gCurrentMap.MusicName; + SkyName := gCurrentMap.SkyName; + Height := gCurrentMap.Height; + Width := gCurrentMap.Width; end; // Çàãðóçêà òåêñòóð: @@ -1781,6 +1790,7 @@ begin begin e_WriteLog('error loading map: invalid texture index for panel', MSG_FATALERROR); result := false; + gCurrentMap.Free(); gCurrentMap := nil; gCurrentMapFileName := ''; exit; @@ -2079,9 +2089,9 @@ begin for rec in monsters do CreateMonster(rec); end; - gCurrentMap := mapReader; // this will be our current map now + //gCurrentMap := mapReader; // this will be our current map now gCurrentMapFileName := Res; - mapReader := nil; + //mapReader := nil; // Çàãðóçêà íåáà if (gMapInfo.SkyName <> '') then @@ -2166,10 +2176,11 @@ begin mapOk := true; finally sfsGCEnable(); // enable releasing unused volumes - mapReader.Free(); + //mapReader.Free(); e_ClearInputBuffer(); // why not? if not mapOk then begin + gCurrentMap.Free(); gCurrentMap := nil; gCurrentMapFileName := ''; end; @@ -2346,6 +2357,7 @@ begin begin e_LogWritefln('g_Map_Free: no previous map.', []); end; + if freeTextures then begin e_LogWritefln('g_Map_Free: clearing textures...', []); @@ -2374,6 +2386,9 @@ begin TextNameHash := nil; BadTextNameHash.Free(); BadTextNameHash := nil; + gCurrentMapFileName := ''; + gCurrentMap.Free(); + gCurrentMap := nil; end; panByGUID := nil; diff --git a/src/game/g_window.pas b/src/game/g_window.pas index 46ec6df..71ec201 100644 --- a/src/game/g_window.pas +++ b/src/game/g_window.pas @@ -865,7 +865,6 @@ begin end; end; - {$IF DEFINED(D2F_DEBUG)} if (arg = '--game-scale') or (arg = '-game-scale') then begin if (idx <= ParamCount) then @@ -874,7 +873,6 @@ begin Inc(idx); end; end; - {$ENDIF} if (arg = '--write-mapdef') or (arg = '-write-mapdef') then begin diff --git a/src/shared/a_modes.inc b/src/shared/a_modes.inc index 7e14a8b..9a17a82 100644 --- a/src/shared/a_modes.inc +++ b/src/shared/a_modes.inc @@ -46,7 +46,7 @@ {$POINTERMATH ON} {$RANGECHECKS OFF} {$SAFEFPUEXCEPTIONS OFF} -{$SCOPEDENUMS OFF} // this will possibly be changed later +{$SCOPEDENUMS OFF} // this may be changed later {$SMARTLINK ON} {$TYPEDADDRESS ON} {$TYPEINFO ON}