Skip to content

Commit

Permalink
Add a EWMA mode to the error bar
Browse files Browse the repository at this point in the history
  • Loading branch information
caiohsr14 committed Apr 18, 2018
1 parent 198a676 commit 2344255
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Themes/Til Death/Languages/en.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion Themes/Til Death/Scripts/01 player_config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ local defaultConfig = {
TargetGoal = 93,
TargetTrackerMode = 0,
JudgeCounter = true,
ErrorBar = true,
ErrorBar = 1,
PlayerInfo = true,
FullProgressBar = true,
MiniProgressBar = true,
Expand Down
16 changes: 9 additions & 7 deletions Themes/Til Death/Scripts/02 ThemePrefs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 2344255

Please sign in to comment.