abusive cpu usage ?

  • vinid3
  • Novice
  • Novice
  • vinid3
  • Posts: 17

Post 3+ Months Ago

hello!

Im having troube with a code that uses waays to much cpu usage, And I dont get it why...
this is the website: (its under construction)
http://www.vincentduprez.com/sandbox/dsc/
(I know I may not post urls.. but I can't figure out how to show it in another way)

As you can see, the cpu usage goes up as soon as you enter the website, and goes down once you leave it
the problem is probably in these lines: (as when I comment them, it doesn't takes that much cpu anymore..)
ACTIONSCRIPT Code: [ Select ]
this.onEnterFrame = function (){
   
   
   //variable flicker est une variable entre 0 et 100
   var flicker = Math.round(Math.random()*100);
 
   //flickering
   website.fond._alpha = 100-(flicker/12);
   
 
   //position souris:
   mouseXpos = _xmouse/Stage.width
   
   //mouvement pelicule
   pastpeliculex = pelicule._x;
   pelicule._x -= (pelicule._x-(0-(mouseXpos*(pelicule._width-Stage.width))))/15; //complex, avec ralentissement
   //pelicule._x = 0-(mouseXpos*(pelicule._width-Stage.width)); //simple sans ralentissement
   
   //mouvement backtitle
   backtitle._x -= (backtitle._x-(0-(mouseXpos*((backtitle._width-500)-Stage.width))))/15; //complex, avec ralentissement
   //pelicule._x = 0-(mouseXpos*(pelicule._width-Stage.width)); //simple sans ralentissement
   
   //mouvement de la plaque logo
   screenmovement = pelicule._x - pastpeliculex;
   this.website.logo.plaque._x = (0+ screenmovement)/4;
   this.website.logo.chainegauche._rotation = (0- screenmovement)/8;
   this.website.logo.chainedroite._rotation = (0- screenmovement)/8;
 
   
};
 
  1. this.onEnterFrame = function (){
  2.    
  3.    
  4.    //variable flicker est une variable entre 0 et 100
  5.    var flicker = Math.round(Math.random()*100);
  6.  
  7.    //flickering
  8.    website.fond._alpha = 100-(flicker/12);
  9.    
  10.  
  11.    //position souris:
  12.    mouseXpos = _xmouse/Stage.width
  13.    
  14.    //mouvement pelicule
  15.    pastpeliculex = pelicule._x;
  16.    pelicule._x -= (pelicule._x-(0-(mouseXpos*(pelicule._width-Stage.width))))/15; //complex, avec ralentissement
  17.    //pelicule._x = 0-(mouseXpos*(pelicule._width-Stage.width)); //simple sans ralentissement
  18.    
  19.    //mouvement backtitle
  20.    backtitle._x -= (backtitle._x-(0-(mouseXpos*((backtitle._width-500)-Stage.width))))/15; //complex, avec ralentissement
  21.    //pelicule._x = 0-(mouseXpos*(pelicule._width-Stage.width)); //simple sans ralentissement
  22.    
  23.    //mouvement de la plaque logo
  24.    screenmovement = pelicule._x - pastpeliculex;
  25.    this.website.logo.plaque._x = (0+ screenmovement)/4;
  26.    this.website.logo.chainegauche._rotation = (0- screenmovement)/8;
  27.    this.website.logo.chainedroite._rotation = (0- screenmovement)/8;
  28.  
  29.    
  30. };
  31.  


I can't see anything wrong.. It can't bee the Math can it? I mean, this code even pushes a macpro 16core to 100% cpu

Thanks in advance,
Vincent
Moderator Remark: fixed the link
  • graphixboy
  • Control + Z
  • Mastermind
  • User avatar
  • Posts: 1827
  • Loc: In the Great White North

Post 3+ Months Ago

I doubt its the math your using, but what's the frame rate and what are you trying to rotate? If you moving big images (lots of pixel data) that can kill the CPU pretty quickly. Also the Flash player on the mac is anything but efficient (probably the main reason steve jobs hates it) so you could be getting problems there too.

try dropping your frame rate down so the calculations happen less frequently and maybe consider using onMouseMove() instead of onEnterFrame() since that only runs when the mouse pointer changes position.
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

oh ye, flash generally is a CPU killer, not only on mac.
And that happens especially when you overload your frames with graphic processing.
From what i see in that site, you're continuously creating a flickering effect in the middle of the scene. I'd remove that, since i bet is very CPU consumer plus it tends to become annoying after a few seconds.
As for the moving of the slide, either use onMouseMove as graphixboy suggested, or keep the onEnterFrame and use a counter to delay the processing of the movement.
something like:
Code: [ Select ]
var counter = 0;
this.onEnterFrame = function (){
counter++; if (counter < 5) return;
counter = 0;
.... }
  1. var counter = 0;
  2. this.onEnterFrame = function (){
  3. counter++; if (counter < 5) return;
  4. counter = 0;
  5. .... }
  • vinid3
  • Novice
  • Novice
  • vinid3
  • Posts: 17

Post 3+ Months Ago

hey!

Thanks folks for your answers!
well, the onMouseMove instead of the onEnterFrame isn't a solution in this case, because soma actiions have to be finished even the mouse is stopped, the sliding mouvement of the filmstrip, the hanging logo, ... strangely enough, eventhough I removed a lot of graphical stuff and remoced the onenterframe completely, The resource stayed at a high level.. like 50% cpu I dont understand what's going on in the flash engine. Isn't there a ressource watcher for flashfiles? like for other languages' IDE's something that keeps track of cpu and memory consumption...

I don't really understand what you mean by delaying the process,w what purpose?

but thanks for your answers! Im still learning AS.

I haven't answered sooner because This project is extremely urgent. It was supposed to be finished last week, now this monday, the website should be online, in 3 languages (lol) So I didn't had the time to investigate this cpu issue.

another thing that annoys me is the poor flv playback on macs. sin't there a solution to make flv playback better? At the moment, I use the embedded player and load content in it using AS, on the pc version of flash, it workd more or less, but not on the mac version.. its not smooth at all
you can see it bly going on the 'dance show contest' tab on the left, the on clicking on the 'video' link. whatever video you choose.

thanks a million times

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 5 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.