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 & HelpIntegration › java: other classes
Page Index Toggle Pages: 1
java: other classes (Read 454 times)
java: other classes
Jul 24th, 2008, 10:02pm
 
Hey,

I am experiencing growing pains with my project, in particular wanting to push all my inner classes into their own files.  This would be no problem except for all the PApplet methods like fill() that I call, which would require that each of my classes with a display() method would need to receive my PApplet (ie "this") as an argument:

before:
void display() {
  rect(0,0,20,20);
}

after:
void display(PApplet p) {
  p.rect(0,0,20,20);
}

I wouldn't mind making this sort of change, but I was a little afraid of performance hits. I know p is just a little int-sized pointer of course, but I was afraid that the setting of this arg at bytecode level at every display call might cause some slowdown.  Anyone have any experienced advice on this?
Re: java: other classes
Reply #1 - Jul 24th, 2008, 10:31pm
 
Why not just pass the PApplet object to the constructor of your classes? Thus it will be a member like the others, with same performance.
Re: java: other classes
Reply #2 - Jul 24th, 2008, 11:17pm
 
yes, I considered this, too.  And, I suppose I shouldn't be too worried about the extra pointer memory for each instance of something I draw; I'm sure it wouldn't be too much.

After some thought, I think for now I will just keep everything as inner classes to my PApplet subclass.  Even though this means one big hefty file, I just don't feel like using "p.***" for every PApplet method because of calls throughout my code to sin, cos, map, etc that must be preceded by the class name and some static final config variables that multiple classes depend on that I am too lazy to deal with.

Anyway, it should be easy to change between the two choices if I need to.
Page Index Toggle Pages: 1