-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathscene.rs
More file actions
62 lines (49 loc) · 1.66 KB
/
scene.rs
File metadata and controls
62 lines (49 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use core::Actor;
use core::EngineState;
use config::Config;
use input::InputSystem;
use renderer::GraphicsState;
use std::sync::{Arc, Mutex};
pub struct Scene {
pub created: Vec<Arc<Actor>>,
pub active: Vec<Arc<Actor>>,
//pub destroy: Vec<Fn(u64) -> bool>,
}
impl Scene {
pub fn new(actors: Vec<Arc<Actor>>) -> Scene {
Scene {
created: actors,
active: Vec::new(),
//destroy: Vec::new(),
}
}
/// Add actor to the scene
pub fn add(&mut self, actor: Arc<Actor>) {
self.created.push(actor);
}
// Updates the scene. Spawns new actors, updates current actors, and destroys other actors.
pub fn update(&mut self, config: &Arc<Config>, gfx: &Arc<Mutex<GraphicsState>>, input: &Arc<Mutex<InputSystem>>) {
while let Some(mut new_actor) = self.created.pop() {
// Mount component to scene
{
let a = Arc::get_mut(&mut new_actor).unwrap();
a.start(EngineState::new(0, config.clone(), input.clone(), gfx.clone()));
}
self.active.push(new_actor);
}
for actor in &mut self.active {
let a = Arc::get_mut(actor).unwrap();
a.update();
}
// @TODO - Faster algorithm/data structure
//while let Some(actor_killer) = self.destroy.pop() {
// for actor in self.active {
// actor_killer(target_actor);
// }
//}
}
// Queue actors to be destroyed that satisfy callback.
//pub fn destroy(&mut self, callback: Fn(Actor) -> bool) {
// self.destroy(callback);
//}
}