From: Ketmar Dark Date: Thu, 7 Sep 2017 01:57:22 +0000 (+0300) Subject: center player when the game is scaled (lighting is not working correctly yet, tho) X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=fd12a344c25480e0db011c3084804df3f98d005c;p=d2df-sdl.git center player when the game is scaled (lighting is not working correctly yet, tho) --- diff --git a/src/game/g_console.pas b/src/game/g_console.pas index b62a7e1..3bceba1 100644 --- a/src/game/g_console.pas +++ b/src/game/g_console.pas @@ -40,8 +40,8 @@ function conGetBoolArg (p: SArray; idx: Integer): Integer; procedure g_Console_Chat_Switch (team: Boolean=false); -procedure conRegVar (const conname: AnsiString; pvar: PBoolean; const ahelp: AnsiString; const amsg: AnsiString; acheat: Boolean=false); overload; -procedure conRegVar (const conname: AnsiString; pvar: PSingle; amin, amax: Single; const ahelp: AnsiString; const amsg: AnsiString; acheat: Boolean=false); overload; +procedure conRegVar (const conname: AnsiString; pvar: PBoolean; const ahelp: AnsiString; const amsg: AnsiString; acheat: Boolean=false; ahidden: Boolean=false); overload; +procedure conRegVar (const conname: AnsiString; pvar: PSingle; amin, amax: Single; const ahelp: AnsiString; const amsg: AnsiString; acheat: Boolean=false; ahidden: Boolean=false); overload; // poor man's floating literal parser; i'm sorry, but `StrToFloat()` sux cocks function conParseFloat (var res: Single; const s: AnsiString): Boolean; @@ -183,7 +183,8 @@ procedure boolVarHandler (me: PCommand; p: SArray); 1: if not me.cheat or conIsCheatsEnabled then flag := true else begin conwriteln('not available'); exit; end; 666: if not me.cheat or conIsCheatsEnabled then flag := not flag else begin conwriteln('not available'); exit; end; end; - if flag then conwritefln('%s: tan', [msg]) else conwritefln('%s: ona', [msg]); + if (Length(msg) = 0) then msg := p[0] else msg += ':'; + if flag then conwritefln('%s tan', [msg]) else conwritefln('%s ona', [msg]); end; end; begin @@ -191,7 +192,7 @@ begin end; -procedure conRegVar (const conname: AnsiString; pvar: PBoolean; const ahelp: AnsiString; const amsg: AnsiString; acheat: Boolean=false); overload; +procedure conRegVar (const conname: AnsiString; pvar: PBoolean; const ahelp: AnsiString; const amsg: AnsiString; acheat: Boolean=false; ahidden: Boolean=false); overload; var f: Integer; cp: PCommand; @@ -203,7 +204,7 @@ begin cp.proc := nil; cp.procEx := boolVarHandler; cp.help := ahelp; - cp.hidden := false; + cp.hidden := ahidden; cp.ptr := pvar; cp.msg := amsg; cp.cheat := acheat; @@ -227,7 +228,7 @@ var begin if (Length(p) > 2) then begin - conwritefln('too many arguments to ''%s''', [p[0]]); + conwritefln('too many arguments to ''%s''', [me.cmd]); exit; end; pv := PVarSingle(me.ptr); @@ -244,7 +245,7 @@ begin begin if not conParseFloat(nv, p[1]) then begin - conwritefln('%s: ''%s'' doesn''t look like a floating number', [p[0], p[1]]); + conwritefln('%s: ''%s'' doesn''t look like a floating number', [me.cmd, p[1]]); exit; end; if (nv < pv.min) then nv := pv.min; @@ -253,12 +254,12 @@ begin end; end; msg := me.msg; - if (Length(msg) = 0) then msg := p[0] else msg += ':'; + if (Length(msg) = 0) then msg := me.cmd else msg += ':'; conwritefln('%s %s', [msg, pv.val^]); end; -procedure conRegVar (const conname: AnsiString; pvar: PSingle; amin, amax: Single; const ahelp: AnsiString; const amsg: AnsiString; acheat: Boolean=false); overload; +procedure conRegVar (const conname: AnsiString; pvar: PSingle; amin, amax: Single; const ahelp: AnsiString; const amsg: AnsiString; acheat: Boolean=false; ahidden: Boolean=false); overload; var f: Integer; cp: PCommand; @@ -276,7 +277,7 @@ begin cp.proc := nil; cp.procEx := singleVarHandler; cp.help := ahelp; - cp.hidden := false; + cp.hidden := ahidden; cp.ptr := pv; cp.msg := amsg; cp.cheat := acheat; @@ -953,16 +954,15 @@ begin g_Console_Add(''); for i := 0 to High(commands) do begin - if not commands[i].hidden then + // hidden commands are hidden when cheats aren't enabled + if commands[i].hidden and not conIsCheatsEnabled then continue; + if (Length(commands[i].help) > 0) then begin - if (Length(commands[i].help) > 0) then - begin - g_Console_Add(' '+commands[i].cmd+' -- '+commands[i].help); - end - else - begin - g_Console_Add(' '+commands[i].cmd); - end; + g_Console_Add(' '+commands[i].cmd+' -- '+commands[i].help); + end + else + begin + g_Console_Add(' '+commands[i].cmd); end; end; exit; @@ -976,7 +976,8 @@ begin ll := Copy(ll, 0, Length(ll)-1); for i := 0 to High(commands) do begin - if commands[i].hidden then continue; + // hidden commands are hidden when cheats aren't enabled + if commands[i].hidden and not conIsCheatsEnabled then continue; if (commands[i].cmd = ll) then begin if (Length(commands[i].help) > 0) then @@ -992,7 +993,8 @@ begin tused := 0; for i := 0 to High(commands) do begin - if commands[i].hidden then continue; + // hidden commands are hidden when cheats aren't enabled + if commands[i].hidden and not conIsCheatsEnabled then continue; cmd := commands[i].cmd; if (Length(cmd) >= Length(ll)) and (ll = Copy(cmd, 0, Length(ll))) then begin diff --git a/src/game/g_game.pas b/src/game/g_game.pas index 5f56a74..467c13f 100644 --- a/src/game/g_game.pas +++ b/src/game/g_game.pas @@ -2780,9 +2780,29 @@ begin end; +function fixViewportForScale (): Boolean; +var + nx0, ny0, nw, nh: Integer; +begin + result := false; + if (g_dbg_scale <> 1.0) then + begin + result := true; + nx0 := round(sX-(gPlayerScreenSize.X-(sWidth*g_dbg_scale))/2/g_dbg_scale); + ny0 := round(sY-(gPlayerScreenSize.Y-(sHeight*g_dbg_scale))/2/g_dbg_scale); + nw := round(sWidth/g_dbg_scale); + nh := round(sHeight/g_dbg_scale); + sX := nx0; + sY := ny0; + sWidth := nw; + sHeight := nh; + end; +end; + + // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this! // WARNING! this WILL CALL `glTranslatef()`, but won't restore matrices! -procedure renderMapInternal (backXOfs, backYOfs: Integer; transX, transY: Integer; setTransMatrix: Boolean); +procedure renderMapInternal (backXOfs, backYOfs: Integer; setTransMatrix: Boolean); type TDrawCB = procedure (); @@ -2825,14 +2845,7 @@ begin profileFrameDraw.sectionBegin('collect'); if gdbg_map_use_accel_render then begin - if (g_dbg_scale <> 1.0) then - begin - g_Map_CollectDrawPanels(sX, sY, round(sWidth/g_dbg_scale)+1, round(sHeight/g_dbg_scale)+1); - end - else - begin - g_Map_CollectDrawPanels(sX, sY, sWidth, sHeight); - end; + g_Map_CollectDrawPanels(sX, sY, sWidth, sHeight); end; profileFrameDraw.sectionEnd(); @@ -2843,7 +2856,7 @@ begin if setTransMatrix then begin glScalef(g_dbg_scale, g_dbg_scale, 1.0); - glTranslatef(transX, transY, 0); + glTranslatef(-sX, -sY, 0); end; drawPanelType('*back', PANEL_BACK, g_rlayer_back); @@ -2889,7 +2902,8 @@ begin sWidth := w; sHeight := h; - renderMapInternal(-bx, -by, -x, -y, true); + fixViewportForScale(); + renderMapInternal(-bx, -by, true); glPopMatrix(); end; @@ -2918,24 +2932,33 @@ begin px := p.GameX + PLAYER_RECT_CX; py := p.GameY + PLAYER_RECT_CY+p.Obj.slopeUpLeft; - if px > (gPlayerScreenSize.X div 2) then a := -px+(gPlayerScreenSize.X div 2) else a := 0; - if py > (gPlayerScreenSize.Y div 2) then b := -py+(gPlayerScreenSize.Y div 2) else b := 0; + if (g_dbg_scale = 1.0) then + begin + if (px > (gPlayerScreenSize.X div 2)) then a := -px+(gPlayerScreenSize.X div 2) else a := 0; + if (py > (gPlayerScreenSize.Y div 2)) then b := -py+(gPlayerScreenSize.Y div 2) else b := 0; - if px > gMapInfo.Width-(gPlayerScreenSize.X div 2) then a := -gMapInfo.Width+gPlayerScreenSize.X; - if py > gMapInfo.Height-(gPlayerScreenSize.Y div 2) then b := -gMapInfo.Height+gPlayerScreenSize.Y; + if (px > gMapInfo.Width-(gPlayerScreenSize.X div 2)) then a := -gMapInfo.Width+gPlayerScreenSize.X; + if (py > gMapInfo.Height-(gPlayerScreenSize.Y div 2)) then b := -gMapInfo.Height+gPlayerScreenSize.Y; - if (gMapInfo.Width = gPlayerScreenSize.X) then a := 0 - else if (gMapInfo.Width < gPlayerScreenSize.X) then - begin - // hcenter - a := (gPlayerScreenSize.X-gMapInfo.Width) div 2; - end; + if (gMapInfo.Width = gPlayerScreenSize.X) then a := 0 + else if (gMapInfo.Width < gPlayerScreenSize.X) then + begin + // hcenter + a := (gPlayerScreenSize.X-gMapInfo.Width) div 2; + end; - if (gMapInfo.Height = gPlayerScreenSize.Y) then b := 0 - else if (gMapInfo.Height < gPlayerScreenSize.Y) then + if (gMapInfo.Height = gPlayerScreenSize.Y) then b := 0 + else if (gMapInfo.Height < gPlayerScreenSize.Y) then + begin + // vcenter + b := (gPlayerScreenSize.Y-gMapInfo.Height) div 2; + end; + end + else begin - // vcenter - b := (gPlayerScreenSize.Y-gMapInfo.Height) div 2; + // scaled, ignore level bounds + a := -px+(gPlayerScreenSize.X div 2); + b := -py+(gPlayerScreenSize.Y div 2); end; if p.IncCam <> 0 then @@ -2982,17 +3005,17 @@ begin //glTranslatef(a, b+p.IncCam, 0); + if (p = gPlayer1) then g_Holmes_plrViewSize(sWidth, sHeight); + + fixViewportForScale(); p.viewPortX := sX; p.viewPortY := sY; p.viewPortW := sWidth; p.viewPortH := sHeight; - if (p = gPlayer1) then - begin - g_Holmes_plrView(p.viewPortX, p.viewPortY, p.viewPortW, p.viewPortH); - end; + if (p = gPlayer1) then g_Holmes_plrViewPos(sX, sY); - renderMapInternal(-c, -d, a, b+p.IncCam, true); + renderMapInternal(-c, -d, true); if p.FSpectator then e_TextureFontPrintEx(p.GameX + PLAYER_RECT_CX - 4, diff --git a/src/game/g_gfx.pas b/src/game/g_gfx.pas index ff7089b..52c3b24 100644 --- a/src/game/g_gfx.pas +++ b/src/game/g_gfx.pas @@ -1617,7 +1617,6 @@ end; procedure g_GFX_Draw (); var a, len: Integer; - scaled: Boolean; begin if not gpart_dbg_enabled then exit; @@ -1631,15 +1630,13 @@ begin glBegin(GL_POINTS); - scaled := (g_dbg_scale <> 1.0); - len := High(Particles); for a := 0 to len do begin with Particles[a] do begin if not alive then continue; - if scaled or ((x >= sX) and (y >= sY) and (x <= sX+sWidth) and (sY <= sY+sHeight)) then + if (x >= sX) and (y >= sY) and (x <= sX+sWidth) and (sY <= sY+sHeight) then begin glColor4ub(red, green, blue, alpha); glVertex2f(x+0.37, y+0.37); diff --git a/src/game/g_holmes.pas b/src/game/g_holmes.pas index 82f2be1..9d21545 100644 --- a/src/game/g_holmes.pas +++ b/src/game/g_holmes.pas @@ -83,7 +83,8 @@ function g_Holmes_MouseEvent (var ev: THMouseEvent): Boolean; // returns `true` function g_Holmes_KeyEvent (var ev: THKeyEvent): Boolean; // returns `true` if event was eaten // hooks for player -procedure g_Holmes_plrView (viewPortX, viewPortY, viewPortW, viewPortH: Integer); +procedure g_Holmes_plrViewPos (viewPortX, viewPortY: Integer); +procedure g_Holmes_plrViewSize (viewPortW, viewPortH: Integer); procedure g_Holmes_plrLaser (ax0, ay0, ax1, ay1: Integer); @@ -656,11 +657,16 @@ var platMarkedGUID: Integer = -1; -procedure g_Holmes_plrView (viewPortX, viewPortY, viewPortW, viewPortH: Integer); +procedure g_Holmes_plrViewPos (viewPortX, viewPortY: Integer); begin vpSet := true; vpx := viewPortX; vpy := viewPortY; +end; + +procedure g_Holmes_plrViewSize (viewPortW, viewPortH: Integer); +begin + vpSet := true; vpw := viewPortW; vph := viewPortH; end; diff --git a/src/game/g_items.pas b/src/game/g_items.pas index c756541..6365d7b 100644 --- a/src/game/g_items.pas +++ b/src/game/g_items.pas @@ -630,7 +630,7 @@ begin with ggItems[i] do begin - if (g_dbg_scale <> 1.0) or g_Collide(Obj.X, Obj.Y, Obj.Rect.Width, Obj.Rect.Height, sX, sY, sWidth, sHeight) then + if g_Collide(Obj.X, Obj.Y, Obj.Rect.Width, Obj.Rect.Height, sX, sY, sWidth, sHeight) then begin if (Animation = nil) then begin diff --git a/src/game/g_monsters.pas b/src/game/g_monsters.pas index d982204..7161951 100644 --- a/src/game/g_monsters.pas +++ b/src/game/g_monsters.pas @@ -2154,6 +2154,7 @@ begin o.Y+o.Rect.Y+o.Rect.Height-128, M_NONE); // Íå â îáëàñòè ðèñîâàíèÿ íå ðåñóåì: +//FIXME! if (g_dbg_scale = 1.0) then begin if not g_Collide(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, FObj.Rect.Width, FObj.Rect.Height, diff --git a/src/game/g_panel.pas b/src/game/g_panel.pas index b43a668..5e29885 100644 --- a/src/game/g_panel.pas +++ b/src/game/g_panel.pas @@ -416,8 +416,8 @@ var NW, NH: Word; begin if {Enabled and} (FCurTexture >= 0) and - (Width > 0) and (Height > 0) and (FAlpha < 255) and - ((g_dbg_scale <> 1.0) or g_Collide(X, Y, Width, Height, sX, sY, sWidth, sHeight)) then + (Width > 0) and (Height > 0) and (FAlpha < 255) {and + g_Collide(X, Y, Width, Height, sX, sY, sWidth, sHeight)} then begin if FTextureIDs[FCurTexture].Anim then begin // Àíèìèðîâàííàÿ òåêñòóðà @@ -493,8 +493,8 @@ procedure TPanel.DrawShadowVolume(lightX: Integer; lightY: Integer; radius: Inte begin if radius < 4 then exit; - if Enabled and (FCurTexture >= 0) and (Width > 0) and (Height > 0) and (FAlpha < 255) and - ((g_dbg_scale <> 1.0) or g_Collide(X, Y, Width, Height, sX, sY, sWidth, sHeight)) then + if Enabled and (FCurTexture >= 0) and (Width > 0) and (Height > 0) and (FAlpha < 255) {and + g_Collide(X, Y, Width, Height, sX, sY, sWidth, sHeight)} then begin if not FTextureIDs[FCurTexture].Anim then begin diff --git a/src/game/g_player.pas b/src/game/g_player.pas index 300979a..98535cc 100644 --- a/src/game/g_player.pas +++ b/src/game/g_player.pas @@ -3980,7 +3980,7 @@ begin if not (R_BERSERK in FRulez) then begin Include(FRulez, R_BERSERK); - if gBerserkAutoswitch and (FBFGFireCounter = -1) then + if gBerserkAutoswitch and (gDebugMode or gCheats) and (FBFGFireCounter = -1) then begin FCurrWeap := WEAPON_KASTET; resetWeaponQueue(); @@ -7614,4 +7614,7 @@ begin FDifficult := TDifficult(p^); end; + +begin + conRegVar('cheat_berserk_autoswitch', @gBerserkAutoswitch, 'autoswitch to fist when berserk pack taken', '', true, true); end.