DR_rs update
This commit is contained in:
parent
c9dc1bb4e6
commit
f32319c6f7
@ -13,6 +13,7 @@ gitee: @shenjackyuanjie
|
||||
# import ctypes
|
||||
import sys
|
||||
import logging
|
||||
import warnings
|
||||
import traceback
|
||||
from typing import List, Dict, Union, Optional
|
||||
|
||||
@ -21,25 +22,26 @@ from Difficult_Rocket.api.types import Options
|
||||
from libs.MCDR.version import Version
|
||||
|
||||
game_version = Version("0.6.5.0") # 游戏版本
|
||||
build_version = Version("1.0.1.0") # 编译文件版本(与游戏本体无关)
|
||||
DR_rust_version = Version("0.0.1.0") # DR 的 Rust 编写部分的版本
|
||||
build_version = Version("1.1.0.0") # 编译文件版本(与游戏本体无关)
|
||||
DR_rust_version = Version("0.0.5.0") # DR 的 Rust 编写部分的版本
|
||||
__version__ = game_version
|
||||
|
||||
long_version: int = 9
|
||||
long_version: int = 10
|
||||
"""
|
||||
long_version: 一个用于标记内部协议的整数
|
||||
9: 为 DR_option 添加 pyglet_macosx_dev_test
|
||||
8: 为 DR_runtime 添加 DR_rust_version
|
||||
为 DR_option 添加 DR_rust_available
|
||||
10: 为 DR_runtime 添加 DR_Rust_get_version
|
||||
9 : 为 DR_option 添加 pyglet_macosx_dev_test
|
||||
8 : 为 DR_runtime 添加 DR_rust_version
|
||||
为 DR_option 添加 DR_rust_available
|
||||
以后就有 DR_rust 了
|
||||
7: 为 DR_option 添加 std_font_size
|
||||
6: 事实证明, 不如直接用int
|
||||
5: 添加 build_version 信息,用于标记编译文件版本,
|
||||
游戏版本改为四位数,终于有一个可以让我随便刷的版本号位数了
|
||||
4: 把 translate 的字体常量位置改了一下,顺便调换顺序
|
||||
3: 就是试试改一下,正好 compiler 要用
|
||||
2: 哦,对 longlong 好耶!
|
||||
1: 我可算想起来还有这回事了 v0.6.4
|
||||
7 : 为 DR_option 添加 std_font_size
|
||||
6 : 事实证明, 不如直接用int
|
||||
5 : 添加 build_version 信息,用于标记编译文件版本,
|
||||
游戏版本改为四位数,终于有一个可以让我随便刷的版本号位数了
|
||||
4 : 把 translate 的字体常量位置改了一下,顺便调换顺序
|
||||
3 : 就是试试改一下,正好 compiler 要用
|
||||
2 : 哦,对 longlong 好耶!
|
||||
1 : 我可算想起来还有这回事了 v0.6.4
|
||||
"""
|
||||
|
||||
|
||||
@ -70,9 +72,9 @@ class _DR_option(Options):
|
||||
if not sys.platform == 'darwin': # MacOS 的测试只能在 Macos 上跑
|
||||
self.pyglet_macosx_dev_test = False
|
||||
try:
|
||||
from libs.Difficult_Rocket_rs import test_call
|
||||
from libs.Difficult_Rocket_rs import test_call, get_version_str
|
||||
test_call(self)
|
||||
self.DR_rust_available = True
|
||||
print(f'DR_rust available: {get_version_str()}')
|
||||
except ImportError:
|
||||
if not __name__ == '__main__':
|
||||
traceback.print_exc()
|
||||
@ -96,6 +98,7 @@ class _DR_runtime(Options):
|
||||
DR_version: Version = game_version
|
||||
Build_version: Version = build_version
|
||||
DR_Rust_version: Version = DR_rust_version
|
||||
DR_Rust_get_version: Optional[Version] = None
|
||||
DR_long_version: int = long_version
|
||||
|
||||
# run status
|
||||
@ -111,6 +114,17 @@ class _DR_runtime(Options):
|
||||
_language = 'zh-CN'
|
||||
default_language: str = 'zh-CN'
|
||||
|
||||
def init(self, **kwargs) -> None:
|
||||
try:
|
||||
from libs.Difficult_Rocket_rs import get_version_str
|
||||
self.DR_Rust_get_version = Version(get_version_str())
|
||||
if self.DR_Rust_get_version != self.DR_Rust_version:
|
||||
relationship = 'larger' if self.DR_Rust_version > self.DR_Rust_get_version else 'smaller'
|
||||
warnings.warn(f'DR_rust builtin version is {self.DR_Rust_version} but true version is {get_version_str()}.\n'
|
||||
f'Builtin version {relationship} than true version')
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.__options = {'language': self.language}
|
||||
super().__init__(**kwargs)
|
||||
@ -135,11 +149,6 @@ _DR_runtime.add_option('language', _DR_runtime.language)
|
||||
DR_option = _DR_option()
|
||||
DR_runtime = _DR_runtime()
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(DR_option.InputBox_use_TextEntry)
|
||||
print(sys.platform)
|
||||
...
|
||||
|
||||
if DR_option.playing:
|
||||
from Difficult_Rocket.utils import new_thread
|
||||
|
||||
|
@ -29,7 +29,7 @@ if TYPE_CHECKING:
|
||||
from Difficult_Rocket.client import ClientWindow
|
||||
|
||||
if DR_option.DR_rust_available:
|
||||
from libs.Difficult_Rocket_rs import better_update_parts
|
||||
from libs.Difficult_Rocket_rs import better_update_parts, PartDatas
|
||||
|
||||
|
||||
def get_sr1_part(part_xml: Element) -> Optional[SR1PartData]:
|
||||
@ -109,12 +109,14 @@ class SR1ShipRender(BaseScreen):
|
||||
self.part_batch = Batch()
|
||||
self.part_group = Group()
|
||||
self.debug_label = Label(x=20, y=main_window.height - 20, font_size=DR_option.std_font_size,
|
||||
text='SR1 render!', font_name=Fonts.微软等宽无线,
|
||||
width=main_window.width - 20, height=20,
|
||||
anchor_x='left', anchor_y='top',
|
||||
batch=self.part_batch)
|
||||
text='SR1 render!', font_name=Fonts.微软等宽无线,
|
||||
width=main_window.width - 20, height=20,
|
||||
anchor_x='left', anchor_y='top',
|
||||
batch=self.part_batch)
|
||||
self.part_data: Dict[int, SR1PartData] = {}
|
||||
self.parts_sprite: Dict[int, Sprite] = {}
|
||||
if DR_option.DR_rust_available:
|
||||
self.rust_parts = None
|
||||
|
||||
def load_xml(self, file_path: str) -> bool:
|
||||
try:
|
||||
@ -170,20 +172,27 @@ class SR1ShipRender(BaseScreen):
|
||||
self.parts_sprite[part.id].visible = False
|
||||
self.parts_sprite[part.id] = cache_sprite
|
||||
self.need_draw = False
|
||||
if DR_option.DR_rust_available:
|
||||
print(type(self.part_data))
|
||||
self.rust_parts = PartDatas(self.part_data)
|
||||
self.rendered = True
|
||||
|
||||
def update_parts(self) -> bool:
|
||||
if DR_option.DR_rust_available:
|
||||
return better_update_parts(self, SR1ShipRender_Option, self.window_pointer)
|
||||
return better_update_parts(self, SR1ShipRender_Option, self.window_pointer, self.rust_parts)
|
||||
if not self.rendered:
|
||||
return False
|
||||
self.debug_line.x2, self.debug_line.y2 = self.dx + (self.window_pointer.width / 2), self.dy + (self.window_pointer.height / 2)
|
||||
self.debug_line.x2, self.debug_line.y2 = self.dx + (self.window_pointer.width / 2), self.dy + (
|
||||
self.window_pointer.height / 2)
|
||||
self.debug_d_pos_label.text = f'x: {self.dx} y: {self.dy}'
|
||||
self.debug_d_pos_label.position = self.dx + (self.window_pointer.width / 2), self.dy + (self.window_pointer.height / 2) + 10, 0
|
||||
self.debug_d_pos_label.position = self.dx + (self.window_pointer.width / 2), self.dy + (
|
||||
self.window_pointer.height / 2) + 10, 0
|
||||
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.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].scale = self.scale * DR_option.gui_scale
|
||||
|
||||
def on_draw(self):
|
||||
@ -223,8 +232,10 @@ class SR1ShipRender(BaseScreen):
|
||||
self.dy += (mouse_dy - self.dy) * (1 - (0.5 ** scroll_y))
|
||||
else:
|
||||
self.scale = 10
|
||||
self.debug_mouse_delta_line.x2 = (mouse_dx - self.dx) * (1 - (0.5 ** scroll_y)) + (self.window_pointer.width / 2)
|
||||
self.debug_mouse_delta_line.y2 = (mouse_dy - self.dy) * (1 - (0.5 ** scroll_y)) + (self.window_pointer.height / 2)
|
||||
self.debug_mouse_delta_line.x2 = (mouse_dx - self.dx) * (1 - (0.5 ** scroll_y)) + (
|
||||
self.window_pointer.width / 2)
|
||||
self.debug_mouse_delta_line.y2 = (mouse_dy - self.dy) * (1 - (0.5 ** scroll_y)) + (
|
||||
self.window_pointer.height / 2)
|
||||
self.debug_mouse_label.text = f'x: {mouse_dx} y: {mouse_dy}'
|
||||
self.debug_mouse_label.position = x, y + 10, 0
|
||||
self.update_parts()
|
||||
|
@ -17,6 +17,22 @@
|
||||
- [![Readme-gitee](https://img.shields.io/badge/Readme-中文(点我!)-blue.svg?style=flat-square)](../../README.md)
|
||||
- Using [SemVer 2.0.0](https://semver.org/) to manage version
|
||||
|
||||
## 202301 V 0.7.0
|
||||
|
||||
### 啊哈! 现在真就是 0.7 了
|
||||
|
||||
### Add
|
||||
|
||||
- `libs.Difficult_Rocket_rs` (`DR_rs`)
|
||||
- `get_version_str`
|
||||
- 返回 `DR_rs` 的版本号 可以用于检查我有没有忘记跑 `after_build.py`
|
||||
- 别问为啥不是返回一个 `Version` 对象 问就是懒得转换
|
||||
- `better_update_pats`
|
||||
- 用于优化 `SR1ShipRender.update_parts` 的性能
|
||||
- ( Python 原生的 for 循环真慢 )
|
||||
- `PartDatas`
|
||||
- 用于在 `PyObj` 里 暗 渡 陈 仓 装 `HashMap<uszie, SR1PartData>`
|
||||
|
||||
## 20230120 V 0.6.5.0
|
||||
|
||||
### 抱歉,我撒谎了(
|
||||
|
@ -6,20 +6,24 @@
|
||||
|
||||
from .lib import *
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
from typing import TYPE_CHECKING, Dict
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from Difficult_Rocket.client.screen import BaseScreen
|
||||
from Difficult_Rocket.api.types.SR1 import SR1PartData
|
||||
from Difficult_Rocket.client.render.sr1_ship import SR1ShipRender, SR1ShipRender_Option
|
||||
def sum_as_string(a: int, b: int) -> int: ...
|
||||
|
||||
def for_x_in_range(a: int, b: int) -> None: ...
|
||||
|
||||
def test_call(py_obj) -> bool: ...
|
||||
|
||||
def better_update_parts(render: SR1ShipRender, option: SR1ShipRender_Option, window: BaseScreen) -> bool: ...
|
||||
def get_version_str() -> str: ...
|
||||
|
||||
class PartDatas:
|
||||
""" 用于在 PyObj 里塞一个浓眉大眼的 HashMap<uszie, SR1PartData>"""
|
||||
def __new__(cls, py_part_data) -> "PartDatas": ...
|
||||
def __new__(cls, py_part_data: Dict[int, SR1PartData]) -> "PartDatas": ...
|
||||
|
||||
def better_update_parts(render: SR1ShipRender,
|
||||
option: SR1ShipRender_Option,
|
||||
window: BaseScreen,
|
||||
parts: PartDatas) -> bool: ...
|
||||
|
||||
|
||||
|
@ -10,10 +10,9 @@ mod sr1_render;
|
||||
|
||||
use pyo3::prelude::*;
|
||||
|
||||
/// Formats the sum of two numbers as string.
|
||||
#[pyfunction]
|
||||
fn sum_as_string(a: usize, b: usize) -> PyResult<String> {
|
||||
Ok((a + b).to_string())
|
||||
fn get_version_str() -> String {
|
||||
return String::from("0.0.5.0");
|
||||
}
|
||||
|
||||
#[pyfunction]
|
||||
@ -22,24 +21,13 @@ fn test_call(py_obj: &PyAny) -> PyResult<bool> {
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
|
||||
#[pyfunction]
|
||||
fn for_x_in_range(a: usize, b: usize) -> PyResult<()> {
|
||||
assert!(a <= b);
|
||||
for x in a..b {
|
||||
println!("{}", x);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// A Python module implemented in Rust. The name of this function must match
|
||||
/// the `lib.name` setting in the `Cargo.toml`, else Python will not be able to
|
||||
/// import the module.
|
||||
#[pymodule]
|
||||
#[pyo3(name = "Difficult_Rocket_rs")]
|
||||
fn module_init(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
|
||||
m.add_function(wrap_pyfunction!(sum_as_string, m)?)?;
|
||||
m.add_function(wrap_pyfunction!(for_x_in_range, m)?)?;
|
||||
m.add_function(wrap_pyfunction!(get_version_str, m)?)?;
|
||||
m.add_function(wrap_pyfunction!(test_call, m)?)?;
|
||||
m.add_function(wrap_pyfunction!(sr1_render::better_update_parts, m)?)?;
|
||||
m.add_class::<sr1_render::types::PartDatas>()?;
|
||||
|
@ -10,14 +10,13 @@ use std::collections::HashMap;
|
||||
use pyo3::intern;
|
||||
use pyo3::prelude::*;
|
||||
use pyo3::types::PyDict;
|
||||
use crate::sr1_render::types::Point;
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub mod types {
|
||||
use std::collections::HashMap;
|
||||
use pyo3::intern;
|
||||
use pyo3::prelude::*;
|
||||
use pyo3::types::PyDict;
|
||||
use pyo3::types::{PyDict};
|
||||
|
||||
pub struct SR1PartData {
|
||||
pub x: f64,
|
||||
@ -32,7 +31,7 @@ pub mod types {
|
||||
pub flip_y: bool,
|
||||
pub explode: bool,
|
||||
pub textures: String,
|
||||
pub connections: Vec<usize>
|
||||
// pub connections: Vec<usize>
|
||||
}
|
||||
|
||||
pub struct Point {
|
||||
@ -52,6 +51,7 @@ pub mod types {
|
||||
#[new]
|
||||
pub fn py_new(py_part_data: &PyDict) -> PyResult<Self> {
|
||||
let datas: HashMap<usize, SR1PartData> = part_data_tp_SR1PartDatas(py_part_data)?;
|
||||
// let datas: HashMap<usize, SR1PartData> = HashMap::new();
|
||||
return Ok(PartDatas { part_structs: datas })
|
||||
}
|
||||
}
|
||||
@ -77,7 +77,7 @@ pub mod types {
|
||||
flip_y: input.getattr(intern!(input.py(), "flip_y"))?.extract()?,
|
||||
explode: input.getattr(intern!(input.py(), "explode"))?.extract()?,
|
||||
textures: input.getattr(intern!(input.py(), "textures"))?.extract()?,
|
||||
connections: input.getattr(intern!(input.py(), "connections"))?.extract()?,
|
||||
// connections: input.getattr(intern!(input.py(), "connections"))?.extract()?,
|
||||
})
|
||||
}
|
||||
|
||||
@ -87,6 +87,7 @@ pub mod types {
|
||||
for key in input.iter() {
|
||||
result.insert(key.0.extract()?, part_data_to_SR1PartData(key.1)?);
|
||||
}
|
||||
println!("it calls me success");
|
||||
return Ok(result)
|
||||
}
|
||||
|
||||
@ -114,7 +115,7 @@ pub mod types {
|
||||
|
||||
#[pyfunction]
|
||||
#[allow(unused_variables)]
|
||||
pub fn better_update_parts(render: &PyAny, option: &PyAny, window: &PyAny) -> PyResult<bool> {
|
||||
pub fn better_update_parts(render: &PyAny, option: &PyAny, window: &PyAny, parts: &types::PartDatas) -> PyResult<bool> {
|
||||
if !render.getattr(intern!(render.py(), "rendered"))?.is_true()? {
|
||||
return Ok(false);
|
||||
}
|
||||
@ -125,7 +126,7 @@ pub fn better_update_parts(render: &PyAny, option: &PyAny, window: &PyAny) -> Py
|
||||
let x_center: f32 = x_center / 2.0;
|
||||
let y_center: f32 = y_center / 2.0;
|
||||
let part_datas: &PyDict = render.getattr(intern!(render.py(), "part_data"))?.extract()?;
|
||||
let parts: HashMap<usize, Point> = types::part_datas_to_points(part_datas)?;
|
||||
let parts: HashMap<usize, types::Point> = types::part_datas_to_points(part_datas)?;
|
||||
if option.getattr("debug_d_pos")?.is_true()? {
|
||||
let line = render.getattr(intern!(render.py(), "debug_line"))?;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user