Skip to content

Commit

Permalink
Merge branch 'all-in-one-vs2022' into all-in-one-vs2022-wpo
Browse files Browse the repository at this point in the history
  • Loading branch information
themrdemonized committed Nov 10, 2024
2 parents 3d2424d + 2a1316d commit 70aea26
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 14 deletions.
6 changes: 6 additions & 0 deletions gamedata/configs/text/eng/ui_mm_modded_exes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
<string id="ui_mm_modded_exes_new_zoom_enable">
<text>Shader Scopes Smooth Zoom Change (new_zoom_enable)</text>
</string>
<string id="ui_mm_modded_exes_new_zoom_delta_algorithm">
<text>Shader Scopes New Zoom Delta Algorithm (new_zoom_delta_algorithm)</text>
</string>
<string id="ui_mm_modded_exes_new_zoom_delta_algorithm_desc">
<text>Changes zoom levels of a scope to have same Visual zoom change between levels</text>
</string>
<string id="ui_mm_modded_exes_zoom_step_count">
<text>Shader Scopes Smooth Zoom Step Count (zoom_step_count)</text>
</string>
Expand Down
6 changes: 6 additions & 0 deletions gamedata/configs/text/rus/ui_mm_modded_exes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
<string id="ui_mm_modded_exes_new_zoom_enable">
<text>Shader Scopes ïëàâíûé çóì (new_zoom_enable)</text>
</string>
<string id="ui_mm_modded_exes_new_zoom_delta_algorithm">
<text>Shader Scopes íîâûé àëãîðèòì çóìà (new_zoom_delta_algorithm)</text>
</string>
<string id="ui_mm_modded_exes_new_zoom_delta_algorithm_desc">
<text>Ìåíÿåò àëãîðèòì èçìåíåíèÿ çóìà ò.î. ÷òîáû áûëî îäèíàêîâîå âèçóàëüíîå óâåëè÷åíèå</text>
</string>
<string id="ui_mm_modded_exes_zoom_step_count">
<text>Shader Scopes êîë-âî ñòàäèé çóìà (zoom_step_count)</text>
</string>
Expand Down
1 change: 1 addition & 0 deletions gamedata/scripts/lua_help_ex.script
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
sds_zoom_enable [0; 1] // Enable correction of max. zoom with scope_factor, if this option is enabled then max. zoom will be such as prescribed in settings regardless of scope_factor value, if this option is disabled then max. zoom will be sum of value prescribed in settings and the increase that gives scope_factor.
new_zoom_enable [0; 1] // Enable alternative zoom control. Minimal zoom is equal to either mechanical zoom or the one prescribed in section min_scope_zoom_factor. The step of zoom adjustment is more precise.
zoom_step_count [1.0, 10.0] // Adjust the step of zoom if new_zoom_enable is on
new_zoom_delta_algorithm [0; 1] // New zoom delta algorithm
demo_record_return_ctrl_inputs // Launch (from console or scripts) `demo_record` but propagate ESC and TAB keypresses back to launcher entity (game or scripts)
demo_record_blocked_input 1 // Start demo_record without move or stop. The console and Esc key are available
Expand Down
7 changes: 7 additions & 0 deletions gamedata/scripts/ui_options_modded_exes.script
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ function init_opt_base()
def = true,
cmd = "new_zoom_enable",
},
{
id = "new_zoom_delta_algorithm",
type = "check",
val = 1,
def = false,
cmd = "new_zoom_delta_algorithm",
},
{
id = "zoom_step_count",
type = "track",
Expand Down
23 changes: 17 additions & 6 deletions src/xrGame/Weapon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,8 @@ void CWeapon::LoadFireParams(LPCSTR section)
};

void GetZoomData(const float scope_factor, const float zoom_step_count, float& delta, float& min_zoom_factor);
void newGetZoomDelta(const float scope_factor, float& delta, const float min_zoom_factor, float steps);
extern BOOL useNewZoomDeltaAlgorithm;

void NewGetZoomData(const float scope_factor, const float zoom_step_count, float& delta, float& min_zoom_factor, float zoom, float min_zoom)
{
Expand All @@ -856,6 +858,9 @@ void NewGetZoomData(const float scope_factor, const float zoom_step_count, float
float steps = zoom_step_count ? zoom_step_count : n_zoom_step_count;
delta = (min_zoom_factor - scope_factor) / steps;

if (useNewZoomDeltaAlgorithm)
newGetZoomDelta(scope_factor, delta, min_zoom_factor, steps);

//Msg("min zoom factor %f, min zoom %f, loc min zoom factor %f, g_ironsights_factor %f, scope_radius %f, scope_scrollpower %f, zoom_step_count %f, n_zoom_step_count %f, steps %f, delta %f", min_zoom_factor, min_zoom, loc_min_zoom_factor, g_ironsights_factor, scope_radius, scope_scrollpower, zoom_step_count, n_zoom_step_count, steps, delta);
}

Expand Down Expand Up @@ -3035,17 +3040,20 @@ void CWeapon::ZoomInc()
if (!m_zoom_params.m_bUseDynamicZoom) return;
float delta, min_zoom_factor;
float power = scope_radius > 0.0 ? scope_scrollpower : 1;
//

if (zoomFlags.test(NEW_ZOOM)) {
NewGetZoomData(m_zoom_params.m_fScopeZoomFactor * power, m_zoom_params.m_fZoomStepCount, delta, min_zoom_factor, GetZoomFactor() * power, m_zoom_params.m_fMinBaseZoomFactor);
} else {
GetZoomData(m_zoom_params.m_fScopeZoomFactor * power, m_zoom_params.m_fZoomStepCount, delta, min_zoom_factor);
}
//

float f = GetZoomFactor() * power - delta;
if (useNewZoomDeltaAlgorithm)
f = GetZoomFactor() * power * delta;

clamp(f, m_zoom_params.m_fScopeZoomFactor * power, min_zoom_factor);
SetZoomFactor(f / power);
//

m_fRTZoomFactor = GetZoomFactor() * power;
}

