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);
}
}