v0.3.0c: refactored finding a character, no longer need to maintain chars[] array
This commit is contained in:
@@ -102,13 +102,10 @@ public abstract class Actor implements Bundlable {
|
||||
|
||||
private static float now = 0;
|
||||
|
||||
private static Char[] chars = new Char[Level.LENGTH];
|
||||
|
||||
public static void clear() {
|
||||
|
||||
now = 0;
|
||||
|
||||
Arrays.fill( chars, null );
|
||||
|
||||
all.clear();
|
||||
|
||||
ids.clear();
|
||||
@@ -160,14 +157,6 @@ public abstract class Actor implements Bundlable {
|
||||
public static void resetNextID(){
|
||||
nextID = 1;
|
||||
}
|
||||
|
||||
public static void occupyCell( Char ch ) {
|
||||
chars[ch.pos] = ch;
|
||||
}
|
||||
|
||||
public static void freeCell( int pos ) {
|
||||
chars[pos] = null;
|
||||
}
|
||||
|
||||
/*protected*/public void next() {
|
||||
if (current == this) {
|
||||
@@ -186,8 +175,7 @@ public abstract class Actor implements Bundlable {
|
||||
do {
|
||||
now = Float.MAX_VALUE;
|
||||
current = null;
|
||||
|
||||
Arrays.fill( chars, null );
|
||||
|
||||
|
||||
for (Actor actor : all) {
|
||||
|
||||
@@ -197,11 +185,7 @@ public abstract class Actor implements Bundlable {
|
||||
now = actor.time;
|
||||
current = actor;
|
||||
}
|
||||
|
||||
if (actor instanceof Char) {
|
||||
Char ch = (Char)actor;
|
||||
chars[ch.pos] = ch;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (current != null) {
|
||||
@@ -247,7 +231,6 @@ public abstract class Actor implements Bundlable {
|
||||
|
||||
if (actor instanceof Char) {
|
||||
Char ch = (Char)actor;
|
||||
chars[ch.pos] = ch;
|
||||
for (Buff buff : ch.buffs()) {
|
||||
all.add( buff );
|
||||
buff.onAdd();
|
||||
@@ -268,7 +251,11 @@ public abstract class Actor implements Bundlable {
|
||||
}
|
||||
|
||||
public static Char findChar( int pos ) {
|
||||
return chars[pos];
|
||||
for (Actor actor : all){
|
||||
if (actor instanceof Char && ((Char)actor).pos == pos)
|
||||
return (Char)actor;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Actor findById( int id ) {
|
||||
|
||||
@@ -279,7 +279,6 @@ public abstract class Char extends Actor {
|
||||
public void destroy() {
|
||||
HP = 0;
|
||||
Actor.remove( this );
|
||||
Actor.freeCell( pos );
|
||||
}
|
||||
|
||||
public void die( Object src ) {
|
||||
@@ -404,10 +403,7 @@ public abstract class Char extends Actor {
|
||||
Door.leave( pos );
|
||||
}
|
||||
|
||||
Actor.freeCell(pos);
|
||||
pos = step;
|
||||
Actor.occupyCell( this );
|
||||
|
||||
|
||||
if (flying && Dungeon.level.map[pos] == Terrain.DOOR) {
|
||||
Door.enter( pos );
|
||||
|
||||
@@ -181,8 +181,6 @@ public class Ghost extends NPC {
|
||||
}
|
||||
if (newPos != -1) {
|
||||
|
||||
Actor.freeCell(pos);
|
||||
|
||||
CellEmitter.get(pos).start(Speck.factory(Speck.LIGHT), 0.2f, 3);
|
||||
pos = newPos;
|
||||
sprite.place(pos);
|
||||
@@ -317,7 +315,6 @@ public class Ghost extends NPC {
|
||||
ghost.pos = level.randomRespawnCell();
|
||||
} while (ghost.pos == -1);
|
||||
level.mobs.add( ghost );
|
||||
Actor.occupyCell( ghost );
|
||||
|
||||
spawned = true;
|
||||
//dungeon depth determines type of quest.
|
||||
|
||||
@@ -217,9 +217,8 @@ public class Imp extends NPC {
|
||||
npc.pos = level.randomRespawnCell();
|
||||
} while (npc.pos == -1 || level.heaps.get( npc.pos ) != null);
|
||||
level.mobs.add( npc );
|
||||
Actor.occupyCell( npc );
|
||||
|
||||
spawned = true;
|
||||
spawned = true;
|
||||
alternative = Random.Int( 2 ) == 0;
|
||||
|
||||
given = false;
|
||||
|
||||
@@ -214,7 +214,6 @@ public class Wandmaker extends NPC {
|
||||
npc.pos = room.random();
|
||||
} while (level.map[npc.pos] == Terrain.ENTRANCE || level.map[npc.pos] == Terrain.SIGN);
|
||||
level.mobs.add( npc );
|
||||
Actor.occupyCell( npc );
|
||||
|
||||
spawned = true;
|
||||
alternative = Random.Int( 2 ) == 0;
|
||||
|
||||
Reference in New Issue
Block a user