We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Poor performace when rewritten into a class.
Page Index Toggle Pages: 1
Poor performace when rewritten into a class. (Read 394 times)
Poor performace when rewritten into a class.
Jan 8th, 2008, 1:02pm
 
I'm having some troubles with something that works as a standalone program but when put inside a class it slows down incredibly, obviously there's something wrong with the code, something that probably repeates into infinity... but I can't find it.

/**
 * Seaweed object
 *
 */  
public class weed{
 //vars
 float inc = 0.0;
 int x, vUnits;
 float angle;
 int hSize, vSize;

 /**
   * CONSTRUCTOR
   * Draws at the bottom of the screen,
   * iX, horistontal position of the object.
   * ivUnits = number of units inside each object, the more units the higher the object.
   * ihSize, horisontal size of the drawing screen.
   * ivSize, vertical size of the drawing screen.
   */
 weed(int iX, int ivUnits, int ihSize, int ivSize){
   x = iX;
   vUnits = ivUnits;
   hSize = ihSize;
   vSize = ivSize;    
 }
 
 /**
   * Update/draw method.
   */
 void update(){
   stroke(0xCC99FF66);
   smooth();    
   
   inc += 0.01;
   float angle = sin(inc)/10.0 + sin(inc*1.2)/20.0;    
   pushMatrix();
   translate(x, vSize);    
   for(int i = vUnits; i > 0; i--){    
     strokeWeight(i);
     line(0, 0, 0, -8);
     translate(0, -8);
     rotate(angle);
   }
   popMatrix();
 }
}
Re: Poor performace when rewritten into a class.
Reply #1 - Jan 8th, 2008, 7:59pm
 
can you post all of your sketch? how many weeds are you drawing?

this runs smooth on my MacBook Pro at 60fps:

Quote:


import processing.opengl.*;

ArrayList weeds = new ArrayList();
PFont font;

void setup() {
 size(1000,200, OPENGL);
 frameRate(999);
 font = createFont("Courier", 12);
 textFont(font);
 //strokeJoin(MITER);
 for (int i=0; i<250; i++) {
   weeds.add(new weed((int)random(width), (int)random(2,20), width, height));
 }
 smooth();
}

void draw() {
 background(0);
 for (int i=0; i<weeds.size();i++) {
   ((weed)weeds.get(i)).update();
 }

 fill(255);
 text("fps: " + frameRate, 10,10);

}

/**
* Seaweed object
*  
*/
public class weed{
 //vars
 float inc = random(5.0);
 int x, vUnits;
 float angle;
 int hSize, vSize;

 /**
  * CONSTRUCTOR
  * Draws at the bottom of the screen,  
  * iX, horistontal position of the object.
  * ivUnits = number of units inside each object, the more units the higher the object.
  * ihSize, horisontal size of the drawing screen.
  * ivSize, vertical size of the drawing screen.
  */
 weed(int iX, int ivUnits, int ihSize, int ivSize){
   x = iX;
   vUnits = ivUnits;
   hSize = ihSize;
   vSize = ivSize;    
 }

 /**
  * Update/draw method.
  */
 void update(){
   stroke(0xCC99FF66);
   //stroke(10,200,100);

   inc += 0.02;
   float angle = sin(inc)/10.0 + sin(inc*1.2)/20.0;    
   pushMatrix();
   translate(x, vSize);    
   for(int i = vUnits; i > 0; i--){    
     strokeWeight(i/2.5);
     line(0, 0, 0, -12);
     translate(0, -8);
     rotate(angle);
   }
   popMatrix();
 }
}


Re: Poor performace when rewritten into a class.
Reply #2 - Jan 9th, 2008, 9:59am
 
I think I found the issue, might have had to do with a new background image that was missbehaving.

Thanks for the help though, reminded me how to write a few things better. =)
Page Index Toggle Pages: 1