fix: 缩放问题 加入了计算质量 DR_rs 标记

This commit is contained in:
shenjack 2023-04-05 16:43:20 +08:00
parent 98fa6c6934
commit c4dff6db49
8 changed files with 83 additions and 10 deletions

View File

@ -210,10 +210,14 @@ class SR1ShipRender(BaseScreen):
except GeneratorExit:
self.drawing = False
self.need_draw = False
full_mass = 0
if DR_option.use_DR_rust:
for part in self.part_data:
full_mass += self.part_list_rs.get_part_type(self.part_data[part].p_type).mass * 500
logger.info(tr().client.sr1_render.ship.load_time().format(
(time.perf_counter_ns() - start_time) / 1000000000))
logger.info(tr().client.sr1_render.ship.info().format(
len(self.part_data), len(self.part_data) * 10))
len(self.part_data), f'{full_mass}kg' if DR_option.use_DR_rust else tr().game.require_DR_rs()))
self.rendered = True
def get_ship_size(self) -> (int, int):
@ -284,7 +288,7 @@ class SR1ShipRender(BaseScreen):
else:
zoom_d = ((2 ** scroll_y) - 1) * 0.5 + 1
# 缩放的变换量
if not self.camera_rs.zoom == 10 and scroll_y > 0:
if not self.camera_rs.zoom == 10 or scroll_y > 0:
if self.camera_rs.zoom * zoom_d >= 10:
zoom_d = 10 / self.camera_rs.zoom
self.camera_rs.zoom = 10

View File

@ -60,6 +60,7 @@ os.pid_is = "Server PID: {} PPID: {}"
input = "console"
command = "in game commands"
window = "window"
require_DR_rs = "require DR_rs module"
[client.sr1_render]
setup.start = "SR1 Renderer start loading"

View File

@ -60,6 +60,7 @@ os.pid_is = "服务端 PID: {} PPID: {}"
input = "控制台"
command = "游戏内命令行"
window = "窗口"
require_DR_rs = "需要 DR_rs 模块"
[client.sr1_render]
setup.start = "SR1 渲染器开始载入"

View File

@ -45,6 +45,9 @@
- 用于设置语言
- Added the `lang` parameter
- Used to set the language
- `game.require_DR_rs`
- 用于标记需要 `DR_rs` 才能运行的部分
- Used to mark the parts that need `DR_rs` to run
### Exception

View File

@ -9,9 +9,6 @@ from .lib import *
from typing import TYPE_CHECKING, Dict, Tuple, Optional
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
from pyglet.window import Window
@ -76,3 +73,22 @@ if TYPE_CHECKING:
class PartFrame_rs:
...
class SR1PartType_rs:
""" 用于从 rust 中读取 SR1PartType
不能从 Python 端创建"""
@property
def name(self) -> str: ...
@property
def mass(self) -> float: ...
class SR1PartList_rs:
""" 用于从 rust 中读取 SR1PartList """
def __init__(self, file_name: Optional[str] = "./configs/PartList.xml",
list_name: Optional[str] = 'NewPartList'): ...
def as_dict(self) -> Dict[str, SR1PartType_rs]: ...
def get_part_type(self, name: str) -> SR1PartType_rs: ...

View File

@ -40,5 +40,6 @@ fn module_init(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
m.add_class::<render::camera::CenterCameraRs>()?;
m.add_class::<render::screen::PartFrame>()?;
m.add_class::<python::data::PySR1PartList>()?;
m.add_class::<python::data::PySR1PartType>()?;
Ok(())
}

View File

@ -9,10 +9,36 @@
pub mod data {
use pyo3::prelude::*;
use serde_xml_rs::from_str;
use std::collections::HashMap;
use crate::sr1_data::part_list::RawPartList;
use crate::sr1_data::ship::RawShip;
use crate::types::sr1::{SR1PartList, SR1PartListTrait, SR1Ship};
use crate::types::sr1::{SR1PartList, SR1PartListTrait, SR1PartType, SR1Ship};
#[pyclass]
#[pyo3(name = "SR1PartType_rs")]
pub struct PySR1PartType {
pub data: SR1PartType,
}
#[pymethods]
impl PySR1PartType {
#[getter]
fn get_name(&self) -> String {
self.data.name.clone()
}
#[getter]
fn get_mass(&self) -> f64 {
self.data.mass
}
}
impl PySR1PartType {
pub fn new(data: SR1PartType) -> Self {
Self { data }
}
}
#[pyclass]
#[pyo3(name = "SR1PartList_rs")]
@ -30,8 +56,25 @@ pub mod data {
Self { part_list }
}
// fn get_weight(&self, part_type: String) -> PyRe<f64> {
// self.part_list.get_weight()
// }
fn as_dict(&self) -> HashMap<String, PySR1PartType> {
let mut dict = HashMap::new();
for part_type in self.part_list.types.iter() {
dict.insert(
part_type.name.clone(),
PySR1PartType::new(part_type.clone()),
);
}
dict
}
fn get_part_type(&mut self, name: String) -> Option<PySR1PartType> {
let cache = self.part_list.get_hash_map();
let part_type = cache.get(&name);
if let Some(part_type) = part_type {
Some(PySR1PartType::new(part_type.clone()))
} else {
None
}
}
}
}

View File

@ -212,11 +212,15 @@ pub mod sr1 {
}
impl SR1PartList {
pub fn get_hash_map(&self) -> HashMap<String, SR1PartType> {
pub fn get_hash_map(&mut self) -> HashMap<String, SR1PartType> {
if let Some(map) = &self.cache {
return map.clone();
}
let mut map = HashMap::new();
for part in self.types.iter() {
map.insert(part.id.clone(), part.clone());
}
self.cache = Some(map.clone());
map
}
}