Skip to content

Commit

Permalink
fix-断开链接后client重置到可以链接的状态
Browse files Browse the repository at this point in the history
  • Loading branch information
zzhgithub committed Sep 5, 2023
1 parent 7c10fa5 commit 165c0c9
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 6 deletions.
10 changes: 10 additions & 0 deletions src/client/filled_object/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,13 @@ fn sync_filled_objects(
}
}
}

pub fn setdown_filled_object(
mut commands: Commands,
mut filled_object_pool: ResMut<FilledObjectPool>,
) {
for (_, entity) in filled_object_pool.entities_map.clone() {
commands.entity(entity).despawn();
}
filled_object_pool.entities_map = HashMap::new();
}
19 changes: 19 additions & 0 deletions src/client/mesh_display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,3 +488,22 @@ fn cycle_check_mesh(
}
}
}

pub fn mesh_chunk_map_setdown(
mut commands: Commands,
mut mesh_manager: ResMut<MeshManager>,
mut chunk_sync_task: ResMut<ChunkSyncTask>,
mut chunk_map: ResMut<ChunkMap>,
mut chunk_update_task: ResMut<ChunkUpdateTask>,
) {
chunk_update_task.tasks.drain(..);
chunk_sync_task.tasks.drain(..);
chunk_map.map_data.clear();
for (_, entity) in mesh_manager.entities.clone() {
commands.entity(entity).despawn();
}
for (_, entity) in mesh_manager.water_entities.clone() {
commands.entity(entity).despawn();
}
*mesh_manager.as_mut() = MeshManager::default();
}
2 changes: 1 addition & 1 deletion src/client/player/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub mod mouse_control;
pub mod player_input;
pub mod throw_system;

#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct PlayerInfo {
// 客户端 实体
pub client_entity: Entity,
Expand Down
25 changes: 20 additions & 5 deletions src/client/state_manager/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use bevy::{
app::AppExit,
input::mouse::MouseWheel,
prelude::{
in_state, AmbientLight, Commands, Entity, EventReader, EventWriter, Input,
IntoSystemConfigs, KeyCode, Local, NextState, OnEnter, Plugin, Query, Res, ResMut, State,
States, Update, Vec2, With,
in_state, AmbientLight, Commands, DespawnRecursiveExt, Entity, EventReader, EventWriter,
Input, IntoSystemConfigs, KeyCode, Local, NextState, OnEnter, OnExit, Plugin, Query, Res,
ResMut, State, States, Update, Vec2, With,
},
window::{CursorGrabMode, PrimaryWindow, Window, WindowCloseRequested},
};
Expand All @@ -21,8 +21,8 @@ use crate::{
client::{
client_sync_players, client_sync_players_state,
console_commands::ConsoleCommandPlugins,
filled_object::ClientFilledObjectnPlugin,
mesh_display::ClientMeshPlugin,
filled_object::{setdown_filled_object, ClientFilledObjectnPlugin},
mesh_display::{mesh_chunk_map_setdown, ClientMeshPlugin},
player::{
controller::{CharacterController, CharacterControllerPlugin, ControllerFlag},
mouse_control::MouseControlPlugin,
Expand Down Expand Up @@ -115,13 +115,26 @@ impl Plugin for GamePlugin {
.run_if(in_state(GameState::Game))
.run_if(bevy_renet::transport::client_just_diconnected()),
);
app.add_systems(
OnExit(GameState::Game),
(setdown, mesh_chunk_map_setdown, setdown_filled_object),
);
}
}

fn setdown(mut commands: Commands, mut client_lobby: ResMut<ClientLobby>) {
for (_, info) in client_lobby.players.clone() {
commands.entity(info.client_entity).despawn_recursive();
}
// 清空数据
*client_lobby.as_mut() = ClientLobby::default();
}

fn setup(
mut commands: Commands,
connection_addr: Res<ConnectionAddr>,
mut play_state: ResMut<NextState<PlayState>>,
mut flags: ResMut<ControllerFlag>,
) {
let (client, transport) = new_renet_client(connection_addr.clone());
commands.insert_resource(client);
Expand All @@ -132,6 +145,8 @@ fn setup(
});
commands.insert_resource(ClientLobby::default());
play_state.set(PlayState::Main);
// 重新进入游戏后可以控制
flags.flag = true;
}

// 切换合成公式
Expand Down

0 comments on commit 165c0c9

Please sign in to comment.