From: Ketmar Dark Date: Fri, 25 Aug 2017 10:41:56 +0000 (+0300) Subject: fixed(?) loading saved games X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=fb2545cc618f2ffe256ab3bc0173b063382c8887;p=d2df-sdl.git fixed(?) loading saved games --- diff --git a/src/game/g_game.pas b/src/game/g_game.pas index 75d2693..24f6324 100644 --- a/src/game/g_game.pas +++ b/src/game/g_game.pas @@ -124,7 +124,6 @@ procedure GameCVars(P: SArray); procedure GameCommands(P: SArray); procedure GameCheats(P: SArray); procedure DebugCommands(P: SArray); -//procedure ProfilerCommands(P: SArray); procedure g_Game_Process_Params; procedure g_Game_SetLoadingText(Text: String; Max: Integer; reWrite: Boolean); procedure g_Game_StepLoading(); @@ -4975,59 +4974,6 @@ begin end; end; -(* -// profiler console commands -procedure ProfilerCommands (P: SArray); -var - cmd: string; - - function getBool (idx: Integer): Integer; - begin - if (idx < 0) or (idx > High(P)) then begin result := -1; exit; end; - result := 0; - if (P[idx] = '1') or (P[idx] = 'on') or (P[idx] = 'true') or (P[idx] = 'tan') then result := 1; - end; - - procedure binaryFlag (var flag: Boolean; msg: string); - begin - if (Length(p) > 2) then - begin - g_Console_Add('too many arguments to '''+P[0]+''''); - end - else - begin - case getBool(1) of - -1: begin end; - 0: flag := false; - 1: flag := true; - end; - if flag then g_Console_Add(msg+': tan') else g_Console_Add(msg+': ona'); - end; - end; - -begin - //if not gDebugMode then exit; - cmd := LowerCase(P[0]); - - if (cmd = 'pf_draw_frame') then begin binaryFlag(g_profile_frame_draw, 'render profiles'); exit; end; - if (cmd = 'pf_update_frame') then begin binaryFlag(g_profile_frame_update, 'update profiles (not yet)'); exit; end; - if (cmd = 'pf_coldet') then begin binaryFlag(g_profile_collision, 'coldet profiles'); exit; end; - if (cmd = 'pf_los') then begin binaryFlag(g_profile_los, 'monster LOS profiles'); exit; end; - if (cmd = 'r_sq_draw') then begin binaryFlag(gdbg_map_use_accel_render, 'accelerated rendering'); exit; end; - if (cmd = 'cd_sq_enabled') then begin binaryFlag(gdbg_map_use_accel_coldet, 'accelerated map coldet'); exit; end; - if (cmd = 'mon_sq_enabled') then begin binaryFlag(gmon_debug_use_sqaccel, 'accelerated monster coldet'); exit; end; - if (cmd = 'wtrace_sq_enabled') then begin binaryFlag(gwep_debug_fast_trace, 'accelerated weapon hitscan'); exit; end; - if (cmd = 'pr_enabled') then begin binaryFlag(gpart_dbg_enabled, 'particles'); exit; end; - if (cmd = 'pr_phys_enabled') then begin binaryFlag(gpart_dbg_phys_enabled, 'particle physics'); exit; end; - if (cmd = 'los_enabled') then begin binaryFlag(gmon_dbg_los_enabled, 'LOS calculations'); exit; end; - - if (not gGameOn) or (not gCheats) or ((gGameSettings.GameType <> GT_SINGLE) and - (gGameSettings.GameMode <> GM_COOP) and (not gDebugMode)) or g_Game_IsNet then exit; - - if (cmd = 'mon_think') then begin binaryFlag(gmon_debug_think, 'monster thinking'); exit; end; - if (cmd = 'dbg_holmes') then begin binaryFlag(g_holmes_enabled, 'Holmes'); exit; end; -end; -*) procedure DebugCommands(P: SArray); var diff --git a/src/game/g_map.pas b/src/game/g_map.pas index b9da59d..d93f0aa 100644 --- a/src/game/g_map.pas +++ b/src/game/g_map.pas @@ -1217,7 +1217,7 @@ begin calcBoundingBox(gLifts); calcBoundingBox(gBlockMon); - e_WriteLog(Format('map dimensions: (%d,%d)-(%d,%d); editor size:(0,0)-(%d,%d)', [mapX0, mapY0, mapX1, mapY1, gMapInfo.Width, gMapInfo.Height]), MSG_WARNING); + e_LogWritefln('map dimensions: (%d,%d)-(%d,%d); editor size:(0,0)-(%d,%d)', [mapX0, mapY0, mapX1, mapY1, gMapInfo.Width, gMapInfo.Height]); if (mapX0 > 0) then mapX0 := 0; if (mapY0 > 0) then mapY0 := 0; @@ -2757,6 +2757,7 @@ var PAMem.LoadFromMemory(Mem); for i := 0 to Length(panels)-1 do + begin if panels[i].SaveIt then begin // ID ïàíåëè: @@ -2767,7 +2768,9 @@ var end; // Çàãðóæàåì ïàíåëü: panels[i].LoadState(PAMem); + panels[i].arrIdx := i; end; + end; // Ýòîò ñïèñîê ïàíåëåé çàãðóæåí: PAMem.Free(); @@ -2820,7 +2823,7 @@ begin // Îáíîâëÿåì êàðòó ñòîëêíîâåíèé è ñåòêó: g_GFX_Init(); - mapCreateGrid(); + //mapCreateGrid(); ///// Çàãðóæàåì ìóçûêó: ///// // Ñèãíàòóðà ìóçûêè: diff --git a/src/game/g_monsters.pas b/src/game/g_monsters.pas index 8c2f2d7..04e1924 100644 --- a/src/game/g_monsters.pas +++ b/src/game/g_monsters.pas @@ -173,7 +173,7 @@ procedure g_Mons_InitTree (x, y, w, h: Integer); procedure g_Monsters_LoadData (); procedure g_Monsters_FreeData (); procedure g_Monsters_Init (); -procedure g_Monsters_Free (); +procedure g_Monsters_Free (clearGrid: Boolean=true); function g_Monsters_Create (MonsterType: Byte; X, Y: Integer; Direction: TDirection; AdjCoord: Boolean = False; ForcedUID: Integer = -1): TMonster; procedure g_Monsters_Update (); @@ -1191,12 +1191,16 @@ begin soulcount := 0; end; -procedure g_Monsters_Free(); +procedure g_Monsters_Free (clearGrid: Boolean=true); var a: Integer; begin - monsGrid.Free(); - monsGrid := nil; + e_LogWritefln('Cleared monster data (clearGrid=%s)', [clearGrid]); + if (clearGrid) then + begin + monsGrid.Free(); + monsGrid := nil; + end; for a := 0 to High(gMonsters) do gMonsters[a].Free(); gMonsters := nil; clearUidMap(); @@ -1209,6 +1213,8 @@ procedure g_Mons_InitTree (x, y, w, h: Integer); begin monsGrid.Free(); monsGrid := TMonsterGrid.Create(x, y, w, h); + //clearUidMap(); // why not? + e_LogWritefln('%s', ['Recreated monster tree']); end; @@ -1417,7 +1423,7 @@ var begin if Mem = nil then exit; - g_Monsters_Free(); + g_Monsters_Free(false); // Çàãðóæàåì èíôîðìàöèþ öåëåóêàçàòåëÿ Mem.ReadInt(pt_x); @@ -4345,6 +4351,10 @@ begin end; end; +procedure monsPostLoad (); +begin +end; + procedure TMonster.LoadState(var Mem: TBinMemoryReader); var i: Integer; @@ -4361,8 +4371,13 @@ begin begin raise EBinSizeError.Create('TMonster.LoadState: Wrong Monster Signature'); end; + if (uidMap[FUID] <> nil) and (uidMap[FUID] <> self) then raise Exception.Create('internal error in monster loader (0)'); + uidMap[FUID] := nil; // UID ìîíñòðà: Mem.ReadWord(FUID); + //if (arrIdx = -1) then raise Exception.Create('internal error in monster loader'); + if (uidMap[FUID] <> nil) then raise Exception.Create('internal error in monster loader (1)'); + uidMap[FUID] := self; // Íàïðàâëåíèå: Mem.ReadByte(b); if b = 1 then @@ -4665,4 +4680,6 @@ begin end; +begin + g_SetPostLoadHook(monsPostLoad); end. diff --git a/src/game/g_saveload.pas b/src/game/g_saveload.pas index aaf01b5..e6a1ca2 100644 --- a/src/game/g_saveload.pas +++ b/src/game/g_saveload.pas @@ -27,6 +27,16 @@ function g_LoadGame(n: Integer): Boolean; procedure Obj_SaveState(o: PObj; var Mem: TBinMemoryWriter); procedure Obj_LoadState(o: PObj; var Mem: TBinMemoryReader); +type + TLoadSaveHook = procedure (); + +procedure g_SetPreLoadHook (ahook: TLoadSaveHook); +procedure g_SetPostLoadHook (ahook: TLoadSaveHook); + +procedure g_CallPreLoadHooks (); +procedure g_CallPostLoadHooks (); + + implementation uses @@ -42,6 +52,44 @@ const PLAYER_VIEW_SIGNATURE = $57564C50; // 'PLVW' OBJ_SIGNATURE = $4A424F5F; // '_OBJ' + +var + preloadHooks: array of TLoadSaveHook = nil; + postloadHooks: array of TLoadSaveHook = nil; + + +procedure g_SetPreLoadHook (ahook: TLoadSaveHook); +begin + if not assigned(ahook) then exit; + SetLength(preloadHooks, Length(preloadHooks)+1); + preloadHooks[High(preloadHooks)] := ahook; +end; + + +procedure g_SetPostLoadHook (ahook: TLoadSaveHook); +begin + if not assigned(ahook) then exit; + SetLength(postloadHooks, Length(postloadHooks)+1); + postloadHooks[High(postloadHooks)] := ahook; +end; + + +procedure g_CallPreLoadHooks (); +var + f: Integer; +begin + for f := 0 to High(preloadHooks) do preloadHooks[f](); +end; + + +procedure g_CallPostLoadHooks (); +var + f: Integer; +begin + for f := 0 to High(postloadHooks) do postloadHooks[f](); +end; + + procedure Obj_SaveState(o: PObj; var Mem: TBinMemoryWriter); var sig: DWORD; @@ -359,6 +407,8 @@ begin g_Game_SetLoadingText(_lc[I_LOAD_SAVE_FILE], 0, False); gLoadGameMode := True; + g_CallPreLoadHooks(); + ///// Çàãðóæàåì ñîñòîÿíèå èãðû: ///// bMem := TBinMemoryReader.Create(); bFile.ReadMemory(bMem); @@ -571,6 +621,7 @@ begin // Çàêðûâàåì ôàéë çàãðóçêè: bFile.Close(); gLoadGameMode := False; + g_CallPostLoadHooks(); Result := True; except