From: binarymaster Date: Wed, 27 Sep 2017 15:13:19 +0000 (+0300) Subject: Map: Add test map override feature X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=8ef4762ff23dd290f3db936eafb12b247b5a9ac6;p=d2df-sdl.git Map: Add test map override feature --- diff --git a/src/game/g_console.pas b/src/game/g_console.pas index 9e6f4d5..fb0b9eb 100644 --- a/src/game/g_console.pas +++ b/src/game/g_console.pas @@ -265,7 +265,7 @@ var cp: PCommand; pv: PVarSingle; begin - GetMem(pv, sizeof(pv^)); + GetMem(pv, sizeof(TVarSingle)); pv.val := pvar; pv.min := amin; pv.max := amax; diff --git a/src/game/g_game.pas b/src/game/g_game.pas index eaccccc..5328038 100644 --- a/src/game/g_game.pas +++ b/src/game/g_game.pas @@ -7188,6 +7188,11 @@ begin if (s <> '') then gMapOnce := True; + // Override map to test: + s := LowerCase(Find_Param_Value(pars, '-testmap')); + if s <> '' then + gTestMap := MapsDir + s; + // Delete test map after play: s := Find_Param_Value(pars, '--testdelete'); if (s <> '') then @@ -7199,9 +7204,9 @@ begin // Delete temporary WAD after play: s := Find_Param_Value(pars, '--tempdelete'); - if (s <> '') then + if (s <> '') and (gTestMap <> '') then begin - gMapToDelete := MapsDir + map; + gMapToDelete := gTestMap; gTempDelete := True; end; diff --git a/src/game/g_map.pas b/src/game/g_map.pas index 2278353..f692113 100644 --- a/src/game/g_map.pas +++ b/src/game/g_map.pas @@ -236,6 +236,7 @@ var gCurrentMap: TDynRecord = nil; gCurrentMapFileName: AnsiString = ''; // so we can skip texture reloading + gTestMap: String = ''; function panelTypeToTag (panelType: Word): Integer; // returns GridTagXXX @@ -1613,7 +1614,7 @@ type actPanel: TDynRecord; end; var - WAD: TWADFile; + WAD, TestWAD: TWADFile; //mapReader: TDynRecord = nil; mapTextureList: TDynField = nil; //TTexturesRec1Array; tagInt: texture index panels: TDynField = nil; //TPanelsRec1Array; @@ -1642,6 +1643,8 @@ var begin mapGrid.Free(); mapGrid := nil; + TestWAD := nil; + Data := nil; //gCurrentMap.Free(); //gCurrentMap := nil; @@ -1670,13 +1673,41 @@ begin Exit; end; - //k8: why loader ignores path here? - mapResName := g_ExtractFileName(Res); - if not WAD.GetMapResource(mapResName, Data, Len) then + if gTestMap <> '' then begin - g_FatalError(Format(_lc[I_GAME_ERROR_MAP_RES], [mapResName])); - WAD.Free(); - Exit; + s := g_ExtractWadName(gTestMap); + TestWAD := TWADFile.Create(); + if not TestWAD.ReadFile(s) then + begin + g_SimpleError(Format(_lc[I_GAME_ERROR_MAP_WAD], [s])); + TestWAD.Free(); + TestWAD := nil; + end; + end; + + if TestWAD <> nil then + begin + mapResName := g_ExtractFileName(gTestMap); + if not TestWAD.GetMapResource(mapResName, Data, Len) then + begin + g_SimpleError(Format(_lc[I_GAME_ERROR_MAP_RES], [mapResName])); + Data := nil; + end else + e_WriteLog('Using test map: '+gTestMap, TMsgType.Notify); + TestWAD.Free(); + TestWAD := nil; + end; + + if Data = nil then + begin + //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; end; WAD.Free();