PShape() - significant performance issues
in
Core Library Questions
•
7 months ago
I've implemented a class called drums, which receives an array of values (via OSC) from Max. The values are extracted and used to resize one of 8 corresponding ellipses a few times a second.
When drawing the shapes via the standard ellispe(x,y,x1,y1); method, frame rate performance is pretty stable and more or less acceptable (occasional spikes down, but they're not significant). When implementing the PShape() method and drawing the shapes with shape(); performance takes a massive hit. I've benchmarked the phenomenon using a 5 minute benchmark in FRAPS. The graph is attached below.
When drawing the shapes via the standard ellispe(x,y,x1,y1); method, frame rate performance is pretty stable and more or less acceptable (occasional spikes down, but they're not significant). When implementing the PShape() method and drawing the shapes with shape(); performance takes a massive hit. I've benchmarked the phenomenon using a 5 minute benchmark in FRAPS. The graph is attached below.
Is this a known issue with PShape() or am I implementing it wrong? The code in its entirety is below. The PShape code is commented out and the standard code is working.
- public class Drums{
- int[] array = new int[8];
- boolean running = false;
- PShape kick;
- float kickx = 60;
- float kicky = 60;
- PShape snare;
- float snarex = 60;
- float snarey = 60;
- PShape oHat;
- float oHatx = 60;
- float oHaty = 60;
- PShape cHat;
- float cHatx = 60;
- float cHaty = 60;
- PShape clap;
- float clapx = 60;
- float clapy = 60;
- PShape rim;
- float rimx = 60;
- float rimy = 60;
- PShape cow;
- float cowx = 60;
- float cowy = 60;
- PShape shake;
- float shakex = 60;
- float shakey = 60;
- float centerx = width/2;
- float centery = height/2;
- public void run(){
- if(running){
- display();
- shrink();
- }
- }
- public void display(){
- stroke(255);
- fill(255,255,255);
- /*
- kick = createShape(ELLIPSE, centerx, centery, kickx, kicky);
- snare = createShape(ELLIPSE, centerx-200, centery, snarex, snarey);
- oHat = createShape(ELLIPSE, centerx+200, centery, oHatx, oHaty);
- cHat = createShape(ELLIPSE, centerx+200, centery, cHatx, cHaty);
- clap = createShape(ELLIPSE, centerx, centery+200, clapx, clapy);
- rim = createShape(ELLIPSE, centerx+200, centery-200, rimx, rimy);
- cow = createShape(ELLIPSE, centerx+200, centery+200, cowx, cowy);
- shake = createShape(ELLIPSE, centerx-200, centery-200, shakex, shakey);
- shape(kick);
- shape(snare);
- shape(oHat);
- shape(cHat);
- shape(clap);
- shape(rim);
- shape(cow);
- shape(shake);
- */
- ellipse(centerx, centery, kickx, kicky);
- ellipse(centerx-200, centery, snarex, snarey);
- ellipse(centerx+200, centery, oHatx, oHaty);
- ellipse(centerx+200, centery, cHatx, cHaty);
- ellipse(centerx, centery+200, clapx, clapy);
- ellipse(centerx+200, centery-200, rimx, rimy);
- ellipse(centerx+200, centery+200, cowx, cowy);
- ellipse(centerx-200, centery-200, shakex, shakey);
- }
- public void shrink(){
- if (kickx <= height/2 && kicky <= height/2 && kickx > 0 && kicky > 0){
- kickx -= height/100;
- kicky -= height/100;
- }
- if (snarex <= 100 && snarey <= 100 && snarex > 0 && snarey > 0){
- snarex -= 2;
- snarey -= 2;
- }
- if (cHatx <= 100 && cHaty <= 100 && cHatx > 0 && cHaty > 0){
- cHatx -= 2;
- cHaty -= 2;
- }
- if (oHatx <= 100 && oHaty <= 100 && oHatx > 0 && oHaty > 0){
- oHatx -= 2;
- oHaty -= 2;
- }
- if (clapx <= 100 && clapy <= 100 && clapx > 0 && clapy > 0){
- clapx -= 2;
- clapy -= 2;
- }
- if (rimx <= 100 && rimy <= 100 && rimx > 0 && rimy > 0){
- rimx -= 2;
- rimy -= 2;
- }
- if (cowx <= 100 && cowy <= 100 && cowx > 0 && cowy > 0){
- cowx -= 2;
- cowy -= 2;
- }
- if (shakex <= 100 && shakey <= 100 && shakex > 0 && shakey > 0){
- shakex -= 2;
- shakey -= 2;
- }
- }
- public void running(int[] _array){
- array = _array;
- running = true;
- if(array[0] == 1){
- kickx = height/2;
- kicky = height/2;
- }
- if(array[1] == 1){
- snarex = 100;
- snarey = 100;
- }
- if(array[2] == 1){
- cHatx = 100;
- cHaty = 100;
- }
- if(array[3] == 1){
- oHatx = 100;
- oHaty = 100;
- }
- if(array[4] == 1){
- clapx = 100;
- clapy = 100;
- }
- if(array[5] == 1){
- rimx = 100;
- rimy = 100;
- }
- if(array[6] == 1){
- cowx = 100;
- cowy = 100;
- }
- if(array[7] == 1){
- shakex = 100;
- shakey = 100;
- }
- }
1