Renamed ArbSpeedMods to ArbitrarySpeedMods to avoid the wrath of the OpenGL Architecture Review Board. Added option rows for controlling the size of the increments used by ArbitrarySpeedMods. Simplified logic in ASM and added rounding to avoid excessive precision. Removed pointless setmetatable calls from various lua option rows.

This commit is contained in:
Kyzentun
2014-06-20 22:48:00 -06:00
parent c02a17f393
commit de8799ebdc
7 changed files with 143 additions and 39 deletions
+4
View File
@@ -478,6 +478,8 @@ SoundResampleQuality=Advanced: Select the resampling quality to use.
SoundVolume=Adjust the volume level during gameplay.
SoundVolumeAttract=Adjust the volume level during attract mode.
Speed=Speed
Speed Increment=Size of the smaller increments used to adjust the speed mod.
Speed Multiple=Multiplied by Speed Increment to calculate the size of the large increments used to adjust the speed mod.
StepMania Credits=The StepMania Development Team.
Steps=Steps
StretchBackgrounds=Toggle the stretching of backgrounds.
@@ -1099,6 +1101,8 @@ SoundResampleQuality=Resampling Quality
SoundVolume=Sound Volume
SoundVolumeAttract=Attract Volume
Speed=Speed
Speed Increment=Speed Increment
Speed Multiple=Speed Multiple
Step Author=Step Author
Steps=Steps
Stream=Stream
+9
View File
@@ -34,6 +34,15 @@ function string:find_last(text)
end
end
-- Round to nearest integer.
function math.round(n)
if n > 0 then
return math.floor(n+0.5)
else
return math.ceil(n-0.5)
end
end
-- (c) 2006 Glenn Maynard
-- All rights reserved.
--
@@ -91,7 +91,6 @@ function OptionsRandomJukebox()
GAMESTATE:SetJukeboxUsesModifiers(val)
end
}
setmetatable( t, t )
return t
end
@@ -134,7 +133,6 @@ function OptionsWeight()
end
end,
}
setmetatable(t, t)
return t
end
+125 -32
View File
@@ -246,8 +246,105 @@ function SpeedMods()
return t
end
function ArbSpeedMods()
local default_speed_increment= 25
local default_speed_inc_multiple= 4
local function get_speed_increment()
local increment= default_speed_increment
if ReadGamePrefFromFile("SpeedIncrement") then
increment= tonumber(GetGamePref("SpeedIncrement")) or default_speed_increment
else
WriteGamePrefToFile("SpeedIncrement", increment)
end
return increment
end
local function get_speed_multiple()
local multiple= default_speed_inc_multiple
if ReadGamePrefFromFile("SpeedMultiple") then
multiple= tonumber(GetGamePref("SpeedMultiple")) or default_speed_inc_multiple
else
WriteGamePrefToFile("SpeedMultiple", multiple)
end
return multiple
end
function SpeedModIncSize()
-- An option row for controlling the size of the increment used by
-- ArbitrarySpeedMods.
local increment= get_speed_increment()
local ret= {
Name= "Speed Increment",
LayoutType= "ShowAllInRow",
SelectType= "SelectMultiple",
OneChoiceForAllPlayers= true,
LoadSelections= function(self, list, pn)
-- The first value is the status element, only it should be true.
list[1]= true
end,
SaveSelections= function(self, list, pn)
WriteGamePrefToFile("SpeedIncrement", increment)
end,
NotifyOfSelection= function(self, pn, choice)
-- return true even though we didn't actually change anything so that
-- the underlines will stay correct.
if choice == 1 then return true end
local incs= {10, 1, -1, -10}
local new_val= increment + incs[choice-1]
if new_val > 0 then
increment= new_val
end
self:GenChoices()
return true
end,
GenChoices= function(self)
self.Choices= {tostring(increment), "+10", "+1", "-1", "-10"}
end
}
ret:GenChoices()
return ret
end
function SpeedModIncMultiple()
-- An option row for controlling the size of the increment used by
-- ArbitrarySpeedMods.
local multiple= get_speed_multiple()
local ret= {
Name= "Speed Multiple",
LayoutType= "ShowAllInRow",
SelectType= "SelectMultiple",
OneChoiceForAllPlayers= true,
LoadSelections= function(self, list, pn)
-- The first value is the status element, only it should be true.
list[1]= true
end,
SaveSelections= function(self, list, pn)
WriteGamePrefToFile("SpeedMultiple", multiple)
end,
NotifyOfSelection= function(self, pn, choice)
-- return true even though we didn't actually change anything so that
-- the underlines will stay correct.
if choice == 1 then return true end
local incs= {5, 1, -1, -5}
local new_val= multiple + incs[choice-1]
if new_val > 0 then
multiple= new_val
end
self:GenChoices()
return true
end,
GenChoices= function(self)
self.Choices= {tostring(multiple), "+5", "+1", "-1", "-5"}
end
}
ret:GenChoices()
return ret
end
function ArbitrarySpeedMods()
-- If players are allowed to join while this option row is active, problems will probably occur.
local increment= get_speed_increment()
local multiple= get_speed_multiple()
local ret= {
Name= "Speed",
LayoutType= "ShowAllInRow",
@@ -269,10 +366,11 @@ function ArbSpeedMods()
local soptions= GAMESTATE:GetPlayerState(pn):GetPlayerOptions("ModsLevel_Song")
local coptions= GAMESTATE:GetPlayerState(pn):GetPlayerOptions("ModsLevel_Current")
if val.mode == "x" then
poptions:XMod(val.speed)
stoptions:XMod(val.speed)
soptions:XMod(val.speed)
coptions:XMod(val.speed)
local speed= val.speed / 100
poptions:XMod(speed)
stoptions:XMod(speed)
soptions:XMod(speed)
coptions:XMod(speed)
elseif val.mode == "C" then
poptions:CMod(val.speed)
stoptions:CMod(val.speed)
@@ -288,31 +386,19 @@ function ArbSpeedMods()
NotifyOfSelection= function(self, pn, choice)
-- Adjust for the status elements
local real_choice= choice - self.NumPlayers
-- return true even though we didn't actually change anything so that the underlines will stay correct.
-- return true even though we didn't actually change anything so that
-- the underlines will stay correct.
if real_choice < 1 then return true end
local val= self.CurValues[pn]
if real_choice < 5 then
local incs= {100, 25, -25, -100}
if val.mode == "x" then
val.speed= val.speed + (incs[real_choice] / 100)
else
val.speed= val.speed + incs[real_choice]
local big_inc= increment * multiple
local incs= {big_inc, increment, -increment, -big_inc}
local new_val= val.speed + incs[real_choice]
if new_val > 0 then
val.speed= math.round(new_val)
end
elseif real_choice == 5 then
if val.mode ~= "x" then
val.speed= val.speed / 100
val.mode= "x"
end
elseif real_choice == 6 then
if val.mode == "x" then
val.speed= math.floor(val.speed * 100)
end
val.mode= "C"
elseif real_choice == 7 then
if val.mode == "x" then
val.speed= math.floor(val.speed * 100)
end
val.mode= "m"
elseif real_choice >= 5 then
val.mode= ({"x", "C", "m"})[real_choice - 4]
end
self:GenChoices()
return true
@@ -326,17 +412,24 @@ function ArbSpeedMods()
show_x_incs= true
end
end
local big_inc= increment * multiple
local small_inc= increment
if show_x_incs then
self.Choices= {"+1", "+.25", "-.25", "-1", "Xmod", "Cmod", "Mmod"}
big_inc= tostring(big_inc / 100)
small_inc= tostring(small_inc / 100)
else
self.Choices= {"+100", "+25", "-25", "-100", "Xmod", "Cmod", "Mmod"}
big_inc= tostring(big_inc)
small_inc= tostring(small_inc)
end
self.Choices= {
"+" .. big_inc, "+" .. small_inc, "-" .. small_inc, "-" .. big_inc,
"Xmod", "Cmod", "Mmod"}
-- Insert the status element for P2 first so it will be second
for i, pn in ipairs({PLAYER_2, PLAYER_1}) do
local val= self.CurValues[pn]
if val then
if val.mode == "x" then
table.insert(self.Choices, 1, val.speed .. "x")
table.insert(self.Choices, 1, (val.speed/100) .. "x")
else
table.insert(self.Choices, 1, val.mode .. val.speed)
end
@@ -352,13 +445,13 @@ function ArbSpeedMods()
local mode= nil
if poptions:MaxScrollBPM() > 0 then
mode= "m"
speed= poptions:MaxScrollBPM()
speed= math.round(poptions:MaxScrollBPM())
elseif poptions:TimeSpacing() > 0 then
mode= "C"
speed= poptions:ScrollBPM()
speed= math.round(poptions:ScrollBPM())
else
mode= "x"
speed= poptions:ScrollSpeed()
speed= math.round(poptions:ScrollSpeed() * 100)
end
ret.CurValues[pn]= {mode= mode, speed= speed}
ret.NumPlayers= ret.NumPlayers + 1
@@ -121,7 +121,6 @@ function OptionRowProTiming()
setenv("ProTiming"..pname, val); --]]
end;
};
setmetatable( t, t );
return t;
end;
@@ -202,6 +201,5 @@ function GamePrefDefaultFail()
THEME:ReloadMetrics();
end;
};
setmetatable( t, t );
return t;
end
+4 -2
View File
@@ -2941,11 +2941,13 @@ Line20="conf,VisualDelaySeconds"
Fallback="ScreenOptionsServiceChild"
NextScreen="ScreenOptionsService"
PrevScreen="ScreenOptionsService"
LineNames="3,4,8,11,13,14,15,16,28,29,30,31"
LineNames="3,4,8,SI,SM,11,13,14,15,16,28,29,30,31"
#LineScore="lua,UserPrefScoringMode()"
Line3="conf,TimingWindowScale"
Line4="conf,LifeDifficulty"
Line8="lua,GamePrefDefaultFail()"
LineSI="lua,SpeedModIncSize()"
LineSM="lua,SpeedModIncMultiple()"
Line11="conf,AllowW1"
Line13="conf,HiddenSongs"
Line14="conf,EasterEggs"
@@ -3076,7 +3078,7 @@ PlayMusic=false
TimerSeconds=30
#
LineNames="1,2,3A,3B,4,5,6,R1,R2,7,8,9,10,11,12,13,14,16,17"
Line1="lua,ArbSpeedMods()"
Line1="lua,ArbitrarySpeedMods()"
# Line1="list,Speed"
Line2="list,Accel"
Line3A="list,EffectsReceptor"
+1 -1
View File
@@ -1327,7 +1327,7 @@ LineFlashyCombo="lua,ThemePrefRow('FlashyCombo')"
[ScreenOptionsGraphicsSound]
[ScreenOptionsAdvanced]
LineNames="3,4,8,11,13,14,16,28,29,30,RollCombo"
LineNames="3,4,8,SI,SM,11,13,14,16,28,29,30,RollCombo"
LineRollCombo="lua,ThemePrefRow('ComboOnRolls')"
[ScreenAppearanceOptions]