render iteration
This commit is contained in:
178
src/world.rs
178
src/world.rs
@@ -1,9 +1,12 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::components::dissolve::DissolveComponent;
|
||||
use crate::components::follow::FollowComponent;
|
||||
use crate::components::jump::JumpComponent;
|
||||
use crate::components::lights::spot::SpotlightComponent;
|
||||
use crate::components::{
|
||||
CameraComponent, CameraFollowComponent, InputComponent, MeshComponent, MovementComponent,
|
||||
PhysicsComponent,
|
||||
CameraComponent, InputComponent, MeshComponent, MovementComponent, PhysicsComponent,
|
||||
RotateComponent,
|
||||
};
|
||||
use crate::entity::{EntityHandle, EntityManager};
|
||||
use crate::state::StateMachine;
|
||||
@@ -415,12 +418,12 @@ impl CameraStorage
|
||||
}
|
||||
}
|
||||
|
||||
pub struct CameraFollowStorage
|
||||
pub struct SpotlightStorage
|
||||
{
|
||||
pub components: HashMap<EntityHandle, CameraFollowComponent>,
|
||||
pub components: HashMap<EntityHandle, SpotlightComponent>,
|
||||
}
|
||||
|
||||
impl CameraFollowStorage
|
||||
impl SpotlightStorage
|
||||
{
|
||||
pub fn new() -> Self
|
||||
{
|
||||
@@ -429,26 +432,159 @@ impl CameraFollowStorage
|
||||
}
|
||||
}
|
||||
|
||||
pub fn insert(&mut self, entity: EntityHandle, component: CameraFollowComponent)
|
||||
pub fn insert(&mut self, entity: EntityHandle, component: SpotlightComponent)
|
||||
{
|
||||
self.components.insert(entity, component);
|
||||
}
|
||||
|
||||
pub fn get(&self, entity: EntityHandle) -> Option<&CameraFollowComponent>
|
||||
pub fn get(&self, entity: EntityHandle) -> Option<&SpotlightComponent>
|
||||
{
|
||||
self.components.get(&entity)
|
||||
}
|
||||
|
||||
pub fn get_mut(&mut self, entity: EntityHandle) -> Option<&mut CameraFollowComponent>
|
||||
pub fn get_mut(&mut self, entity: EntityHandle) -> Option<&mut SpotlightComponent>
|
||||
{
|
||||
self.components.get_mut(&entity)
|
||||
}
|
||||
|
||||
pub fn with_mut<F, R>(&mut self, entity: EntityHandle, f: F) -> Option<R>
|
||||
where
|
||||
F: FnOnce(&mut CameraFollowComponent) -> R,
|
||||
pub fn remove(&mut self, entity: EntityHandle)
|
||||
{
|
||||
self.components.get_mut(&entity).map(f)
|
||||
self.components.remove(&entity);
|
||||
}
|
||||
|
||||
pub fn all(&self) -> Vec<EntityHandle>
|
||||
{
|
||||
self.components.keys().copied().collect()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TreeTagStorage
|
||||
{
|
||||
pub components: HashMap<EntityHandle, ()>,
|
||||
}
|
||||
|
||||
impl TreeTagStorage
|
||||
{
|
||||
pub fn new() -> Self
|
||||
{
|
||||
Self {
|
||||
components: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn insert(&mut self, entity: EntityHandle)
|
||||
{
|
||||
self.components.insert(entity, ());
|
||||
}
|
||||
|
||||
pub fn remove(&mut self, entity: EntityHandle)
|
||||
{
|
||||
self.components.remove(&entity);
|
||||
}
|
||||
|
||||
pub fn all(&self) -> Vec<EntityHandle>
|
||||
{
|
||||
self.components.keys().copied().collect()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct DissolveStorage
|
||||
{
|
||||
pub components: HashMap<EntityHandle, DissolveComponent>,
|
||||
}
|
||||
|
||||
impl DissolveStorage
|
||||
{
|
||||
pub fn new() -> Self
|
||||
{
|
||||
Self {
|
||||
components: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn insert(&mut self, entity: EntityHandle, component: DissolveComponent)
|
||||
{
|
||||
self.components.insert(entity, component);
|
||||
}
|
||||
|
||||
pub fn get(&self, entity: EntityHandle) -> Option<&DissolveComponent>
|
||||
{
|
||||
self.components.get(&entity)
|
||||
}
|
||||
|
||||
pub fn get_mut(&mut self, entity: EntityHandle) -> Option<&mut DissolveComponent>
|
||||
{
|
||||
self.components.get_mut(&entity)
|
||||
}
|
||||
|
||||
pub fn remove(&mut self, entity: EntityHandle)
|
||||
{
|
||||
self.components.remove(&entity);
|
||||
}
|
||||
|
||||
pub fn all(&self) -> Vec<EntityHandle>
|
||||
{
|
||||
self.components.keys().copied().collect()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct FollowStorage
|
||||
{
|
||||
pub components: HashMap<EntityHandle, FollowComponent>,
|
||||
}
|
||||
|
||||
impl FollowStorage
|
||||
{
|
||||
pub fn new() -> Self
|
||||
{
|
||||
Self {
|
||||
components: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn insert(&mut self, entity: EntityHandle, component: FollowComponent)
|
||||
{
|
||||
self.components.insert(entity, component);
|
||||
}
|
||||
|
||||
pub fn get(&self, entity: EntityHandle) -> Option<&FollowComponent>
|
||||
{
|
||||
self.components.get(&entity)
|
||||
}
|
||||
|
||||
pub fn remove(&mut self, entity: EntityHandle)
|
||||
{
|
||||
self.components.remove(&entity);
|
||||
}
|
||||
|
||||
pub fn all(&self) -> Vec<EntityHandle>
|
||||
{
|
||||
self.components.keys().copied().collect()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct RotateStorage
|
||||
{
|
||||
pub components: HashMap<EntityHandle, RotateComponent>,
|
||||
}
|
||||
|
||||
impl RotateStorage
|
||||
{
|
||||
pub fn new() -> Self
|
||||
{
|
||||
Self {
|
||||
components: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn insert(&mut self, entity: EntityHandle, component: RotateComponent)
|
||||
{
|
||||
self.components.insert(entity, component);
|
||||
}
|
||||
|
||||
pub fn get(&self, entity: EntityHandle) -> Option<&RotateComponent>
|
||||
{
|
||||
self.components.get(&entity)
|
||||
}
|
||||
|
||||
pub fn remove(&mut self, entity: EntityHandle)
|
||||
@@ -474,7 +610,11 @@ pub struct World
|
||||
pub player_tags: PlayerTagStorage,
|
||||
pub state_machines: StateMachineStorage,
|
||||
pub cameras: CameraStorage,
|
||||
pub camera_follows: CameraFollowStorage,
|
||||
pub spotlights: SpotlightStorage,
|
||||
pub tree_tags: TreeTagStorage,
|
||||
pub dissolves: DissolveStorage,
|
||||
pub follows: FollowStorage,
|
||||
pub rotates: RotateStorage,
|
||||
}
|
||||
|
||||
impl World
|
||||
@@ -492,7 +632,11 @@ impl World
|
||||
player_tags: PlayerTagStorage::new(),
|
||||
state_machines: StateMachineStorage::new(),
|
||||
cameras: CameraStorage::new(),
|
||||
camera_follows: CameraFollowStorage::new(),
|
||||
spotlights: SpotlightStorage::new(),
|
||||
tree_tags: TreeTagStorage::new(),
|
||||
dissolves: DissolveStorage::new(),
|
||||
follows: FollowStorage::new(),
|
||||
rotates: RotateStorage::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -512,7 +656,11 @@ impl World
|
||||
self.player_tags.remove(entity);
|
||||
self.state_machines.remove(entity);
|
||||
self.cameras.remove(entity);
|
||||
self.camera_follows.remove(entity);
|
||||
self.spotlights.remove(entity);
|
||||
self.tree_tags.remove(entity);
|
||||
self.dissolves.remove(entity);
|
||||
self.follows.remove(entity);
|
||||
self.rotates.remove(entity);
|
||||
self.entities.despawn(entity);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user