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

View File

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