Author Topic: 2.5 framerate troubles  (Read 3485 times)

spolvid

  • New Member
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
2.5 framerate troubles
« on: Sun, May 1, 2011 »
I just tried upgrading my project to 2.5, and the framerate is now substantially worse and jumpy. Has anyone else had this happen to them?

photonstorm

  • Administrator
  • Key Contributor
  • *****
  • Posts: 1502
  • Karma: +1/-0
    • View Profile
    • Photon Storm
Re: 2.5 framerate troubles
« Reply #1 on: Mon, May 2, 2011 »
Actually yes, I have too.

I have not had much time to investigate but perhaps together we can rule some things out?

Which Flex version are you compiling with? and which Flash Player version are you running in?

I have the "stuttering" problem with just one sprite on the screen. I used Monster Debugger to track it externally, and there is no frame rate drop that I can see, and memory use is fine, no gc kicking in. Which makes me think it's the way the internal timers are being calculated.
http://www.photonstorm.com



"Tell me and I will forget, show me and I might remember, involve me and I will understand" - Confucius

nineraser

  • Member
  • **
  • Posts: 13
  • Karma: +0/-0
    • View Profile
Re: 2.5 framerate troubles
« Reply #2 on: Mon, May 2, 2011 »
it happens to me too.

sdk 4.1 , flash player 10.2.159.1

photonstorm

  • Administrator
  • Key Contributor
  • *****
  • Posts: 1502
  • Karma: +1/-0
    • View Profile
    • Photon Storm
Re: 2.5 framerate troubles
« Reply #3 on: Mon, May 2, 2011 »
Could someone try rolling back to flex 4.0?

Also I think we ought to try earlier builds of 2.5, see if the change happened internally in the code base (which it must have, but at what point I really don't know)
http://www.photonstorm.com



"Tell me and I will forget, show me and I might remember, involve me and I will understand" - Confucius

geckojsc

  • New Member
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: 2.5 framerate troubles
« Reply #4 on: Mon, May 2, 2011 »
I was having this problem too. In FlashDevelop, I changed the [Debug] drop-down box to [Release], compiled the game again, and the frame rate was perfectly normal again.
No idea what the cause of the problem was, but that seems to do the trick.

Adam Atomic

  • Founder
  • Key Contributor
  • *****
  • Posts: 852
  • Karma: +0/-0
  • new dad
    • View Profile
    • Adam Atomic
Re: 2.5 framerate troubles
« Reply #5 on: Mon, May 2, 2011 »
the debugger overlay might be too CPU intensive - compiling in release mode with forceDebugger = false should prevent it from even being instantiated, which might bewhats going on...

geckojsc

  • New Member
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: 2.5 framerate troubles
« Reply #6 on: Mon, May 2, 2011 »
Possibly. The value of forceDebugger doesn't seem to make any difference for me, just having it in release mode fixes it.

photonstorm

  • Administrator
  • Key Contributor
  • *****
  • Posts: 1502
  • Karma: +1/-0
    • View Profile
    • Photon Storm
Re: 2.5 framerate troubles
« Reply #7 on: Mon, May 2, 2011 »
Release mode doesn't make any difference for this problem that I've seen. You should *always* compile in Release mode for the final version, as it makes your SWF smaller and a little faster as it chops out all the debug crap that exists in the Debug SWFs. I've tried it with the flixel debugger disabled as well, but I still don't think the problem is that.

I'll try some more experiments tonight to narrow it down, but it (visually) looks like a game timer problem to me.
http://www.photonstorm.com



"Tell me and I will forget, show me and I might remember, involve me and I will understand" - Confucius

spolvid

  • New Member
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: 2.5 framerate troubles
« Reply #8 on: Mon, May 2, 2011 »
Neither forceDebugger = false or Release mode seems to help. For what it's worth, I'm using Flex 4.1 and Flash Player Debugger 10.2.153.1. Until this is sorted out, I think I'm going back to 2.35...

photonstorm

  • Administrator
  • Key Contributor
  • *****
  • Posts: 1502
  • Karma: +1/-0
    • View Profile
    • Photon Storm
Re: 2.5 framerate troubles
« Reply #9 on: Mon, May 2, 2011 »
Try the 2.52 that Adam just pushed to dev. I tried it on a "problem" project of mine and it seemed to fix it. So am curious to know if it works for you too.
http://www.photonstorm.com



"Tell me and I will forget, show me and I might remember, involve me and I will understand" - Confucius

spolvid

  • New Member
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: 2.5 framerate troubles
« Reply #10 on: Mon, May 2, 2011 »
Nope, still jumpy.

photonstorm

  • Administrator
  • Key Contributor
  • *****
  • Posts: 1502
  • Karma: +1/-0
    • View Profile
    • Photon Storm
Re: 2.5 framerate troubles
« Reply #11 on: Wed, May 4, 2011 »
I've spent hours looking into this - and here is the conclusion I've come to.

2.43 used a simple ENTER FRAME event. Every time the event fired all of the physics were updated and the screen re-drawn. Providing your game never got complex enough to push the latency too high, you'd have a consistently smooth frame rate.

2.5 uses a delta timer. The delta timer only effects the "physics / motion" updates. The call to draw happens every event regardless. It basically uses an "elapsed" timer, which is the time it took to render the frame, and an accumulator. Every frame elapsed is added to the accumulator. If this is > the max Accumulator then it gets capped off at that. The maxA is 2000 / FLASH frame rate + 1. So for a flash frame rate of 30fps the maxA is 65. For a flash frame rate of 60fps the maxA is 32.

The math goes like this (ac = accumulator) :

1) ac = ac + elapsed
2) If ac > maxA then ac = maxA
3) Start of a while loop - while ac >= step then run step()
4) ac = ac - step
5) if ac is < step then end loop and draw

