X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;ds=sidebyside;f=src%2Fgame%2Fg_game.pas;h=380126ee18a6a1d6ea60a876883518ce6dd53106;hb=a40ccefc0daf17edf117f5ff143842b398e2c6e5;hp=bb914b69a94f862ae651197d616bdd88733fbebd;hpb=b8b3691f5a4d6537539f557588cfd6fab79ed4b6;p=d2df-sdl.git diff --git a/src/game/g_game.pas b/src/game/g_game.pas index bb914b6..380126e 100644 --- a/src/game/g_game.pas +++ b/src/game/g_game.pas @@ -132,7 +132,7 @@ procedure g_Game_Announce_KillCombo(Param: Integer); procedure g_Game_Announce_BodyKill(SpawnerUID: Word); procedure g_Game_StartVote(Command, Initiator: string); procedure g_Game_CheckVote; -{$IFNDEF HEADLESS} +{$IFDEF ENABLE_RENDER} procedure g_TakeScreenShot(Filename: string = ''); {$ENDIF} procedure g_FatalError(Text: String); @@ -146,9 +146,6 @@ procedure GameCommands(P: SSArray); procedure GameCheats(P: SSArray); procedure DebugCommands(P: SSArray); procedure g_Game_Process_Params; -procedure g_Game_SetLoadingText(Text: String; Max: Integer; reWrite: Boolean); -procedure g_Game_StepLoading(Value: Integer = -1); -procedure g_Game_ClearLoading(); procedure g_Game_SetDebugMode(); function IsActivePlayer(p: TPlayer): Boolean; @@ -159,9 +156,10 @@ procedure SortGameStat(var stat: TPlayerStatArray); {$IFDEF ENABLE_MENU} procedure g_Game_InGameMenu(Show: Boolean); {$ENDIF} -{$IFNDEF HEADLESS} +{$IFDEF ENABLE_SYSTEM} procedure CharPress (C: AnsiChar); {$ENDIF} + procedure KeyPress (K: Word); { procedure SetWinPause(Enable: Boolean); } @@ -169,9 +167,6 @@ procedure SortGameStat(var stat: TPlayerStatArray); const GAME_TICK = 28; - LOADING_SHOW_STEP = 100; - LOADING_INTERLINE = 20; - GT_NONE = 0; GT_SINGLE = 1; GT_CUSTOM = 2; @@ -254,15 +249,13 @@ var gPlayer2Settings: TPlayerSettings; gGameOn: Boolean; gPlayerScreenSize: TDFPoint; - gPlayer1ScreenCoord: TDFPoint; - gPlayer2ScreenCoord: TDFPoint; gPlayer1: TPlayer = nil; gPlayer2: TPlayer = nil; - gPlayerDrawn: TPlayer = nil; gTime: LongWord; gLerpFactor: Single = 1.0; gSwitchGameMode: Byte = GM_DM; gHearPoint1, gHearPoint2: THearPoint; + gMaxDist: Integer = 1; // for sound gSoundEffectsDF: Boolean = False; gSoundTriggerTime: Word = 0; gAnnouncer: Integer = ANNOUNCE_NONE; @@ -417,15 +410,6 @@ function gPause (): Boolean; inline; TotalSecrets: Integer; end; - TLoadingStat = record - CurValue: Integer; - MaxValue: Integer; - ShowCount: Integer; - Msgs: Array of String; - NextMsg: Word; - PBarWasHere: Boolean; // did we draw a progress bar for this message? - end; - TDynLight = record x, y, radius: Integer; r, g, b, a: Single; @@ -438,7 +422,6 @@ function gPause (): Boolean; inline; StatShotDone: Boolean; StatFilename: string = ''; // used by stat screenshot to save with the same name as the csv SingleStat: TEndSingleGameStat; - LoadingStat: TLoadingStat; MessageText: String; IsDrawStat: Boolean; EndingGameCounter: Byte; @@ -466,8 +449,14 @@ uses {$IFDEF ENABLE_SHELLS} g_shells, {$ENDIF} - {$IFNDEF HEADLESS} - r_render, g_system, + {$IFDEF ENABLE_CORPSES} + g_corpses, + {$ENDIF} + {$IFDEF ENABLE_RENDER} + r_render, + {$ENDIF} + {$IFDEF ENABLE_SYSTEM} + g_system, {$ENDIF} e_res, g_window, e_input, e_log, g_console, g_items, g_map, g_panel, @@ -805,7 +794,7 @@ end; end; {$ENDIF} -{$IFNDEF HEADLESS} +{$IFDEF ENABLE_SYSTEM} procedure CharPress (C: AnsiChar); {$IFDEF ENABLE_MENU} var Msg: g_gui.TMessage; @@ -1449,12 +1438,6 @@ begin sfsGCDisable(); // temporary disable removing of temporary volumes try - 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_MODELS], 0, False); - gGameOn := false; gPauseMain := false; gPauseHolmes := false; @@ -1462,7 +1445,6 @@ begin {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); @@ -1498,7 +1480,16 @@ begin g_Map_Free(freeTextures); g_Player_Free(); - g_Player_RemoveAllCorpses(); + + {$IFDEF ENABLE_GIBS} + g_Gibs_RemoveAll; + {$ENDIF} + {$IFDEF ENALBE_SHELLS} + g_Shells_RemoveAll; + {$ENDIF} + {$IFDEF ENABLE_CORPSES} + g_Corpses_RemoveAll; + {$ENDIF} gGameSettings.GameType := GT_NONE; if gGameSettings.GameMode = GM_SINGLE then @@ -1737,6 +1728,60 @@ begin g_Weapon_PreUpdate(); end; + procedure g_Game_SetupHearPoints; + var p1, p2: TPlayer; a, b: Integer; + begin + p1 := nil; + p2 := nil; + gHearPoint1.Active := false; + gHearPoint2.Active := false; + if gSpectMode = SPECT_MAPVIEW then + begin + // TODO something better (render dependency) + gHearPoint1.Active := true; + gHearPoint1.Coords.X := gSpectX + gScreenWidth div 2; + gHearPoint1.Coords.Y := gSpectY + gScreenHeight div 2; + end + else if gSpectMode = SPECT_PLAYERS then + begin + p1 := g_Player_Get(gSpectPID1); + if gSpectViewTwo then + p2 := g_Player_Get(gSpectPID2); + end + else if gSpectMode = SPECT_NONE then + begin + p1 := gPlayer1; + p2 := gPlayer2; + end; + if p1 <> nil then + begin + gHearPoint1.Active := true; + gHearPoint1.Coords.X := p1.obj.x + p1.obj.rect.width div 2; + gHearPoint1.Coords.Y := p1.obj.y + p1.obj.rect.height div 2; + end; + if (p2 <> nil) and (p1 <> p2) then + begin + gHearPoint2.Active := true; + gHearPoint2.Coords.X := p2.obj.x + p2.obj.rect.width div 2; + gHearPoint2.Coords.Y := p2.obj.y + p2.obj.rect.height div 2; + end; + // TODO something better (render dependency) + if (p1 <> nil) and (p2 <> nil) then + begin + gPlayerScreenSize.X := gScreenWidth - 196; + gPlayerScreenSize.Y := gScreenHeight div 2; + end + else + begin + gPlayerScreenSize.X := gScreenWidth - 196; + gPlayerScreenSize.Y := gScreenHeight; + end; + // sound distance + if gMapInfo.Height > gPlayerScreenSize.Y then a := gMapInfo.Height - gPlayerScreenSize.Y else a := gMapInfo.Height; + if gMapInfo.Width > gPlayerScreenSize.X then b := gMapInfo.Width - gPlayerScreenSize.X else b := gMapInfo.Width; + gMaxDist := Trunc(Hypot(a, b)); + end; + procedure g_Game_Update(); var {$IFDEF ENABLE_MENU} @@ -1956,7 +2001,22 @@ begin // Статистика по Tab: if gGameOn then + begin IsDrawStat := (not gConsoleShow) and (not gChatShow) and (gGameSettings.GameType <> GT_SINGLE) and g_Console_Action(ACTION_SCORES); + end + else + begin + if g_Console_Action(ACTION_SCORES) then + begin + if not gStatsPressed then + begin + gStatsOff := not gStatsOff; + gStatsPressed := True; + end; + end + else + gStatsPressed := False; + end; // Игра идет: if gGameOn and not gPause and (gState <> STATE_FOLD) then @@ -2206,6 +2266,19 @@ begin end; end; + (* spectator state check from render *) + + if (gPlayer1 = nil) and (gPlayer2 = nil) and (gSpectMode = SPECT_NONE) then + gSpectMode := SPECT_STATS; + + if IsActivePlayer(g_Player_Get(gSpectPID1)) = false then + gSpectPID1 := GetActivePlayerID_Next(); + + if IsActivePlayer(g_Player_Get(gSpectPID2)) = false then + gSpectPID2 := GetActivePlayerID_Next(); + + g_Game_SetupHearPoints; + // Обновляем все остальное: g_Map_Update(); g_Items_Update(); @@ -2219,7 +2292,9 @@ begin {$IFDEF ENABLE_GIBS} g_Gibs_Update; {$ENDIF} - g_Player_UpdatePhysicalObjects(); + {$IFDEF ENABLE_CORPSES} + g_Corpses_Update; + {$ENDIF} {$IFDEF ENABLE_SHELLS} g_Shells_Update; {$ENDIF} @@ -2332,7 +2407,7 @@ begin // Нужно сменить разрешение: if gResolutionChange then begin - {$IFNDEF HEADLESS} + {$IFDEF ENABLE_RENDER} e_WriteLog('Changing resolution', TMsgType.Notify); r_Render_Apply; {$ENDIF} @@ -2470,6 +2545,7 @@ begin if DataLoaded then Exit; e_WriteLog('Loading game data...', TMsgType.Notify); + g_Game_SetLoadingText(_lc[I_LOAD_GAME_DATA], 0, False); g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD+':SOUNDS\TELEPORT'); g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD+':SOUNDS\NOTELEPORT'); @@ -2552,10 +2628,8 @@ begin g_Game_LoadChatSounds(GameWAD+':CHATSND\SNDCFG'); - g_Game_SetLoadingText(_lc[I_LOAD_ITEMS_DATA], 0, False); g_Items_LoadData(); - g_Game_SetLoadingText(_lc[I_LOAD_WEAPONS_DATA], 0, False); g_Weapon_LoadData(); g_Monsters_LoadData(); @@ -2569,9 +2643,9 @@ begin gMusic.Free(); g_Game_FreeData(); g_PlayerModel_FreeData(); -{$IFNDEF HEADLESS} - //g_Menu_Free(); //k8: this segfaults after resolution change; who cares? -{$ENDIF} + {$IFDEF ENABLE_MENU} + // g_Menu_Free(); //k8: this segfaults after resolution change; who cares? + {$ENDIF} if NetInitDone then g_Net_Free; @@ -2581,7 +2655,7 @@ begin gExit := EXIT_QUIT; - {$IFNDEF HEADLESS} + {$IFDEF ENABLE_SYSTEM} sys_RequestQuit; {$ENDIF} end; @@ -3361,7 +3435,16 @@ var nws: AnsiString; begin g_Map_Free((Map <> gCurrentMapFileName) and (oldMapPath <> gCurrentMapFileName)); - g_Player_RemoveAllCorpses(); + + {$IFDEF ENABLE_GIBS} + g_Gibs_RemoveAll; + {$ENDIF} + {$IFDEF ENALBE_SHELLS} + g_Shells_RemoveAll; + {$ENDIF} + {$IFDEF ENABLE_CORPSES} + g_Corpses_RemoveAll; + {$ENDIF} if (not g_Game_IsClient) and (gSwitchGameMode <> gGameSettings.GameMode) and @@ -3430,7 +3513,7 @@ begin begin //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName); result := g_Map_Load(NewWAD+':\'+ResName); - {$IFNDEF HEADLESS} + {$IFDEF ENABLE_RENDER} r_Render_LoadTextures; {$ENDIF} end; @@ -3691,7 +3774,16 @@ begin Exit; end; - g_Player_RemoveAllCorpses; + {$IFDEF ENABLE_GIBS} + g_Gibs_RemoveAll; + {$ENDIF} + {$IFDEF ENALBE_SHELLS} + g_Shells_RemoveAll; + {$ENDIF} + {$IFDEF ENABLE_CORPSES} + g_Corpses_RemoveAll; + {$ENDIF} + g_Game_Message(_lc[I_MESSAGE_LMS_START], 144); if g_Game_IsNet then MH_SEND_GameEvent(NET_EV_LMS_START); @@ -4116,12 +4208,18 @@ begin begin if Length(p) = 2 then begin - a := Max(0, StrToIntDef(p[1], 0)); - g_Corpses_SetMax(a) + {$IFDEF ENABLE_CORPSES} + a := Max(0, StrToIntDef(p[1], 0)); + g_Corpses_SetMax(a) + {$ENDIF} end else if Length(p) = 1 then begin - e_LogWritefln('%s', [g_Corpses_GetMax()]) + {$IFDEF ENABLE_CORPSES} + e_LogWritefln('%s', [g_Corpses_GetMax()]) + {$ELSE} + e_LogWritefln('%s', [0]) + {$ENDIF} end else begin @@ -5881,8 +5979,8 @@ begin end else if cmd = 'screenshot' then begin - {$IFNDEF HEADLESS} - g_TakeScreenShot() + {$IFDEF ENABLE_RENDER} + g_TakeScreenShot; {$ENDIF} end else if (cmd = 'weapnext') or (cmd = 'weapprev') then @@ -6167,7 +6265,7 @@ begin g_Game_Free(); g_Game_Quit(); end; -{$IFNDEF HEADLESS} +{$IFDEF ENABLE_RENDER} 'r_reset': r_Render_Apply; {$ENDIF} @@ -6216,7 +6314,7 @@ begin end; end; -{$IFNDEF HEADLESS} +{$IFDEF ENABLE_RENDER} procedure g_TakeScreenShot(Filename: string = ''); var t: TDateTime; dir, date, name: String; begin @@ -6690,81 +6788,6 @@ begin gCheats := True; end; -procedure g_Game_SetLoadingText(Text: String; Max: Integer; reWrite: Boolean); -var - i: Word; -begin - if Length(LoadingStat.Msgs) = 0 then - Exit; - - with LoadingStat do - begin - if not reWrite then - begin // Переходим на следующую строку или скроллируем: - if NextMsg = Length(Msgs) then - begin // scroll - for i := 0 to High(Msgs)-1 do - Msgs[i] := Msgs[i+1]; - end - else - Inc(NextMsg); - end else - if NextMsg = 0 then - Inc(NextMsg); - - Msgs[NextMsg-1] := Text; - CurValue := 0; - MaxValue := Max; - ShowCount := 0; - PBarWasHere := false; - end; - - {$IFDEF ENABLE_MENU} - g_ActiveWindow := nil; - {$ENDIF} - - ProcessLoading(true); -end; - -procedure g_Game_StepLoading(Value: Integer = -1); -begin - with LoadingStat do - begin - if Value = -1 then - begin - Inc(CurValue); - Inc(ShowCount); - end - else - CurValue := Value; - - if (ShowCount > LOADING_SHOW_STEP) or (Value > -1) then - begin - ShowCount := 0; - ProcessLoading(False); - end; - end; -end; - -procedure g_Game_ClearLoading(); -var - len: Word; -begin - with LoadingStat do - begin - CurValue := 0; - MaxValue := 0; - ShowCount := 0; - len := ((gScreenHeight div 3)*2 - 50) div LOADING_INTERLINE; - if len < 1 then len := 1; - SetLength(Msgs, len); - for len := Low(Msgs) to High(Msgs) do - Msgs[len] := ''; - NextMsg := 0; - PBarWasHere := false; - end; -end; - procedure Parse_Params(var pars: TParamStrValues); var i: Integer;