@@ -6,10 +6,14 @@ use super::input;
6
6
use super :: time;
7
7
use crate :: audio;
8
8
use crate :: cfg;
9
+ use crate :: ecs:: components:: gfx:: C_Camera2D ;
10
+ use crate :: ecs:: components:: transform:: C_Transform2D ;
11
+ use crate :: ecs:: entity_manager:: Entity ;
9
12
use crate :: fs;
10
13
use crate :: game:: gameplay_system;
11
14
use crate :: gfx;
12
15
use crate :: resources;
16
+ use std:: collections:: HashMap ;
13
17
use std:: convert:: TryFrom ;
14
18
use std:: sync:: mpsc;
15
19
use std:: thread:: JoinHandle ;
@@ -55,13 +59,14 @@ pub struct App<'r> {
55
59
env : Env_Info ,
56
60
57
61
config : cfg:: Config ,
58
- ui_req_tx : Option < std :: sync :: mpsc:: Sender < gfx:: ui:: UI_Request > > ,
62
+ ui_req_tx : Option < mpsc:: Sender < gfx:: ui:: UI_Request > > ,
59
63
60
64
// Resources
61
65
audio_resources : resources:: audio:: Audio_Resources < ' r > ,
62
66
63
67
// Engine Systems
64
68
render_thread : Option < JoinHandle < ( ) > > ,
69
+ render_thread_quit : Option < mpsc:: Sender < ( ) > > ,
65
70
input_actions_rx : Option < mpsc:: Receiver < input:: Action_List > > ,
66
71
audio_system : audio:: system:: Audio_System ,
67
72
gameplay_system : gameplay_system:: Gameplay_System ,
@@ -80,6 +85,7 @@ impl<'r> App<'r> {
80
85
ui_req_tx : None ,
81
86
audio_resources : resources:: audio:: Audio_Resources :: new ( sound_loader) ,
82
87
render_thread : None ,
88
+ render_thread_quit : None ,
83
89
input_actions_rx : None ,
84
90
audio_system : audio:: system:: Audio_System :: new ( 10 ) ,
85
91
gameplay_system : gameplay_system:: Gameplay_System :: new ( ) ,
@@ -99,8 +105,6 @@ impl<'r> App<'r> {
99
105
}
100
106
101
107
fn init_all_systems ( & mut self ) -> Maybe_Error {
102
- self . gameplay_system . init ( & self . config ) ?;
103
-
104
108
let config_watcher = Box :: new ( cfg:: sync:: Config_Watch_Handler :: new ( & self . config ) ) ;
105
109
fs:: file_watcher:: start_file_watch (
106
110
self . env . get_cfg_root ( ) . to_path_buf ( ) ,
@@ -110,25 +114,39 @@ impl<'r> App<'r> {
110
114
Ok ( ( ) )
111
115
}
112
116
113
- fn start_render_thread ( & mut self ) {
117
+ fn start_render_thread (
118
+ & mut self ,
119
+ entity_transform_rx : mpsc:: Receiver < ( Entity , C_Transform2D ) > ,
120
+ camera_transform_rx : mpsc:: Receiver < C_Camera2D > ,
121
+ ) {
114
122
let ( input_tx, input_rx) = mpsc:: channel ( ) ;
115
123
self . input_actions_rx = Some ( input_rx) ;
116
124
117
125
let ( ui_tx, ui_rx) = mpsc:: channel ( ) ;
118
126
self . ui_req_tx = Some ( ui_tx) ;
119
127
128
+ let ( quit_tx, quit_rx) = mpsc:: channel ( ) ;
129
+ self . render_thread_quit = Some ( quit_tx) ;
130
+
120
131
self . render_thread = Some ( gfx:: render_system:: start_render_thread (
121
132
self . env . clone ( ) ,
122
133
input_tx,
123
134
ui_rx,
135
+ entity_transform_rx,
136
+ camera_transform_rx,
137
+ quit_rx,
124
138
gfx:: render_system:: Render_System_Config {
125
139
clear_color : colors:: rgb ( 48 , 10 , 36 ) ,
126
140
} ,
127
141
) ) ;
128
142
}
129
143
130
144
pub fn run ( & mut self ) -> Maybe_Error {
131
- self . start_render_thread ( ) ;
145
+ let ( et_tx, et_rx) = mpsc:: channel ( ) ;
146
+ let ( cam_tx, cam_rx) = mpsc:: channel ( ) ;
147
+ self . gameplay_system . init ( & self . config , et_tx, cam_tx) ?; // @Temporary workaround
148
+ self . start_render_thread ( et_rx, cam_rx) ;
149
+
132
150
self . start_game_loop ( ) ?;
133
151
Ok ( ( ) )
134
152
}
@@ -193,6 +211,17 @@ impl<'r> App<'r> {
193
211
}
194
212
}
195
213
214
+ self . render_thread_quit
215
+ . as_mut ( )
216
+ . unwrap ( )
217
+ . send ( ( ) )
218
+ . expect ( "[ ERR ] Failed to send quit message to render thread!" ) ;
219
+ self . render_thread
220
+ . take ( )
221
+ . unwrap ( )
222
+ . join ( )
223
+ . expect ( "[ ERR ] Failed to join render thread!" ) ;
224
+
196
225
Ok ( ( ) )
197
226
}
198
227
0 commit comments