Jump to content
Search Community

Frame throttling support?

Rabies test
Moderator Tag

Recommended Posts

Mr Sock,

Have you considered implementing support for frame throttling? I'm working on an Adobe AIR project and the CPU resources it uses is horrible (50 to 60% of the CPU for an app that's running at 40 fps!)

 

Adobe suggest frame throttling when the app is not active. Since frame rate is mostly for motion, what you do is set the frame rate low when the "movie" is not doing much, and then put it back up when you need smooth motion:

 

http://www.adobe.com/devnet/air/flex/ar ... tling.html

 

Since animation in my projects rely almost entirely on your Tween package, it should be fairly easily to implement a frame throttling solution directly into the tween package, however I don't know enough about modifying classes, etc to do so.

 

The way I envision this feature working in your package would be:

1. Make it a plugin that you activate.

2. In the flash movie, I would set the frame rate low, let's say 4fps.

2. You add a property to set the frame rate. So for example when I tween it would look like this:

 

TweenLite.to(mc, 0.3, {scaleX:1, scaleY:1, framerate:40, ease:Expo.easeOut});

 

What would then happen is

A. your script would first fetch and store the current framerate via stage.frameRate

B. set the framerate to 40 at the start of the tween.

C. On completion of the tween you set it back to the stored value.

 

Complications: You'd have to also track if multiple tweens are going, so they don't over-write each other. I suppose ideally instead of a property/parameter in the actual Tweening script line, perhaps a global variable of some sort could be set so the Tween package knows what to consistently use when tweening, and this way there's no chance of different framerate values competing. I also realize such a feature would not be compatible with AS2 or old versions of Flash (prior to 9 I think?)

 

I haven't outlined the ideal solution here, but it's something to think about that I am sure you could perfect. Let me know if you add this! In the mean time I have to implement my own solution.

RB

Link to comment
Share on other sites

First of all, I highly doubt that allowing the frame rate to stay at 40fps while there are no tweens happening is causing any significant CPU drain whatsoever unless you have a bunch of other scripts/calculations running unrelated to the tweening engine. Seriously, even 1% would shock me. It consumes VERY little. The thing that typically dwarfs ActionScript execution by comparison is graphics rendering. The ratio is literally more than 100:1 in most situations. Not even close. So if your app is using 50-60% of the CPU when there are no tweens happening, you must have something else significant going on.

 

Baking frame rate throttling into the core engine could get rather cumbersome because:

 

1) What about scenarios where there are multiple tweens with various start times that partially overlap, like if we start out at 2fps and tween1 takes the frameRate to 40fps and halfway through that tween, tween2 begins which sets the frame rate to 30fps and records the fps at the beginning (in this case it will record 40fps). Then tween1 finishes and sets it back down to 2fps...but wait, tween2 is still running! When tween2 finishes, it sets it back to what it was when it began which in this case was 40fps! The point is that it can get tricky unless there was just a generic "whenever any tweens are happening ALWAYS use ___ frame rate, otherwise set it back down to ___fps." but then you could run into issues with some other interactivity like the SCROLL_WHEEL thing they mention in the article you linked to.

 

2) It would require extra logic to run on every frame ("are we done with all the tweens yet?" and "were we idle and just started some new tweens?") which would exact a performance penalty across the board. Everyone pays a price for this feature even though most people probably won't use it.

 

3) It'd bloat the core TweenLite engine in terms of kb and I work VERY hard to protect that.

 

You could already accomplish something like this, though, by simply tucking your tweens into a TimelineLite that has an onStart and an onComplete that call methods that do the throttling for you. See what I mean? http://www.greensock.com/timelinelite/

Link to comment
Share on other sites

I understand, no problem.

 

Regarding CPU usage, I do have a z-sorting function running on enterframe. It's the only thing I imagine is keeping the CPU use up, however Adobe AIR apps *are* notorious CPU resource hogs. It's just how it is. I'm also using MovieClips (I'm new to AS3, so I'm doing things in a way I was used to in AS2, until I learn more).

 

I could perhaps make sure the z-sorting only runs when my 3D cube is rotating. This is the sort code, in case you were curious:

 

mcCube.addEventListener(Event.ENTER_FRAME, cubeRender);
function cubeRender(event:Event):void {
// z-sorting credit goes to http://theflashblog.com/?p=470
// accelerate the rotation
stepX = 0;// no default motion
//stepX = (mouseY-stage.stageHeight/2)/(stage.stageHeight/2)*-thrust;

if (stepRemX < stepX) {
	stepRemX += accelerate;
} else if (stepRemX > stepX) {
	stepRemX -= accelerate;
}
stepY=0; // temp stopper
//stepY = (mouseX-stage.stageWidth/2)/(stage.stageWidth/2)*thrust;

if (stepRemY < stepY) {
	stepRemY += accelerate;
} else if (stepRemY > stepY) {
	stepRemY -= accelerate;
}
// simply rotate the whole mcCube holder
mcCube.rotationX += stepRemX;
mcCube.rotationY += stepRemY;
for (c = 0; c < 6; c++) {
	// get a reference to all 6 mcCube sides
	mcCubeSide=MovieClip(mcCube.getChildAt(c));
	//This transformed matrix contains the actual transformed Z position.
	transformedMatrix = mcCubeSide.transform.getRelativeMatrix3D(this);
	//store this mcCubeSideMC and its 'z' position in the sortArray.
	sortArray[c].MCobject=mcCubeSide;
	sortArray[c].screenZ = transformedMatrix.position.z;
}
// sorting
sortArray.sortOn("screenZ", Array.NUMERIC | Array.DESCENDING);
for (c = 0; c < 6; c++) {
	// set the 3 sides in the back to visible = false and render the 3 in the front according to their Z Sorted value.
	if (c<3) {
		//sortArray[c].MCobject.visible=false;
	} else {
		mcCube.setChildIndex(sortArray[c].MCobject, c);
		sortArray[c].MCobject.visible=true;
	}
}
}

Link to comment
Share on other sites

I just took the entire enter_frame function out and re-published. THe app still uses up to 60% cpu resources. Adobe AIR is just a resource hog.

That's INSANE! Seriously? There's nothing else going on in the app? And if you drop the frame rate, does it change the CPU usage drastically? If so, I'd recommend hammering Adobe's tech team to make them fix that because it is absolutely inexcusable. Feel free to post a simple FLA that demonstrates the issue (if you can) so that we can publish on our end and see the problem reproduced.

Link to comment
Share on other sites

Yes, lowering frame rate reduces the CPU usage. For example, a FPS of around 20 will knock down the CPU consumption to the 20-30% range. I'll post some sample files when I get to the optimization stage. (Adobe *is* aware of the issue, as you see the URL I posted in the first post is on their site. ;-) )

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...