From 9a0d51ad0566fc90e0ec9c80e2f07f2bca9bdb33 Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Sun, 1 Nov 2020 15:04:13 -0800 Subject: [PATCH] Wire up the rest of CTweakGame to CVars --- DataSpec/DNAMP1/Tweaks/CTweakGame.cpp | 128 +++++++++++++++++--------- DataSpec/DNAMP1/Tweaks/CTweakGame.hpp | 6 +- Runtime/Character/CCharAnimTime.cpp | 66 +++++-------- 3 files changed, 112 insertions(+), 88 deletions(-) diff --git a/DataSpec/DNAMP1/Tweaks/CTweakGame.cpp b/DataSpec/DNAMP1/Tweaks/CTweakGame.cpp index f2f7a923a..400415185 100644 --- a/DataSpec/DNAMP1/Tweaks/CTweakGame.cpp +++ b/DataSpec/DNAMP1/Tweaks/CTweakGame.cpp @@ -4,56 +4,96 @@ #include #include +#define DEFINE_CVAR_GLOBAL(name) \ + constexpr std::string_view sk##name = std::string_view("tweak.game." #name); \ + hecl::CVar* tw_##name = nullptr; + +#define CREATE_CVAR(name, help, value, flags) \ + tw_##name = mgr->findOrMakeCVar(sk##name, help, value, flags); \ + if (tw_##name->wasDeserialized()) { \ + tw_##name->toValue(value); \ + } \ + tw_##name->addListener([this](hecl::CVar* cv) { _tweakListener(cv); }); + +#define CREATE_CVAR_BITFIELD(name, help, value, flags) \ + { \ + bool tmp = value; \ + CREATE_CVAR(name, help, tmp, flags) \ + } + +#define UPDATE_CVAR(name, cv, value) \ + if ((cv) == tw_##name) { \ + (cv)->toValue(value); \ + return; \ + } + +#define UPDATE_CVAR_BITFIELD(name, cv, value) \ + { \ + bool tmp = value; \ + UPDATE_CVAR(name, cv, tmp) \ + (value) = tmp; \ + } + namespace DataSpec::DNAMP1 { -hecl::CVar* tw_fov = nullptr; -hecl::CVar* tw_hardmodeDMult = nullptr; -hecl::CVar* tw_hardmodeWMult = nullptr; -hecl::CVar* tw_splashScreensDisabled = nullptr; namespace { -constexpr std::string_view skFov = "tweak.game.FieldOfView"sv; -constexpr std::string_view skHardModeDamageMultName = "tweak.game.HardModeDamageMult"sv; -constexpr std::string_view skHardModeWeaponMultName = "tweak.game.HardModeWeaponMult"sv; -constexpr std::string_view skSplashScreensDisabled = "tweak.game.SplashScreensDisabled"sv; +constexpr hecl::CVar::EFlags skDefaultFlags = hecl::CVar::EFlags::Game | hecl::CVar::EFlags::Archive; +DEFINE_CVAR_GLOBAL(WorldPrefix); +DEFINE_CVAR_GLOBAL(FieldOfView); +DEFINE_CVAR_GLOBAL(SplashScreensDisabled); +DEFINE_CVAR_GLOBAL(PressStartDelay); +DEFINE_CVAR_GLOBAL(WavecapIntensityNormal); +DEFINE_CVAR_GLOBAL(WavecapIntensityPoison); +DEFINE_CVAR_GLOBAL(WavecapIntensityLava); +DEFINE_CVAR_GLOBAL(RippleIntensityNormal); +DEFINE_CVAR_GLOBAL(RippleIntensityPoison); +DEFINE_CVAR_GLOBAL(RippleIntensityLava); +DEFINE_CVAR_GLOBAL(FluidEnvBumpScale); +DEFINE_CVAR_GLOBAL(WaterFogDistanceBase); +DEFINE_CVAR_GLOBAL(WaterFogDistanceRange); +DEFINE_CVAR_GLOBAL(GravityWaterFogDistanceBase); +DEFINE_CVAR_GLOBAL(GravityWaterFogDistanceRange); +DEFINE_CVAR_GLOBAL(HardModeDamageMult); +DEFINE_CVAR_GLOBAL(HardModeWeaponMult); } // anonymous namespace -void CTweakGame::_tweakGameListener(hecl::CVar* cv) { - if (cv == tw_fov) { - x24_fov = cv->toReal(); - } else if (cv == tw_hardmodeDMult) { - x60_hardmodeDamageMult = cv->toReal(); - } else if (cv == tw_hardmodeWMult) { - x64_hardmodeWeaponMult = cv->toReal(); - } else if (cv == tw_splashScreensDisabled) { - x2b_splashScreensDisabled = cv->toBoolean(); - } +void CTweakGame::_tweakListener(hecl::CVar* cv) { + UPDATE_CVAR(WorldPrefix, cv, x4_worldPrefix); + UPDATE_CVAR(FieldOfView, cv, x24_fov); + UPDATE_CVAR(SplashScreensDisabled, cv, x2b_splashScreensDisabled); + UPDATE_CVAR(PressStartDelay, cv, x30_pressStartDelay); + UPDATE_CVAR(WavecapIntensityNormal, cv, x34_wavecapIntensityNormal); + UPDATE_CVAR(WavecapIntensityPoison, cv, x38_wavecapIntensityPoison); + UPDATE_CVAR(WavecapIntensityLava, cv, x3c_wavecapIntensityLava); + UPDATE_CVAR(RippleIntensityNormal, cv, x40_rippleIntensityNormal); + UPDATE_CVAR(RippleIntensityPoison, cv, x44_rippleIntensityPoison); + UPDATE_CVAR(RippleIntensityLava, cv, x48_rippleIntensityLava); + UPDATE_CVAR(FluidEnvBumpScale, cv, x4c_fluidEnvBumpScale); + UPDATE_CVAR(WaterFogDistanceBase, cv, x50_waterFogDistanceBase); + UPDATE_CVAR(WaterFogDistanceRange, cv, x54_waterFogDistanceRange); + UPDATE_CVAR(GravityWaterFogDistanceBase, cv, x58_gravityWaterFogDistanceBase); + UPDATE_CVAR(GravityWaterFogDistanceRange, cv, x5c_gravityWaterFogDistanceRange); + UPDATE_CVAR(HardModeDamageMult, cv, x60_hardmodeDamageMult); + UPDATE_CVAR(HardModeWeaponMult, cv, x64_hardmodeWeaponMult); } void CTweakGame::initCVars(hecl::CVarManager* mgr) { - auto assignRealValue = [this, mgr](std::string_view name, std::string_view desc, float& v, hecl::CVar::EFlags flags) { - hecl::CVar* cv = mgr->findOrMakeCVar(name, desc, v, flags); - // Check if the CVar was deserialized, this avoid an unnecessary conversion - if (cv->wasDeserialized()) - v = static_cast(cv->toReal()); - cv->addListener([this](hecl::CVar* cv) { _tweakGameListener(cv); }); - return cv; - }; - auto assignBoolValue = [this, mgr](std::string_view name, std::string_view desc, bool& v, hecl::CVar::EFlags flags) { - hecl::CVar* cv = mgr->findOrMakeCVar(name, desc, v, flags); - // Check if the CVar was deserialized, this avoid an unnecessary conversion - if (cv->wasDeserialized()) - v = cv->toBoolean(); - cv->addListener([this](hecl::CVar* cv) { _tweakGameListener(cv); }); - return cv; - }; - - tw_fov = assignRealValue(skFov, "", x24_fov, hecl::CVar::EFlags::Game | hecl::CVar::EFlags::Archive); - tw_hardmodeDMult = - assignRealValue(skHardModeDamageMultName, "", x60_hardmodeDamageMult, - hecl::CVar::EFlags::Game | hecl::CVar::EFlags::Archive | hecl::CVar::EFlags::Cheat); - tw_hardmodeWMult = - assignRealValue(skHardModeWeaponMultName, "", x64_hardmodeWeaponMult, - hecl::CVar::EFlags::Game | hecl::CVar::EFlags::Archive | hecl::CVar::EFlags::Cheat); - tw_splashScreensDisabled = assignBoolValue(skSplashScreensDisabled, "", x2b_splashScreensDisabled, - hecl::CVar::EFlags::Game | hecl::CVar::EFlags::Archive); + CREATE_CVAR(WorldPrefix, "", x4_worldPrefix, skDefaultFlags); + CREATE_CVAR(FieldOfView, "", x24_fov, skDefaultFlags); + CREATE_CVAR(SplashScreensDisabled, "", x2b_splashScreensDisabled, + hecl::CVar::EFlags::Game | hecl::CVar::EFlags::Archive); + CREATE_CVAR(PressStartDelay, "", x30_pressStartDelay, , skDefaultFlags); + CREATE_CVAR(WavecapIntensityNormal, "", x34_wavecapIntensityNormal, skDefaultFlags); + CREATE_CVAR(WavecapIntensityPoison, "", x38_wavecapIntensityPoison, skDefaultFlags); + CREATE_CVAR(WavecapIntensityLava, "", x3c_wavecapIntensityLava, skDefaultFlags); + CREATE_CVAR(RippleIntensityNormal, "", x40_rippleIntensityNormal, skDefaultFlags); + CREATE_CVAR(RippleIntensityPoison, "", x44_rippleIntensityPoison, skDefaultFlags); + CREATE_CVAR(RippleIntensityLava, "", x48_rippleIntensityLava, skDefaultFlags); + CREATE_CVAR(FluidEnvBumpScale, "", x4c_fluidEnvBumpScale, skDefaultFlags); + CREATE_CVAR(WaterFogDistanceBase, "", x50_waterFogDistanceBase, skDefaultFlags); + CREATE_CVAR(WaterFogDistanceRange, "", x54_waterFogDistanceRange, skDefaultFlags); + CREATE_CVAR(GravityWaterFogDistanceBase, "", x58_gravityWaterFogDistanceBase, skDefaultFlags); + CREATE_CVAR(GravityWaterFogDistanceRange, "", x5c_gravityWaterFogDistanceRange, skDefaultFlags); + CREATE_CVAR(HardModeDamageMult, "", x60_hardmodeDamageMult, skDefaultFlags); + CREATE_CVAR(HardModeWeaponMult, "", x64_hardmodeWeaponMult, skDefaultFlags); } } // namespace DataSpec::DNAMP1 diff --git a/DataSpec/DNAMP1/Tweaks/CTweakGame.hpp b/DataSpec/DNAMP1/Tweaks/CTweakGame.hpp index 5fe8c5203..2b0ad0201 100644 --- a/DataSpec/DNAMP1/Tweaks/CTweakGame.hpp +++ b/DataSpec/DNAMP1/Tweaks/CTweakGame.hpp @@ -23,7 +23,7 @@ struct CTweakGame final : ITweakGame { Value x38_wavecapIntensityPoison; Value x3c_wavecapIntensityLava; Value x40_rippleIntensityNormal; - Value x44_rippleIntentityPoison; + Value x44_rippleIntensityPoison; Value x48_rippleIntensityLava; Value x4c_fluidEnvBumpScale; Value x50_waterFogDistanceBase; @@ -42,7 +42,7 @@ struct CTweakGame final : ITweakGame { float GetWavecapIntensityPoison() const override { return x38_wavecapIntensityPoison; } float GetWavecapIntensityLava() const override { return x3c_wavecapIntensityLava; } float GetRippleIntensityNormal() const override { return x40_rippleIntensityNormal; } - float GetRippleIntensityPoison() const override { return x44_rippleIntentityPoison; } + float GetRippleIntensityPoison() const override { return x44_rippleIntensityPoison; } float GetRippleIntensityLava() const override { return x48_rippleIntensityLava; } float GetFluidEnvBumpScale() const override { return x4c_fluidEnvBumpScale; } float GetWaterFogDistanceBase() const override { return x50_waterFogDistanceBase; } @@ -61,6 +61,6 @@ struct CTweakGame final : ITweakGame { void initCVars(hecl::CVarManager* mgr) override; private: - void _tweakGameListener(hecl::CVar* cv); + void _tweakListener(hecl::CVar* cv); }; } // namespace DataSpec::DNAMP1 diff --git a/Runtime/Character/CCharAnimTime.cpp b/Runtime/Character/CCharAnimTime.cpp index 089ea0fe9..14a72f1fc 100644 --- a/Runtime/Character/CCharAnimTime.cpp +++ b/Runtime/Character/CCharAnimTime.cpp @@ -76,52 +76,38 @@ bool CCharAnimTime::operator>(const CCharAnimTime& other) const { return (!(*thi bool CCharAnimTime::operator<(const CCharAnimTime& other) const { if (x4_type == EType::NonZero) { - if (other.x4_type == EType::NonZero) + if (other.x4_type == EType::NonZero) { return x0_time < other.x0_time; - if (other.EqualsZero()) - return x0_time < 0.f; - else - return other.x0_time > 0.f; - } - - if (EqualsZero()) { - if (other.EqualsZero()) { - int type = -1; - if (x4_type != EType::ZeroDecreasing) { - if (x4_type != EType::ZeroSteady) - type = 1; - else - type = 0; - } - - int otherType = -1; - if (other.x4_type != EType::ZeroDecreasing) { - if (other.x4_type != EType::ZeroSteady) - otherType = 1; - else - otherType = 0; - } - - return type < otherType; } - if (other.x4_type == EType::NonZero) - return other.x0_time > 0.f; - return other.x0_time > 0.f; // ? + return other.EqualsZero() ? x0_time < 0.f : other.x0_time > 0; } - if (other.x4_type == EType::Infinity) - return x0_time < 0.f && other.x0_time > 0.f; - return x0_time < 0.f; + if (!EqualsZero()) { + if (other.x4_type == EType::Infinity) { + return x0_time >= 0 || other.x0_time <= 0.f; + } + + return x0_time < 0.f; + } + + if (!other.EqualsZero()) { + if (other.x4_type == EType::NonZero) { + return other.x0_time > 0.f; + } + + return other.x0_time > 0.f; + } + + int type = x4_type == EType::ZeroDecreasing ? -1 : x4_type == EType::ZeroSteady ? 0 : 1; + int otherType = other.x4_type == EType::ZeroDecreasing ? -1 : other.x4_type == EType::ZeroSteady ? 0 : 1; + + return type < otherType; } -CCharAnimTime& CCharAnimTime::operator*=(const CCharAnimTime& other) { - return *this = *this * other; -} +CCharAnimTime& CCharAnimTime::operator*=(const CCharAnimTime& other) { return *this = *this * other; } -CCharAnimTime& CCharAnimTime::operator+=(const CCharAnimTime& other) { - return *this = *this + other; -} +CCharAnimTime& CCharAnimTime::operator+=(const CCharAnimTime& other) { return *this = *this + other; } CCharAnimTime CCharAnimTime::operator+(const CCharAnimTime& other) const { if (x4_type == EType::Infinity && other.x4_type == EType::Infinity) { @@ -157,9 +143,7 @@ CCharAnimTime CCharAnimTime::operator+(const CCharAnimTime& other) const { return {EType::ZeroIncreasing, 0.f}; } -CCharAnimTime& CCharAnimTime::operator-=(const CCharAnimTime& other) { - return *this = *this - other; -} +CCharAnimTime& CCharAnimTime::operator-=(const CCharAnimTime& other) { return *this = *this - other; } CCharAnimTime CCharAnimTime::operator-(const CCharAnimTime& other) const { if (x4_type == EType::Infinity && other.x4_type == EType::Infinity) {