@@ -32,7 +32,7 @@ use std::{
32
32
cell:: RefCell ,
33
33
fmt:: Debug ,
34
34
io:: Write ,
35
- net:: { SocketAddr , ToSocketAddrs } ,
35
+ net:: SocketAddr ,
36
36
sync:: { Arc , atomic:: AtomicBool } ,
37
37
} ;
38
38
@@ -144,15 +144,6 @@ pub fn adjust_file_descriptor_limits(recommended_min: u64) -> std::io::Result<()
144
144
#[ derive( Component , Debug , Clone , PartialEq , Eq , Hash , Constructor ) ]
145
145
pub struct Address ( SocketAddr ) ;
146
146
147
- #[ derive( Component ) ]
148
- pub struct AddressModule ;
149
-
150
- impl Module for AddressModule {
151
- fn module ( world : & World ) {
152
- world. component :: < Address > ( ) ;
153
- }
154
- }
155
-
156
147
/// The central [`HyperionCore`] struct which owns and manages the entire server.
157
148
#[ derive( Component ) ]
158
149
pub struct HyperionCore ;
@@ -164,28 +155,21 @@ struct Shutdown {
164
155
165
156
impl Module for HyperionCore {
166
157
fn module ( world : & World ) {
167
- let address = world. get :: < & Address > ( |address| address. 0 ) ;
168
- Self :: init_with ( world, address) . unwrap ( ) ;
158
+ Self :: init_with ( world) . unwrap ( ) ;
169
159
}
170
160
}
171
161
172
162
impl HyperionCore {
173
163
/// Initializes the server with a custom handler.
174
- fn init_with (
175
- world : & World ,
176
- address : impl ToSocketAddrs + Send + Sync + ' static ,
177
- ) -> anyhow:: Result < ( ) > {
164
+ fn init_with ( world : & World ) -> anyhow:: Result < ( ) > {
178
165
// Denormals (numbers very close to 0) are flushed to zero because doing computations on them
179
166
// is slow.
180
167
181
- no_denormals:: no_denormals ( || Self :: init_with_helper ( world, address ) )
168
+ no_denormals:: no_denormals ( || Self :: init_with_helper ( world) )
182
169
}
183
170
184
171
/// Initialize the server.
185
- fn init_with_helper (
186
- world : & World ,
187
- address : impl ToSocketAddrs + Send + Sync + ' static ,
188
- ) -> anyhow:: Result < ( ) > {
172
+ fn init_with_helper ( world : & World ) -> anyhow:: Result < ( ) > {
189
173
// 10k players * 2 file handles / player = 20,000. We can probably get away with 16,384 file handles
190
174
#[ cfg( unix) ]
191
175
adjust_file_descriptor_limits ( 32_768 ) . context ( "failed to set file limits" ) ?;
@@ -212,10 +196,7 @@ impl HyperionCore {
212
196
. map_err ( |_| anyhow:: anyhow!( "failed to create compression level" ) ) ?,
213
197
} ) ;
214
198
215
- let address = address
216
- . to_socket_addrs ( ) ?
217
- . next ( )
218
- . context ( "could not get first address" ) ?;
199
+ world. component :: < Address > ( ) ;
219
200
220
201
world. component :: < Shutdown > ( ) ;
221
202
let shutdown = Arc :: new ( AtomicBool :: new ( false ) ) ;
@@ -328,9 +309,18 @@ impl HyperionCore {
328
309
329
310
world. set ( MojangClient :: new ( & runtime, ApiProvider :: MAT_DOES_DEV ) ) ;
330
311
331
- let ( receive_state, egress_comm) = init_proxy_comms ( & runtime, address) ;
332
-
333
- world. set ( receive_state) ;
312
+ #[ rustfmt:: skip]
313
+ world
314
+ . observer :: < flecs:: OnSet , ( & Address , & AsyncRuntime ) > ( )
315
+ . term_at ( 0 ) . singleton ( )
316
+ . term_at ( 1 ) . filter ( ) . singleton ( )
317
+ . each_iter ( |it, _, ( address, runtime) | {
318
+ let world = it. world ( ) ;
319
+ let address = address. 0 ;
320
+ let ( receive_state, egress_comm) = init_proxy_comms ( runtime, address) ;
321
+ world. set ( receive_state) ;
322
+ world. set ( egress_comm) ;
323
+ } ) ;
334
324
335
325
let global = Global :: new ( shared. clone ( ) ) ;
336
326
@@ -348,8 +338,6 @@ impl HyperionCore {
348
338
let events = Events :: initialize ( world) ;
349
339
world. set ( events) ;
350
340
351
- world. set ( egress_comm) ;
352
-
353
341
world. set ( runtime) ;
354
342
world. set ( StreamLookup :: default ( ) ) ;
355
343
0 commit comments