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 23, 2016 at 7:30 pm #3374
I found a class at this forum and did try it on my engine.
It din’t work 100% oke ;(Then I test some things but the animation are still not 100% correct.
And I don’t know if the timing is correct.Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314#Import "<std>"#Import "<mojo>"#Import "assets/animation/1.jpg"#Import "assets/animation/2.jpg"#Import "assets/animation/3.jpg"#Import "assets/animation/4.jpg"#Import "assets/animation/5.jpg"#Import "assets/animation/6.jpg"#Import "assets/animation/7.jpg"#Import "assets/animation/8.jpg"#Import "assets/animation/9.jpg"#Import "assets/animation/10.jpg"#Import "assets/animation/11.jpg"#Import "assets/animation/12.jpg"#Import "assets/animation/13.jpg"#Import "assets/animation/14.jpg"#Import "assets/animation/15.jpg"#Import "assets/animation/16.jpg"Using std..Using mojo..Global GameTime:FixedRateLogicTimer = New FixedRateLogicTimer(100.0, 20)#rem monkeydocALPHA TEST CODE, WITHOUT ALL THE CLASSES AND OTHER THINGS.Problem- At the start, the FPS is not 'correct' and the [FrameSet] movement is to fastQuestions- Is the timing correct, [Frame] duration drawing ?- Is this stable on mid-range/fast IOS/Android/Desktop ?- movement*_delta in OnUpdateGameLogic not working or not necessary ?The engine is something like this- 1 [scene]- contains 0:n [FrameSet]- contains 1:n [Frame][FrameSet]- If it contains >1 [Frame] then its a animation, using duration- If it contains 1 [Frame] then its not a animation[Frame]- A single image with optional a duration#endClass MyWindow Extends WindowField frameSets:Stack<FrameSet> = New Stack<FrameSet>()Method New( )SwapInterval=1 ' vsync' 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,300 )oFS.move2left = True' another framesetframeSets.Add(New FrameSet())oFS = frameSets.Get(1) ' another framesetoFS.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,150 )oFS.move2left = True' another framesetframeSets.Add(New FrameSet())oFS = frameSets.Get(2)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( 200,100 )' ==========================================EndMethod OnRender( canvas:Canvas ) Overridecanvas.TextureFilteringEnabled=FalseApp.RequestRender()GameTime.ShowFPS(0, 0, canvas)Local delta:Float = GameTime.ProcessTime()While GameTime.LogicUpdateRequired()OnUpdateGameLogic(delta)EndLocal tween:Float = GameTime.GetTween()OnRenderGame(canvas)EndMethod OnUpdateGameLogic(_delta:Float)For Local oFS:FrameSet = Eachin frameSetsoFS.UpdateFrameTimer()If oFS.move2leftoFS.Position.x-=1 '*_delta IF using then its to slowEndNextEndMethod OnRenderGame(canvas:Canvas)For Local oFS:FrameSet = Eachin frameSetsoFS.Draw(canvas)NextEndEndClass FrameSetField frames:Stack<Frame> = New Stack<Frame>()Field currFrameKey:Int = 0Field timer:IntField frameEnd:IntField Position:=New Vec2fField move2left:BoolMethod New()EndMethod UpdateFrameTimer:Void()If GameTime.newTime > timer + frames.Get(currFrameKey).durationcurrFrameKey+=1If currFrameKey > frameEndcurrFrameKey = 0Endtimer = Millisecs()EndEndMethod Draw:Void(canvas:Canvas)Local oF:Frame = frames.Get(currFrameKey)canvas.DrawImage(oF.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 ClassClass 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 / logicCyclesPerSecond' Print "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)EndEndEndFunction Main()New AppInstanceNew MyWindow()App.Run()EndAnd you need to unpack the animation.zip
I can’t upload all the 16 frames here, only four uploads are allowed.August 23, 2016 at 11:22 pm #3380I havent executed your code, but looking at your logic you are basing your animations on millisecs but using the FRL update control. This may mean you could get bigger gaps with your millisecs calls.
What I’ve done in the past is calculate the number of millisecs to frame time.
[/crayon]Monkey123456789101112131415[crayon-5cb9e2f34f938678684280 inline="true" ]Class FrameField duration:FloatField name:StringField img:ImageMethod New (_name:String,_duration:Int)name= _nameduration = GameTime.CalcFrameTime(_duration)img=Image.Load( "asset::"+_name)img.Handle=New Vec2f( .5,.5 )EndEnd Class[/crayon]Monkey123456[crayon-5cb9e2f34f950684441651 inline="true" ]Class FixedRateLogicTimer...Method CalcFrameTime:Float(ms:Int)Return ms / 1000.0 / (logicFPS / 1.0)EndThen in FrameSet you will increase the frametime by 1*delta…
August 24, 2016 at 6:55 am #3393Created new topic below
August 24, 2016 at 11:44 am #3399I think I have it now, but not sure because its hard to understand this part of game making
Here is a video
There is only a problem when starting a game, you can see it in the beginning of the ‘movie’
The movement is way to fast, and after 1 or 2 seconds the Logic FPS is oke (100)The first animation is 1 second
oFS.frames.Add(New Frame(“1.jpg”,10000))
I want to use MS each frame, but I thought 1000 MS is 1 second (not 10000)The second frame is moving and the animation speed is
oFS.frames.Add(New Frame(“1.jpg”,500))The third frame is moving and the animation speed is
oFS.frames.Add(New Frame(“15.jpg”,60))If I understand it correctly, this means
New FixedRateLogicTimer(100.0, 20)Call Method OnUpdateGameLogic(_delta:Float) after every 100 frames.
AND everything inside that method don’t have to use speed*delta movement because this will happen every 100 frames (locked)Inside that OnUpdateGameLogic() I call the UpdateFrameTimer() to update the current frame duration like this.
Monkey1234567891011Method UpdateFrameTimer:Void(_delta:Float)If GameTime.newTime > timer + CurrentFrame().durationcurrFrameKey+=1If currFrameKey > frameEndcurrFrameKey = 0Endtimer = Millisecs()CurrentFrame().duration += 1*_deltaEndEndFull code
Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335#Import "<std>"#Import "<mojo>"#Import "assets/animation/1.jpg"#Import "assets/animation/2.jpg"#Import "assets/animation/3.jpg"#Import "assets/animation/4.jpg"#Import "assets/animation/5.jpg"#Import "assets/animation/6.jpg"#Import "assets/animation/7.jpg"#Import "assets/animation/8.jpg"#Import "assets/animation/9.jpg"#Import "assets/animation/10.jpg"#Import "assets/animation/11.jpg"#Import "assets/animation/12.jpg"#Import "assets/animation/13.jpg"#Import "assets/animation/14.jpg"#Import "assets/animation/15.jpg"#Import "assets/animation/16.jpg"Using std..Using mojo..Global GameTime:FixedRateLogicTimer = New FixedRateLogicTimer(100.0, 20)#rem monkeydocALPHA TEST CODE, WITHOUT ALL THE CLASSES AND OTHER THINGS.Problem- At the start, the FPS is not 'correct' and the [FrameSet] movement is to fastQuestions- Is the timing correct, [Frame] duration drawing ?- Is this stable on mid-range/fast IOS/Android/Desktop ?- movement*_delta in OnUpdateGameLogic not working or not necessary ?The engine is something like this- 1 [scene]- contains 0:n [FrameSet]- contains 1:n [Frame][FrameSet]- If it contains >1 [Frame] then its a animation, using duration- If it contains 1 [Frame] then its not a animation[Frame]- A single image with optional a duration#endClass MyWindow Extends WindowField frameSets:Stack<FrameSet> = New Stack<FrameSet>()Method New( )SwapInterval=1 ' vsync' 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",10000))oFS.frames.Add(New Frame("2.jpg",10000))oFS.frames.Add(New Frame("3.jpg",10000))oFS.frames.Add(New Frame("4.jpg",10000))oFS.frames.Add(New Frame("5.jpg",10000))oFS.frames.Add(New Frame("6.jpg",10000))oFS.frames.Add(New Frame("7.jpg",10000))oFS.frames.Add(New Frame("8.jpg",10000))oFS.frames.Add(New Frame("9.jpg",10000))oFS.frames.Add(New Frame("10.jpg",10000))oFS.frames.Add(New Frame("11.jpg",10000))oFS.frames.Add(New Frame("12.jpg",10000))oFS.frames.Add(New Frame("13.jpg",10000))oFS.frames.Add(New Frame("14.jpg",10000))oFS.frames.Add(New Frame("15.jpg",10000))oFS.frames.Add(New Frame("16.jpg",10000))oFS.frameEnd = oFS.frames.Length-1oFS.Position = New Vec2f( 200,100 )' ==========================================EndMethod OnRender( canvas:Canvas ) Overridecanvas.TextureFilteringEnabled=FalseApp.RequestRender()GameTime.ShowFPS(0, 0, canvas)Local delta:Float = GameTime.ProcessTime()While GameTime.LogicUpdateRequired()OnUpdateGameLogic(delta)EndLocal tween:Float = GameTime.GetTween()OnRenderGame(canvas)EndMethod OnUpdateGameLogic(_delta:Float)For Local oFS:FrameSet = Eachin frameSetsoFS.UpdateFrameTimer(_delta)If oFS.move2leftoFS.Position.x-=1If oFS.Position.x <= 50oFS.move2left = FalseoFS.move2right = TrueEndElseif oFS.move2rightoFS.Position.x+=1If oFS.Position.x >= 450oFS.move2left = TrueoFS.move2right = FalseEndEndNextEndMethod OnRenderGame(canvas:Canvas)For Local oFS:FrameSet = Eachin frameSetsoFS.Draw(canvas)NextEndEndClass 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(_delta:Float)If GameTime.newTime > timer + CurrentFrame().durationcurrFrameKey+=1If currFrameKey > frameEndcurrFrameKey = 0Endtimer = Millisecs()CurrentFrame().duration += 1*_deltaEndEndMethod 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 = GameTime.CalcFrameTime(_duration)img=Image.Load( "asset::"+_name)img.Handle=New Vec2f( .5,.5 )EndEnd ClassClass 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 / logicCyclesPerSecond' Print "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 CalcFrameTime:Float(ms:Int)Return ms / 1000.0 / (logicFPS / 1.0)EndMethod 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)EndEndEndFunction Main()New AppInstanceNew MyWindow()App.Run()EndAugust 24, 2016 at 12:26 pm #3402IMHO a game should run at 60 Hz or 30 Hz (SwapInterval=1 or SwapInterval=2).
If a game doesn’t run well it is typical to allow the user to downgrade visuals or resolution.
A lot of the code above seems to be based on the premise that it is ok to skip frames because it can be fixed with some kind of algorithm. I’m pretty sure it can’t.
August 24, 2016 at 12:45 pm #3404This is also very complicated code. For me anyway. I’m not sure this is the way to go. I just force 60 updates per sec and be done with it.
August 24, 2016 at 1:41 pm #340860, 30 I don’t ‘care’ what it is haha because I don’t know what i’m doing/must do at this most important thing :S
Are those facts true ?
– MX is running at unlimited random frames a second.
– I need to call every 60 screenframe OnUpdate()I can drop that FixedLogicFPS because I don’t know if its better than something like below.
I was hoping that that there was one ‘template’ script that covers it all, so every programmer can start program.
Monkey1234567891011121314151617181920212223242526272829303132333435#Import "<std>"#Import "<mojo>"Using std..Using mojo..Class MyWindow Extends WindowGlobal counter:IntGlobal timer:TimerMethod OnRender( canvas:Canvas ) OverrideApp.RequestRender()canvas.DrawText( "Hello World!",Width/2,Height/2,.5,.5 )canvas.DrawText( "Ticks : "+counter+" "+Millisecs(),Width/2,Height/2+50,.5,.5 )EndMethod New()timer=New Timer(60,OnUpdate) ' 60 ????EndMethod OnUpdate()Print "tock..." + countercounter=counter+1EndEndFunction Main()New AppInstanceNew MyWindowApp.Run()EndIf there was only one drawing/moving animation script that is working on the same speed on every mid-range desktop/ios/android.
By drawing I mean:
– animation multiple image frames, (can set the duration each frame in MS)By moving I mean:
– the frame animation moving from point A to B– And later in the future collision will be added.
August 24, 2016 at 7:49 pm #3424I would start with looking at the games included in the bananas folder of monkey2.
None use a timer and all expect OnRender to be called at 60hz as Window.SwapInterval defaults to 1 which means App.RequestRender causes subsequent OnRender to be correctly frame synced.
August 24, 2016 at 8:20 pm #3425What integers does SwapInterval support? If i’m not mistaken, it calls to SDL_GL_SetSwapInterval but the documentation on it says 0 for immediate and 1 for vsync. In Monkey2 however, if you put 2 I get 30fps, 20fps with 3, etc… What’s officially supported and will putting 3 for example, give the same fps across all supported platforms?
August 24, 2016 at 11:14 pm #3431Also, what about the new monitors that run at 120/144hz?
August 25, 2016 at 8:14 am #3439I would start with looking at the games included in the bananas folder of monkey2.
None use a timer and all expect OnRender to be called at 60hz as Window.SwapInterval defaults to 1 which means App.RequestRender causes subsequent OnRender to be correctly frame synced.
I will remove all the code, and see what happen.
I know about the bananas folder, I did see it, but I thought that maybe the creators din’t care about creating it.
But when I remove all the ‘timing’ code, I still need to use delta calculation or not ?
Is MX2 withSwapInterval=1 do all the things so I don’t need to care of delta anymore ?- Why not default SwapInterval=1 inside MX2 so beginners don’t have to know/ try to learn about those things.</span>
 
August 25, 2016 at 9:19 am #3441As peterigz says, given all the different hardware available I don’t think it’s as simple as “default SwapInterval to 1 and never have to do delta timing again”.
Looks like SwapInterval just sets SDL_GL_SetSwapInterval(), which when set to 1 means “updates synchronized with the vertical retrace” – i.e. it enables vsync, so updates are then linked to your monitors refresh rate.
Great if all monitors were 60hz. But monitors that runs at different frequencies will update a different number of times per seconds (e.g. 60hz, 75hz, 120hz, 144hz). So if you write fixed logic assuming 60hz and run it on a non-60hz monitor your game would run at a different speed
Plus there are plenty of examples out there of PCs/GPUs just not honouring vsync, which again would break your game.
I just don’t see how we can avoid delta timing – I see it as a fundamental part of ensuring your game runs properly on “every PC” and I’ve never seen anything magical that would take that burden away, and given the complexity of PCs, I doubt we ever will.
August 25, 2016 at 10:37 am #3444Maybe Mark will chime in.
I assumed mojo would force 60hz for full screen mode and that typical games would simply use native resolution fullscreen mode at 60hz.
I see that for casual /windowed games the desktop frequency is something you can’t control (or even query atm) so yes, a fixed timing strategy is not for everyone (just most of us).
August 25, 2016 at 10:51 am #3445ignore the fixed timing strategy
I was searching for the ‘best’ possible solution to make my app things running at the same speed on all ios/android/desktop (full screen/windowed).
In the weekend i’m going back to basic delta timing.
Maybe if I publish a game in the future, I will add something like this:
System requirements:
– Screen device must run at 60hz and the OS must have enabled vsync.Just to make sure I don’t get any/(less) sad/mad customers.
August 25, 2016 at 10:56 am #3446As I say, all SwapInterval does is call SDL_GL_SetSwapInterval(), which just enables vsync – it doesn’t force any particular frequency.
So just setting SwapInterval won’t do what you want, but yes if you explicitly set a 60hz (presumably fullscreen) mode then you’re probably good to go
Edit: that was in response to Simon
 - 
		AuthorPosts
 
You must be logged in to reply to this topic.


