Minor cleanup
parent
a417abf099
commit
99f198c9d6
|
@ -1,4 +1,4 @@
|
|||
[engine."plasma"]
|
||||
|
||||
thrust = 50
|
||||
flare.sprite = "flare::ion"
|
||||
flare.sprite_texture = "flare::ion"
|
||||
|
|
|
@ -10,7 +10,7 @@ rate = 0.2
|
|||
rate_rng = 0.1
|
||||
|
||||
|
||||
projectile.sprite = "projectile::blaster"
|
||||
projectile.sprite_texture = "projectile::blaster"
|
||||
# Height of projectile in game units
|
||||
projectile.size = 10
|
||||
projectile.size_rng = 0.0
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
[ship."Gypsum"]
|
||||
sprite = "ship::gypsum"
|
||||
sprite_texture = "ship::gypsum"
|
||||
size = 100
|
||||
mass = 10
|
||||
hull = 200
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
[system."12 Autumn Above"]
|
||||
|
||||
object.star.sprite = "star::star"
|
||||
object.star.sprite_texture = "star::star"
|
||||
object.star.position = [0.0, 0.0, 30.0]
|
||||
object.star.size = 2000
|
||||
|
||||
object.earth.sprite = "planet::earth"
|
||||
object.earth.sprite_texture = "planet::earth"
|
||||
object.earth.position.center = "star"
|
||||
object.earth.position.radius = 4000
|
||||
object.earth.position.angle = 0
|
||||
object.earth.position.z = 10.0
|
||||
object.earth.size = 1000
|
||||
|
||||
object.luna.sprite = "planet::luna"
|
||||
object.luna.sprite_texture = "planet::luna"
|
||||
object.luna.position.center = "earth"
|
||||
object.luna.position.radius = 1600
|
||||
object.luna.position.angle = 135
|
||||
|
|
|
@ -17,7 +17,7 @@ pub(super) mod syntax {
|
|||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct Flare {
|
||||
pub sprite: String,
|
||||
pub sprite_texture: String,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ pub struct Engine {
|
|||
/// The flare sprite this engine creates.
|
||||
/// Its location and size is determined by a ship's
|
||||
/// engine points.
|
||||
pub flare_sprite: TextureHandle,
|
||||
pub flare_sprite_texture: TextureHandle,
|
||||
}
|
||||
|
||||
impl super::Build for Engine {
|
||||
|
@ -41,11 +41,11 @@ impl super::Build for Engine {
|
|||
|
||||
fn build(engine: Self::InputSyntax, ct: &mut Content) -> Result<()> {
|
||||
for (engine_name, engine) in engine {
|
||||
let th = match ct.texture_index.get(&engine.flare.sprite) {
|
||||
let th = match ct.texture_index.get(&engine.flare.sprite_texture) {
|
||||
None => bail!(
|
||||
"In engine `{}`: texture `{}` doesn't exist",
|
||||
engine_name,
|
||||
engine.flare.sprite
|
||||
engine.flare.sprite_texture
|
||||
),
|
||||
Some(t) => *t,
|
||||
};
|
||||
|
@ -53,7 +53,7 @@ impl super::Build for Engine {
|
|||
ct.engines.push(Self {
|
||||
name: engine_name,
|
||||
thrust: engine.thrust,
|
||||
flare_sprite: th,
|
||||
flare_sprite_texture: th,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ pub(super) mod syntax {
|
|||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct Projectile {
|
||||
pub sprite: String,
|
||||
pub sprite_texture: String,
|
||||
pub size: f32,
|
||||
pub size_rng: f32,
|
||||
pub speed: f32,
|
||||
|
@ -59,7 +59,7 @@ pub struct Gun {
|
|||
#[derive(Debug, Clone)]
|
||||
pub struct Projectile {
|
||||
/// The projectile sprite
|
||||
pub sprite: TextureHandle,
|
||||
pub sprite_texture: TextureHandle,
|
||||
|
||||
/// The average size of this projectile
|
||||
/// (height in game units)
|
||||
|
@ -87,11 +87,11 @@ impl super::Build for Gun {
|
|||
|
||||
fn build(gun: Self::InputSyntax, ct: &mut Content) -> Result<()> {
|
||||
for (gun_name, gun) in gun {
|
||||
let th = match ct.texture_index.get(&gun.projectile.sprite) {
|
||||
let th = match ct.texture_index.get(&gun.projectile.sprite_texture) {
|
||||
None => bail!(
|
||||
"In gun `{}`: texture `{}` doesn't exist",
|
||||
gun_name,
|
||||
gun.projectile.sprite
|
||||
gun.projectile.sprite_texture
|
||||
),
|
||||
Some(t) => *t,
|
||||
};
|
||||
|
@ -102,7 +102,7 @@ impl super::Build for Gun {
|
|||
rate: gun.rate,
|
||||
rate_rng: gun.rate_rng,
|
||||
projectile: Projectile {
|
||||
sprite: th,
|
||||
sprite_texture: th,
|
||||
size: gun.projectile.size,
|
||||
size_rng: gun.projectile.size_rng,
|
||||
speed: gun.projectile.speed,
|
||||
|
|
|
@ -13,7 +13,7 @@ pub(super) mod syntax {
|
|||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct Ship {
|
||||
pub sprite: String,
|
||||
pub sprite_texture: String,
|
||||
pub size: f32,
|
||||
pub engines: Vec<Engine>,
|
||||
pub guns: Vec<Gun>,
|
||||
|
@ -52,7 +52,7 @@ pub struct Ship {
|
|||
pub name: String,
|
||||
|
||||
/// This ship's sprite
|
||||
pub sprite: TextureHandle,
|
||||
pub sprite_texture: TextureHandle,
|
||||
|
||||
/// The size of this ship.
|
||||
/// Measured as unrotated height,
|
||||
|
@ -113,11 +113,11 @@ impl super::Build for Ship {
|
|||
|
||||
fn build(ship: Self::InputSyntax, ct: &mut Content) -> Result<()> {
|
||||
for (ship_name, ship) in ship {
|
||||
let th = match ct.texture_index.get(&ship.sprite) {
|
||||
let th = match ct.texture_index.get(&ship.sprite_texture) {
|
||||
None => bail!(
|
||||
"In ship `{}`: texture `{}` doesn't exist",
|
||||
ship_name,
|
||||
ship.sprite
|
||||
ship.sprite_texture
|
||||
),
|
||||
Some(t) => *t,
|
||||
};
|
||||
|
@ -128,7 +128,7 @@ impl super::Build for Ship {
|
|||
ct.ships.push(Self {
|
||||
aspect,
|
||||
name: ship_name,
|
||||
sprite: th,
|
||||
sprite_texture: th,
|
||||
mass: ship.mass,
|
||||
size,
|
||||
hull: ship.hull,
|
||||
|
|
|
@ -17,7 +17,7 @@ pub(super) mod syntax {
|
|||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct Object {
|
||||
pub sprite: String,
|
||||
pub sprite_texture: String,
|
||||
pub position: Position,
|
||||
|
||||
pub size: f32,
|
||||
|
@ -94,7 +94,7 @@ pub struct System {
|
|||
#[derive(Debug)]
|
||||
pub struct Object {
|
||||
/// This object's sprite
|
||||
pub sprite: TextureHandle,
|
||||
pub sprite_texture: TextureHandle,
|
||||
|
||||
/// This object's size.
|
||||
/// Measured as height in game units.
|
||||
|
@ -185,17 +185,17 @@ impl super::Build for System {
|
|||
let mut cycle_detector = HashSet::new();
|
||||
cycle_detector.insert(label.clone());
|
||||
|
||||
let th = match ct.texture_index.get(&obj.sprite) {
|
||||
let th = match ct.texture_index.get(&obj.sprite_texture) {
|
||||
None => bail!(
|
||||
"In system `{}`: texture `{}` doesn't exist",
|
||||
system_name,
|
||||
obj.sprite
|
||||
obj.sprite_texture
|
||||
),
|
||||
Some(t) => *t,
|
||||
};
|
||||
|
||||
objects.push(Object {
|
||||
sprite: th,
|
||||
sprite_texture: th,
|
||||
position: resolve_position(&system.object, &obj, cycle_detector)
|
||||
.with_context(|| format!("In object {:#?}", label))?,
|
||||
size: obj.size,
|
||||
|
|
|
@ -103,7 +103,7 @@ impl<'a> ShipOutfits {
|
|||
// TODO: better way to pick flare texture
|
||||
self.engine_flare_sprites.clear();
|
||||
let t = if let Some(e) = self.iter_engines().next() {
|
||||
e.flare_sprite
|
||||
e.flare_sprite_texture
|
||||
} else {
|
||||
return;
|
||||
};
|
||||
|
|
|
@ -50,7 +50,7 @@ impl System {
|
|||
for o in &ct.objects {
|
||||
s.bodies.push(SystemObject {
|
||||
pos: o.position,
|
||||
sprite: o.sprite,
|
||||
sprite_texture: o.sprite_texture,
|
||||
size: o.size,
|
||||
angle: o.angle,
|
||||
});
|
||||
|
|
|
@ -4,7 +4,7 @@ use galactica_content::TextureHandle;
|
|||
use crate::render::Sprite;
|
||||
|
||||
pub struct SystemObject {
|
||||
pub sprite: TextureHandle,
|
||||
pub sprite_texture: TextureHandle,
|
||||
pub pos: Point3<f32>,
|
||||
pub size: f32,
|
||||
pub angle: Deg<f32>,
|
||||
|
@ -13,7 +13,7 @@ pub struct SystemObject {
|
|||
impl SystemObject {
|
||||
pub(super) fn get_sprite(&self) -> Sprite {
|
||||
return Sprite {
|
||||
texture: self.sprite.clone(),
|
||||
texture: self.sprite_texture,
|
||||
pos: self.pos,
|
||||
angle: self.angle,
|
||||
size: self.size,
|
||||
|
|
|
@ -10,7 +10,7 @@ use crate::{physics::util, render::Sprite};
|
|||
pub struct ProjectileBuilder {
|
||||
pub rigid_body: RigidBodyBuilder,
|
||||
pub collider: ColliderBuilder,
|
||||
pub sprite: TextureHandle,
|
||||
pub sprite_texture: TextureHandle,
|
||||
pub lifetime: f32,
|
||||
pub size: f32,
|
||||
pub damage: f32,
|
||||
|
@ -21,7 +21,7 @@ impl ProjectileBuilder {
|
|||
Projectile {
|
||||
rigid_body: r,
|
||||
collider: c,
|
||||
sprite: self.sprite,
|
||||
sprite_texture: self.sprite_texture,
|
||||
lifetime: self.lifetime,
|
||||
size: self.size,
|
||||
damage: self.damage,
|
||||
|
@ -33,7 +33,7 @@ impl ProjectileBuilder {
|
|||
pub struct Projectile {
|
||||
pub rigid_body: RigidBodyHandle,
|
||||
pub collider: ColliderHandle,
|
||||
pub sprite: TextureHandle,
|
||||
pub sprite_texture: TextureHandle,
|
||||
pub lifetime: f32,
|
||||
pub size: f32,
|
||||
pub damage: f32,
|
||||
|
@ -52,7 +52,7 @@ impl Projectile {
|
|||
let pos = util::rigidbody_position(r);
|
||||
let ang = util::rigidbody_angle(r);
|
||||
Sprite {
|
||||
texture: self.sprite.clone(),
|
||||
texture: self.sprite_texture,
|
||||
pos: Point3 {
|
||||
x: pos.x,
|
||||
y: pos.y,
|
||||
|
|
|
@ -42,7 +42,7 @@ pub struct Ship {
|
|||
pub physics_handle: ShipHandle,
|
||||
outfits: outfits::ShipOutfits,
|
||||
|
||||
sprite: TextureHandle,
|
||||
sprite_texture: TextureHandle,
|
||||
size: f32,
|
||||
pub hull: f32,
|
||||
pub controls: ShipControls,
|
||||
|
@ -62,7 +62,7 @@ impl Ship {
|
|||
Ship {
|
||||
physics_handle,
|
||||
outfits: o,
|
||||
sprite: c.sprite,
|
||||
sprite_texture: c.sprite_texture,
|
||||
size: c.size,
|
||||
hull: c.hull,
|
||||
controls: ShipControls::new(),
|
||||
|
@ -108,7 +108,7 @@ impl Ship {
|
|||
out.push(ProjectileBuilder {
|
||||
rigid_body: p_r,
|
||||
collider: p_c,
|
||||
sprite: g.kind.projectile.sprite,
|
||||
sprite_texture: g.kind.projectile.sprite_texture,
|
||||
lifetime: g.kind.projectile.lifetime
|
||||
+ rng.gen_range(
|
||||
-g.kind.projectile.lifetime_rng..=g.kind.projectile.lifetime_rng,
|
||||
|
@ -159,7 +159,7 @@ impl Ship {
|
|||
|
||||
Sprite {
|
||||
pos: (ship_pos.x, ship_pos.y, 1.0).into(),
|
||||
texture: self.sprite.clone(), // TODO: sprite texture should be easy to clone
|
||||
texture: self.sprite_texture.clone(), // TODO: sprite texture should be easy to clone
|
||||
angle: ship_ang,
|
||||
size: self.size,
|
||||
|
||||
|
|
|
@ -1,9 +1,77 @@
|
|||
use anyhow::Result;
|
||||
use galactica_content::{Content, TextureHandle};
|
||||
use image::GenericImageView;
|
||||
use std::{collections::HashMap, fs::File, io::Read, num::NonZeroU32};
|
||||
use wgpu::BindGroupLayout;
|
||||
|
||||
use super::{rawtexture::RawTexture, Texture};
|
||||
pub(super) struct RawTexture {
|
||||
pub(super) view: wgpu::TextureView,
|
||||
}
|
||||
|
||||
impl RawTexture {
|
||||
pub(super) fn from_bytes(
|
||||
device: &wgpu::Device,
|
||||
queue: &wgpu::Queue,
|
||||
bytes: &[u8],
|
||||
label: &str,
|
||||
) -> Result<Self> {
|
||||
let img = image::load_from_memory(bytes)?;
|
||||
Self::from_image(device, queue, &img, Some(label))
|
||||
}
|
||||
|
||||
pub(super) fn from_image(
|
||||
device: &wgpu::Device,
|
||||
queue: &wgpu::Queue,
|
||||
img: &image::DynamicImage,
|
||||
label: Option<&str>,
|
||||
) -> Result<Self> {
|
||||
let rgba = img.to_rgba8();
|
||||
let dimensions = img.dimensions();
|
||||
|
||||
let size = wgpu::Extent3d {
|
||||
width: dimensions.0,
|
||||
height: dimensions.1,
|
||||
depth_or_array_layers: 1,
|
||||
};
|
||||
|
||||
let texture = device.create_texture(&wgpu::TextureDescriptor {
|
||||
label,
|
||||
size,
|
||||
mip_level_count: 1,
|
||||
sample_count: 1,
|
||||
dimension: wgpu::TextureDimension::D2,
|
||||
format: wgpu::TextureFormat::Rgba8UnormSrgb,
|
||||
usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST,
|
||||
view_formats: &[],
|
||||
});
|
||||
|
||||
let view = texture.create_view(&wgpu::TextureViewDescriptor::default());
|
||||
|
||||
queue.write_texture(
|
||||
wgpu::ImageCopyTexture {
|
||||
aspect: wgpu::TextureAspect::All,
|
||||
texture: &texture,
|
||||
mip_level: 0,
|
||||
origin: wgpu::Origin3d::ZERO,
|
||||
},
|
||||
&rgba,
|
||||
wgpu::ImageDataLayout {
|
||||
offset: 0,
|
||||
bytes_per_row: Some(4 * dimensions.0),
|
||||
rows_per_image: Some(dimensions.1),
|
||||
},
|
||||
size,
|
||||
);
|
||||
|
||||
Ok(Self { view })
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Texture {
|
||||
pub index: u32, // Index in texture array
|
||||
pub aspect: f32, // width / height
|
||||
}
|
||||
|
||||
pub struct TextureArray {
|
||||
pub bind_group: wgpu::BindGroup,
|
|
@ -1,10 +0,0 @@
|
|||
mod array;
|
||||
mod rawtexture;
|
||||
|
||||
pub use array::TextureArray;
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Texture {
|
||||
pub index: u32, // Index in texture array
|
||||
pub aspect: f32, // width / height
|
||||
}
|
|
@ -1,65 +0,0 @@
|
|||
use anyhow::Result;
|
||||
use image::GenericImageView;
|
||||
|
||||
pub(super) struct RawTexture {
|
||||
pub(super) view: wgpu::TextureView,
|
||||
}
|
||||
|
||||
impl RawTexture {
|
||||
pub(super) fn from_bytes(
|
||||
device: &wgpu::Device,
|
||||
queue: &wgpu::Queue,
|
||||
bytes: &[u8],
|
||||
label: &str,
|
||||
) -> Result<Self> {
|
||||
let img = image::load_from_memory(bytes)?;
|
||||
Self::from_image(device, queue, &img, Some(label))
|
||||
}
|
||||
|
||||
pub(super) fn from_image(
|
||||
device: &wgpu::Device,
|
||||
queue: &wgpu::Queue,
|
||||
img: &image::DynamicImage,
|
||||
label: Option<&str>,
|
||||
) -> Result<Self> {
|
||||
let rgba = img.to_rgba8();
|
||||
let dimensions = img.dimensions();
|
||||
|
||||
let size = wgpu::Extent3d {
|
||||
width: dimensions.0,
|
||||
height: dimensions.1,
|
||||
depth_or_array_layers: 1,
|
||||
};
|
||||
|
||||
let texture = device.create_texture(&wgpu::TextureDescriptor {
|
||||
label,
|
||||
size,
|
||||
mip_level_count: 1,
|
||||
sample_count: 1,
|
||||
dimension: wgpu::TextureDimension::D2,
|
||||
format: wgpu::TextureFormat::Rgba8UnormSrgb,
|
||||
usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST,
|
||||
view_formats: &[],
|
||||
});
|
||||
|
||||
let view = texture.create_view(&wgpu::TextureViewDescriptor::default());
|
||||
|
||||
queue.write_texture(
|
||||
wgpu::ImageCopyTexture {
|
||||
aspect: wgpu::TextureAspect::All,
|
||||
texture: &texture,
|
||||
mip_level: 0,
|
||||
origin: wgpu::Origin3d::ZERO,
|
||||
},
|
||||
&rgba,
|
||||
wgpu::ImageDataLayout {
|
||||
offset: 0,
|
||||
bytes_per_row: Some(4 * dimensions.0),
|
||||
rows_per_image: Some(dimensions.1),
|
||||
},
|
||||
size,
|
||||
);
|
||||
|
||||
Ok(Self { view })
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue