fix: finally removed the storage.rsin the comet_ecs

This commit is contained in:
lisk77 2025-03-05 08:39:57 +01:00
parent 7b6ccbe72c
commit cae678747f
8 changed files with 45 additions and 10 deletions

View file

@ -4,7 +4,7 @@ use std::sync::atomic::AtomicBool;
use std::thread;
use std::time::{Duration, Instant};
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_renderer::renderer2d::Renderer2D;
@ -113,7 +113,7 @@ impl App {
fn load_icon(path: &std::path::Path) -> Option<Icon> {
let image = match image::open(path) {
Ok(image) => image,
Err(e) => {
Err(_) => {
error!("Failed loading icon {}", path.display());
return None;
}

View file

@ -1,5 +1,5 @@
use std::collections::HashMap;
use crate::ComponentSet;
use comet_structs::ComponentSet;
#[derive(Debug, Clone)]
pub struct Archetypes {

View file

@ -1,4 +1,3 @@
pub use storage::*;
pub use entity::*;
pub use component::*;
pub use world::*;
@ -6,7 +5,6 @@ pub use id::*;
pub use component_derive::*;
pub use comet_math as math;
mod storage;
mod entity;
mod component;
mod world;

View file

@ -6,11 +6,10 @@ use crate::{
Transform2D,
Transform3D,
IdQueue,
Archetypes,
ComponentSet
};
use comet_log::*;
use comet_structs::*;
use crate::archetypes::Archetypes;
#[derive(Clone)]
pub struct World {
@ -206,10 +205,10 @@ impl World {
/// Returns a list of entities that have the given components.
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) {
return self.archetypes.get_archetype(&components).unwrap().clone();
}
error!("The given components {:?} are not registered in the world!", components);
Vec::new()
}
}

View file

@ -9,6 +9,7 @@ comet_math = { path = "../comet_math" }
comet_resources = { path = "../comet_resources" }
comet_colors = { path = "../comet_colors" }
comet_log = { path = "../comet_log" }
comet_structs = { path = "../comet_structs" }
cfg-if = "1"
anyhow = "1.0"

View file

@ -8,11 +8,12 @@ use wgpu::util::DeviceExt;
use winit::dpi::PhysicalSize;
use winit::window::Window;
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_math::{Point3, Vec2, Vec3};
use comet_resources::{texture, graphic_resource_manager::GraphicResorceManager, Texture, Vertex};
use comet_resources::texture_atlas::TextureRegion;
use comet_structs::ComponentSet;
use crate::camera::{Camera as OldCam, CameraUniform};
use crate::render_pass::RenderPassInfo;
use crate::renderer::Renderer;

View 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);
}
}

View file

@ -2,8 +2,10 @@ pub use column::Column;
pub use sparse_set::SparseSet;
pub use flat_map::FlatMap;
pub use component_storage::ComponentStorage;
pub use componet_set::ComponentSet;
mod column;
mod sparse_set;
mod flat_map;
mod component_storage;
mod component_storage;
mod componet_set;