optimalised canvas repaint
This commit is contained in:
parent
79c65a1f3c
commit
05477a578c
6
pom.xml
6
pom.xml
@ -44,5 +44,11 @@
|
|||||||
<version>2.5</version>
|
<version>2.5</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter</artifactId>
|
||||||
|
<version>RELEASE</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
@ -205,9 +205,11 @@ public class InteractionCell extends Cell {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
if (!message.contains("cutscene")){
|
||||||
dialog.skipShowText();
|
dialog.skipShowText();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void endEvent() {
|
public void endEvent() {
|
||||||
if (dialog != null) {
|
if (dialog != null) {
|
||||||
|
|||||||
@ -198,7 +198,7 @@ public class WindowOfFreeMove extends JLayeredPane {
|
|||||||
mapManager.createMap();
|
mapManager.createMap();
|
||||||
isReadyToPaint = true;
|
isReadyToPaint = true;
|
||||||
|
|
||||||
Timer timer = new Timer(10, actionEvent -> {
|
Timer timer = new Timer(20, actionEvent -> {
|
||||||
mapManager.getActualMap().getPerson().move();
|
mapManager.getActualMap().getPerson().move();
|
||||||
camera.moveCamera();
|
camera.moveCamera();
|
||||||
canvas.repaint();
|
canvas.repaint();
|
||||||
@ -240,37 +240,49 @@ public class WindowOfFreeMove extends JLayeredPane {
|
|||||||
mapManager.getActualMap().getImageCell().paintBackground(g2D, j, i);
|
mapManager.getActualMap().getImageCell().paintBackground(g2D, j, i);
|
||||||
}
|
}
|
||||||
for (Cell cell : mapManager.getActualMap().getMoveToCells()) {
|
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()) {
|
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);
|
if (mapManager.getActualMap().getPerson().getY() == i && mapManager.getActualMap().getPerson().getDirectionMoveLast() != KEY_UP) mapManager.getActualMap().getPerson().paint(g2D);
|
||||||
for (Cell cell : mapManager.getActualMap().getInteractionEventCells()) {
|
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()) {
|
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);
|
if (mapManager.getActualMap().getPerson().getY() == (i-1) && mapManager.getActualMap().getPerson().getDirectionMoveLast() == KEY_UP) mapManager.getActualMap().getPerson().paint(g2D);
|
||||||
for (Block cell : mapManager.getActualMap().getBlocks()) {
|
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()) {
|
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()) {
|
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++) {
|
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()) {
|
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 {
|
public class Foreground extends JPanel {
|
||||||
|
|||||||
@ -14,12 +14,12 @@
|
|||||||
<trigger>
|
<trigger>
|
||||||
<x>6</x>
|
<x>6</x>
|
||||||
<y>4</y>
|
<y>4</y>
|
||||||
<active>true</active>
|
<active>false</active>
|
||||||
</trigger>
|
</trigger>
|
||||||
<trigger>
|
<trigger>
|
||||||
<x>14</x>
|
<x>14</x>
|
||||||
<y>16</y>
|
<y>16</y>
|
||||||
<active>false</active>
|
<active>true</active>
|
||||||
</trigger>
|
</trigger>
|
||||||
<chest>
|
<chest>
|
||||||
<x>1</x>
|
<x>1</x>
|
||||||
@ -52,14 +52,14 @@
|
|||||||
<door>
|
<door>
|
||||||
<x>16</x>
|
<x>16</x>
|
||||||
<y>10</y>
|
<y>10</y>
|
||||||
<locked>false</locked>
|
<locked>true</locked>
|
||||||
<open>false</open>
|
<open>false</open>
|
||||||
</dooŕ>
|
</dooŕ>
|
||||||
<door>
|
<door>
|
||||||
<x>8</x>
|
<x>8</x>
|
||||||
<y>13</y>
|
<y>13</y>
|
||||||
<locked>false</locked>
|
<locked>false</locked>
|
||||||
<open>true</open>
|
<open>false</open>
|
||||||
</dooŕ>
|
</dooŕ>
|
||||||
</events>
|
</events>
|
||||||
</map>
|
</map>
|
||||||
@ -74,7 +74,7 @@
|
|||||||
<chest>
|
<chest>
|
||||||
<x>1</x>
|
<x>1</x>
|
||||||
<y>9</y>
|
<y>9</y>
|
||||||
<active>false</active>
|
<active>true</active>
|
||||||
</chest>
|
</chest>
|
||||||
<door>
|
<door>
|
||||||
<x>12</x>
|
<x>12</x>
|
||||||
@ -104,13 +104,13 @@
|
|||||||
<x>4</x>
|
<x>4</x>
|
||||||
<y>1</y>
|
<y>1</y>
|
||||||
<locked>false</locked>
|
<locked>false</locked>
|
||||||
<open>false</open>
|
<open>true</open>
|
||||||
</dooŕ>
|
</dooŕ>
|
||||||
<door>
|
<door>
|
||||||
<x>2</x>
|
<x>2</x>
|
||||||
<y>12</y>
|
<y>12</y>
|
||||||
<locked>false</locked>
|
<locked>false</locked>
|
||||||
<open>false</open>
|
<open>true</open>
|
||||||
</dooŕ>
|
</dooŕ>
|
||||||
<door>
|
<door>
|
||||||
<x>17</x>
|
<x>17</x>
|
||||||
@ -126,13 +126,13 @@
|
|||||||
<trigger>
|
<trigger>
|
||||||
<x>4</x>
|
<x>4</x>
|
||||||
<y>18</y>
|
<y>18</y>
|
||||||
<active>true</active>
|
<active>false</active>
|
||||||
</trigger>
|
</trigger>
|
||||||
<door>
|
<door>
|
||||||
<x>4</x>
|
<x>4</x>
|
||||||
<y>19</y>
|
<y>19</y>
|
||||||
<locked>false</locked>
|
<locked>false</locked>
|
||||||
<open>false</open>
|
<open>true</open>
|
||||||
</dooŕ>
|
</dooŕ>
|
||||||
</events>
|
</events>
|
||||||
</map>
|
</map>
|
||||||
@ -152,13 +152,13 @@
|
|||||||
<trigger>
|
<trigger>
|
||||||
<x>6</x>
|
<x>6</x>
|
||||||
<y>2</y>
|
<y>2</y>
|
||||||
<active>true</active>
|
<active>false</active>
|
||||||
</trigger>
|
</trigger>
|
||||||
<door>
|
<door>
|
||||||
<x>6</x>
|
<x>6</x>
|
||||||
<y>1</y>
|
<y>1</y>
|
||||||
<locked>false</locked>
|
<locked>false</locked>
|
||||||
<open>false</open>
|
<open>true</open>
|
||||||
</dooŕ>
|
</dooŕ>
|
||||||
</events>
|
</events>
|
||||||
</map>
|
</map>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user