I have your answer. First, I updated that Code i posted in my last message. Run it. Hold Control Button for a few seconds to toggle between both of our timing methods.
First things first:
Quote: "Why are you dividing by 60 ???
What purpose does it serve ???"
factors(30) = Diff# / 100.0
You are dividing by 100, what purpose does that serve?
Secondly and this is very important.
Forget the fact that you are Averaging the last 30 frames for a second. If you ignore this then my code always spits out a value equal to 6 times the value yours does. Check it. It's true.
My code actually does the same thing yours does when you don't average values. The value is merely 6 times larger. This means any issue over accuracy is irrelevant. Both methods are equal.
Proof: Check it. It's True.
global Flast# as float
global Diff# as float
global Ideal# as float
global Factor# as float
global mysync as integer
Dim factors(30) as float
global movetimer as integer
global thisMove as float
global moveTotal as float
global moved as float
Global FrameX#
Global FrameLast
Global DelayPeriod#
Global MoreAcurateFPS#
Global TurnStartTime#
GLobal TurnTimeTaken#
Global UseAlternateTiming
Global FrameTimeLength#
sync on
Set Display Mode 1024, 768, 32
FrameTimeLength# = 16.6666666666666
FrameTimer()
tm_Update()
Do
Text 10,10, "Simulated Framerate of " + Str$(1000.0 / FrameTimeLength#) + "fps. Frame length is " + str$(FrameTimeLength#) + "ms."
Text 10,20,"-----------------------------"
Text 10,30,"Mage's Multiplier FrameX#"
Text 10,40, Str$(FrameX#)
Text 10,60,"KISTech's Multiplier Factor#"
Text 10,70,Str$(Factor#)
Text 10,90,"Factor# times 6.0"
Text 10,100,Str$(Factor# * 6.0)
Sync
Loop
`Mages Timing Solution
Function FrameTimer()
`Diff# = (Timer() - FrameLast) `replaced for this demo
Diff# = FrameTimeLength# `Added for this demo.
Ideal# = 1000.0 / 60.0
FrameX# = Diff# / Ideal#
If Diff# > 1000 then FrameX# = 0
FrameLast = Timer()
EndFunction
`KISTech's Timing Solution
function tm_Update()
Diff# as float
`Diff# = timer() - Flast# `replaced for this demo
Diff# = FrameTimeLength# `Added for this demo
If Diff# > 1000 then Diff# = 0
Flast# = timer()
factor# = 0.0
for tx = 1 to 29
factors(tx) = factors(tx+1)
factor# = factor# + factors(tx)
next tx
factors(30) = Diff# / 100.0
`factor# = factor# + factors(30) `removed for this demo
factor# = factors(30) `Added for this demo (this removes the timing averaging)
`factor# = factor# / 30.0 `removed for this demo (this removes the timing averaging)
endfunction
Mind = blown.
This brings me to my third big point.
I had a good look at your code. Why are you averaging your timing?!? This is extremely bad!
Proof:
global Flast# as float
global Diff# as float
global Ideal# as float
global Factor# as float
global mysync as integer
Dim factors(30) as float
global movetimer as integer
global thisMove as float
global moveTotal as float
global moved as float
Global FrameX#
Global FrameLast
Global DelayPeriod#
Global MoreAcurateFPS#
Global TurnStartTime#
GLobal TurnTimeTaken#
Global UseAlternateTiming
sync on
Set Display Mode 1024, 768, 32
make object cube 1, 10
position object 1, 0, 0, 0
position camera 0, 0, 100, -100
point camera 0, 0, 0, 0
TurnStartTime# = Timer()
Do
StartTime# = Timer()
`Run Frame Timing Corrections
Handle_FrameTiming()
`Control Frame Timing Scheme
UseAlternateTiming = 0
if ControlKey() = 1 Then UseAlternateTiming = 1
`Insert An Erratic Delay Into Frame
Handle_Delay()
`Rotate Object with timing corrections
YRotate Object 1, WrapValue(Object Angle Y(1) + 1.0 * FrameX#)
`Display Data On Screen
Handle_Hud()
`Draw Frame
Sync
`Update Time Taken for full rotation when it occurs.
If Object Angle Y(1) < PreviousAngle#
TurnTimeTaken# = Abs(TurnStartTime# - Timer())
TurnStartTime# = Timer()
EndIf
PreviousAngle# = Object Angle Y(1)
`Calc more acurate frame rate.
MoreAcurateFPS# = 1000 / Abs(Timer() - StartTime#)
Loop
`Mage's Frame Timing Function
Function FrameTimer()
Diff# = (Timer() - FrameLast)
Ideal# = 1000.0 / 60.0
FrameX# = Diff# / Ideal#
If Diff# > 1000 then FrameX# = 0
FrameLast = Timer()
EndFunction
Function Handle_Hud()
Text 10,10, "Object Angle:" + Str$(Object Angle Y(1) + 1.0 * FrameX#)
Text 10,20, "Object Speed per Frame:" + Str$(1.0 * FrameX#)
Text 10,40, "Last Rotation Period:" + Str$(TurnTimeTaken# / 1000) + "s"
Text 10,50, "FPS: " + Str$(Screen FPS())
Text 10,60, "Per Frame FPS:" + str$(MoreAcurateFPS#)
Text 10,80, "Delay added in this frame:"
Text 10,90, Str$(DelayPeriod#) + "ms"
If UseAlternateTiming = 0 Then Text 10,140, "Mage Timing Method"
If UseAlternateTiming = 1 Then Text 10,140, "KISTECH Timing Method"
Text 10,150, "Press Control Button."
EndFunction
`Sin Function Based Delay - Delay Varies from 0 to 50ms based on Object Rotation Angle.
Function Handle_Delay()
DelayFactor# = Abs(Sin(Object Angle Y(1)))
DelayPeriod# = 50 * DelayFactor#
Start# = Timer()
While Abs(Start# - Timer()) < DelayPeriod#
EndWhile
EndFunction
Function Handle_FrameTiming()
If UseAlternateTiming = 1
tm_Update()
FrameX# = Factor# * 6.0
Else
FrameTimer()
EndIF
EndFunction
`KISTech's Timing Solution
function tm_Update()
Diff# as float
Diff# = timer() - Flast#
If Diff# > 1000 then Diff# = 0
Flast# = timer()
factor# = 0.0
for tx = 1 to 29
factors(tx) = factors(tx+1)
factor# = factor# + factors(tx)
next tx
factors(30) = Diff# / 100.0
factor# = factor# + factors(30)
factor# = factor# / 30.0
endfunction
Take a look at the code I posted in my previous message. I updated it. It shows what your code does with your averaging when the fps is always changing. You have a major issue here.
I have a constantly changing delay driven by a SIN() function that your averaging can't handle. Take the averaging out. This is a huge problem. If fps suddenly jumps from 20 to 40, your program still thinks fps is somewhere in between for about 30 frames.
Check the code in the previous message. I Updated it. It's complete proof of this.
Otherwise, this settles it. Your method (without the averaging) is the same as mine. QED.