mirror of
https://github.com/lisk77/comet.git
synced 2025-10-23 21:38:50 +00:00
fix: finally removed the storage.rsin the comet_ecs
This commit is contained in:
parent
7b6ccbe72c
commit
cae678747f
8 changed files with 45 additions and 10 deletions
|
|
@ -4,7 +4,7 @@ use std::sync::atomic::AtomicBool;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
use crossbeam_channel::bounded;
|
use crossbeam_channel::bounded;
|
||||||
use comet_ecs::{Camera2D, Component, ComponentSet, Entity, Render, Render2D, Transform2D, Transform3D, World};
|
use comet_ecs::{Camera2D, Component, Entity, Render, Render2D, Transform2D, Transform3D, World};
|
||||||
use comet_resources::{ResourceManager, Vertex};
|
use comet_resources::{ResourceManager, Vertex};
|
||||||
use comet_renderer::renderer2d::Renderer2D;
|
use comet_renderer::renderer2d::Renderer2D;
|
||||||
|
|
||||||
|
|
@ -113,7 +113,7 @@ impl App {
|
||||||
fn load_icon(path: &std::path::Path) -> Option<Icon> {
|
fn load_icon(path: &std::path::Path) -> Option<Icon> {
|
||||||
let image = match image::open(path) {
|
let image = match image::open(path) {
|
||||||
Ok(image) => image,
|
Ok(image) => image,
|
||||||
Err(e) => {
|
Err(_) => {
|
||||||
error!("Failed loading icon {}", path.display());
|
error!("Failed loading icon {}", path.display());
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use crate::ComponentSet;
|
use comet_structs::ComponentSet;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Archetypes {
|
pub struct Archetypes {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
pub use storage::*;
|
|
||||||
pub use entity::*;
|
pub use entity::*;
|
||||||
pub use component::*;
|
pub use component::*;
|
||||||
pub use world::*;
|
pub use world::*;
|
||||||
|
|
@ -6,7 +5,6 @@ pub use id::*;
|
||||||
pub use component_derive::*;
|
pub use component_derive::*;
|
||||||
pub use comet_math as math;
|
pub use comet_math as math;
|
||||||
|
|
||||||
mod storage;
|
|
||||||
mod entity;
|
mod entity;
|
||||||
mod component;
|
mod component;
|
||||||
mod world;
|
mod world;
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,10 @@ use crate::{
|
||||||
Transform2D,
|
Transform2D,
|
||||||
Transform3D,
|
Transform3D,
|
||||||
IdQueue,
|
IdQueue,
|
||||||
Archetypes,
|
|
||||||
ComponentSet
|
|
||||||
};
|
};
|
||||||
use comet_log::*;
|
use comet_log::*;
|
||||||
use comet_structs::*;
|
use comet_structs::*;
|
||||||
|
use crate::archetypes::Archetypes;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct World {
|
pub struct World {
|
||||||
|
|
@ -206,10 +205,10 @@ impl World {
|
||||||
|
|
||||||
/// Returns a list of entities that have the given components.
|
/// Returns a list of entities that have the given components.
|
||||||
pub fn get_entities_with(&self, components: ComponentSet) -> Vec<u32> {
|
pub fn get_entities_with(&self, components: ComponentSet) -> Vec<u32> {
|
||||||
error!("The given components {:?} are not registered in the world!", components);
|
|
||||||
if self.archetypes.contains_archetype(&components) {
|
if self.archetypes.contains_archetype(&components) {
|
||||||
return self.archetypes.get_archetype(&components).unwrap().clone();
|
return self.archetypes.get_archetype(&components).unwrap().clone();
|
||||||
}
|
}
|
||||||
|
error!("The given components {:?} are not registered in the world!", components);
|
||||||
Vec::new()
|
Vec::new()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ comet_math = { path = "../comet_math" }
|
||||||
comet_resources = { path = "../comet_resources" }
|
comet_resources = { path = "../comet_resources" }
|
||||||
comet_colors = { path = "../comet_colors" }
|
comet_colors = { path = "../comet_colors" }
|
||||||
comet_log = { path = "../comet_log" }
|
comet_log = { path = "../comet_log" }
|
||||||
|
comet_structs = { path = "../comet_structs" }
|
||||||
|
|
||||||
cfg-if = "1"
|
cfg-if = "1"
|
||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,12 @@ use wgpu::util::DeviceExt;
|
||||||
use winit::dpi::PhysicalSize;
|
use winit::dpi::PhysicalSize;
|
||||||
use winit::window::Window;
|
use winit::window::Window;
|
||||||
use comet_colors::LinearRgba;
|
use comet_colors::LinearRgba;
|
||||||
use comet_ecs::{Camera, Camera2D, Component, ComponentSet, Render, Render2D, Transform2D, World};
|
use comet_ecs::{Camera, Camera2D, Component, Render, Render2D, Transform2D, World};
|
||||||
use comet_log::{debug, info};
|
use comet_log::{debug, info};
|
||||||
use comet_math::{Point3, Vec2, Vec3};
|
use comet_math::{Point3, Vec2, Vec3};
|
||||||
use comet_resources::{texture, graphic_resource_manager::GraphicResorceManager, Texture, Vertex};
|
use comet_resources::{texture, graphic_resource_manager::GraphicResorceManager, Texture, Vertex};
|
||||||
use comet_resources::texture_atlas::TextureRegion;
|
use comet_resources::texture_atlas::TextureRegion;
|
||||||
|
use comet_structs::ComponentSet;
|
||||||
use crate::camera::{Camera as OldCam, CameraUniform};
|
use crate::camera::{Camera as OldCam, CameraUniform};
|
||||||
use crate::render_pass::RenderPassInfo;
|
use crate::render_pass::RenderPassInfo;
|
||||||
use crate::renderer::Renderer;
|
use crate::renderer::Renderer;
|
||||||
|
|
|
||||||
34
crates/comet_structs/src/componet_set.rs
Normal file
34
crates/comet_structs/src/componet_set.rs
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
use std::any::TypeId;
|
||||||
|
use std::collections::HashSet;
|
||||||
|
use std::hash::{Hash, Hasher};
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
pub struct ComponentSet {
|
||||||
|
set: HashSet<TypeId>
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ComponentSet {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
set: HashSet::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn from_ids(ids: Vec<TypeId>) -> Self {
|
||||||
|
Self {
|
||||||
|
set: ids.into_iter().collect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_subset(&self, other: &ComponentSet) -> bool {
|
||||||
|
self.set.is_subset(&other.set)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Hash for ComponentSet {
|
||||||
|
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||||
|
let mut types: Vec<TypeId> = self.set.iter().cloned().collect();
|
||||||
|
types.sort();
|
||||||
|
types.hash(state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,8 +2,10 @@ pub use column::Column;
|
||||||
pub use sparse_set::SparseSet;
|
pub use sparse_set::SparseSet;
|
||||||
pub use flat_map::FlatMap;
|
pub use flat_map::FlatMap;
|
||||||
pub use component_storage::ComponentStorage;
|
pub use component_storage::ComponentStorage;
|
||||||
|
pub use componet_set::ComponentSet;
|
||||||
|
|
||||||
mod column;
|
mod column;
|
||||||
mod sparse_set;
|
mod sparse_set;
|
||||||
mod flat_map;
|
mod flat_map;
|
||||||
mod component_storage;
|
mod component_storage;
|
||||||
|
mod componet_set;
|
||||||
Loading…
Add table
Add a link
Reference in a new issue