Browse Source

Fixed world generator invocation

master
Thomas Johnson 3 years ago
parent
commit
a948222629
  1. 43
      src/world/gen.rs

43
src/world/gen.rs

@ -24,12 +24,26 @@ pub mod extra_utils
{
use rogue_util::coord::{R2i, V2i};
pub fn enlarge_rect(rect: R2i, upper: V2i, lower: V2i)
pub fn enlarge_rect(rect: R2i, upper: V2i, lower: V2i) -> R2i
{
R2i::origin_dim(rect.origin() - lower, rect.dim() + upper + lower)
}
pub fn rects_have_intersection_or_common_edge(r1: R2i, r2: R2i) -> bool
{
let enlarged = enlarge_rect(r1, V2i(1, 1), V2i(1, 1));
if let Some(_) = enlarged.intersect(r2)
{
true
} else
{
false
}
}
}
use extra_utils::*;
#[derive(Clone, Debug)]
enum RoomShape
{
@ -123,13 +137,36 @@ fn carve_rooms<T: Iterator<Item=RoomShape>>(map: &mut [Tile], shapes: T)
RoomShape::Rect(rect) => true,
RoomShape::Circ(c, r) => (tile - c).l2_sq() < r * r,
} {
map[(tile.0 * GRID_SIZE + tile.1) as usize].content = Content::Stone;
map[(tile.0 * GRID_SIZE + tile.1) as usize].content = Content::Air;
}
}
}
}
}
fn test_rooms_intersect(rs1: RoomShape, rs2: RoomShape) -> bool
{
use RoomShape::*;
match (rs1, rs2)
{
(Rect(r1), Rect(r2)) => rects_have_intersection_or_common_edge(r1, r2),
(Rect(r), Circ(c, rad)) |
(Circ(c, rad), Rect(r)) =>
{
enlarge_rect(r, V2i(1, 1), V2i(1, 1)).iter().fold(false, |b, t| b | ((c - t).l2_sq() < rad * rad))
},
(Circ(c1, r1), Circ(c2, r2)) =>
{
let dist2 = ((c2 - c1).l2_sq() as f64).sqrt();
(r1 as f64).sqrt() + (r2 as f64).sqrt() > dist2 + 1.0
},
}
}
fn hash_unique_pair<H: Hasher>(rs1: RoomShape, rs2: RoomShape)
{
}
pub fn carve(seed: u64, grid: &mut Grid<Tile>, coords: V2i)
{
let rsi = get_nearby_room_shapes(seed, coords);

Loading…
Cancel
Save