Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extension - Update to latest arma-rs #10312

Merged
merged 4 commits into from
Sep 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 59 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified ace.dll
Binary file not shown.
Binary file modified ace_x64.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion extension/Cargo.toml
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ name = "ace"
crate-type = ["cdylib"]

[dependencies]
arma-rs = { version = "1.10.5", features = ["uuid"] }
arma-rs = { version = "1.11.0", default-features = false, features = ["extension", "uuid"]}
uuid = { version = "1.10.0", features = ["v4"] }
rand = "0.8.5"
rand_chacha = "0.3.1"
6 changes: 3 additions & 3 deletions extension/src/ballistics/atmosphere.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use arma_rs::FromArma;
use arma_rs::{FromArma, FromArmaError};

use super::map::Map;
use crate::common::Temperature;
@@ -10,12 +10,12 @@ pub enum AtmosphereModel {
}

impl FromArma for AtmosphereModel {
fn from_arma(s: String) -> Result<Self, String> {
fn from_arma(s: String) -> Result<Self, FromArmaError> {
let s = s.trim_matches('"');
match s.to_lowercase().as_str() {
"icao" => Ok(Self::Icao),
"asm" => Ok(Self::Asm),
_ => Err(String::from("unexpected model")),
_ => Err(FromArmaError::InvalidValue("unexpected model".into())),
}
}
}
8 changes: 5 additions & 3 deletions extension/src/ballistics/drag.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![allow(clippy::approx_constant)]

use arma_rs::FromArma;
use arma_rs::{FromArma, FromArmaError};

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum DragFunction {
@@ -13,15 +13,17 @@ pub enum DragFunction {
}

impl FromArma for DragFunction {
fn from_arma(s: String) -> Result<Self, String> {
fn from_arma(s: String) -> Result<Self, FromArmaError> {
match s.as_str() {
"1" => Ok(Self::G1),
"2" => Ok(Self::G2),
"5" => Ok(Self::G5),
"6" => Ok(Self::G6),
"7" => Ok(Self::G7),
"8" => Ok(Self::G8),
_ => Err(format!("Unknown drag function: {s}")),
_ => Err(FromArmaError::InvalidValue(format!(
"Unknown drag function: {s}"
))),
}
}
}
8 changes: 5 additions & 3 deletions extension/src/common/types/height.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::ops::Deref;

use arma_rs::FromArma;
use arma_rs::{FromArma, FromArmaError};

#[derive(Debug, Clone, Copy)]
/// Height in meters
@@ -13,8 +13,10 @@ impl Height {
}

impl FromArma for Height {
fn from_arma(value: String) -> Result<Self, String> {
Ok(Self(value.parse::<f64>().map_err(|_| "Invalid height")?))
fn from_arma(value: String) -> Result<Self, FromArmaError> {
Ok(Self(value.parse::<f64>().map_err(|_| {
FromArmaError::InvalidValue("Invalid height".into())
})?))
}
}

12 changes: 5 additions & 7 deletions extension/src/common/types/muzzle_velocity.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::ops::Deref;

use arma_rs::FromArma;
use arma_rs::{FromArma, FromArmaError};

#[derive(Debug, Clone, Copy)]
/// Muzzle velocity in m/s
@@ -14,12 +14,10 @@ impl MuzzleVelocity {
}

impl FromArma for MuzzleVelocity {
fn from_arma(value: String) -> Result<Self, String> {
Ok(Self(
value
.parse::<f64>()
.map_err(|_| "Invalid muzzle velocity")?,
))
fn from_arma(value: String) -> Result<Self, FromArmaError> {
Ok(Self(value.parse::<f64>().map_err(|_| {
FromArmaError::InvalidValue("Invalid muzzle velocity".into())
})?))
}
}

24 changes: 17 additions & 7 deletions extension/src/common/types/temperature.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use arma_rs::FromArma;
use arma_rs::{FromArma, FromArmaError};

#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Temperature(f64);
@@ -35,25 +35,35 @@ impl Temperature {
}

impl FromArma for Temperature {
fn from_arma(s: String) -> Result<Self, String> {
fn from_arma(s: String) -> Result<Self, FromArmaError> {
if s.is_empty() {
return Err(String::from("unexpected empty string"));
return Err(FromArmaError::InvalidValue(
"unexpected empty string".into(),
));
}
match s.chars().next().unwrap() {
'c' => {
let temp = s[1..].parse::<f64>().map_err(|e| format!("{e}"))?;
let temp = s[1..]
.parse::<f64>()
.map_err(|e| FromArmaError::InvalidValue(format!("{e}")))?;
Ok(Self::new_celsius(temp))
}
'f' => {
let temp = s[1..].parse::<f64>().map_err(|e| format!("{e}"))?;
let temp = s[1..]
.parse::<f64>()
.map_err(|e| FromArmaError::InvalidValue(format!("{e}")))?;
Ok(Self::new_fahrenheit(temp))
}
'k' => {
let temp = s[1..].parse::<f64>().map_err(|e| format!("{e}"))?;
let temp = s[1..]
.parse::<f64>()
.map_err(|e| FromArmaError::InvalidValue(format!("{e}")))?;
Ok(Self::new_kelvin(temp))
}
_ => {
let temp = s.parse::<f64>().map_err(|e| format!("{e}"))?;
let temp = s
.parse::<f64>()
.map_err(|e| FromArmaError::InvalidValue(format!("{e}")))?;
Ok(Self::new_celsius(temp))
}
}
4 changes: 2 additions & 2 deletions extension/src/common/types/vector3.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use arma_rs::{FromArma, IntoArma};
use arma_rs::{FromArma, FromArmaError, IntoArma};

#[derive(Debug, Clone, Copy, PartialEq, Default)]
pub struct Vector3 {
@@ -52,7 +52,7 @@ impl Vector3 {
}

impl FromArma for Vector3 {
fn from_arma(s: String) -> Result<Self, String> {
fn from_arma(s: String) -> Result<Self, FromArmaError> {
let data = <[f64; 3]>::from_arma(s)?;
Ok(Self {
x: data[0],