diff --git a/Cargo.lock b/Cargo.lock index b961089..2b02ad1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -584,6 +584,7 @@ dependencies = [ "galactica-content", "galactica-physics", "galactica-render", + "galactica-shipbehavior", "image", "nalgebra", "pollster", @@ -615,19 +616,13 @@ dependencies = [ name = "galactica-physics" version = "0.0.0" dependencies = [ - "anyhow", "cgmath", "crossbeam", "galactica-content", "galactica-render", - "image", "nalgebra", - "pollster", "rand", "rapier2d", - "walkdir", - "wgpu", - "winit", ] [[package]] @@ -645,6 +640,15 @@ dependencies = [ "winit", ] +[[package]] +name = "galactica-shipbehavior" +version = "0.0.0" +dependencies = [ + "cgmath", + "galactica-content", + "galactica-physics", +] + [[package]] name = "getrandom" version = "0.2.11" diff --git a/Cargo.toml b/Cargo.toml index 501c74d..9620c13 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,6 +33,7 @@ members = [ "crates/render", "crates/constants", "crates/physics", + "crates/shipbehavior", ] @@ -42,6 +43,7 @@ galactica-content = { path = "crates/content" } galactica-render = { path = "crates/render" } galactica-constants = { path = "crates/constants" } galactica-physics = { path = "crates/physics" } +galactica-shipbehavior = { path = "crates/shipbehavior" } # Files image = { version = "0.24", features = ["png"] } diff --git a/crates/physics/Cargo.toml b/crates/physics/Cargo.toml index 88473be..b6c9c35 100644 --- a/crates/physics/Cargo.toml +++ b/crates/physics/Cargo.toml @@ -4,24 +4,11 @@ version = "0.0.0" edition = "2021" [dependencies] -# Internal crates galactica-render = { path = "../render" } galactica-content = { path = "../content" } - -# Files -image = { version = "0.24", features = ["png"] } -# Graphics -winit = "0.28" -wgpu = "0.18" -# Physics rapier2d = { version = "0.17.2" } nalgebra = "0.32.3" crossbeam = "0.8.3" -# Misc helpers -pollster = "0.3" -anyhow = "1.0" -# TODO: migrate to nalgebra cgmath = "0.18.0" rand = "0.8.5" -walkdir = "2.4.0" diff --git a/crates/shipbehavior/Cargo.toml b/crates/shipbehavior/Cargo.toml new file mode 100644 index 0000000..815e375 --- /dev/null +++ b/crates/shipbehavior/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "galactica-shipbehavior" +version = "0.0.0" +edition = "2021" + +[dependencies] +galactica-content = { path = "../content" } +galactica-physics = { path = "../physics" } +cgmath = "0.18.0" diff --git a/crates/shipbehavior/src/behavior/dummy.rs b/crates/shipbehavior/src/behavior/dummy.rs new file mode 100644 index 0000000..59db192 --- /dev/null +++ b/crates/shipbehavior/src/behavior/dummy.rs @@ -0,0 +1,20 @@ +use crate::ShipBehavior; +use galactica_content as content; +use galactica_physics::{Physics, ShipHandle}; + +pub struct Dummy { + _handle: ShipHandle, +} + +impl Dummy { + pub fn new(handle: ShipHandle) -> Box { + Box::new(Self { _handle: handle }) + } +} + +impl ShipBehavior for Dummy { + fn update_controls(&mut self, _physics: &mut Physics, _content: &content::Content) {} + fn get_handle(&self) -> ShipHandle { + return self._handle; + } +} diff --git a/crates/shipbehavior/src/behavior/mod.rs b/crates/shipbehavior/src/behavior/mod.rs new file mode 100644 index 0000000..96cf301 --- /dev/null +++ b/crates/shipbehavior/src/behavior/mod.rs @@ -0,0 +1,7 @@ +mod dummy; +mod player; +mod point; + +pub use dummy::Dummy; +pub use player::Player; +pub use point::Point; diff --git a/crates/shipbehavior/src/behavior/player.rs b/crates/shipbehavior/src/behavior/player.rs new file mode 100644 index 0000000..b015349 --- /dev/null +++ b/crates/shipbehavior/src/behavior/player.rs @@ -0,0 +1,37 @@ +use crate::ShipBehavior; +use galactica_content as content; +use galactica_physics::{Physics, ShipHandle}; + +pub struct Player { + handle: ShipHandle, + key_left: bool, + key_right: bool, + key_guns: bool, + key_thrust: bool, +} + +impl Player { + pub fn new(handle: ShipHandle) -> Box { + Box::new(Self { + handle, + key_left: false, + key_right: false, + key_guns: false, + key_thrust: false, + }) + } +} + +impl ShipBehavior for Player { + fn update_controls(&mut self, physics: &mut Physics, _content: &content::Content) { + let s = physics.get_ship_mut(&self.handle).unwrap(); + s.controls.left = self.key_left; + s.controls.right = self.key_right; + s.controls.guns = self.key_guns; + s.controls.thrust = self.key_thrust; + } + + fn get_handle(&self) -> ShipHandle { + return self.handle; + } +} diff --git a/src/shipbehavior/mod.rs b/crates/shipbehavior/src/behavior/point.rs similarity index 61% rename from src/shipbehavior/mod.rs rename to crates/shipbehavior/src/behavior/point.rs index c42d01a..31f58df 100644 --- a/src/shipbehavior/mod.rs +++ b/crates/shipbehavior/src/behavior/point.rs @@ -1,67 +1,9 @@ use cgmath::{Deg, InnerSpace}; -use crate::content; +use crate::ShipBehavior; +use galactica_content as content; use galactica_physics::{util, Physics, ShipHandle}; -pub trait ShipBehavior -where - Self: Send, -{ - fn update_controls(&mut self, physics: &mut Physics, content: &content::Content); - fn get_handle(&self) -> ShipHandle; -} - -pub struct Dummy { - _handle: ShipHandle, -} - -impl Dummy { - pub fn new(handle: ShipHandle) -> Box { - Box::new(Self { _handle: handle }) - } -} - -impl ShipBehavior for Dummy { - fn update_controls(&mut self, _physics: &mut Physics, _content: &content::Content) {} - fn get_handle(&self) -> ShipHandle { - return self._handle; - } -} - -pub struct Player { - handle: ShipHandle, - key_left: bool, - key_right: bool, - key_guns: bool, - key_thrust: bool, -} - -impl Player { - pub fn new(handle: ShipHandle) -> Box { - Box::new(Self { - handle, - key_left: false, - key_right: false, - key_guns: false, - key_thrust: false, - }) - } -} - -impl ShipBehavior for Player { - fn update_controls(&mut self, physics: &mut Physics, _content: &content::Content) { - let s = physics.get_ship_mut(&self.handle).unwrap(); - s.controls.left = self.key_left; - s.controls.right = self.key_right; - s.controls.guns = self.key_guns; - s.controls.thrust = self.key_thrust; - } - - fn get_handle(&self) -> ShipHandle { - return self.handle; - } -} - pub struct Point { handle: ShipHandle, } diff --git a/crates/shipbehavior/src/lib.rs b/crates/shipbehavior/src/lib.rs new file mode 100644 index 0000000..8c1de42 --- /dev/null +++ b/crates/shipbehavior/src/lib.rs @@ -0,0 +1,12 @@ +pub mod behavior; + +use galactica_content as content; +use galactica_physics::{Physics, ShipHandle}; + +pub trait ShipBehavior +where + Self: Send, +{ + fn update_controls(&mut self, physics: &mut Physics, content: &content::Content); + fn get_handle(&self) -> ShipHandle; +} diff --git a/src/game/game.rs b/src/game/game.rs index 0186055..39f4b6a 100644 --- a/src/game/game.rs +++ b/src/game/game.rs @@ -3,14 +3,11 @@ use std::time::Instant; use winit::event::{ElementState, MouseButton, MouseScrollDelta, TouchPhase, VirtualKeyCode}; use super::{camera::Camera, system::System}; -use crate::{ - content, - inputstatus::InputStatus, - shipbehavior::{self, ShipBehavior}, -}; +use crate::{content, inputstatus::InputStatus}; use galactica_constants; use galactica_physics::{objects::ShipOutfits, util, Physics, ShipHandle}; use galactica_render::{AnchoredUiPosition, ObjectSprite, UiSprite}; +use galactica_shipbehavior::{behavior, ShipBehavior}; struct Ui {} @@ -120,9 +117,9 @@ impl Game { ); let mut shipbehaviors: Vec> = Vec::new(); - shipbehaviors.push(shipbehavior::Player::new(h1)); - shipbehaviors.push(shipbehavior::Dummy::new(h2)); - shipbehaviors.push(shipbehavior::Point::new(h3)); + shipbehaviors.push(behavior::Player::new(h1)); + shipbehaviors.push(behavior::Dummy::new(h2)); + shipbehaviors.push(behavior::Point::new(h3)); Game { last_update: Instant::now(), diff --git a/src/main.rs b/src/main.rs index 159eaeb..c427b96 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,5 @@ mod game; mod inputstatus; -mod shipbehavior; pub use galactica_content as content;