mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Add entity spawn on painter
This commit is contained in:
parent
d05cb99007
commit
e21f04d456
@ -44,7 +44,7 @@ fn main() -> Result {
|
|||||||
CanvasInfo::with_mock_canvas_info(index.as_index_ref(), world.sim(), |canvas| {
|
CanvasInfo::with_mock_canvas_info(index.as_index_ref(), world.sim(), |canvas| {
|
||||||
for plot in site.plots() {
|
for plot in site.plots() {
|
||||||
if let PlotKind::Dungeon(dungeon) = plot.kind() {
|
if let PlotKind::Dungeon(dungeon) = plot.kind() {
|
||||||
let (prim_tree, fills) = dungeon.render_collect(&site, canvas);
|
let (prim_tree, fills, _entities) = dungeon.render_collect(&site, canvas);
|
||||||
|
|
||||||
for (prim, fill) in fills {
|
for (prim, fill) in fills {
|
||||||
let aabb = fill.get_bounds(&prim_tree, prim);
|
let aabb = fill.get_bounds(&prim_tree, prim);
|
||||||
|
@ -6,6 +6,7 @@ use crate::{
|
|||||||
CanvasInfo,
|
CanvasInfo,
|
||||||
};
|
};
|
||||||
use common::{
|
use common::{
|
||||||
|
generation::EntityInfo,
|
||||||
store::{Id, Store},
|
store::{Id, Store},
|
||||||
terrain::{
|
terrain::{
|
||||||
structure::{Structure as PrefabStructure, StructureBlock},
|
structure::{Structure as PrefabStructure, StructureBlock},
|
||||||
@ -665,6 +666,7 @@ impl Fill {
|
|||||||
pub struct Painter {
|
pub struct Painter {
|
||||||
prims: RefCell<Store<Primitive>>,
|
prims: RefCell<Store<Primitive>>,
|
||||||
fills: RefCell<Vec<(Id<Primitive>, Fill)>>,
|
fills: RefCell<Vec<(Id<Primitive>, Fill)>>,
|
||||||
|
entities: RefCell<Vec<EntityInfo>>,
|
||||||
render_area: Aabr<i32>,
|
render_area: Aabr<i32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1035,7 +1037,15 @@ impl Painter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The area that the canvas is currently rendering.
|
||||||
pub fn render_aabr(&self) -> Aabr<i32> { self.render_area }
|
pub fn render_aabr(&self) -> Aabr<i32> { self.render_area }
|
||||||
|
|
||||||
|
/// Spawns an entity if it is in the render_aabr, otherwise does nothing.
|
||||||
|
pub fn spawn(&self, entity: EntityInfo) {
|
||||||
|
if self.render_area.contains_point(entity.pos.xy().as_()) {
|
||||||
|
self.entities.borrow_mut().push(entity)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
@ -1188,10 +1198,15 @@ pub trait Structure {
|
|||||||
&self,
|
&self,
|
||||||
site: &Site,
|
site: &Site,
|
||||||
canvas: &CanvasInfo,
|
canvas: &CanvasInfo,
|
||||||
) -> (Store<Primitive>, Vec<(Id<Primitive>, Fill)>) {
|
) -> (
|
||||||
|
Store<Primitive>,
|
||||||
|
Vec<(Id<Primitive>, Fill)>,
|
||||||
|
Vec<EntityInfo>,
|
||||||
|
) {
|
||||||
let painter = Painter {
|
let painter = Painter {
|
||||||
prims: RefCell::new(Store::default()),
|
prims: RefCell::new(Store::default()),
|
||||||
fills: RefCell::new(Vec::new()),
|
fills: RefCell::new(Vec::new()),
|
||||||
|
entities: RefCell::new(Vec::new()),
|
||||||
render_area: Aabr {
|
render_area: Aabr {
|
||||||
min: canvas.wpos,
|
min: canvas.wpos,
|
||||||
max: canvas.wpos + TerrainChunkSize::RECT_SIZE.map(|e| e as i32),
|
max: canvas.wpos + TerrainChunkSize::RECT_SIZE.map(|e| e as i32),
|
||||||
@ -1199,7 +1214,11 @@ pub trait Structure {
|
|||||||
};
|
};
|
||||||
|
|
||||||
self.render(site, &canvas.land(), &painter);
|
self.render(site, &canvas.land(), &painter);
|
||||||
(painter.prims.into_inner(), painter.fills.into_inner())
|
(
|
||||||
|
painter.prims.into_inner(),
|
||||||
|
painter.fills.into_inner(),
|
||||||
|
painter.entities.into_inner(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Extend a 2d AABR to a 3d AABB
|
/// Extend a 2d AABR to a 3d AABB
|
||||||
|
@ -984,7 +984,7 @@ impl Site {
|
|||||||
let info = canvas.info();
|
let info = canvas.info();
|
||||||
|
|
||||||
for plot in plots_to_render {
|
for plot in plots_to_render {
|
||||||
let (prim_tree, fills) = match &self.plots[plot].kind {
|
let (prim_tree, fills, entities) = match &self.plots[plot].kind {
|
||||||
PlotKind::House(house) => house.render_collect(self, canvas),
|
PlotKind::House(house) => house.render_collect(self, canvas),
|
||||||
PlotKind::Workshop(workshop) => workshop.render_collect(self, canvas),
|
PlotKind::Workshop(workshop) => workshop.render_collect(self, canvas),
|
||||||
PlotKind::Castle(castle) => castle.render_collect(self, canvas),
|
PlotKind::Castle(castle) => castle.render_collect(self, canvas),
|
||||||
@ -994,6 +994,10 @@ impl Site {
|
|||||||
_ => continue,
|
_ => continue,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
for entity in entities {
|
||||||
|
canvas.spawn(entity);
|
||||||
|
}
|
||||||
|
|
||||||
for (prim, fill) in fills {
|
for (prim, fill) in fills {
|
||||||
for mut aabb in fill.get_bounds_disjoint(&prim_tree, prim) {
|
for mut aabb in fill.get_bounds_disjoint(&prim_tree, prim) {
|
||||||
aabb.min = Vec2::max(aabb.min.xy(), chunk_aabr.min).with_z(aabb.min.z);
|
aabb.min = Vec2::max(aabb.min.xy(), chunk_aabr.min).with_z(aabb.min.z);
|
||||||
|
Loading…
Reference in New Issue
Block a user