We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, The question is a bit hard to formulate, but here is my problem: I am doing a cell-based simulation and want to display the states of the so-called cells on a grid using color codes. In Java mode, it's quite fast and I have used the architecture below:
in setup(): create the cells (an Arraylist of cells), start a thread("computation"), and call noLoop();
in the method computation(): update the state values of all cells, and, at the end, call redraw();
in draw(): a "for" loop in which I call the draw() for each cell.
It did not bother me and basically I was happy that the simulation time was faster than the real time.
I tried to port it to Android (I am testing it on a Galaxy S5), and now it is much slower. I guess it is because of the for loop in the draw(), so I tried:
putting this "for" loop in another thread(), but then everything bugs
putting this "for" loop in a class inheriting AsyncTask: it works but the display is messed up.
I guess i need to put some "synchronize" here and there, but I am always confused on how to do that.
Any help?
Thanks.
Answers
You can't draw to the canvas in another thread. I don't know anything about Android mode but I guess this is similar to java mode. There are two options:
or
In the other threads, render to a PGraphics instead of the default PApplet PGraphics then at the end put everything together. Pseudocode:
Then in the main draw loop use image:
image(p, 0, 0);