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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// extern crate blizzard_engine;
// extern crate blizzard_engine_derive;
// use blizzard_engine::ecs::{ComponentRegistry, EntityManager, World};
// use blizzard_engine::game::Game;
// use blizzard_engine_derive::ComponentRegistry;
// use std::collections::HashMap;
// use std::sync::{Arc, Mutex};
// // World
// #[derive(Debug)]
// struct MyWorld {
// entity_manager: EntityManager,
// position: PositionRegistry,
// counters: CounterRegistry,
// others: OtherRegistry,
// }
// impl World for MyWorld {
// fn new() -> Self {
// Self {
// entity_manager: EntityManager::new(),
// position: PositionRegistry::new(),
// counters: CounterRegistry::new(),
// others: OtherRegistry::new(),
// }
// }
// fn run_systems(&mut self) {
// position_system(&mut self.position.components);
// counter_system(&mut self.counters.components);
// other_system(&mut self.others.components);
// }
// }
// #[derive(ComponentRegistry, Debug)]
// struct OtherRegistry {
// components: HashMap<u32, i32>,
// }
// #[derive(ComponentRegistry, Debug)]
// struct PositionRegistry {
// components: HashMap<u32, Position>,
// }
// #[derive(Debug, Clone, Copy)]
// struct Position {
// x: i32,
// y: i32,
// }
// impl Position {
// fn new() -> Self {
// Self { x: 0, y: 0 }
// }
// fn displace(&mut self, x: i32, y: i32) {
// self.x += x;
// self.y += y;
// }
// }
// #[derive(ComponentRegistry, Debug)]
// struct CounterRegistry {
// components: HashMap<u32, i32>,
// }
// // Systems
// fn position_system(positions: &mut HashMap<u32, Position>) {
// for (_, position) in positions.iter_mut() {
// position.displace(1, 1);
// }
// }
// fn counter_system(counters: &mut HashMap<u32, i32>) {
// for (_, counter) in counters.iter_mut() {
// *counter *= 2;
// }
// }
// fn other_system(others: &mut HashMap<u32, i32>) {
// for (_, other) in others.iter_mut() {
// *other -= 1;
// }
// }
// // Games
// struct MyGame {
// world: MyWorld,
// counter: u32,
// }
// impl Game<i32, i32> for MyGame {
// fn world_config(&mut self) {
// // Create Entities
// let ent1 = self.world.entity_manager.create_entity();
// let ent2 = self.world.entity_manager.create_entity();
// let ent3 = self.world.entity_manager.create_entity();
// // Add components
// self.world.position.add(ent1, Position::new());
// self.world.position.add(ent3, Position::new());
// self.world.counters.add(ent2, 1);
// self.world.counters.add(ent3, 1);
// self.world.others.add(ent1, 0);
// // Create multiple entities
// let entities = self.world.entity_manager.create_n_entities(2);
// // Add components to many entities
// self.world.counters.add_many(&entities, 1);
// self.world.position.add_many(&entities, Position::new());
// }
// fn update(&mut self, _: i32, _: Arc<Mutex<i32>>) {
// self.world.run_systems();
// self.counter += 1;
// println!("{:#?}", self.world);
// }
// fn render(&mut self) {}
// fn end_game(&self) -> bool {
// self.counter > 10
// }
// }
// fn new_game(world: MyWorld) -> impl Game<i32, i32> {
// MyGame {
// counter: 0,
// world: world,
// }
// }
// fn main() {
// let game = new_game(MyWorld::new());
// blizzard_engine::start(game, 0, 0, );
// }