We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I have roughly 54 objects that have a function to draw rect() in draw(). So I have loop from 0 to 54 that do calculation to call the object function to draw rectangle for every frame. This caused the frameRate for this sketch dropped to 5.
Is there anyway so that I can update 54 objects or more that draw itself without reducing frameRate. I have been thinking to use multithreading but it always return null pointer exception in rect() and then the sketch runs but behaves very weird. What to do?
Answers
There might be a way to optimize performance, 54 rectangles should really not have a great impact. But without seeing your code, that's just a guess.
Can you post some code? It's a bit hard to tell why it's so slow.
Drawing 54 rectangles should not reduce the framerate, certainly not to 5fps. There is probably something wrong with your code, I suggest you post it here.
It is most unlikely this would help because the 'drawing' has to be done in the main event thread. That might explain why you are getting NPEs
https://github.com/NoTalentGeek/JavaProcessingMuseumSimulator/blob/master/JavaProcessingMuseumSimulator.pde
Here around line 141.
https://github.com/NoTalentGeek/JavaProcessingMuseumSimulator/blob/master/ObjectMuseum.pde
Here around line 256.
An example using Processing 3's "only" new feature: FXD2 renderer.
Plus Comparable + sort() in order to achieve high performance: :ar!
https://forum.Processing.org/two/discussion/comment/52645/#Comment_52645
I think the biggest problem, that you do not only draw your MuseumObjects. You create new instances of Panel every frame. you should only create the panel once and store it. Then update it, if it changes. But keep the drawing seperate from this.
Another problem is, that you create fonts all the time in Panel.drawVoid(). You could do that once in the constructor instead.
With some minor changes, your program runs with 60fps.
this
Well isn't that the most OCD formatted code I've ever seen! :O)