From 165c0c9e8c3e4eb4abd073a7b9426f48b4524664 Mon Sep 17 00:00:00 2001 From: zhouzihao <1042181618@qq.com> Date: Tue, 5 Sep 2023 10:48:28 +0800 Subject: [PATCH] =?UTF-8?q?fix-=E6=96=AD=E5=BC=80=E9=93=BE=E6=8E=A5?= =?UTF-8?q?=E5=90=8Eclient=E9=87=8D=E7=BD=AE=E5=88=B0=E5=8F=AF=E4=BB=A5?= =?UTF-8?q?=E9=93=BE=E6=8E=A5=E7=9A=84=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/client/filled_object/mod.rs | 10 ++++++++++ src/client/mesh_display.rs | 19 +++++++++++++++++++ src/client/player/mod.rs | 2 +- src/client/state_manager/game.rs | 25 ++++++++++++++++++++----- 4 files changed, 50 insertions(+), 6 deletions(-) diff --git a/src/client/filled_object/mod.rs b/src/client/filled_object/mod.rs index 9a407c2..624ac19 100644 --- a/src/client/filled_object/mod.rs +++ b/src/client/filled_object/mod.rs @@ -168,3 +168,13 @@ fn sync_filled_objects( } } } + +pub fn setdown_filled_object( + mut commands: Commands, + mut filled_object_pool: ResMut, +) { + for (_, entity) in filled_object_pool.entities_map.clone() { + commands.entity(entity).despawn(); + } + filled_object_pool.entities_map = HashMap::new(); +} diff --git a/src/client/mesh_display.rs b/src/client/mesh_display.rs index 536d404..e20b2ff 100644 --- a/src/client/mesh_display.rs +++ b/src/client/mesh_display.rs @@ -488,3 +488,22 @@ fn cycle_check_mesh( } } } + +pub fn mesh_chunk_map_setdown( + mut commands: Commands, + mut mesh_manager: ResMut, + mut chunk_sync_task: ResMut, + mut chunk_map: ResMut, + mut chunk_update_task: ResMut, +) { + 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(); +} diff --git a/src/client/player/mod.rs b/src/client/player/mod.rs index 74f6493..7057538 100644 --- a/src/client/player/mod.rs +++ b/src/client/player/mod.rs @@ -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, diff --git a/src/client/state_manager/game.rs b/src/client/state_manager/game.rs index cafe55c..14a7737 100644 --- a/src/client/state_manager/game.rs +++ b/src/client/state_manager/game.rs @@ -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}, }; @@ -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, @@ -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) { + 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, mut play_state: ResMut>, + mut flags: ResMut, ) { let (client, transport) = new_renet_client(connection_addr.clone()); commands.insert_resource(client); @@ -132,6 +145,8 @@ fn setup( }); commands.insert_resource(ClientLobby::default()); play_state.set(PlayState::Main); + // 重新进入游戏后可以控制 + flags.flag = true; } // 切换合成公式