Expand All @@ -3055,17 +3063,20 @@ void CWeapon::ZoomDec()
if (!m_zoom_params.m_bUseDynamicZoom) return;
float delta, min_zoom_factor;
float power = scope_radius > 0.0 ? scope_scrollpower : 1;
//

if (zoomFlags.test(NEW_ZOOM)) {
NewGetZoomData(m_zoom_params.m_fScopeZoomFactor * power, m_zoom_params.m_fZoomStepCount, delta, min_zoom_factor, GetZoomFactor() * power, m_zoom_params.m_fMinBaseZoomFactor);
} else {
GetZoomData(m_zoom_params.m_fScopeZoomFactor * power, m_zoom_params.m_fZoomStepCount, delta, min_zoom_factor);
}
//

float f = GetZoomFactor() * power + delta;
if (useNewZoomDeltaAlgorithm)
f = GetZoomFactor() * power / delta;

clamp(f, m_zoom_params.m_fScopeZoomFactor * power, min_zoom_factor);
SetZoomFactor(f / power);
//

m_fRTZoomFactor = GetZoomFactor() * power;
}

Expand Down
23 changes: 15 additions & 8 deletions src/xrGame/WeaponBinoculars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,26 +110,33 @@ void CWeaponBinoculars::render_item_ui()
inherited::render_item_ui();
}

// demonized: new zoom delta change to have same multiple between steps for same visual change with each step
BOOL useNewZoomDeltaAlgorithm = FALSE;
void newGetZoomDelta(const float scope_factor, float& delta, const float min_zoom_factor, float steps)
{
delta = pow(scope_factor / min_zoom_factor, 1.0f / steps);
}

void GetZoomData(const float scope_factor, const float zoom_step_count, float& delta, float& min_zoom_factor)
{
float def_fov = float(g_fov);
float min_zoom_k = 0.3f;
float delta_factor_total = def_fov - scope_factor;
VERIFY(delta_factor_total>0);
VERIFY(delta_factor_total > 0);
min_zoom_factor = def_fov - delta_factor_total * min_zoom_k;
float steps = zoom_step_count ? zoom_step_count : 3.0;
delta = (min_zoom_factor - scope_factor) / steps;
if (useNewZoomDeltaAlgorithm)
newGetZoomDelta(scope_factor, delta, min_zoom_factor, steps);
}

void newGetZoomData(const float scope_factor, const float zoom_step_count, float& delta, float& min_zoom_factor, float c_zoom)
{
float def_fov = float(g_fov);
float min_zoom_k = 0.3f;
float delta_factor_total = def_fov - scope_factor;
VERIFY(delta_factor_total > 0);
min_zoom_factor = def_fov - delta_factor_total * min_zoom_k;
GetZoomData(scope_factor, zoom_step_count, delta, min_zoom_factor);
float steps = zoom_step_count ? zoom_step_count : n_zoom_step_count;
delta = (min_zoom_factor - scope_factor) / steps;
if (useNewZoomDeltaAlgorithm)
newGetZoomDelta(scope_factor, delta, min_zoom_factor, steps);
}

void CWeaponBinoculars::ZoomInc()
Expand All @@ -141,7 +148,7 @@ void CWeaponBinoculars::ZoomInc()
GetZoomData(m_zoom_params.m_fScopeZoomFactor, m_zoom_params.m_fZoomStepCount, delta, min_zoom_factor);
}

float f = GetZoomFactor() - delta;
float f = useNewZoomDeltaAlgorithm ? GetZoomFactor() * delta : GetZoomFactor() - delta;
clamp(f, m_zoom_params.m_fScopeZoomFactor, min_zoom_factor);
SetZoomFactor(f);
czoom = f;
Expand All @@ -156,7 +163,7 @@ void CWeaponBinoculars::ZoomDec()
GetZoomData(m_zoom_params.m_fScopeZoomFactor, m_zoom_params.m_fZoomStepCount, delta, min_zoom_factor);
}

float f = GetZoomFactor() + delta;
float f = useNewZoomDeltaAlgorithm ? GetZoomFactor() / delta : GetZoomFactor() + delta;
clamp(f, m_zoom_params.m_fScopeZoomFactor, min_zoom_factor);
SetZoomFactor(f);
czoom = f;
Expand Down
4 changes: 4 additions & 0 deletions src/xrGame/console_commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ extern int MOUSEBUFFERSIZE;
extern int KEYBOARDBUFFERSIZE;
extern BOOL print_bone_warnings;
extern BOOL poltergeist_spawn_corpse_on_death;
extern BOOL useNewZoomDeltaAlgorithm;

ENGINE_API extern float g_console_sensitive;

Expand Down Expand Up @@ -2806,6 +2807,9 @@ void CCC_RegisterCommands()
// Poltergeists spawn corpses on death
CMD4(CCC_Integer, "poltergeist_spawn_corpse_on_death", &poltergeist_spawn_corpse_on_death, 0, 1);

// New zoom delta algorithm
CMD4(CCC_Integer, "new_zoom_delta_algorithm", &useNewZoomDeltaAlgorithm, 0, 1);

if (strstr(Core.Params, "-dbgdev"))
CMD4(CCC_Float, "g_streff", &streff, -10.f, 10.f);
//No need for server commands in a singleplayer-only mod
Expand Down

0 comments on commit 70aea26

Please sign in to comment.