optimalised canvas repaint

This commit is contained in:
musilto9 2020-06-09 15:46:36 +02:00
parent 79c65a1f3c
commit 05477a578c
4 changed files with 42 additions and 22 deletions

View File

@ -44,5 +44,11 @@
<version>2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -205,9 +205,11 @@ public class InteractionCell extends Cell {
}
}
else {
if (!message.contains("cutscene")){
dialog.skipShowText();
}
}
}
public void endEvent() {
if (dialog != null) {

View File

@ -198,7 +198,7 @@ public class WindowOfFreeMove extends JLayeredPane {
mapManager.createMap();
isReadyToPaint = true;
Timer timer = new Timer(10, actionEvent -> {
Timer timer = new Timer(20, actionEvent -> {
mapManager.getActualMap().getPerson().move();
camera.moveCamera();
canvas.repaint();
@ -240,37 +240,49 @@ public class WindowOfFreeMove extends JLayeredPane {
mapManager.getActualMap().getImageCell().paintBackground(g2D, j, i);
}
for (Cell cell : mapManager.getActualMap().getMoveToCells()) {
if (cell.getY() == i) cell.paint(g2D);
if (cell.getY() == i && isinView(cell)) cell.paint(g2D);
}
for (Block cell : mapManager.getActualMap().getBlocks()) {
if (cell.getY() == i && !cell.isPartial()) cell.paint(g2D);
if (cell.getY() == i && !cell.isPartial() && isinView(cell)) cell.paint(g2D);
}
if (mapManager.getActualMap().getPerson().getY() == i && mapManager.getActualMap().getPerson().getDirectionMoveLast() != KEY_UP) mapManager.getActualMap().getPerson().paint(g2D);
for (Cell cell : mapManager.getActualMap().getInteractionEventCells()) {
if (cell.getY() == i) cell.paint(g2D);
if (cell.getY() == i && isinView(cell)) cell.paint(g2D);
}
for (ChestCell cell : mapManager.getActualMap().getChestCells()) {
if (cell.getY() == i && cell.getPaint()) cell.paint(g2D);
if (cell.getY() == i && cell.getPaint() && isinView(cell)) cell.paint(g2D);
}
if (mapManager.getActualMap().getPerson().getY() == (i-1) && mapManager.getActualMap().getPerson().getDirectionMoveLast() == KEY_UP) mapManager.getActualMap().getPerson().paint(g2D);
for (Block cell : mapManager.getActualMap().getBlocks()) {
if (cell.getY() == i && cell.isPartial()) cell.paint(g2D);
if (cell.getY() == i && cell.isPartial() && isinView(cell)) cell.paint(g2D);
}
for (DoorCell cell : mapManager.getActualMap().getDoorCells()) {
if (cell.getY() == i) cell.paint(g2D);
if (cell.getY() == i && isinView(cell)) cell.paint(g2D);
}
for (Person person : mapManager.getActualMap().getNpcs()) {
if (person.getY() == i) person.paint(g2D);
if (person.getY() == i && isinView(person)) person.paint(g2D);
}
for (int j = 0; j < mapManager.getActualMap().getCanvasSize()[0]; j++) {
mapManager.getActualMap().getImageCell().paintForeground(g2D, j, i);
if (isinView(j, i)) mapManager.getActualMap().getImageCell().paintForeground(g2D, j, i);
}
for (ChestCell cell : mapManager.getActualMap().getChestCells()) {
if (cell.getY() == i && cell.getShowItem()) cell.paint(g2D);
if (cell.getY() == i && cell.getShowItem() && isinView(cell)) cell.paint(g2D);
}
}
}
}
private boolean isinView(Cell cell) {
Boolean xValue = (CELL_SIZE * (cell.getX()+1) > -canvas.getLocation().x) && (CELL_SIZE * (cell.getX()-1) < (-canvas.getLocation().x + CELL_SIZE * WINDOW_WIDTH));
Boolean yValue = (CELL_SIZE * (cell.getY()+1) > -canvas.getLocation().y) && (CELL_SIZE * (cell.getY()-1) < (-canvas.getLocation().y + CELL_SIZE * WINDOW_HEIGHT));
return xValue && yValue;
}
private boolean isinView(int x, int y) {
Boolean xValue = (CELL_SIZE * (x+1) > -canvas.getLocation().x) && (CELL_SIZE * (x-1) < (-canvas.getLocation().x + CELL_SIZE * WINDOW_WIDTH));
Boolean yValue = (CELL_SIZE * (y+1) > -canvas.getLocation().y) && (CELL_SIZE * (y-1) < (-canvas.getLocation().y + CELL_SIZE * WINDOW_HEIGHT));
return xValue && yValue;
}
}
public class Foreground extends JPanel {

View File

@ -14,12 +14,12 @@
<trigger>
<x>6</x>
<y>4</y>
<active>true</active>
<active>false</active>
</trigger>
<trigger>
<x>14</x>
<y>16</y>
<active>false</active>
<active>true</active>
</trigger>
<chest>
<x>1</x>
@ -52,14 +52,14 @@
<door>
<x>16</x>
<y>10</y>
<locked>false</locked>
<locked>true</locked>
<open>false</open>
</dooŕ>
<door>
<x>8</x>
<y>13</y>
<locked>false</locked>
<open>true</open>
<open>false</open>
</dooŕ>
</events>
</map>
@ -74,7 +74,7 @@
<chest>
<x>1</x>
<y>9</y>
<active>false</active>
<active>true</active>
</chest>
<door>
<x>12</x>
@ -104,13 +104,13 @@
<x>4</x>
<y>1</y>
<locked>false</locked>
<open>false</open>
<open>true</open>
</dooŕ>
<door>
<x>2</x>
<y>12</y>
<locked>false</locked>
<open>false</open>
<open>true</open>
</dooŕ>
<door>
<x>17</x>
@ -126,13 +126,13 @@
<trigger>
<x>4</x>
<y>18</y>
<active>true</active>
<active>false</active>
</trigger>
<door>
<x>4</x>
<y>19</y>
<locked>false</locked>
<open>false</open>
<open>true</open>
</dooŕ>
</events>
</map>
@ -152,13 +152,13 @@
<trigger>
<x>6</x>
<y>2</y>
<active>true</active>
<active>false</active>
</trigger>
<door>
<x>6</x>
<y>1</y>
<locked>false</locked>
<open>false</open>
<open>true</open>
</dooŕ>
</events>
</map>