v0.9.2: added checks to reduce levelgen hanging
This commit is contained in:
parent
4cc28b269a
commit
75e8ba7fd9
|
@ -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
|
||||||
|
|
|
@ -33,7 +33,8 @@ public abstract class PatchRoom extends StandardRoom {
|
||||||
protected boolean[] patch;
|
protected boolean[] patch;
|
||||||
|
|
||||||
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 {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user