Quantcast
Channel: Android Mode - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 941

Any idea why recent Android Mode versions are slower than older ones?

$
0
0

I did a basic test to compare the versions for which PApplet extends Fragment against versions for which PApplet extends Activity. in terms of frame rates.

My test consisted of displaying lots of ellipses, with background() being called at each frame.

http://imgur.com/a/e2Bvx

As seen in the above pictures, the older version (Release 0239) had as much as 72% more frames than the newer one (Release 0249) for a dot count of 500.

I used the following code:

ArrayList<Dot> dots = new ArrayList<Dot>();

@ Override
public void settings() {
    //Call size/fullscreen from here
    fullScreen(PConstants.P3D);
}

@ Override
public void setup() {
    textSize(displayWidth/20);
}

@ Override
public void draw() {
    background(0);
    for (Dot dot : dots){
        dot.move();
        dot.display();
    }
    noStroke();
    fill(150,0,0);
    rect(0,0,displayWidth, displayHeight/10);
    fill(255);
    text("Release 0249: #dots: " + dots.size() + ", frameRate: " + (int)(frameRate), 0, displayHeight/20);
}

@ Override
public void mouseDragged(){
    dots.add(new Dot());
}

@ Override
public void mousePressed(){
    if (mouseY <= displayHeight/10){
        dots.clear();
    }else{
        dots.add(new Dot(true));
    }
}

class Dot {
    float x, y;
    float speedX, speedY;
    int r = MainActivity.randInt(0 , 255);
    int g = MainActivity.randInt(0 , 255);
    int b = MainActivity.randInt(0 , 255);

    Dot(){
        x = mouseX;
        y = mouseY;
        speedX = (mouseX - pmouseX)/5;
        speedY = (mouseY - pmouseY)/5;
    }

    Dot(boolean mousePressed){
        x = mouseX;
        y = mouseY;
    }

    void display(){
        fill(r,g,b);
        ellipse(x, y, displayWidth/30, displayWidth/30);
    }

    void move(){
        accelerate();
        checkBounds();
        x += speedX;
        y += speedY;
    }

    void checkBounds(){
        if (x <= 0){
            speedX *= -1;
            x = 0;
        }else if (x >= displayWidth){
            speedX *= -1;
            x = displayWidth;
        }
        if (y <= 0){
            speedY *= -1;
            y = 0;
        }else if (y >= displayHeight){
            speedY *= -1;
            y = displayHeight;
        }
    }

    void accelerate(){
        speedX += MainActivity.randInt(-displayWidth/800, displayWidth/800);
        speedY += MainActivity.randInt(-displayWidth/800, displayWidth/800);
    }
}

Hopefully the code is formatted well...

Press or drag to create dots. Touch red area to reset. Read red area info to draw conclusions. The same code was used for both versions apart from sketchRenderer() instead of settings() - shouldn't make a difference.

The test above uses dots. But it would be great to test other stuff, like images, lines, pshapes etc. and under different cases (different renderers etc.) It would be great if you could emulate the test and confirm if you reach the same conclusion. Different releases are here:

https://github.com/processing/processing-android/releases

So, assuming my results are correct, my main question is: why are newer releases slower than older ones? Is this related to the fact that older ones extend Activity and newer ones extend Fragment?

Any thoughts appreciated.


Viewing all articles
Browse latest Browse all 941

Trending Articles