Compare commits
No commits in common. "025a1df69e75d2ec0fa3cd1e76d212858b1c1824" and "3b7ac5bc9a8349d3be5c70efe7ebb3baae89b337" have entirely different histories.
025a1df69e
...
3b7ac5bc9a
|
@ -42,7 +42,6 @@ fn main() -> Result<()> {
|
||||||
let mut gpu = pollster::block_on(galactica_render::GPUState::new(window, &content))?;
|
let mut gpu = pollster::block_on(galactica_render::GPUState::new(window, &content))?;
|
||||||
gpu.init(&content);
|
gpu.init(&content);
|
||||||
|
|
||||||
// TODO: don't clone content
|
|
||||||
let mut game = game::Game::new(content.clone());
|
let mut game = game::Game::new(content.clone());
|
||||||
let p = game.make_player();
|
let p = game.make_player();
|
||||||
|
|
||||||
|
@ -97,16 +96,6 @@ fn main() -> Result<()> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ShipState::UnLanding { .. } => {
|
|
||||||
let pos =
|
|
||||||
o.data.get_state().unlanding_position(&content).unwrap();
|
|
||||||
Some(Point2 { x: pos.x, y: pos.y })
|
|
||||||
}
|
|
||||||
ShipState::Landing { .. } => {
|
|
||||||
let pos =
|
|
||||||
o.data.get_state().landing_position(&content).unwrap();
|
|
||||||
Some(Point2 { x: pos.x, y: pos.y })
|
|
||||||
}
|
|
||||||
ShipState::Landed { target } => {
|
ShipState::Landed { target } => {
|
||||||
let b = content.get_system_object(*target);
|
let b = content.get_system_object(*target);
|
||||||
Some(Point2 {
|
Some(Point2 {
|
||||||
|
@ -114,8 +103,6 @@ fn main() -> Result<()> {
|
||||||
y: b.pos.y,
|
y: b.pos.y,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
ShipState::Dead => None,
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
//! GPUState routines for drawing items in a systemsim
|
//! GPUState routines for drawing items in a systemsim
|
||||||
|
|
||||||
use bytemuck;
|
use bytemuck;
|
||||||
use cgmath::{EuclideanSpace, InnerSpace, Point2, Point3, Rad, Vector2};
|
use cgmath::{EuclideanSpace, InnerSpace, Point2, Vector2};
|
||||||
use galactica_system::{data::ShipState, phys::util};
|
use galactica_system::{data::ShipState, phys::util};
|
||||||
use galactica_util::constants::OBJECT_SPRITE_INSTANCE_LIMIT;
|
use galactica_util::constants::OBJECT_SPRITE_INSTANCE_LIMIT;
|
||||||
|
|
||||||
|
@ -19,72 +19,28 @@ impl GPUState {
|
||||||
screen_clip: (Point2<f32>, Point2<f32>),
|
screen_clip: (Point2<f32>, Point2<f32>),
|
||||||
) {
|
) {
|
||||||
for ship in state.systemsim.iter_ships() {
|
for ship in state.systemsim.iter_ships() {
|
||||||
// TODO: move collapse sequence here?
|
|
||||||
|
|
||||||
let ship_pos;
|
|
||||||
let ship_ang;
|
|
||||||
let ship_cnt;
|
|
||||||
match ship.data.get_state() {
|
match ship.data.get_state() {
|
||||||
ShipState::Dead | ShipState::Landed { .. } => continue,
|
ShipState::Collapsing { .. } | ShipState::Flying => {}
|
||||||
|
ShipState::Landed { .. } => continue,
|
||||||
ShipState::Collapsing { .. } | ShipState::Flying => {
|
|
||||||
let r = state.systemsim.get_rigid_body(ship.rigid_body).unwrap();
|
|
||||||
let pos = util::rigidbody_position(&r);
|
|
||||||
ship_pos = Point3 {
|
|
||||||
x: pos.x,
|
|
||||||
y: pos.y,
|
|
||||||
z: 1.0,
|
|
||||||
};
|
|
||||||
let ship_rot = util::rigidbody_rotation(r);
|
|
||||||
ship_ang = -ship_rot.angle(Vector2 { x: 0.0, y: 1.0 }); // TODO: inconsistent angles. Fix!
|
|
||||||
ship_cnt = state.ct.get_ship(ship.data.get_content());
|
|
||||||
}
|
|
||||||
ShipState::Landing {
|
|
||||||
from_position,
|
|
||||||
from_angle,
|
|
||||||
target,
|
|
||||||
total: _total,
|
|
||||||
elapsed,
|
|
||||||
} => {
|
|
||||||
let target = state.ct.get_system_object(*target);
|
|
||||||
|
|
||||||
let diff = Point2 {
|
|
||||||
x: target.pos.x,
|
|
||||||
y: target.pos.y,
|
|
||||||
} - from_position;
|
|
||||||
|
|
||||||
ship_pos = ship.data.get_state().landing_position(state.ct).unwrap();
|
|
||||||
|
|
||||||
let target_angle = -diff.angle(Vector2 { x: 0.0, y: 1.0 });
|
|
||||||
|
|
||||||
ship_ang = from_angle + ((target_angle - from_angle) * 1f32.min(elapsed / 1.0));
|
|
||||||
ship_cnt = state.ct.get_ship(ship.data.get_content());
|
|
||||||
}
|
|
||||||
|
|
||||||
ShipState::UnLanding {
|
|
||||||
to_angle, elapsed, ..
|
|
||||||
} => {
|
|
||||||
ship_pos = ship.data.get_state().unlanding_position(state.ct).unwrap();
|
|
||||||
ship_ang = Rad(0.0) + ((to_angle - Rad(0.0)) * 1f32.min(elapsed / 1.0));
|
|
||||||
ship_cnt = state.ct.get_ship(ship.data.get_content());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let r = state.systemsim.get_rigid_body(ship.rigid_body).unwrap();
|
||||||
|
let ship_pos = util::rigidbody_position(&r);
|
||||||
|
let ship_rot = util::rigidbody_rotation(r);
|
||||||
|
let ship_ang = -ship_rot.angle(Vector2 { x: 0.0, y: 1.0 }); // TODO: inconsistent angles. Fix!
|
||||||
|
let ship_cnt = state.ct.get_ship(ship.data.get_content());
|
||||||
|
|
||||||
// Position adjusted for parallax
|
// Position adjusted for parallax
|
||||||
// TODO: adjust parallax for zoom?
|
// TODO: adjust parallax for zoom?
|
||||||
// 1.0 is z-coordinate, which is constant for ships
|
// 1.0 is z-coordinate, which is constant for ships
|
||||||
let pos: Point2<f32> = (Point2 {
|
let pos: Point2<f32> = (ship_pos - state.camera_pos.to_vec()) / 1.0;
|
||||||
x: ship_pos.x,
|
|
||||||
y: ship_pos.y,
|
|
||||||
} - state.camera_pos.to_vec())
|
|
||||||
/ ship_pos.z;
|
|
||||||
|
|
||||||
// Game dimensions of this sprite post-scale.
|
// Game dimensions of this sprite post-scale.
|
||||||
// Post-scale width or height, whichever is larger.
|
// Post-scale width or height, whichever is larger.
|
||||||
// This is in game units.
|
// This is in game units.
|
||||||
//
|
//
|
||||||
// We take the maximum to account for rotated sprites.
|
// We take the maximum to account for rotated sprites.
|
||||||
let m = (ship_cnt.size / ship_pos.z) * ship_cnt.sprite.aspect.max(1.0);
|
let m = (ship_cnt.size / 1.0) * ship_cnt.sprite.aspect.max(1.0);
|
||||||
|
|
||||||
// Don't draw sprites that are off the screen
|
// Don't draw sprites that are off the screen
|
||||||
if pos.x < screen_clip.0.x - m
|
if pos.x < screen_clip.0.x - m
|
||||||
|
@ -103,7 +59,7 @@ impl GPUState {
|
||||||
bytemuck::cast_slice(&[ObjectData {
|
bytemuck::cast_slice(&[ObjectData {
|
||||||
xpos: ship_pos.x,
|
xpos: ship_pos.x,
|
||||||
ypos: ship_pos.y,
|
ypos: ship_pos.y,
|
||||||
zpos: ship_pos.z,
|
zpos: 1.0,
|
||||||
angle: ship_ang.0,
|
angle: ship_ang.0,
|
||||||
size: ship_cnt.size,
|
size: ship_cnt.size,
|
||||||
parent: 0,
|
parent: 0,
|
||||||
|
@ -130,13 +86,7 @@ impl GPUState {
|
||||||
self.state.vertex_buffers.object_counter += 1;
|
self.state.vertex_buffers.object_counter += 1;
|
||||||
|
|
||||||
let flare = ship.data.get_outfits().get_flare_sprite(state.ct);
|
let flare = ship.data.get_outfits().get_flare_sprite(state.ct);
|
||||||
if {
|
if ship.get_controls().thrust && flare.is_some() && ship.data.get_state().is_flying() {
|
||||||
let is_flying = match ship.data.get_state() {
|
|
||||||
ShipState::Flying => true,
|
|
||||||
_ => false,
|
|
||||||
};
|
|
||||||
ship.get_controls().thrust && flare.is_some() && is_flying
|
|
||||||
} {
|
|
||||||
for engine_point in &ship_cnt.engines {
|
for engine_point in &ship_cnt.engines {
|
||||||
self.state.queue.write_buffer(
|
self.state.queue.write_buffer(
|
||||||
&self.state.global_uniform.object_buffer,
|
&self.state.global_uniform.object_buffer,
|
||||||
|
|
|
@ -39,26 +39,6 @@ impl Radar {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
match player_ship.data.get_state() {
|
match player_ship.data.get_state() {
|
||||||
ShipState::Dead => {}
|
|
||||||
|
|
||||||
ShipState::Landing { .. } => {
|
|
||||||
let pos = player_ship
|
|
||||||
.data
|
|
||||||
.get_state()
|
|
||||||
.landing_position(&input.ct)
|
|
||||||
.unwrap();
|
|
||||||
self.last_player_position = Point2 { x: pos.x, y: pos.y }
|
|
||||||
}
|
|
||||||
|
|
||||||
ShipState::UnLanding { .. } => {
|
|
||||||
let pos = player_ship
|
|
||||||
.data
|
|
||||||
.get_state()
|
|
||||||
.unlanding_position(&input.ct)
|
|
||||||
.unwrap();
|
|
||||||
self.last_player_position = Point2 { x: pos.x, y: pos.y }
|
|
||||||
}
|
|
||||||
|
|
||||||
ShipState::Landed { target } => {
|
ShipState::Landed { target } => {
|
||||||
let landed_body = input.ct.get_system_object(*target);
|
let landed_body = input.ct.get_system_object(*target);
|
||||||
self.last_player_position = Point2 {
|
self.last_player_position = Point2 {
|
||||||
|
@ -153,14 +133,10 @@ impl Radar {
|
||||||
// This will be None if this ship is dead.
|
// This will be None if this ship is dead.
|
||||||
// Stays around while the physics system runs a collapse sequence
|
// Stays around while the physics system runs a collapse sequence
|
||||||
let color = match s.data.get_state() {
|
let color = match s.data.get_state() {
|
||||||
ShipState::Dead | ShipState::Landed { .. } => {
|
ShipState::Landed { .. } => {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
ShipState::Collapsing { .. } => {
|
||||||
// TODO: different color for landing?
|
|
||||||
ShipState::UnLanding { .. }
|
|
||||||
| ShipState::Landing { .. }
|
|
||||||
| ShipState::Collapsing { .. } => {
|
|
||||||
// TODO: configurable
|
// TODO: configurable
|
||||||
[0.2, 0.2, 0.2, 1.0]
|
[0.2, 0.2, 0.2, 1.0]
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,20 +37,10 @@ impl Status {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
match player_ship.data.get_state() {
|
match player_ship.data.get_state() {
|
||||||
ShipState::Dead => {
|
ShipState::Landed { .. } | ShipState::Collapsing { .. } | ShipState::Flying => {
|
||||||
current_shields = 0.0;
|
|
||||||
current_hull = 0.0;
|
|
||||||
max_shields = player_ship.data.get_outfits().get_shield_strength();
|
max_shields = player_ship.data.get_outfits().get_shield_strength();
|
||||||
max_hull = input.ct.get_ship(player_ship.data.get_content()).hull;
|
|
||||||
}
|
|
||||||
ShipState::UnLanding { .. }
|
|
||||||
| ShipState::Landing { .. }
|
|
||||||
| ShipState::Landed { .. }
|
|
||||||
| ShipState::Collapsing { .. }
|
|
||||||
| ShipState::Flying => {
|
|
||||||
current_shields = player_ship.data.get_shields();
|
current_shields = player_ship.data.get_shields();
|
||||||
current_hull = player_ship.data.get_hull();
|
current_hull = player_ship.data.get_hull();
|
||||||
max_shields = player_ship.data.get_outfits().get_shield_strength();
|
|
||||||
max_hull = input.ct.get_ship(player_ship.data.get_content()).hull;
|
max_hull = input.ct.get_ship(player_ship.data.get_content()).hull;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use std::{collections::HashMap, time::Instant};
|
use std::{collections::HashMap, time::Instant};
|
||||||
|
|
||||||
use super::{OutfitSet, ShipPersonality};
|
use super::{OutfitSet, ShipPersonality};
|
||||||
use cgmath::{InnerSpace, Point2, Point3, Rad};
|
|
||||||
use galactica_content::{Content, FactionHandle, GunPoint, Outfit, ShipHandle, SystemObjectHandle};
|
use galactica_content::{Content, FactionHandle, GunPoint, Outfit, ShipHandle, SystemObjectHandle};
|
||||||
use rand::{rngs::ThreadRng, Rng};
|
use rand::{rngs::ThreadRng, Rng};
|
||||||
|
|
||||||
|
@ -11,9 +10,6 @@ use rand::{rngs::ThreadRng, Rng};
|
||||||
/// sequence fully plays out.
|
/// sequence fully plays out.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum ShipState {
|
pub enum ShipState {
|
||||||
/// This ship is dead, and should be removed from the game.
|
|
||||||
Dead,
|
|
||||||
|
|
||||||
/// This ship is alive and well in open space
|
/// This ship is alive and well in open space
|
||||||
Flying, // TODO: system, position (also in collapse)?
|
Flying, // TODO: system, position (also in collapse)?
|
||||||
|
|
||||||
|
@ -31,47 +27,41 @@ pub enum ShipState {
|
||||||
/// The planet this ship is landed on
|
/// The planet this ship is landed on
|
||||||
target: SystemObjectHandle,
|
target: SystemObjectHandle,
|
||||||
},
|
},
|
||||||
|
|
||||||
/// This ship is landing on a planet
|
|
||||||
/// (playing the animation)
|
|
||||||
Landing {
|
|
||||||
/// The point, in world coordinates, where we started
|
|
||||||
from_position: Point2<f32>,
|
|
||||||
|
|
||||||
/// The ship's angle when we started landing
|
|
||||||
from_angle: Rad<f32>,
|
|
||||||
|
|
||||||
/// The planet we're landing on
|
|
||||||
target: SystemObjectHandle,
|
|
||||||
|
|
||||||
/// The total amount of time, in seconds, we will spend landing
|
|
||||||
total: f32,
|
|
||||||
|
|
||||||
/// The amount of time we've already spent playing this landing sequence
|
|
||||||
elapsed: f32,
|
|
||||||
},
|
|
||||||
|
|
||||||
/// This ship is taking off from a planet
|
|
||||||
/// (playing the animation)
|
|
||||||
UnLanding {
|
|
||||||
/// The point, in world coordinates, to which we're going
|
|
||||||
to_position: Point2<f32>,
|
|
||||||
|
|
||||||
/// The angle we'll be at when we arrive
|
|
||||||
to_angle: Rad<f32>,
|
|
||||||
|
|
||||||
/// The planet we're taking off from
|
|
||||||
from: SystemObjectHandle,
|
|
||||||
|
|
||||||
/// The total amount of time, in seconds, we will spend taking off
|
|
||||||
total: f32,
|
|
||||||
|
|
||||||
/// The amount of time we've already spent playing this unlanding sequence
|
|
||||||
elapsed: f32,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ShipState {
|
impl ShipState {
|
||||||
|
/// Is this ship playing its collapse sequence?
|
||||||
|
pub fn is_collapsing(&self) -> bool {
|
||||||
|
match self {
|
||||||
|
Self::Collapsing { .. } => true,
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Is this ship flying in open space?
|
||||||
|
pub fn is_flying(&self) -> bool {
|
||||||
|
match self {
|
||||||
|
Self::Flying => true,
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Is this ship landed on a planet?
|
||||||
|
pub fn is_landed(&self) -> bool {
|
||||||
|
match self {
|
||||||
|
Self::Landed { .. } => true,
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// True if this ship has been destroyed and has finished it's collapse sequence.
|
||||||
|
/// Ships are deleted once this is true.
|
||||||
|
pub fn should_be_removed(&self) -> bool {
|
||||||
|
match self {
|
||||||
|
Self::Collapsing { elapsed, total } => elapsed >= total,
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// What planet is this ship landed on?
|
/// What planet is this ship landed on?
|
||||||
pub fn landed_on(&self) -> Option<SystemObjectHandle> {
|
pub fn landed_on(&self) -> Option<SystemObjectHandle> {
|
||||||
match self {
|
match self {
|
||||||
|
@ -91,86 +81,6 @@ impl ShipState {
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Compute position of this ship's sprite during its landing sequence
|
|
||||||
pub fn landing_position(&self, ct: &Content) -> Option<Point3<f32>> {
|
|
||||||
match self {
|
|
||||||
Self::Landing {
|
|
||||||
from_position,
|
|
||||||
target,
|
|
||||||
total,
|
|
||||||
elapsed,
|
|
||||||
..
|
|
||||||
} => Some({
|
|
||||||
let target = ct.get_system_object(*target);
|
|
||||||
|
|
||||||
let diff = Point2 {
|
|
||||||
x: target.pos.x,
|
|
||||||
y: target.pos.y,
|
|
||||||
} - from_position;
|
|
||||||
let diff = diff - diff.normalize() * (target.size / 2.0) * 0.8;
|
|
||||||
|
|
||||||
// TODO: improve animation
|
|
||||||
// TODO: fade
|
|
||||||
// TODO: atmosphere burn
|
|
||||||
// TODO: land at random point
|
|
||||||
// TODO: don't jump camera
|
|
||||||
// TODO: time by distance
|
|
||||||
// TODO: keep momentum
|
|
||||||
|
|
||||||
let pos = from_position + (diff * (elapsed / total));
|
|
||||||
|
|
||||||
Point3 {
|
|
||||||
x: pos.x,
|
|
||||||
y: pos.y,
|
|
||||||
z: 1.0 + ((target.pos.z - 1.0) * (elapsed / total)),
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Compute position of this ship's sprite during its unlanding sequence
|
|
||||||
pub fn unlanding_position(&self, ct: &Content) -> Option<Point3<f32>> {
|
|
||||||
match self {
|
|
||||||
Self::UnLanding {
|
|
||||||
to_position,
|
|
||||||
from,
|
|
||||||
total,
|
|
||||||
elapsed,
|
|
||||||
..
|
|
||||||
} => Some({
|
|
||||||
let from = ct.get_system_object(*from);
|
|
||||||
|
|
||||||
let diff = to_position
|
|
||||||
- Point2 {
|
|
||||||
x: from.pos.x,
|
|
||||||
y: from.pos.y,
|
|
||||||
};
|
|
||||||
//let diff = diff - diff.normalize() * (target.size / 2.0) * 0.8;
|
|
||||||
|
|
||||||
// TODO: improve animation
|
|
||||||
// TODO: fade
|
|
||||||
// TODO: atmosphere burn
|
|
||||||
// TODO: land at random point
|
|
||||||
// TODO: don't jump camera
|
|
||||||
// TODO: time by distance
|
|
||||||
// TODO: keep momentum
|
|
||||||
|
|
||||||
let pos = Point2 {
|
|
||||||
x: from.pos.x,
|
|
||||||
y: from.pos.y,
|
|
||||||
} + (diff * (elapsed / total));
|
|
||||||
|
|
||||||
Point3 {
|
|
||||||
x: pos.x,
|
|
||||||
y: pos.y,
|
|
||||||
z: from.pos.z + ((1.0 - from.pos.z) * (elapsed / total)),
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Represents all attributes of a single ship
|
/// Represents all attributes of a single ship
|
||||||
|
@ -226,47 +136,26 @@ impl ShipData {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: position in data?
|
|
||||||
/// Land this ship on `target`
|
/// Land this ship on `target`
|
||||||
pub fn land_on(
|
pub fn land_on(&mut self, target: SystemObjectHandle) -> bool {
|
||||||
&mut self,
|
if self.state.is_flying() {
|
||||||
target: SystemObjectHandle,
|
self.state = ShipState::Landed { target };
|
||||||
from_position: Point2<f32>,
|
} else {
|
||||||
from_angle: Rad<f32>,
|
return false;
|
||||||
) -> bool {
|
}
|
||||||
match self.state {
|
|
||||||
ShipState::Flying => {
|
return true;
|
||||||
self.state = ShipState::Landing {
|
|
||||||
elapsed: 0.0,
|
|
||||||
total: 5.0,
|
|
||||||
target,
|
|
||||||
from_position,
|
|
||||||
from_angle,
|
|
||||||
};
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
unreachable!("Called `land_on` on a ship that isn't flying!")
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Take off from `target`
|
/// Take off from `target`
|
||||||
pub fn unland(&mut self, to_position: Point2<f32>) {
|
pub fn unland(&mut self) -> bool {
|
||||||
match self.state {
|
if self.state.is_landed() {
|
||||||
ShipState::Landed { target } => {
|
self.state = ShipState::Flying;
|
||||||
self.state = ShipState::UnLanding {
|
} else {
|
||||||
to_position,
|
return false;
|
||||||
to_angle: Rad(1.0),
|
}
|
||||||
from: target,
|
|
||||||
total: 5.0,
|
return true;
|
||||||
elapsed: 0.0,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
unreachable!("Called `unland` on a ship that isn't landed!")
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add an outfit to this ship
|
/// Add an outfit to this ship
|
||||||
|
@ -305,13 +194,9 @@ impl ShipData {
|
||||||
|
|
||||||
/// Hit this ship with the given amount of damage
|
/// Hit this ship with the given amount of damage
|
||||||
pub(crate) fn apply_damage(&mut self, ct: &Content, mut d: f32) {
|
pub(crate) fn apply_damage(&mut self, ct: &Content, mut d: f32) {
|
||||||
match self.state {
|
if self.state.is_collapsing() {
|
||||||
ShipState::Flying => {}
|
return;
|
||||||
_ => {
|
|
||||||
unreachable!("Cannot apply damage to a ship that is not flying!")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.shields >= d {
|
if self.shields >= d {
|
||||||
self.shields -= d
|
self.shields -= d
|
||||||
} else {
|
} else {
|
||||||
|
@ -333,27 +218,10 @@ impl ShipData {
|
||||||
/// Update this ship's state by `t` seconds
|
/// Update this ship's state by `t` seconds
|
||||||
pub(crate) fn step(&mut self, t: f32) {
|
pub(crate) fn step(&mut self, t: f32) {
|
||||||
match self.state {
|
match self.state {
|
||||||
ShipState::Landing {
|
ShipState::Collapsing {
|
||||||
ref mut elapsed,
|
ref mut elapsed, ..
|
||||||
total,
|
|
||||||
target,
|
|
||||||
..
|
|
||||||
} => {
|
} => {
|
||||||
*elapsed += t;
|
*elapsed += t;
|
||||||
if *elapsed >= total {
|
|
||||||
self.state = ShipState::Landed { target };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ShipState::UnLanding {
|
|
||||||
ref mut elapsed,
|
|
||||||
total,
|
|
||||||
..
|
|
||||||
} => {
|
|
||||||
*elapsed += t;
|
|
||||||
if *elapsed >= total {
|
|
||||||
self.state = ShipState::Flying;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ShipState::Landed { .. } => {
|
ShipState::Landed { .. } => {
|
||||||
|
@ -392,18 +260,6 @@ impl ShipData {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ShipState::Collapsing {
|
|
||||||
ref mut elapsed,
|
|
||||||
total,
|
|
||||||
} => {
|
|
||||||
*elapsed += t;
|
|
||||||
if *elapsed >= total {
|
|
||||||
self.state = ShipState::Dead
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ShipState::Dead => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,6 @@ use galactica_content::Relationship;
|
||||||
use rapier2d::{dynamics::RigidBodySet, geometry::ColliderHandle};
|
use rapier2d::{dynamics::RigidBodySet, geometry::ColliderHandle};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use crate::data::ShipState;
|
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
super::{
|
super::{
|
||||||
objects::{PhysSimShip, ShipControls},
|
objects::{PhysSimShip, ShipControls},
|
||||||
|
@ -48,10 +46,7 @@ impl ShipControllerStruct for PointShipController {
|
||||||
.filter(
|
.filter(
|
||||||
// Target only flying ships we're hostile towards
|
// Target only flying ships we're hostile towards
|
||||||
|s| match my_faction.relationships.get(&s.data.get_faction()).unwrap() {
|
|s| match my_faction.relationships.get(&s.data.get_faction()).unwrap() {
|
||||||
Relationship::Hostile => match s.data.get_state() {
|
Relationship::Hostile => s.data.get_state().is_flying(),
|
||||||
ShipState::Flying => true,
|
|
||||||
_ => false,
|
|
||||||
},
|
|
||||||
_ => false,
|
_ => false,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
|
@ -99,10 +99,7 @@ impl PhysSimShip {
|
||||||
ShipState::Flying => {
|
ShipState::Flying => {
|
||||||
return self.step_live(res, rigid_body, collider);
|
return self.step_live(res, rigid_body, collider);
|
||||||
}
|
}
|
||||||
ShipState::UnLanding { .. }
|
ShipState::Landed { .. } => {}
|
||||||
| ShipState::Dead
|
|
||||||
| ShipState::Landing { .. }
|
|
||||||
| ShipState::Landed { .. } => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,47 +69,32 @@ impl<'a> PhysSim {
|
||||||
|
|
||||||
fn land_ship(&mut self, collider: ColliderHandle, target: SystemObjectHandle) {
|
fn land_ship(&mut self, collider: ColliderHandle, target: SystemObjectHandle) {
|
||||||
let ship = self.ships.get_mut(&collider).unwrap();
|
let ship = self.ships.get_mut(&collider).unwrap();
|
||||||
|
self.rigid_body_set
|
||||||
let r = self.rigid_body_set.get(ship.rigid_body).unwrap();
|
.get_mut(ship.rigid_body)
|
||||||
ship.data.land_on(
|
.unwrap()
|
||||||
target,
|
.set_enabled(false);
|
||||||
util::rigidbody_position(r),
|
|
||||||
-util::rigidbody_rotation(r).angle(Vector2 { x: 0.0, y: 1.0 }),
|
|
||||||
);
|
|
||||||
|
|
||||||
let r = self.rigid_body_set.get_mut(ship.rigid_body).unwrap();
|
|
||||||
r.set_enabled(false);
|
|
||||||
r.set_angvel(0.0, false);
|
|
||||||
r.set_linvel(nalgebra::Vector2::new(0.0, 0.0), false);
|
|
||||||
|
|
||||||
self.collider_set
|
self.collider_set
|
||||||
.get_mut(ship.collider)
|
.get_mut(ship.collider)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.set_enabled(false);
|
.set_enabled(false);
|
||||||
|
|
||||||
|
ship.data.land_on(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unland_ship(&mut self, ct: &Content, collider: ColliderHandle) {
|
fn unland_ship(&mut self, ct: &Content, collider: ColliderHandle) {
|
||||||
let ship = self.ships.get_mut(&collider).unwrap();
|
let ship = self.ships.get_mut(&collider).unwrap();
|
||||||
let obj = ship.data.get_state().landed_on().unwrap();
|
let obj = ship.data.get_state().landed_on().unwrap();
|
||||||
let obj = ct.get_system_object(obj);
|
let obj = ct.get_system_object(obj);
|
||||||
|
ship.data.unland();
|
||||||
|
|
||||||
let target_pos = Point2 {
|
self.rigid_body_set
|
||||||
x: obj.pos.x + 100.0,
|
.get_mut(ship.rigid_body)
|
||||||
y: obj.pos.y + 100.0,
|
.unwrap()
|
||||||
};
|
.set_position(point![obj.pos.x, obj.pos.y].into(), true);
|
||||||
|
self.rigid_body_set
|
||||||
ship.data.unland(target_pos);
|
.get_mut(ship.rigid_body)
|
||||||
|
.unwrap()
|
||||||
let r = self.rigid_body_set.get_mut(ship.rigid_body).unwrap();
|
.set_enabled(true);
|
||||||
r.set_enabled(true);
|
|
||||||
|
|
||||||
r.set_position(
|
|
||||||
nalgebra::Vector2::new(target_pos.x, target_pos.y).into(),
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
|
|
||||||
r.set_rotation(nalgebra::Rotation2::new(1.0).into(), false);
|
|
||||||
|
|
||||||
self.collider_set
|
self.collider_set
|
||||||
.get_mut(ship.collider)
|
.get_mut(ship.collider)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -151,14 +136,10 @@ impl<'a> PhysSim {
|
||||||
let f = res.ct.get_faction(projectile.faction);
|
let f = res.ct.get_faction(projectile.faction);
|
||||||
let r = f.relationships.get(&ship.data.get_faction()).unwrap();
|
let r = f.relationships.get(&ship.data.get_faction()).unwrap();
|
||||||
let destory_projectile = match r {
|
let destory_projectile = match r {
|
||||||
Relationship::Hostile => match ship.data.get_state() {
|
Relationship::Hostile => {
|
||||||
ShipState::Flying => {
|
ship.data.apply_damage(res.ct, projectile.content.damage);
|
||||||
ship.data.apply_damage(res.ct, projectile.content.damage);
|
true
|
||||||
true
|
}
|
||||||
}
|
|
||||||
ShipState::Collapsing { .. } => true,
|
|
||||||
_ => false,
|
|
||||||
},
|
|
||||||
_ => false,
|
_ => false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -310,15 +291,15 @@ impl PhysSim {
|
||||||
// Borrow immutably for now...
|
// Borrow immutably for now...
|
||||||
// (required to compute controls)
|
// (required to compute controls)
|
||||||
let ship = self.ships.get(&collider).unwrap();
|
let ship = self.ships.get(&collider).unwrap();
|
||||||
match ship.data.get_state() {
|
if ship.data.get_state().should_be_removed() {
|
||||||
ShipState::Dead => {
|
to_remove.push(collider);
|
||||||
to_remove.push(collider);
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
ShipState::UnLanding { .. }
|
match ship.data.get_state() {
|
||||||
| ShipState::Landing { .. }
|
ShipState::Landed { .. } => {}
|
||||||
| ShipState::Landed { .. }
|
|
||||||
| ShipState::Collapsing { .. } => {
|
ShipState::Collapsing { .. } => {
|
||||||
let ship = self.ships.get_mut(&collider).unwrap();
|
let ship = self.ships.get_mut(&collider).unwrap();
|
||||||
ship.step(
|
ship.step(
|
||||||
res,
|
res,
|
||||||
|
|
Loading…
Reference in New Issue