fix: changed the name of World to Scene (because the name fits better)

This commit is contained in:
lisk77 2025-03-11 01:23:33 +01:00
parent e94df6c221
commit ab73b145b1
8 changed files with 55 additions and 57 deletions

View file

@ -9,7 +9,7 @@ use crate::math::{
Vec3
};
use component_derive::Component;
use crate::{Entity, World};
use crate::{Entity, Scene};
// ##################################################
// # BASIC #
@ -101,7 +101,7 @@ pub trait Render {
}
pub trait Camera {
fn get_visible_entities(&self, camera_position: Position2D, world: World) -> Vec<Entity>;
fn get_visible_entities(&self, camera_position: Position2D, scene: Scene) -> Vec<Entity>;
fn get_projection_matrix(&self) -> Mat4;
}
@ -328,11 +328,11 @@ impl Camera2D {
}
impl Camera for Camera2D {
fn get_visible_entities(&self, camera_position: Position2D, world: World) -> Vec<Entity> {
let entities = world.entities();
fn get_visible_entities(&self, camera_position: Position2D, scene: Scene) -> Vec<Entity> {
let entities = scene.entities();
let mut visible_entities = Vec::new();
for entity in entities {
if self.in_view_frustum(camera_position, *world.get_component::<Transform2D>(*entity.clone().unwrap().id() as usize).unwrap().position()) {
if self.in_view_frustum(camera_position, *scene.get_component::<Transform2D>(*entity.clone().unwrap().id() as usize).unwrap().position()) {
visible_entities.push(entity.clone().unwrap());
}
}

View file

@ -1,12 +1,12 @@
pub use entity::*;
pub use component::*;
pub use world::*;
pub use scene::*;
pub use id::*;
pub use component_derive::*;
pub use comet_math as math;
mod entity;
mod component;
mod world;
mod scene;
mod id;
mod archetypes;

View file

@ -11,7 +11,7 @@ use comet_log::*;
use comet_structs::*;
use crate::archetypes::Archetypes;
pub struct World {
pub struct Scene {
id_queue: IdQueue,
next_id: u32,
entities: Vec<Option<Entity>>,
@ -19,7 +19,7 @@ pub struct World {
archetypes: Archetypes
}
impl World {
impl Scene {
pub fn new() -> Self {
Self {
id_queue: IdQueue::new(),
@ -30,7 +30,7 @@ impl World {
}
}
/// Returns the number of how many entities exist in the current World.
/// Returns the number of how many entities exist in the current Scene.
pub fn active_entities(&self) -> u32 {
self.entities.len() as u32 - self.id_queue.size()
}
@ -45,7 +45,7 @@ impl World {
}
}
/// Retuns the `Vec` of `Option<Entity>` which contains all the entities in the current World.
/// Retuns the `Vec` of `Option<Entity>` which contains all the entities in the current Scene.
pub fn entities(&self) -> &Vec<Option<Entity>> {
&self.entities
}
@ -86,8 +86,6 @@ impl World {
}
self.id_queue.sorted_enqueue(entity_id as u32);
self.get_next_id();
}
fn create_archetype(&mut self, components: ComponentSet) {
@ -156,14 +154,14 @@ impl World {
ComponentSet::from_ids(type_ids)
}
/// Registers a new component in the world.
/// Registers a new component in the scene.
pub fn register_component<C: Component + 'static>(&mut self) {
self.components.register_component::<C>(self.entities.len());
self.create_archetype(ComponentSet::from_ids(vec![C::type_id()]));
info!("Registered component: {}", C::type_name());
}
/// Deregisters a component from the world.
/// Deregisters a component from the scene.
pub fn deregister_component<C: Component + 'static>(&mut self) {
self.components.deregister_component::<C>();
info!("Deregistered component: {}", C::type_name());
@ -207,7 +205,7 @@ impl World {
if self.archetypes.contains_archetype(&components) {
return self.archetypes.get_archetype(&components).unwrap().clone().iter().map(|x| *x as usize).collect();
}
error!("The given components {:?} are not registered in the world!", components);
error!("The given components {:?} are not registered in the scene!", components);
Vec::new()
}
}