diff --git a/crates/galactica/src/game.rs b/crates/galactica/src/game.rs index 6d45114..d508620 100644 --- a/crates/galactica/src/game.rs +++ b/crates/galactica/src/game.rs @@ -45,10 +45,7 @@ impl Game { //o1.add_gun(&ct, content::GunHandle { index: 0 }); //o1.add_gun(&ct, content::GunHandle { index: 0 }); - let mut o1 = OutfitSet::new(ss.space, &[]); - o1.add(&ct.get_outfit(content::OutfitHandle { index: 0 })); - //o1.add_gun(&ct, content::GunHandle { index: 0 }); - + print!("{:?}", o1); let player = gamedata.create_ship( &ct, content::ShipHandle { index: 0 }, @@ -67,6 +64,10 @@ impl Game { &content::SystemHandle { index: 0 }, ); + let mut o1 = OutfitSet::new(ss.space, &[]); + o1.add(&ct.get_outfit(content::OutfitHandle { index: 0 })); + //o1.add_gun(&ct, content::GunHandle { index: 0 }); + gamedata.create_ship( &ct, content::ShipHandle { index: 0 }, diff --git a/crates/gameobject/src/ship/outfitset.rs b/crates/gameobject/src/ship/outfitset.rs index ba4d6f5..a888d1a 100644 --- a/crates/gameobject/src/ship/outfitset.rs +++ b/crates/gameobject/src/ship/outfitset.rs @@ -1,6 +1,6 @@ use std::collections::HashMap; -use content::{GunPoint, OutfitHandle, OutfitSpace}; +use content::{GunPoint, OutfitHandle, OutfitSpace, SpriteHandle}; use galactica_content as content; /// Possible outcomes when adding an outfit @@ -98,6 +98,12 @@ impl OutfitSet { generation: o.shield_generation, }); + if self.outfits.contains_key(&o.handle) { + *self.outfits.get_mut(&o.handle).unwrap() += 1; + } else { + self.outfits.insert(o.handle, 1); + } + return OutfitAddResult::Ok; } @@ -131,6 +137,17 @@ impl OutfitSet { return OutfitRemoveResult::Ok; } + + // TODO: pick these better + pub fn get_flare_sprite(&self, ct: &content::Content) -> Option { + for i in self.outfits.keys() { + let c = ct.get_outfit(*i); + if c.engine_flare_sprite.is_some() { + return c.engine_flare_sprite; + } + } + return None; + } } // Simple getters to make sure nobody meddles with our internal state diff --git a/crates/render/src/gpustate/world.rs b/crates/render/src/gpustate/world.rs index 11353e1..70e84f7 100644 --- a/crates/render/src/gpustate/world.rs +++ b/crates/render/src/gpustate/world.rs @@ -22,7 +22,7 @@ impl GPUState { s: &ShipWorldObject, ) { let r = state.world.get_rigid_body(s.rigid_body).unwrap(); - let ship = state.data.get_ship(s.data_handle); + let ship = state.data.get_ship(s.data_handle).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! @@ -85,25 +85,18 @@ impl GPUState { ); self.vertex_buffers.object_counter += 1; - /* - // Draw engine flares if necessary - //if s.controls.thrust && !s.ship.is_dead() { - if s.controls.thrust { - for f in s.ship.outfits.iter_enginepoints() { - let flare = match s.ship.outfits.get_flare_sprite() { - None => continue, - Some(s) => s, - }; - + let flare = ship.get_outfits().get_flare_sprite(state.content); + if s.get_controls().thrust && flare.is_some() && !ship.is_dead() { + for engine_point in &ship_cnt.engines { self.queue.write_buffer( &self.global_uniform.object_buffer, ObjectData::SIZE * self.vertex_buffers.object_counter as u64, bytemuck::cast_slice(&[ObjectData { - xpos: f.pos.x, - ypos: f.pos.y - f.size / 2.0, + xpos: engine_point.pos.x, + ypos: engine_point.pos.y - engine_point.size / 2.0, zpos: 1.0, angle: 0.0, - size: f.size, + size: engine_point.size, parent: idx as u32, is_child: 1, _padding: Default::default(), @@ -122,14 +115,13 @@ impl GPUState { &self.vertex_buffers.object.instances, ObjectInstance::SIZE * self.vertex_buffers.object_counter, bytemuck::cast_slice(&[ObjectInstance { - sprite_index: flare.get_index(), + sprite_index: flare.unwrap().get_index(), object_index: self.vertex_buffers.object_counter as u32, }]), ); self.vertex_buffers.object_counter += 1; } } - */ } pub(super) fn world_push_projectile( diff --git a/crates/world/src/objects/ship.rs b/crates/world/src/objects/ship.rs index 27d63c4..38561c0 100644 --- a/crates/world/src/objects/ship.rs +++ b/crates/world/src/objects/ship.rs @@ -304,3 +304,10 @@ impl ShipWorldObject { //} } } + +impl ShipWorldObject { + /// Get this ship's control state + pub fn get_controls(&self) -> &ShipControls { + &self.controls + } +}