About Monkey 2 › Forums › Monkey 2 Programming Help › FPS, Delta, FixedFPS, Timing, Animation Topic (almost done)
This topic contains 16 replies, has 7 voices, and was last updated by
Arjailer
2 years, 7 months ago.
-
AuthorPosts
-
August 25, 2016 at 7:57 pm #3450
Final round
I just going back to my old setup what is working, using a delta class I found some years ago.
(In the bananas, no delta code found)Can someone agree with the fact below ?, then I and maybe others understand it better then.
Its hard to understand because of the various factors:
CPU / GPU / MONITOR (hz) / MX2
When I use my delta timing code below and use the this setting:
– SwapInterval=0 > I get FPS 450+
– SwapInterval=1 > I get FPS 60 (I will use this setting)Everything looks oke now, but need to be sure.
[fact 1] Because I’m using the delta I don’t care about the FPS, the movement (looks) works oke
[fact 2] Devices that don’t support SwapInterval=1, movement will be oke because i’m using delta
[fact 3] Devices with 75hz or other are oke because i’m using delta
[fact 4] MX2 loop is always like this App.RequestRender() then OnUpdate() then OnRender()Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207#Import "<std>"#Import "<mojo>"#Import "assets/animation/"Using std..Using mojo..Global dt:DeltaTimerClass DeltaTimerField targetfps:Float = 60Field currentticks:FloatField lastticks:FloatField frametime:FloatField delta:FloatMethod New (fps:Float)targetfps = fpslastticks = Millisecs()EndMethod UpdateDelta:Void()currentticks = Millisecs()frametime = currentticks - lastticksdelta = frametime / (1000.0 / targetfps)lastticks = currentticksEndEndClass MyWindow Extends WindowField frameSets:Stack<FrameSet> = New Stack<FrameSet>()Method New( )SwapInterval=0 ' vsyncdt = New DeltaTimer(60)' this part is normaly using loaded using json and 1 atlas file' ==========================================frameSets.Add(New FrameSet())Local oFS:FrameSet = frameSets.Get(0)oFS.frames.Add(New Frame("1.jpg",60))oFS.frames.Add(New Frame("2.jpg",60))oFS.frames.Add(New Frame("3.jpg",60))oFS.frames.Add(New Frame("4.jpg",60))oFS.frames.Add(New Frame("5.jpg",60))oFS.frames.Add(New Frame("6.jpg",60))oFS.frames.Add(New Frame("7.jpg",60))oFS.frames.Add(New Frame("8.jpg",60))oFS.frames.Add(New Frame("9.jpg",60))oFS.frames.Add(New Frame("10.jpg",60))oFS.frames.Add(New Frame("11.jpg",60))oFS.frames.Add(New Frame("12.jpg",60))oFS.frames.Add(New Frame("13.jpg",60))oFS.frames.Add(New Frame("14.jpg",60))oFS.frames.Add(New Frame("15.jpg",60))oFS.frames.Add(New Frame("16.jpg",60))oFS.frameEnd = oFS.frames.Length-1oFS.Position = New Vec2f( 400,400 )oFS.move2left = True' another framesetframeSets.Add(New FrameSet())oFS = frameSets.Get(1) ' another framesetoFS.frames.Add(New Frame("1.jpg",500))oFS.frames.Add(New Frame("2.jpg",500))oFS.frames.Add(New Frame("3.jpg",500))oFS.frames.Add(New Frame("4.jpg",500))oFS.frames.Add(New Frame("5.jpg",500))oFS.frames.Add(New Frame("6.jpg",500))oFS.frames.Add(New Frame("7.jpg",500))oFS.frames.Add(New Frame("8.jpg",500))oFS.frames.Add(New Frame("9.jpg",500))oFS.frames.Add(New Frame("10.jpg",500))oFS.frames.Add(New Frame("11.jpg",500))oFS.frames.Add(New Frame("12.jpg",500))oFS.frames.Add(New Frame("13.jpg",500))oFS.frames.Add(New Frame("14.jpg",500))oFS.frames.Add(New Frame("15.jpg",500))oFS.frames.Add(New Frame("16.jpg",500))oFS.frameEnd = oFS.frames.Length-1oFS.Position = New Vec2f( 400,250 )oFS.move2left = True' another framesetframeSets.Add(New FrameSet())oFS = frameSets.Get(2)oFS.frames.Add(New Frame("1.jpg",1000))oFS.frames.Add(New Frame("2.jpg",1000))oFS.frames.Add(New Frame("3.jpg",1000))oFS.frames.Add(New Frame("4.jpg",1000))oFS.frames.Add(New Frame("5.jpg",1000))oFS.frames.Add(New Frame("6.jpg",1000))oFS.frames.Add(New Frame("7.jpg",1000))oFS.frames.Add(New Frame("8.jpg",1000))oFS.frames.Add(New Frame("9.jpg",1000))oFS.frames.Add(New Frame("10.jpg",1000))oFS.frames.Add(New Frame("11.jpg",1000))oFS.frames.Add(New Frame("12.jpg",1000))oFS.frames.Add(New Frame("13.jpg",1000))oFS.frames.Add(New Frame("14.jpg",1000))oFS.frames.Add(New Frame("15.jpg",1000))oFS.frames.Add(New Frame("16.jpg",1000))oFS.frameEnd = oFS.frames.Length-1oFS.Position = New Vec2f( 200,100 )' ==========================================EndMethod OnRender( canvas:Canvas ) OverrideApp.RequestRender()OnUpdate()canvas.TextureFilteringEnabled=Falsecanvas.DrawText( "FPS="+App.FPS,Width/2,0,.5,0 )For Local oFS:FrameSet = Eachin frameSetsoFS.Draw(canvas)NextEndMethod OnUpdate()dt.UpdateDelta()For Local oFS:FrameSet = Eachin frameSetsoFS.UpdateFrameTimer()If oFS.move2leftoFS.Position.x-=1*dt.deltaIf oFS.Position.x <= 50oFS.move2left = FalseoFS.move2right = TrueEndElseif oFS.move2rightoFS.Position.x+=1*dt.deltaIf oFS.Position.x >= 450oFS.move2left = TrueoFS.move2right = FalseEndEndNextEndEndClass FrameSetField frames:Stack<Frame> = New Stack<Frame>()Field currFrameKey:Int = 0Field timer:IntField frameEnd:IntField Position:=New Vec2fField move2left:Bool ' debugField move2right:Bool ' debugMethod New()EndMethod CurrentFrame:Frame()Return frames.Get(currFrameKey)EndMethod UpdateFrameTimer:Void()' If frame_total > 1If dt.lastticks > timer + frames.Get(currFrameKey).durationcurrFrameKey+=1If currFrameKey > frameEndcurrFrameKey = 0Endtimer = Millisecs()End' EndEndMethod Draw:Void(canvas:Canvas)canvas.DrawImage(CurrentFrame().img,Position.X,Position.Y)EndEnd ClassClass FrameField duration:IntField name:StringField img:ImageMethod New (_name:String,_duration:Int)name= _nameduration = _durationimg=Image.Load( "asset::"+_name)img.Handle=New Vec2f( .5,.5 )EndEnd ClassFunction Main()New AppInstanceNew MyWindow()App.Run()EndAugust 26, 2016 at 7:49 am #3466As far as I know:
[fact 1] Yes
[fact 2] Yes
[fact 3] Yes
[fact 4] Yes- with a clarification – App.RequestRender() seems to be telling the app to call OnRender() for the next frame (so it’s too late to stop the current frame as it’s already underway, but you could avoid calling it for subsequent frames if you wanted – e.g. if the window had lost focus). So as long as you call App.RequestRender() somewhere in the OnRender() method you’re good – I don’t think the order matters.Also, I confirmed the SwapInterval behaviour last night with an old 19″ 75hz monitor I have at home – just using SwapInterval = 1 and not setting an explicit resolution it’s updating 75 times a second as I suspected.
-
AuthorPosts
You must be logged in to reply to this topic.