Skip to content

Commit

Permalink
fix-修复不能打落特殊类型的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
zzhgithub committed Sep 17, 2023
1 parent cf0fa40 commit 299c3fa
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 30 additions & 5 deletions src/client/sp_mesh_display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

use bevy::{
prelude::{
Assets, Color, Commands, Entity, OnExit, PbrBundle, Plugin, Res, ResMut, Resource,
in_state, Assets, Color, Commands, Component, DespawnRecursiveExt, Entity,
IntoSystemConfigs, OnExit, PbrBundle, Plugin, Query, Res, ResMut, Resource,
StandardMaterial, Transform, Update, Vec3,
},
tasks::{AsyncComputeTaskPool, Task},
Expand Down Expand Up @@ -42,6 +43,8 @@ pub struct SpMeshTasks {
pub tasks: Vec<Task<(Voxel, ChunkKey, usize)>>,
}

#[derive(Debug, Component)]
pub struct NeedDelete;
pub struct SpMeshManagerPlugin;

impl Plugin for SpMeshManagerPlugin {
Expand All @@ -52,7 +55,13 @@ impl Plugin for SpMeshManagerPlugin {
app.insert_resource(SpMeshTasks { tasks: Vec::new() });
app.add_systems(
Update,
(sp_mesh_tasks_update, deal_sp_mesh_tasks, despawn_sp_mesh),
(
sp_mesh_tasks_update,
deal_sp_mesh_delete,
deal_sp_mesh_tasks,
despawn_sp_mesh,
)
.run_if(in_state(GameState::Game)),
);
app.add_systems(OnExit(GameState::Game), unset_all);
}
Expand Down Expand Up @@ -114,17 +123,26 @@ fn sp_mesh_tasks_update(
}
// 有一批要删除的数据
for del_key in old_keys.iter() {
println!("要删除的数据{:?}", old_keys);
if let Some(index_voxels_entity_map) = sp_mesh_manager.entities.get_mut(&chunk_key)
{
if let Some((_, entity)) = index_voxels_entity_map.remove(del_key) {
commands.entity(entity).despawn();
println!("删除的entity[{:?}]", entity);
commands.entity(entity).insert(NeedDelete);
println!("删除了mesh{}", del_key);
}
}
}
}
}
}

fn deal_sp_mesh_delete(mut commands: Commands, mesh_query: Query<Entity, &NeedDelete>) {
for entity in mesh_query.iter() {
commands.entity(entity).despawn_recursive();
}
}

fn deal_sp_mesh_tasks(
mut commands: Commands,
mut sp_mesh_tasks: ResMut<SpMeshTasks>,
Expand Down Expand Up @@ -154,8 +172,15 @@ fn deal_sp_mesh_tasks(
))))
.id();
if let Some(inner_map) = sp_mesh_manager.entities.get_mut(&chunk_key) {
inner_map.insert(index as u32, (v, entity));
if !inner_map.contains_key(&(index as u32)) {
println!("创建的entity[{:?}]", entity);
inner_map.insert(index as u32, (v, entity));
} else {
// 这要处理不需要的数据!
commands.entity(entity).despawn();
}
} else {
println!("第一次创建的entity[{:?}]", entity);
let mut map = HashMap::new();
map.insert(index as u32, (v, entity));
sp_mesh_manager.entities.insert(chunk_key, map);
Expand Down Expand Up @@ -189,7 +214,7 @@ fn despawn_sp_mesh(
if let Some(inner_map) = sp_mesh_manager.entities.remove(&key) {
println!("要清理的数据{}", inner_map.len());
for (_, (_, entity)) in inner_map {
commands.entity(entity).despawn();
commands.entity(entity).despawn_recursive();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/server/async_chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ pub fn deal_chunk_query_system(
// FIXME: 这里要考虑把代码格式简化 一下
// 发送物体被打下来的消息 old_voxel chunk_key, pos, 还原物体的位置!
if old_voxel.id != Voxel::EMPTY.id && voxel_type.id == Voxel::EMPTY.id {
println!("cube被打下来了: {:?}", voxel_type);
println!("cube被打下来了: {:?}", old_voxel);
// 物体时被打下来了 这里通过配置掉落
if let Some(staff_list) =
staff_info_stroge.voxel_to_staff_list(old_voxel)
Expand Down

0 comments on commit 299c3fa

Please sign in to comment.