pub mod topdown;
use crate::config::NormalizedConfig;
use crate::error::PcgResult;
use crate::layout::LayoutOutput;
use crate::model::request::Constraint;
use crate::model::result::GenerationResult;
use crate::model::room::{DoorAnchor, Room, RoomGraph};
use crate::model::terrain::Terrain;
use crate::rng::StableRng;
use crate::spawn::{SpawnOutput, SpawnOutputWithDebug};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum ValidationScope {
FullFloor,
Chunk,
}
pub(crate) trait PipelineBackend: Send + Sync {
fn solve_layout(
&self,
graph: &RoomGraph,
config: &NormalizedConfig,
rng: &mut StableRng,
) -> PcgResult<LayoutOutput>;
fn generate_terrains(
&self,
rooms: &[Room],
door_anchors: &[DoorAnchor],
config: &NormalizedConfig,
rng: &mut StableRng,
) -> PcgResult<Vec<Terrain>>;
fn generate_spawns(
&self,
rooms: &[Room],
terrains: &[Terrain],
config: &NormalizedConfig,
rng: &StableRng,
) -> PcgResult<SpawnOutput>;
fn generate_spawns_with_debug(
&self,
rooms: &[Room],
terrains: &[Terrain],
config: &NormalizedConfig,
rng: &StableRng,
) -> PcgResult<SpawnOutputWithDebug>;
fn validate(
&self,
result: &GenerationResult,
config: &NormalizedConfig,
constraints: &[Constraint],
scope: ValidationScope,
) -> PcgResult<()>;
}
pub(crate) enum Backend {
TopDown(topdown::TopDownBackend),
}
impl PipelineBackend for Backend {
fn solve_layout(
&self,
graph: &RoomGraph,
config: &NormalizedConfig,
rng: &mut StableRng,
) -> PcgResult<LayoutOutput> {
match self {
Self::TopDown(b) => b.solve_layout(graph, config, rng),
}
}
fn generate_terrains(
&self,
rooms: &[Room],
door_anchors: &[DoorAnchor],
config: &NormalizedConfig,
rng: &mut StableRng,
) -> PcgResult<Vec<Terrain>> {
match self {
Self::TopDown(b) => b.generate_terrains(rooms, door_anchors, config, rng),
}
}
fn generate_spawns(
&self,
rooms: &[Room],
terrains: &[Terrain],
config: &NormalizedConfig,
rng: &StableRng,
) -> PcgResult<SpawnOutput> {
match self {
Self::TopDown(b) => b.generate_spawns(rooms, terrains, config, rng),
}
}
fn generate_spawns_with_debug(
&self,
rooms: &[Room],
terrains: &[Terrain],
config: &NormalizedConfig,
rng: &StableRng,
) -> PcgResult<SpawnOutputWithDebug> {
match self {
Self::TopDown(b) => b.generate_spawns_with_debug(rooms, terrains, config, rng),
}
}
fn validate(
&self,
result: &GenerationResult,
config: &NormalizedConfig,
constraints: &[Constraint],
scope: ValidationScope,
) -> PcgResult<()> {
match self {
Self::TopDown(b) => b.validate(result, config, constraints, scope),
}
}
}
pub(crate) fn select_backend(_config: &NormalizedConfig) -> Backend {
Backend::TopDown(topdown::TopDownBackend)
}