From 2463d84c67b7cb6f5707edda01926d5aa0dee50d Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Wed, 5 Apr 2023 10:34:58 +0800 Subject: [PATCH] DR_rs 0.2.5.7 --- Difficult_Rocket/__init__.py | 2 +- Difficult_Rocket/client/render/sr1_ship.py | 9 ++++-- configs/lang/en-us.toml | 11 +++++++ configs/lang/zh-CN.toml | 10 ++++++ libs/Difficult_Rocket_rs/src/src/lib.rs | 8 +++-- libs/Difficult_Rocket_rs/src/src/logger.rs | 1 - libs/Difficult_Rocket_rs/src/src/python.rs | 34 ++++++++++++++++++++ libs/Difficult_Rocket_rs/src/src/sr1_data.rs | 27 ++++++---------- libs/Difficult_Rocket_rs/src/src/types.rs | 11 ++++--- 9 files changed, 84 insertions(+), 29 deletions(-) create mode 100644 libs/Difficult_Rocket_rs/src/src/python.rs diff --git a/Difficult_Rocket/__init__.py b/Difficult_Rocket/__init__.py index 9369a18..43f4689 100644 --- a/Difficult_Rocket/__init__.py +++ b/Difficult_Rocket/__init__.py @@ -24,7 +24,7 @@ from libs.MCDR.version import Version game_version = Version("0.7.1.4") # 游戏版本 build_version = Version("1.2.1.0") # 编译文件版本(与游戏本体无关) -DR_rust_version = Version("0.2.5.6") # DR 的 Rust 编写部分的版本 +DR_rust_version = Version("0.2.5.7") # DR 的 Rust 编写部分的版本 Api_version = Version("0.0.1.0") # API 版本 __version__ = game_version diff --git a/Difficult_Rocket/client/render/sr1_ship.py b/Difficult_Rocket/client/render/sr1_ship.py index 22a3828..bc377f4 100644 --- a/Difficult_Rocket/client/render/sr1_ship.py +++ b/Difficult_Rocket/client/render/sr1_ship.py @@ -33,7 +33,7 @@ if TYPE_CHECKING: from Difficult_Rocket.client import ClientWindow if DR_option.use_DR_rust: - from libs.Difficult_Rocket_rs import CenterCamera_rs, SR1PartData + from libs.Difficult_Rocket_rs import CenterCamera_rs, SR1PartList_rs logger = logging.getLogger('client') @@ -84,6 +84,7 @@ class SR1ShipRender(BaseScreen): def __init__(self, main_window: "ClientWindow"): super().__init__(main_window) + load_start_time = time.time_ns() self.rendered = False self.focus = True self.need_draw = False @@ -121,11 +122,15 @@ class SR1ShipRender(BaseScreen): anchor_x='left', anchor_y='top') self.part_data: Dict[int, SR1PartData] = {} self.parts_sprite: Dict[int, Sprite] = {} + load_end_time = time.time_ns() + logger.info(tr().client.sr1_render.setup.done()) + logger.info(tr().client.sr1_render.setup.use_time().format( + (load_end_time - load_start_time) / 1000000000)) if DR_option.use_DR_rust: self.camera_rs = CenterCamera_rs(main_window, min_zoom=(1 / 2) ** 10, max_zoom=10) self.rust_parts = None - self.part_list_rs = + # self.part_list_rs = def load_xml(self, file_path: str) -> bool: try: diff --git a/configs/lang/en-us.toml b/configs/lang/en-us.toml index a889992..722622b 100644 --- a/configs/lang/en-us.toml +++ b/configs/lang/en-us.toml @@ -55,3 +55,14 @@ os.pid_is = "Server PID: {} PPID: {}" input = "console" command = "in game commands" window = "window" + +[client.sr1_render] +setup.done = "SR1 Renderer loaded" +setup.use_time = "SR1 Renderer loading has used: {} second" +xml.loading = "Loading XML file: {}" +xml.load_done = "XML file loaded" +xml.load_time = "XML file loading has used: {} second" +ship.load = "Loading ship: {}" +ship.load_time = "Ship loading has used: {} second" +ship.info = "Ship info:\n- Parts: {}\n- Weight: {}\n- File size: {}" + diff --git a/configs/lang/zh-CN.toml b/configs/lang/zh-CN.toml index 91cf91f..e970f35 100644 --- a/configs/lang/zh-CN.toml +++ b/configs/lang/zh-CN.toml @@ -55,3 +55,13 @@ os.pid_is = "服务端 PID: {} PPID: {}" input = "控制台" command = "游戏内命令行" window = "窗口" + +[client.sr1_render] +setup.done = "SR1 渲染器载入完成" +setup.use_time = "SR1 渲染器载入消耗时间: {} 秒" +xml.loading = "正在加载XML文件: {}" +xml.load_done = "XML 文件加载完成" +xml.load_time = "XML 文件加载消耗时间: {} 秒" +ship.load = "正在加载飞船: {}" +ship.load_time = "飞船加载消耗时间: {} 秒" +ship.info = "飞船信息:\n- 部件数量: {}\n- 部件重量: {}\n- 文件大小: {}" diff --git a/libs/Difficult_Rocket_rs/src/src/lib.rs b/libs/Difficult_Rocket_rs/src/src/lib.rs index 66c31c8..456b447 100644 --- a/libs/Difficult_Rocket_rs/src/src/lib.rs +++ b/libs/Difficult_Rocket_rs/src/src/lib.rs @@ -6,17 +6,18 @@ * ------------------------------- */ +mod logger; +mod python; +mod render; mod simulator; mod sr1_data; -mod render; -mod logger; mod types; use pyo3::prelude::*; #[pyfunction] fn get_version_str() -> String { - return "0.2.5.6".to_string(); + return "0.2.5.7".to_string(); } #[pyfunction] @@ -38,5 +39,6 @@ fn module_init(_py: Python<'_>, m: &PyModule) -> PyResult<()> { m.add_class::()?; m.add_class::()?; m.add_class::()?; + m.add_class::()?; Ok(()) } diff --git a/libs/Difficult_Rocket_rs/src/src/logger.rs b/libs/Difficult_Rocket_rs/src/src/logger.rs index f8cf460..72f16f6 100644 --- a/libs/Difficult_Rocket_rs/src/src/logger.rs +++ b/libs/Difficult_Rocket_rs/src/src/logger.rs @@ -5,4 +5,3 @@ * All rights reserved * ------------------------------- */ - diff --git a/libs/Difficult_Rocket_rs/src/src/python.rs b/libs/Difficult_Rocket_rs/src/src/python.rs new file mode 100644 index 0000000..1a112bb --- /dev/null +++ b/libs/Difficult_Rocket_rs/src/src/python.rs @@ -0,0 +1,34 @@ +/* + * ------------------------------- + * Difficult Rocket + * Copyright © 2020-2023 by shenjackyuanjie 3695888@qq.com + * All rights reserved + * ------------------------------- + */ + +pub mod data { + use pyo3::prelude::*; + use serde_xml_rs::from_str; + + use crate::sr1_data::part_list::RawPartList; + use crate::sr1_data::ship::RawShip; + use crate::types::sr1::{SR1PartList, SR1PartListTrait, SR1Ship}; + + #[pyclass] + #[pyo3(name = "SR1PartList_rs")] + #[pyo3(text_signature = "(file_path = './configs/PartList.xml', list_name = 'NewPartList')")] + pub struct PySR1PartList { + pub part_list: SR1PartList, + } + + #[pymethods] + impl PySR1PartList { + #[new] + fn new(file_path: String, list_name: String) -> Self { + let raw_part_list: RawPartList = RawPartList::from_file(file_path).unwrap(); + Self { + part_list: raw_part_list.to_sr_part_list(Some(list_name.to_string())), + } + } + } +} diff --git a/libs/Difficult_Rocket_rs/src/src/sr1_data.rs b/libs/Difficult_Rocket_rs/src/src/sr1_data.rs index 8fab20f..a45727d 100644 --- a/libs/Difficult_Rocket_rs/src/src/sr1_data.rs +++ b/libs/Difficult_Rocket_rs/src/src/sr1_data.rs @@ -326,10 +326,19 @@ pub mod part_list { } impl RawPartList { + #[inline] pub fn new(parts: Vec) -> Self { RawPartList { part_types: parts } } + #[inline] + pub fn from_file(file_name: String) -> Option { + let part_list_file = fs::read_to_string(file_name).unwrap(); + let part_list: RawPartList = from_str(part_list_file.as_str()).unwrap(); + Some(part_list) + } + + #[inline] pub fn list_print(&self) -> () { for part_data in self.part_types.iter() { println!("{:?}\n", part_data); @@ -351,27 +360,11 @@ pub mod part_list { } } - #[inline] - pub fn read_part_list(file_name: String) -> Option { - let part_list_file = fs::read_to_string(file_name.to_string()); - - match part_list_file { - Ok(part_list_file) => { - let part_list: RawPartList = from_str(part_list_file.as_str()).unwrap(); - Some(part_list) - } - Err(_) => { - println!("Error while reading File {}", file_name); - None - } - } - } - #[pyfunction] #[pyo3(name = "part_list_read_test", signature = (file_name = "./configs/PartList.xml".to_string()))] pub fn read_part_list_py(_py: Python, file_name: Option) -> PyResult<()> { let file_name = file_name.unwrap_or("./configs/PartList.xml".to_string()); - let _parts = read_part_list(file_name); + let _parts = RawPartList::from_file(file_name); if let Some(parts) = _parts { // println!("{:?}", parts) parts.list_print(); diff --git a/libs/Difficult_Rocket_rs/src/src/types.rs b/libs/Difficult_Rocket_rs/src/src/types.rs index a98aeba..1547901 100644 --- a/libs/Difficult_Rocket_rs/src/src/types.rs +++ b/libs/Difficult_Rocket_rs/src/src/types.rs @@ -7,6 +7,7 @@ */ pub mod sr1 { + use std::collections::HashMap; // use super::math::{Shape, Point2D}; use crate::sr1_data::part_list::Damage as RawDamage; use crate::sr1_data::part_list::{ @@ -210,12 +211,12 @@ pub mod sr1 { } impl SR1PartList { - pub fn to_raw_part_list(&self) -> RawPartList { - let mut types: Vec = Vec::new(); - for part_type in &self.types { - types.insert(0, part_type.to_raw_part_type()); + pub fn get_hash_map(&self) -> HashMap { + let mut map = HashMap::new(); + for part in self.types.iter() { + map.insert(part.id.clone(), part.clone()); } - RawPartList { part_types: types } + map } }