Rc'd content struct
parent
40fb31ad7e
commit
1343c01379
|
@ -4,11 +4,12 @@ use galactica_system::data::ShipPersonality;
|
|||
use galactica_system::phys::{PhysImage, PhysSim, PhysSimShipHandle, PhysStepResources};
|
||||
use galactica_util::timing::Timing;
|
||||
use nalgebra::Point2;
|
||||
use std::rc::Rc;
|
||||
use std::time::Instant;
|
||||
|
||||
pub struct Game {
|
||||
// Core game data
|
||||
ct: Content,
|
||||
ct: Rc<Content>,
|
||||
phys_sim: PhysSim,
|
||||
timing: Timing,
|
||||
start_instant: Instant,
|
||||
|
@ -43,7 +44,7 @@ impl<'a> Game {
|
|||
return player;
|
||||
}
|
||||
|
||||
pub fn new(ct: Content) -> Self {
|
||||
pub fn new(ct: Rc<Content>) -> Self {
|
||||
let mut phys_sim = PhysSim::new(&ct, SystemHandle { index: 0 });
|
||||
|
||||
let a = phys_sim.add_ship(
|
||||
|
@ -118,7 +119,7 @@ impl<'a> Game {
|
|||
self.timing.start_frame();
|
||||
self.phys_sim.step(
|
||||
PhysStepResources {
|
||||
ct: &self.ct,
|
||||
ct: self.ct.clone(),
|
||||
t: self.last_update.elapsed().as_secs_f32() * self.time_scale,
|
||||
timing: &mut self.timing,
|
||||
},
|
||||
|
|
|
@ -21,6 +21,7 @@ use nalgebra::Vector2;
|
|||
use std::{
|
||||
fs,
|
||||
path::{Path, PathBuf},
|
||||
rc::Rc,
|
||||
time::Instant,
|
||||
};
|
||||
use winit::{
|
||||
|
@ -112,17 +113,17 @@ fn try_main() -> Result<()> {
|
|||
}
|
||||
|
||||
// TODO: pretty error if missing (also in cli)
|
||||
let content = Content::load_dir(
|
||||
let content = Rc::new(Content::load_dir(
|
||||
PathBuf::from("./content"),
|
||||
PathBuf::from("./assets"),
|
||||
atlas_index,
|
||||
)?;
|
||||
)?);
|
||||
|
||||
let event_loop = EventLoop::new();
|
||||
let window = WindowBuilder::new().build(&event_loop).unwrap();
|
||||
let mut gpu = pollster::block_on(galactica_render::GPUState::new(
|
||||
window,
|
||||
&content,
|
||||
content.clone(),
|
||||
RenderScenes::System,
|
||||
))?;
|
||||
gpu.init(&content);
|
||||
|
@ -147,7 +148,7 @@ fn try_main() -> Result<()> {
|
|||
camera_pos: player.camera.pos,
|
||||
camera_zoom: player.camera.zoom,
|
||||
current_time: game.get_current_time(),
|
||||
ct: &content,
|
||||
ct: content.clone(),
|
||||
phys_img: &phys_img,
|
||||
player: &player,
|
||||
time_since_last_run: last_run.elapsed().as_secs_f32(),
|
||||
|
|
|
@ -174,7 +174,7 @@ impl PhysEffect {
|
|||
return;
|
||||
}
|
||||
|
||||
self.anim.step(res.ct, res.t);
|
||||
self.anim.step(&res.ct, res.t);
|
||||
self.lifetime -= res.t;
|
||||
|
||||
if self.lifetime <= 0.0 {
|
||||
|
|
|
@ -67,7 +67,7 @@ impl PhysProjectile {
|
|||
wrapper: &mut PhysWrapper,
|
||||
) {
|
||||
self.lifetime -= res.t;
|
||||
self.anim.step(res.ct, res.t);
|
||||
self.anim.step(&res.ct, res.t);
|
||||
|
||||
if self.lifetime <= 0.0 {
|
||||
self.destroy(res, new, wrapper, true);
|
||||
|
@ -102,7 +102,7 @@ impl PhysProjectile {
|
|||
None => {}
|
||||
Some(handle) => {
|
||||
new.effects.push(PhysEffect::new(
|
||||
res.ct,
|
||||
&res.ct,
|
||||
wrapper,
|
||||
*handle,
|
||||
*rb.translation(),
|
||||
|
|
|
@ -84,12 +84,12 @@ impl ShipCollapseSequence {
|
|||
let pos: Vector2<f32> = if let Some(pos) = spawner.pos {
|
||||
Vector2::new(pos.x, pos.y)
|
||||
} else {
|
||||
self.random_in_ship(res.ct, ship_content, &collider)
|
||||
self.random_in_ship(&res.ct, ship_content, &collider)
|
||||
};
|
||||
let pos = ship_pos + (ship_rot * pos);
|
||||
|
||||
new.effects.push(PhysEffect::new(
|
||||
res.ct,
|
||||
&res.ct,
|
||||
wrapper,
|
||||
spawner.effect,
|
||||
pos,
|
||||
|
@ -124,13 +124,13 @@ impl ShipCollapseSequence {
|
|||
let pos = if let Some(pos) = spawner.pos {
|
||||
Vector2::new(pos.x, pos.y)
|
||||
} else {
|
||||
self.random_in_ship(res.ct, ship_content, &collider)
|
||||
self.random_in_ship(&res.ct, ship_content, &collider)
|
||||
};
|
||||
|
||||
// Position, adjusted for ship rotation
|
||||
let pos = ship_pos + (ship_rot * pos);
|
||||
new.effects.push(PhysEffect::new(
|
||||
res.ct,
|
||||
&res.ct,
|
||||
wrapper,
|
||||
spawner.effect,
|
||||
pos,
|
||||
|
|
|
@ -100,32 +100,32 @@ impl PhysShip {
|
|||
}
|
||||
|
||||
self.data.step(res.t);
|
||||
self.anim.step(res.ct, res.t);
|
||||
self.anim.step(&res.ct, res.t);
|
||||
|
||||
for (_, e) in &mut self.engine_anim {
|
||||
e.step(res.ct, res.t);
|
||||
e.step(&res.ct, res.t);
|
||||
}
|
||||
|
||||
// Flare animations
|
||||
if !self.controls.thrust && self.last_controls.thrust {
|
||||
let flare = self.get_flare(res.ct);
|
||||
let flare = self.get_flare(&res.ct);
|
||||
if flare.is_some() {
|
||||
let flare_outfit = flare.unwrap();
|
||||
let flare = res.ct.get_outfit(flare_outfit);
|
||||
if flare.engine_flare_on_stop.is_some() {
|
||||
for (_, e) in &mut self.engine_anim {
|
||||
e.jump_to(res.ct, flare.engine_flare_on_stop.unwrap());
|
||||
e.jump_to(&res.ct, flare.engine_flare_on_stop.unwrap());
|
||||
}
|
||||
}
|
||||
};
|
||||
} else if self.controls.thrust && !self.last_controls.thrust {
|
||||
let flare = self.get_flare(res.ct);
|
||||
let flare = self.get_flare(&res.ct);
|
||||
if flare.is_some() {
|
||||
let flare_outfit = flare.unwrap();
|
||||
let flare = res.ct.get_outfit(flare_outfit);
|
||||
if flare.engine_flare_on_start.is_some() {
|
||||
for (_, e) in &mut self.engine_anim {
|
||||
e.jump_to(res.ct, flare.engine_flare_on_start.unwrap());
|
||||
e.jump_to(&res.ct, flare.engine_flare_on_start.unwrap());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -232,7 +232,7 @@ impl PhysShip {
|
|||
.collect();
|
||||
|
||||
for (gun_point, outfit) in pairs {
|
||||
if self.data.fire_gun(res.ct, &gun_point) {
|
||||
if self.data.fire_gun(&res.ct, &gun_point) {
|
||||
let outfit = outfit.unwrap();
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
|
@ -285,7 +285,7 @@ impl PhysShip {
|
|||
let collider = wrapper.insert_collider(collider, rigid_body);
|
||||
|
||||
new.projectiles.push(PhysProjectile::new(
|
||||
res.ct,
|
||||
&res.ct,
|
||||
outfit.projectile.clone(),
|
||||
rigid_body,
|
||||
self.data.get_faction(),
|
||||
|
@ -456,7 +456,7 @@ impl PhysShip {
|
|||
let pos = ship_pos + (Rotation2::new(ship_ang) * pos);
|
||||
|
||||
new.effects.push(PhysEffect::new(
|
||||
res.ct,
|
||||
&res.ct,
|
||||
wrapper,
|
||||
e.effect,
|
||||
pos,
|
||||
|
|
|
@ -131,7 +131,7 @@ impl PhysSim {
|
|||
None => {}
|
||||
Some(x) => {
|
||||
self.effects.push(PhysEffect::new(
|
||||
res.ct,
|
||||
&res.ct,
|
||||
&mut self.wrapper,
|
||||
*x,
|
||||
pos,
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
use std::rc::Rc;
|
||||
|
||||
use galactica_content::Content;
|
||||
use galactica_util::timing::Timing;
|
||||
|
||||
/// External resources we need to compute time steps
|
||||
pub struct PhysStepResources<'a> {
|
||||
/// Game content
|
||||
pub ct: &'a Content,
|
||||
pub ct: Rc<Content>,
|
||||
|
||||
/// Length of time step
|
||||
pub t: f32,
|
||||
|
|
Loading…
Reference in New Issue