mirror of
https://git.neonteam.dev/amizing/robinsr.git
synced 2025-03-12 03:28:30 -04:00
perf: remove lazy_static
This commit is contained in:
parent
7d233dc614
commit
6d9bf58a85
45
Cargo.toml
45
Cargo.toml
@ -6,19 +6,22 @@ resolver = "3"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
anyhow = "1.0.81"
|
# Framework
|
||||||
ansi_term = "0.12.1"
|
tokio = { version = "1.36.0", features = ["full"] }
|
||||||
atomic_refcell = "0.1.13"
|
|
||||||
lazy_static = "1.4.0"
|
|
||||||
|
|
||||||
axum = "0.8.1"
|
axum = "0.8.1"
|
||||||
axum-server = "0.7.1"
|
axum-server = "0.7.1"
|
||||||
tower-http = "0.6.2"
|
tower-http = "0.6.2"
|
||||||
|
|
||||||
|
# JSON
|
||||||
|
serde = { version = "1.0.197", features = ["derive"] }
|
||||||
|
serde_json = "1.0.114"
|
||||||
|
|
||||||
|
# Logging
|
||||||
|
tracing = "0.1.40"
|
||||||
|
ansi_term = "0.12.1"
|
||||||
env_logger = "0.11.3"
|
env_logger = "0.11.3"
|
||||||
|
|
||||||
rbase64 = "2.0.3"
|
# Cryptography
|
||||||
rand = "0.9.0"
|
|
||||||
rsa = { version = "0.9.6", features = [
|
rsa = { version = "0.9.6", features = [
|
||||||
"sha1",
|
"sha1",
|
||||||
"nightly",
|
"nightly",
|
||||||
@ -26,42 +29,26 @@ rsa = { version = "0.9.6", features = [
|
|||||||
"serde",
|
"serde",
|
||||||
"sha2",
|
"sha2",
|
||||||
] }
|
] }
|
||||||
|
rand = "0.9.0"
|
||||||
|
|
||||||
|
# Serialization
|
||||||
prost = "0.13.5"
|
prost = "0.13.5"
|
||||||
prost-types = "0.13.5"
|
prost-types = "0.13.5"
|
||||||
prost-build = "0.13.5"
|
prost-build = "0.13.5"
|
||||||
|
rbase64 = "2.0.3"
|
||||||
|
|
||||||
|
# Utilities
|
||||||
paste = "1.0.14"
|
paste = "1.0.14"
|
||||||
sysinfo = "0.33.1"
|
|
||||||
notify = "8.0.0"
|
notify = "8.0.0"
|
||||||
notify-debouncer-mini = "0.6.0"
|
notify-debouncer-mini = "0.6.0"
|
||||||
|
anyhow = "1.0.81"
|
||||||
|
|
||||||
hex = "0.4.3"
|
# Local
|
||||||
|
|
||||||
serde = { version = "1.0.197", features = ["derive"] }
|
|
||||||
serde_json = "1.0.114"
|
|
||||||
|
|
||||||
tokio = { version = "1.36.0", features = ["full"] }
|
|
||||||
tokio-util = { version = "0.7.10", features = ["io"] }
|
|
||||||
|
|
||||||
tracing = "0.1.40"
|
|
||||||
tracing-futures = "0.2.5"
|
|
||||||
tracing-log = { version = "0.2.0", features = ["std", "log-tracer"] }
|
|
||||||
tracing-subscriber = { version = "0.3.18", features = [
|
|
||||||
"env-filter",
|
|
||||||
"registry",
|
|
||||||
"std",
|
|
||||||
"tracing",
|
|
||||||
"tracing-log",
|
|
||||||
] }
|
|
||||||
tracing-bunyan-formatter = "0.3.9"
|
|
||||||
|
|
||||||
proto = { path = "proto/" }
|
proto = { path = "proto/" }
|
||||||
proto-derive = { path = "proto/proto-derive" }
|
proto-derive = { path = "proto/proto-derive" }
|
||||||
mhy-kcp = { path = "kcp/", features = ["tokio"] }
|
mhy-kcp = { path = "kcp/", features = ["tokio"] }
|
||||||
common = { path = "common/" }
|
common = { path = "common/" }
|
||||||
|
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
strip = true # Automatically strip symbols from the binary.
|
strip = true # Automatically strip symbols from the binary.
|
||||||
opt-level = "z" # Optimize for size.
|
opt-level = "z" # Optimize for size.
|
||||||
|
|||||||
@ -4,33 +4,35 @@ edition = "2024"
|
|||||||
version.workspace = true
|
version.workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
ansi_term.workspace = true
|
# Framework
|
||||||
anyhow.workspace = true
|
tokio.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
|
|
||||||
|
|
||||||
|
# JSON
|
||||||
serde.workspace = true
|
serde.workspace = true
|
||||||
serde_json.workspace = true
|
serde_json.workspace = true
|
||||||
|
|
||||||
tokio.workspace = true
|
# Logging
|
||||||
tokio-util.workspace = true
|
|
||||||
|
|
||||||
tracing.workspace = true
|
tracing.workspace = true
|
||||||
tracing-futures.workspace = true
|
ansi_term.workspace = true
|
||||||
tracing-log.workspace = true
|
env_logger.workspace = true
|
||||||
tracing-subscriber.workspace = true
|
|
||||||
tracing-bunyan-formatter.workspace = true
|
|
||||||
|
|
||||||
|
# Encoding / Serialization
|
||||||
prost.workspace = true
|
prost.workspace = true
|
||||||
proto.workspace = true
|
rbase64.workspace = true
|
||||||
proto-derive.workspace = true
|
|
||||||
|
|
||||||
|
# Cryptography
|
||||||
rand.workspace = true
|
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
|
mhy-kcp.workspace = true
|
||||||
common.workspace = true
|
common.workspace = true
|
||||||
|
proto.workspace = true
|
||||||
|
proto-derive.workspace = true
|
||||||
|
|||||||
@ -4,9 +4,7 @@ use common::{
|
|||||||
resources::GAME_RES,
|
resources::GAME_RES,
|
||||||
sr_tools::{AvatarJson, Position},
|
sr_tools::{AvatarJson, Position},
|
||||||
};
|
};
|
||||||
use lazy_static::lazy_static;
|
|
||||||
use scene_entity_info::Entity;
|
use scene_entity_info::Entity;
|
||||||
use tokio::sync::Mutex;
|
|
||||||
|
|
||||||
use crate::util::{self};
|
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(
|
pub async fn on_scene_entity_move_cs_req(
|
||||||
session: &mut PlayerSession,
|
session: &mut PlayerSession,
|
||||||
req: &SceneEntityMoveCsReq,
|
req: &SceneEntityMoveCsReq,
|
||||||
@ -131,14 +125,12 @@ pub async fn on_scene_entity_move_cs_req(
|
|||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut timestamp = NEXT_SCENE_SAVE.lock().await;
|
if util::cur_timestamp_ms() <= session.next_scene_save {
|
||||||
|
|
||||||
if util::cur_timestamp_ms() <= *timestamp {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// save every 5 sec
|
// 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 {
|
for entity in &req.entity_motion_list {
|
||||||
if entity.entity_id != 0 {
|
if entity.entity_id != 0 {
|
||||||
|
|||||||
@ -14,12 +14,12 @@ use proto::{AvatarSync, CmdID, CmdPlayerType, PlayerSyncScNotify};
|
|||||||
use tokio::{
|
use tokio::{
|
||||||
io::AsyncWrite,
|
io::AsyncWrite,
|
||||||
net::UdpSocket,
|
net::UdpSocket,
|
||||||
sync::{Mutex, watch},
|
sync::{watch, Mutex},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::util;
|
use crate::util;
|
||||||
|
|
||||||
use super::{NetPacket, packet::CommandHandler};
|
use super::{packet::CommandHandler, NetPacket};
|
||||||
|
|
||||||
struct RemoteEndPoint {
|
struct RemoteEndPoint {
|
||||||
socket: Arc<UdpSocket>,
|
socket: Arc<UdpSocket>,
|
||||||
@ -33,6 +33,7 @@ pub struct PlayerSession {
|
|||||||
pub shutdown_tx: watch::Sender<()>,
|
pub shutdown_tx: watch::Sender<()>,
|
||||||
pub shutdown_rx: watch::Receiver<()>,
|
pub shutdown_rx: watch::Receiver<()>,
|
||||||
pub json_data: OnceLock<FreesrData>,
|
pub json_data: OnceLock<FreesrData>,
|
||||||
|
pub next_scene_save: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PlayerSession {
|
impl PlayerSession {
|
||||||
@ -40,14 +41,17 @@ impl PlayerSession {
|
|||||||
let (shutdown_tx, shutdown_rx) = watch::channel(());
|
let (shutdown_tx, shutdown_rx) = watch::channel(());
|
||||||
Self {
|
Self {
|
||||||
token,
|
token,
|
||||||
kcp: Arc::new(Mutex::new(Kcp::new(conv, token, false, RemoteEndPoint {
|
kcp: Arc::new(Mutex::new(Kcp::new(
|
||||||
socket,
|
conv,
|
||||||
addr,
|
token,
|
||||||
}))),
|
false,
|
||||||
|
RemoteEndPoint { socket, addr },
|
||||||
|
))),
|
||||||
start_time: util::cur_timestamp_secs(),
|
start_time: util::cur_timestamp_secs(),
|
||||||
json_data: OnceLock::new(),
|
json_data: OnceLock::new(),
|
||||||
shutdown_rx,
|
shutdown_rx,
|
||||||
shutdown_tx,
|
shutdown_tx,
|
||||||
|
next_scene_save: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -4,29 +4,28 @@ version = "0.1.0"
|
|||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow.workspace = true
|
# Framework
|
||||||
env_logger.workspace = true
|
tokio.workspace = true
|
||||||
|
|
||||||
tower-http = { workspace = true, features = ["cors"] }
|
tower-http = { workspace = true, features = ["cors"] }
|
||||||
axum.workspace = true
|
axum.workspace = true
|
||||||
axum-server.workspace = true
|
axum-server.workspace = true
|
||||||
|
|
||||||
lazy_static.workspace = true
|
# JSON
|
||||||
|
|
||||||
serde.workspace = true
|
serde.workspace = true
|
||||||
serde_json.workspace = true
|
serde_json.workspace = true
|
||||||
|
|
||||||
tokio.workspace = true
|
# Logging
|
||||||
tokio-util.workspace = true
|
|
||||||
|
|
||||||
tracing.workspace = true
|
tracing.workspace = true
|
||||||
tracing-futures.workspace = true
|
|
||||||
tracing-log.workspace = true
|
|
||||||
tracing-subscriber.workspace = true
|
|
||||||
tracing-bunyan-formatter.workspace = true
|
|
||||||
ansi_term.workspace = true
|
ansi_term.workspace = true
|
||||||
|
env_logger.workspace = true
|
||||||
|
|
||||||
|
# Encoding / Serialization
|
||||||
prost.workspace = true
|
prost.workspace = true
|
||||||
rbase64.workspace = true
|
rbase64.workspace = true
|
||||||
proto.workspace = true
|
|
||||||
|
# Error handling
|
||||||
|
anyhow.workspace = true
|
||||||
|
|
||||||
|
# Local
|
||||||
common.workspace = true
|
common.workspace = true
|
||||||
|
proto.workspace = true
|
||||||
|
|||||||
@ -1,3 +1 @@
|
|||||||
mod version_config;
|
pub mod version_config;
|
||||||
|
|
||||||
pub use version_config::INSTANCE as versions;
|
|
||||||
|
|||||||
@ -1,10 +1,8 @@
|
|||||||
use std::collections::HashMap;
|
use std::{collections::HashMap, sync::OnceLock};
|
||||||
|
|
||||||
use lazy_static::lazy_static;
|
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serde_json::from_str;
|
|
||||||
|
|
||||||
const DEFAULT_VERSIONS: &str = include_str!("../../versions.json");
|
const DEFAULT_VERSIONS: &str = include_str!("../../../versions.json");
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct VersionConfig {
|
pub struct VersionConfig {
|
||||||
@ -14,16 +12,16 @@ pub struct VersionConfig {
|
|||||||
// pub lua_version: String,
|
// pub lua_version: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
lazy_static! {
|
pub fn instance() -> &'static HashMap<String, VersionConfig> {
|
||||||
pub static ref INSTANCE: HashMap<String, VersionConfig> = {
|
static INSTANCE: OnceLock<HashMap<String, VersionConfig>> = OnceLock::new();
|
||||||
let local_config = std::path::Path::new("versions.json");
|
INSTANCE.get_or_init(|| {
|
||||||
let data = if local_config.exists() {
|
const CONFIG_PATH: &str = "versions.json";
|
||||||
std::fs::read_to_string("versions.json").unwrap()
|
|
||||||
} else {
|
|
||||||
std::fs::write("versions.json", DEFAULT_VERSIONS).unwrap();
|
|
||||||
DEFAULT_VERSIONS.to_string()
|
|
||||||
};
|
|
||||||
|
|
||||||
from_str(&data).unwrap()
|
let data = std::fs::read_to_string(CONFIG_PATH).unwrap_or_else(|_| {
|
||||||
};
|
std::fs::write(CONFIG_PATH, DEFAULT_VERSIONS).expect("Failed to create versions file");
|
||||||
|
DEFAULT_VERSIONS.to_string()
|
||||||
|
});
|
||||||
|
|
||||||
|
serde_json::from_str(&data).unwrap_or_else(|e| panic!("Failed to parse versions.json: {e}"))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
use crate::config::versions;
|
use crate::config::version_config;
|
||||||
use axum::extract::Query;
|
use axum::extract::Query;
|
||||||
use prost::Message;
|
use prost::Message;
|
||||||
use proto::{DispatchRegionData, Gateserver, RegionEntry};
|
use proto::{DispatchRegionData, Gateserver, RegionEntry};
|
||||||
@ -34,7 +34,7 @@ pub struct QueryGatewayParameters {
|
|||||||
|
|
||||||
#[tracing::instrument]
|
#[tracing::instrument]
|
||||||
pub async fn query_gateway(parameters: Query<QueryGatewayParameters>) -> String {
|
pub async fn query_gateway(parameters: Query<QueryGatewayParameters>) -> String {
|
||||||
let rsp = if let Some(config) = versions.get(¶meters.version) {
|
let rsp = if let Some(config) = version_config::instance().get(¶meters.version) {
|
||||||
Gateserver {
|
Gateserver {
|
||||||
retcode: 0,
|
retcode: 0,
|
||||||
ip: String::from("127.0.0.1"),
|
ip: String::from("127.0.0.1"),
|
||||||
|
|||||||
@ -1,8 +0,0 @@
|
|||||||
{
|
|
||||||
"OSBETAWin3.1.51": {
|
|
||||||
"asset_bundle_url": "https://autopatchos.starrails.com/asb/BetaLive/output_9573347_b03981f01966",
|
|
||||||
"ex_resource_url": "https://autopatchos.starrails.com/design_data/BetaLive/output_9589567_9c50629b0369",
|
|
||||||
"lua_url": "https://autopatchos.starrails.com/lua/BetaLive/output_9567078_0e2b6acf6a2f",
|
|
||||||
"ifix_url": "https://autopatchos.starrails.com/ifix/BetaLive/output_0_40d2ce0253"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user