From 89b25c381542119e51cf5278f29a8bbd68cc4f9e Mon Sep 17 00:00:00 2001 From: Ketmar Dark Date: Sun, 3 Sep 2017 04:28:19 +0300 Subject: [PATCH] "hlm_ui_scale" convar; "--holmes_ui_scale" cli arg; (fgsfds request) --- src/game/g_console.pas | 89 +++++++++++++++++++++------------------- src/game/g_holmes.pas | 17 ++++++-- src/game/g_holmes_ui.inc | 8 +++- src/game/g_window.pas | 52 ++++++++++++++--------- 4 files changed, 99 insertions(+), 67 deletions(-) diff --git a/src/game/g_console.pas b/src/game/g_console.pas index e0f401d..6cd897c 100644 --- a/src/game/g_console.pas +++ b/src/game/g_console.pas @@ -43,6 +43,9 @@ 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; +// poor man's floating literal parser; i'm sorry, but `StrToFloat()` sux cocks +function conParseFloat (var res: Single; const s: AnsiString): Boolean; + var gConsoleShow: Boolean = false; // True - êîíñîëü îòêðûòà èëè îòêðûâàåòñÿ @@ -113,6 +116,45 @@ var end; +// poor man's floating literal parser; i'm sorry, but `StrToFloat()` sux cocks +function conParseFloat (var res: Single; const s: AnsiString): Boolean; +var + pos: Integer = 1; + frac: Single = 1; + slen: Integer; +begin + result := false; + res := 0; + slen := Length(s); + while (slen > 0) and (s[slen] <= ' ') do Dec(slen); + while (pos <= slen) and (s[pos] <= ' ') do Inc(pos); + if (pos > slen) then exit; + if (slen-pos = 1) and (s[pos] = '.') then exit; // single dot + // integral part + while (pos <= slen) do + begin + if (s[pos] < '0') or (s[pos] > '9') then break; + res := res*10+Byte(s[pos])-48; + Inc(pos); + end; + if (pos <= slen) then + begin + // must be a dot + if (s[pos] <> '.') then exit; + Inc(pos); + while (pos <= slen) do + begin + if (s[pos] < '0') or (s[pos] > '9') then break; + frac := frac/10; + res += frac*(Byte(s[pos])-48); + Inc(pos); + end; + end; + if (pos <= slen) then exit; // oops + result := true; +end; + + // ////////////////////////////////////////////////////////////////////////// // // <0: no arg; 0/1: true/false; 666: toggle function conGetBoolArg (p: SArray; idx: Integer): Integer; @@ -137,9 +179,9 @@ procedure boolVarHandler (me: PCommand; p: SArray); begin case conGetBoolArg(p, 1) of -1: begin end; - 0: if conIsCheatsEnabled then flag := false else begin conwriteln('not available'); exit; end; - 1: if conIsCheatsEnabled then flag := true else begin conwriteln('not available'); exit; end; - 666: if conIsCheatsEnabled then flag := not flag else begin conwriteln('not available'); exit; end; + 0: if not me.cheat or conIsCheatsEnabled then flag := false else begin conwriteln('not available'); exit; end; + 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]); end; @@ -178,43 +220,6 @@ type procedure singleVarHandler (me: PCommand; p: SArray); - // poor man's floating literal parser; i'm sorry, but `StrToFloat()` sux cocks - function parseFloat (var res: Single; const s: AnsiString): Boolean; - var - pos: Integer = 1; - frac: Single = 1; - slen: Integer; - begin - result := false; - res := 0; - slen := Length(s); - while (slen > 0) and (s[slen] <= ' ') do Dec(slen); - while (pos <= slen) and (s[pos] <= ' ') do Inc(pos); - if (pos > slen) then exit; - if (slen-pos = 1) and (s[pos] = '.') then exit; // single dot - // integral part - while (pos <= slen) do - begin - if (s[pos] < '0') or (s[pos] > '9') then break; - res := res*10+Byte(s[pos])-48; - Inc(pos); - end; - if (pos <= slen) then - begin - // must be a dot - if (s[pos] <> '.') then exit; - Inc(pos); - while (pos <= slen) do - begin - if (s[pos] < '0') or (s[pos] > '9') then break; - frac := frac/10; - res += frac*(Byte(s[pos])-48); - Inc(pos); - end; - end; - if (pos <= slen) then exit; // oops - result := true; - end; var pv: PVarSingle; nv: Single; @@ -228,7 +233,7 @@ begin pv := PVarSingle(me.ptr); if (Length(p) = 2) then begin - if not conIsCheatsEnabled then begin conwriteln('not available'); exit; end; + if me.cheat and (not conIsCheatsEnabled) then begin conwriteln('not available'); exit; end; if (CompareText(p[1], 'default') = 0) or (CompareText(p[1], 'def') = 0) or (CompareText(p[1], 'd') = 0) or (CompareText(p[1], 'off') = 0) or (CompareText(p[1], 'ona') = 0) then @@ -237,7 +242,7 @@ begin end else begin - if not parseFloat(nv, p[1]) then + if not conParseFloat(nv, p[1]) then begin conwritefln('%s: ''%s'' doesn''t look like a floating number', [p[0], p[1]]); exit; diff --git a/src/game/g_holmes.pas b/src/game/g_holmes.pas index 570a1d9..9f98ca3 100644 --- a/src/game/g_holmes.pas +++ b/src/game/g_holmes.pas @@ -96,6 +96,7 @@ operator = (const s: AnsiString; constref ev: THMouseEvent): Boolean; var g_holmes_enabled: Boolean = {$IF DEFINED(D2F_DEBUG)}true{$ELSE}false{$ENDIF}; + g_holmes_ui_scale: Single = 1.0; implementation @@ -1162,16 +1163,21 @@ end; // ////////////////////////////////////////////////////////////////////////// // function g_Holmes_MouseEvent (var ev: THMouseEvent): Boolean; +var + he: THMouseEvent; begin holmesInitCommands(); holmesInitBinds(); result := true; - msX := ev.x; - msY := ev.y; + msX := trunc(ev.x/g_holmes_ui_scale); + msY := trunc(ev.y/g_holmes_ui_scale); msB := ev.bstate; kbS := ev.kstate; msB := msB; - if not uiMouseEvent(ev) then plrDebugMouse(ev); + he := ev; + he.x := trunc(he.x/g_holmes_ui_scale); + he.y := trunc(he.y/g_holmes_ui_scale); + if not uiMouseEvent(he) then plrDebugMouse(he); end; @@ -1262,8 +1268,11 @@ end; procedure g_Holmes_DrawUI (); begin {$IF not DEFINED(HEADLESS)} + glPushMatrix(); + glScalef(g_holmes_ui_scale, g_holmes_ui_scale, 1.0); uiDraw(); drawCursor(); + glPopMatrix(); {$ENDIF} end; @@ -1490,4 +1499,6 @@ begin end; +begin + conRegVar('hlm_ui_scale', @g_holmes_ui_scale, 0.01, 5.0, 'Holmes UI scale', '', false); end. diff --git a/src/game/g_holmes_ui.inc b/src/game/g_holmes_ui.inc index a6daf4f..d9909a2 100644 --- a/src/game/g_holmes_ui.inc +++ b/src/game/g_holmes_ui.inc @@ -664,6 +664,10 @@ end; procedure THControl.setScissorGLInternal (x, y, w, h: Integer); begin if not scallowed then exit; + x := trunc(x*g_holmes_ui_scale); + y := trunc(y*g_holmes_ui_scale); + w := trunc(w*g_holmes_ui_scale); + h := trunc(h*g_holmes_ui_scale); y := gWinSizeY-(y+h); if not intersectRect(x, y, w, h, scxywh[0], scxywh[1], scxywh[2], scxywh[3]) then glScissor(0, 0, 0, 0) else glScissor(x, y, w, h); end; @@ -849,8 +853,8 @@ procedure THTopWindow.centerInScreen (); begin if (mWidth > 0) and (mHeight > 0) then begin - mX := (gWinSizeX-mWidth) div 2; - mY := (gWinSizeY-mHeight) div 2; + mX := trunc((gWinSizeX/g_holmes_ui_scale-mWidth)/2); + mY := trunc((gWinSizeY/g_holmes_ui_scale-mHeight)/2); end; end; diff --git a/src/game/g_window.pas b/src/game/g_window.pas index 1b60950..0ac255f 100644 --- a/src/game/g_window.pas +++ b/src/game/g_window.pas @@ -844,31 +844,43 @@ function SDLMain(): Integer; var idx: Integer; ltmp: Integer; + arg: AnsiString; begin {$IFDEF HEADLESS} e_NoGraphics := True; {$ENDIF} - for idx := 1 to ParamCount do - begin - if ParamStr(idx) = '--opengl-dump-exts' then gwin_dump_extensions := true; - if ParamStr(idx) = '--twinkletwinkle' then gwin_k8_enable_light_experiments := true; - if ParamStr(idx) = '--jah' then g_profile_history_size := 100; - if ParamStr(idx) = '--no-particles' then gpart_dbg_enabled := false; - if ParamStr(idx) = '--no-los' then gmon_dbg_los_enabled := false; - - if ParamStr(idx) = '--profile-render' then g_profile_frame_draw := true; - if ParamStr(idx) = '--profile-coldet' then g_profile_collision := true; - if ParamStr(idx) = '--profile-los' then g_profile_los := true; - - if ParamStr(idx) = '--no-part-phys' then gpart_dbg_phys_enabled := false; - if ParamStr(idx) = '--no-part-physics' then gpart_dbg_phys_enabled := false; - if ParamStr(idx) = '--no-particles-phys' then gpart_dbg_phys_enabled := false; - if ParamStr(idx) = '--no-particles-physics' then gpart_dbg_phys_enabled := false; - if ParamStr(idx) = '--no-particle-phys' then gpart_dbg_phys_enabled := false; - if ParamStr(idx) = '--no-particle-physics' then gpart_dbg_phys_enabled := false; - - if ParamStr(idx) = '--holmes' then begin g_holmes_enabled := true; g_Game_SetDebugMode(); end; + idx := 1; + while (idx <= ParamCount) do + begin + arg := ParamStr(idx); + Inc(idx); + if arg = '--opengl-dump-exts' then gwin_dump_extensions := true; + if arg = '--twinkletwinkle' then gwin_k8_enable_light_experiments := true; + if arg = '--jah' then g_profile_history_size := 100; + if arg = '--no-particles' then gpart_dbg_enabled := false; + if arg = '--no-los' then gmon_dbg_los_enabled := false; + + if arg = '--profile-render' then g_profile_frame_draw := true; + if arg = '--profile-coldet' then g_profile_collision := true; + if arg = '--profile-los' then g_profile_los := true; + + if arg = '--no-part-phys' then gpart_dbg_phys_enabled := false; + if arg = '--no-part-physics' then gpart_dbg_phys_enabled := false; + if arg = '--no-particles-phys' then gpart_dbg_phys_enabled := false; + if arg = '--no-particles-physics' then gpart_dbg_phys_enabled := false; + if arg = '--no-particle-phys' then gpart_dbg_phys_enabled := false; + if arg = '--no-particle-physics' then gpart_dbg_phys_enabled := false; + + if arg = '--holmes' then begin g_holmes_enabled := true; g_Game_SetDebugMode(); end; + if (arg = '--holmes-ui-scale') or (arg = '-holmes-ui-scale') then + begin + if (idx <= ParamCount) then + begin + if not conParseFloat(g_holmes_ui_scale, ParamStr(idx)) then g_holmes_ui_scale := 1.0; + Inc(idx); + end; + end; end; e_WriteLog('Initializing OpenGL', MSG_NOTIFY); -- 2.29.2