perf: remove lazy_static
This commit is contained in:
+21
-19
@@ -4,33 +4,35 @@ edition = "2024"
|
||||
version.workspace = true
|
||||
|
||||
[dependencies]
|
||||
ansi_term.workspace = true
|
||||
anyhow.workspace = true
|
||||
atomic_refcell.workspace = true
|
||||
env_logger.workspace = true
|
||||
hex.workspace = true
|
||||
lazy_static.workspace = true
|
||||
paste.workspace = true
|
||||
rbase64.workspace = true
|
||||
notify.workspace = true
|
||||
notify-debouncer-mini.workspace = true
|
||||
# Framework
|
||||
tokio.workspace = true
|
||||
|
||||
# JSON
|
||||
serde.workspace = true
|
||||
serde_json.workspace = true
|
||||
|
||||
tokio.workspace = true
|
||||
tokio-util.workspace = true
|
||||
|
||||
# Logging
|
||||
tracing.workspace = true
|
||||
tracing-futures.workspace = true
|
||||
tracing-log.workspace = true
|
||||
tracing-subscriber.workspace = true
|
||||
tracing-bunyan-formatter.workspace = true
|
||||
ansi_term.workspace = true
|
||||
env_logger.workspace = true
|
||||
|
||||
# Encoding / Serialization
|
||||
prost.workspace = true
|
||||
proto.workspace = true
|
||||
proto-derive.workspace = true
|
||||
rbase64.workspace = true
|
||||
|
||||
# Cryptography
|
||||
rand.workspace = true
|
||||
|
||||
# Utilities
|
||||
paste.workspace = true
|
||||
notify.workspace = true
|
||||
notify-debouncer-mini.workspace = true
|
||||
|
||||
# Error handling
|
||||
anyhow.workspace = true
|
||||
|
||||
# Local
|
||||
mhy-kcp.workspace = true
|
||||
common.workspace = true
|
||||
proto.workspace = true
|
||||
proto-derive.workspace = true
|
||||
|
||||
@@ -4,9 +4,7 @@ use common::{
|
||||
resources::GAME_RES,
|
||||
sr_tools::{AvatarJson, Position},
|
||||
};
|
||||
use lazy_static::lazy_static;
|
||||
use scene_entity_info::Entity;
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
use crate::util::{self};
|
||||
|
||||
@@ -117,10 +115,6 @@ pub async fn on_get_scene_map_info_cs_req(
|
||||
}
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
static ref NEXT_SCENE_SAVE: Mutex<u64> = Mutex::new(0);
|
||||
}
|
||||
|
||||
pub async fn on_scene_entity_move_cs_req(
|
||||
session: &mut PlayerSession,
|
||||
req: &SceneEntityMoveCsReq,
|
||||
@@ -131,14 +125,12 @@ pub async fn on_scene_entity_move_cs_req(
|
||||
return;
|
||||
};
|
||||
|
||||
let mut timestamp = NEXT_SCENE_SAVE.lock().await;
|
||||
|
||||
if util::cur_timestamp_ms() <= *timestamp {
|
||||
if util::cur_timestamp_ms() <= session.next_scene_save {
|
||||
return;
|
||||
}
|
||||
|
||||
// save every 5 sec
|
||||
*timestamp = util::cur_timestamp_ms() + (5 * 1000);
|
||||
session.next_scene_save = util::cur_timestamp_ms() + (5 * 1000);
|
||||
|
||||
for entity in &req.entity_motion_list {
|
||||
if entity.entity_id != 0 {
|
||||
|
||||
@@ -14,12 +14,12 @@ use proto::{AvatarSync, CmdID, CmdPlayerType, PlayerSyncScNotify};
|
||||
use tokio::{
|
||||
io::AsyncWrite,
|
||||
net::UdpSocket,
|
||||
sync::{Mutex, watch},
|
||||
sync::{watch, Mutex},
|
||||
};
|
||||
|
||||
use crate::util;
|
||||
|
||||
use super::{NetPacket, packet::CommandHandler};
|
||||
use super::{packet::CommandHandler, NetPacket};
|
||||
|
||||
struct RemoteEndPoint {
|
||||
socket: Arc<UdpSocket>,
|
||||
@@ -33,6 +33,7 @@ pub struct PlayerSession {
|
||||
pub shutdown_tx: watch::Sender<()>,
|
||||
pub shutdown_rx: watch::Receiver<()>,
|
||||
pub json_data: OnceLock<FreesrData>,
|
||||
pub next_scene_save: u64,
|
||||
}
|
||||
|
||||
impl PlayerSession {
|
||||
@@ -40,14 +41,17 @@ impl PlayerSession {
|
||||
let (shutdown_tx, shutdown_rx) = watch::channel(());
|
||||
Self {
|
||||
token,
|
||||
kcp: Arc::new(Mutex::new(Kcp::new(conv, token, false, RemoteEndPoint {
|
||||
socket,
|
||||
addr,
|
||||
}))),
|
||||
kcp: Arc::new(Mutex::new(Kcp::new(
|
||||
conv,
|
||||
token,
|
||||
false,
|
||||
RemoteEndPoint { socket, addr },
|
||||
))),
|
||||
start_time: util::cur_timestamp_secs(),
|
||||
json_data: OnceLock::new(),
|
||||
shutdown_rx,
|
||||
shutdown_tx,
|
||||
next_scene_save: 0,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user