BSP: include walls in room boundary

This commit is contained in:
Pyrex 2023-09-20 21:08:46 -07:00
parent c4c2b26653
commit 757cca1392
3 changed files with 12 additions and 71 deletions

View File

@ -29,16 +29,11 @@ void main() async {
int seed = 0; int seed = 0;
while (true) { while (true) {
Vault output = Generator(math.Random(seed), vaults).generateBoxed( Vault output = Generator(math.Random(seed), vaults).generate(Requirement(
Requirement( 32,
32, 24,
24, DirectionSet(
DirectionSet({ {Direction.up, Direction.left, Direction.right, Direction.down})));
Direction.up,
Direction.left,
Direction.right,
Direction.down
})));
var w = output.vx; var w = output.vx;
var h = output.vy; var h = output.vy;
for (var y = 0; y < h; y++) { for (var y = 0; y < h; y++) {

View File

@ -20,21 +20,6 @@ class Generator {
Generator(this._random, this._vaults); Generator(this._random, this._vaults);
Vault generateBoxed(Requirement req) {
var vx = req.vx;
var vy = req.vy;
var v = Vault.blank(vx, vy, req.smooth, VaultTile.wall);
if (req.vx < 2 || req.vy < 2) {
return v;
}
var req2 = Requirement(vx - 2, vy - 2, req.smooth);
var inner = generate(req2);
v.blitFrom(inner, 1, 1);
return v;
}
Vault generate(Requirement requirement) { Vault generate(Requirement requirement) {
Vault? suggested = _suggest(vaultTries, requirement); Vault? suggested = _suggest(vaultTries, requirement);
if (suggested != null) { if (suggested != null) {
@ -66,21 +51,23 @@ class Generator {
var vy = req.vy; var vy = req.vy;
var v = Vault.blank(vx, vy, req.smooth, VaultTile.wall); var v = Vault.blank(vx, vy, req.smooth, VaultTile.wall);
if (vx < 5 || vx * vy < 10) { if (vx < 2 || vy < 2) {
v.clear(VaultTile.bspfloor); } else if (vx < 9 || (vx - 2) * (vy - 2) < 12) {
var v2 = Vault.blank(vx - 2, vy - 2, req.smooth, VaultTile.bspfloor);
v.blitFrom(v2, 1, 1);
} else { } else {
// pick a split point // pick a split point
var splitVx = _random.nextInt(vx - 4) + 2; var splitVx = _random.nextInt(vx - 8) + 4;
var reqLeft = Requirement(splitVx, vy, req.smooth.clone()); var reqLeft = Requirement(splitVx, vy, req.smooth.clone());
reqLeft.smooth.directions.add(Direction.right); reqLeft.smooth.directions.add(Direction.right);
var reqRight = Requirement((vx - splitVx - 1), vy, req.smooth.clone()); var reqRight = Requirement((vx - splitVx + 1), vy, req.smooth.clone());
reqRight.smooth.directions.add(Direction.left); reqRight.smooth.directions.add(Direction.left);
var vaultLeft = generate(reqLeft); var vaultLeft = generate(reqLeft);
var vaultRight = generate(reqRight); var vaultRight = generate(reqRight);
v.blitFrom(vaultLeft, 0, 0); v.blitFrom(vaultLeft, 0, 0);
v.blitFrom(vaultRight, splitVx + 1, 0); v.blitFrom(vaultRight, splitVx - 1, 0);
} }
return v; return v;

View File

@ -9,47 +9,6 @@ class Vault {
assert(tiles.length == vx * vy); assert(tiles.length == vx * vy);
} }
// TODO: We should be assessing this based on whether the pattern in the input
// PNG had right-angled borders on this side, not based on the literal
// presence or absence of walls
//
// In other words, this is wrong.
static Vault fromVaultData(int vx, int vy, List<VaultTile> tiles) {
assert(tiles.length == vx * vy);
var smooth = {
Direction.up,
Direction.left,
Direction.down,
Direction.right
};
for (var x = 0; x < vx; x++) {
if (tiles[x + 0 * vx] == VaultTile.wall) {
smooth.remove(Direction.up);
break;
}
}
for (var x = 0; x < vx; x++) {
if (tiles[x + (vy - 1) * vx] == VaultTile.wall) {
smooth.remove(Direction.down);
break;
}
}
for (var y = 0; y < vy; y++) {
if (tiles[0 + y * vx] == VaultTile.wall) {
smooth.remove(Direction.left);
break;
}
}
for (var y = 0; y < vy; y++) {
if (tiles[vx - 1 + y * vx] == VaultTile.wall) {
smooth.remove(Direction.right);
break;
}
}
return Vault(vx, vy, DirectionSet(smooth), tiles);
}
void clear(VaultTile lt) { void clear(VaultTile lt) {
for (var y = 0; y < vy; y++) { for (var y = 0; y < vy; y++) {
for (var x = 0; x < vx; x++) { for (var x = 0; x < vx; x++) {