v0.4.2: array access and general performance improvements
This commit is contained in:
parent
e87ce8949e
commit
c23a284423
|
@ -37,6 +37,7 @@ public class PathFinder {
|
||||||
private static int[] dir;
|
private static int[] dir;
|
||||||
|
|
||||||
//performance-light shortcuts for some common pathfinder cases
|
//performance-light shortcuts for some common pathfinder cases
|
||||||
|
//they are in array-access order for increased memory performance
|
||||||
public static int[] NEIGHBOURS4;
|
public static int[] NEIGHBOURS4;
|
||||||
public static int[] NEIGHBOURS8;
|
public static int[] NEIGHBOURS8;
|
||||||
public static int[] NEIGHBOURS9;
|
public static int[] NEIGHBOURS9;
|
||||||
|
@ -55,9 +56,9 @@ public class PathFinder {
|
||||||
|
|
||||||
dir = new int[]{-1, +1, -width, +width, -width-1, -width+1, +width-1, +width+1};
|
dir = new int[]{-1, +1, -width, +width, -width-1, -width+1, +width-1, +width+1};
|
||||||
|
|
||||||
NEIGHBOURS4 = new int[]{-width, +1, +width, -1};
|
NEIGHBOURS4 = new int[]{-width, -1, +1, +width};
|
||||||
NEIGHBOURS8 = new int[]{-width, +1-width, +1, +1+width, +width, -1+width, -1, -1-width};
|
NEIGHBOURS8 = new int[]{-width-1, -width, -width+1, -1, +1, +width-1, +width, +width+1};
|
||||||
NEIGHBOURS9 = new int[]{0, -width, +1-width, +1, +1+width, +width, -1+width, -1, -1-width};
|
NEIGHBOURS9 = new int[]{-width-1, -width, -width+1, -1, 0, +1, +width-1, +width, +width+1};
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO currently this isn't used, and all pathfinding is recomputed each step.
|
//TODO currently this isn't used, and all pathfinding is recomputed each step.
|
||||||
|
|
|
@ -160,6 +160,10 @@ public class Hero extends Char {
|
||||||
|
|
||||||
private ArrayList<Mob> visibleEnemies;
|
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() {
|
public Hero() {
|
||||||
super();
|
super();
|
||||||
name = Messages.get(this, "name");
|
name = Messages.get(this, "name");
|
||||||
|
@ -975,7 +979,7 @@ public class Hero extends Char {
|
||||||
newMob = true;
|
newMob = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (QuickSlotButton.autoAim(m) != -1){
|
if (!mindVisionEnemies.contains(m) && QuickSlotButton.autoAim(m) != -1){
|
||||||
if (target == null){
|
if (target == null){
|
||||||
target = m;
|
target = m;
|
||||||
} else if (distance(target) > distance(m)) {
|
} else if (distance(target) > distance(m)) {
|
||||||
|
|
|
@ -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 ) {
|
private int getWaterTile( int pos ) {
|
||||||
int t = Terrain.WATER_TILES;
|
int t = Terrain.WATER_TILES;
|
||||||
for (int j=0; j < PathFinder.NEIGHBOURS4.length; j++) {
|
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;
|
t += 1 << j;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -942,47 +945,36 @@ public abstract class Level implements Bundlable {
|
||||||
|
|
||||||
//Currently only the hero can get mind vision or awareness
|
//Currently only the hero can get mind vision or awareness
|
||||||
if (c.isAlive() && c == Dungeon.hero) {
|
if (c.isAlive() && c == Dungeon.hero) {
|
||||||
|
Dungeon.hero.mindVisionEnemies.clear();
|
||||||
if (c.buff( MindVision.class ) != null) {
|
if (c.buff( MindVision.class ) != null) {
|
||||||
for (Mob mob : mobs) {
|
for (Mob mob : mobs) {
|
||||||
int p = mob.pos;
|
int p = mob.pos;
|
||||||
fieldOfView[p] = true;
|
|
||||||
fieldOfView[p + 1] = true;
|
if (!fieldOfView[p]){
|
||||||
fieldOfView[p - 1] = true;
|
Dungeon.hero.mindVisionEnemies.add(mob);
|
||||||
fieldOfView[p + width() + 1] = true;
|
}
|
||||||
fieldOfView[p + width() - 1] = true;
|
for (int i : PathFinder.NEIGHBOURS9)
|
||||||
fieldOfView[p - width() + 1] = true;
|
fieldOfView[p+i] = true;
|
||||||
fieldOfView[p - width() - 1] = true;
|
|
||||||
fieldOfView[p + width()] = true;
|
|
||||||
fieldOfView[p - width()] = true;
|
|
||||||
}
|
}
|
||||||
} else if (((Hero)c).heroClass == HeroClass.HUNTRESS) {
|
} else if (((Hero)c).heroClass == HeroClass.HUNTRESS) {
|
||||||
for (Mob mob : mobs) {
|
for (Mob mob : mobs) {
|
||||||
int p = mob.pos;
|
int p = mob.pos;
|
||||||
if (distance( c.pos, p) == 2) {
|
if (distance( c.pos, p) == 2) {
|
||||||
fieldOfView[p] = true;
|
|
||||||
fieldOfView[p + 1] = true;
|
if (!fieldOfView[p]){
|
||||||
fieldOfView[p - 1] = true;
|
Dungeon.hero.mindVisionEnemies.add(mob);
|
||||||
fieldOfView[p + width() + 1] = true;
|
}
|
||||||
fieldOfView[p + width() - 1] = true;
|
for (int i : PathFinder.NEIGHBOURS9)
|
||||||
fieldOfView[p - width() + 1] = true;
|
fieldOfView[p+i] = true;
|
||||||
fieldOfView[p - width() - 1] = true;
|
|
||||||
fieldOfView[p + width()] = true;
|
|
||||||
fieldOfView[p - width()] = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (c.buff( Awareness.class ) != null) {
|
if (c.buff( Awareness.class ) != null) {
|
||||||
for (Heap heap : heaps.values()) {
|
for (Heap heap : heaps.values()) {
|
||||||
int p = heap.pos;
|
int p = heap.pos;
|
||||||
fieldOfView[p] = true;
|
for (int i : PathFinder.NEIGHBOURS9)
|
||||||
fieldOfView[p + 1] = true;
|
fieldOfView[p+i] = 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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user