v0.9.2: added checks to reduce levelgen hanging

This commit is contained in:
Evan Debenham 2021-02-19 18:58:25 -05:00
parent 4cc28b269a
commit 75e8ba7fd9
2 changed files with 10 additions and 2 deletions

View File

@ -504,7 +504,8 @@ public abstract class RegularLevel extends Level {
}
protected int randomDropCell( Class<?extends Room> roomType ) {
while (true) {
int tries = 100;
while (tries-- > 0) {
Room room = randomRoom( roomType );
if (room == null){
return -1;
@ -529,6 +530,7 @@ public abstract class RegularLevel extends Level {
}
}
}
return -1;
}
@Override

View File

@ -33,7 +33,8 @@ public abstract class PatchRoom extends StandardRoom {
protected boolean[] patch;
protected void setupPatch(Level level, float fill, int clustering, boolean ensurePath){
int attempts = 0;
if (ensurePath){
PathFinder.setMapSize(width()-2, height()-2);
boolean valid;
@ -69,6 +70,11 @@ public abstract class PatchRoom extends StandardRoom {
break;
}
}
attempts++;
if (attempts > 100){
fill -= 0.01f;
attempts = 0;
}
} while (!valid);
PathFinder.setMapSize(level.width(), level.height());
} else {