X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fgame%2Fg_saveload.pas;h=bf56c6eeb0afb6b227e1dcbee88595b806f49489;hb=bab60f8ad58f03e8a35dbb44aba77bb9ff9201f9;hp=36cf7295eca66469710d281626452db2c3a3e2ab;hpb=88ce644db1b40111bdb380f4357fa59bdb5173be;p=d2df-sdl.git diff --git a/src/game/g_saveload.pas b/src/game/g_saveload.pas index 36cf729..bf56c6e 100644 --- a/src/game/g_saveload.pas +++ b/src/game/g_saveload.pas @@ -1,3 +1,19 @@ +(* Copyright (C) DooM 2D:Forever Developers + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + *) +{$INCLUDE ../shared/a_modes.inc} unit g_saveload; interface @@ -5,27 +21,30 @@ interface uses e_graphics, g_phys, g_textures, BinEditor; + function g_GetSaveName(n: Integer): String; function g_SaveGame(n: Integer; Name: String): Boolean; function g_LoadGame(n: Integer): Boolean; procedure Obj_SaveState(o: PObj; var Mem: TBinMemoryWriter); procedure Obj_LoadState(o: PObj; var Mem: TBinMemoryReader); + implementation uses g_game, g_items, g_map, g_monsters, g_triggers, - g_basic, g_main, SysUtils, Math, WADEDITOR, - MAPSTRUCT, MAPDEF, g_weapons, g_player, g_console, + g_basic, g_main, SysUtils, Math, wadreader, + MAPDEF, g_weapons, g_player, g_console, e_log, g_language; const SAVE_SIGNATURE = $56534644; // 'DFSV' - SAVE_VERSION = $02; + SAVE_VERSION = $05; END_MARKER_STRING = 'END'; PLAYER_VIEW_SIGNATURE = $57564C50; // 'PLVW' OBJ_SIGNATURE = $4A424F5F; // '_OBJ' + procedure Obj_SaveState(o: PObj; var Mem: TBinMemoryWriter); var sig: DWORD; @@ -147,11 +166,14 @@ begin bMem := TBinMemoryWriter.Create(256); // Èìÿ èãðû: bMem.WriteString(Name, 32); + // Ïîëíûé ïóòü ê âàäó è êàðòà + if (Length(gCurrentMapFileName) <> 0) then e_LogWritefln('SAVE: current map is ''%s''...', [gCurrentMapFileName]); + bMem.WriteString(gCurrentMapFileName); // Ïóòü ê êàðòå: str := gGameSettings.WAD; bMem.WriteString(str, 128); // Èìÿ êàðòû: - g_ProcessResourceStr(gMapInfo.Map, nil, nil, @str); + str := g_ExtractFileName(gMapInfo.Map); bMem.WriteString(str, 32); // Êîëè÷åñòâî èãðîêîâ: nPlayers := g_Player_GetCount(); @@ -321,6 +343,8 @@ var Game_CoopTotalSecrets, PID1, PID2: Word; i: Integer; + gameCleared: Boolean = false; + curmapfile: AnsiString = ''; begin Result := False; bMem := nil; @@ -337,7 +361,7 @@ begin end; e_WriteLog('Loading saved game...', MSG_NOTIFY); - g_Game_Free(); + //g_Game_Free(false); // don't free textures for the same map g_Game_ClearLoading(); g_Game_SetLoadingText(_lc[I_LOAD_SAVE_FILE], 0, False); @@ -348,6 +372,16 @@ begin bFile.ReadMemory(bMem); // Èìÿ èãðû: bMem.ReadString(str); + + // Ïîëíûé ïóòü ê âàäó è êàðòà + bMem.ReadString(curmapfile); + + if (Length(gCurrentMapFileName) <> 0) then e_LogWritefln('LOAD: previous map was ''%s''...', [gCurrentMapFileName]); + if (Length(curmapfile) <> 0) then e_LogWritefln('LOAD: new map is ''%s''...', [curmapfile]); + // À âîò òóò, íàêîíåö, ÷èñòèì ðåñóðñû + g_Game_Free(curmapfile <> gCurrentMapFileName); // don't free textures for the same map + gameCleared := true; + // Ïóòü ê êàðòå: bMem.ReadString(WAD_Path); // Èìÿ êàðòû: @@ -425,7 +459,7 @@ begin g_Game_SetupScreenSize(); // Çàãðóçêà è çàïóñê êàðòû: - if not g_Game_StartMap(WAD_Path + ':\' + Map_Name, True) then + if not g_Game_StartMap(WAD_Path + ':\' + Map_Name, True, curmapfile) then begin g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [WAD_Path + ':\' + Map_Name])); Exit; @@ -549,7 +583,7 @@ begin ///// ///// // Èùåì òðèããåðû ñ óñëîâèåì ñìåðòè ìîíñòðîâ: - if (gMonsters <> nil) and (gTriggers <> nil) then + if {(gMonsters <> nil) and} (gTriggers <> nil) then g_Map_ReAdd_DieTriggers(); // Çàêðûâàåì ôàéë çàãðóçêè: @@ -562,11 +596,13 @@ begin begin g_Console_Add(_lc[I_GAME_ERROR_LOAD]); e_WriteLog('LoadState I/O Error: '+E1.Message, MSG_WARNING); + if not gameCleared then g_Game_Free(); end; on E2: EBinSizeError do begin g_Console_Add(_lc[I_GAME_ERROR_LOAD]); e_WriteLog('LoadState Size Error: '+E2.Message, MSG_WARNING); + if not gameCleared then g_Game_Free(); end; end;