v0.3.0e: refactored the new findChars() function and re-added a collection of chars to Actor. Better readability and (trivially) better performance.
This commit is contained in:
parent
c55e38a86a
commit
2aee4fe3c6
|
@ -717,12 +717,9 @@ public class Dungeon {
|
||||||
System.arraycopy( pass, 0, passable, 0, Level.LENGTH );
|
System.arraycopy( pass, 0, passable, 0, Level.LENGTH );
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Actor actor : Actor.all()) {
|
for (Char c : Actor.chars()) {
|
||||||
if (actor instanceof Char) {
|
if (visible[c.pos]) {
|
||||||
int pos = ((Char)actor).pos;
|
passable[c.pos] = false;
|
||||||
if (visible[pos]) {
|
|
||||||
passable[pos] = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -738,12 +735,9 @@ public class Dungeon {
|
||||||
System.arraycopy( pass, 0, passable, 0, Level.LENGTH );
|
System.arraycopy( pass, 0, passable, 0, Level.LENGTH );
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Actor actor : Actor.all()) {
|
for (Char c : Actor.chars()) {
|
||||||
if (actor instanceof Char) {
|
if (visible[c.pos]) {
|
||||||
int pos = ((Char)actor).pos;
|
passable[c.pos] = false;
|
||||||
if (visible[pos]) {
|
|
||||||
passable[pos] = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
passable[cur] = true;
|
passable[cur] = true;
|
||||||
|
|
|
@ -98,7 +98,8 @@ public abstract class Actor implements Bundlable {
|
||||||
// **********************
|
// **********************
|
||||||
// *** Static members ***
|
// *** Static members ***
|
||||||
|
|
||||||
private static HashSet<Actor> all = new HashSet<Actor>();
|
private static HashSet<Actor> all = new HashSet<>();
|
||||||
|
private static HashSet<Char> chars = new HashSet<>();
|
||||||
private static Actor current;
|
private static Actor current;
|
||||||
|
|
||||||
private static SparseArray<Actor> ids = new SparseArray<Actor>();
|
private static SparseArray<Actor> ids = new SparseArray<Actor>();
|
||||||
|
@ -110,6 +111,7 @@ public abstract class Actor implements Bundlable {
|
||||||
now = 0;
|
now = 0;
|
||||||
|
|
||||||
all.clear();
|
all.clear();
|
||||||
|
chars.clear();
|
||||||
|
|
||||||
ids.clear();
|
ids.clear();
|
||||||
}
|
}
|
||||||
|
@ -234,6 +236,7 @@ public abstract class Actor implements Bundlable {
|
||||||
|
|
||||||
if (actor instanceof Char) {
|
if (actor instanceof Char) {
|
||||||
Char ch = (Char)actor;
|
Char ch = (Char)actor;
|
||||||
|
chars.add( ch );
|
||||||
for (Buff buff : ch.buffs()) {
|
for (Buff buff : ch.buffs()) {
|
||||||
all.add( buff );
|
all.add( buff );
|
||||||
buff.onAdd();
|
buff.onAdd();
|
||||||
|
@ -245,6 +248,7 @@ public abstract class Actor implements Bundlable {
|
||||||
|
|
||||||
if (actor != null) {
|
if (actor != null) {
|
||||||
all.remove( actor );
|
all.remove( actor );
|
||||||
|
chars.remove( actor );
|
||||||
actor.onRemove();
|
actor.onRemove();
|
||||||
|
|
||||||
if (actor.id > 0) {
|
if (actor.id > 0) {
|
||||||
|
@ -254,9 +258,9 @@ public abstract class Actor implements Bundlable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Char findChar( int pos ) {
|
public static Char findChar( int pos ) {
|
||||||
for (Actor actor : all){
|
for (Char ch : chars){
|
||||||
if (actor instanceof Char && ((Char)actor).pos == pos)
|
if (ch.pos == pos)
|
||||||
return (Char)actor;
|
return ch;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -268,4 +272,6 @@ public abstract class Actor implements Bundlable {
|
||||||
public static HashSet<Actor> all() {
|
public static HashSet<Actor> all() {
|
||||||
return all;
|
return all;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static HashSet<Char> chars() { return chars; }
|
||||||
}
|
}
|
||||||
|
|
|
@ -170,10 +170,8 @@ public class King extends Mob {
|
||||||
Sample.INSTANCE.play( Assets.SND_CHALLENGE );
|
Sample.INSTANCE.play( Assets.SND_CHALLENGE );
|
||||||
|
|
||||||
boolean[] passable = Level.passable.clone();
|
boolean[] passable = Level.passable.clone();
|
||||||
for (Actor actor : Actor.all()) {
|
for (Char c : Actor.chars()) {
|
||||||
if (actor instanceof Char) {
|
passable[c.pos] = false;
|
||||||
passable[((Char)actor).pos] = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int undeadsToSummon = maxArmySize() - Undead.count;
|
int undeadsToSummon = maxArmySize() - Undead.count;
|
||||||
|
|
|
@ -164,7 +164,7 @@ public class QuickSlotButton extends Button implements WndBag.Listener {
|
||||||
targeting = lastTarget != null && lastTarget.isAlive() && Dungeon.visible[lastTarget.pos];
|
targeting = lastTarget != null && lastTarget.isAlive() && Dungeon.visible[lastTarget.pos];
|
||||||
|
|
||||||
if (targeting) {
|
if (targeting) {
|
||||||
if (Actor.all().contains( lastTarget )) {
|
if (Actor.chars().contains( lastTarget )) {
|
||||||
lastTarget.sprite.parent.add( crossM );
|
lastTarget.sprite.parent.add( crossM );
|
||||||
crossM.point( DungeonTilemap.tileToWorld( lastTarget.pos ) );
|
crossM.point( DungeonTilemap.tileToWorld( lastTarget.pos ) );
|
||||||
crossB.x = PixelScene.align( x + (width - crossB.width) / 2 );
|
crossB.x = PixelScene.align( x + (width - crossB.width) / 2 );
|
||||||
|
|
Loading…
Reference in New Issue
Block a user