Moved `shipbehavior` to crates
parent
bd8651b02a
commit
afa6bd6690
|
@ -584,6 +584,7 @@ dependencies = [
|
||||||
"galactica-content",
|
"galactica-content",
|
||||||
"galactica-physics",
|
"galactica-physics",
|
||||||
"galactica-render",
|
"galactica-render",
|
||||||
|
"galactica-shipbehavior",
|
||||||
"image",
|
"image",
|
||||||
"nalgebra",
|
"nalgebra",
|
||||||
"pollster",
|
"pollster",
|
||||||
|
@ -615,19 +616,13 @@ dependencies = [
|
||||||
name = "galactica-physics"
|
name = "galactica-physics"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
|
||||||
"cgmath",
|
"cgmath",
|
||||||
"crossbeam",
|
"crossbeam",
|
||||||
"galactica-content",
|
"galactica-content",
|
||||||
"galactica-render",
|
"galactica-render",
|
||||||
"image",
|
|
||||||
"nalgebra",
|
"nalgebra",
|
||||||
"pollster",
|
|
||||||
"rand",
|
"rand",
|
||||||
"rapier2d",
|
"rapier2d",
|
||||||
"walkdir",
|
|
||||||
"wgpu",
|
|
||||||
"winit",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -645,6 +640,15 @@ dependencies = [
|
||||||
"winit",
|
"winit",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "galactica-shipbehavior"
|
||||||
|
version = "0.0.0"
|
||||||
|
dependencies = [
|
||||||
|
"cgmath",
|
||||||
|
"galactica-content",
|
||||||
|
"galactica-physics",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "getrandom"
|
name = "getrandom"
|
||||||
version = "0.2.11"
|
version = "0.2.11"
|
||||||
|
|
|
@ -33,6 +33,7 @@ members = [
|
||||||
"crates/render",
|
"crates/render",
|
||||||
"crates/constants",
|
"crates/constants",
|
||||||
"crates/physics",
|
"crates/physics",
|
||||||
|
"crates/shipbehavior",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -42,6 +43,7 @@ galactica-content = { path = "crates/content" }
|
||||||
galactica-render = { path = "crates/render" }
|
galactica-render = { path = "crates/render" }
|
||||||
galactica-constants = { path = "crates/constants" }
|
galactica-constants = { path = "crates/constants" }
|
||||||
galactica-physics = { path = "crates/physics" }
|
galactica-physics = { path = "crates/physics" }
|
||||||
|
galactica-shipbehavior = { path = "crates/shipbehavior" }
|
||||||
|
|
||||||
# Files
|
# Files
|
||||||
image = { version = "0.24", features = ["png"] }
|
image = { version = "0.24", features = ["png"] }
|
||||||
|
|
|
@ -4,24 +4,11 @@ version = "0.0.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
# Internal crates
|
|
||||||
galactica-render = { path = "../render" }
|
galactica-render = { path = "../render" }
|
||||||
galactica-content = { path = "../content" }
|
galactica-content = { path = "../content" }
|
||||||
|
|
||||||
|
|
||||||
# Files
|
|
||||||
image = { version = "0.24", features = ["png"] }
|
|
||||||
# Graphics
|
|
||||||
winit = "0.28"
|
|
||||||
wgpu = "0.18"
|
|
||||||
# Physics
|
|
||||||
rapier2d = { version = "0.17.2" }
|
rapier2d = { version = "0.17.2" }
|
||||||
nalgebra = "0.32.3"
|
nalgebra = "0.32.3"
|
||||||
crossbeam = "0.8.3"
|
crossbeam = "0.8.3"
|
||||||
# Misc helpers
|
|
||||||
pollster = "0.3"
|
|
||||||
anyhow = "1.0"
|
|
||||||
# TODO: migrate to nalgebra
|
|
||||||
cgmath = "0.18.0"
|
cgmath = "0.18.0"
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
walkdir = "2.4.0"
|
|
||||||
|
|
|
@ -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"
|
|
@ -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<Self> {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
mod dummy;
|
||||||
|
mod player;
|
||||||
|
mod point;
|
||||||
|
|
||||||
|
pub use dummy::Dummy;
|
||||||
|
pub use player::Player;
|
||||||
|
pub use point::Point;
|
|
@ -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<Self> {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,67 +1,9 @@
|
||||||
use cgmath::{Deg, InnerSpace};
|
use cgmath::{Deg, InnerSpace};
|
||||||
|
|
||||||
use crate::content;
|
use crate::ShipBehavior;
|
||||||
|
use galactica_content as content;
|
||||||
use galactica_physics::{util, Physics, ShipHandle};
|
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<Self> {
|
|
||||||
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<Self> {
|
|
||||||
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 {
|
pub struct Point {
|
||||||
handle: ShipHandle,
|
handle: ShipHandle,
|
||||||
}
|
}
|
|
@ -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;
|
||||||
|
}
|
|
@ -3,14 +3,11 @@ use std::time::Instant;
|
||||||
use winit::event::{ElementState, MouseButton, MouseScrollDelta, TouchPhase, VirtualKeyCode};
|
use winit::event::{ElementState, MouseButton, MouseScrollDelta, TouchPhase, VirtualKeyCode};
|
||||||
|
|
||||||
use super::{camera::Camera, system::System};
|
use super::{camera::Camera, system::System};
|
||||||
use crate::{
|
use crate::{content, inputstatus::InputStatus};
|
||||||
content,
|
|
||||||
inputstatus::InputStatus,
|
|
||||||
shipbehavior::{self, ShipBehavior},
|
|
||||||
};
|
|
||||||
use galactica_constants;
|
use galactica_constants;
|
||||||
use galactica_physics::{objects::ShipOutfits, util, Physics, ShipHandle};
|
use galactica_physics::{objects::ShipOutfits, util, Physics, ShipHandle};
|
||||||
use galactica_render::{AnchoredUiPosition, ObjectSprite, UiSprite};
|
use galactica_render::{AnchoredUiPosition, ObjectSprite, UiSprite};
|
||||||
|
use galactica_shipbehavior::{behavior, ShipBehavior};
|
||||||
|
|
||||||
struct Ui {}
|
struct Ui {}
|
||||||
|
|
||||||
|
@ -120,9 +117,9 @@ impl Game {
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut shipbehaviors: Vec<Box<dyn ShipBehavior>> = Vec::new();
|
let mut shipbehaviors: Vec<Box<dyn ShipBehavior>> = Vec::new();
|
||||||
shipbehaviors.push(shipbehavior::Player::new(h1));
|
shipbehaviors.push(behavior::Player::new(h1));
|
||||||
shipbehaviors.push(shipbehavior::Dummy::new(h2));
|
shipbehaviors.push(behavior::Dummy::new(h2));
|
||||||
shipbehaviors.push(shipbehavior::Point::new(h3));
|
shipbehaviors.push(behavior::Point::new(h3));
|
||||||
|
|
||||||
Game {
|
Game {
|
||||||
last_update: Instant::now(),
|
last_update: Instant::now(),
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
mod game;
|
mod game;
|
||||||
mod inputstatus;
|
mod inputstatus;
|
||||||
mod shipbehavior;
|
|
||||||
|
|
||||||
pub use galactica_content as content;
|
pub use galactica_content as content;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue