From fba4e28b314d595d3e2579af63c2c24428f669ed Mon Sep 17 00:00:00 2001 From: Jared McFarland Date: Mon, 17 Nov 2014 12:29:45 -0700 Subject: [PATCH] it works! --- src/actor.rs | 2 +- src/game.rs | 16 ++++++++-------- src/game_states.rs | 35 +++++++++++++++++++++-------------- src/movement.rs | 8 ++++---- src/rendering/renderers.rs | 8 ++++---- src/rendering/windows.rs | 23 ++++++----------------- 6 files changed, 44 insertions(+), 48 deletions(-) diff --git a/src/actor.rs b/src/actor.rs index 878d91d..218c03e 100644 --- a/src/actor.rs +++ b/src/actor.rs @@ -18,7 +18,7 @@ pub struct Actor { } impl Clone for Actor { - pub fn clone(&self) -> Actor { + fn clone(&self) -> Actor { let mc = self.movement_component.box_clone(); Actor::new(self.position.x, self.position.y, self.display_char, mc, self.is_pc, self.foreground, self.background, self.health) } diff --git a/src/game.rs b/src/game.rs index 4c43481..2e54cdb 100644 --- a/src/game.rs +++ b/src/game.rs @@ -44,18 +44,18 @@ impl MoveInfo { } } -pub struct Game<'a, 'b> { +pub struct Game { pub move_info: Rc>, pub exit: bool, pub window_bounds: Bound, - pub rendering_component: Box, - pub game_state: Box + 'a>, - pub windows: Windows<'a>, + pub rendering_component: Box, + pub game_state: Box, + pub windows: Windows, pub maps: Maps } -impl<'a, 'b> Game<'a, 'b> { - pub fn new() -> Game<'a, 'b> { +impl Game { + pub fn new() -> Game { let total_bounds = Bound::new(0, 0, 99, 61); let stats_bounds = Bound::new(79, 0, 99, 49); let input_bounds = Bound::new(0, 50, 99, 51); @@ -92,11 +92,11 @@ impl<'a, 'b> Game<'a, 'b> { } } - pub fn render(&'a mut self) { + pub fn render(&mut self) { self.game_state.render(&mut self.rendering_component, &mut self.maps, &mut self.windows); } - pub fn update(&'b mut self) { + pub fn update(&mut self) { if self.game_state.should_update_state() { self.game_state.exit(); self.update_state(); diff --git a/src/game_states.rs b/src/game_states.rs index 17b5fd3..d5b3f9c 100644 --- a/src/game_states.rs +++ b/src/game_states.rs @@ -8,20 +8,27 @@ use game::MoveInfo; use input::{KeyCode, SpecialKey}; use combat::{Weapon, Boomerang}; -pub trait GameState<'a> { +pub trait GameState { fn new() -> Self; - fn new_with_weapon(Box) -> Self; + fn new_with_weapon(Box) -> Self; fn enter(&self, &mut Windows) {} fn exit(&self) {} fn update(&mut self, maps: &mut Maps, windows: &mut Windows, Rc>); - fn render<'r>(&mut self, renderer: &mut Box, maps: &mut Maps, windows: &'r mut Windows<'r>) { + fn render(&mut self, renderer: &mut Box, maps: &mut Maps, windows: &mut Windows) { renderer.before_render_new_frame(); - let mut all_windows = windows.all_windows(); - for window in all_windows.iter_mut() { - renderer.attach_window(*window); - } + let ref mut stats = windows.stats; + renderer.attach_window(stats); + + let ref mut input = windows.input; + renderer.attach_window(input); + + let ref mut messages = windows.messages; + renderer.attach_window(messages); + + let ref mut map = windows.map; + renderer.attach_window(map); maps.render(renderer); renderer.after_render_new_frame(); } @@ -31,12 +38,12 @@ pub trait GameState<'a> { pub struct MovementGameState; -impl<'a> GameState<'a> for MovementGameState { +impl GameState for MovementGameState { fn new() -> MovementGameState { MovementGameState } - fn new_with_weapon(_: Box) -> MovementGameState { + fn new_with_weapon(_: Box) -> MovementGameState { MovementGameState } @@ -69,13 +76,13 @@ impl<'a> GameState<'a> for MovementGameState { } } -pub struct AttackInputGameState<'a> { +pub struct AttackInputGameState { should_update_state: bool, - pub weapon: Box + pub weapon: Box } -impl<'a> GameState<'a> for AttackInputGameState<'a> { - fn new() -> AttackInputGameState<'a> { +impl GameState for AttackInputGameState { + fn new() -> AttackInputGameState { let weapon : Box = box Weapon::new(); AttackInputGameState { should_update_state: false, @@ -83,7 +90,7 @@ impl<'a> GameState<'a> for AttackInputGameState<'a> { } } - fn new_with_weapon(weapon: Box) -> AttackInputGameState<'a> { + fn new_with_weapon(weapon: Box) -> AttackInputGameState { AttackInputGameState { should_update_state: false, weapon: weapon diff --git a/src/movement.rs b/src/movement.rs index b52e8db..7ad8d6c 100644 --- a/src/movement.rs +++ b/src/movement.rs @@ -24,7 +24,7 @@ use std::rand::Rng; pub trait MovementComponent { fn new(Rc>) -> Self; fn update(&self, Point, &mut Windows) -> Point; - fn box_clone(&self) -> Box; + fn box_clone(&self) -> Box; } pub struct AggroMovementComponent { @@ -36,7 +36,7 @@ impl MovementComponent for AggroMovementComponent { AggroMovementComponent { move_info: move_info } } - fn box_clone(&self) -> Box { + fn box_clone(&self) -> Box { box AggroMovementComponent { move_info: self.move_info.clone() } } @@ -81,7 +81,7 @@ impl MovementComponent for UserMovementComponent { UserMovementComponent { move_info: move_info } } - fn box_clone(&self) -> Box { + fn box_clone(&self) -> Box { box UserMovementComponent { move_info: self.move_info.clone() } } @@ -135,7 +135,7 @@ impl MovementComponent for RandomMovementComponent { RandomMovementComponent { move_info: move_info } } - fn box_clone(&self) -> Box { + fn box_clone(&self) -> Box { box RandomMovementComponent { move_info: self.move_info.clone() } } diff --git a/src/rendering/renderers.rs b/src/rendering/renderers.rs index e33ada3..e97143b 100644 --- a/src/rendering/renderers.rs +++ b/src/rendering/renderers.rs @@ -27,13 +27,13 @@ pub trait RenderingComponent { fn translate_color(&self, Color) -> tcod::Color; } -pub struct TcodRenderingComponent<'a> { +pub struct TcodRenderingComponent { pub console: Console, - pub input_component: Box + 'a> + pub input_component: Box + 'static> } -impl<'a> RenderingComponent for TcodRenderingComponent<'a> { - fn new(bounds: Bound) -> TcodRenderingComponent<'a> { +impl RenderingComponent for TcodRenderingComponent { + fn new(bounds: Bound) -> TcodRenderingComponent { let console = Console::init_root( (bounds.max.x + 1) as int, (bounds.max.y + 1) as int, diff --git a/src/rendering/windows.rs b/src/rendering/windows.rs index 39ce239..4599903 100644 --- a/src/rendering/windows.rs +++ b/src/rendering/windows.rs @@ -120,25 +120,14 @@ impl WindowComponent for TcodMessagesWindowComponent { window_component_getters!() } -pub struct Windows<'a> { - pub stats: Box, - pub map: Box, - pub input: Box, - pub messages: Box +pub struct Windows { + pub stats: Box, + pub map: Box, + pub input: Box, + pub messages: Box } -impl<'a > Windows<'a > { - pub fn all_windows(&'a mut self) -> Vec<&mut Box> { - let windows = vec![ - &mut self.stats, - &mut self.input, - &mut self.messages, - &mut self.map - ]; - - return windows; - } - +impl Windows { pub fn get_map_bounds(&self) -> Bound { self.map.get_bounds() }