From: DeaDDooMER Date: Tue, 21 Feb 2023 19:26:02 +0000 (+0300) Subject: game: fix spectator camera X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=b8cc5f22e26818c1db1df53234fdaa36ab723325;p=d2df-sdl.git game: fix spectator camera --- diff --git a/src/game/g_game.pas b/src/game/g_game.pas index 3105360..d7b9b2d 100644 --- a/src/game/g_game.pas +++ b/src/game/g_game.pas @@ -1820,6 +1820,8 @@ procedure g_Game_Update(); var reliableUpdate: Boolean; + rSpectX0, rSpectY0: Integer; + rSpectX1, rSpectY1: Integer; begin g_ResetDynlights(); framePool.reset(); @@ -2096,7 +2098,15 @@ begin // process weapon switch queue end; // if server - // Наблюдатель + // Spectator + + {$IFDEF ENABLE_RENDER} + r_Render_GetSpectatorLimits(rSpectX0, rSpectY0, rSpectX1, rSpectY1); + {$ELSE} + rSpectX0 := 0; rSpectY0 := 0; + rSpectX1 := gMapInfo.Width - 1; rSpectY1 := gMapInfo.Height - 1; + {$ENDIF} + if (gPlayer1 = nil) and (gPlayer2 = nil) and (not gConsoleShow) and (not gChatShow) {$IFDEF ENABLE_MENU} @@ -2120,14 +2130,10 @@ begin if (gSpectMode = SPECT_MAPVIEW) and (not gSpectAuto) then begin - if gPlayerAction[0, ACTION_MOVELEFT] then - gSpectX := Max(gSpectX - gSpectStep, 0); - if gPlayerAction[0, ACTION_MOVERIGHT] then - gSpectX := Min(gSpectX + gSpectStep, gMapInfo.Width - gScreenWidth); - if gPlayerAction[0, ACTION_LOOKUP] then - gSpectY := Max(gSpectY - gSpectStep, 0); - if gPlayerAction[0, ACTION_LOOKDOWN] then - gSpectY := Min(gSpectY + gSpectStep, gMapInfo.Height - gScreenHeight); + if gPlayerAction[0, ACTION_MOVELEFT] then gSpectX := gSpectX - gSpectStep; + if gPlayerAction[0, ACTION_MOVERIGHT] then gSpectX := gSpectX + gSpectStep; + if gPlayerAction[0, ACTION_LOOKUP] then gSpectY := gSpectY - gSpectStep; + if gPlayerAction[0, ACTION_LOOKDOWN] then gSpectY := gSpectY + gSpectStep; if gWeaponAction[0, WP_PREV] then begin // decrease step @@ -2212,12 +2218,12 @@ begin begin if gSpectMode = SPECT_MAPVIEW then begin - i := Min(Max(gSpectX + gSpectAutoStepX, 0), gMapInfo.Width - gScreenWidth); + i := Min(Max(gSpectX + gSpectAutoStepX, rSpectX0), rSpectX1); if i = gSpectX then gSpectAutoNext := gTime else gSpectX := i; - i := Min(Max(gSpectY + gSpectAutoStepY, 0), gMapInfo.Height - gScreenHeight); + i := Min(Max(gSpectY + gSpectAutoStepY, rSpectY0), rSpectY1); if i = gSpectY then gSpectAutoNext := gTime else @@ -2231,15 +2237,15 @@ begin case gSpectMode of SPECT_MAPVIEW: begin - gSpectX := Random(gMapInfo.Width - gScreenWidth); - gSpectY := Random(gMapInfo.Height - gScreenHeight); + gSpectX := rSpectX0 + Random(rSpectX1 - rSpectX0); + gSpectY := rSpectY0 + Random(rSpectY1 - rSpectY0); gSpectAutoStepX := Random(9) - 4; gSpectAutoStepY := Random(9) - 4; - if ((gSpectX < 800) and (gSpectAutoStepX < 0)) or - ((gSpectX > gMapInfo.Width - gScreenWidth - 800) and (gSpectAutoStepX > 0)) then + if ((gSpectX < rSpectX0) and (gSpectAutoStepX < 0)) or + ((gSpectX > rSpectX1) and (gSpectAutoStepX > 0)) then gSpectAutoStepX := gSpectAutoStepX * -1; - if ((gSpectY < 800) and (gSpectAutoStepY < 0)) or - ((gSpectY > gMapInfo.Height - gScreenHeight - 800) and (gSpectAutoStepY > 0)) then + if ((gSpectY < rSpectY0) and (gSpectAutoStepY < 0)) or + ((gSpectY > rSpectY1) and (gSpectAutoStepY > 0)) then gSpectAutoStepY := gSpectAutoStepY * -1; end; SPECT_PLAYERS: @@ -2255,6 +2261,14 @@ begin end; end; end; + + if gSpectMode = SPECT_MAPVIEW then + begin + gSpectX := Max(gSpectX, rSpectX0); + gSpectX := Min(gSpectX, rSpectX1); + gSpectY := Max(gSpectY, rSpectY0); + gSpectY := Min(gSpectY, rSpectY1); + end; end; (* spectator state check from render *) diff --git a/src/game/renders/opengl/r_map.pas b/src/game/renders/opengl/r_map.pas index f27043e..ecc2192 100644 --- a/src/game/renders/opengl/r_map.pas +++ b/src/game/renders/opengl/r_map.pas @@ -42,6 +42,7 @@ interface procedure r_Map_Update; procedure r_Map_Draw (x, y, w, h, camx, camy: Integer; player: TPlayer; out acx, acy: Integer); + procedure r_Map_GetSpectatorLimits (out x0, y0, x1, y1: Integer); implementation @@ -1711,6 +1712,34 @@ implementation g_Anim_GetFrameByTime(FlagAnim, tick, count, FlagFrame); end; + procedure r_Map_GetSpectatorLimits (out x0, y0, x1, y1: Integer); + var w, h: Integer; + begin + w := Round(gScreenWidth / g_dbg_scale); + if gMapInfo.Width > w then + begin + x0 := w div 2; + x1 := gMapInfo.Width - w div 2 - 1; + end + else + begin + x0 := gMapInfo.Width div 2; + x1 := gMapInfo.Width div 2; + end; + + h := Round(gScreenHeight / g_dbg_scale); + if gMapInfo.Height > h then + begin + y0 := h div 2; + y1 := gMapInfo.Height - h div 2 - 1; + end + else + begin + y0 := gMapInfo.Height div 2; + y1 := gMapInfo.Height div 2; + end; + end; + initialization conRegVar('r_sq_draw', @UseAccel, 'accelerated spatial queries in rendering', 'accelerated rendering'); conRegVar('r_debug_camera_scale', @DebugCameraScale, 0.0001, 1000.0, '', ''); diff --git a/src/game/renders/opengl/r_render.pas b/src/game/renders/opengl/r_render.pas index 76adb8e..a16a37d 100644 --- a/src/game/renders/opengl/r_render.pas +++ b/src/game/renders/opengl/r_render.pas @@ -80,6 +80,8 @@ interface function r_Render_HolmesViewIsSet (): Boolean; {$ENDIF} + procedure r_Render_GetSpectatorLimits (out x0, y0, x1, y1: Integer); + implementation uses @@ -1204,7 +1206,7 @@ implementation begin if gSpectMode = SPECT_MAPVIEW then begin - r_Render_DrawMapView(0, 0, gScreenWidth, gScreenHeight, gSpectX + gScreenWidth div 2, gSpectY + gScreenHeight div 2); + r_Render_DrawMapView(0, 0, gScreenWidth, gScreenHeight, gSpectX, gSpectY); end else if (p1 <> nil) and (p2 <> nil) then begin @@ -1484,6 +1486,11 @@ implementation end; {$ENDIF} + procedure r_Render_GetSpectatorLimits (out x0, y0, x1, y1: Integer); + begin + r_Map_GetSpectatorLimits(x0, y0, x1, y1); + end; + begin conRegVar('d_sounds', @DebugSound, '', ''); DebugSound := false;