Adjust file structures and bump version to 0.3.1.

This commit is contained in:
InfyniteHeap 2023-12-24 21:29:04 +08:00
parent 57472028b7
commit 3224c8fc9f
No known key found for this signature in database
GPG Key ID: 9D33043072466AB8
18 changed files with 78 additions and 118 deletions

View File

@ -67,9 +67,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "crossbeam"
version = "0.8.2"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2801af0d36612ae591caa9568261fddce32ce6e08a7275ea334a06a4ad021a2c"
checksum = "6eb9105919ca8e40d437fc9cbb8f1975d916f1bd28afe795a48aae32a2cc8920"
dependencies = [
"cfg-if",
"crossbeam-channel",
@ -81,9 +81,9 @@ dependencies = [
[[package]]
name = "crossbeam-channel"
version = "0.5.9"
version = "0.5.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14c3242926edf34aec4ac3a77108ad4854bffaa2e4ddc1824124ce59231302d5"
checksum = "82a9b73a36529d9c47029b9fb3a6f0ea3cc916a261195352ba19e770fc1748b2"
dependencies = [
"cfg-if",
"crossbeam-utils",
@ -102,21 +102,20 @@ dependencies = [
[[package]]
name = "crossbeam-epoch"
version = "0.9.16"
version = "0.9.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2d2fe95351b870527a5d09bf563ed3c97c0cffb87cf1c78a591bf48bb218d9aa"
checksum = "0e3681d554572a651dda4186cd47240627c3d0114d45a95f6ad27f2f22e7548d"
dependencies = [
"autocfg",
"cfg-if",
"crossbeam-utils",
"memoffset",
]
[[package]]
name = "crossbeam-queue"
version = "0.3.9"
version = "0.3.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9bcf5bdbfdd6030fb4a1c497b5d5fc5921aa2f60d359a17e249c0e6df3de153"
checksum = "adc6598521bb5a83d491e8c1fe51db7296019d2ca3cb93cc6c2a20369a4d78a2"
dependencies = [
"cfg-if",
"crossbeam-utils",
@ -124,9 +123,9 @@ dependencies = [
[[package]]
name = "crossbeam-utils"
version = "0.8.17"
version = "0.8.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c06d96137f14f244c37f989d9fff8f95e6c18b918e71f36638f8c49112e4c78f"
checksum = "c3a430a770ebd84726f584a90ee7f020d28db52c6d02138900f22341f866d39c"
dependencies = [
"cfg-if",
]
@ -144,7 +143,7 @@ dependencies = [
[[package]]
name = "difficult_rocket_rs"
version = "0.3.0"
version = "0.3.1"
dependencies = [
"dict_derive",
"fs-err",
@ -381,9 +380,9 @@ checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c"
[[package]]
name = "proc-macro2"
version = "1.0.70"
version = "1.0.71"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b"
checksum = "75cb1540fadbd5b8fbccc4dddad2734eba435053f725621c070711a14bb5f4b8"
dependencies = [
"unicode-ident",
]
@ -434,7 +433,7 @@ dependencies = [
"proc-macro2",
"pyo3-macros-backend",
"quote",
"syn 2.0.41",
"syn 2.0.42",
]
[[package]]
@ -446,7 +445,7 @@ dependencies = [
"heck",
"proc-macro2",
"quote",
"syn 2.0.41",
"syn 2.0.42",
]
[[package]]
@ -548,7 +547,7 @@ checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.41",
"syn 2.0.42",
]
[[package]]
@ -604,9 +603,9 @@ dependencies = [
[[package]]
name = "syn"
version = "2.0.41"
version = "2.0.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "44c8b28c477cc3bf0e7966561e3460130e1255f7a1cf71931075f1c5e7a7e269"
checksum = "5b7d0a2c048d661a1a59fcd7355baa232f7ed34e0ee4df2eef3c1c1c0d3852d8"
dependencies = [
"proc-macro2",
"quote",
@ -718,20 +717,20 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
[[package]]
name = "zerocopy"
version = "0.7.31"
version = "0.7.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1c4061bedbb353041c12f413700357bec76df2c7e2ca8e4df8bac24c6bf68e3d"
checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be"
dependencies = [
"zerocopy-derive",
]
[[package]]
name = "zerocopy-derive"
version = "0.7.31"
version = "0.7.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b3c129550b3e6de3fd0ba67ba5c81818f9805e58b8d7fee80a3a59d2c9fc601a"
checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.41",
"syn 2.0.42",
]

View File

@ -1,6 +1,6 @@
[package]
name = "difficult_rocket_rs"
version = "0.3.0"
version = "0.3.1"
edition = "2021"
license-file = '../../LICENSE'
authors = ["shenjackyuanjie <3695888@qq.com>"]
@ -14,13 +14,10 @@ crate-type = ["cdylib"]
#[profile.dev.package.rapier2d-f64]
#opt-level = 2
[profile.dev]
opt-level = 0
[profile.release]
lto = "fat"
# Abort panic info to rapidly terminate program instead of unwinding call stacks.
# To check panic info, compile the program in dev mode.
# 舍弃恐慌信息以快速终止程序,而非展开调用栈。
# 请以开发模式编译程序以检查恐慌信息。
panic = "abort"
opt-level = 2
@ -28,9 +25,7 @@ opt-level = 2
fs-err = "2.11.0"
quick-xml = { version = "0.31.0", features = ["serialize"] }
serde = { version = "1.0", features = ["derive"] }
nalgebra = "0.32.3"
rapier2d-f64 = { version = "0.17.2", features = ["simd-stable"] }
pyo3 = { version = "0.20.0", features = ["extension-module", "macros"] }
dict_derive = "0.5"

View File

@ -12,7 +12,7 @@ package_path = "Difficult_Rocket_rs"
setup(
name="Difficult_Rocket_rs",
version="0.3.0",
version="0.3.1",
author="shenjackyuanjie",
author_email="3695888@qq.com",
rust_extensions=[

View File

@ -1,13 +0,0 @@
/*
* -------------------------------
* Difficult Rocket
* Copyright © 2020-2023 by shenjackyuanjie 3695888@qq.com
* All rights reserved
* -------------------------------
*/
pub mod dr;
pub mod math;
pub mod sr1;
pub type IdType = i64;

View File

@ -0,0 +1,3 @@
pub mod math;
pub mod rigid;
pub mod simulation;

View File

@ -1,6 +1,6 @@
pub const POINT_D: f64 = 1.0;
pub trait Rotatable {
pub trait Rotate {
// 懒了,直接实现一个协议得了
fn rotate(&self, angle: f64) -> Self;
fn rotate_radius(&self, radius: f64) -> Self;
@ -44,7 +44,7 @@ impl Point2D {
}
}
impl Rotatable for Point2D {
impl Rotate for Point2D {
fn rotate_radius(&self, radius: f64) -> Self {
let sin = radius.sin();
let cos = radius.cos();
@ -85,13 +85,14 @@ pub struct OneTimeLine {
// pub b: f64,
// y = kx + b
// kx + b - y = 0
pub start: Point2D,
// start point
pub end: Point2D,
pub start: Point2D,
// end point
pub end: Point2D,
}
impl Rotatable for OneTimeLine {
impl Rotate for OneTimeLine {
fn rotate(&self, angle: f64) -> Self {
self.rotate_radius(angle.to_radians())
}

View File

@ -6,18 +6,18 @@
* -------------------------------
*/
mod data_type;
mod plugin_loader;
mod dr_physics;
mod python;
mod simulator;
mod sr1_data;
mod sr1_parse;
mod xml_reader;
use pyo3::prelude::*;
pub type IdType = i64;
#[pyfunction]
fn get_version_str() -> String {
"0.3.0".to_string()
"0.3.1".to_string()
}
#[pyfunction]
@ -31,8 +31,8 @@ fn test_call(py_obj: &PyAny) -> PyResult<bool> {
fn module_init(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
m.add_function(wrap_pyfunction!(get_version_str, m)?)?;
m.add_function(wrap_pyfunction!(test_call, m)?)?;
m.add_function(wrap_pyfunction!(sr1_data::part_list::read_part_list_py, m)?)?;
m.add_function(wrap_pyfunction!(sr1_data::ship::py_raw_ship_from_file, m)?)?;
m.add_function(wrap_pyfunction!(sr1_parse::part_list::read_part_list_py, m)?)?;
m.add_function(wrap_pyfunction!(sr1_parse::ship::py_raw_ship_from_file, m)?)?;
m.add_function(wrap_pyfunction!(python::data::load_and_save_test, m)?)?;
m.add_class::<python::data::PySR1Ship>()?;
m.add_class::<python::data::PySR1PartList>()?;

View File

@ -1,22 +0,0 @@
/*
* -------------------------------
* Difficult Rocket
* Copyright © 2020-2023 by shenjackyuanjie 3695888@qq.com
* All rights reserved
* -------------------------------
*/
// TODO libloading
/// https://docs.rs/libloading/latest/libloading/
/// 插件加载
///
pub struct ModInfo {
pub name: String,
pub version: String,
}
pub trait ModInfoTrait {
fn info() -> ModInfo;
}

View File

@ -3,13 +3,13 @@ use std::collections::HashMap;
use pyo3::exceptions::PyValueError;
use pyo3::prelude::*;
use crate::data_type::math::{Point2D, Rotatable};
use crate::data_type::sr1::SaveStatus;
use crate::data_type::sr1::{get_max_box, SR1PartData, SR1PartListTrait};
use crate::data_type::sr1::{SR1PartList, SR1PartType, SR1Ship};
use crate::data_type::IdType;
use crate::sr1_data::part_list::RawPartList;
use crate::sr1_data::ship::RawShip;
use crate::dr_physics::math::{Point2D, Rotate};
use crate::sr1_parse::part_list::RawPartList;
use crate::sr1_parse::ship::RawShip;
use crate::sr1_parse::SaveStatus;
use crate::sr1_parse::{get_max_box, SR1PartData, SR1PartListTrait};
use crate::sr1_parse::{SR1PartList, SR1PartType, SR1Ship};
use crate::IdType;
// use serde_xml_rs::to_string;
use quick_xml::se::to_string;

View File

@ -10,7 +10,7 @@ use nalgebra::{Matrix2, Vector2};
use pyo3::prelude::*;
use rapier2d_f64::math::Real;
use crate::data_type::IdType;
use crate::IdType;
/// Id 位置 碰撞体
pub type BoundedShape = (IdType, Vector2<Real>, EditorShapeEnum);

View File

@ -1,22 +1,26 @@
mod data_structure;
pub use self::data_structure::*;
use std::cell::{Cell, RefCell};
use std::collections::HashMap;
use std::fs;
use std::io::Cursor;
use std::ops::Deref;
use super::math::{Edge, Shape};
use crate::sr1_data::part_list::Damage as RawDamage;
use crate::sr1_data::part_list::{AttachPoint, AttachPoints, Engine, Lander, Rcs, Shape as RawShape, Solar, Tank};
use crate::sr1_data::part_list::{RawPartList, RawPartType, SR1PartTypeEnum};
use crate::sr1_data::ship::{
use crate::dr_physics::math::{Edge, Shape};
use crate::sr1_parse::part_list::Damage as RawDamage;
use crate::sr1_parse::part_list::{AttachPoint, AttachPoints, Engine, Lander, Rcs, Shape as RawShape, Solar, Tank};
use crate::sr1_parse::part_list::{RawPartList, RawPartType, SR1PartTypeEnum};
use crate::sr1_parse::ship::{
Activate as RawActivate, Connection, Connections, DisconnectedPart as RawDisconnectedPart,
DisconnectedParts as RawDisconnectedParts, Engine as RawEngine, Part as RawPartData, Parts as RawParts,
Pod as RawPod, RawShip, Staging as RawStaging, Step as RawStep, Tank as RawTank,
};
use crate::data_type::math::{Point2D, Rotatable};
use crate::data_type::IdType;
use crate::dr_physics::math::{Point2D, Rotate};
use crate::IdType;
use fs_err as fs;
use quick_xml::events::{BytesEnd, BytesStart, Event};
use quick_xml::writer::Writer;
@ -45,11 +49,11 @@ pub enum SR1PartTypeAttr {
consumption: f64,
size: f64,
turn: f64,
fuel_type: i32,
/// 0 -> 普通燃料
/// 1 -> Rcs
/// 2 -> 电量
/// 3 -> 固推
fuel_type: i32,
throttle_exponential: bool,
},
Rcs {
@ -161,7 +165,6 @@ pub struct SR1PartList {
}
impl SR1PartList {
#[inline]
pub fn new(name: String, types: Vec<SR1PartType>) -> SR1PartList {
SR1PartList {
types,
@ -170,7 +173,6 @@ impl SR1PartList {
}
}
#[inline]
pub fn from_file(file_name: String) -> Option<SR1PartList> {
if let Some(raw_list) = RawPartList::from_file(file_name) {
let sr_list = raw_list.to_sr_part_list(None);
@ -191,7 +193,6 @@ impl SR1PartList {
self.cache.borrow().clone().unwrap()
}
#[inline]
pub fn get_part_type(&self, type_name: &String) -> Option<SR1PartType> {
let cache = self.get_cache();
cache.get(type_name).cloned()
@ -373,12 +374,10 @@ impl SR1PartTypeData for SR1PartType {
}
impl SR1PartDataTrait for SR1PartData {
#[inline]
fn to_sr_part_data(&self) -> SR1PartData {
self.clone()
}
#[inline]
fn to_raw_part_data(&self) -> RawPartData {
let (tank, engine) = if let Some(fuel) = &self.attr.fuel {
match self.part_type {
@ -600,7 +599,6 @@ impl SR1PartDataAttr {
Some(pod.throttle),
Some(pod.stages.current_stage),
Some({
// The mother-fucking nests come out again!
let mut steps = Vec::new();
match &pod.stages.steps {
Some(step_vec) => {
@ -697,7 +695,6 @@ impl SR1Ship {
part.part_type = SR1PartTypeEnum::strut;
}
}
// Why are you fucking nesting such this fucking loops?!
for disconnects in self.disconnected.iter_mut() {
for (parts, _) in disconnects.iter_mut() {
for part in parts.iter_mut() {

View File

@ -1,10 +1,10 @@
use crate::data_type::sr1::{SR1PartList, SR1PartType, SR1PartTypeAttr};
use crate::data_type::sr1::{SR1PartListTrait, SR1PartTypeData};
use crate::sr1_parse::{SR1PartList, SR1PartType, SR1PartTypeAttr};
use crate::sr1_parse::{SR1PartListTrait, SR1PartTypeData};
use fs_err as fs;
use pyo3::prelude::*;
use serde::{Deserialize, Serialize};
use quick_xml::de::from_str;
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct RawPartList {
@ -138,8 +138,8 @@ pub struct Damage {
}
impl Damage {
pub fn take_damage(&self) -> crate::data_type::sr1::Damage {
crate::data_type::sr1::Damage {
pub fn take_damage(&self) -> crate::sr1_parse::Damage {
crate::sr1_parse::Damage {
disconnect: self.disconnect,
explode: self.explode,
explosion_power: self.explosion_power.unwrap_or(100_f64),

View File

@ -6,9 +6,9 @@ use quick_xml::se::to_string;
// use quick_xml::Error as XmlError;
use serde::{Deserialize, Serialize};
use crate::data_type::sr1::{SR1PartData, SR1PartDataAttr, SR1Ship};
use crate::data_type::sr1::{SR1PartDataTrait, SR1ShipTrait};
use crate::data_type::IdType;
use crate::sr1_parse::{SR1PartData, SR1PartDataAttr, SR1Ship};
use crate::sr1_parse::{SR1PartDataTrait, SR1ShipTrait};
use crate::IdType;
/// https://docs.rs/quick-xml/latest/quick_xml/de/index.html#basics
/// using quick xml

View File

@ -2,14 +2,14 @@ use std::io;
use fs_err as fs;
// Input the directory of the xml file.
// If file does not exsit or not the XML file, return errors or return file handle.
// I think this fuction can be improved as its implementations are not as good as what I expected.
pub fn read_xml(dir: &str) -> io::Result<fs::File> {
if dir.split_inclusive('.').collect::<Vec<&str>>()[1] != "xml" {
// 输入XML文件的路径。
// 若文件不存在或非XML文件则返回错误否则返回文件句柄。
// 我认为该函数仍可改进,因为它的实现并未达到我所预期的那样。
pub fn read_xml(path: &str) -> io::Result<fs::File> {
if path.split_inclusive('.').collect::<Vec<&str>>()[1] != "xml" {
Err(io::Error::new(io::ErrorKind::Other, "This file is not an XML file!"))
} else {
fs::File::open(dir)
fs::File::open(path)
}
}