mod grid;
mod index;
mod run;
mod schedule;
use std::time::Duration;
pub use self::grid::{Aabb, Shape};
pub use self::index::{CollisionGroup, CollisionIndex, Item, Overlap, RetainedQueryData};
pub(crate) use self::run::{ErasedPlacement, Placements, participant};
#[cfg(feature = "bench")]
pub(crate) use self::run::{place_alone, placing_layers};
pub(crate) use self::schedule::{PlacementController, PlacementInputs};
use crate::camera::View;
use crate::draw::identity::SimpleIdentity;
use crate::layer::bucket::{Bucket, ErasedBucket};
pub(crate) use crate::layer::layer_drawing::ChangedBuckets;
use crate::layer::layer_type::EvaluatedLayer;
use crate::layer::render_layer::Layer;
use crate::map::MapMode;
use crate::render::terrain::TerrainElevation;
use crate::render::tile::FrameTile;
use crate::tile::OverscaledTileID;
use crate::worker::job::SourceKey;
pub trait Placement: Default + 'static {
type Layer: Layer;
fn collect(&mut self, layer: &CollectCx<'_, Self::Layer>, tiles: &[FrameTile<'_, Self::Layer>]) -> bool;
fn begin_frame(&mut self);
fn prepare(&mut self, layers: &[PlacingLayer], cx: &mut PrepareCx<'_>) -> Prepared;
fn begin(&mut self, cx: &mut PlaceCx<'_>);
fn place_crossing(&mut self, _layers: &[PlacingLayer], _cx: &mut PlaceCx<'_>) {}
fn place(&mut self, layer: &PlacingLayer, cx: &mut PlaceCx<'_>);
fn commit(&mut self, cx: &mut CommitCx<'_>) -> Placed;
fn update(&mut self, cx: &mut UpdateCx<'_>);
fn forget_buckets(&mut self);
fn forget_placement(&mut self);
}
pub struct CollectCx<'a, L: Layer> {
pub key: usize,
pub values: &'a EvaluatedLayer<L::Style>,
pub source: Option<SourceKey>,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct PlacingLayer {
pub key: usize,
pub position: usize,
pub group: CollisionGroup,
}
pub struct PrepareCx<'a> {
pub view: &'a View,
pub ground: Option<&'a TerrainElevation>,
pub buckets: PlacementBuckets<'a>,
}
pub struct PlaceCx<'a> {
pub index: &'a mut CollisionIndex,
pub view: &'a View,
pub mode: MapMode,
pub ground: Option<&'a TerrainElevation>,
pub buckets: &'a dyn LaidBuckets,
pub records: Option<&'a mut Vec<PlacedSymbolData>>,
}
pub struct CommitCx<'a> {
pub mode: MapMode,
pub fade: f32,
pub buckets: PlacementBuckets<'a>,
}
pub struct UpdateCx<'a> {
pub view: &'a View,
pub mode: MapMode,
pub placed: bool,
pub ground: Option<&'a TerrainElevation>,
pub index: &'a mut CollisionIndex,
pub buckets: PlacementBuckets<'a>,
pub changed: &'a mut ChangedBuckets,
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct Prepared {
pub added: bool,
pub changed: bool,
}
impl Prepared {
pub(crate) const SOON: Duration = Duration::from_millis(30);
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct Placed {
pub changed: bool,
pub settled: bool,
}
impl Default for Placed {
fn default() -> Self {
Placed { changed: false, settled: true }
}
}
impl std::ops::BitOrAssign for Placed {
fn bitor_assign(&mut self, other: Placed) {
self.changed |= other.changed;
self.settled &= other.settled;
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct PlacedSymbolData {
pub key: String,
pub text_collision_box: Option<Aabb>,
pub icon_collision_box: Option<Aabb>,
pub text_placed: bool,
pub icon_placed: bool,
pub intersects_tile_border: bool,
pub viewport_padding: f32,
pub layer: String,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct BucketKey {
pub bucket: usize,
pub slot: Option<usize>,
pub tile: OverscaledTileID,
pub source: SourceKey,
}
pub trait LaidBuckets {
fn id(&self, key: &BucketKey) -> Option<SimpleIdentity>;
fn bucket(&self, key: &BucketKey) -> Option<&dyn ErasedBucket>;
fn bucket_mut(&mut self, key: &BucketKey) -> Option<&mut dyn ErasedBucket>;
}
impl dyn LaidBuckets + '_ {
pub fn get<B: Bucket>(&self, key: &BucketKey) -> Option<&B> {
self.bucket(key)?.downcast_ref()
}
}
pub struct PlacementBuckets<'a> {
store: &'a mut dyn LaidBuckets,
}
impl<'a> PlacementBuckets<'a> {
pub(crate) fn new(store: &'a mut dyn LaidBuckets) -> Self {
PlacementBuckets { store }
}
#[must_use]
pub fn id(&self, key: &BucketKey) -> Option<SimpleIdentity> {
self.store.id(key)
}
pub fn get_mut<B: Bucket>(&mut self, key: &BucketKey) -> Option<&mut B> {
self.store.bucket_mut(key)?.downcast_mut()
}
#[must_use]
pub fn store(&self) -> &dyn LaidBuckets {
self.store
}
}