Optimize water item update.

This commit is contained in:
Mike 2020-05-04 05:53:28 +02:00
parent 196c1ef23d
commit 87fdba280a

View File

@ -42,12 +42,15 @@ public class InteractionWaterItem extends InteractionDefault {
public void update() { public void update() {
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
if (room == null) if (room == null) {
return; return;
}
Rectangle rectangle = RoomLayout.getRectangle(this.getX(), this.getY(), this.getBaseItem().getWidth(), this.getBaseItem().getLength(), this.getRotation()); Rectangle rectangle = this.getRectangle();
// Check if every tile of the furni is in water.
boolean foundWater = true; boolean foundWater = true;
for (short x = (short) rectangle.x; x < rectangle.getWidth() + rectangle.x && foundWater; x++) { for (short x = (short) rectangle.x; x < rectangle.getWidth() + rectangle.x && foundWater; x++) {
for (short y = (short) rectangle.y; y < rectangle.getHeight() + rectangle.y && foundWater; y++) { for (short y = (short) rectangle.y; y < rectangle.getHeight() + rectangle.y && foundWater; y++) {
boolean tile = false; boolean tile = false;
@ -66,16 +69,14 @@ public class InteractionWaterItem extends InteractionDefault {
} }
} }
if (foundWater) { // Update data if changed.
this.setExtradata("1"); String updatedData = foundWater ? "1" : "0";
if (!this.getExtradata().equals(updatedData)) {
this.setExtradata(updatedData);
this.needsUpdate(true); this.needsUpdate(true);
room.updateItem(this); room.updateItem(this);
return;
} }
this.setExtradata("0");
this.needsUpdate(true);
room.updateItem(this);
} }
@Override @Override