Skip to content

Commit

Permalink
Fixes for level size mismatches caused by Epic level gen and fog of w…
Browse files Browse the repository at this point in the history
…ar updates
  • Loading branch information
Mikhael-Danilov committed Dec 22, 2024
1 parent b7f8592 commit 2530a69
Show file tree
Hide file tree
Showing 19 changed files with 188 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.watabou.noosa.tweeners.Tweener;
import com.watabou.pixeldungeon.Dungeon;
import com.watabou.pixeldungeon.DungeonTilemap;
import com.watabou.pixeldungeon.levels.Level;
import com.watabou.pixeldungeon.scenes.GameScene;
import com.watabou.pixeldungeon.utils.Utils;
import com.watabou.utils.Callback;
Expand Down Expand Up @@ -98,8 +99,9 @@ public void reset(int image) {

@Override
public boolean getVisible() {
if(Dungeon.level != null) {
return Dungeon.level.mapped[cell] && super.getVisible();
Level level = Dungeon.level;
if(level != null && level.cellValid(cell)) {
return level.mapped[cell] && super.getVisible();
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.nyrds.util.ModError;
import com.nyrds.util.ModdingMode;
import com.nyrds.util.Util;
import com.watabou.pixeldungeon.utils.GLog;
import com.watabou.pixeldungeon.utils.Utils;

import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -143,7 +142,7 @@ public <T> T runOptional(String method, T defaultValue, Object... args) {

try {
if (Util.isDebug() && !method.equals("onStep")) {
GLog.debug("Running script %s:%s", scriptFile, method);
//GLog.debug("Running script %s:%s", scriptFile, method);
}
if(defaultValue==null) {
run(method, luaArgs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.watabou.pixeldungeon.actors.mobs.Fraction;
import com.watabou.pixeldungeon.actors.mobs.WalkingType;
import com.watabou.pixeldungeon.mechanics.Ballistica;
import com.watabou.pixeldungeon.utils.GLog;

import org.jetbrains.annotations.NotNull;
import org.json.JSONObject;
Expand Down Expand Up @@ -106,6 +107,7 @@ public void damage(int dmg, @NotNull NamedEntityKind src) {
protected void fillMobStats(boolean restoring) {
JSONObject classDesc = getClassDef();
if(! classDesc.keys().hasNext()) {
GLog.debug("No mob def: " + mobClass);
return;
}

Expand Down
11 changes: 11 additions & 0 deletions RemixedDungeon/src/main/java/com/watabou/noosa/Group.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,17 @@ public Gizmo add(Gizmo g) {
return g;
}

public Gizmo addAfter(Gizmo g, Gizmo after) {
int i = members.indexOf(after);
if (i == -1) {
return add(g);
} else {
members.add(i + 1, g);
g.setParent(this);
sorted = false;
return g;
}
}
@SneakyThrows
public Gizmo recycle(@NotNull Class<? extends Gizmo> c) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.nyrds.pixeldungeon.levels.NecroLevel;
import com.nyrds.pixeldungeon.mechanics.buffs.BuffFactory;
import com.nyrds.pixeldungeon.mechanics.spells.SpellFactory;
import com.nyrds.pixeldungeon.ml.BuildConfig;
import com.nyrds.pixeldungeon.ml.R;
import com.nyrds.pixeldungeon.mobs.npc.AzuterronNPC;
import com.nyrds.pixeldungeon.mobs.npc.CagedKobold;
Expand Down Expand Up @@ -128,8 +129,13 @@ public class Dungeon {


public static void initSizeDependentStuff(int w, int h) {

if(BuildConfig.DEBUG) {
GLog.debug("dungeon size: " + w + "x" + h);
Utils.printStackTrace();
}

int size = w * h;
Actor.clearActors();

visible = new boolean[size];
passable = new boolean[size];
Expand Down Expand Up @@ -805,6 +811,7 @@ public static void observe() {

public static void observeImpl() {
level.updateFieldOfView(hero.getControlTarget());

System.arraycopy(level.fieldOfView, 0, visible, 0, visible.length);

BArray.or(level.mapped, visible, level.mapped);
Expand Down
38 changes: 18 additions & 20 deletions RemixedDungeon/src/main/java/com/watabou/pixeldungeon/FogOfWar.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,29 @@

public class FogOfWar extends Image {

private static final int VISIBLE = 0x00000000;
private static final int VISITED = 0xCC111111;
private static final int MAPPED = 0xCC442211;
private static final int INVISIBLE = 0xFF000000;
private static final int VISIBLE = 0x00000000;
private static final int VISITED = 0xCC111111;
private static final int MAPPED = 0xCC442211;
private static final int INVISIBLE = 0xFF000000;

private final int[] pixels;
private final int[] old_pixels;
private int[] pixels;
private int[] old_pixels;

private final int pWidth;
private final int pHeight;
private int pWidth;
private int pHeight;

private int width2;
private int height2;

private final int mWidth;
private final int mHeight;

public FogOfWar( int mapWidth, int mapHeight ) {
private int mWidth;
private int mHeight;

public FogOfWar(int mapWidth, int mapHeight) {
super();
reinit(mapWidth, mapHeight);
}

public void reinit(int mapWidth, int mapHeight) {
mWidth = mapWidth;
mHeight = mapHeight;

Expand Down Expand Up @@ -94,7 +96,6 @@ public void updateVisibility(boolean[] visible, boolean[] visited, boolean[] map
pos++;
int c = INVISIBLE;


int p_minus_w_minus_one = pos - w_minus_one;
if (visible[pos] && visible[p_minus_w_minus_one] &&
visible[pos - 1] && visible[p_minus_w_minus_one - 1]) {
Expand Down Expand Up @@ -123,8 +124,7 @@ public void updateVisibility(boolean[] visible, boolean[] visited, boolean[] map

@Override
public void draw() {

if(dirty || !Arrays.equals(pixels, old_pixels)) {
if (dirty || !Arrays.equals(pixels, old_pixels)) {
texture.pixels(width2, height2, pixels);
System.arraycopy(pixels, 0, old_pixels, 0, pixels.length);
}
Expand All @@ -136,13 +136,11 @@ public void draw() {

private class FogTexture extends SmartTexture {


public FogTexture() {
super(toDispose=BitmapData.createBitmap( width2, height2) );
super(toDispose = BitmapData.createBitmap(width2, height2));
toDispose.dispose();
//filter( Texture.NEAREST, Texture.NEAREST );
filter( Texture.LINEAR, Texture.LINEAR );
TextureCache.add( FogOfWar.class, this );
filter(Texture.LINEAR, Texture.LINEAR);
TextureCache.add(FogOfWar.class, this);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.watabou.pixeldungeon.levels.Terrain;
import com.watabou.pixeldungeon.levels.TerrainFlags;
import com.watabou.pixeldungeon.utils.BArray;
import com.watabou.pixeldungeon.utils.GLog;
import com.watabou.pixeldungeon.utils.Utils;

import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -635,6 +636,11 @@ public DungeonTilemap doorTilemap() {
@Override
public void updateFow(@NotNull FogOfWar fog) {

if(Dungeon.visible.length != mVisible.length) {
GLog.debug("Dungeon.visible.length != mVisible.length");
Utils.printStackTrace();
}

System.arraycopy(Dungeon.visible, 0, mVisible, 0, mVisible.length);

//System.arraycopy(level.mapped, 0, mMapped, 0, mMapped.length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1432,6 +1432,7 @@ public void onSpawn(Level level) {
protected JSONObject getClassDef() {
String entityKind = getEntityKind();
if (!defMap.containsKey(entityKind)) {
GLog.debug("Loading mob def: " + entityKind);
defMap.put(entityKind, JsonHelper.tryReadJsonFromAssets("mobsDesc/" + entityKind + ".json"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ public class Blob extends Actor implements NamedEntityKind {
public BlobEmitter emitter;

protected Blob() {
cur = new int[getLength()];
off = new int[getLength()];

setVolume(0);
}

public void reinit() {
cur = new int[getLength()];
off = new int[getLength()];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@ protected void emit( int index ) {
float size = DungeonTilemap.SIZE;
final Level level = Dungeon.level;

if(blob.cur.length != level.getLength()) {
blob.reinit();
return;
}

for (int i = 0; i < level.getLength(); i++) {
if (blob.cur[i] > 0 && Dungeon.isCellVisible(i)) {
float x = ((level.cellX(i)) + Random.Float()) * size;
float y = ((level.cellY(i)) + Random.Float()) * size;



y+= Gizmo.isometricShift();
factory.emit( this, index, x, y );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.watabou.pixeldungeon.items.food.RottenFood;
import com.watabou.pixeldungeon.items.weapon.missiles.Arrow;
import com.watabou.pixeldungeon.items.weapon.missiles.CommonArrow;
import com.watabou.pixeldungeon.levels.Level;
import com.watabou.pixeldungeon.utils.BArray;
import com.watabou.pixeldungeon.utils.GLog;
import com.watabou.utils.PathFinder;
Expand All @@ -32,15 +33,15 @@ public class PotionOfPurity extends UpgradablePotion{

@Override
public void shatter(int cell) {

PathFinder.buildDistanceMap(cell, BArray.not(Dungeon.level.losBlocking, null), (int) (DISTANCE * qualityFactor()));
Level level = getOwner().level();
PathFinder.buildDistanceMap(cell, BArray.not(level.losBlocking, null), (int) (DISTANCE * qualityFactor()));

boolean procd = false;

Blob[] blobs = {
Dungeon.level.blobs.get(ToxicGas.class),
Dungeon.level.blobs.get(ParalyticGas.class),
Dungeon.level.blobs.get(ConfusionGas.class)
level.blobs.get(ToxicGas.class),
level.blobs.get(ParalyticGas.class),
level.blobs.get(ConfusionGas.class)
};

for (Blob blob : blobs) {
Expand All @@ -49,7 +50,7 @@ public void shatter(int cell) {
continue;
}

for (int i = 0; i < Dungeon.level.getLength(); i++) {
for (int i = 0; i < level.getLength(); i++) {
if (PathFinder.distance[i] < Integer.MAX_VALUE) {

int value = blob.cur[i];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ public void create() {
}

protected void initSizeDependentStuff() {

GLog.debug("Level: initSizeDependentStuff: "+levelId);
Dungeon.initSizeDependentStuff(getWidth(), getHeight());
NEIGHBOURS4 = new int[]{-getWidth(), +1, +getWidth(), -1};
NEIGHBOURS5 = new int[]{0, -getWidth(), +1, +getWidth(), -1};
Expand Down
Loading

0 comments on commit 2530a69

Please sign in to comment.