Add support for timing using delta clocks (#97)

* Small correction to getConstantName. I swear this didn't work before, but now it does.
* Support delta timing in mkxp-z
* refresh Graphics.delta time at the start of update
* Speed up load_data
* Replace Input.count calls with Input.time?
This commit is contained in:
Roza
2021-02-26 14:57:52 -05:00
committed by GitHub
parent dd0bbe5da4
commit c9903c59c8
6 changed files with 20 additions and 17 deletions

View File

@@ -50,14 +50,14 @@ def pbPrintException(e)
print("#{message}\r\nThis exception was logged in #{errorlogline}.\r\nHold Ctrl after closing this message to copy it to the clipboard.")
# Give a ~500ms coyote time to start holding Control
(Graphics.frame_rate / 2).ceil.times{
Graphics.update
t = System.delta
until (System.delta - t) >= 500000
Input.update
if Input.press?(Input::CTRL)
Input.clipboard = message
break
end
}
end
end
def pbCriticalCode

View File

@@ -112,7 +112,7 @@ end
def getConstantName(mod,value)
mod = Object.const_get(mod) if mod.is_a?(Symbol)
for c in mod.constants
return c if mod.const_get(c.to_sym).to_s==value
return c if mod.const_get(c.to_sym)==value
end
raise _INTL("Value {1} not defined by a constant in {2}",value,mod.name)
end
@@ -120,7 +120,7 @@ end
def getConstantNameOrValue(mod,value)
mod = Object.const_get(mod) if mod.is_a?(Symbol)
for c in mod.constants
return c if mod.const_get(c.to_sym).to_s==value
return c if mod.const_get(c.to_sym)==value
end
return value.inspect
end

View File

@@ -263,6 +263,7 @@ class AnimationWindow < SpriteWrapper
right.x+=self.x
right.y+=self.y
swatchrects=[]
repeattime = Input.time?(Input::MOUSELEFT) / 1000
for i in 0...NUMFRAMES
swatchrects.push(Rect.new(arrowwidth+i*96+self.x,self.y,96,96))
end
@@ -276,7 +277,7 @@ class AnimationWindow < SpriteWrapper
end
# Left arrow
if left.contains(mousepos[0],mousepos[1])
if Input.count(Input::MOUSELEFT)>30
if repeattime>750
@start-=3
else
@start-=1
@@ -286,7 +287,7 @@ class AnimationWindow < SpriteWrapper
end
# Right arrow
if right.contains(mousepos[0],mousepos[1])
if Input.count(Input::MOUSELEFT)>30
if repeattime>750
@start+=3
else
@start+=1

View File

@@ -396,12 +396,13 @@ class Slider < UIControl
left=toAbsoluteRect(@leftarrow)
right=toAbsoluteRect(@rightarrow)
oldvalue=self.curvalue
repeattime = Input.time?(Input::MOUSELEFT) / 1000
# Left arrow
if left.contains(mousepos[0],mousepos[1])
if Input.count(Input::MOUSELEFT)>100
if repeattime>2500
self.curvalue-=10
self.curvalue=self.curvalue.floor
elsif Input.count(Input::MOUSELEFT)>50
elsif repeattime>1250
self.curvalue-=5
self.curvalue=self.curvalue.floor
else
@@ -413,10 +414,10 @@ class Slider < UIControl
end
#Right arrow
if right.contains(mousepos[0],mousepos[1])
if Input.count(Input::MOUSELEFT)>100
if repeattime>2500
self.curvalue+=10
self.curvalue=self.curvalue.floor
elsif Input.count(Input::MOUSELEFT)>50
elsif repeattime>1250
self.curvalue+=5
self.curvalue=self.curvalue.floor
else
@@ -644,11 +645,12 @@ class TextSlider < UIControl
left=toAbsoluteRect(@leftarrow)
right=toAbsoluteRect(@rightarrow)
oldvalue=self.curvalue
repeattime = Input.time?(Input::MOUSELEFT) / 1000
# Left arrow
if left.contains(mousepos[0],mousepos[1])
if Input.count(Input::MOUSELEFT)>100
if repeattime>2500
self.curvalue-=10
elsif Input.count(Input::MOUSELEFT)>50
elsif repeattime>1250
self.curvalue-=5
else
self.curvalue-=1
@@ -658,9 +660,9 @@ class TextSlider < UIControl
end
# Right arrow
if right.contains(mousepos[0],mousepos[1])
if Input.count(Input::MOUSELEFT)>100
if repeattime>2500
self.curvalue+=10
elsif Input.count(Input::MOUSELEFT)>50
elsif repeattime>1250
self.curvalue+=5
else
self.curvalue+=1

View File

@@ -20,7 +20,7 @@ class ControlPointSprite < SpriteWrapper
end
def mouseover
if Input.count(Input::MOUSELEFT)==0 || !@dragging
if Input.time?(Input::MOUSELEFT)==0 || !@dragging
@dragging=false
return
end
@@ -389,7 +389,7 @@ def pbDefinePath(canvas)
window.text = (mousepos) ? sprintf("(%d,%d)",mousepos[0],mousepos[1]) : "(??,??)"
Graphics.update
Input.update
if Input.triggerex?(:ESCAPE) || Input.count(Input::MOUSELEFT)==0
if Input.triggerex?(:ESCAPE) || Input.time?(Input::MOUSELEFT)==0
break
end
end

BIN
Game.exe

Binary file not shown.