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