Renames
parent
e60670c189
commit
9f1db1c7b6
|
@ -643,10 +643,9 @@ dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"cgmath",
|
"cgmath",
|
||||||
"galactica-content",
|
"galactica-content",
|
||||||
"galactica-galaxy",
|
|
||||||
"galactica-playeragent",
|
"galactica-playeragent",
|
||||||
"galactica-render",
|
"galactica-render",
|
||||||
"galactica-systemsim",
|
"galactica-system",
|
||||||
"galactica-util",
|
"galactica-util",
|
||||||
"pollster",
|
"pollster",
|
||||||
"rand",
|
"rand",
|
||||||
|
@ -668,15 +667,6 @@ dependencies = [
|
||||||
"walkdir",
|
"walkdir",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "galactica-galaxy"
|
|
||||||
version = "0.0.0"
|
|
||||||
dependencies = [
|
|
||||||
"cgmath",
|
|
||||||
"galactica-content",
|
|
||||||
"rand",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "galactica-packer"
|
name = "galactica-packer"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
|
@ -696,7 +686,6 @@ dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"cgmath",
|
"cgmath",
|
||||||
"galactica-content",
|
"galactica-content",
|
||||||
"galactica-galaxy",
|
|
||||||
"galactica-util",
|
"galactica-util",
|
||||||
"pollster",
|
"pollster",
|
||||||
"rapier2d",
|
"rapier2d",
|
||||||
|
@ -712,9 +701,8 @@ dependencies = [
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
"cgmath",
|
"cgmath",
|
||||||
"galactica-content",
|
"galactica-content",
|
||||||
"galactica-galaxy",
|
|
||||||
"galactica-packer",
|
"galactica-packer",
|
||||||
"galactica-systemsim",
|
"galactica-system",
|
||||||
"galactica-util",
|
"galactica-util",
|
||||||
"glyphon",
|
"glyphon",
|
||||||
"image",
|
"image",
|
||||||
|
@ -724,13 +712,12 @@ dependencies = [
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "galactica-systemsim"
|
name = "galactica-system"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cgmath",
|
"cgmath",
|
||||||
"crossbeam",
|
"crossbeam",
|
||||||
"galactica-content",
|
"galactica-content",
|
||||||
"galactica-galaxy",
|
|
||||||
"galactica-playeragent",
|
"galactica-playeragent",
|
||||||
"galactica-util",
|
"galactica-util",
|
||||||
"nalgebra",
|
"nalgebra",
|
||||||
|
|
|
@ -45,8 +45,7 @@ readme = ""
|
||||||
galactica-util = { path = "crates/util" }
|
galactica-util = { path = "crates/util" }
|
||||||
galactica-content = { path = "crates/content" }
|
galactica-content = { path = "crates/content" }
|
||||||
galactica-render = { path = "crates/render" }
|
galactica-render = { path = "crates/render" }
|
||||||
galactica-systemsim = { path = "crates/systemsim" }
|
galactica-system = { path = "crates/system" }
|
||||||
galactica-galaxy = { path = "crates/galaxy" }
|
|
||||||
galactica-packer = { path = "crates/packer" }
|
galactica-packer = { path = "crates/packer" }
|
||||||
galactica-playeragent = { path = "crates/playeragent" }
|
galactica-playeragent = { path = "crates/playeragent" }
|
||||||
galactica = { path = "crates/galactica" }
|
galactica = { path = "crates/galactica" }
|
||||||
|
|
|
@ -24,8 +24,7 @@ workspace = true
|
||||||
galactica-content = { workspace = true }
|
galactica-content = { workspace = true }
|
||||||
galactica-render = { workspace = true }
|
galactica-render = { workspace = true }
|
||||||
galactica-util = { workspace = true }
|
galactica-util = { workspace = true }
|
||||||
galactica-systemsim = { workspace = true }
|
galactica-system = { workspace = true }
|
||||||
galactica-galaxy = { workspace = true }
|
|
||||||
galactica-playeragent = { workspace = true }
|
galactica-playeragent = { workspace = true }
|
||||||
|
|
||||||
rand = { workspace = true }
|
rand = { workspace = true }
|
||||||
|
|
|
@ -1,15 +1,17 @@
|
||||||
use cgmath::Point2;
|
use cgmath::Point2;
|
||||||
use galactica_content::{Content, FactionHandle, OutfitHandle, ShipHandle, SystemHandle};
|
use galactica_content::{Content, FactionHandle, OutfitHandle, ShipHandle, SystemHandle};
|
||||||
use galactica_galaxy::ship::ShipPersonality;
|
|
||||||
use galactica_playeragent::PlayerAgent;
|
use galactica_playeragent::PlayerAgent;
|
||||||
use galactica_systemsim::{ParticleBuilder, StepResources, SySimShipHandle, SystemSim, Wrapper};
|
use galactica_system::data::ShipPersonality;
|
||||||
|
use galactica_system::phys::{
|
||||||
|
ParticleBuilder, PhysSim, PhysSimShipHandle, PhysStepResources, Wrapper,
|
||||||
|
};
|
||||||
use galactica_util::timing::Timing;
|
use galactica_util::timing::Timing;
|
||||||
use rand::seq::SliceRandom;
|
use rand::seq::SliceRandom;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct GameState {
|
pub struct GameState {
|
||||||
pub systemsim: SystemSim,
|
pub systemsim: PhysSim,
|
||||||
pub timing: Timing,
|
pub timing: Timing,
|
||||||
pub start_instant: Instant,
|
pub start_instant: Instant,
|
||||||
}
|
}
|
||||||
|
@ -36,7 +38,7 @@ pub struct Game {
|
||||||
unsafe impl<'a> Send for Game {}
|
unsafe impl<'a> Send for Game {}
|
||||||
|
|
||||||
impl<'a> Game {
|
impl<'a> Game {
|
||||||
pub fn make_player(&mut self) -> SySimShipHandle {
|
pub fn make_player(&mut self) -> PhysSimShipHandle {
|
||||||
let player = self.state.systemsim.add_ship(
|
let player = self.state.systemsim.add_ship(
|
||||||
&self.ct,
|
&self.ct,
|
||||||
ShipHandle { index: 0 },
|
ShipHandle { index: 0 },
|
||||||
|
@ -57,7 +59,7 @@ impl<'a> Game {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(ct: Content) -> Self {
|
pub fn new(ct: Content) -> Self {
|
||||||
let mut systemsim = SystemSim::new(&ct, SystemHandle { index: 0 });
|
let mut systemsim = PhysSim::new(&ct, SystemHandle { index: 0 });
|
||||||
|
|
||||||
let a = systemsim.add_ship(
|
let a = systemsim.add_ship(
|
||||||
&ct,
|
&ct,
|
||||||
|
@ -119,7 +121,7 @@ impl<'a> Game {
|
||||||
let t: f32 = self.last_update.elapsed().as_secs_f32() * self.time_scale;
|
let t: f32 = self.last_update.elapsed().as_secs_f32() * self.time_scale;
|
||||||
self.new_particles.clear();
|
self.new_particles.clear();
|
||||||
|
|
||||||
self.state.systemsim.step(StepResources {
|
self.state.systemsim.step(PhysStepResources {
|
||||||
ct: &self.ct,
|
ct: &self.ct,
|
||||||
particles: &mut self.new_particles,
|
particles: &mut self.new_particles,
|
||||||
timing: &mut self.state.timing,
|
timing: &mut self.state.timing,
|
||||||
|
|
|
@ -4,7 +4,7 @@ use anyhow::{bail, Result};
|
||||||
use galactica_content::{Content, SystemHandle};
|
use galactica_content::{Content, SystemHandle};
|
||||||
use galactica_playeragent::{PlayerAgent, PlayerStatus};
|
use galactica_playeragent::{PlayerAgent, PlayerStatus};
|
||||||
use galactica_render::RenderInput;
|
use galactica_render::RenderInput;
|
||||||
use galactica_systemsim::{util, SySimShipHandle};
|
use galactica_system::phys::{util, PhysSimShipHandle};
|
||||||
use galactica_util::constants::ASSET_CACHE;
|
use galactica_util::constants::ASSET_CACHE;
|
||||||
use std::{
|
use std::{
|
||||||
fs,
|
fs,
|
||||||
|
@ -56,7 +56,7 @@ fn main() -> Result<()> {
|
||||||
ct: &content,
|
ct: &content,
|
||||||
systemsim: &game.get_state().systemsim,
|
systemsim: &game.get_state().systemsim,
|
||||||
particles: game.get_particles(),
|
particles: game.get_particles(),
|
||||||
player_ship: SySimShipHandle(player.ship.unwrap()),
|
player_ship: PhysSimShipHandle(player.ship.unwrap()),
|
||||||
current_system: SystemHandle { index: 0 },
|
current_system: SystemHandle { index: 0 },
|
||||||
timing: game.get_state().timing.clone(),
|
timing: game.get_state().timing.clone(),
|
||||||
};
|
};
|
||||||
|
@ -79,7 +79,7 @@ fn main() -> Result<()> {
|
||||||
let o = &game
|
let o = &game
|
||||||
.get_state()
|
.get_state()
|
||||||
.systemsim
|
.systemsim
|
||||||
.get_ship(&SySimShipHandle(player.ship.unwrap()));
|
.get_ship(&PhysSimShipHandle(player.ship.unwrap()));
|
||||||
if let Some(o) = o {
|
if let Some(o) = o {
|
||||||
let r = &game.get_state().systemsim.get_rigid_body(o.rigid_body);
|
let r = &game.get_state().systemsim.get_rigid_body(o.rigid_body);
|
||||||
if let Some(r) = r {
|
if let Some(r) = r {
|
||||||
|
|
|
@ -1,23 +0,0 @@
|
||||||
[package]
|
|
||||||
name = "galactica-galaxy"
|
|
||||||
description = "Galactica's game data manager"
|
|
||||||
categories = { workspace = true }
|
|
||||||
keywords = { workspace = true }
|
|
||||||
version = { workspace = true }
|
|
||||||
rust-version = { workspace = true }
|
|
||||||
authors = { workspace = true }
|
|
||||||
edition = { workspace = true }
|
|
||||||
homepage = { workspace = true }
|
|
||||||
repository = { workspace = true }
|
|
||||||
license = { workspace = true }
|
|
||||||
documentation = { workspace = true }
|
|
||||||
readme = { workspace = true }
|
|
||||||
|
|
||||||
[lints]
|
|
||||||
workspace = true
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
galactica-content = { workspace = true }
|
|
||||||
|
|
||||||
cgmath = { workspace = true }
|
|
||||||
rand = { workspace = true }
|
|
|
@ -1 +0,0 @@
|
||||||
pub mod ship;
|
|
|
@ -19,7 +19,6 @@ workspace = true
|
||||||
[dependencies]
|
[dependencies]
|
||||||
galactica-content = { workspace = true }
|
galactica-content = { workspace = true }
|
||||||
galactica-util = { workspace = true }
|
galactica-util = { workspace = true }
|
||||||
galactica-galaxy = { workspace = true }
|
|
||||||
|
|
||||||
winit = { workspace = true }
|
winit = { workspace = true }
|
||||||
wgpu = { workspace = true }
|
wgpu = { workspace = true }
|
||||||
|
|
|
@ -20,8 +20,7 @@ workspace = true
|
||||||
galactica-content = { workspace = true }
|
galactica-content = { workspace = true }
|
||||||
galactica-util = { workspace = true }
|
galactica-util = { workspace = true }
|
||||||
galactica-packer = { workspace = true }
|
galactica-packer = { workspace = true }
|
||||||
galactica-systemsim = { workspace = true }
|
galactica-system = { workspace = true }
|
||||||
galactica-galaxy = { workspace = true }
|
|
||||||
|
|
||||||
anyhow = { workspace = true }
|
anyhow = { workspace = true }
|
||||||
cgmath = { workspace = true }
|
cgmath = { workspace = true }
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use cgmath::Point2;
|
use cgmath::Point2;
|
||||||
use galactica_content::{Content, SystemHandle};
|
use galactica_content::{Content, SystemHandle};
|
||||||
use galactica_systemsim::{ParticleBuilder, SySimShipHandle, SystemSim};
|
use galactica_system::phys::{ParticleBuilder, PhysSim, PhysSimShipHandle};
|
||||||
use galactica_util::timing::Timing;
|
use galactica_util::timing::Timing;
|
||||||
use glyphon::{FontSystem, SwashCache, TextAtlas, TextRenderer};
|
use glyphon::{FontSystem, SwashCache, TextAtlas, TextRenderer};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
@ -15,7 +15,7 @@ pub struct RenderInput<'a> {
|
||||||
pub camera_pos: Point2<f32>,
|
pub camera_pos: Point2<f32>,
|
||||||
|
|
||||||
/// Player ship data
|
/// Player ship data
|
||||||
pub player_ship: SySimShipHandle,
|
pub player_ship: PhysSimShipHandle,
|
||||||
|
|
||||||
/// The system we're currently in
|
/// The system we're currently in
|
||||||
pub current_system: SystemHandle,
|
pub current_system: SystemHandle,
|
||||||
|
@ -24,7 +24,7 @@ pub struct RenderInput<'a> {
|
||||||
pub camera_zoom: f32,
|
pub camera_zoom: f32,
|
||||||
|
|
||||||
/// The world state to render
|
/// The world state to render
|
||||||
pub systemsim: &'a SystemSim,
|
pub systemsim: &'a PhysSim,
|
||||||
|
|
||||||
// TODO: handle overflow. is it a problem?
|
// TODO: handle overflow. is it a problem?
|
||||||
/// The current time, in seconds
|
/// The current time, in seconds
|
||||||
|
|
|
@ -10,8 +10,8 @@ use crate::{
|
||||||
/// GPUState is very big, so its methods have been split
|
/// GPUState is very big, so its methods have been split
|
||||||
/// among the following files.
|
/// among the following files.
|
||||||
mod new;
|
mod new;
|
||||||
|
mod phys;
|
||||||
mod render;
|
mod render;
|
||||||
mod systemsim;
|
|
||||||
|
|
||||||
/// A high-level GPU wrapper. Reads game state (via RenderInput),
|
/// A high-level GPU wrapper. Reads game state (via RenderInput),
|
||||||
/// produces pretty pictures.
|
/// produces pretty pictures.
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
use bytemuck;
|
use bytemuck;
|
||||||
use cgmath::{EuclideanSpace, InnerSpace, Point2, Vector2};
|
use cgmath::{EuclideanSpace, InnerSpace, Point2, Vector2};
|
||||||
use galactica_systemsim::util;
|
use galactica_system::phys::util;
|
||||||
use galactica_util::constants::OBJECT_SPRITE_INSTANCE_LIMIT;
|
use galactica_util::constants::OBJECT_SPRITE_INSTANCE_LIMIT;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -12,7 +12,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
|
|
||||||
impl GPUState {
|
impl GPUState {
|
||||||
pub(super) fn sysim_push_ship(
|
pub(super) fn phys_push_ship(
|
||||||
&mut self,
|
&mut self,
|
||||||
state: &RenderInput,
|
state: &RenderInput,
|
||||||
// NE and SW corners of screen
|
// NE and SW corners of screen
|
||||||
|
@ -120,7 +120,7 @@ impl GPUState {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn sysim_push_projectile(
|
pub(super) fn phys_push_projectile(
|
||||||
&mut self,
|
&mut self,
|
||||||
state: &RenderInput,
|
state: &RenderInput,
|
||||||
// NE and SW corners of screen
|
// NE and SW corners of screen
|
||||||
|
@ -190,7 +190,7 @@ impl GPUState {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn sysim_push_system(
|
pub(super) fn phys_push_system(
|
||||||
&mut self,
|
&mut self,
|
||||||
state: &RenderInput,
|
state: &RenderInput,
|
||||||
// NE and SW corners of screen
|
// NE and SW corners of screen
|
|
@ -116,9 +116,9 @@ impl super::GPUState {
|
||||||
// Order matters, it determines what is drawn on top.
|
// Order matters, it determines what is drawn on top.
|
||||||
// The order inside ships and projectiles doesn't matter,
|
// The order inside ships and projectiles doesn't matter,
|
||||||
// but ships should always be under projectiles.
|
// but ships should always be under projectiles.
|
||||||
self.sysim_push_system(&input, (clip_ne, clip_sw));
|
self.phys_push_system(&input, (clip_ne, clip_sw));
|
||||||
self.sysim_push_ship(&input, (clip_ne, clip_sw));
|
self.phys_push_ship(&input, (clip_ne, clip_sw));
|
||||||
self.sysim_push_projectile(&input, (clip_ne, clip_sw));
|
self.phys_push_projectile(&input, (clip_ne, clip_sw));
|
||||||
self.ui.draw(&input, &mut self.state);
|
self.ui.draw(&input, &mut self.state);
|
||||||
|
|
||||||
// These should match the indices in each shader,
|
// These should match the indices in each shader,
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use cgmath::{Deg, InnerSpace, Point2, Rad, Vector2};
|
use cgmath::{Deg, InnerSpace, Point2, Rad, Vector2};
|
||||||
use galactica_galaxy::ship::ShipState;
|
use galactica_system::{data::ShipState, phys::util};
|
||||||
use galactica_systemsim::util;
|
|
||||||
use galactica_util::constants::UI_SPRITE_INSTANCE_LIMIT;
|
use galactica_util::constants::UI_SPRITE_INSTANCE_LIMIT;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use std::f32::consts::TAU;
|
use std::f32::consts::TAU;
|
||||||
|
|
||||||
|
use galactica_system::data::ShipState;
|
||||||
use galactica_util::constants::{RADIALBAR_SPRITE_INSTANCE_LIMIT, UI_SPRITE_INSTANCE_LIMIT};
|
use galactica_util::constants::{RADIALBAR_SPRITE_INSTANCE_LIMIT, UI_SPRITE_INSTANCE_LIMIT};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -32,8 +33,7 @@ impl Status {
|
||||||
let player_ship = input.systemsim.get_ship(&input.player_ship).unwrap();
|
let player_ship = input.systemsim.get_ship(&input.player_ship).unwrap();
|
||||||
|
|
||||||
match player_ship.data.get_state() {
|
match player_ship.data.get_state() {
|
||||||
galactica_galaxy::ship::ShipState::Collapsing { .. }
|
ShipState::Collapsing { .. } | ShipState::Flying => {
|
||||||
| galactica_galaxy::ship::ShipState::Flying => {
|
|
||||||
max_shields = player_ship.data.get_outfits().get_shield_strength();
|
max_shields = player_ship.data.get_outfits().get_shield_strength();
|
||||||
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();
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "galactica-systemsim"
|
name = "galactica-system"
|
||||||
description = "Physics interactions for Galactica"
|
description = "Galactica's star system simulations"
|
||||||
categories = { workspace = true }
|
categories = { workspace = true }
|
||||||
keywords = { workspace = true }
|
keywords = { workspace = true }
|
||||||
version = { workspace = true }
|
version = { workspace = true }
|
||||||
|
@ -18,7 +18,6 @@ workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
galactica-content = { workspace = true }
|
galactica-content = { workspace = true }
|
||||||
galactica-galaxy = { workspace = true }
|
|
||||||
galactica-util = { workspace = true }
|
galactica-util = { workspace = true }
|
||||||
galactica-playeragent = { workspace = true }
|
galactica-playeragent = { workspace = true }
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
//! This module contains data structs shared between all simulations
|
||||||
|
|
||||||
|
mod ship;
|
||||||
|
pub use ship::*;
|
|
@ -160,6 +160,8 @@ impl OutfitSet {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: pick these better
|
// TODO: pick these better
|
||||||
|
/// Returns the flare sprite that should be shown when this
|
||||||
|
/// ship is using its thrusters
|
||||||
pub fn get_flare_sprite(&self, ct: &Content) -> Option<SpriteHandle> {
|
pub fn get_flare_sprite(&self, ct: &Content) -> Option<SpriteHandle> {
|
||||||
for i in self.outfits.keys() {
|
for i in self.outfits.keys() {
|
||||||
let c = ct.get_outfit(*i);
|
let c = ct.get_outfit(*i);
|
|
@ -14,8 +14,13 @@ pub enum ShipState {
|
||||||
Flying, // TODO: system, position (also in collapse)?
|
Flying, // TODO: system, position (also in collapse)?
|
||||||
|
|
||||||
/// This ship has been destroyed, and is playing its collapse sequence.
|
/// This ship has been destroyed, and is playing its collapse sequence.
|
||||||
/// Parameters are total collapse sequence length and remaining sequence length, in seconds.
|
Collapsing {
|
||||||
Collapsing { total: f32, elapsed: f32 },
|
/// Total collapse sequence length, in seconds
|
||||||
|
total: f32,
|
||||||
|
|
||||||
|
/// How many seconds of the collapse sequence we've played
|
||||||
|
elapsed: f32,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ShipState {
|
impl ShipState {
|
||||||
|
@ -57,8 +62,9 @@ impl ShipState {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Represents all attributes of a single ship
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct GxShip {
|
pub struct ShipData {
|
||||||
// Metadata values
|
// Metadata values
|
||||||
ct_handle: ShipHandle,
|
ct_handle: ShipHandle,
|
||||||
faction: FactionHandle,
|
faction: FactionHandle,
|
||||||
|
@ -82,15 +88,16 @@ pub struct GxShip {
|
||||||
last_hit: Instant,
|
last_hit: Instant,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GxShip {
|
impl ShipData {
|
||||||
pub fn new(
|
/// Create a new ShipData
|
||||||
|
pub(crate) fn new(
|
||||||
ct: &Content,
|
ct: &Content,
|
||||||
ct_handle: ShipHandle,
|
ct_handle: ShipHandle,
|
||||||
faction: FactionHandle,
|
faction: FactionHandle,
|
||||||
personality: ShipPersonality,
|
personality: ShipPersonality,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let s = ct.get_ship(ct_handle);
|
let s = ct.get_ship(ct_handle);
|
||||||
GxShip {
|
ShipData {
|
||||||
ct_handle,
|
ct_handle,
|
||||||
faction,
|
faction,
|
||||||
outfits: OutfitSet::new(s.space, &s.guns),
|
outfits: OutfitSet::new(s.space, &s.guns),
|
||||||
|
@ -124,7 +131,7 @@ impl GxShip {
|
||||||
/// Will panic if `which` isn't a point on this ship.
|
/// Will panic if `which` isn't a point on this ship.
|
||||||
/// Returns `true` if this gun was fired,
|
/// Returns `true` if this gun was fired,
|
||||||
/// and `false` if it is on cooldown or empty.
|
/// and `false` if it is on cooldown or empty.
|
||||||
pub fn fire_gun(&mut self, ct: &Content, which: &GunPoint) -> bool {
|
pub(crate) fn fire_gun(&mut self, ct: &Content, which: &GunPoint) -> bool {
|
||||||
let c = self.gun_cooldowns.get_mut(which).unwrap();
|
let c = self.gun_cooldowns.get_mut(which).unwrap();
|
||||||
|
|
||||||
if *c > 0.0 {
|
if *c > 0.0 {
|
||||||
|
@ -143,7 +150,7 @@ impl GxShip {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Hit this ship with the given amount of damage
|
/// Hit this ship with the given amount of damage
|
||||||
pub fn apply_damage(&mut self, ct: &Content, mut d: f32) {
|
pub(crate) fn apply_damage(&mut self, ct: &Content, mut d: f32) {
|
||||||
if self.state.is_collapsing() {
|
if self.state.is_collapsing() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -166,7 +173,7 @@ impl GxShip {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Update this ship's state by `t` seconds
|
/// Update this ship's state by `t` seconds
|
||||||
pub fn step(&mut self, t: f32) {
|
pub(crate) fn step(&mut self, t: f32) {
|
||||||
match self.state {
|
match self.state {
|
||||||
ShipState::Collapsing {
|
ShipState::Collapsing {
|
||||||
ref mut elapsed, ..
|
ref mut elapsed, ..
|
||||||
|
@ -201,7 +208,7 @@ impl GxShip {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Misc getters, so internal state is untouchable
|
// Misc getters, so internal state is untouchable
|
||||||
impl GxShip {
|
impl ShipData {
|
||||||
/// Get this ship's state
|
/// Get this ship's state
|
||||||
pub fn get_state(&self) -> &ShipState {
|
pub fn get_state(&self) -> &ShipState {
|
||||||
&self.state
|
&self.state
|
|
@ -0,0 +1,8 @@
|
||||||
|
#![warn(missing_docs)]
|
||||||
|
|
||||||
|
//! Galactica's system simulation.
|
||||||
|
//! data contains shared object data,
|
||||||
|
//! phys contains the physics system simulation (the one you see)
|
||||||
|
|
||||||
|
pub mod data;
|
||||||
|
pub mod phys;
|
|
@ -9,9 +9,9 @@ use point::PointShipController;
|
||||||
use rapier2d::{dynamics::RigidBodySet, geometry::ColliderHandle};
|
use rapier2d::{dynamics::RigidBodySet, geometry::ColliderHandle};
|
||||||
use std::{collections::HashMap, fmt::Debug};
|
use std::{collections::HashMap, fmt::Debug};
|
||||||
|
|
||||||
use crate::{
|
use super::{
|
||||||
objects::{ShipControls, SySimShip},
|
objects::{PhysSimShip, ShipControls},
|
||||||
StepResources,
|
PhysStepResources,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Represents a ship controller
|
/// Represents a ship controller
|
||||||
|
@ -38,9 +38,9 @@ impl ShipController {
|
||||||
/// Compute new ship controls from world state
|
/// Compute new ship controls from world state
|
||||||
pub fn update_controls(
|
pub fn update_controls(
|
||||||
&mut self,
|
&mut self,
|
||||||
res: &StepResources,
|
res: &PhysStepResources,
|
||||||
rigid_bodies: &RigidBodySet,
|
rigid_bodies: &RigidBodySet,
|
||||||
ships: &HashMap<ColliderHandle, SySimShip>,
|
ships: &HashMap<ColliderHandle, PhysSimShip>,
|
||||||
this_ship: ColliderHandle,
|
this_ship: ColliderHandle,
|
||||||
) -> Option<ShipControls> {
|
) -> Option<ShipControls> {
|
||||||
match self {
|
match self {
|
||||||
|
@ -61,9 +61,9 @@ where
|
||||||
/// or None if no change is to be made.
|
/// or None if no change is to be made.
|
||||||
fn update_controls(
|
fn update_controls(
|
||||||
&mut self,
|
&mut self,
|
||||||
res: &StepResources,
|
res: &PhysStepResources,
|
||||||
rigid_bodies: &RigidBodySet,
|
rigid_bodies: &RigidBodySet,
|
||||||
ships: &HashMap<ColliderHandle, SySimShip>,
|
ships: &HashMap<ColliderHandle, PhysSimShip>,
|
||||||
this_ship: ColliderHandle,
|
this_ship: ColliderHandle,
|
||||||
) -> Option<ShipControls>;
|
) -> Option<ShipControls>;
|
||||||
}
|
}
|
|
@ -1,10 +1,12 @@
|
||||||
use rapier2d::{dynamics::RigidBodySet, geometry::ColliderHandle};
|
use rapier2d::{dynamics::RigidBodySet, geometry::ColliderHandle};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use super::ShipControllerStruct;
|
use super::{
|
||||||
use crate::{
|
super::{
|
||||||
objects::{ShipControls, SySimShip},
|
objects::{PhysSimShip, ShipControls},
|
||||||
StepResources,
|
PhysStepResources,
|
||||||
|
},
|
||||||
|
ShipControllerStruct,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The Null controller is assigned to objects that are static or not controlled by the computer.
|
/// The Null controller is assigned to objects that are static or not controlled by the computer.
|
||||||
|
@ -22,9 +24,9 @@ impl NullShipController {
|
||||||
impl ShipControllerStruct for NullShipController {
|
impl ShipControllerStruct for NullShipController {
|
||||||
fn update_controls(
|
fn update_controls(
|
||||||
&mut self,
|
&mut self,
|
||||||
_res: &StepResources,
|
_res: &PhysStepResources,
|
||||||
_rigid_bodies: &RigidBodySet,
|
_rigid_bodies: &RigidBodySet,
|
||||||
_ships: &HashMap<ColliderHandle, SySimShip>,
|
_ships: &HashMap<ColliderHandle, PhysSimShip>,
|
||||||
_this_ship: ColliderHandle,
|
_this_ship: ColliderHandle,
|
||||||
) -> Option<ShipControls> {
|
) -> Option<ShipControls> {
|
||||||
None
|
None
|
|
@ -3,10 +3,12 @@ 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 super::ShipControllerStruct;
|
use super::{
|
||||||
use crate::{
|
super::{
|
||||||
objects::{ShipControls, SySimShip},
|
objects::{PhysSimShip, ShipControls},
|
||||||
util, StepResources,
|
util, PhysStepResources,
|
||||||
|
},
|
||||||
|
ShipControllerStruct,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// "Point" ship controller.
|
/// "Point" ship controller.
|
||||||
|
@ -24,9 +26,9 @@ impl PointShipController {
|
||||||
impl ShipControllerStruct for PointShipController {
|
impl ShipControllerStruct for PointShipController {
|
||||||
fn update_controls(
|
fn update_controls(
|
||||||
&mut self,
|
&mut self,
|
||||||
res: &StepResources,
|
res: &PhysStepResources,
|
||||||
rigid_bodies: &RigidBodySet,
|
rigid_bodies: &RigidBodySet,
|
||||||
ships: &HashMap<ColliderHandle, SySimShip>,
|
ships: &HashMap<ColliderHandle, PhysSimShip>,
|
||||||
this_ship: ColliderHandle,
|
this_ship: ColliderHandle,
|
||||||
) -> Option<ShipControls> {
|
) -> Option<ShipControls> {
|
||||||
let mut controls = ShipControls::new();
|
let mut controls = ShipControls::new();
|
|
@ -1,6 +1,4 @@
|
||||||
#![warn(missing_docs)]
|
//! This module provides a physics-based simulation of one system.
|
||||||
|
|
||||||
//! This module provides a physics-based simulation of one galaxy system.
|
|
||||||
|
|
||||||
pub mod controller;
|
pub mod controller;
|
||||||
pub mod objects;
|
pub mod objects;
|
||||||
|
@ -12,5 +10,5 @@ mod wrapper;
|
||||||
|
|
||||||
pub use particlebuilder::*;
|
pub use particlebuilder::*;
|
||||||
pub use stepresources::*;
|
pub use stepresources::*;
|
||||||
pub use systemsim::{SySimShipHandle, SystemSim};
|
pub use systemsim::{PhysSim, PhysSimShipHandle};
|
||||||
pub use wrapper::Wrapper;
|
pub use wrapper::Wrapper;
|
|
@ -1,11 +1,11 @@
|
||||||
use cgmath::{Deg, EuclideanSpace, InnerSpace, Matrix2, Rad, Vector2, Zero};
|
use cgmath::{Deg, EuclideanSpace, InnerSpace, Matrix2, Rad, Vector2, Zero};
|
||||||
use galactica_content::{CollapseEvent, Ship};
|
use galactica_content::{CollapseEvent, Ship};
|
||||||
use galactica_galaxy::ship::GxShip;
|
|
||||||
use nalgebra::point;
|
use nalgebra::point;
|
||||||
use rand::{rngs::ThreadRng, Rng};
|
use rand::{rngs::ThreadRng, Rng};
|
||||||
use rapier2d::{dynamics::RigidBody, geometry::Collider};
|
use rapier2d::{dynamics::RigidBody, geometry::Collider};
|
||||||
|
|
||||||
use crate::{util, ParticleBuilder, StepResources};
|
use super::super::{util, ParticleBuilder, PhysStepResources};
|
||||||
|
use crate::data::ShipData;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub(super) struct ShipCollapseSequence {
|
pub(super) struct ShipCollapseSequence {
|
||||||
|
@ -40,8 +40,8 @@ impl ShipCollapseSequence {
|
||||||
/// Step this sequence `t` seconds
|
/// Step this sequence `t` seconds
|
||||||
pub(super) fn step(
|
pub(super) fn step(
|
||||||
&mut self,
|
&mut self,
|
||||||
res: &mut StepResources,
|
res: &mut PhysStepResources,
|
||||||
ship_data: &GxShip,
|
ship_data: &ShipData,
|
||||||
rigid_body: &mut RigidBody,
|
rigid_body: &mut RigidBody,
|
||||||
collider: &mut Collider,
|
collider: &mut Collider,
|
||||||
) {
|
) {
|
||||||
|
@ -57,6 +57,8 @@ impl ShipCollapseSequence {
|
||||||
// The fraction of this collapse sequence that has been played
|
// The fraction of this collapse sequence that has been played
|
||||||
let frac_done = elapsed / total;
|
let frac_done = elapsed / total;
|
||||||
|
|
||||||
|
// TODO: slight random offset for event particles
|
||||||
|
|
||||||
// Trigger collapse events
|
// Trigger collapse events
|
||||||
for event in &ship_content.collapse.events {
|
for event in &ship_content.collapse.events {
|
||||||
match event {
|
match event {
|
|
@ -3,5 +3,5 @@ mod collapse;
|
||||||
mod projectile;
|
mod projectile;
|
||||||
mod ship;
|
mod ship;
|
||||||
|
|
||||||
pub use projectile::SySimProjectile;
|
pub use projectile::PhysProjectile;
|
||||||
pub use ship::{ShipControls, SySimShip};
|
pub use ship::{PhysSimShip, ShipControls};
|
|
@ -2,9 +2,9 @@ use galactica_content::{FactionHandle, Projectile};
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use rapier2d::{dynamics::RigidBodyHandle, geometry::ColliderHandle};
|
use rapier2d::{dynamics::RigidBodyHandle, geometry::ColliderHandle};
|
||||||
|
|
||||||
/// A single projectile in this sim
|
/// A single projectile in this simulation
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct SySimProjectile {
|
pub struct PhysProjectile {
|
||||||
/// This projectile's game data
|
/// This projectile's game data
|
||||||
pub content: Projectile,
|
pub content: Projectile,
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ pub struct SySimProjectile {
|
||||||
pub size_rng: f32,
|
pub size_rng: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SySimProjectile {
|
impl PhysProjectile {
|
||||||
/// Create a new projectile
|
/// Create a new projectile
|
||||||
pub fn new(
|
pub fn new(
|
||||||
content: Projectile, // TODO: use a handle
|
content: Projectile, // TODO: use a handle
|
||||||
|
@ -35,7 +35,7 @@ impl SySimProjectile {
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::thread_rng();
|
||||||
let size_rng = content.size_rng;
|
let size_rng = content.size_rng;
|
||||||
let lifetime = content.lifetime;
|
let lifetime = content.lifetime;
|
||||||
SySimProjectile {
|
PhysProjectile {
|
||||||
rigid_body,
|
rigid_body,
|
||||||
collider,
|
collider,
|
||||||
content,
|
content,
|
|
@ -1,6 +1,5 @@
|
||||||
use cgmath::{Deg, EuclideanSpace, InnerSpace, Matrix2, Rad, Vector2, Zero};
|
use cgmath::{Deg, EuclideanSpace, InnerSpace, Matrix2, Rad, Vector2, Zero};
|
||||||
use galactica_content::{Content, FactionHandle, ShipHandle};
|
use galactica_content::{Content, FactionHandle, ShipHandle};
|
||||||
use galactica_galaxy::ship::{GxShip, ShipPersonality, ShipState};
|
|
||||||
use nalgebra::{point, vector};
|
use nalgebra::{point, vector};
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use rapier2d::{
|
use rapier2d::{
|
||||||
|
@ -8,9 +7,12 @@ use rapier2d::{
|
||||||
geometry::{Collider, ColliderHandle},
|
geometry::{Collider, ColliderHandle},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{util, ParticleBuilder, StepResources};
|
use crate::data::{ShipData, ShipPersonality, ShipState};
|
||||||
|
|
||||||
use super::collapse::ShipCollapseSequence;
|
use super::{
|
||||||
|
super::{util, ParticleBuilder, PhysStepResources},
|
||||||
|
collapse::ShipCollapseSequence,
|
||||||
|
};
|
||||||
|
|
||||||
/// A ship's controls
|
/// A ship's controls
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
@ -42,7 +44,7 @@ impl ShipControls {
|
||||||
|
|
||||||
/// A ship instance in the physics system
|
/// A ship instance in the physics system
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct SySimShip {
|
pub struct PhysSimShip {
|
||||||
/// This ship's physics handle
|
/// This ship's physics handle
|
||||||
pub rigid_body: RigidBodyHandle,
|
pub rigid_body: RigidBodyHandle,
|
||||||
|
|
||||||
|
@ -50,7 +52,7 @@ pub struct SySimShip {
|
||||||
pub collider: ColliderHandle,
|
pub collider: ColliderHandle,
|
||||||
|
|
||||||
/// This ship's game data
|
/// This ship's game data
|
||||||
pub data: GxShip,
|
pub data: ShipData,
|
||||||
|
|
||||||
/// This ship's controls
|
/// This ship's controls
|
||||||
pub(crate) controls: ShipControls,
|
pub(crate) controls: ShipControls,
|
||||||
|
@ -59,7 +61,7 @@ pub struct SySimShip {
|
||||||
collapse_sequence: Option<ShipCollapseSequence>,
|
collapse_sequence: Option<ShipCollapseSequence>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SySimShip {
|
impl PhysSimShip {
|
||||||
/// Make a new ship
|
/// Make a new ship
|
||||||
pub(crate) fn new(
|
pub(crate) fn new(
|
||||||
ct: &Content,
|
ct: &Content,
|
||||||
|
@ -69,10 +71,10 @@ impl SySimShip {
|
||||||
rigid_body: RigidBodyHandle,
|
rigid_body: RigidBodyHandle,
|
||||||
collider: ColliderHandle,
|
collider: ColliderHandle,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
SySimShip {
|
PhysSimShip {
|
||||||
rigid_body,
|
rigid_body,
|
||||||
collider,
|
collider,
|
||||||
data: GxShip::new(ct, handle, faction, personality),
|
data: ShipData::new(ct, handle, faction, personality),
|
||||||
controls: ShipControls::new(),
|
controls: ShipControls::new(),
|
||||||
collapse_sequence: Some(ShipCollapseSequence::new()),
|
collapse_sequence: Some(ShipCollapseSequence::new()),
|
||||||
}
|
}
|
||||||
|
@ -81,7 +83,7 @@ impl SySimShip {
|
||||||
/// Step this ship's state by t seconds
|
/// Step this ship's state by t seconds
|
||||||
pub fn step(
|
pub fn step(
|
||||||
&mut self,
|
&mut self,
|
||||||
res: &mut StepResources,
|
res: &mut PhysStepResources,
|
||||||
rigid_body: &mut RigidBody,
|
rigid_body: &mut RigidBody,
|
||||||
collider: &mut Collider,
|
collider: &mut Collider,
|
||||||
) {
|
) {
|
||||||
|
@ -103,7 +105,7 @@ impl SySimShip {
|
||||||
/// Step this ship's state by t seconds (called when alive)
|
/// Step this ship's state by t seconds (called when alive)
|
||||||
fn step_live(
|
fn step_live(
|
||||||
&mut self,
|
&mut self,
|
||||||
res: &mut StepResources,
|
res: &mut PhysStepResources,
|
||||||
rigid_body: &mut RigidBody,
|
rigid_body: &mut RigidBody,
|
||||||
collider: &mut Collider,
|
collider: &mut Collider,
|
||||||
) {
|
) {
|
||||||
|
@ -180,7 +182,7 @@ impl SySimShip {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SySimShip {
|
impl PhysSimShip {
|
||||||
/// Get this ship's control state
|
/// Get this ship's control state
|
||||||
pub fn get_controls(&self) -> &ShipControls {
|
pub fn get_controls(&self) -> &ShipControls {
|
||||||
&self.controls
|
&self.controls
|
|
@ -1,9 +1,9 @@
|
||||||
use crate::{wrapper::Wrapper, ParticleBuilder};
|
use super::{wrapper::Wrapper, ParticleBuilder};
|
||||||
use galactica_content::Content;
|
use galactica_content::Content;
|
||||||
use galactica_util::timing::Timing;
|
use galactica_util::timing::Timing;
|
||||||
|
|
||||||
/// External resources we need to compute time steps
|
/// External resources we need to compute time steps
|
||||||
pub struct StepResources<'a> {
|
pub struct PhysStepResources<'a> {
|
||||||
/// Game content
|
/// Game content
|
||||||
pub ct: &'a Content,
|
pub ct: &'a Content,
|
||||||
|
|
|
@ -3,7 +3,6 @@ use galactica_content::{
|
||||||
Content, FactionHandle, GunPoint, OutfitHandle, ProjectileCollider, Relationship, ShipHandle,
|
Content, FactionHandle, GunPoint, OutfitHandle, ProjectileCollider, Relationship, ShipHandle,
|
||||||
SystemHandle,
|
SystemHandle,
|
||||||
};
|
};
|
||||||
use galactica_galaxy::ship::ShipPersonality;
|
|
||||||
use galactica_playeragent::PlayerAgent;
|
use galactica_playeragent::PlayerAgent;
|
||||||
use nalgebra::{point, vector};
|
use nalgebra::{point, vector};
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
|
@ -14,39 +13,41 @@ use rapier2d::{
|
||||||
};
|
};
|
||||||
use std::{collections::HashMap, f32::consts::PI};
|
use std::{collections::HashMap, f32::consts::PI};
|
||||||
|
|
||||||
use crate::{
|
use crate::data::ShipPersonality;
|
||||||
|
|
||||||
|
use super::{
|
||||||
controller::ShipController,
|
controller::ShipController,
|
||||||
objects::{SySimProjectile, SySimShip},
|
objects::{PhysProjectile, PhysSimShip},
|
||||||
util, ParticleBuilder, StepResources,
|
util, ParticleBuilder, PhysStepResources,
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: replace with a more generic handle
|
// TODO: replace with a more generic handle
|
||||||
/// A handle for a ship in this simulation
|
/// A handle for a ship in this simulation
|
||||||
/// This lets other crates reference ships
|
/// This lets other crates reference ships
|
||||||
/// without including `rapier2d`.
|
/// without including `rapier2d`.
|
||||||
pub struct SySimShipHandle(pub ColliderHandle);
|
pub struct PhysSimShipHandle(pub ColliderHandle);
|
||||||
|
|
||||||
/// Manages the physics state of one system
|
/// Manages the physics state of one system
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct SystemSim {
|
pub struct PhysSim {
|
||||||
/// The system this sim is attached to
|
/// The system this sim is attached to
|
||||||
_system: SystemHandle,
|
_system: SystemHandle,
|
||||||
|
|
||||||
rigid_body_set: RigidBodySet,
|
rigid_body_set: RigidBodySet,
|
||||||
collider_set: ColliderSet,
|
collider_set: ColliderSet,
|
||||||
|
|
||||||
projectiles: HashMap<ColliderHandle, SySimProjectile>,
|
projectiles: HashMap<ColliderHandle, PhysProjectile>,
|
||||||
ships: HashMap<ColliderHandle, SySimShip>,
|
ships: HashMap<ColliderHandle, PhysSimShip>,
|
||||||
ship_behaviors: HashMap<ColliderHandle, ShipController>,
|
ship_behaviors: HashMap<ColliderHandle, ShipController>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Private methods
|
// Private methods
|
||||||
impl<'a> SystemSim {
|
impl<'a> PhysSim {
|
||||||
fn remove_projectile(
|
fn remove_projectile(
|
||||||
&mut self,
|
&mut self,
|
||||||
res: &mut StepResources,
|
res: &mut PhysStepResources,
|
||||||
c: ColliderHandle,
|
c: ColliderHandle,
|
||||||
) -> Option<(RigidBody, SySimProjectile)> {
|
) -> Option<(RigidBody, PhysProjectile)> {
|
||||||
let p = match self.projectiles.remove(&c) {
|
let p = match self.projectiles.remove(&c) {
|
||||||
Some(p) => p,
|
Some(p) => p,
|
||||||
None => return None,
|
None => return None,
|
||||||
|
@ -66,7 +67,7 @@ impl<'a> SystemSim {
|
||||||
return Some((r, p));
|
return Some((r, p));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn remove_ship(&mut self, res: &mut StepResources, colliderhandle: ColliderHandle) {
|
fn remove_ship(&mut self, res: &mut PhysStepResources, colliderhandle: ColliderHandle) {
|
||||||
let ship = match self.ships.get(&colliderhandle) {
|
let ship = match self.ships.get(&colliderhandle) {
|
||||||
None => return,
|
None => return,
|
||||||
Some(s) => s,
|
Some(s) => s,
|
||||||
|
@ -86,7 +87,7 @@ impl<'a> SystemSim {
|
||||||
|
|
||||||
fn collide_projectile_ship(
|
fn collide_projectile_ship(
|
||||||
&mut self,
|
&mut self,
|
||||||
res: &mut StepResources,
|
res: &mut PhysStepResources,
|
||||||
projectile_h: ColliderHandle,
|
projectile_h: ColliderHandle,
|
||||||
ship_h: ColliderHandle,
|
ship_h: ColliderHandle,
|
||||||
) {
|
) {
|
||||||
|
@ -151,7 +152,7 @@ impl<'a> SystemSim {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Public methods
|
// Public methods
|
||||||
impl SystemSim {
|
impl PhysSim {
|
||||||
/// Create a new physics system
|
/// Create a new physics system
|
||||||
pub fn new(_ct: &Content, system: SystemHandle) -> Self {
|
pub fn new(_ct: &Content, system: SystemHandle) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
@ -172,7 +173,7 @@ impl SystemSim {
|
||||||
faction: FactionHandle,
|
faction: FactionHandle,
|
||||||
personality: ShipPersonality,
|
personality: ShipPersonality,
|
||||||
position: Point2<f32>,
|
position: Point2<f32>,
|
||||||
) -> SySimShipHandle {
|
) -> PhysSimShipHandle {
|
||||||
let ship_content = ct.get_ship(handle);
|
let ship_content = ct.get_ship(handle);
|
||||||
let cl = ColliderBuilder::convex_decomposition(
|
let cl = ColliderBuilder::convex_decomposition(
|
||||||
&ship_content.collision.points[..],
|
&ship_content.collision.points[..],
|
||||||
|
@ -205,10 +206,10 @@ impl SystemSim {
|
||||||
|
|
||||||
self.ships.insert(
|
self.ships.insert(
|
||||||
collider,
|
collider,
|
||||||
SySimShip::new(ct, handle, personality, faction, ridid_body, collider),
|
PhysSimShip::new(ct, handle, personality, faction, ridid_body, collider),
|
||||||
);
|
);
|
||||||
|
|
||||||
return SySimShipHandle(collider);
|
return PhysSimShipHandle(collider);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Update a player ship's controls
|
/// Update a player ship's controls
|
||||||
|
@ -229,7 +230,7 @@ impl SystemSim {
|
||||||
/// - updates ship controls (runs behaviors)
|
/// - updates ship controls (runs behaviors)
|
||||||
/// - applies ship controls
|
/// - applies ship controls
|
||||||
/// - creates projectiles
|
/// - creates projectiles
|
||||||
fn step_ships(&mut self, res: &mut StepResources) {
|
fn step_ships(&mut self, res: &mut PhysStepResources) {
|
||||||
// We can't apply these right away since self is borrowed
|
// We can't apply these right away since self is borrowed
|
||||||
// by the iterator
|
// by the iterator
|
||||||
// TODO: don't allocate!
|
// TODO: don't allocate!
|
||||||
|
@ -350,7 +351,7 @@ impl SystemSim {
|
||||||
|
|
||||||
self.projectiles.insert(
|
self.projectiles.insert(
|
||||||
collider.clone(),
|
collider.clone(),
|
||||||
SySimProjectile::new(
|
PhysProjectile::new(
|
||||||
outfit.projectile.clone(),
|
outfit.projectile.clone(),
|
||||||
rigid_body,
|
rigid_body,
|
||||||
ship.data.get_faction(),
|
ship.data.get_faction(),
|
||||||
|
@ -361,7 +362,7 @@ impl SystemSim {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Step this physics system by `t` seconds
|
/// Step this physics system by `t` seconds
|
||||||
pub fn step(&mut self, mut res: StepResources) {
|
pub fn step(&mut self, mut res: PhysStepResources) {
|
||||||
res.timing.start_physics_ships();
|
res.timing.start_physics_ships();
|
||||||
self.step_ships(&mut res);
|
self.step_ships(&mut res);
|
||||||
res.timing.mark_physics_ships();
|
res.timing.mark_physics_ships();
|
||||||
|
@ -441,14 +442,14 @@ impl SystemSim {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Public getters
|
// Public getters
|
||||||
impl SystemSim {
|
impl PhysSim {
|
||||||
/// Get a ship physics object
|
/// Get a ship physics object
|
||||||
pub fn get_ship(&self, ship: &SySimShipHandle) -> Option<&SySimShip> {
|
pub fn get_ship(&self, ship: &PhysSimShipHandle) -> Option<&PhysSimShip> {
|
||||||
self.ships.get(&ship.0)
|
self.ships.get(&ship.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a ship physics object
|
/// Get a ship physics object
|
||||||
pub fn get_ship_mut(&mut self, ship: &SySimShipHandle) -> Option<&mut SySimShip> {
|
pub fn get_ship_mut(&mut self, ship: &PhysSimShipHandle) -> Option<&mut PhysSimShip> {
|
||||||
self.ships.get_mut(&ship.0)
|
self.ships.get_mut(&ship.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -463,19 +464,19 @@ impl SystemSim {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Iterate over all ships in this physics system
|
/// Iterate over all ships in this physics system
|
||||||
pub fn iter_ship_body(&self) -> impl Iterator<Item = (&SySimShip, &RigidBody)> + '_ {
|
pub fn iter_ship_body(&self) -> impl Iterator<Item = (&PhysSimShip, &RigidBody)> + '_ {
|
||||||
self.ships
|
self.ships
|
||||||
.values()
|
.values()
|
||||||
.map(|x| (x, self.rigid_body_set.get(x.rigid_body).unwrap()))
|
.map(|x| (x, self.rigid_body_set.get(x.rigid_body).unwrap()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Iterate over all ships in this physics system
|
/// Iterate over all ships in this physics system
|
||||||
pub fn iter_ships(&self) -> impl Iterator<Item = &SySimShip> + '_ {
|
pub fn iter_ships(&self) -> impl Iterator<Item = &PhysSimShip> + '_ {
|
||||||
self.ships.values()
|
self.ships.values()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Iterate over all ships in this physics system
|
/// Iterate over all ships in this physics system
|
||||||
pub fn iter_projectiles(&self) -> impl Iterator<Item = &SySimProjectile> + '_ {
|
pub fn iter_projectiles(&self) -> impl Iterator<Item = &PhysProjectile> + '_ {
|
||||||
self.projectiles.values()
|
self.projectiles.values()
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -48,7 +48,7 @@ impl Timing {
|
||||||
self.physics_ship_timer = Instant::now();
|
self.physics_ship_timer = Instant::now();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Record galaxy simulation time.
|
/// Record total frame compute time
|
||||||
pub fn mark_frame(&mut self) {
|
pub fn mark_frame(&mut self) {
|
||||||
self.frame = self.frame_timer.elapsed();
|
self.frame = self.frame_timer.elapsed();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue