About Monkey 2 › Forums › Monkey 2 Programming Help › Delta Timing Vs Fixed Rate Logic Vs Timer
This topic contains 4 replies, has 3 voices, and was last updated by
gcmartijn 2 years, 8 months ago.
-
AuthorPosts
-
June 5, 2016 at 5:23 am #903
What’s the best way to deal with various FPS for MX2?
I’ve been messing around with the mojo example “space chimps” which uses the Timer class… and with my Monkeyroid I’ve converted a Fixed Rate Logic model…. but can’t decide what is the best way. Any clues?
FRLTimer, converted from http://www.rightanglegames.com/top-down-shooter-tutorial-with-blitzmax.html
Monkey12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697Class FixedRateLogicTimerField newTime:Double = Millisecs()Field oldTime:Double = Millisecs()Field delta:FloatField dssOn:Int ' do we use delta spike suppression?Field dssIndex:Int ' index into DSS_Array where next delta value is writtenField dssArray:Float[] ' this array contains the delta values to smoothField dssLenArray:Int ' how big is the array of delta valuesField logicFPS:FloatField accumulator:Float, tween:FloatField fpsAccumulator:FloatField updateCount:IntField renderCount:IntField updatesPerSecond:IntField rendersPerSecond:IntMethod New(logicCyclesPerSecond:Float, numSamples:Int = 0)logicFPS = 1.0 / logicCyclesPerSecondPrint "logicFPS = " + logicFPSIf numSamplesdssOn = TruedssArray = New Float[numSamples]dssLenArray = numSamplesEndEndMethod ProcessTime:Float()newTime = Millisecs()delta = Float (newTime - oldTime) * 0.001oldTime = newTimeIf dssOndssArray[dssIndex] = deltaLocal smoothDelta:Float = 0For Local i:Int = 0 To dssLenArray - 1smoothDelta += dssArray[i]Nextdelta = Float(smoothDelta / dssLenArray)dssIndex += 1If dssIndex > dssLenArray - 1 Then dssIndex = 0Endaccumulator += deltafpsAccumulator += deltaIf fpsAccumulator > 1.0fpsAccumulator -= 1.0updatesPerSecond = updateCountupdateCount = 0rendersPerSecond = renderCountrenderCount = 0EndReturn deltaEndMethod LogicUpdateRequired:Int()If accumulator > logicFPSupdateCount += 1accumulator -= logicFPSReturn TrueEndReturn FalseEndMethod GetLogicFPS:Float()Return logicFPSEndMethod GetTween:Float()renderCount += 1Return accumulator / logicFPSEndMethod ShowSpikeSuppression(x:Int, y:Int, canvas:Canvas)canvas.DrawText("Delta Spike Suppressor:", x, y)canvas.DrawText("Final Delta: " + delta, x, y + 20)EndMethod ShowFPS(x:Int, y:Int, canvas:Canvas, showUpdateFPS:Int = True, showRenderFPS:Int = True)Local ty:Int = yIf showUpdateFPScanvas.DrawText("Logic FPS: " + updatesPerSecond, x, ty)ty += 20EndIf showRenderFPScanvas.DrawText("Render FPS: " + rendersPerSecond, x, ty)EndEndEndInit FRL:
Monkey12345Class MyWindow Extends WindowConst UPDATE_FREQUENCY:Float = 100.0Const SPIKE_SUPPRESSION:Int = 20Global GameTime:FixedRateLogicTimer = New FixedRateLogicTimer(UPDATE_FREQUENCY, SPIKE_SUPPRESSION)In OnRender:
Monkey12345678910Method OnRender(canvas:Canvas) OverrideApp.RequestRender()Local delta:Float = GameTime.ProcessTime()While GameTime.LogicUpdateRequired()GameLogic()EndLocal tween:Float = GameTime.GetTween()GameRender(canvas, tween)EndSo if your object has a default speed of 3.0, and you set your logic framerate to 100 it’ll move at 300 pixels per second…
July 22, 2016 at 8:12 pm #2354I hope that someone create (maybe mark) a good tutorial about
deltatime / framerate / oprender / update in MX2
A year ago I was using this for Monkey1 but I don’t know what now the best use is using MX2
https://github.com/Regal-Internet-Brothers/deltatime
Some tests using deltatime with huge ‘strange’ things
http://www.monkey-x.com/Community/posts.php?topic=9918&post=107293&view=all#107293
July 23, 2016 at 9:26 am #2363I am using fixed time to great satisfaction.
July 23, 2016 at 10:12 am #2364Example please, is it slow Device proof ?
I want to try something new, a fresh start using mx2.
But as you can see I had some trouble with getting the most important thing oke, fps.
is the way mx2 handle a render/update setframerate the same ?
July 30, 2016 at 2:41 pm #2555That fixed rate logic seems a good way, but I want to be sure before I’m going to start working with a new test project.
I also use spacechimps as a start, and deleted the timer and other stuff
Monkey12345678910111213141516171819202122232425262728293031323334353637383940#Import "<std>"#Import "<mojo>"Using std..Using mojo..Class MyWindow Extends WindowMethod New( title:String,width:Int,height:Int )Super.New( title,width,height,WindowFlags.Center)SwapInterval=1End MethodMethod OnUpdate()App.RequestRender()' do all the math stuff' ----EndMethod OnRender( canvas:Canvas ) Overridecanvas.TextureFilteringEnabled=FalseOnUpdate()' do all the draw/little math stuffcanvas.DrawText( "FPS="+App.FPS,Width/2,0,.5,0 )EndEnd ClassFunction Main()New AppInstance()New MyWindow("Test",App.DesktopSize.x/2,App.DesktopSize.y/2 )App.Run()EndMy game is going to use
- animated images using a atlas which contains the animation frame speed in ms
- the animated images moving from point A to B in x speed (fixed)
- has to work on ultra fast and/or slower computers/tablet/phone
So my problem is , how do I can handle all those things without getting lag or moving to fast images.
Does the fixed rate logic class solve all those problems for me ?
So someone with a fast computer don’t see to fast movements or animations and <span style=”text-decoration: underline;”>very</span> slow computers see some frame drops (that is not my real problem, and impossible to fix).Monkey12345678910111213Method OnRender(canvas:Canvas) OverrideApp.RequestRender()'' are you going to use that delta ?? , why not only GameTime.ProcessTime()Local delta:Float = GameTime.ProcessTime()While GameTime.LogicUpdateRequired()GameLogic()End'' is the tween the 'delta' i need to use for my moving objects and image frameLocal tween:Float = GameTime.GetTween()GameRender(canvas, tween)End -
AuthorPosts
You must be logged in to reply to this topic.