summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bin/client.rs2
-rw-r--r--src/client/navigation.rs2
-rw-r--r--src/lib.rs2
-rw-r--r--src/mass.rs6
-rw-r--r--src/module.rs172
-rw-r--r--src/modules/dashboard.rs8
-rw-r--r--src/modules/engines.rs70
-rw-r--r--src/modules/mining.rs23
-rw-r--r--src/modules/mod.rs5
-rw-r--r--src/modules/navigation.rs64
-rw-r--r--src/modules/types.rs7
-rw-r--r--src/server/connection.rs2
-rw-r--r--src/server/engines.rs2
-rw-r--r--src/server/mining.rs3
14 files changed, 189 insertions, 179 deletions
diff --git a/src/bin/client.rs b/src/bin/client.rs
index a26f68a..e5dec5a 100644
--- a/src/bin/client.rs
+++ b/src/bin/client.rs
@@ -6,9 +6,9 @@ use std::io::BufReader;
use std::io::prelude::*;
use std::net::TcpStream;
-use space::module::ModuleType;
use space::client::mining::client_mining;
use space::client::engines::client_engines;
+use space::modules::types::ModuleType;
use space::client::dashboard::client_dashboard;
use space::client::navigation::client_navigation;
diff --git a/src/client/navigation.rs b/src/client/navigation.rs
index 2063de4..9bc13f9 100644
--- a/src/client/navigation.rs
+++ b/src/client/navigation.rs
@@ -10,7 +10,7 @@ use self::termion::raw::IntoRawMode;
use math::distance;
use mass::{Mass, MassType};
-use module::Navigation;
+use modules::navigation::Navigation;
pub fn client_navigation(name : String, mut stream : TcpStream, mut buff_r : BufReader<TcpStream>){
let stdout = stdout();
diff --git a/src/lib.rs b/src/lib.rs
index 608a1ee..0c917f7 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -4,7 +4,7 @@ extern crate serde_derive;
pub mod mass;
pub mod item;
pub mod math;
-pub mod module;
pub mod client;
pub mod server;
+pub mod modules;
pub mod storage;
diff --git a/src/mass.rs b/src/mass.rs
index 3a0e10e..85651d4 100644
--- a/src/mass.rs
+++ b/src/mass.rs
@@ -5,7 +5,11 @@ use self::rand::distributions::Sample;
use item::Item;
use storage::Storage;
-use module::{Mining, Navigation, Dashboard, Engines, ModuleType};
+use modules::mining::Mining;
+use modules::engines::Engines;
+use modules::types::ModuleType;
+use modules::dashboard::Dashboard;
+use modules::navigation::Navigation;
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Mass {
diff --git a/src/module.rs b/src/module.rs
deleted file mode 100644
index 333ba05..0000000
--- a/src/module.rs
+++ /dev/null
@@ -1,172 +0,0 @@
-use std::time::SystemTime;
-use std::collections::HashMap;
-
-use mass::Mass;
-use math::distance;
-
-#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
-pub enum ModuleType {
- Navigation,
- Mining,
- Engines,
- Dashboard,
-}
-
-#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
-pub enum NavigationStatus {
- None,
- Targeting,
- Targeted,
-}
-
-#[derive(Serialize, Deserialize, Debug, Clone)]
-pub struct Navigation {
- pub range : f64,
- pub status : NavigationStatus,
- pub target_name : Option<String>,
- time : u64,
- start : Option<SystemTime>,
-}
-
-#[derive(Serialize, Deserialize, Debug, Clone)]
-pub struct Mining {
- pub range : f64,
- pub status : bool,
- time : u64,
- start : Option<SystemTime>,
-}
-
-#[derive(Serialize, Deserialize, Debug, Clone)]
-pub struct Engines {
- acceleration : (f64, f64, f64),
-}
-
-#[derive(Serialize, Deserialize, Debug, Clone)]
-pub struct Dashboard {}
-
-impl Mining {
- pub fn new() -> Mining {
- Mining {
- range : 10.0,
- status : false,
- time : 1,
- start : None,
- }
- }
-
- pub fn toggle(&self) {
- }
-}
-
-impl Navigation {
- pub fn new() -> Navigation {
- Navigation {
- target_name : None,
- range : 100.0,
- status : NavigationStatus::None,
- time : 3,
- start : None,
- }
- }
-
- pub fn process(&mut self) {
- match self.start.clone() {
- Some(timer) => {
- if timer.elapsed().unwrap().as_secs() > self.time {
- self.status = NavigationStatus::Targeted;
- self.start = None;
- }
- }
- _ => (),
- }
- }
-
- pub fn give_target(&mut self, target_name : String) {
- self.start = Some(SystemTime::now());
- self.status = NavigationStatus::Targeting;
- self.target_name = Some(target_name);
- }
-
- pub fn verify_target(&mut self, ship_position : (f64, f64, f64), masses : &HashMap<String, Mass>) {
- match self.target_name.clone() {
- Some(name) => {
- let target = masses.get(&name).unwrap();
- if distance(target.position, ship_position) > self.range {
- self.target_name = None;
- self.status = NavigationStatus::None;
- }
- }
- _ => (),
- }
- }
-}
-
-impl Dashboard {
- pub fn new() -> Dashboard {
- Dashboard {}
- }
-}
-
-impl Engines {
- pub fn new() -> Engines {
- Engines {
- acceleration : (0.0, 0.0, 0.0)
- }
- }
-
- pub fn recv_acceleration(&mut self) -> (f64, f64, f64) {
- let acceleration = self.acceleration;
- self.acceleration = (0.0, 0.0, 0.0);
- acceleration
- }
-
- pub fn give_client_data(&mut self, ship : &Mass, target : Option<&Mass>, data : String) {
- let mut acceleration = (0.0, 0.0, 0.0);
- match data.as_bytes() {
- b"5\n" => acceleration.0 += 0.1,
- b"0\n" => acceleration.0 -= 0.1,
- b"8\n" => acceleration.1 += 0.1,
- b"2\n" => acceleration.1 -= 0.1,
- b"4\n" => acceleration.2 += 0.1,
- b"6\n" => acceleration.2 -= 0.1,
- b"+\n" => {
- let m_v = ship.velocity;
- acceleration = (m_v.0 * 0.05,
- m_v.1 * 0.05,
- m_v.2 * 0.05);
- },
- b"-\n" => {
- let m_v = ship.velocity;
- acceleration = (-1.0 * m_v.0 * 0.05,
- -1.0 * m_v.1 * 0.05,
- -1.0 * m_v.2 * 0.05);
- },
- b"c\n" => {
- match target {
- Some(target) => {
- let d_v = target.velocity;
- let m_v = ship.velocity;
- acceleration = (d_v.0 - m_v.0,
- d_v.1 - m_v.1,
- d_v.2 - m_v.2);
- },
- None => (),
- }
- },
- b"t\n" => {
- match target {
- Some(target) => {
- let d_p = target.position;
- let m_p = ship.position;
- acceleration = ((d_p.0 - m_p.0) * 0.01,
- (d_p.1 - m_p.1) * 0.01,
- (d_p.2 - m_p.2) * 0.01);
- },
- None => (),
- }
- },
- _ => (),
- }
- self.acceleration = acceleration;
- }
-}
diff --git a/src/modules/dashboard.rs b/src/modules/dashboard.rs
new file mode 100644
index 0000000..e7f739b
--- /dev/null
+++ b/src/modules/dashboard.rs
@@ -0,0 +1,8 @@
+#[derive(Serialize, Deserialize, Debug, Clone)]
+pub struct Dashboard {}
+
+impl Dashboard {
+ pub fn new() -> Dashboard {
+ Dashboard {}
+ }
+}
diff --git a/src/modules/engines.rs b/src/modules/engines.rs
new file mode 100644
index 0000000..10e4c85
--- /dev/null
+++ b/src/modules/engines.rs
@@ -0,0 +1,70 @@
+use mass::Mass;
+
+#[derive(Serialize, Deserialize, Debug, Clone)]
+pub struct Engines {
+ acceleration : (f64, f64, f64),
+}
+
+impl Engines {
+ pub fn new() -> Engines {
+ Engines {
+ acceleration : (0.0, 0.0, 0.0)
+ }
+ }
+
+ pub fn recv_acceleration(&mut self) -> (f64, f64, f64) {
+ let acceleration = self.acceleration;
+ self.acceleration = (0.0, 0.0, 0.0);
+ acceleration
+ }
+
+ pub fn give_client_data(&mut self, ship : &Mass, target : Option<&Mass>, data : String) {
+ let mut acceleration = (0.0, 0.0, 0.0);
+ match data.as_bytes() {
+ b"5\n" => acceleration.0 += 0.1,
+ b"0\n" => acceleration.0 -= 0.1,
+ b"8\n" => acceleration.1 += 0.1,
+ b"2\n" => acceleration.1 -= 0.1,
+ b"4\n" => acceleration.2 += 0.1,
+ b"6\n" => acceleration.2 -= 0.1,
+ b"+\n" => {
+ let m_v = ship.velocity;
+ acceleration = (m_v.0 * 0.05,
+ m_v.1 * 0.05,
+ m_v.2 * 0.05);
+ },
+ b"-\n" => {
+ let m_v = ship.velocity;
+ acceleration = (-1.0 * m_v.0 * 0.05,
+ -1.0 * m_v.1 * 0.05,
+ -1.0 * m_v.2 * 0.05);
+ },
+ b"c\n" => {
+ match target {
+ Some(target) => {
+ let d_v = target.velocity;
+ let m_v = ship.velocity;
+ acceleration = (d_v.0 - m_v.0,
+ d_v.1 - m_v.1,
+ d_v.2 - m_v.2);
+ },
+ None => (),
+ }
+ },
+ b"t\n" => {
+ match target {
+ Some(target) => {
+ let d_p = target.position;
+ let m_p = ship.position;
+ acceleration = ((d_p.0 - m_p.0) * 0.01,
+ (d_p.1 - m_p.1) * 0.01,
+ (d_p.2 - m_p.2) * 0.01);
+ },
+ None => (),
+ }
+ },
+ _ => (),
+ }
+ self.acceleration = acceleration;
+ }
+}
diff --git a/src/modules/mining.rs b/src/modules/mining.rs
new file mode 100644
index 0000000..e22918f
--- /dev/null
+++ b/src/modules/mining.rs
@@ -0,0 +1,23 @@
+use std::time::SystemTime;
+
+#[derive(Serialize, Deserialize, Debug, Clone)]
+pub struct Mining {
+ pub range : f64,
+ pub status : bool,
+ time : u64,
+ start : Option<SystemTime>,
+}
+
+
+impl Mining {
+ pub fn new() -> Mining {
+ Mining {
+ range : 10.0,
+ status : false,
+ time : 1,
+ start : None,
+ }
+ }
+
+ pub fn toggle(&self) {}
+}
diff --git a/src/modules/mod.rs b/src/modules/mod.rs
new file mode 100644
index 0000000..0c19156
--- /dev/null
+++ b/src/modules/mod.rs
@@ -0,0 +1,5 @@
+pub mod mining;
+pub mod engines;
+pub mod dashboard;
+pub mod navigation;
+pub mod types;
diff --git a/src/modules/navigation.rs b/src/modules/navigation.rs
new file mode 100644
index 0000000..179a766
--- /dev/null
+++ b/src/modules/navigation.rs
@@ -0,0 +1,64 @@
+use std::time::SystemTime;
+use std::collections::HashMap;
+
+use mass::Mass;
+use math::distance;
+
+#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
+pub enum NavigationStatus {
+ None,
+ Targeting,
+ Targeted,
+}
+
+#[derive(Serialize, Deserialize, Debug, Clone)]
+pub struct Navigation {
+ pub range : f64,
+ pub status : NavigationStatus,
+ pub target_name : Option<String>,
+ time : u64,
+ start : Option<SystemTime>,
+}
+
+impl Navigation {
+ pub fn new() -> Navigation {
+ Navigation {
+ target_name : None,
+ range : 100.0,
+ status : NavigationStatus::None,
+ time : 3,
+ start : None,
+ }
+ }
+
+ pub fn process(&mut self) {
+ match self.start.clone() {
+ Some(timer) => {
+ if timer.elapsed().unwrap().as_secs() > self.time {
+ self.status = NavigationStatus::Targeted;
+ self.start = None;
+ }
+ }
+ _ => (),
+ }
+ }
+
+ pub fn give_target(&mut self, target_name : String) {
+ self.start = Some(SystemTime::now());
+ self.status = NavigationStatus::Targeting;
+ self.target_name = Some(target_name);
+ }
+
+ pub fn verify_target(&mut self, ship_position : (f64, f64, f64), masses : &HashMap<String, Mass>) {
+ match self.target_name.clone() {
+ Some(name) => {
+ let target = masses.get(&name).unwrap();
+ if distance(target.position, ship_position) > self.range {
+ self.target_name = None;
+ self.status = NavigationStatus::None;
+ }
+ }
+ _ => (),
+ }
+ }
+}
diff --git a/src/modules/types.rs b/src/modules/types.rs
new file mode 100644
index 0000000..1af99d6
--- /dev/null
+++ b/src/modules/types.rs
@@ -0,0 +1,7 @@
+#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
+pub enum ModuleType {
+ Navigation,
+ Mining,
+ Engines,
+ Dashboard,
+}
diff --git a/src/server/connection.rs b/src/server/connection.rs
index a1b808d..fd76661 100644
--- a/src/server/connection.rs
+++ b/src/server/connection.rs
@@ -6,7 +6,7 @@ use std::net::TcpStream;
use std::collections::HashMap;
use mass::Mass;
-use module::ModuleType;
+use modules::types::ModuleType;
pub struct ServerConnection {
pub name : String,
diff --git a/src/server/engines.rs b/src/server/engines.rs
index fcce76a..17391e6 100644
--- a/src/server/engines.rs
+++ b/src/server/engines.rs
@@ -5,7 +5,7 @@ use std::io::BufRead;
use std::collections::HashMap;
use mass::{Mass, MassType};
-use module::NavigationStatus;
+use modules::navigation::NavigationStatus;
use server::connection::ServerConnection;
impl ServerConnection {
diff --git a/src/server/mining.rs b/src/server/mining.rs
index c02937a..c5c0ce7 100644
--- a/src/server/mining.rs
+++ b/src/server/mining.rs
@@ -6,8 +6,9 @@ use std::collections::HashMap;
use math::distance;
use mass::{Mass, MassType};
+use modules::mining::Mining;
+use modules::navigation::Navigation;
use server::connection::ServerConnection;
-use module::{Navigation, Mining};
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct MiningData {