Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature support tree #53

Merged
merged 4 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"./Cargo.toml",
"./Cargo.toml",
".\\Cargo.toml",
".\\Cargo.toml"
".\\Cargo.toml",
"./Cargo.toml"
]
}
Binary file added assets/textures/苹果叶子.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/苹果树A面.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/苹果树B面.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 0 additions & 9 deletions src/bin/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,3 @@ fn main() {
//app.add_systems(Startup, setting_language);
app.run();
}

//setting of switch the lanuguage
// fn setting_language(mut localize: ResMut<Localize>) {
// localize.set_language(CHINESE);

// println!("开始是:{}", localize.get("开始"));
// }

// 快速注释 Ctrl + ?
2 changes: 2 additions & 0 deletions src/bin/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use just_join::{
},
sky::ServerSkyPlugins,
staff::ServerStaffInfoPlugin,
voxel_world::biomes::OtherTreePlugin,
PROTOCOL_ID,
};
use renet_visualizer::RenetServerVisualizer;
Expand Down Expand Up @@ -119,6 +120,7 @@ fn main() {
ObjectFilingPlugin,
ServerStaffRulePlugin,
CossTroughCheckPlugin,
OtherTreePlugin,
));

let (server, transport) = new_renet_server();
Expand Down
11 changes: 10 additions & 1 deletion src/client/mesh_display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{

use bevy::{
prelude::{
AlphaMode, AssetServer, Assets, Color, Commands, Component, Entity, Handle,
AlphaMode, AssetServer, Assets, Color, Commands, Component, Entity, Handle, IVec3,
IntoSystemConfigs, Last, MaterialMeshBundle, MaterialPlugin, Mesh, Plugin, PreUpdate, Res,
ResMut, Resource, StandardMaterial, Startup, Transform, Update,
},
Expand Down Expand Up @@ -165,6 +165,15 @@ pub fn async_chunk_result(
while let Some(message) = client.receive_message(ServerChannel::ChunkResult) {
let chunk_result: ChunkResult = bincode::deserialize(&message).unwrap();
match chunk_result {
ChunkResult::UpdateChunkData { key, data } => {
let voxel = uncompress(&data.0, data.1);
chunk_map.write_chunk(key.clone(), voxel);
key_set.insert((1, key.to_y_zore()));
key_set.insert((0, key.to_y_zore().add_ivec3(IVec3::new(1, 0, 0))));
key_set.insert((0, key.to_y_zore().add_ivec3(IVec3::new(-1, 0, 0))));
key_set.insert((0, key.to_y_zore().add_ivec3(IVec3::new(0, 0, 1))));
key_set.insert((0, key.to_y_zore().add_ivec3(IVec3::new(0, 0, -1))));
}
ChunkResult::ChunkData { key, data } => {
let task = pool.spawn(async move { (key, uncompress(&data.0, data.1)) });
chunk_sync_task.tasks.push(task);
Expand Down
4 changes: 2 additions & 2 deletions src/client/state_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,5 @@ pub fn new_renet_client(connection_addr: ConnectionAddr) -> (RenetClient, Netcod
(client, transport)
}

pub const CHINESE:&str="Chinese";
pub const ENGLISH:&str="English";
pub const CHINESE: &str = "Chinese";
pub const ENGLISH: &str = "English";
2 changes: 1 addition & 1 deletion src/client/ui/staff_rules.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// 合成相关UI
use bevy_easy_localize::Localize;
use bevy::{
prelude::{Entity, Query, Res, ResMut, With},
window::{PrimaryWindow, Window},
};
use bevy_easy_localize::Localize;
use bevy_egui::{
egui::{self, Align2, Vec2},
EguiContext, EguiUserTextures,
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ pub const CHUNK_SIZE: i32 = 16;
pub const CHUNK_SIZE_U32: u32 = CHUNK_SIZE as u32;
pub const CHUNK_SIZE_ADD_2_U32: u32 = CHUNK_SIZE_U32 + 2;
// 贴图个数
pub const MAX_TEXTURE_COUNT: usize = 13;
pub const MAX_TEXTURE_COUNT: usize = 16;
// 物体选择半径
pub const TOUCH_RADIUS: f32 = 5.;
pub const CLIENT_DEBUG: bool = false;
pub const CLIENT_FPS: bool = false;
// 是否每次都重新生成地形
pub const CLIENT_MAP_GEN: bool = false;
pub const CLIENT_MAP_GEN: bool = true;

// 最大物品堆放
pub const MAX_STAFF_FIXED: usize = 999;
Expand Down
14 changes: 12 additions & 2 deletions src/server/async_chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::{
server::{message_def::ServerChannel, object_filing::put_object::put_object},
staff::StaffInfoStroge,
voxel_world::{
biomes::OtherTreeTasksMap,
chunk::ChunkKey,
chunk_map::ChunkMap,
compress::compress,
Expand Down Expand Up @@ -47,6 +48,7 @@ pub fn deal_chunk_query_system(
// 获取玩家当前状态 和处理
mut query_state: Query<&mut PlayerOntimeState>,
server_lobby: Res<ServerLobby>,
mut other_tree_tasks_map: ResMut<OtherTreeTasksMap>,
) {
let pool = AsyncComputeTaskPool::get();
for client_id in server.clients_id() {
Expand All @@ -63,7 +65,11 @@ pub fn deal_chunk_query_system(
if let Some(data) = chunk_map.map_data.get(&new_key) {
voxels = data.clone();
} else {
voxels = db.find_by_chunk_key(new_key, db_save_task.as_mut());
voxels = db.find_by_chunk_key(
new_key,
db_save_task.as_mut(),
other_tree_tasks_map.as_mut(),
);
}
let (buffer, tree) = compress(voxels.clone());
let message = if buffer.len() == 0 {
Expand Down Expand Up @@ -264,7 +270,11 @@ pub fn send_message(mut tasks: ResMut<ChunkResultTasks>, mut server: ResMut<Rene
if let Some((client_id, message)) =
futures_lite::future::block_on(futures_lite::future::poll_once(ele))
{
server.send_message(client_id, ServerChannel::ChunkResult, message);
if client_id == 0 {
server.broadcast_message(ServerChannel::ChunkResult, message);
} else {
server.send_message(client_id, ServerChannel::ChunkResult, message);
}
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/server/chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use bevy::prelude::{Last, Plugin, Res, ResMut, Update};
use crate::{
common::ServerClipSpheres,
voxel_world::{
biomes::OtherTreeTasksMap,
chunk::{
find_chunk_keys_by_shpere_to_full_height, generate_offset_resoure, NeighbourOffest,
},
Expand All @@ -21,6 +22,7 @@ pub fn server_chunk_generate_system(
server_clip_spheres: Res<ServerClipSpheres>,
mut db: ResMut<MapDataBase>,
mut db_save_tasks: ResMut<DbSaveTasks>,
mut other_tree_tasks_map: ResMut<OtherTreeTasksMap>,
) {
for (_client_id, clip_spheres) in server_clip_spheres.clip_spheres.iter() {
// 通过球体计算 chunkey
Expand All @@ -32,7 +34,11 @@ pub fn server_chunk_generate_system(
// chunk_map.gen_chunk_data(key);
if !chunk_map.map_data.contains_key(&key) {
// 这里可以判断一下是否是 已经加载的数据
let data = db.find_by_chunk_key(key, db_save_tasks.as_mut());
let data = db.find_by_chunk_key(
key,
db_save_tasks.as_mut(),
other_tree_tasks_map.as_mut(),
);
chunk_map.write_chunk(key, data);
}
},
Expand Down
6 changes: 5 additions & 1 deletion src/server/message_def/chunk_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ pub enum ChunkResult {
key: ChunkKey,
data: (BitVec, Tree<Voxel>),
},
ChunkSame((ChunkKey,Voxel)),
UpdateChunkData {
key: ChunkKey,
data: (BitVec, Tree<Voxel>),
},
ChunkSame((ChunkKey, Voxel)),
ChunkUpdateOne {
chunk_key: ChunkKey,
pos: [u32; 3],
Expand Down
3 changes: 3 additions & 0 deletions src/server/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use bevy_rapier3d::prelude::{

use crate::voxel_world::player_state::{PlayerOntimeState, PlayerState};

use super::cross_through_check::CossTroughCheck;

#[derive(Debug, Component)]
pub struct Player {
pub id: u64,
Expand Down Expand Up @@ -54,6 +56,7 @@ pub fn server_create_player(
Group::GROUP_3,
Group::GROUP_1 | Group::GROUP_3,
))
.insert(CossTroughCheck)
.id()
}

Expand Down
1 change: 0 additions & 1 deletion src/sky/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use bevy_renet::renet::{RenetClient, RenetServer};

use crate::server::message_def::{time_sync::TimeSync, ServerChannel};


#[derive(Component)]
pub struct Sun;

Expand Down
51 changes: 49 additions & 2 deletions src/voxel_world/biomes/basic_land.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
// 基础大陆

use bevy::prelude::Vec3;
use ndshape::ConstShape;
use rand::Rng;

use crate::voxel_world::voxel::{Grass, Soli, Sown, Stone, Voxel, VoxelMaterial};
use crate::{
tools::chunk_key_any_xyz_to_vec3,
voxel_world::{
chunk::ChunkKey,
voxel::{AppleLeaf, AppleWood, Grass, Soli, Sown, Stone, Voxel, VoxelMaterial},
},
};

use super::{BiomesGenerator, SampleShape, MOUNTAIN_LEVEL, SEE_LEVEL, SNOW_LEVEL};
use super::{
find_out_chunk_keys, BiomesGenerator, SampleShape, TreeGentor, MOUNTAIN_LEVEL, SEE_LEVEL,
SNOW_LEVEL,
};

// 基础大陆
// 1. 雪顶
Expand Down Expand Up @@ -46,4 +57,40 @@ impl BiomesGenerator for BasicLandBiomes {
}
}
}

fn make_tree_with_info(
&self,
chunk_key: crate::voxel_world::chunk::ChunkKey,
voxels: &mut Vec<Voxel>,
_chunk_index: u32,
_plane_index: u32,
height: f32,
xyz: [u32; 3],
) -> Option<(Vec<ChunkKey>, TreeGentor)> {
if height >= MOUNTAIN_LEVEL {
return None;
}
let mut rng = rand::thread_rng();
let root_pos = chunk_key_any_xyz_to_vec3(chunk_key, xyz);

// 判断 是否需要给其他的模块处理?
let h = rng.gen_range(1..5);
let r = rng.gen_range(2.0..4.6);

let leaf_center = root_pos + Vec3::new(0.0, h as f32 - 1.0, 0.0);
// 这里 可以判断的又5个方向
let mut tree_gentor = TreeGentor {
tree: AppleWood::into_voxel(),
leaf: AppleLeaf::into_voxel(),
trunk_params: (root_pos, h),
leafs_params: (leaf_center, r, 0.0),
};
tree_gentor.make_tree_for_chunk(voxels, chunk_key.clone());

let vec_list = find_out_chunk_keys(xyz, chunk_key.clone(), h, r.ceil() as u32);
if vec_list.len() > 0 {
return Some((vec_list, tree_gentor));
}
None
}
}
Loading
Loading