Skip to content

Commit e959555

Browse files
committed
Merge remote-tracking branch 'origin/pr/149/head'
2 parents e0cd824 + c330100 commit e959555

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

resmon.lua

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,18 @@ function resmon.tick_deposit_count(site)
646646
site.iter_key = index
647647
end
648648

649+
-- as a default case, takes a diff between two values and returns a smoothed
650+
-- easing step. however to force convergence, it does *not* smooth diffs below 1
651+
-- and clamps smoothed diffs below 10 to be at least 1.
652+
function resmon.smooth_clamp_diff(diff)
653+
if math.abs(diff) < 1 then
654+
return diff
655+
elseif math.abs(diff) < 10 then
656+
return math.abs(diff) / diff
657+
end
658+
659+
return 0.1 * diff
660+
end
649661

650662
function resmon.finish_deposit_count(site)
651663
site.iter_key = nil
@@ -658,14 +670,15 @@ function resmon.finish_deposit_count(site)
658670
site.last_modified_tick = site.last_ore_check --
659671
end
660672
local delta_ore_since_last_update = site.last_modified_amount - site.amount
661-
if delta_ore_since_last_update ~= 0 then -- only store the amount and tick from last update if it actually changed
673+
if delta_ore_since_last_update ~= 0 then -- only store the amount and tick from last update if it actually changed
662674
site.last_modified_tick = site.last_ore_check --
663675
site.last_modified_amount = site.amount --
664676
end
665677
local delta_ore_since_last_change = site.update_amount - site.last_modified_amount -- use final amount and tick to calculate
666678
local delta_ticks = game.tick - site.last_modified_tick --
667-
local new_ore_per_minute = math.floor(delta_ore_since_last_change * 3600 / delta_ticks) -- ease the per minute value over time
668-
site.ore_per_minute = site.ore_per_minute + (0.1 * (new_ore_per_minute - site.ore_per_minute)) --
679+
local new_ore_per_minute = delta_ore_since_last_change * 3600 / delta_ticks -- ease the per minute value over time
680+
local diff_step = resmon.smooth_clamp_diff(new_ore_per_minute - site.ore_per_minute) --
681+
site.ore_per_minute = site.ore_per_minute + diff_step --
669682
end
670683

671684
site.amount = site.update_amount

0 commit comments

Comments
 (0)