diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java index de6b17516..a0c143384 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java @@ -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 ) { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/utils/BArray.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/utils/BArray.java index 5dec9a88a..9168cf845 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/utils/BArray.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/utils/BArray.java @@ -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]; }