Skip to content

Commit fba4e28

Browse files
committed
it works!
1 parent 1c87c61 commit fba4e28

File tree

6 files changed

+44
-48
lines changed

6 files changed

+44
-48
lines changed

src/actor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub struct Actor {
1818
}
1919

2020
impl Clone for Actor {
21-
pub fn clone(&self) -> Actor {
21+
fn clone(&self) -> Actor {
2222
let mc = self.movement_component.box_clone();
2323
Actor::new(self.position.x, self.position.y, self.display_char, mc, self.is_pc, self.foreground, self.background, self.health)
2424
}

src/game.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,18 @@ impl MoveInfo {
4444
}
4545
}
4646

47-
pub struct Game<'a, 'b> {
47+
pub struct Game {
4848
pub move_info: Rc<RefCell<MoveInfo>>,
4949
pub exit: bool,
5050
pub window_bounds: Bound,
51-
pub rendering_component: Box<RenderingComponent + 'a>,
52-
pub game_state: Box<GameState<'a> + 'a>,
53-
pub windows: Windows<'a>,
51+
pub rendering_component: Box<RenderingComponent + 'static>,
52+
pub game_state: Box<GameState + 'static>,
53+
pub windows: Windows,
5454
pub maps: Maps
5555
}
5656

57-
impl<'a, 'b> Game<'a, 'b> {
58-
pub fn new() -> Game<'a, 'b> {
57+
impl Game {
58+
pub fn new() -> Game {
5959
let total_bounds = Bound::new(0, 0, 99, 61);
6060
let stats_bounds = Bound::new(79, 0, 99, 49);
6161
let input_bounds = Bound::new(0, 50, 99, 51);
@@ -92,11 +92,11 @@ impl<'a, 'b> Game<'a, 'b> {
9292
}
9393
}
9494

95-
pub fn render(&'a mut self) {
95+
pub fn render(&mut self) {
9696
self.game_state.render(&mut self.rendering_component, &mut self.maps, &mut self.windows);
9797
}
9898

99-
pub fn update(&'b mut self) {
99+
pub fn update(&mut self) {
100100
if self.game_state.should_update_state() {
101101
self.game_state.exit();
102102
self.update_state();

src/game_states.rs

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,27 @@ use game::MoveInfo;
88
use input::{KeyCode, SpecialKey};
99
use combat::{Weapon, Boomerang};
1010

11-
pub trait GameState<'a> {
11+
pub trait GameState {
1212
fn new() -> Self;
13-
fn new_with_weapon(Box<Weapon + 'a>) -> Self;
13+
fn new_with_weapon(Box<Weapon + 'static>) -> Self;
1414

1515
fn enter(&self, &mut Windows) {}
1616
fn exit(&self) {}
1717

1818
fn update(&mut self, maps: &mut Maps, windows: &mut Windows, Rc<RefCell<MoveInfo>>);
19-
fn render<'r>(&mut self, renderer: &mut Box<RenderingComponent>, maps: &mut Maps, windows: &'r mut Windows<'r>) {
19+
fn render(&mut self, renderer: &mut Box<RenderingComponent>, maps: &mut Maps, windows: &mut Windows) {
2020
renderer.before_render_new_frame();
21-
let mut all_windows = windows.all_windows();
22-
for window in all_windows.iter_mut() {
23-
renderer.attach_window(*window);
24-
}
21+
let ref mut stats = windows.stats;
22+
renderer.attach_window(stats);
23+
24+
let ref mut input = windows.input;
25+
renderer.attach_window(input);
26+
27+
let ref mut messages = windows.messages;
28+
renderer.attach_window(messages);
29+
30+
let ref mut map = windows.map;
31+
renderer.attach_window(map);
2532
maps.render(renderer);
2633
renderer.after_render_new_frame();
2734
}
@@ -31,12 +38,12 @@ pub trait GameState<'a> {
3138

3239
pub struct MovementGameState;
3340

34-
impl<'a> GameState<'a> for MovementGameState {
41+
impl GameState for MovementGameState {
3542
fn new() -> MovementGameState {
3643
MovementGameState
3744
}
3845

39-
fn new_with_weapon(_: Box<Weapon + 'a>) -> MovementGameState {
46+
fn new_with_weapon(_: Box<Weapon>) -> MovementGameState {
4047
MovementGameState
4148
}
4249

@@ -69,21 +76,21 @@ impl<'a> GameState<'a> for MovementGameState {
6976
}
7077
}
7178

72-
pub struct AttackInputGameState<'a> {
79+
pub struct AttackInputGameState {
7380
should_update_state: bool,
74-
pub weapon: Box<Weapon + 'a>
81+
pub weapon: Box<Weapon + 'static>
7582
}
7683

77-
impl<'a> GameState<'a> for AttackInputGameState<'a> {
78-
fn new() -> AttackInputGameState<'a> {
84+
impl GameState for AttackInputGameState {
85+
fn new() -> AttackInputGameState {
7986
let weapon : Box<Boomerang> = box Weapon::new();
8087
AttackInputGameState {
8188
should_update_state: false,
8289
weapon: weapon
8390
}
8491
}
8592

86-
fn new_with_weapon(weapon: Box<Weapon + 'a>) -> AttackInputGameState<'a> {
93+
fn new_with_weapon(weapon: Box<Weapon + 'static>) -> AttackInputGameState {
8794
AttackInputGameState {
8895
should_update_state: false,
8996
weapon: weapon

src/movement.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use std::rand::Rng;
2424
pub trait MovementComponent {
2525
fn new(Rc<RefCell<MoveInfo>>) -> Self;
2626
fn update(&self, Point, &mut Windows) -> Point;
27-
fn box_clone(&self) -> Box<MovementComponent>;
27+
fn box_clone(&self) -> Box<MovementComponent + 'static>;
2828
}
2929

3030
pub struct AggroMovementComponent {
@@ -36,7 +36,7 @@ impl MovementComponent for AggroMovementComponent {
3636
AggroMovementComponent { move_info: move_info }
3737
}
3838

39-
fn box_clone(&self) -> Box<MovementComponent> {
39+
fn box_clone(&self) -> Box<MovementComponent + 'static> {
4040
box AggroMovementComponent { move_info: self.move_info.clone() }
4141
}
4242

@@ -81,7 +81,7 @@ impl MovementComponent for UserMovementComponent {
8181
UserMovementComponent { move_info: move_info }
8282
}
8383

84-
fn box_clone(&self) -> Box<MovementComponent> {
84+
fn box_clone(&self) -> Box<MovementComponent + 'static> {
8585
box UserMovementComponent { move_info: self.move_info.clone() }
8686
}
8787

@@ -135,7 +135,7 @@ impl MovementComponent for RandomMovementComponent {
135135
RandomMovementComponent { move_info: move_info }
136136
}
137137

138-
fn box_clone(&self) -> Box<MovementComponent> {
138+
fn box_clone(&self) -> Box<MovementComponent + 'static> {
139139
box RandomMovementComponent { move_info: self.move_info.clone() }
140140
}
141141

src/rendering/renderers.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ pub trait RenderingComponent {
2727
fn translate_color(&self, Color) -> tcod::Color;
2828
}
2929

30-
pub struct TcodRenderingComponent<'a> {
30+
pub struct TcodRenderingComponent {
3131
pub console: Console,
32-
pub input_component: Box<InputComponent<KeyState> + 'a>
32+
pub input_component: Box<InputComponent<KeyState> + 'static>
3333
}
3434

35-
impl<'a> RenderingComponent for TcodRenderingComponent<'a> {
36-
fn new(bounds: Bound) -> TcodRenderingComponent<'a> {
35+
impl RenderingComponent for TcodRenderingComponent {
36+
fn new(bounds: Bound) -> TcodRenderingComponent {
3737
let console = Console::init_root(
3838
(bounds.max.x + 1) as int,
3939
(bounds.max.y + 1) as int,

src/rendering/windows.rs

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -120,25 +120,14 @@ impl WindowComponent for TcodMessagesWindowComponent {
120120
window_component_getters!()
121121
}
122122

123-
pub struct Windows<'a> {
124-
pub stats: Box<WindowComponent + 'a>,
125-
pub map: Box<WindowComponent + 'a>,
126-
pub input: Box<WindowComponent + 'a>,
127-
pub messages: Box<WindowComponent + 'a>
123+
pub struct Windows {
124+
pub stats: Box<WindowComponent + 'static>,
125+
pub map: Box<WindowComponent + 'static>,
126+
pub input: Box<WindowComponent + 'static>,
127+
pub messages: Box<WindowComponent + 'static>
128128
}
129129

130-
impl<'a > Windows<'a > {
131-
pub fn all_windows(&'a mut self) -> Vec<&mut Box<WindowComponent>> {
132-
let windows = vec![
133-
&mut self.stats,
134-
&mut self.input,
135-
&mut self.messages,
136-
&mut self.map
137-
];
138-
139-
return windows;
140-
}
141-
130+
impl Windows {
142131
pub fn get_map_bounds(&self) -> Bound {
143132
self.map.get_bounds()
144133
}

0 commit comments

Comments
 (0)