Performance update to Pathfinder and room loading

This commit is contained in:
Beny 2020-08-16 03:01:37 +02:00
parent f247588658
commit 68a197526f

View File

@ -426,7 +426,6 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
if (this.itemCount() > Room.MAXIMUM_FURNI) { if (this.itemCount() > Room.MAXIMUM_FURNI) {
LOGGER.error("Room ID: {} has exceeded the furniture limit ({} > {}).", this.getId(), this.itemCount(), Room.MAXIMUM_FURNI); LOGGER.error("Room ID: {} has exceeded the furniture limit ({} > {}).", this.getId(), this.itemCount(), Room.MAXIMUM_FURNI);
} }
} }
private synchronized void loadWiredData(Connection connection) { private synchronized void loadWiredData(Connection connection) {
@ -542,7 +541,6 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
public void updateTile(RoomTile tile) { public void updateTile(RoomTile tile) {
if (tile != null) { if (tile != null) {
tile.setStackHeight(this.getStackHeight(tile.x, tile.y, false)); tile.setStackHeight(this.getStackHeight(tile.x, tile.y, false));
tile.setState(this.calculateTileState(tile)); tile.setState(this.calculateTileState(tile));
} }
} }
@ -566,17 +564,28 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
return RoomTileState.INVALID; return RoomTileState.INVALID;
RoomTileState result = RoomTileState.OPEN; RoomTileState result = RoomTileState.OPEN;
HabboItem lowestItem = null; HabboItem highestItem = null;
HabboItem lowestChair = this.getLowestChair(tile); HabboItem lowestChair = this.getLowestChair(tile);
THashSet<HabboItem> items = this.getItemsAt(tile); THashSet<HabboItem> items = this.getItemsAt(tile);
if (items == null) return RoomTileState.INVALID;
if (items.stream().anyMatch(i -> i.getBaseItem().allowLay())) return RoomTileState.LAY; if (items == null) return RoomTileState.INVALID;
for (HabboItem item : items) { for (HabboItem item : items) {
if (exclude != null && item == exclude) continue; if (exclude != null && item == exclude) continue;
if (lowestChair != null && item.getZ() > lowestChair.getZ() + 1.5) { if(item.getBaseItem().allowLay()) {
return RoomTileState.LAY;
}
if (highestItem != null && highestItem.getZ() + Item.getCurrentHeight(highestItem) > item.getZ() + Item.getCurrentHeight(item))
continue;
highestItem = item;
if (result == RoomTileState.OPEN) {
result = this.checkStateForItem(item, tile);
}
/*if (lowestChair != null && item.getZ() > lowestChair.getZ() + 1.5) {
continue; continue;
} }
@ -588,7 +597,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
if (result == RoomTileState.OPEN) { if (result == RoomTileState.OPEN) {
result = this.checkStateForItem(item, tile); result = this.checkStateForItem(item, tile);
} }
} }*/
} }
if (lowestChair != null) return RoomTileState.SIT; if (lowestChair != null) return RoomTileState.SIT;
@ -3311,6 +3320,10 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
} }
public THashSet<HabboItem> getItemsAt(RoomTile tile) { public THashSet<HabboItem> getItemsAt(RoomTile tile) {
return getItemsAt(tile, false);
}
public THashSet<HabboItem> getItemsAt(RoomTile tile, boolean returnOnFirst) {
THashSet<HabboItem> items = new THashSet<>(0); THashSet<HabboItem> items = new THashSet<>(0);
if (tile == null) if (tile == null)
@ -3339,19 +3352,24 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
if (item.getBaseItem().getType() != FurnitureType.FLOOR) if (item.getBaseItem().getType() != FurnitureType.FLOOR)
continue; continue;
if (item.getX() == tile.x && item.getY() == tile.y) { int width, length;
items.add(item);
} else {
if (item.getBaseItem().getWidth() <= 1 && item.getBaseItem().getLength() <= 1) {
continue;
}
THashSet<RoomTile> tiles = this.getLayout().getTilesAt(this.layout.getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation()); if (item.getRotation() != 2 && item.getRotation() != 6) {
for (RoomTile t : tiles) { width = item.getBaseItem().getWidth() > 0 ? item.getBaseItem().getWidth() : 1;
if ((t.x == tile.x) && (t.y == tile.y) && (!items.contains(item))) { length = item.getBaseItem().getLength() > 0 ? item.getBaseItem().getLength() : 1;
items.add(item); }
} else {
} width = item.getBaseItem().getLength() > 0 ? item.getBaseItem().getLength() : 1;
length = item.getBaseItem().getWidth() > 0 ? item.getBaseItem().getWidth() : 1;
}
if (!(tile.x >= item.getX() && tile.x <= item.getX() + width - 1 && tile.y >= item.getY() && tile.y <= item.getY() + length - 1))
continue;
items.add(item);
if(returnOnFirst) {
return items;
} }
} }
@ -3369,20 +3387,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
if (item.getZ() < minZ) if (item.getZ() < minZ)
continue; continue;
if (item.getX() == x && item.getY() == y && item.getZ() >= minZ) { items.add(item);
items.add(item);
} else {
if (item.getBaseItem().getWidth() <= 1 && item.getBaseItem().getLength() <= 1) {
continue;
}
THashSet<RoomTile> tiles = this.getLayout().getTilesAt(this.layout.getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation());
for (RoomTile tile : tiles) {
if ((tile.x == x) && (tile.y == y) && (!items.contains(item))) {
items.add(item);
}
}
}
} }
return items; return items;
} }
@ -3390,54 +3395,22 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
public THashSet<HabboItem> getItemsAt(Class<? extends HabboItem> type, int x, int y) { public THashSet<HabboItem> getItemsAt(Class<? extends HabboItem> type, int x, int y) {
THashSet<HabboItem> items = new THashSet<>(); THashSet<HabboItem> items = new THashSet<>();
TIntObjectIterator<HabboItem> iterator = this.roomItems.iterator(); for (HabboItem item : this.getItemsAt(x, y)) {
if (!item.getClass().equals(type))
continue;
for (int i = this.roomItems.size(); i-- > 0; ) { items.add(item);
HabboItem item;
try {
iterator.advance();
item = iterator.value();
} catch (Exception e) {
break;
}
if (item.getClass().equals(type)) {
if (item.getX() == x && item.getY() == y) {
items.add(item);
} else {
if (item.getBaseItem().getWidth() <= 1 && item.getBaseItem().getLength() <= 1) {
continue;
}
THashSet<RoomTile> tiles = this.getLayout().getTilesAt(this.layout.getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation());
for (RoomTile tile : tiles) {
if ((tile.x == x) && (tile.y == y) && (!items.contains(item))) {
items.add(item);
}
}
}
}
} }
return items; return items;
} }
public boolean hasItemsAt(int x, int y) { public boolean hasItemsAt(int x, int y) {
TIntObjectIterator<HabboItem> iterator = this.roomItems.iterator(); RoomTile tile = this.getLayout().getTile((short) x, (short) y);
for (int i = this.roomItems.size(); i-- > 0; ) { if(tile == null)
HabboItem habboItem; return false;
try {
iterator.advance();
habboItem = iterator.value();
} catch (Exception e) {
break;
}
if (habboItem.getX() == x && habboItem.getY() == y) return true; return this.getItemsAt(tile, true).size() > 0;
}
return false;
} }
public HabboItem getTopItemAt(int x, int y) { public HabboItem getTopItemAt(int x, int y) {
@ -3445,55 +3418,24 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
} }
public HabboItem getTopItemAt(int x, int y, HabboItem exclude) { public HabboItem getTopItemAt(int x, int y, HabboItem exclude) {
HabboItem item = null; RoomTile tile = this.getLayout().getTile((short) x, (short) y);
TIntObjectIterator<HabboItem> iterator = this.roomItems.iterator(); if(tile == null)
return null;
for (int i = this.roomItems.size(); i-- > 0; ) { HabboItem highestItem = null;
HabboItem habboItem;
try {
iterator.advance();
habboItem = iterator.value();
} catch (Exception e) {
break;
}
if (habboItem.getBaseItem().getType() != FurnitureType.FLOOR) for (HabboItem item : this.getItemsAt(x, y)) {
if(exclude != null && exclude == item)
continue; continue;
if (exclude != null) { if (highestItem != null && highestItem.getZ() + Item.getCurrentHeight(highestItem) > item.getZ() + Item.getCurrentHeight(item))
if (exclude == habboItem) continue;
continue;
}
if (habboItem.getX() == x && habboItem.getY() == y) { highestItem = item;
if (item == null || (habboItem.getZ() + Item.getCurrentHeight(habboItem)) > (item.getZ() + Item.getCurrentHeight(item))) {
item = habboItem;
}
} else {
if (habboItem.getBaseItem().getWidth() <= 1 && habboItem.getBaseItem().getLength() <= 1) {
continue;
}
if (this.layout == null) continue;
THashSet<RoomTile> tiles = this.layout.getTilesAt(
this.layout.getTile(habboItem.getX(), habboItem.getY()),
habboItem.getBaseItem().getWidth(),
habboItem.getBaseItem().getLength(),
habboItem.getRotation()
);
for (RoomTile tile : tiles) {
if (((tile.x == x) && (tile.y == y))) {
if (item == null || item.getZ() < habboItem.getZ())
item = habboItem;
}
}
}
} }
return item; return highestItem;
} }
public double getTopHeightAt(int x, int y) { public double getTopHeightAt(int x, int y) {
@ -3524,17 +3466,14 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
THashSet<HabboItem> items = this.getItemsAt(tile); THashSet<HabboItem> items = this.getItemsAt(tile);
if (items != null && !items.isEmpty()) { if (items != null && !items.isEmpty()) {
for (HabboItem item : items) { for (HabboItem item : items) {
if (item.getBaseItem().allowSit()) {
if (lowestChair == null || item.getZ() < lowestChair.getZ()) {
lowestChair = item;
}
}
if (lowestChair != null) { if(!item.getBaseItem().allowSit())
if (item.getZ() > lowestChair.getZ() && item.getZ() - lowestChair.getZ() < 1.5) { continue;
lowestChair = null;
} if(lowestChair != null && lowestChair.getZ() < item.getZ())
} continue;
lowestChair = item;
} }
} }
@ -3542,37 +3481,32 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
} }
public double getStackHeight(short x, short y, boolean calculateHeightmap, HabboItem exclude) { public double getStackHeight(short x, short y, boolean calculateHeightmap, HabboItem exclude) {
if (x < 0 || y < 0 || this.layout == null) if (x < 0 || y < 0 || this.layout == null)
return calculateHeightmap ? Short.MAX_VALUE : 0.0; return calculateHeightmap ? Short.MAX_VALUE : 0.0;
double height = this.layout.getHeightAtSquare(x, y); double height = this.layout.getHeightAtSquare(x, y);
boolean canStack = true; boolean canStack = true;
boolean stackHelper = false;
THashSet<HabboItem> items = this.getItemsAt(x, y); THashSet<HabboItem> stackHelpers = this.getItemsAt(InteractionStackHelper.class, x, y);
if (items != null) {
for (HabboItem item : items) { if(stackHelpers.size() > 0) {
for(HabboItem item : stackHelpers) {
if (item == exclude) continue; if (item == exclude) continue;
return calculateHeightmap ? item.getZ() * 256.0D : item.getZ();
if (item instanceof InteractionStackHelper) {
stackHelper = true;
height = item.getExtradata().isEmpty() ? Double.valueOf("0.0") : (Double.valueOf(item.getExtradata()) / 100);
canStack = true;
}
} }
}
if (!stackHelper) { HabboItem item = this.getTopItemAt(x, y, exclude);
HabboItem item = this.getTopItemAt(x, y, exclude); if (item != null) {
if (item != null) { canStack = item.getBaseItem().allowStack();
canStack = item.getBaseItem().allowStack(); height = item.getZ() + Item.getCurrentHeight(item);
height = item.getZ() + Item.getCurrentHeight(item); }
}
HabboItem lowestChair = this.getLowestChair(x, y); HabboItem lowestChair = this.getLowestChair(x, y);
if (lowestChair != null && lowestChair != exclude) { if (lowestChair != null && lowestChair != exclude) {
canStack = true; canStack = true;
height = lowestChair.getZ(); height = lowestChair.getZ();
}
}
} }
if (calculateHeightmap) { if (calculateHeightmap) {