From fde8695bbca220e5af85344a7da23bea0f6513b6 Mon Sep 17 00:00:00 2001 From: troido Date: Mon, 27 Jan 2020 23:01:26 +0100 Subject: cleanup! --- src/room.rs | 79 +++++++++++-------------------------------------------------- 1 file changed, 14 insertions(+), 65 deletions(-) (limited to 'src/room.rs') diff --git a/src/room.rs b/src/room.rs index 4c1b291..b9614e3 100644 --- a/src/room.rs +++ b/src/room.rs @@ -1,7 +1,5 @@ use std::collections::HashMap; -// use std::collections::HashSet; -// use std::ops::Deref; use specs::{ VecStorage, @@ -17,7 +15,8 @@ use specs::{ Write }; -struct EntityId(usize); + +// Components #[derive(Component, Debug, Hash, PartialEq, Eq, Clone, Copy)] #[storage(VecStorage)] @@ -37,6 +36,17 @@ struct Visible { struct Size (i32, i32); +// Resources + +#[derive(Default)] +struct TopView { + width: i32, + height: i32, + cells: HashMap> +} + +// Systems + struct Draw; impl <'a> System<'a> for Draw { @@ -53,13 +63,8 @@ impl <'a> System<'a> for Draw { } } -#[derive(Default)] -struct TopView { - width: i32, - height: i32, - cells: HashMap> -} +// Higher level stuff pub struct Room<'a, 'b> { world: World, @@ -92,13 +97,11 @@ impl <'a, 'b>Room<'a, 'b> { let tv = &*self.world.fetch::(); let width = tv.width; let height = tv.height; -// let TopView{width: width, height: height, cells: cells} = ; let size = width * height; let mut values :Vec = Vec::with_capacity(size as usize); let mut mapping: Vec> = Vec::with_capacity(size as usize); for y in 0..height { for x in 0..width { -// values.push(mapping.len()); let sprites = match tv.cells.get(&Position{x: x, y: y}) { Some(sprites) => {sprites.to_vec()} None => {vec![]} @@ -143,57 +146,3 @@ fn gen_world(world: &mut World){ } } -// pub fn make_room<'a, 'b>(size: (i32, i32)) -> (World, Dispatcher<'a, 'b>){ -// let (width, height) = size; -// let mut world = World::new(); -// world.register::(); -// world.register::(); -// world.insert(Size(width, height)); -// world.insert(TopView{width: width, height: height, cells: HashMap::new()}); -// -// -// -// let mut dispatcher = DispatcherBuilder::new() -// .with(Draw, "draw", &[]) -// .build(); -// -// -// gen_world(&mut world); -// -// (world, dispatcher) -// } - -// pub fn view_room(world :&World) -> (Vec, Vec>) { -// let TopView{width: width, height: height, cells: cells} = *world.fetch::(); -// let size = width * height; -// let mut values :Vec = Vec::with_capacity(size as usize); -// let mut mapping = Vec::with_capacity(size as usize); -// for y in 0..height { -// for x in 0..width { -// values.push(mapping.len()); -// mapping.push(match cells.get(Position{x: x, y: y}) { -// Some(sprites) => {sprites} -// None => {vec![]} -// }); -// } -// } -// return (values, mapping) -// -// } - -// struct Room { -// entities: Entities, -// width: u32, -// height: u32, -// ground: HashMap<(u32, u32), GroundTile> -// } -// -// struct Entities { -// components: HashMap>, -// systems: HashMap> -// } -// -// -// struct GroundTile { -// entities: HashSet -// } -- cgit