diff --git a/Difficult_Rocket/__init__.py b/Difficult_Rocket/__init__.py index 66ad73e..aedbcd7 100644 --- a/Difficult_Rocket/__init__.py +++ b/Difficult_Rocket/__init__.py @@ -25,7 +25,7 @@ from libs.MCDR.version import Version game_version = Version("0.7.0.0") # 游戏版本 build_version = Version("1.1.0.0") # 编译文件版本(与游戏本体无关) -DR_rust_version = Version("0.1.6.2") # DR 的 Rust 编写部分的版本 +DR_rust_version = Version("0.1.6.5") # DR 的 Rust 编写部分的版本 __version__ = game_version long_version: int = 11 diff --git a/Difficult_Rocket/client/render/sr1_ship.py b/Difficult_Rocket/client/render/sr1_ship.py index 7a70875..3a895f8 100644 --- a/Difficult_Rocket/client/render/sr1_ship.py +++ b/Difficult_Rocket/client/render/sr1_ship.py @@ -29,7 +29,7 @@ if TYPE_CHECKING: from Difficult_Rocket.client import ClientWindow if DR_option.use_DR_rust: - from libs.Difficult_Rocket_rs import better_update_parts, PartDatas + from libs.Difficult_Rocket_rs import better_update_parts, PartDatas, Camera_rs def get_sr1_part(part_xml: Element) -> Optional[SR1PartData]: @@ -116,6 +116,7 @@ class SR1ShipRender(BaseScreen): self.part_data: Dict[int, SR1PartData] = {} self.parts_sprite: Dict[int, Sprite] = {} if DR_option.use_DR_rust: + self.camera_rs = Camera_rs(main_window) self.rust_parts = None def load_xml(self, file_path: str) -> bool: @@ -136,9 +137,9 @@ class SR1ShipRender(BaseScreen): start_time = time.perf_counter_ns() self.part_data: Dict[int, SR1PartData] = {} self.parts_sprite: Dict[int, Sprite] = {} + self.scale = 1.0 self.dx = 0 self.dy = 0 - self.scale = 1.0 parts = self.xml_root.find('Parts') for part_xml in parts: if part_xml.tag != 'Part': @@ -153,8 +154,8 @@ class SR1ShipRender(BaseScreen): render_scale = DR_option.gui_scale # 这个是 DR 的缩放比例 可以调节的( # 主要是 Windows 下有一个缩放系数嘛,我待会试试这玩意能不能获取(估计得 ctypes # 在不缩放的情况下,XML的1个单位长度对应60个像素 - render_x = part.x * render_scale * self.scale * 60 + self.window_pointer.width / 2 + self.dx - render_y = part.y * render_scale * self.scale * 60 + self.window_pointer.height / 2 + self.dy + render_x = part.x * render_scale * self.scale * 60 + self.window_pointer.width / 2 + render_y = part.y * render_scale * self.scale * 60 + self.window_pointer.height / 2 # 你就这里改吧 cache_sprite = Sprite(img=self.textures.get_texture(part.textures), x=render_x, y=render_y, @@ -197,8 +198,8 @@ class SR1ShipRender(BaseScreen): self.rust_parts, DR_option.gui_scale, 60) for part_id in self.part_data: # x y scale - self.parts_sprite[part_id].x = self.part_data[part_id].x * DR_option.gui_scale * self.scale * 60 + self.window_pointer.width / 2 + self.dx - self.parts_sprite[part_id].y = self.part_data[part_id].y * DR_option.gui_scale * self.scale * 60 + self.window_pointer.height / 2 + self.dy + self.parts_sprite[part_id].x = self.part_data[part_id].x * DR_option.gui_scale * self.scale * 60 + self.window_pointer.width / 2 + self.parts_sprite[part_id].y = self.part_data[part_id].y * DR_option.gui_scale * self.scale * 60 + self.window_pointer.height / 2 self.parts_sprite[part_id].scale = self.scale * DR_option.gui_scale self.need_update_parts = False @@ -208,7 +209,11 @@ class SR1ShipRender(BaseScreen): if self.need_update_parts: self.update_parts() self.need_update_parts = False + if DR_option.use_DR_rust: + self.camera_rs.begin() self.part_batch.draw() + if DR_option.use_DR_rust: + self.camera_rs.end() self.debug_label.draw() if SR1ShipRender_Option.debug_d_pos: self.debug_line.draw() diff --git a/libs/Difficult_Rocket_rs/__init__.py b/libs/Difficult_Rocket_rs/__init__.py index 3e228f1..5797bd9 100644 --- a/libs/Difficult_Rocket_rs/__init__.py +++ b/libs/Difficult_Rocket_rs/__init__.py @@ -40,7 +40,7 @@ if TYPE_CHECKING: min_zoom: float = 1.0, max_zoom: float = 1.0): ... - def start(self) -> None: ... + def begin(self) -> None: ... def end(self) -> None: ... diff --git a/libs/Difficult_Rocket_rs/src/Cargo.lock b/libs/Difficult_Rocket_rs/src/Cargo.lock index aac33e8..88fddeb 100644 --- a/libs/Difficult_Rocket_rs/src/Cargo.lock +++ b/libs/Difficult_Rocket_rs/src/Cargo.lock @@ -22,7 +22,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "difficult_rocket_rs" -version = "0.1.4" +version = "0.1.6" dependencies = [ "pyo3", ] diff --git a/libs/Difficult_Rocket_rs/src/Cargo.toml b/libs/Difficult_Rocket_rs/src/Cargo.toml index 734b0ac..5330204 100644 --- a/libs/Difficult_Rocket_rs/src/Cargo.toml +++ b/libs/Difficult_Rocket_rs/src/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "difficult_rocket_rs" -version = "0.1.4" +version = "0.1.6" edition = "2021" license-file = '../../LICENSE' # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/libs/Difficult_Rocket_rs/src/src/lib.rs b/libs/Difficult_Rocket_rs/src/src/lib.rs index d92b36c..f445308 100644 --- a/libs/Difficult_Rocket_rs/src/src/lib.rs +++ b/libs/Difficult_Rocket_rs/src/src/lib.rs @@ -13,7 +13,7 @@ use pyo3::prelude::*; #[pyfunction] fn get_version_str() -> String { - return String::from("0.1.6.2"); + return String::from("0.1.6.5"); } #[pyfunction] diff --git a/libs/Difficult_Rocket_rs/src/src/render.rs b/libs/Difficult_Rocket_rs/src/src/render.rs index e7c5a38..0bfdb5d 100644 --- a/libs/Difficult_Rocket_rs/src/src/render.rs +++ b/libs/Difficult_Rocket_rs/src/src/render.rs @@ -29,7 +29,7 @@ pub mod camera { impl CameraRs { #[new] #[allow(unused_variables)] - #[pyo3(signature = (window, zoom=1.0, dx=1.0, dy=1.0,min_zoom=1.0, max_zoom=1.0))] + #[pyo3(signature = (window, zoom=1.0, dx=1.0, dy=1.0, min_zoom=1.0, max_zoom=1.0))] pub fn py_new(window: &PyAny, zoom: f64, dx: f64, dy: f64,min_zoom: f64, max_zoom: f64) -> PyResult { return Ok(CameraRs {dx, dy, zoom, min_zoom, max_zoom, window: window.into()}) @@ -41,6 +41,17 @@ pub mod camera { })?) } + #[getter] + pub fn get_position(&self) -> (f64, f64) { + return (self.dx, self.dy) + } + + #[setter] + pub fn set_position(&mut self, value: (f64, f64)) -> () { + self.dx = value.0; + self.dy = value.1; + } + #[getter] pub fn get_zoom(&self) -> PyResult { Ok(self.zoom) @@ -52,28 +63,32 @@ pub mod camera { Ok(()) } - #[allow(unused_variables)] pub fn begin(&self) -> PyResult<()> { Python::with_gil(|py| -> PyResult<()> { let view = self.window.getattr(py, intern!(py, "view"))?; - let args = (-self.dx * self.zoom, -self.dy * self.zoom, 0); + + let args = ((-self.dx * self.zoom, -self.dy * self.zoom, 0), ); let view_matrix = view.call_method1(py, intern!(py, "translate"), args)?; - let args = (self.zoom, self.zoom, 1); + + let args = ((self.zoom, self.zoom, 1), ); let view_matrix = view_matrix.call_method1(py, intern!(py, "scale"), args)?; + self.window.setattr(py, intern!(py, "view"), view_matrix)?; Ok(()) })?; return Ok(()) } - #[allow(unused_variables)] pub fn end(&self) -> PyResult<()> { Python::with_gil(|py| -> PyResult<()> { let view = self.window.getattr(py, intern!(py, "view"))?; - let args = (1.0 / self.zoom, 1.0 / self.zoom, 1); + + let args = ((1.0 / self.zoom, 1.0 / self.zoom, 1), ); let view_matrix = view.call_method1(py, intern!(py, "scale"), args)?; - let args = (self.dx * self.zoom, self.dy * self.zoom, 0); + + let args = ((self.dx * self.zoom, self.dy * self.zoom, 0), ); let view_matrix = view_matrix.call_method1(py, intern!(py, "translate"), args)?; + self.window.setattr(py, intern!(py, "view"), view_matrix)?; Ok(()) })?; diff --git a/libs/Difficult_Rocket_rs/src/src/sr1_render.rs b/libs/Difficult_Rocket_rs/src/src/sr1_render.rs index 3fdfc2e..f2602ac 100644 --- a/libs/Difficult_Rocket_rs/src/src/sr1_render.rs +++ b/libs/Difficult_Rocket_rs/src/src/sr1_render.rs @@ -116,19 +116,15 @@ pub mod types { #[pyfunction] #[allow(unused_variables)] pub fn better_update_parts(render: &PyAny, option: &PyAny, window: &PyAny, - parts: &types::PartDatas, - global_scale: f64, sr1_xml_scale: i32) -> PyResult { + parts: &types::PartDatas, sr1_xml_scale: i32) -> PyResult { if !render.getattr(intern!(render.py(), "rendered"))?.is_true()? { return Ok(false); } let start_time = time::Instant::now(); - let dx: f64 = render.getattr(intern!(render.py(), "dx"))?.extract()?; - let dy: f64 = render.getattr(intern!(render.py(), "dy"))?.extract()?; let x_center: f32 = window.getattr(intern!(window.py(), "width"))?.extract()?; let y_center: f32 = window.getattr(intern!(window.py(), "height"))?.extract()?; let x_center: f32 = x_center / 2.0; let y_center: f32 = y_center / 2.0; - let render_scale: f32 = render.getattr(intern!(render.py(), "scale"))?.extract()?; let datas: &HashMap = &parts.part_structs; let part_sprites = render.getattr(intern!(render.py(), "parts_sprite"))?; // let part_sprites: &PyDict = part_sprites.downcast::()?; @@ -138,12 +134,10 @@ pub fn better_update_parts(render: &PyAny, option: &PyAny, window: &PyAny, for keys in datas { // let index = keys.0.to_string(); let sprite = part_sprites.get_item(keys.0)?; - let new_x: f64 = keys.1.x * global_scale * render_scale as f64 * sr1_xml_scale as f64 + x_center as f64 + dx; - let new_y: f64 = keys.1.y * global_scale * render_scale as f64 * sr1_xml_scale as f64 + y_center as f64 + dy; - let new_scale: f32 = render_scale * global_scale as f32; + let new_x: f64 = keys.1.x * sr1_xml_scale as f64 + x_center as f64; + let new_y: f64 = keys.1.y * sr1_xml_scale as f64 + y_center as f64; sprite.setattr(intern!(sprite.py(), "x"), new_x)?; sprite.setattr(intern!(sprite.py(), "y"), new_y)?; - sprite.setattr(intern!(sprite.py(), "scale"), new_scale)?; // part_sprites.set_item(keys.0, sprite)?; // println!("{}", keys.0); }