When step runs it updates all the positions of the objects.

The problem is the balance between the two frame rates.

If you set the game rate to 30 and the flash frame rate to 30 this is what happened for me:

Pass #1

elapsed is only 12, ac = 33 + 12 = 45
step runs
ac = 45 - 33 = 12, which is < step so loop ends and we draw

Pass #2

elapsed was 114, ac = 114 + 12 (left over from #1) = 126
this is > than maxA so ac = maxA (65)
step runs
ac = 65 - 33 = 32, which is < step, so loop ends and we draw

Pass #3

elapsed was 20, ac = 20 + 10 (left over from #2) = 30
30 is < than the step size (33) so the step never runs

This means that on the 4th pass none of the object motion was updated, so it has almost double the amount of movement to do before the draw, causing a brief "pause then jump" in the visuals


Attempt 2

Set the game rate to 60 and the flash FPS rate to 30 (this is the flixel default)

maxA is 65 again but this time the step value is only 16 (step is 1000 / game frame rate, so 1000 / 60 is 16)

Pass #1

elapsed was 11, ac = 16 + 11 = 27
step runs
ac = 27 - 16 = 11, so loop ends and draw happens

Pass #2

elapsed was 114, ac = 114 + 11 = 125
ac > maxA, so ac = maxA (65)
step runs - ac is now 49, still > step (16), so ...
step runs again - ac is now 33
step runs again - ac is now 17, which is STILL > step, so ...
step runs again - ac is now 1 and the loop ends, THEN draw happens

Attempt 3

Game timer was 30 but the flash timer was 60 and it got a bit nasty.

maxA is 33 and the step value is 33

Pass #1

elapsed was 12, ac = 33 + 12 = 45
ac > maxA, so ac = 33
step runs
ac = 33 - 33 = 0, loop ends, draw starts

Pass #2

elapsed was 20, ac = 0 + 20 = 20
ac is below the step size, so step never runs!

and this repeats, alternating - meaning that with this combination of frame rates flixel will skip every 2nd enter frame event (in terms of updating the object motion), and sometimes it even skipped 2 before it updated again, causing very erratic frame rates.

Solution?

Honestly I think the new delta timer is causing more problems than it tries to solve. To get around it I tried creating my own FlxGame onEnterFrame method which just called step and then draw every frame, regardless of the accumulator.

Performance was instantly better and less erratic, but still not quite as smooth as 2.43 for some reason. I suspect the answer to that part lies in the way objects are rendered / referenced.

Also I set the stage.quality to LOW for an extra boost of speed, and compiled in Release mode with the debugger disabled.
http://www.photonstorm.com



"Tell me and I will forget, show me and I might remember, involve me and I will understand" - Confucius

spolvid

  • New Member
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: 2.5 framerate troubles
« Reply #12 on: Wed, May 4, 2011 »
Sounds like it's not really worth upgrading to me. Hopefully this can be better by the next release. I'm nowhere near a competent programmer yet, so I'm not really comfortable messing around in the engine.

foosety

  • Member
  • **
  • Posts: 88
  • Karma: +0/-0
    • View Profile
Re: 2.5 framerate troubles
« Reply #13 on: Thu, May 12, 2011 »
This is a rather big setback for 2.5, after porting my project to 2.5 I think I will have to downgrade back to 2.43 just because the game isn't as smooth as it used to. Is Adam working on fixing this? Otherwise I am in the same boat as spolvid, not having the same expertise as Photonstorm.  :(

photonstorm

  • Administrator
  • Key Contributor
  • *****
  • Posts: 1502
  • Karma: +1/-0
    • View Profile
    • Photon Storm
Re: 2.5 framerate troubles
« Reply #14 on: Thu, May 12, 2011 »
I suspect it won't be fixed because every sample (that runs crap for me) that I send to Adam seems to run fine on his Mac! So it's like debugging a black hole.

One thing you can do is disable the delta timer and step/draw on every enter frame. This doesn't take much fiddling. Also setting stage quality to LOW can be done in your preloader for a free boost of speed.
http://www.photonstorm.com



"Tell me and I will forget, show me and I might remember, involve me and I will understand" - Confucius

goog

  • Member
  • **
  • Posts: 12
  • Karma: +0/-0
  • my blog: http://michaelcurtiss.blogspot.com/
    • View Profile
    • my blog
Re: 2.5 framerate troubles
« Reply #15 on: Thu, May 12, 2011 »
I suspect it won't be fixed because every sample (that runs crap for me) that I send to Adam seems to run fine on his Mac! So it's like debugging a black hole.


I wouldn't be surprised if it is somehow a mac/pc thing. I have the same version of windows installed on a mac and a pc - a little prototype that I am working on runs 60fps on the mac and can only get to 50 on the pc. And this is with a very small amount of operations taking place, so I am pretty confident it isn't a difference in hardware capabilities.

xyroclast

  • Contributor
  • ****
  • Posts: 389
  • Karma: +0/-0
    • View Profile
Re: 2.5 framerate troubles
« Reply #16 on: Thu, May 12, 2011 »
I found that, for me, it seems that, possibly, a lot of loops that used to be innocuous have now become very process-intensive in 2.5,
for example, a type of enemy that spawns a lot of copies and each one has a big routine.
As soon as I kill those enemies, the performance actually increases to much higher than it was in 2.43.
So, it seems like there's some kind of a double-edged sword going on here, and maybe things just need to be done in a very "2.5" way?

That's just my noob speculation, though :)

xyroclast

  • Contributor
  • ****
  • Posts: 389
  • Karma: +0/-0
    • View Profile
Re: 2.5 framerate troubles
« Reply #17 on: Thu, May 12, 2011 »
Actually, guys, I just tried my game, which was lagging painfully in flash debug on Google Chrome Mac, and found it blindingly fast,
and then tried it in Windows Chrome, and found it to still be blindingly fast.
It seems to be the exact issue I'd mentioned before regarding performance-related bugs only showing up in flash player,
and I think, really, this is starting to suggest that Flash Player itself is not good.

goshki

  • Active Member
  • ***
  • Posts: 172
  • Karma: +0/-0
    • View Profile
    • Vigeo Games
Re: 2.5 framerate troubles
« Reply #18 on: Thu, May 12, 2011 »
I suspect it won't be fixed because every sample (that runs crap for me) that I send to Adam seems to run fine on his Mac! So it's like debugging a black hole.

One thing you can do is disable the delta timer and step/draw on every enter frame. This doesn't take much fiddling. Also setting stage quality to LOW can be done in your preloader for a free boost of speed.

I run Flixel 2.53 on Windows 7 64-bit and on Ubuntu 9.10 32-bit. I could try to help with debugging those samples if you'd like.

foosety

  • Member
  • **
  • Posts: 88
  • Karma: +0/-0
    • View Profile
Re: 2.5 framerate troubles
« Reply #19 on: Fri, May 13, 2011 »
This may sound stupid but I found the solution (at least for my problem).

I changed the flash framerate to 60 and kept update to 60...
So this is what I have now:

super(360, 252, MenuState, 2 , 60, 60);