From 77a42199f02d7ba26b7af530b036ce6b379717eb Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Wed, 1 Feb 2023 08:04:40 +0800 Subject: [PATCH] DR_rs 0.1.6.2 --- Difficult_Rocket/__init__.py | 2 +- docs/src/update_logs.md | 2 ++ libs/Difficult_Rocket_rs/src/src/lib.rs | 2 +- libs/Difficult_Rocket_rs/src/src/render.rs | 24 ++++++++++++++++------ 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/Difficult_Rocket/__init__.py b/Difficult_Rocket/__init__.py index 8ff4a7a..66ad73e 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.0") # DR 的 Rust 编写部分的版本 +DR_rust_version = Version("0.1.6.2") # DR 的 Rust 编写部分的版本 __version__ = game_version long_version: int = 11 diff --git a/docs/src/update_logs.md b/docs/src/update_logs.md index f2a748a..c036eb2 100644 --- a/docs/src/update_logs.md +++ b/docs/src/update_logs.md @@ -21,6 +21,8 @@ ### 啊哈! 现在真就是 0.7 了 +毕竟加了一整个 `DR_rs` + ### Add - `libs.Difficult_Rocket_rs` (`DR_rs`) `0.1.0.0` diff --git a/libs/Difficult_Rocket_rs/src/src/lib.rs b/libs/Difficult_Rocket_rs/src/src/lib.rs index 05efb04..d92b36c 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.0"); + return String::from("0.1.6.2"); } #[pyfunction] diff --git a/libs/Difficult_Rocket_rs/src/src/render.rs b/libs/Difficult_Rocket_rs/src/src/render.rs index c28f238..e7c5a38 100644 --- a/libs/Difficult_Rocket_rs/src/src/render.rs +++ b/libs/Difficult_Rocket_rs/src/src/render.rs @@ -53,10 +53,14 @@ pub mod camera { } #[allow(unused_variables)] - pub fn start(&self) -> PyResult<()> { - let view = self.get_view()?; + 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 view_matrix = view.call_method1(py, intern!(py, "translate"), args)?; + 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(()) @@ -64,7 +68,15 @@ pub mod camera { #[allow(unused_variables)] pub fn end(&self) -> PyResult<()> { - let view = self.get_view()?; + 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 view_matrix = view.call_method1(py, intern!(py, "scale"), args)?; + 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(()) + })?; return Ok(()) } @@ -72,11 +84,11 @@ pub mod camera { /// https://github.com/PyO3/pyo3/issues/1205#issuecomment-1164096251 for advice on `__enter__` pub fn __enter__(py_self: PyRef) -> PyResult> { // println!("enter!"); - py_self.start()?; + py_self.begin()?; Ok(py_self) } - pub fn __exit__(&mut self, _exc_type: PyObject, _exc_value: PyObject, _traceback: PyObject) -> PyResult<()>{ + pub fn __exit__(&self, _exc_type: PyObject, _exc_value: PyObject, _traceback: PyObject) -> PyResult<()>{ // println!("exit!"); self.end()?; return Ok(())