Fix map
This commit is contained in:
parent
7253251e9d
commit
d7a58d7352
8 changed files with 147 additions and 201 deletions
|
@ -87,6 +87,10 @@ impl World {
|
||||||
self.entity_object_manager.create_entity()
|
self.entity_object_manager.create_entity()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn clone_without_components(&mut self, entity: &EntityObject) -> EntityObject {
|
||||||
|
entity.clone_without_components(self.entity_object_manager.fetch_add_entity_id())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn entities(&self) -> impl Iterator<Item = &EntityObject> {
|
pub fn entities(&self) -> impl Iterator<Item = &EntityObject> {
|
||||||
self.entities.values()
|
self.entities.values()
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,11 @@ use crate::prelude::*;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
|
||||||
pub trait AssetLoader {
|
pub trait AssetLoader {
|
||||||
fn load_entity(&mut self, assets: AssetHandler<'_>, entity_file: &str) -> Result<EntityObject>;
|
fn load_entity(
|
||||||
|
&mut self,
|
||||||
|
assets: &mut AssetHandler<'_>,
|
||||||
|
entity_file: &str,
|
||||||
|
) -> Result<EntityObject>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct AssetHandler<'a> {
|
pub struct AssetHandler<'a> {
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
use std::any::Any;
|
|
||||||
|
|
||||||
use crate::prelude::*;
|
|
||||||
|
|
||||||
use anyhow::Result;
|
|
||||||
use utilities::prelude::cgmath::{Vector2, Vector3};
|
|
||||||
|
|
||||||
pub trait Map: Any + Send + Sync {
|
|
||||||
fn name(&self) -> &str;
|
|
||||||
|
|
||||||
fn check_walkability(
|
|
||||||
&self,
|
|
||||||
position: Vector2<f32>,
|
|
||||||
direction: Vector2<f32>,
|
|
||||||
radius: f32,
|
|
||||||
) -> Result<bool>;
|
|
||||||
|
|
||||||
fn get_height(&self, x: f32, y: f32) -> Result<f32>;
|
|
||||||
|
|
||||||
fn spawn_positions(&self) -> Result<Vec<Vector3<f32>>>;
|
|
||||||
fn leave_markers(&self) -> Result<Vec<Entity>>;
|
|
||||||
|
|
||||||
fn disable(&self, scene: &mut Scene) -> Result<()>;
|
|
||||||
}
|
|
|
@ -1,5 +1,4 @@
|
||||||
pub mod components;
|
pub mod components;
|
||||||
|
|
||||||
pub mod map;
|
|
||||||
pub mod prelude;
|
pub mod prelude;
|
||||||
// mod query;
|
// mod query;
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
pub use super::map::Map;
|
|
||||||
|
|
||||||
pub use super::components::{animation::Animation, audio::Audio, draw::Draw};
|
pub use super::components::{animation::Animation, audio::Audio, draw::Draw};
|
||||||
|
|
||||||
pub use super::components::{
|
pub use super::components::{
|
||||||
|
|
|
@ -126,7 +126,7 @@ impl AssetLoader for EntityManager {
|
||||||
/// Loads an entity file and creates an Entity
|
/// Loads an entity file and creates an Entity
|
||||||
fn load_entity(
|
fn load_entity(
|
||||||
&mut self,
|
&mut self,
|
||||||
mut assets: AssetHandler<'_>,
|
assets: &mut AssetHandler<'_>,
|
||||||
entity_file: &str,
|
entity_file: &str,
|
||||||
) -> Result<EntityObject> {
|
) -> Result<EntityObject> {
|
||||||
// load entity file
|
// load entity file
|
||||||
|
|
192
map/src/map.rs
192
map/src/map.rs
|
@ -2,7 +2,6 @@
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use assetpath::AssetPath;
|
use assetpath::AssetPath;
|
||||||
|
|
||||||
use engine::prelude::PrimitiveMaterial;
|
|
||||||
use engine::prelude::*;
|
use engine::prelude::*;
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
|
@ -12,25 +11,19 @@ use super::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::async_db::AsyncDBAccess;
|
use super::async_db::AsyncDBAccess;
|
||||||
|
|
||||||
use super::map_db::{DBEntityInfo, MapDataBase};
|
use super::map_db::{DBEntityInfo, MapDataBase};
|
||||||
|
|
||||||
// std
|
// std
|
||||||
|
|
||||||
use std::cmp::{max, min};
|
use std::cmp::{max, min};
|
||||||
|
use std::collections::HashMap;
|
||||||
use std::sync::atomic::{AtomicBool, Ordering::SeqCst};
|
|
||||||
|
|
||||||
use std::sync::{Arc, RwLock};
|
|
||||||
|
|
||||||
use std::{collections::HashMap, intrinsics::transmute};
|
|
||||||
|
|
||||||
use std::ops::IndexMut;
|
use std::ops::IndexMut;
|
||||||
|
use std::sync::atomic::{AtomicBool, Ordering::SeqCst};
|
||||||
|
use std::sync::{Arc, RwLock};
|
||||||
|
|
||||||
// cgmath
|
// cgmath
|
||||||
|
|
||||||
use cgmath::Rad;
|
use cgmath::Rad;
|
||||||
|
|
||||||
use cgmath::{InnerSpace, Vector2, Vector3, Zero, vec2};
|
use cgmath::{InnerSpace, Vector2, Vector3, Zero, vec2};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
|
@ -58,16 +51,11 @@ impl Map {
|
||||||
// describes the length of a chunk (e.g.: 10 in x and in y direction = 100 tiles per chunk)
|
// describes the length of a chunk (e.g.: 10 in x and in y direction = 100 tiles per chunk)
|
||||||
const CHUNK_DIMENSION: u32 = 10;
|
const CHUNK_DIMENSION: u32 = 10;
|
||||||
|
|
||||||
pub fn downcast(upcasted: &Box<dyn engine::prelude::Map>) -> &Box<Self> {
|
|
||||||
unsafe { transmute(destructure_traitobject::data(upcasted)) }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new(
|
pub fn new(
|
||||||
name: &str,
|
name: &str,
|
||||||
width: u32,
|
width: u32,
|
||||||
height: u32,
|
height: u32,
|
||||||
engine: &Engine,
|
world: &mut World,
|
||||||
scene: &mut Scene,
|
|
||||||
maps: &mut HashMap<String, AssetPath>,
|
maps: &mut HashMap<String, AssetPath>,
|
||||||
tiles: &HashMap<String, AssetPath>,
|
tiles: &HashMap<String, AssetPath>,
|
||||||
entity_manager: &mut impl AssetLoader,
|
entity_manager: &mut impl AssetLoader,
|
||||||
|
@ -76,8 +64,8 @@ impl Map {
|
||||||
let map_path = build_path(&("maps/".to_string() + name));
|
let map_path = build_path(&("maps/".to_string() + name));
|
||||||
|
|
||||||
let sql_connection = MapDataBase::new(map_path.full_path(), name, width, height)?;
|
let sql_connection = MapDataBase::new(map_path.full_path(), name, width, height)?;
|
||||||
let map = Self::load_data_from_db(engine, scene, sql_connection, tiles, entity_manager)?;
|
let map = Self::load_data_from_db(world, sql_connection, tiles, entity_manager)?;
|
||||||
scene.set_map(Some(Box::new(map)))?;
|
world.resources.insert(map);
|
||||||
|
|
||||||
maps.insert(name.to_string(), map_path);
|
maps.insert(name.to_string(), map_path);
|
||||||
|
|
||||||
|
@ -85,15 +73,14 @@ impl Map {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load_raw_scene(
|
pub fn load_raw_scene(
|
||||||
engine: &Engine,
|
world: &mut World,
|
||||||
scene: &mut Scene,
|
|
||||||
path: AssetPath,
|
path: AssetPath,
|
||||||
tiles: &HashMap<String, AssetPath>,
|
tiles: &HashMap<String, AssetPath>,
|
||||||
entity_manager: &mut impl AssetLoader,
|
entity_manager: &mut impl AssetLoader,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let sql_connection = MapDataBase::load(&path.full_path())?;
|
let sql_connection = MapDataBase::load(&path.full_path())?;
|
||||||
let map = Self::load_data_from_db(engine, scene, sql_connection, tiles, entity_manager)?;
|
let map = Self::load_data_from_db(world, sql_connection, tiles, entity_manager)?;
|
||||||
scene.set_map(Some(Box::new(map)))?;
|
world.resources.insert(map);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -129,7 +116,7 @@ impl Map {
|
||||||
Self::calculate_chunk_and_primitive_indices(dx, dy);
|
Self::calculate_chunk_and_primitive_indices(dx, dy);
|
||||||
|
|
||||||
let chunk_entity = data.chunk_handles[&chunk];
|
let chunk_entity = data.chunk_handles[&chunk];
|
||||||
let entity = scene.entity_mut(chunk_entity)?;
|
let entity = world.entity_mut(chunk_entity)?;
|
||||||
|
|
||||||
let draw = entity.get_component_mut::<Draw>()?;
|
let draw = entity.get_component_mut::<Draw>()?;
|
||||||
let mesh = &mut draw[0];
|
let mesh = &mut draw[0];
|
||||||
|
@ -189,8 +176,8 @@ impl Map {
|
||||||
self.updated.store(true, SeqCst);
|
self.updated.store(true, SeqCst);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_height_at(&self, x: u32, y: u32, scene: &mut Scene) -> Result<()> {
|
pub fn check_height_at(&self, x: u32, y: u32, world: &mut World) -> Result<()> {
|
||||||
self.data.write().unwrap().check_height_at(x, y, scene)
|
self.data.write().unwrap().check_height_at(x, y, world)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn npc_spawn_info(&self, position: Vector2<f32>) -> Result<MapNPCSpawnInfo> {
|
pub fn npc_spawn_info(&self, position: Vector2<f32>) -> Result<MapNPCSpawnInfo> {
|
||||||
|
@ -245,13 +232,13 @@ impl Map {
|
||||||
|
|
||||||
pub fn change_npc_spawn(
|
pub fn change_npc_spawn(
|
||||||
&self,
|
&self,
|
||||||
scene_contents: &mut impl SceneEntities,
|
world: &mut World,
|
||||||
position: Vector2<f32>,
|
position: Vector2<f32>,
|
||||||
npc_spawn_parameter: NPCSpawnParameter,
|
npc_spawn_parameter: NPCSpawnParameter,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.data.write().unwrap().change_npc_spawn(
|
self.data.write().unwrap().change_npc_spawn(
|
||||||
&self.async_db,
|
&self.async_db,
|
||||||
scene_contents,
|
world,
|
||||||
position,
|
position,
|
||||||
npc_spawn_parameter,
|
npc_spawn_parameter,
|
||||||
)?;
|
)?;
|
||||||
|
@ -273,7 +260,7 @@ impl Map {
|
||||||
x: u32,
|
x: u32,
|
||||||
y: u32,
|
y: u32,
|
||||||
texture: &Arc<Image>,
|
texture: &Arc<Image>,
|
||||||
scene: &mut impl SceneEntities,
|
world: &mut World,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let mut data = self.data.write().unwrap();
|
let mut data = self.data.write().unwrap();
|
||||||
|
|
||||||
|
@ -283,7 +270,7 @@ impl Map {
|
||||||
let (chunk, primitive_index) = Self::calculate_chunk_and_primitive_indices(x, y);
|
let (chunk, primitive_index) = Self::calculate_chunk_and_primitive_indices(x, y);
|
||||||
|
|
||||||
let chunk_entity = data.chunk_handles[&chunk];
|
let chunk_entity = data.chunk_handles[&chunk];
|
||||||
let entity = scene.entity_mut(chunk_entity)?;
|
let entity = world.entity_mut(chunk_entity)?;
|
||||||
|
|
||||||
let draw = entity.get_component_mut::<Draw>()?;
|
let draw = entity.get_component_mut::<Draw>()?;
|
||||||
let mesh = &mut draw[0];
|
let mesh = &mut draw[0];
|
||||||
|
@ -312,7 +299,7 @@ impl Map {
|
||||||
|
|
||||||
pub fn set_entity(
|
pub fn set_entity(
|
||||||
&self,
|
&self,
|
||||||
scene: &mut impl SceneEntities,
|
world: &mut World,
|
||||||
entity_opt: Option<(String, EntityObject)>,
|
entity_opt: Option<(String, EntityObject)>,
|
||||||
position: Vector2<f32>,
|
position: Vector2<f32>,
|
||||||
rotation: impl Into<Rad<f32>>,
|
rotation: impl Into<Rad<f32>>,
|
||||||
|
@ -320,18 +307,18 @@ impl Map {
|
||||||
self.data
|
self.data
|
||||||
.write()
|
.write()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.set_entity(scene, entity_opt, position, rotation, &self.async_db)
|
.set_entity(world, entity_opt, position, rotation, &self.async_db)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_spawn_location(
|
pub fn set_spawn_location(
|
||||||
&self,
|
&self,
|
||||||
scene: &mut impl SceneEntities,
|
world: &mut World,
|
||||||
entity_opt: Option<(String, EntityObject)>,
|
entity_opt: Option<(String, EntityObject)>,
|
||||||
position: Vector2<f32>,
|
position: Vector2<f32>,
|
||||||
rotation: impl Into<Rad<f32>>,
|
rotation: impl Into<Rad<f32>>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.data.write().unwrap().set_spawn_location(
|
self.data.write().unwrap().set_spawn_location(
|
||||||
scene,
|
world,
|
||||||
entity_opt,
|
entity_opt,
|
||||||
position,
|
position,
|
||||||
rotation,
|
rotation,
|
||||||
|
@ -339,19 +326,19 @@ impl Map {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn disable_spawns(&self, scene: &mut impl SceneEntities) -> Result<()> {
|
pub fn disable_spawns(&self, world: &mut World) -> Result<()> {
|
||||||
self.data.write().unwrap().disable_spawns(scene)
|
self.data.write().unwrap().disable_spawns(world)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_leave_location(
|
pub fn set_leave_location(
|
||||||
&self,
|
&self,
|
||||||
scene: &mut impl SceneEntities,
|
world: &mut World,
|
||||||
entity_opt: Option<(String, EntityObject)>,
|
entity_opt: Option<(String, EntityObject)>,
|
||||||
position: Vector2<f32>,
|
position: Vector2<f32>,
|
||||||
rotation: impl Into<Rad<f32>>,
|
rotation: impl Into<Rad<f32>>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.data.write().unwrap().set_leave_location(
|
self.data.write().unwrap().set_leave_location(
|
||||||
scene,
|
world,
|
||||||
entity_opt,
|
entity_opt,
|
||||||
position,
|
position,
|
||||||
rotation,
|
rotation,
|
||||||
|
@ -359,19 +346,19 @@ impl Map {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn toggle_npc_spawns(&self, engine: &Engine, scene: &mut impl SceneEntities) -> Result<()> {
|
pub fn toggle_npc_spawns(&self, world: &mut World) -> Result<()> {
|
||||||
self.data.write().unwrap().toggle_npc_spawns(engine, scene)
|
self.data.write().unwrap().toggle_npc_spawns(world)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_npc_spawn_marker(
|
pub fn set_npc_spawn_marker(
|
||||||
&self,
|
&self,
|
||||||
flag_name: &str,
|
flag_name: &str,
|
||||||
area_name: &str,
|
area_name: &str,
|
||||||
engine: &Engine,
|
world: &mut World,
|
||||||
entity_manager: &mut impl AssetLoader,
|
entity_manager: &mut impl AssetLoader,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.data.write().unwrap().npc_spawn_marker = Some(SpawnMarkerEntities::new(
|
self.data.write().unwrap().npc_spawn_marker = Some(SpawnMarkerEntities::new(
|
||||||
engine,
|
world,
|
||||||
entity_manager,
|
entity_manager,
|
||||||
flag_name,
|
flag_name,
|
||||||
area_name,
|
area_name,
|
||||||
|
@ -382,56 +369,38 @@ impl Map {
|
||||||
|
|
||||||
pub fn set_npc_spawn(
|
pub fn set_npc_spawn(
|
||||||
&self,
|
&self,
|
||||||
engine: &Engine,
|
|
||||||
scene: &mut impl SceneEntities,
|
world: &mut World,
|
||||||
position: Vector2<f32>,
|
position: Vector2<f32>,
|
||||||
radius: f32,
|
radius: f32,
|
||||||
min: u32,
|
min: u32,
|
||||||
max: u32,
|
max: u32,
|
||||||
) -> Result<()> {
|
|
||||||
self.data.write().unwrap().set_npc_spawn(
|
|
||||||
engine,
|
|
||||||
scene,
|
|
||||||
position,
|
|
||||||
&self.async_db,
|
|
||||||
radius,
|
|
||||||
min,
|
|
||||||
max,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn unset_npc_spawn(
|
|
||||||
&self,
|
|
||||||
scene: &mut impl SceneEntities,
|
|
||||||
position: Vector2<f32>,
|
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.data
|
self.data
|
||||||
.write()
|
.write()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.unset_npc_spawn(scene, position, &self.async_db)
|
.set_npc_spawn(world, position, &self.async_db, radius, min, max)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_boss_spawn(
|
pub fn unset_npc_spawn(&self, world: &mut World, position: Vector2<f32>) -> Result<()> {
|
||||||
&self,
|
|
||||||
engine: &Engine,
|
|
||||||
scene: &mut impl SceneEntities,
|
|
||||||
position: Vector2<f32>,
|
|
||||||
) -> Result<()> {
|
|
||||||
self.data
|
self.data
|
||||||
.write()
|
.write()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.set_boss_spawn(engine, scene, position, &self.async_db)
|
.unset_npc_spawn(world, position, &self.async_db)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn unset_boss_spawn(
|
pub fn set_boss_spawn(&self, world: &mut World, position: Vector2<f32>) -> Result<()> {
|
||||||
&self,
|
|
||||||
scene: &mut impl SceneEntities,
|
|
||||||
position: Vector2<f32>,
|
|
||||||
) -> Result<()> {
|
|
||||||
self.data
|
self.data
|
||||||
.write()
|
.write()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.unset_boss_spawn(scene, position, &self.async_db)
|
.set_boss_spawn(world, position, &self.async_db)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn unset_boss_spawn(&self, world: &mut World, position: Vector2<f32>) -> Result<()> {
|
||||||
|
self.data
|
||||||
|
.write()
|
||||||
|
.unwrap()
|
||||||
|
.unset_boss_spawn(world, position, &self.async_db)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -483,8 +452,7 @@ impl Map {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_tiles(
|
fn create_tiles(
|
||||||
engine: &Engine,
|
world: &mut World,
|
||||||
scene: &mut Scene,
|
|
||||||
textures: &HashMap<u32, OrderedElement<Arc<Image>>>,
|
textures: &HashMap<u32, OrderedElement<Arc<Image>>>,
|
||||||
width: u32,
|
width: u32,
|
||||||
height: u32,
|
height: u32,
|
||||||
|
@ -492,6 +460,9 @@ impl Map {
|
||||||
) -> Result<HashMap<(u32, u32), Entity>> {
|
) -> Result<HashMap<(u32, u32), Entity>> {
|
||||||
let tile_handles = Map::create_tile_handles(width, height, &surface);
|
let tile_handles = Map::create_tile_handles(width, height, &surface);
|
||||||
|
|
||||||
|
let context = world.resources.get_unchecked::<Context>();
|
||||||
|
let scene = world.resources.get_unchecked::<Scene>();
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
Self::verify_tile_handles(width, height, &tile_handles);
|
Self::verify_tile_handles(width, height, &tile_handles);
|
||||||
|
|
||||||
|
@ -511,7 +482,7 @@ impl Map {
|
||||||
let mut tile_entity = {
|
let mut tile_entity = {
|
||||||
let (tiles, bounding_box) = &tile_handles[&(chunk_x, chunk_y)];
|
let (tiles, bounding_box) = &tile_handles[&(chunk_x, chunk_y)];
|
||||||
|
|
||||||
let mut asset_mesh = AssetMesh::new(&scene.device(), scene.render_type())?;
|
let mut asset_mesh = AssetMesh::new(context.device(), scene.render_type())?;
|
||||||
|
|
||||||
for tile_x in 0..Self::CHUNK_DIMENSION {
|
for tile_x in 0..Self::CHUNK_DIMENSION {
|
||||||
for tile_y in 0..Self::CHUNK_DIMENSION {
|
for tile_y in 0..Self::CHUNK_DIMENSION {
|
||||||
|
@ -527,7 +498,7 @@ impl Map {
|
||||||
)
|
)
|
||||||
.set_memory_usage(MemoryUsage::CpuOnly)
|
.set_memory_usage(MemoryUsage::CpuOnly)
|
||||||
.set_data(&buffer_data)
|
.set_data(&buffer_data)
|
||||||
.build(engine.device().clone())?;
|
.build(context.device().clone())?;
|
||||||
|
|
||||||
asset_mesh.add_primitive(
|
asset_mesh.add_primitive(
|
||||||
buffer,
|
buffer,
|
||||||
|
@ -539,7 +510,7 @@ impl Map {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut entity_object = engine.assets().empty_entity();
|
let mut entity_object = AssetHandler::create(world).empty_entity();
|
||||||
|
|
||||||
entity_object.insert_component(Draw::new(vec![asset_mesh]));
|
entity_object.insert_component(Draw::new(vec![asset_mesh]));
|
||||||
entity_object.insert_component(bounding_box.clone());
|
entity_object.insert_component(bounding_box.clone());
|
||||||
|
@ -552,7 +523,7 @@ impl Map {
|
||||||
tile_entity.debug_name = Some(format!("Chunk ({}, {})", chunk_x, chunk_y));
|
tile_entity.debug_name = Some(format!("Chunk ({}, {})", chunk_x, chunk_y));
|
||||||
}
|
}
|
||||||
|
|
||||||
let entity = scene.add_entity(tile_entity)?;
|
let entity = world.add_entity(tile_entity)?;
|
||||||
|
|
||||||
tiles.insert((chunk_x, chunk_y), entity);
|
tiles.insert((chunk_x, chunk_y), entity);
|
||||||
}
|
}
|
||||||
|
@ -656,8 +627,7 @@ impl Map {
|
||||||
// DB load and create map handle
|
// DB load and create map handle
|
||||||
impl Map {
|
impl Map {
|
||||||
fn load_data_from_db(
|
fn load_data_from_db(
|
||||||
engine: &Engine,
|
world: &mut World,
|
||||||
scene: &mut Scene,
|
|
||||||
data_base: MapDataBase,
|
data_base: MapDataBase,
|
||||||
tiles: &HashMap<String, AssetPath>,
|
tiles: &HashMap<String, AssetPath>,
|
||||||
entity_manager: &mut impl AssetLoader,
|
entity_manager: &mut impl AssetLoader,
|
||||||
|
@ -671,6 +641,8 @@ impl Map {
|
||||||
let mob_spawn_locations = data_base.read_mob_spawn_locations()?;
|
let mob_spawn_locations = data_base.read_mob_spawn_locations()?;
|
||||||
let boss_spawn_locations = data_base.read_boss_spawn_locations()?;
|
let boss_spawn_locations = data_base.read_boss_spawn_locations()?;
|
||||||
|
|
||||||
|
let context = world.resources.get_unchecked::<Context>();
|
||||||
|
|
||||||
// check if the amount of tiles and points is correct
|
// check if the amount of tiles and points is correct
|
||||||
let tile_count = data_base.width() * data_base.height();
|
let tile_count = data_base.width() * data_base.height();
|
||||||
let point_count = (data_base.width() + 1) * (data_base.height() + 1);
|
let point_count = (data_base.width() + 1) * (data_base.height() + 1);
|
||||||
|
@ -727,8 +699,8 @@ impl Map {
|
||||||
let image = match tiles.get(&texture.name) {
|
let image = match tiles.get(&texture.name) {
|
||||||
Some(path) => Image::from_file(path.clone())?
|
Some(path) => Image::from_file(path.clone())?
|
||||||
.format(VK_FORMAT_R8G8B8A8_UNORM)
|
.format(VK_FORMAT_R8G8B8A8_UNORM)
|
||||||
.attach_sampler(Sampler::nearest_sampler().build(engine.device())?)
|
.attach_sampler(Sampler::nearest_sampler().build(context.device())?)
|
||||||
.build(engine.device(), engine.queue())?,
|
.build(context.device(), context.queue())?,
|
||||||
None => {
|
None => {
|
||||||
return Err(anyhow::Error::msg(format!(
|
return Err(anyhow::Error::msg(format!(
|
||||||
"Map: Image ({}) could not be found",
|
"Map: Image ({}) could not be found",
|
||||||
|
@ -785,34 +757,39 @@ impl Map {
|
||||||
map_tiles,
|
map_tiles,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let asset_manager = engine.assets();
|
let mut asset_manager = AssetHandler::create(unsafe { remove_life_time_mut(world) });
|
||||||
|
|
||||||
let entity_positions =
|
let entity_positions = Self::create_entity_alike(
|
||||||
Self::create_entity_alike(asset_manager, entity_manager, entity_pos, &surface, scene)?;
|
&mut asset_manager,
|
||||||
|
entity_manager,
|
||||||
|
entity_pos,
|
||||||
|
&surface,
|
||||||
|
world,
|
||||||
|
)?;
|
||||||
|
|
||||||
let spawn_positions = Self::create_entity_alike(
|
let spawn_positions = Self::create_entity_alike(
|
||||||
asset_manager,
|
&mut asset_manager,
|
||||||
entity_manager,
|
entity_manager,
|
||||||
spawn_locations,
|
spawn_locations,
|
||||||
&surface,
|
&surface,
|
||||||
scene,
|
world,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let mut spawns = HashMap::new();
|
let mut spawns = HashMap::new();
|
||||||
|
|
||||||
for (coordinate, entity) in spawn_positions.into_iter() {
|
for (coordinate, entity) in spawn_positions.into_iter() {
|
||||||
let e = scene.entity(entity)?;
|
let e = world.entity(entity)?;
|
||||||
let position = e.get_component::<Location>()?.position();
|
let position = e.get_component::<Location>()?.position();
|
||||||
|
|
||||||
spawns.insert(coordinate, (entity, position));
|
spawns.insert(coordinate, (entity, position));
|
||||||
}
|
}
|
||||||
|
|
||||||
let leave_positions = Self::create_entity_alike(
|
let leave_positions = Self::create_entity_alike(
|
||||||
asset_manager,
|
&mut asset_manager,
|
||||||
entity_manager,
|
entity_manager,
|
||||||
leave_locations,
|
leave_locations,
|
||||||
&surface,
|
&surface,
|
||||||
scene,
|
world,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let npc_spawn_positions = mob_spawn_locations
|
let npc_spawn_positions = mob_spawn_locations
|
||||||
|
@ -876,8 +853,7 @@ impl Map {
|
||||||
|
|
||||||
data: RwLock::new(MapData {
|
data: RwLock::new(MapData {
|
||||||
chunk_handles: Self::create_tiles(
|
chunk_handles: Self::create_tiles(
|
||||||
engine,
|
world,
|
||||||
scene,
|
|
||||||
&textures_info,
|
&textures_info,
|
||||||
data_base.width(),
|
data_base.width(),
|
||||||
data_base.height(),
|
data_base.height(),
|
||||||
|
@ -919,11 +895,11 @@ impl Map {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn create_entity_alike(
|
fn create_entity_alike(
|
||||||
asset_manager: AssetHandler<'_>,
|
asset_manager: &mut AssetHandler<'_>,
|
||||||
entity_manager: &mut impl AssetLoader,
|
entity_manager: &mut impl AssetLoader,
|
||||||
source: Vec<DBEntityInfo>,
|
source: Vec<DBEntityInfo>,
|
||||||
surface: &Surface,
|
surface: &Surface,
|
||||||
scene: &mut Scene,
|
world: &mut World,
|
||||||
) -> Result<HashMap<Coordinate, Entity>> {
|
) -> Result<HashMap<Coordinate, Entity>> {
|
||||||
let mut map = HashMap::new();
|
let mut map = HashMap::new();
|
||||||
|
|
||||||
|
@ -943,7 +919,7 @@ impl Map {
|
||||||
|
|
||||||
Location::new_and_setup(&mut entity_object)?.update_raw(position, info.rotation);
|
Location::new_and_setup(&mut entity_object)?.update_raw(position, info.rotation);
|
||||||
|
|
||||||
let entity = scene.add_entity(entity_object)?;
|
let entity = world.add_entity(entity_object)?;
|
||||||
|
|
||||||
map.insert(
|
map.insert(
|
||||||
Coordinate {
|
Coordinate {
|
||||||
|
@ -956,14 +932,12 @@ impl Map {
|
||||||
|
|
||||||
Ok(map)
|
Ok(map)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl engine::prelude::Map for Map {
|
pub fn name(&self) -> &str {
|
||||||
fn name(&self) -> &str {
|
|
||||||
&self.name
|
&self.name
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_walkability(
|
pub fn check_walkability(
|
||||||
&self,
|
&self,
|
||||||
position: Vector2<f32>,
|
position: Vector2<f32>,
|
||||||
direction: Vector2<f32>,
|
direction: Vector2<f32>,
|
||||||
|
@ -1010,45 +984,45 @@ impl engine::prelude::Map for Map {
|
||||||
Ok(true)
|
Ok(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_height(&self, x: f32, y: f32) -> Result<f32> {
|
pub fn get_height(&self, x: f32, y: f32) -> Result<f32> {
|
||||||
Ok(self.data.read().unwrap().get_height(x, y))
|
Ok(self.data.read().unwrap().get_height(x, y))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn spawn_positions(&self) -> Result<Vec<Vector3<f32>>> {
|
pub fn spawn_positions(&self) -> Result<Vec<Vector3<f32>>> {
|
||||||
Ok(self.data.read().unwrap().spawn_locations())
|
Ok(self.data.read().unwrap().spawn_locations())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn leave_markers(&self) -> Result<Vec<Entity>> {
|
pub fn leave_markers(&self) -> Result<Vec<Entity>> {
|
||||||
Ok(self.data.read().unwrap().leave_markers())
|
Ok(self.data.read().unwrap().leave_markers())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn disable(&self, scene: &mut Scene) -> Result<()> {
|
pub fn disable(&self, world: &mut World) -> Result<()> {
|
||||||
let data = self.data.read().unwrap();
|
let data = self.data.read().unwrap();
|
||||||
|
|
||||||
// clear tiles
|
// clear tiles
|
||||||
for chunk in data.chunk_handles.values() {
|
for chunk in data.chunk_handles.values() {
|
||||||
scene.remove_entity(*chunk)?;
|
world.remove_entity(*chunk)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// clear entities
|
// clear entities
|
||||||
for entity in data.entities.values() {
|
for entity in data.entities.values() {
|
||||||
scene.remove_entity(*entity)?;
|
world.remove_entity(*entity)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// clear spawns
|
// clear spawns
|
||||||
for (spawn, _) in data.spawn_locations.values() {
|
for (spawn, _) in data.spawn_locations.values() {
|
||||||
scene.remove_entity(*spawn)?;
|
world.remove_entity(*spawn)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// clear exits
|
// clear exits
|
||||||
for leave in data.leave_locations.values() {
|
for leave in data.leave_locations.values() {
|
||||||
scene.remove_entity(*leave)?;
|
world.remove_entity(*leave)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// clear npc spawns
|
// clear npc spawns
|
||||||
for (_, marker) in data.npc_spawn_areas.iter() {
|
for (_, marker) in data.npc_spawn_areas.iter() {
|
||||||
if let Some(marker) = marker {
|
if let Some(marker) = marker {
|
||||||
marker.remove(scene)?;
|
marker.remove(world)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ use engine::prelude::*;
|
||||||
use super::{async_db::AsyncDBAccess, map::MapObjectType, map_db::EntityDBType, surface::Surface};
|
use super::{async_db::AsyncDBAccess, map::MapObjectType, map_db::EntityDBType, surface::Surface};
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use cgmath::{vec3, Rad};
|
use cgmath::{Rad, vec3};
|
||||||
use cgmath::{Vector2, Vector3};
|
use cgmath::{Vector2, Vector3};
|
||||||
|
|
||||||
// std
|
// std
|
||||||
|
@ -53,14 +53,14 @@ pub struct SpawnMarkerEntities {
|
||||||
|
|
||||||
impl SpawnMarkerEntities {
|
impl SpawnMarkerEntities {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
engine: &Engine,
|
world: &mut World,
|
||||||
entity_manager: &mut impl AssetLoader,
|
entity_manager: &mut impl AssetLoader,
|
||||||
flag_name: &str,
|
flag_name: &str,
|
||||||
area_name: &str,
|
area_name: &str,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let assets = engine.assets();
|
let mut assets = AssetHandler::create(world);
|
||||||
|
|
||||||
let mut flag = entity_manager.load_entity(assets, flag_name)?;
|
let mut flag = entity_manager.load_entity(&mut assets, flag_name)?;
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
{
|
{
|
||||||
|
@ -69,7 +69,7 @@ impl SpawnMarkerEntities {
|
||||||
|
|
||||||
Location::new_and_setup(&mut flag)?;
|
Location::new_and_setup(&mut flag)?;
|
||||||
|
|
||||||
let mut area = entity_manager.load_entity(assets, area_name)?;
|
let mut area = entity_manager.load_entity(&mut assets, area_name)?;
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
{
|
{
|
||||||
|
@ -81,8 +81,8 @@ impl SpawnMarkerEntities {
|
||||||
Ok(Self { flag, area })
|
Ok(Self { flag, area })
|
||||||
}
|
}
|
||||||
|
|
||||||
fn clone_entity(entity: &EntityObject, engine: &Engine) -> Result<EntityObject> {
|
fn clone_entity(entity: &EntityObject, world: &mut World) -> Result<EntityObject> {
|
||||||
let mut flag = entity.clone_without_components(engine);
|
let mut flag = world.clone_without_components(entity);
|
||||||
flag.clone_component_from::<Draw>(entity)?;
|
flag.clone_component_from::<Draw>(entity)?;
|
||||||
flag.clone_component_from::<Location>(entity)?;
|
flag.clone_component_from::<Location>(entity)?;
|
||||||
flag.clone_component_from::<BoundingBox>(entity)?;
|
flag.clone_component_from::<BoundingBox>(entity)?;
|
||||||
|
@ -92,9 +92,9 @@ impl SpawnMarkerEntities {
|
||||||
Ok(flag)
|
Ok(flag)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn clone(&self, engine: &Engine) -> Result<Self> {
|
fn clone(&self, world: &mut World) -> Result<Self> {
|
||||||
let flag = Self::clone_entity(&self.flag, engine)?;
|
let flag = Self::clone_entity(&self.flag, world)?;
|
||||||
let area = Self::clone_entity(&self.area, engine)?;
|
let area = Self::clone_entity(&self.area, world)?;
|
||||||
|
|
||||||
Ok(Self { flag, area })
|
Ok(Self { flag, area })
|
||||||
}
|
}
|
||||||
|
@ -118,9 +118,9 @@ impl SpawnMarkerEntities {
|
||||||
.set_scale(vec3(radius, radius, 1.0));
|
.set_scale(vec3(radius, radius, 1.0));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add(self, scene: &mut impl SceneEntities) -> Result<SpawnMarker> {
|
pub fn add(self, world: &mut World) -> Result<SpawnMarker> {
|
||||||
let flag = scene.add_entity(self.flag)?;
|
let flag = world.add_entity(self.flag)?;
|
||||||
let area = scene.add_entity(self.area)?;
|
let area = world.add_entity(self.area)?;
|
||||||
|
|
||||||
Ok(SpawnMarker { flag, area })
|
Ok(SpawnMarker { flag, area })
|
||||||
}
|
}
|
||||||
|
@ -132,8 +132,8 @@ pub struct SpawnMarker {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SpawnMarker {
|
impl SpawnMarker {
|
||||||
fn set_radius(&self, scene_contents: &mut impl SceneEntities, radius: f32) -> Result<()> {
|
fn set_radius(&self, world: &mut World, radius: f32) -> Result<()> {
|
||||||
let flag_object = scene_contents.entity_mut(self.area)?;
|
let flag_object = world.entity_mut(self.area)?;
|
||||||
|
|
||||||
flag_object
|
flag_object
|
||||||
.get_component_mut::<Location>()?
|
.get_component_mut::<Location>()?
|
||||||
|
@ -193,9 +193,9 @@ impl AlterEntities for HashMap<Coordinate, (Entity, Vector3<f32>)> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SpawnMarker {
|
impl SpawnMarker {
|
||||||
pub fn remove(&self, scene: &mut impl SceneEntities) -> Result<()> {
|
pub fn remove(&self, world: &mut World) -> Result<()> {
|
||||||
scene.remove_entity(self.flag)?;
|
world.remove_entity(self.flag)?;
|
||||||
scene.remove_entity(self.area)?;
|
world.remove_entity(self.area)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -222,10 +222,10 @@ pub struct MapBossSpawnInfo {
|
||||||
impl MapBossSpawnInfo {
|
impl MapBossSpawnInfo {
|
||||||
fn setup_flag(
|
fn setup_flag(
|
||||||
marker: &SpawnMarkerEntities,
|
marker: &SpawnMarkerEntities,
|
||||||
engine: &Engine,
|
world: &mut World,
|
||||||
position: Vector3<f32>,
|
position: Vector3<f32>,
|
||||||
) -> Result<EntityObject> {
|
) -> Result<EntityObject> {
|
||||||
let mut flag = SpawnMarkerEntities::clone_entity(&marker.flag, engine)?;
|
let mut flag = SpawnMarkerEntities::clone_entity(&marker.flag, world)?;
|
||||||
|
|
||||||
let location = flag.get_component_mut::<Location>()?;
|
let location = flag.get_component_mut::<Location>()?;
|
||||||
let scale = location.scale();
|
let scale = location.scale();
|
||||||
|
@ -472,9 +472,9 @@ impl MapData {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_height_at(&mut self, x: u32, y: u32, scene: &mut Scene) -> Result<()> {
|
pub fn check_height_at(&mut self, x: u32, y: u32, world: &mut World) -> Result<()> {
|
||||||
self.execute_on_entity(x, y, |entity| {
|
self.execute_on_entity(x, y, |entity| {
|
||||||
let entity_object = scene.entity_mut(entity)?;
|
let entity_object = world.entity_mut(entity)?;
|
||||||
|
|
||||||
let location = entity_object.get_component_mut::<Location>()?;
|
let location = entity_object.get_component_mut::<Location>()?;
|
||||||
|
|
||||||
|
@ -493,7 +493,7 @@ impl MapData {
|
||||||
|
|
||||||
pub fn set_spawn_location(
|
pub fn set_spawn_location(
|
||||||
&mut self,
|
&mut self,
|
||||||
scene: &mut impl SceneEntities,
|
world: &mut World,
|
||||||
entity_opt: Option<(String, EntityObject)>,
|
entity_opt: Option<(String, EntityObject)>,
|
||||||
position: cgmath::Vector2<f32>,
|
position: cgmath::Vector2<f32>,
|
||||||
rotation: impl Into<Rad<f32>>,
|
rotation: impl Into<Rad<f32>>,
|
||||||
|
@ -508,7 +508,7 @@ impl MapData {
|
||||||
(self.width, self.height),
|
(self.width, self.height),
|
||||||
&self.surface,
|
&self.surface,
|
||||||
EntityDBType::spawn_location(),
|
EntityDBType::spawn_location(),
|
||||||
scene,
|
world,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -539,7 +539,7 @@ impl MapData {
|
||||||
pub fn change_npc_spawn(
|
pub fn change_npc_spawn(
|
||||||
&mut self,
|
&mut self,
|
||||||
async_db: &AsyncDBAccess,
|
async_db: &AsyncDBAccess,
|
||||||
scene_contents: &mut impl SceneEntities,
|
world: &mut World,
|
||||||
position: Vector2<f32>,
|
position: Vector2<f32>,
|
||||||
npc_spawn_parameter: NPCSpawnParameter,
|
npc_spawn_parameter: NPCSpawnParameter,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
|
@ -580,10 +580,7 @@ impl MapData {
|
||||||
NPCSpawnParameter::Radius(radius) => {
|
NPCSpawnParameter::Radius(radius) => {
|
||||||
spawn_info.radius = radius;
|
spawn_info.radius = radius;
|
||||||
|
|
||||||
marker
|
marker.as_ref().unwrap().set_radius(world, radius)?;
|
||||||
.as_ref()
|
|
||||||
.unwrap()
|
|
||||||
.set_radius(scene_contents, radius)?;
|
|
||||||
|
|
||||||
async_db.add(move |sql| sql.update_npc_spawn_radius(&coordinate, radius))?;
|
async_db.add(move |sql| sql.update_npc_spawn_radius(&coordinate, radius))?;
|
||||||
}
|
}
|
||||||
|
@ -593,12 +590,12 @@ impl MapData {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn disable_spawns(&mut self, scene: &mut impl SceneEntities) -> Result<()> {
|
pub fn disable_spawns(&mut self, world: &mut World) -> Result<()> {
|
||||||
if self.show_spawn_locations {
|
if self.show_spawn_locations {
|
||||||
self.show_spawn_locations = false;
|
self.show_spawn_locations = false;
|
||||||
|
|
||||||
for (spawn_entity, _) in self.spawn_locations.values() {
|
for (spawn_entity, _) in self.spawn_locations.values() {
|
||||||
scene.remove_entity(*spawn_entity)?;
|
world.remove_entity(*spawn_entity)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -621,7 +618,7 @@ impl MapData {
|
||||||
|
|
||||||
pub fn set_leave_location(
|
pub fn set_leave_location(
|
||||||
&mut self,
|
&mut self,
|
||||||
scene: &mut impl SceneEntities,
|
world: &mut World,
|
||||||
entity_opt: Option<(String, EntityObject)>,
|
entity_opt: Option<(String, EntityObject)>,
|
||||||
position: cgmath::Vector2<f32>,
|
position: cgmath::Vector2<f32>,
|
||||||
rotation: impl Into<Rad<f32>>,
|
rotation: impl Into<Rad<f32>>,
|
||||||
|
@ -636,15 +633,11 @@ impl MapData {
|
||||||
(self.width, self.height),
|
(self.width, self.height),
|
||||||
&self.surface,
|
&self.surface,
|
||||||
EntityDBType::leave_location(),
|
EntityDBType::leave_location(),
|
||||||
scene,
|
world,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn toggle_npc_spawns(
|
pub fn toggle_npc_spawns(&mut self, world: &mut World) -> Result<()> {
|
||||||
&mut self,
|
|
||||||
engine: &Engine,
|
|
||||||
scene: &mut impl SceneEntities,
|
|
||||||
) -> Result<()> {
|
|
||||||
self.show_npc_spawns = !self.show_npc_spawns;
|
self.show_npc_spawns = !self.show_npc_spawns;
|
||||||
|
|
||||||
for (spawn_info, marker) in self.npc_spawn_areas.iter_mut() {
|
for (spawn_info, marker) in self.npc_spawn_areas.iter_mut() {
|
||||||
|
@ -660,13 +653,13 @@ impl MapData {
|
||||||
Some(marker) => Some(marker),
|
Some(marker) => Some(marker),
|
||||||
None => match &self.npc_spawn_marker {
|
None => match &self.npc_spawn_marker {
|
||||||
Some(global_marker) => {
|
Some(global_marker) => {
|
||||||
let mut new_marker = global_marker.clone(engine)?;
|
let mut new_marker = global_marker.clone(world)?;
|
||||||
|
|
||||||
// set position
|
// set position
|
||||||
new_marker.set_position(spawn_info.position.extend(height));
|
new_marker.set_position(spawn_info.position.extend(height));
|
||||||
new_marker.set_radius(spawn_info.radius);
|
new_marker.set_radius(spawn_info.radius);
|
||||||
|
|
||||||
*marker = Some(new_marker.add(scene)?);
|
*marker = Some(new_marker.add(world)?);
|
||||||
|
|
||||||
marker.as_mut()
|
marker.as_mut()
|
||||||
}
|
}
|
||||||
|
@ -680,7 +673,7 @@ impl MapData {
|
||||||
if self.show_npc_spawns {
|
if self.show_npc_spawns {
|
||||||
// marker.add(scene)?;
|
// marker.add(scene)?;
|
||||||
} else {
|
} else {
|
||||||
marker.remove(scene)?;
|
marker.remove(world)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -700,11 +693,11 @@ impl MapData {
|
||||||
Some(global_marker) => {
|
Some(global_marker) => {
|
||||||
let flag = MapBossSpawnInfo::setup_flag(
|
let flag = MapBossSpawnInfo::setup_flag(
|
||||||
global_marker,
|
global_marker,
|
||||||
engine,
|
world,
|
||||||
spawn_info.position.extend(height),
|
spawn_info.position.extend(height),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
*flag_marker = Some(scene.add_entity(flag)?);
|
*flag_marker = Some(world.add_entity(flag)?);
|
||||||
|
|
||||||
*flag_marker
|
*flag_marker
|
||||||
}
|
}
|
||||||
|
@ -718,7 +711,7 @@ impl MapData {
|
||||||
if self.show_npc_spawns {
|
if self.show_npc_spawns {
|
||||||
// marker.add(scene)?;
|
// marker.add(scene)?;
|
||||||
} else {
|
} else {
|
||||||
scene.remove_entity(marker)?;
|
world.remove_entity(marker)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -728,8 +721,7 @@ impl MapData {
|
||||||
|
|
||||||
pub fn set_npc_spawn(
|
pub fn set_npc_spawn(
|
||||||
&mut self,
|
&mut self,
|
||||||
engine: &Engine,
|
world: &mut World,
|
||||||
scene: &mut impl SceneEntities,
|
|
||||||
position: cgmath::Vector2<f32>,
|
position: cgmath::Vector2<f32>,
|
||||||
async_db: &AsyncDBAccess,
|
async_db: &AsyncDBAccess,
|
||||||
radius: f32,
|
radius: f32,
|
||||||
|
@ -749,13 +741,13 @@ impl MapData {
|
||||||
|
|
||||||
let marker = match self.npc_spawn_marker.as_ref() {
|
let marker = match self.npc_spawn_marker.as_ref() {
|
||||||
Some(managed_entity) => {
|
Some(managed_entity) => {
|
||||||
let mut marker = managed_entity.clone(engine)?;
|
let mut marker = managed_entity.clone(world)?;
|
||||||
|
|
||||||
// set position
|
// set position
|
||||||
marker.set_position(position.extend(self.get_height(position.x, position.y)));
|
marker.set_position(position.extend(self.get_height(position.x, position.y)));
|
||||||
marker.set_radius(radius);
|
marker.set_radius(radius);
|
||||||
|
|
||||||
Some(marker.add(scene)?)
|
Some(marker.add(world)?)
|
||||||
}
|
}
|
||||||
None => None,
|
None => None,
|
||||||
};
|
};
|
||||||
|
@ -781,7 +773,7 @@ impl MapData {
|
||||||
|
|
||||||
pub fn unset_npc_spawn(
|
pub fn unset_npc_spawn(
|
||||||
&mut self,
|
&mut self,
|
||||||
scene: &mut impl SceneEntities,
|
world: &mut World,
|
||||||
position: cgmath::Vector2<f32>,
|
position: cgmath::Vector2<f32>,
|
||||||
async_db: &AsyncDBAccess,
|
async_db: &AsyncDBAccess,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
|
@ -797,7 +789,7 @@ impl MapData {
|
||||||
async_db.add(move |sql| sql.remove_npc_spawn((coordinate.x, coordinate.y)))?;
|
async_db.add(move |sql| sql.remove_npc_spawn((coordinate.x, coordinate.y)))?;
|
||||||
|
|
||||||
if let Some(marker) = marker {
|
if let Some(marker) = marker {
|
||||||
marker.remove(scene)?;
|
marker.remove(world)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -806,8 +798,7 @@ impl MapData {
|
||||||
|
|
||||||
pub fn set_boss_spawn(
|
pub fn set_boss_spawn(
|
||||||
&mut self,
|
&mut self,
|
||||||
engine: &Engine,
|
world: &mut World,
|
||||||
scene: &mut impl SceneEntities,
|
|
||||||
position: cgmath::Vector2<f32>,
|
position: cgmath::Vector2<f32>,
|
||||||
async_db: &AsyncDBAccess,
|
async_db: &AsyncDBAccess,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
|
@ -826,11 +817,11 @@ impl MapData {
|
||||||
Some(managed_entity) => {
|
Some(managed_entity) => {
|
||||||
let flag = MapBossSpawnInfo::setup_flag(
|
let flag = MapBossSpawnInfo::setup_flag(
|
||||||
managed_entity,
|
managed_entity,
|
||||||
engine,
|
world,
|
||||||
position.extend(self.get_height(position.x, position.y)),
|
position.extend(self.get_height(position.x, position.y)),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Some(scene.add_entity(flag)?)
|
Some(world.add_entity(flag)?)
|
||||||
}
|
}
|
||||||
None => None,
|
None => None,
|
||||||
};
|
};
|
||||||
|
@ -851,7 +842,7 @@ impl MapData {
|
||||||
|
|
||||||
pub fn unset_boss_spawn(
|
pub fn unset_boss_spawn(
|
||||||
&mut self,
|
&mut self,
|
||||||
scene: &mut impl SceneEntities,
|
world: &mut World,
|
||||||
position: cgmath::Vector2<f32>,
|
position: cgmath::Vector2<f32>,
|
||||||
async_db: &AsyncDBAccess,
|
async_db: &AsyncDBAccess,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
|
@ -867,7 +858,7 @@ impl MapData {
|
||||||
async_db.add(move |sql| sql.remove_boss_spawn((coordinate.x, coordinate.y)))?;
|
async_db.add(move |sql| sql.remove_boss_spawn((coordinate.x, coordinate.y)))?;
|
||||||
|
|
||||||
if let Some(marker) = marker {
|
if let Some(marker) = marker {
|
||||||
scene.remove_entity(marker)?;
|
world.remove_entity(marker)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -883,7 +874,7 @@ impl MapData {
|
||||||
(width, height): (u32, u32),
|
(width, height): (u32, u32),
|
||||||
surface: &Surface,
|
surface: &Surface,
|
||||||
table_name: EntityDBType,
|
table_name: EntityDBType,
|
||||||
scene: &mut impl SceneEntities,
|
world: &mut World,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let coordinate = Coordinate {
|
let coordinate = Coordinate {
|
||||||
x: position.x as u32,
|
x: position.x as u32,
|
||||||
|
@ -927,7 +918,7 @@ impl MapData {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.update_raw(position_3d, rad_rotation);
|
.update_raw(position_3d, rad_rotation);
|
||||||
|
|
||||||
let handle = scene.add_entity(entity)?;
|
let handle = world.add_entity(entity)?;
|
||||||
|
|
||||||
entities.insert(coordinate, handle, position_3d);
|
entities.insert(coordinate, handle, position_3d);
|
||||||
}
|
}
|
||||||
|
@ -938,7 +929,7 @@ impl MapData {
|
||||||
sql.remove_entity(table_name, (coordinate.x, coordinate.y))
|
sql.remove_entity(table_name, (coordinate.x, coordinate.y))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
scene.remove_entity(entity)?;
|
world.remove_entity(entity)?;
|
||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
@ -950,7 +941,7 @@ impl MapData {
|
||||||
|
|
||||||
pub fn set_entity(
|
pub fn set_entity(
|
||||||
&mut self,
|
&mut self,
|
||||||
scene: &mut impl SceneEntities,
|
world: &mut World,
|
||||||
entity_opt: Option<(String, EntityObject)>,
|
entity_opt: Option<(String, EntityObject)>,
|
||||||
position: cgmath::Vector2<f32>,
|
position: cgmath::Vector2<f32>,
|
||||||
rotation: impl Into<Rad<f32>>,
|
rotation: impl Into<Rad<f32>>,
|
||||||
|
@ -965,7 +956,7 @@ impl MapData {
|
||||||
(self.width, self.height),
|
(self.width, self.height),
|
||||||
&self.surface,
|
&self.surface,
|
||||||
EntityDBType::entity(),
|
EntityDBType::entity(),
|
||||||
scene,
|
world,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1122,7 +1113,7 @@ impl MapData {
|
||||||
return Err(anyhow::Error::msg(format!(
|
return Err(anyhow::Error::msg(format!(
|
||||||
"Index ({}) in textures_info (MapData) not found",
|
"Index ({}) in textures_info (MapData) not found",
|
||||||
remove_index
|
remove_index
|
||||||
)))
|
)));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1132,7 +1123,7 @@ impl MapData {
|
||||||
return Err(anyhow::Error::msg(format!(
|
return Err(anyhow::Error::msg(format!(
|
||||||
"Could not remove key ({}) from textures_index",
|
"Could not remove key ({}) from textures_index",
|
||||||
info.name
|
info.name
|
||||||
)))
|
)));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue