v0.4.2: observing now only updates relevant parts of the visited array
This commit is contained in:
parent
8537b86c5b
commit
c21efe4156
|
@ -664,14 +664,28 @@ public class Dungeon {
|
|||
}
|
||||
|
||||
level.updateFieldOfView(hero, visible);
|
||||
|
||||
BArray.or( level.visited, visible, level.visited );
|
||||
|
||||
int cx = hero.pos % level.width();
|
||||
int cy = hero.pos / level.width();
|
||||
|
||||
//Add one to account for hero's previous position
|
||||
int viewDist = hero.viewDistance+1;
|
||||
int ax = Math.max( 0, cx - viewDist );
|
||||
int bx = Math.min( cx + viewDist, level.width() - 1 );
|
||||
int ay = Math.max( 0, cy - viewDist );
|
||||
int by = Math.min( cy + viewDist, level.height() - 1 );
|
||||
|
||||
int len = bx - ax + 1;
|
||||
int pos = ax + ay * level.width();
|
||||
for (int y = ay; y <= by; y++, pos+=level.width()) {
|
||||
BArray.or( level.visited, visible, pos, len, level.visited );
|
||||
}
|
||||
|
||||
GameScene.afterObserve();
|
||||
}
|
||||
|
||||
public static int findPath( Char ch, int from, int to, boolean pass[], boolean[] visible ) {
|
||||
|
||||
|
||||
if (level.adjacent( from, to )) {
|
||||
return Actor.findChar( to ) == null && (pass[to] || Level.avoid[to]) ? to : -1;
|
||||
}
|
||||
|
@ -690,7 +704,7 @@ public class Dungeon {
|
|||
}
|
||||
|
||||
return PathFinder.getStep( from, to, passable );
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static int flee( Char ch, int cur, int from, boolean pass[], boolean[] visible ) {
|
||||
|
|
|
@ -46,16 +46,18 @@ public class BArray {
|
|||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static boolean[] or( boolean[] a, boolean[] b, boolean[] result ){
|
||||
return or( a, b, 0, a.length, result);
|
||||
}
|
||||
|
||||
public static boolean[] or( boolean[] a, boolean[] b, boolean[] result ) {
|
||||
|
||||
int length = a.length;
|
||||
public static boolean[] or( boolean[] a, boolean[] b, int offset, int length, boolean[] result ) {
|
||||
|
||||
if (result == null) {
|
||||
result = new boolean[length];
|
||||
}
|
||||
|
||||
for (int i=0; i < length; i++) {
|
||||
for (int i=offset; i < offset+length; i++) {
|
||||
result[i] = a[i] || b[i];
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user