Make BB tile filling threaded

This commit is contained in:
Alejandro 2019-05-18 22:03:11 +03:00
parent 3b10d8abc3
commit 25058296c2

View File

@ -23,6 +23,8 @@ import gnu.trove.map.hash.THashMap;
import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.THashSet;
import java.util.*; import java.util.*;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
public class BattleBanzaiGame extends Game public class BattleBanzaiGame extends Game
{ {
@ -38,6 +40,8 @@ public class BattleBanzaiGame extends Game
public static final int POINTS_LOCK_TILE = Emulator.getConfig().getInt("hotel.banzai.points.tile.lock", 1); public static final int POINTS_LOCK_TILE = Emulator.getConfig().getInt("hotel.banzai.points.tile.lock", 1);
private static final ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(Emulator.getConfig().getInt("hotel.banzai.fill.threads", 2));
private int tileCount; private int tileCount;
private int countDown; private int countDown;
@ -292,11 +296,13 @@ public class BattleBanzaiGame extends Game
if (doNotCheckFill) return; if (doNotCheckFill) return;
int x = item.getX(); final int x = item.getX();
int y = item.getY(); final int y = item.getY();
List<List<RoomTile>> filledAreas = new ArrayList<>(); final List<List<RoomTile>> filledAreas = new ArrayList<>();
THashSet<HabboItem> lockedTiles = new THashSet<>(this.lockedTiles.get(teamColor)); final THashSet<HabboItem> lockedTiles = new THashSet<>(this.lockedTiles.get(teamColor));
executor.execute(() -> {
filledAreas.add(this.floodFill(x, y - 1, lockedTiles, new ArrayList<>(), teamColor)); filledAreas.add(this.floodFill(x, y - 1, lockedTiles, new ArrayList<>(), teamColor));
filledAreas.add(this.floodFill(x, y + 1, lockedTiles, new ArrayList<>(), teamColor)); filledAreas.add(this.floodFill(x, y + 1, lockedTiles, new ArrayList<>(), teamColor));
filledAreas.add(this.floodFill(x - 1, y, lockedTiles, new ArrayList<>(), teamColor)); filledAreas.add(this.floodFill(x - 1, y, lockedTiles, new ArrayList<>(), teamColor));
@ -324,6 +330,7 @@ public class BattleBanzaiGame extends Game
habbo.getHabboInfo().getGamePlayer().addScore(BattleBanzaiGame.POINTS_LOCK_TILE * largestAreaOfAll.get().size()); habbo.getHabboInfo().getGamePlayer().addScore(BattleBanzaiGame.POINTS_LOCK_TILE * largestAreaOfAll.get().size());
} }
} }
});
} }
private List<RoomTile> floodFill(int x, int y, THashSet<HabboItem> lockedTiles, List<RoomTile> stack, GameTeamColors color) private List<RoomTile> floodFill(int x, int y, THashSet<HabboItem> lockedTiles, List<RoomTile> stack, GameTeamColors color)