refactor options to use Time.time to track when key is pressed, instead of using a Real.real value
This commit is contained in:
@@ -47,5 +47,10 @@ struct
|
||||
|
||||
val moveProjectileBy = 11
|
||||
|
||||
val keyDelay = 0.3
|
||||
val keyDelay =
|
||||
let
|
||||
val time = LargeInt.fromInt 300
|
||||
in
|
||||
Time.fromMilliseconds time
|
||||
end
|
||||
end
|
||||
|
||||
@@ -13,15 +13,15 @@ sig
|
||||
type options_type =
|
||||
{ focus: focus
|
||||
, isSelected: bool
|
||||
, lastUpPress: real
|
||||
, lastDownPress: real
|
||||
, lastUpPress: Time.time
|
||||
, lastDownPress: Time.time
|
||||
, tempKeys: CoreKey.user_key
|
||||
}
|
||||
|
||||
val init: CoreKey.user_key -> options_type
|
||||
end
|
||||
|
||||
structure OptionsType :> OPTIONS_TYPE =
|
||||
structure OptionsType : OPTIONS_TYPE =
|
||||
struct
|
||||
datatype focus =
|
||||
LEFT_KEY
|
||||
@@ -36,16 +36,16 @@ struct
|
||||
type options_type =
|
||||
{ focus: focus
|
||||
, isSelected: bool
|
||||
, lastUpPress: real
|
||||
, lastDownPress: real
|
||||
, lastUpPress: Time.time
|
||||
, lastDownPress: Time.time
|
||||
, tempKeys: CoreKey.user_key
|
||||
}
|
||||
|
||||
fun init userKeys =
|
||||
{ focus = LEFT_KEY
|
||||
, isSelected = false
|
||||
, lastUpPress = 0.0
|
||||
, lastDownPress = 0.0
|
||||
, lastUpPress = Time.zeroTime
|
||||
, lastDownPress = Time.zeroTime
|
||||
, tempKeys = userKeys
|
||||
}
|
||||
end
|
||||
|
||||
@@ -49,8 +49,8 @@ struct
|
||||
* as neither is being pressed. *)
|
||||
val options =
|
||||
{ focus = focus
|
||||
, lastUpPress = 0.0
|
||||
, lastDownPress = 0.0
|
||||
, lastUpPress = Time.zeroTime
|
||||
, lastDownPress = Time.zeroTime
|
||||
, isSelected = isSelected
|
||||
, tempKeys = tempKeys
|
||||
}
|
||||
@@ -60,6 +60,9 @@ struct
|
||||
|
||||
fun moveFocusUp (options: OptionsType.options_type, newFocus, userKeys, time) =
|
||||
let
|
||||
(* only opening Time for time comparison and adding; no impurities here *)
|
||||
open Time
|
||||
|
||||
val {focus, isSelected, lastUpPress, tempKeys, ...} = options
|
||||
(* only switch to newFocus if it is time for key delay to be triggered.
|
||||
* We set lastDownPress to 0 because up is currently being pressed instead
|
||||
@@ -68,14 +71,14 @@ struct
|
||||
if lastUpPress + Constants.keyDelay <= time then
|
||||
{ focus = newFocus
|
||||
, lastUpPress = time
|
||||
, lastDownPress = 0.0
|
||||
, lastDownPress = Time.zeroTime
|
||||
, isSelected = isSelected
|
||||
, tempKeys = tempKeys
|
||||
}
|
||||
else
|
||||
{ focus = focus
|
||||
, lastUpPress = lastUpPress
|
||||
, lastDownPress = 0.0
|
||||
, lastDownPress = Time.zeroTime
|
||||
, isSelected = isSelected
|
||||
, tempKeys = tempKeys
|
||||
}
|
||||
@@ -86,18 +89,21 @@ struct
|
||||
fun moveFocusDown
|
||||
(options: OptionsType.options_type, newFocus, userKeys, time) =
|
||||
let
|
||||
(* only opening Time for time comparison and adding; no impurities here *)
|
||||
open Time
|
||||
|
||||
val {focus, isSelected, lastDownPress, tempKeys, ...} = options
|
||||
val options =
|
||||
if lastDownPress + Constants.keyDelay <= time then
|
||||
{ focus = newFocus
|
||||
, lastUpPress = 0.0
|
||||
, lastUpPress = Time.zeroTime
|
||||
, lastDownPress = time
|
||||
, isSelected = isSelected
|
||||
, tempKeys = tempKeys
|
||||
}
|
||||
else
|
||||
{ focus = focus
|
||||
, lastUpPress = 0.0
|
||||
, lastUpPress = Time.zeroTime
|
||||
, lastDownPress = lastDownPress
|
||||
, isSelected = isSelected
|
||||
, tempKeys = tempKeys
|
||||
|
||||
@@ -303,7 +303,7 @@ struct
|
||||
val _ = Gles3.clearColor (1.0, 1.0, 1.0, 1.0)
|
||||
val _ = Gles3.clear ()
|
||||
|
||||
val time = Glfw.getTime ()
|
||||
val time = Time.now ()
|
||||
val input = InputState.getSnapshot ()
|
||||
val game = GameUpdate.update (game, input, time)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user