v0.4.2: array access and general performance improvements
This commit is contained in:
committed by
Evan Debenham
parent
e87ce8949e
commit
c23a284423
@@ -159,6 +159,10 @@ public class Hero extends Char {
|
||||
public int exp = 0;
|
||||
|
||||
private ArrayList<Mob> visibleEnemies;
|
||||
|
||||
//This list is maintained so that some logic checks can be skipped
|
||||
// for enemies we know we aren't seeing normally, resultign in better performance
|
||||
public ArrayList<Mob> mindVisionEnemies = new ArrayList<>();
|
||||
|
||||
public Hero() {
|
||||
super();
|
||||
@@ -975,7 +979,7 @@ public class Hero extends Char {
|
||||
newMob = true;
|
||||
}
|
||||
|
||||
if (QuickSlotButton.autoAim(m) != -1){
|
||||
if (!mindVisionEnemies.contains(m) && QuickSlotButton.autoAim(m) != -1){
|
||||
if (target == null){
|
||||
target = m;
|
||||
} else if (distance(target) > distance(m)) {
|
||||
@@ -995,7 +999,7 @@ public class Hero extends Char {
|
||||
interrupt();
|
||||
resting = false;
|
||||
}
|
||||
|
||||
|
||||
visibleEnemies = visible;
|
||||
}
|
||||
|
||||
|
||||
@@ -607,10 +607,13 @@ public abstract class Level implements Bundlable {
|
||||
}
|
||||
}
|
||||
|
||||
//FIXME this is a temporary fix here to avoid changing the tiles texture
|
||||
//This logic will be changed in 0.4.3 anyway
|
||||
private static int[] N4Indicies = new int[]{0, 2, 3, 1};
|
||||
private int getWaterTile( int pos ) {
|
||||
int t = Terrain.WATER_TILES;
|
||||
for (int j=0; j < PathFinder.NEIGHBOURS4.length; j++) {
|
||||
if ((Terrain.flags[map[pos + PathFinder.NEIGHBOURS4[j]]] & Terrain.UNSTITCHABLE) != 0) {
|
||||
if ((Terrain.flags[map[pos + PathFinder.NEIGHBOURS4[N4Indicies[j]]]] & Terrain.UNSTITCHABLE) != 0) {
|
||||
t += 1 << j;
|
||||
}
|
||||
}
|
||||
@@ -942,47 +945,36 @@ public abstract class Level implements Bundlable {
|
||||
|
||||
//Currently only the hero can get mind vision or awareness
|
||||
if (c.isAlive() && c == Dungeon.hero) {
|
||||
Dungeon.hero.mindVisionEnemies.clear();
|
||||
if (c.buff( MindVision.class ) != null) {
|
||||
for (Mob mob : mobs) {
|
||||
int p = mob.pos;
|
||||
fieldOfView[p] = true;
|
||||
fieldOfView[p + 1] = true;
|
||||
fieldOfView[p - 1] = true;
|
||||
fieldOfView[p + width() + 1] = true;
|
||||
fieldOfView[p + width() - 1] = true;
|
||||
fieldOfView[p - width() + 1] = true;
|
||||
fieldOfView[p - width() - 1] = true;
|
||||
fieldOfView[p + width()] = true;
|
||||
fieldOfView[p - width()] = true;
|
||||
|
||||
if (!fieldOfView[p]){
|
||||
Dungeon.hero.mindVisionEnemies.add(mob);
|
||||
}
|
||||
for (int i : PathFinder.NEIGHBOURS9)
|
||||
fieldOfView[p+i] = true;
|
||||
|
||||
}
|
||||
} else if (((Hero)c).heroClass == HeroClass.HUNTRESS) {
|
||||
for (Mob mob : mobs) {
|
||||
int p = mob.pos;
|
||||
if (distance( c.pos, p) == 2) {
|
||||
fieldOfView[p] = true;
|
||||
fieldOfView[p + 1] = true;
|
||||
fieldOfView[p - 1] = true;
|
||||
fieldOfView[p + width() + 1] = true;
|
||||
fieldOfView[p + width() - 1] = true;
|
||||
fieldOfView[p - width() + 1] = true;
|
||||
fieldOfView[p - width() - 1] = true;
|
||||
fieldOfView[p + width()] = true;
|
||||
fieldOfView[p - width()] = true;
|
||||
|
||||
if (!fieldOfView[p]){
|
||||
Dungeon.hero.mindVisionEnemies.add(mob);
|
||||
}
|
||||
for (int i : PathFinder.NEIGHBOURS9)
|
||||
fieldOfView[p+i] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (c.buff( Awareness.class ) != null) {
|
||||
for (Heap heap : heaps.values()) {
|
||||
int p = heap.pos;
|
||||
fieldOfView[p] = true;
|
||||
fieldOfView[p + 1] = true;
|
||||
fieldOfView[p - 1] = true;
|
||||
fieldOfView[p + width() + 1] = true;
|
||||
fieldOfView[p + width() - 1] = true;
|
||||
fieldOfView[p - width() + 1] = true;
|
||||
fieldOfView[p - width() - 1] = true;
|
||||
fieldOfView[p + width()] = true;
|
||||
fieldOfView[p - width()] = true;
|
||||
for (int i : PathFinder.NEIGHBOURS9)
|
||||
fieldOfView[p+i] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user