@@ -75,9 +75,6 @@ pub const NETWORK_MAX_PREDICTION_WINDOW_DEFAULT: usize = 7;
75
75
/// Amount of frames GGRS will delay local input.
76
76
pub const NETWORK_LOCAL_INPUT_DELAY_DEFAULT : usize = 2 ;
77
77
78
- #[ doc( inline) ]
79
- pub use bones_matchmaker_proto:: MAX_PLAYERS ;
80
-
81
78
/// Possible errors returned by network loop.
82
79
pub enum NetworkError {
83
80
/// The session was disconnected.
@@ -157,15 +154,13 @@ pub trait NetworkSocket: Sync + Send {
157
154
fn send_reliable ( & self , target : SocketTarget , message : & [ u8 ] ) ;
158
155
/// Receive reliable messages from other players. The `usize` is the index of the player that
159
156
/// sent the message.
160
- fn recv_reliable ( & self ) -> Vec < ( usize , Vec < u8 > ) > ;
157
+ fn recv_reliable ( & self ) -> Vec < ( u32 , Vec < u8 > ) > ;
161
158
/// Close the connection.
162
159
fn close ( & self ) ;
163
160
/// Get the player index of the local player.
164
- fn player_idx ( & self ) -> usize ;
165
- /// Return, for every player index, whether the player is a local player.
166
- fn player_is_local ( & self ) -> [ bool ; MAX_PLAYERS ] ;
161
+ fn player_idx ( & self ) -> u32 ;
167
162
/// Get the player count for this network match.
168
- fn player_count ( & self ) -> usize ;
163
+ fn player_count ( & self ) -> u32 ;
169
164
170
165
/// Increment match id so messages from previous match that are still in flight
171
166
/// will be filtered out. Used when starting new session with existing socket.
@@ -175,7 +170,7 @@ pub trait NetworkSocket: Sync + Send {
175
170
/// The destination for a reliable network message.
176
171
pub enum SocketTarget {
177
172
/// Send to a specific player.
178
- Player ( usize ) ,
173
+ Player ( u32 ) ,
179
174
/// Broadcast to all players.
180
175
All ,
181
176
}
@@ -215,11 +210,11 @@ pub struct GgrsSessionRunner<'a, InputTypes: NetworkInputConfig<'a>> {
215
210
/// The GGRS peer-to-peer session.
216
211
pub session : P2PSession < GgrsConfig < InputTypes :: Dense > > ,
217
212
218
- /// Array containing a flag indicating, for each player, whether they are a local player .
219
- pub player_is_local : [ bool ; MAX_PLAYERS ] ,
213
+ /// Local player idx .
214
+ pub player_idx : u32 ,
220
215
221
216
/// Index of local player, computed from player_is_local
222
- pub local_player_idx : usize ,
217
+ pub local_player_idx : u32 ,
223
218
224
219
/// The frame time accumulator, used to produce a fixed refresh rate.
225
220
pub accumulator : f64 ,
@@ -254,10 +249,10 @@ pub struct GgrsSessionRunner<'a, InputTypes: NetworkInputConfig<'a>> {
254
249
pub struct GgrsSessionRunnerInfo {
255
250
/// The socket that will be converted into GGRS socket implementation.
256
251
pub socket : Socket ,
257
- /// The list of local players.
258
- pub player_is_local : [ bool ; MAX_PLAYERS ] ,
252
+ /// The local player idx
253
+ pub player_idx : u32 ,
259
254
/// the player count.
260
- pub player_count : usize ,
255
+ pub player_count : u32 ,
261
256
262
257
/// Max prediction window (max number of frames client may predict ahead of last confirmed frame)
263
258
/// `None` will use Bone's default.
@@ -278,11 +273,11 @@ impl GgrsSessionRunnerInfo {
278
273
max_prediction_window : Option < usize > ,
279
274
local_input_delay : Option < usize > ,
280
275
) -> Self {
281
- let player_is_local = socket. player_is_local ( ) ;
276
+ let player_idx = socket. player_idx ( ) ;
282
277
let player_count = socket. player_count ( ) ;
283
278
Self {
284
279
socket,
285
- player_is_local ,
280
+ player_idx ,
286
281
player_count,
287
282
max_prediction_window,
288
283
local_input_delay,
@@ -323,31 +318,32 @@ where
323
318
. unwrap ( ) ;
324
319
325
320
let mut builder = ggrs:: SessionBuilder :: new ( )
326
- . with_num_players ( info. player_count )
321
+ . with_num_players ( info. player_count as usize )
327
322
. with_input_delay ( local_input_delay)
328
323
. with_fps ( network_fps)
329
324
. unwrap ( )
330
325
. with_max_prediction_window ( max_prediction)
331
326
. unwrap ( ) ;
332
327
333
- let mut local_player_idx: Option < usize > = None ;
328
+ let local_player_idx = info . player_idx ;
334
329
for i in 0 ..info. player_count {
335
- if info. player_is_local [ i] {
336
- builder = builder. add_player ( ggrs:: PlayerType :: Local , i) . unwrap ( ) ;
337
- local_player_idx = Some ( i) ;
330
+ if i == info. player_idx {
331
+ builder = builder
332
+ . add_player ( ggrs:: PlayerType :: Local , i as usize )
333
+ . unwrap ( ) ;
338
334
} else {
339
- builder = builder. add_player ( ggrs:: PlayerType :: Remote ( i) , i) . unwrap ( ) ;
335
+ builder = builder
336
+ . add_player ( ggrs:: PlayerType :: Remote ( i as usize ) , i as usize )
337
+ . unwrap ( ) ;
340
338
}
341
339
}
342
- let local_player_idx =
343
- local_player_idx. expect ( "Networking player_is_local array has no local players." ) ;
344
340
345
341
let session = builder. start_p2p_session ( info. socket . clone ( ) ) . unwrap ( ) ;
346
342
347
343
Self {
348
344
last_player_input : InputTypes :: Dense :: default ( ) ,
349
345
session,
350
- player_is_local : info. player_is_local ,
346
+ player_idx : info. player_idx ,
351
347
local_player_idx,
352
348
accumulator : default ( ) ,
353
349
last_run : None ,
@@ -395,11 +391,11 @@ where
395
391
self . input_collector . update_just_pressed ( ) ;
396
392
397
393
// save local players dense input for use with ggrs
398
- match player_inputs. get_control_source ( self . local_player_idx ) {
394
+ match player_inputs. get_control_source ( self . local_player_idx as usize ) {
399
395
Some ( control_source) => {
400
396
let control = self
401
397
. input_collector
402
- . get_control ( self . local_player_idx , control_source) ;
398
+ . get_control ( self . local_player_idx as usize , control_source) ;
403
399
404
400
self . last_player_input = control. get_dense_input ( ) ;
405
401
} ,
@@ -482,13 +478,16 @@ where
482
478
483
479
if !self . local_input_disabled {
484
480
self . session
485
- . add_local_input ( self . local_player_idx , self . last_player_input )
481
+ . add_local_input ( self . local_player_idx as usize , self . last_player_input )
486
482
. unwrap ( ) ;
487
483
} else {
488
484
// If local input is disabled, we still submit a default value representing no-inputs.
489
485
// This way if input is disabled current inputs will not be held down indefinitely.
490
486
self . session
491
- . add_local_input ( self . local_player_idx , InputTypes :: Dense :: default ( ) )
487
+ . add_local_input (
488
+ self . local_player_idx as usize ,
489
+ InputTypes :: Dense :: default ( ) ,
490
+ )
492
491
. unwrap ( ) ;
493
492
}
494
493
@@ -566,7 +565,7 @@ where
566
565
{
567
566
trace ! (
568
567
"Net player({player_idx}) local: {}, status: {status:?}, input: {:?}" ,
569
- self . local_player_idx == player_idx,
568
+ self . local_player_idx as usize == player_idx,
570
569
input
571
570
) ;
572
571
player_inputs. network_update (
@@ -630,8 +629,8 @@ where
630
629
631
630
let runner_info = GgrsSessionRunnerInfo {
632
631
socket : self . socket . clone ( ) ,
633
- player_is_local : self . player_is_local ,
634
- player_count : self . session . num_players ( ) ,
632
+ player_idx : self . player_idx ,
633
+ player_count : self . session . num_players ( ) . try_into ( ) . unwrap ( ) ,
635
634
max_prediction_window : Some ( self . session . max_prediction ( ) ) ,
636
635
local_input_delay : Some ( self . local_input_delay ) ,
637
636
} ;
0 commit comments