Situation:
I created an application that needs to draw simple rectangles (size 1x1 - 3x3), depending on some variables stored in an array of the corresponding size (size 900x900 - 300x300) with a frequency of 20, 40 or even 60 FPS.
Here is my drawing method:
protected void drawCurrentState()
{
for (int i=0; i<gameLogic.size; i++)
{
for (int j=0; j<gameLogic.size; j++)
{
if (gameLogic.previousStepTable == null || gameLogic.previousStepTable[i][j] != gameLogic.gameTable[i][j])
{
if (gameLogic.gameTable[i][j].state)
graphicsContext.setFill(gameLogic.gameTable[i][j].color);
else
graphicsContext.setFill(Color.WHITE);
graphicsContext.fillRect(leftMargin + (j * (cellSize + cellMargin)),
topMargin + (i * (cellSize + cellMargin)), cellSize, cellSize);
}
}
}
}
As you probably noticed, the drawing is executed only when it is needed (when the state has changed from the previous step). All other operations (states of variable calculations in gameLogic, etc.) are practically timeless and do not affect performance.
Problem:
JavaFX performs this operation incredibly slowly! 10 iterations (which should be drawn for 0.5 s at a speed of 20FPS) are pulled out after 5-10 seconds, which is obviously unacceptable in this case.
Question:
(, 40 60 )?
?