Skip to content

Commit

Permalink
initial support for DCS 2.7 clouds
Browse files Browse the repository at this point in the history
  • Loading branch information
rkusa committed Apr 20, 2021
1 parent 6911248 commit aa73fb1
Show file tree
Hide file tree
Showing 14 changed files with 640 additions and 316 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## [3.0.0-beta.1] - 2021-04-20

BREAKING: Requires DCS 2.7 from now on.

### Added

- Added support for DCS 2.7 cloud presets.

## [2.2.2] - 2021-04-11

### Changed
Expand Down
2 changes: 1 addition & 1 deletion crates/datis-cmd/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "datis-cmd"
version = "2.2.2"
version = "3.0.0-beta.1"
authors = ["Markus Ast <[email protected]>"]
edition = "2018"

Expand Down
2 changes: 1 addition & 1 deletion crates/datis-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "datis-core"
version = "2.2.2"
version = "3.0.0-beta.1"
authors = ["Markus Ast <[email protected]>"]
edition = "2018"

Expand Down
42 changes: 25 additions & 17 deletions crates/datis-core/src/ipc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,21 @@ use crate::weather::{Clouds, WeatherInfo};
use dcs_module_ipc::Error;
use serde::Deserialize;
use serde_json::json;
use tokio::sync::Mutex;

pub struct MissionRpcInner {
ipc: dcs_module_ipc::IPC<()>,
clouds: Option<Clouds>,
fog_thickness: u32, // in m
fog_visibility: u32, // in m
clouds: Mutex<Option<Clouds>>,
}

#[derive(Clone)]
pub struct MissionRpc(Arc<MissionRpcInner>);

impl MissionRpc {
pub fn new(clouds: Option<Clouds>, fog_thickness: u32, fog_visibility: u32) -> Self {
pub fn new() -> Self {
MissionRpc(Arc::new(MissionRpcInner {
ipc: dcs_module_ipc::IPC::new(),
clouds,
fog_thickness,
fog_visibility,
clouds: Mutex::new(None),
}))
}

Expand All @@ -35,16 +32,11 @@ impl MissionRpc {
wind_dir: f64,
temp: f64,
pressure: f64,
fog_thickness: f64, // in m
fog_visibility: f64, // in m
dust_density: u32,
}

let clouds = self.0.clouds.clone();

let visibility = if self.0.fog_thickness > 200 {
Some(self.0.fog_visibility)
} else {
None
};

let data: Data = self
.0
.ipc
Expand Down Expand Up @@ -72,18 +64,34 @@ impl MissionRpc {
wind_dir += 360.0;
}

let clouds = {
let mut clouds = self.0.clouds.lock().await;
if clouds.is_none() {
*clouds = Some(self.get_clouds().await?);
}
clouds.clone().unwrap()
};

Ok(WeatherInfo {
clouds,
visibility,
clouds: Some(clouds),
wind_speed: data.wind_speed,
wind_dir,
temperature: data.temp,
pressure_qnh,
pressure_qfe: data.pressure,
fog_thickness: data.fog_thickness,
fog_visibility: data.fog_visibility,
dust_density: data.dust_density,
position: pos.clone(),
})
}

pub async fn get_clouds(&self) -> Result<Clouds, Error> {
let clouds: Clouds = self.0.ipc.request("get_clouds", None::<()>).await?;

Ok(clouds)
}

pub async fn get_unit_position(&self, name: &str) -> Result<Position, Error> {
self.0
.ipc
Expand Down
Loading

0 comments on commit aa73fb1

Please sign in to comment.