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