implement player id allocation (#90)
* implement player id allocation * move `bevy/debug` to `dbg`
This commit is contained in:
@@ -36,7 +36,7 @@ pub mod water;
|
||||
use crate::{
|
||||
config::NetworkingConfig,
|
||||
heads_database::{HeadDatabaseAsset, HeadsDatabase},
|
||||
protocol::{PlayerId, messages::AssignClientPlayer},
|
||||
protocol::{PlayerIdCounter, messages::AssignClientPlayer},
|
||||
tb_entities::SpawnPoint,
|
||||
};
|
||||
use avian3d::{PhysicsPlugins, prelude::TransformInterpolation};
|
||||
@@ -198,12 +198,16 @@ fn start_solo_client(
|
||||
query: Query<&Transform, With<SpawnPoint>>,
|
||||
heads_db: Res<HeadsDatabase>,
|
||||
mut assign_player_id: MessageWriter<AssignClientPlayer>,
|
||||
mut ids: ResMut<PlayerIdCounter>,
|
||||
) {
|
||||
next.set(GameState::Playing);
|
||||
|
||||
player::spawn(commands, ClientId::Server, query, heads_db);
|
||||
ids.reset();
|
||||
let id = ids.alloc();
|
||||
|
||||
assign_player_id.write(AssignClientPlayer(PlayerId { id: 0 }));
|
||||
player::spawn(commands, ClientId::Server, id, query, heads_db);
|
||||
|
||||
assign_player_id.write(AssignClientPlayer(id));
|
||||
}
|
||||
|
||||
fn start_listen_server(
|
||||
@@ -212,12 +216,16 @@ fn start_listen_server(
|
||||
query: Query<&Transform, With<SpawnPoint>>,
|
||||
heads_db: Res<HeadsDatabase>,
|
||||
mut assign_player_id: MessageWriter<AssignClientPlayer>,
|
||||
mut ids: ResMut<PlayerIdCounter>,
|
||||
) {
|
||||
next.set(GameState::Hosting);
|
||||
|
||||
player::spawn(commands, ClientId::Server, query, heads_db);
|
||||
ids.reset();
|
||||
let id = ids.alloc();
|
||||
|
||||
assign_player_id.write(AssignClientPlayer(PlayerId { id: 0 }));
|
||||
player::spawn(commands, ClientId::Server, id, query, heads_db);
|
||||
|
||||
assign_player_id.write(AssignClientPlayer(id));
|
||||
}
|
||||
|
||||
fn start_client(mut next: ResMut<NextState<GameState>>) {
|
||||
|
||||
Reference in New Issue
Block a user