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 & HelpSyntax Questions › is this comletely crazy way of doing OOP?
Page Index Toggle Pages: 1
is this comletely crazy way of doing OOP??? (Read 398 times)
is this comletely crazy way of doing OOP???
Jul 21st, 2006, 7:22pm
 
disclaimer: - i'm fairly new to processing, especially OOP in processing -
so i have a simple sketch that when run for 10 minutes or more runs my CPU Usage in windows task manager up to the high 90's - 100%

if i stop drawing in this app window after its reached that high, it still hangs there until i shut the app down.

so my question is... would someone who is a bit more experienced be willing to look at this code real quick and tell me where all my memory is being lost?  it seems running a max of 200 iterations per frame should not be too much?? or am i crazy?

anyway, any pointers one of the more experienced lads could  give me would be HIGHLY appreciated...

cheers!

Quote:


import processing.opengl.*;
Boid[] aBoids;

 int nActiveBoids = 10;
 int nTotalBoids = 200;
 int index =0;
 float penPressure, penAng;

 float angDiff;
 color boidColor;

void setup() {
 size(800,600, OPENGL);
 try {
   jtablet = new JTablet();
 } catch (JTabletException jte) {
   println("Could not load JTablet! (" + jte.toString() + ").");
 }
 smooth();
 background (0);
 smooth();
 noCursor();
 ellipseMode(CENTER);
 framerate (120);

 aBoids = new Boid[nTotalBoids];
 for (int i=0; i<nTotalBoids; i++){
  aBoids[i] = new Boid(100+i,100+i,i+1);
 }
PFont font;
font = loadFont ("cn.vlw");
textFont (font, 12);
}

void draw() {
//if (frameCount % 200==0){System.gc();}
//background (0);

 if (mousePressed) {
   penPressure = 0.9; //these will be variable later
   penAng = 5.3;
   for (int i=index; i<index+nActiveBoids; i++){
     aBoids[i].update(penPressure,penAng,i+1);
     aBoids[i].render();
   }
 }
 //update inactive boids here
 for (int j=0; j<index; j++){
  aBoids[j].updateINACTIVE();
  aBoids[j].render();
 }
}

void mouseReleased(){
 println ("arse" + index);
 if (index+nActiveBoids >= nTotalBoids){ index=0;}else{index +=nActiveBoids;}
}

and here's the class:
Quote:


class Boid{
 float x,y;
 int id;
 int aBoidRad = 45;
 int boidSize = 8;
 float angDiff = 0.2;
 color c;
 int s;
 boolean active;
 Boid (int X,int Y,int boidIndex){
   x=X; y=Y; id=boidIndex; active=true;    
 }
 
 void update(float pressure, float ang,int activeID){
     c = color(255,255,255);
     x = round((pressure*aBoidRad)*(sin(ang+angDiff*activeID)))+mouseX;
     y = round((pressure*aBoidRad)*(cos(ang+angDiff*activeID)))+mouseY;
     s = activeID;
 }
 
 void updateINACTIVE(){
  c = color (255,55,55);
 }
 
 void render(){
   fill (c);
   noStroke();
   ellipse (x, y, boidSize, boidSize);
   text (s, x,y-2);
 }
}
Re: is this comletely crazy way of doing OOP???
Reply #1 - Jul 22nd, 2006, 12:40am
 
Looks fine to me.

The openGL drawing (or any frame-iterative drawing for that matter) is CPU intensive and will eat up 100% CPU in general. This is pretty normal.

Anyone back me up on this?
Page Index Toggle Pages: 1