From 2344255485dabcf1a887989a4cf730242dd807ee Mon Sep 17 00:00:00 2001 From: Caio Rodrigues Date: Tue, 17 Apr 2018 20:31:54 -0400 Subject: [PATCH] Add a EWMA mode to the error bar --- .../WifeJudgmentSpotting.lua | 53 +++++++++++++++---- Themes/Til Death/Languages/en.ini | 2 +- Themes/Til Death/Scripts/01 player_config.lua | 2 +- Themes/Til Death/Scripts/02 ThemePrefs.lua | 16 +++--- 4 files changed, 55 insertions(+), 18 deletions(-) diff --git a/Themes/Til Death/BGAnimations/ScreenGameplay overlay/WifeJudgmentSpotting.lua b/Themes/Til Death/BGAnimations/ScreenGameplay overlay/WifeJudgmentSpotting.lua index 9368fda45f..3bb595474b 100644 --- a/Themes/Til Death/BGAnimations/ScreenGameplay overlay/WifeJudgmentSpotting.lua +++ b/Themes/Til Death/BGAnimations/ScreenGameplay overlay/WifeJudgmentSpotting.lua @@ -206,24 +206,28 @@ local function firstHalfInput(event) if event.DeviceInput.button == "DeviceButton_up" then errorBarY = errorBarY - 5 eb.Center:y(errorBarY) + eb.WeightedBar:y(errorBarY) playerConfig:get_data(pn_to_profile_slot(PLAYER_1)).GameplayXYCoordinates.ErrorBarY = errorBarY changed = true end if event.DeviceInput.button == "DeviceButton_down" then errorBarY = errorBarY + 5 eb.Center:y(errorBarY) + eb.WeightedBar:y(errorBarY) playerConfig:get_data(pn_to_profile_slot(PLAYER_1)).GameplayXYCoordinates.ErrorBarY = errorBarY changed = true end if event.DeviceInput.button == "DeviceButton_left" then errorBarX = errorBarX - 5 eb.Center:x(errorBarX) + eb.WeightedBar:x(errorBarX) playerConfig:get_data(pn_to_profile_slot(PLAYER_1)).GameplayXYCoordinates.ErrorBarX = errorBarX changed = true end if event.DeviceInput.button == "DeviceButton_right" then errorBarX = errorBarX + 5 eb.Center:x(errorBarX) + eb.WeightedBar:x(errorBarX) playerConfig:get_data(pn_to_profile_slot(PLAYER_1)).GameplayXYCoordinates.ErrorBarX = errorBarX changed = true end @@ -238,12 +242,14 @@ local function firstHalfInput(event) if event.DeviceInput.button == "DeviceButton_up" then errorBarHeight = errorBarHeight + 1 eb.Center:zoomtoheight(errorBarHeight) + eb.WeightedBar:zoomtoheight(errorBarHeight) playerConfig:get_data(pn_to_profile_slot(PLAYER_1)).GameplaySizes.ErrorBarHeight = errorBarHeight changed = true end if event.DeviceInput.button == "DeviceButton_down" then errorBarHeight = errorBarHeight - 1 eb.Center:zoomtoheight(errorBarHeight) + eb.WeightedBar:zoomtoheight(errorBarHeight) playerConfig:get_data(pn_to_profile_slot(PLAYER_1)).GameplaySizes.ErrorBarHeight = errorBarHeight changed = true end @@ -900,6 +906,9 @@ local barDuration = 0.75 -- Time duration in seconds before the ticks fa --==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==-- local currentbar = 1 -- so we know which error bar we need to update local ingots = {} -- references to the error bars +local alpha = 0.07; -- ewma alpha +local avg; +local lastAvg; -- Makes the error bars. They position themselves relative to the center of the screen based on your dv and diffuse to your judgement value before disappating or refreshing -- Should eventually be handled by the game itself to optimize performance @@ -922,22 +931,45 @@ function smeltErrorBar(index) } end -local e = Def.ActorFrame{ +local e = Def.ActorFrame{ InitCommand = function(self) eb = self:GetChildren() - for i=1,barcount do -- basically the equivalent of using GetChildren() if it returned unnamed children numerically indexed - ingots[#ingots+1] = self:GetChild(i) + if enabledErrorBar == 1 then + for i=1,barcount do -- basically the equivalent of using GetChildren() if it returned unnamed children numerically indexed + ingots[#ingots+1] = self:GetChild(i) + end + else + avg = 0; + lastAvg = 0; end end, - SpottedOffsetMessageCommand=function(self) - currentbar = ((currentbar)%barcount) + 1 - playcommand(ingots[currentbar],"UpdateErrorBar") -- Update the next bar in the queue + SpottedOffsetMessageCommand=function(self) + if enabledErrorBar == 1 then + currentbar = ((currentbar)%barcount) + 1 + playcommand(ingots[currentbar],"UpdateErrorBar") -- Update the next bar in the queue + end end, DootCommand=function(self) self:RemoveChild("DestroyMe") self:RemoveChild("DestroyMe2") end, - + Def.Quad{ + Name = "WeightedBar", + InitCommand=function(self) + if enabledErrorBar == 2 then + self:xy(errorBarX,errorBarY):zoomto(barWidth,errorBarHeight):diffusealpha(1):diffuse(getMainColor('enabled')) + else + self:visible(false) + end + end, + SpottedOffsetMessageCommand=function(self) + if enabledErrorBar == 2 then + avg = alpha * dvCur + (1 - alpha) * lastAvg + lastAvg = avg + self:x(errorBarX+avg*wscale) + end + end + }, Def.Quad { Name = "Center", InitCommand=function(self) @@ -968,9 +1000,12 @@ local e = Def.ActorFrame{ } } + -- Initialize bars -for i=1,barcount do - e[#e+1] = smeltErrorBar(i) +if enabledErrorBar == 1 then + for i=1,barcount do + e[#e+1] = smeltErrorBar(i) + end end -- Add the completed errorbar frame to the primary actor frame t if enabled diff --git a/Themes/Til Death/Languages/en.ini b/Themes/Til Death/Languages/en.ini index 75e53c8e93..2632377f9f 100644 --- a/Themes/Til Death/Languages/en.ini +++ b/Themes/Til Death/Languages/en.ini @@ -150,7 +150,7 @@ TargetTracker = Enable Goal Tracker. Displays the differential between your curr TargetGoal = Set the percentage goal for the target tracker. TargetTrackerMode = Toggle tracker mode between a set percentage and your personal best. If no PB is available it will default to your set target goal. JudgeCounter = Enable Judge Counter. Displays your currently obtained judgment counts. This has a moderate impact on performance. Expect about a 10% penalty to average fps. -ErrorBar = Enable Error Bar. Visual representation of your judgments' deviation from the intended mark. This is about as taxing as the judge counter performance-wise, though more useful. +ErrorBar = Enable Error Bar. Visual representation of your judgments' deviation from the intended mark. This is about as taxing as the judge counter performance-wise, though more useful. EWMA mode uses the Exponential Weighted Moving Average for its display. ErrorBarLoc = Set the positioning of the error bar to center or bottom. PlayerInfo = Enable the player info display in the bottom left. This is the most taxing gameplay screen element. Expect a 20% or higher drop in average fps. It's also useless for non-streamers. Advised to disable. FullProgressBar = Displays your progress through the song as well as song title. diff --git a/Themes/Til Death/Scripts/01 player_config.lua b/Themes/Til Death/Scripts/01 player_config.lua index 8e129452fe..6c06db95c0 100644 --- a/Themes/Til Death/Scripts/01 player_config.lua +++ b/Themes/Til Death/Scripts/01 player_config.lua @@ -8,7 +8,7 @@ local defaultConfig = { TargetGoal = 93, TargetTrackerMode = 0, JudgeCounter = true, - ErrorBar = true, + ErrorBar = 1, PlayerInfo = true, FullProgressBar = true, MiniProgressBar = true, diff --git a/Themes/Til Death/Scripts/02 ThemePrefs.lua b/Themes/Til Death/Scripts/02 ThemePrefs.lua index 07d53b96f5..5b5e90a67b 100644 --- a/Themes/Til Death/Scripts/02 ThemePrefs.lua +++ b/Themes/Til Death/Scripts/02 ThemePrefs.lua @@ -348,18 +348,20 @@ function ErrorBar() SelectType = "SelectOne", OneChoiceForAllPlayers = false, ExportOnChange = true, - Choices = { THEME:GetString('OptionNames','Off'),'On'}, + Choices = { THEME:GetString('OptionNames','Off'),'On', 'EWMA'}, LoadSelections = function(self, list, pn) local pref = playerConfig:get_data(pn_to_profile_slot(pn)).ErrorBar - if pref then - list[2] = true - else - list[1] = true - end + list[pref+1] = true end, SaveSelections = function(self, list, pn) local value - value = list[2] + if list[1] == true then + value = 0 + elseif list[2] == true then + value = 1 + else + value = 2 + end playerConfig:get_data(pn_to_profile_slot(pn)).ErrorBar = value playerConfig:set_dirty(pn_to_profile_slot(pn)) playerConfig:save(pn_to_profile_slot(pn))