From 3749074a4d1478522ddc9b27ebce52da3107b39e Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Sat, 28 Jan 2023 16:49:35 +0200 Subject: [PATCH] Renamed speed setting name to force-reset it to new scale --- client/battle/BattleInterface.cpp | 4 ++-- client/battle/CreatureAnimation.cpp | 30 ++++++++++++++++++----------- client/battle/CreatureAnimation.h | 4 ++++ config/schemas/settings.json | 6 +++--- 4 files changed, 28 insertions(+), 16 deletions(-) diff --git a/client/battle/BattleInterface.cpp b/client/battle/BattleInterface.cpp index 3e54a619c..6a6e435a4 100644 --- a/client/battle/BattleInterface.cpp +++ b/client/battle/BattleInterface.cpp @@ -520,7 +520,7 @@ void BattleInterface::displaySpellHit(const CSpell * spell, BattleHex destinatio void BattleInterface::setAnimSpeed(int set) { - Settings speed = settings.write["battle"]["animationSpeed"]; + Settings speed = settings.write["battle"]["speedFactor"]; speed->Float() = float(set); } @@ -529,7 +529,7 @@ int BattleInterface::getAnimSpeed() const if(settings["session"]["spectate"].Bool() && !settings["session"]["spectate-battle-speed"].isNull()) return static_cast(vstd::round(settings["session"]["spectate-battle-speed"].Float())); - return static_cast(vstd::round(settings["battle"]["animationSpeed"].Float())); + return static_cast(vstd::round(settings["battle"]["speedFactor"].Float())); } CPlayerInterface *BattleInterface::getCurrentPlayerInterface() const diff --git a/client/battle/CreatureAnimation.cpp b/client/battle/CreatureAnimation.cpp index 436cc162d..84bfc513b 100644 --- a/client/battle/CreatureAnimation.cpp +++ b/client/battle/CreatureAnimation.cpp @@ -47,6 +47,15 @@ std::shared_ptr AnimationControls::getAnimation(const CCreatu return std::make_shared(creature->animDefName, func); } +float AnimationControls::getAnimationSpeedFactor() +{ + // according to testing, H3 ratios between slow/medium/fast might actually be 36/60/100 (x1.666) + // exact value is hard to tell due to large rounding errors + // however we will assume them to be 33/66/100 since these values are better for standard 60 fps displays: + // with these numbers, base frame display duration will be 100/66/33 ms - exactly 6/4/2 frames + return settings["battle"]["speedFactor"].Float(); +} + float AnimationControls::getCreatureAnimationSpeed(const CCreature * creature, const CreatureAnimation * anim, ECreatureAnimType type) { assert(creature->animation.walkAnimationTime != 0); @@ -56,10 +65,9 @@ float AnimationControls::getCreatureAnimationSpeed(const CCreature * creature, c // possible new fields for creature format: //split "Attack time" into "Shoot Time" and "Cast Time" - // base speed for all H3 animations is 10/20/30 frames per second (100/50/33 ms per frame) + // base speed for all H3 animations on slow speed is 10 frames per second (or 100ms per frame) const float baseSpeed = 10.f; - const float speedMult = static_cast(settings["battle"]["animationSpeed"].Float()); - const float speed = baseSpeed * speedMult; + const float speed = baseSpeed * getAnimationSpeedFactor(); switch (type) { @@ -73,7 +81,7 @@ float AnimationControls::getCreatureAnimationSpeed(const CCreature * creature, c if ( creature->animation.idleAnimationTime > 0.01) return speed / creature->animation.idleAnimationTime; else - return 0.f; + return 0.f; // this animation is disabled for current creature case ECreatureAnimType::SHOOT_UP: case ECreatureAnimType::SHOOT_FRONT: @@ -121,44 +129,44 @@ float AnimationControls::getCreatureAnimationSpeed(const CCreature * creature, c float AnimationControls::getProjectileSpeed() { // H3 speed: 1250/2500/3750 pixels per second - return static_cast(settings["battle"]["animationSpeed"].Float() * 1250); + return static_cast(getAnimationSpeedFactor() * 1250); } float AnimationControls::getRayProjectileSpeed() { // H3 speed: 4000/8000/12000 pixels per second - return static_cast(settings["battle"]["animationSpeed"].Float() * 4000); + return static_cast(getAnimationSpeedFactor() * 4000); } float AnimationControls::getCatapultSpeed() { // H3 speed: 200/400/600 pixels per second - return static_cast(settings["battle"]["animationSpeed"].Float() * 200); + return static_cast(getAnimationSpeedFactor() * 200); } float AnimationControls::getSpellEffectSpeed() { // H3 speed: 10/20/30 frames per second - return static_cast(settings["battle"]["animationSpeed"].Float() * 10); + return static_cast(getAnimationSpeedFactor() * 10); } float AnimationControls::getMovementDistance(const CCreature * creature) { // H3 speed: 2/4/6 tiles per second - return static_cast( 2.0 * settings["battle"]["animationSpeed"].Float() / creature->animation.walkAnimationTime); + return static_cast( 2.0 * getAnimationSpeedFactor() / creature->animation.walkAnimationTime); } float AnimationControls::getFlightDistance(const CCreature * creature) { // Note: for whatever reason, H3 uses "Walk Animation Time" here, even though "Flight Animation Distance" also exists // H3 speed: 250/500/750 pixels per second - return static_cast( 250.0 * settings["battle"]["animationSpeed"].Float() / creature->animation.walkAnimationTime); + return static_cast( 250.0 * getAnimationSpeedFactor() / creature->animation.walkAnimationTime); } float AnimationControls::getFadeInDuration() { // H3 speed: 500/250/166 ms - return 0.5f / settings["battle"]["animationSpeed"].Float(); + return 0.5f / getAnimationSpeedFactor(); } float AnimationControls::getObstaclesSpeed() diff --git a/client/battle/CreatureAnimation.h b/client/battle/CreatureAnimation.h index 04f68afac..5d14dbb70 100644 --- a/client/battle/CreatureAnimation.h +++ b/client/battle/CreatureAnimation.h @@ -25,6 +25,10 @@ namespace AnimationControls SDL_Color getGoldBorder(); SDL_Color getNoBorder(); + /// returns animation speed factor according to game settings, + /// slow speed is considered to be "base speed" and will return 1.0 + float getAnimationSpeedFactor(); + /// creates animation object with preset speed control std::shared_ptr getAnimation(const CCreature * creature); diff --git a/config/schemas/settings.json b/config/schemas/settings.json index d3472c3ab..c05448291 100644 --- a/config/schemas/settings.json +++ b/config/schemas/settings.json @@ -230,11 +230,11 @@ "type" : "object", "additionalProperties" : false, "default": {}, - "required" : [ "animationSpeed", "mouseShadow", "cellBorders", "stackRange", "showQueue", "queueSize" ], + "required" : [ "speedFactor", "mouseShadow", "cellBorders", "stackRange", "showQueue", "queueSize" ], "properties" : { - "animationSpeed" : { + "speedFactor" : { "type" : "number", - "default" : 0.63 + "default" : 2 }, "mouseShadow" : { "type":"boolean",