Skip to content

Commit

Permalink
refac: clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreamtowards committed Jan 25, 2024
1 parent 3ebdfc8 commit d1d3fed
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 43 deletions.
File renamed without changes.
4 changes: 1 addition & 3 deletions src/bin/dedicated_server.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@

use std::time::Duration;

use bevy::{prelude::*, log::LogPlugin, app::ScheduleRunnerPlugin};
use bevy::{prelude::*, log::LogPlugin};

use ethertia::net::NetworkServerPlugin;

Expand Down
2 changes: 1 addition & 1 deletion src/editor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use bevy::{
};

use bevy_egui::{
egui::{self, style::HandleShape, FontData, FontDefinitions, FontFamily, Rounding},
egui::{style::HandleShape, FontData, FontDefinitions, FontFamily, Rounding},
EguiContexts, EguiPlugin, EguiSettings,
};

Expand Down
25 changes: 11 additions & 14 deletions src/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ fn tick_world(
fn gizmo_sys(
mut gizmo: Gizmos,
mut gizmo_config: ResMut<GizmoConfig>,
mut query_cam: Query<&Transform, With<CharacterControllerCamera>>,
query_cam: Query<&Transform, With<CharacterControllerCamera>>,
) {
gizmo_config.depth_bias = -1.; // always in front

Expand Down Expand Up @@ -273,20 +273,17 @@ fn handle_inputs(

// Toggle MouseGrab
for event in editor_events.read() {
match *event {
EditorEvent::Toggle { now_active } => {
let playing = !now_active;
window.cursor.grab_mode = if playing {
CursorGrabMode::Locked
} else {
CursorGrabMode::None
};
window.cursor.visible = !playing;
for mut controller in &mut controller_query {
controller.enable_input = playing;
}
if let EditorEvent::Toggle { now_active } = *event {
let playing = !now_active;
window.cursor.grab_mode = if playing {
CursorGrabMode::Locked
} else {
CursorGrabMode::None
};
window.cursor.visible = !playing;
for mut controller in &mut controller_query {
controller.enable_input = playing;
}
_ => (),
}
}

Expand Down
13 changes: 4 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@

use bevy::{prelude::*, window::WindowResolution};

mod game;
mod util;
mod voxel;
mod net;

mod character_controller;
mod editor;
use ethertia::editor::EditorPlugin;
use ethertia::game::GamePlugin;


fn main() {
Expand All @@ -26,7 +21,7 @@ fn main() {
..default()
})
)
.add_plugins(editor::EditorPlugin)
.add_plugins(game::GamePlugin)
.add_plugins(EditorPlugin)
.add_plugins(GamePlugin)
.run();
}
5 changes: 3 additions & 2 deletions src/net/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

use std::{net::{UdpSocket, SocketAddr}, time::SystemTime};

use bevy::{prelude::*, transform::commands};
use bevy::{prelude::*};
use bevy_egui::{EguiContexts, egui};
use bevy_renet::{
RenetServerPlugin,
Expand Down Expand Up @@ -73,6 +73,7 @@ fn ui_net(
if ui.button("Connect Server").clicked() {
let addr = (server_addr).parse().unwrap();
commands.insert_resource(new_netcode_client_transport(addr));
// commands.insert_resource(RenetClient::new(ConnectionConfig::default()));
}

if ui.button("Send Pack").clicked() {
Expand Down Expand Up @@ -108,7 +109,7 @@ fn new_netcode_client_transport(server_addr: SocketAddr) -> NetcodeClientTranspo
let client_id = current_time.as_millis() as u64;
let authentication = ClientAuthentication::Unsecure {
protocol_id: PROTOCOL_ID,
client_id: client_id,
client_id,
server_addr: server_addr,
user_data: None
};
Expand Down
2 changes: 1 addition & 1 deletion src/util/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub mod registry;
// pub mod registry;



Expand Down
13 changes: 4 additions & 9 deletions src/voxel/chunk_system.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
use std::sync::{Arc, RwLock};
use bevy::{
prelude::*,
tasks::Task,
utils::{HashMap, HashSet},
};
use bevy_xpbd_3d::components::Collider;

use super::{chunk::{*, self}, TerrainMaterial};
use super::{chunk::*, TerrainMaterial};



use std::sync::{Arc, RwLock};

// pub enum ChunkMeshingState {
// Pending,
// Meshing,//(Task<Mesh>),
// Completed,
// }

// Box<Chunk>; not supported for SharedPtr
// Arc<RwLock<Chunk>>; non convinent for readonly ops
Expand All @@ -23,8 +20,6 @@ pub type ChunkPtr = Arc<RwLock<Chunk>>;
#[reflect(Resource)]
pub struct ChunkSystem {
/// all loaded chunks.
/// ChunkList can be read (by multiple threads) at the same time, but only one can be writing at the same time and no other can be reading at this time.
// 设计一个高性能区块系统,这两个区块列表 及每个区块 都有RwLock特性,即 可同时可被多处读,但只能被互斥写
// linear-list of loaded chunks.
// chunks: Arc<RwLock<HashMap<IVec3, Arc<RwLock<Chunk>>>>>,
#[reflect(ignore)]
Expand Down
3 changes: 1 addition & 2 deletions src/voxel/material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,5 @@ pub mod mtl {
pub const SAND: u16 = 18;
}

use crate::util::registry::*;

// use crate::util::registry::*;
// static REGISTRY: Registry<Material> = Registry::default();
2 changes: 1 addition & 1 deletion src/voxel/meshgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ impl MeshGen {
if !c1.value.is_finite() {
continue;
}
if !Self::sn_signchanged(&c0, &c1) {
if !Self::sn_signchanged(c0, &c1) {
continue;
}

Expand Down
1 change: 0 additions & 1 deletion src/voxel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,6 @@ pub struct HitResult {
}

fn raycast(
commands: Commands,
spatial_query: SpatialQuery,

query_cam: Query<&GlobalTransform, With<CharacterControllerCamera>>,
Expand Down

0 comments on commit d1d3fed

Please sign in to comment.