Compare commits
4 Commits
0af265040c
...
1719faa555
Author | SHA1 | Date |
---|---|---|
Mark | 1719faa555 | |
Mark | 33962f18e9 | |
Mark | 5a276459e9 | |
Mark | 2e57840b7a |
2
assets
2
assets
|
@ -1 +1 @@
|
||||||
Subproject commit 7f9886acae8ab62827821ba4f5271689f9a67d4d
|
Subproject commit a20bd1dad1eb90a7e8ec8010bdba03fdc2e477bd
|
|
@ -3,9 +3,7 @@ use cgmath::{Deg, Point2, Point3};
|
||||||
use crate::{
|
use crate::{
|
||||||
content::{self, ship::Engine},
|
content::{self, ship::Engine},
|
||||||
physics::PhysicsBody,
|
physics::PhysicsBody,
|
||||||
render::Sprite,
|
render::{Sprite, SpriteTexture, Spriteable, SubSprite},
|
||||||
render::SpriteTexture,
|
|
||||||
render::Spriteable,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct Ship {
|
pub struct Ship {
|
||||||
|
@ -35,7 +33,7 @@ impl Spriteable for Ship {
|
||||||
Some(
|
Some(
|
||||||
self.engines
|
self.engines
|
||||||
.iter()
|
.iter()
|
||||||
.map(|e| Sprite {
|
.map(|e| SubSprite {
|
||||||
pos: Point3 {
|
pos: Point3 {
|
||||||
x: e.pos.x,
|
x: e.pos.x,
|
||||||
y: e.pos.y,
|
y: e.pos.y,
|
||||||
|
@ -44,7 +42,6 @@ impl Spriteable for Ship {
|
||||||
texture: SpriteTexture("flare::ion".to_owned()),
|
texture: SpriteTexture("flare::ion".to_owned()),
|
||||||
angle: Deg(0.0),
|
angle: Deg(0.0),
|
||||||
size: e.size,
|
size: e.size,
|
||||||
children: None,
|
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
)
|
)
|
||||||
|
|
|
@ -9,6 +9,7 @@ use super::{
|
||||||
consts::{OPENGL_TO_WGPU_MATRIX, SPRITE_INSTANCE_LIMIT, STARFIELD_INSTANCE_LIMIT},
|
consts::{OPENGL_TO_WGPU_MATRIX, SPRITE_INSTANCE_LIMIT, STARFIELD_INSTANCE_LIMIT},
|
||||||
globaldata::{GlobalData, GlobalDataContent},
|
globaldata::{GlobalData, GlobalDataContent},
|
||||||
pipeline::PipelineBuilder,
|
pipeline::PipelineBuilder,
|
||||||
|
sprite::SubSprite,
|
||||||
texturearray::TextureArray,
|
texturearray::TextureArray,
|
||||||
vertexbuffer::{
|
vertexbuffer::{
|
||||||
consts::{SPRITE_INDICES, SPRITE_VERTICES},
|
consts::{SPRITE_INDICES, SPRITE_VERTICES},
|
||||||
|
@ -285,15 +286,10 @@ impl GPUState {
|
||||||
&self,
|
&self,
|
||||||
game: &Game,
|
game: &Game,
|
||||||
instances: &mut Vec<SpriteInstance>,
|
instances: &mut Vec<SpriteInstance>,
|
||||||
s: Sprite,
|
s: SubSprite,
|
||||||
parent_pos: Point2<f32>,
|
parent_pos: Point2<f32>,
|
||||||
parent_angle: Deg<f32>,
|
parent_angle: Deg<f32>,
|
||||||
) {
|
) {
|
||||||
// TODO: clean up
|
|
||||||
if s.children.is_some() {
|
|
||||||
panic!("Child sprites must not have child sprites!")
|
|
||||||
}
|
|
||||||
|
|
||||||
let texture = self.texture_array.get_sprite_texture(s.texture);
|
let texture = self.texture_array.get_sprite_texture(s.texture);
|
||||||
let scale = s.size / (s.pos.z * game.camera.zoom);
|
let scale = s.size / (s.pos.z * game.camera.zoom);
|
||||||
let sprite_aspect_and_scale =
|
let sprite_aspect_and_scale =
|
||||||
|
|
|
@ -7,8 +7,10 @@ mod texturearray;
|
||||||
mod vertexbuffer;
|
mod vertexbuffer;
|
||||||
|
|
||||||
pub use gpustate::GPUState;
|
pub use gpustate::GPUState;
|
||||||
pub use sprite::{Sprite, Spriteable};
|
pub use sprite::{Sprite, Spriteable, SubSprite};
|
||||||
|
|
||||||
/// A handle to a sprite texture
|
/// A handle to a sprite texture
|
||||||
|
/// TODO: This should be easy to copy,
|
||||||
|
/// but string references create unnecessary complexity
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct SpriteTexture(pub String);
|
pub struct SpriteTexture(pub String);
|
||||||
|
|
|
@ -3,7 +3,7 @@ use cgmath::{Deg, Point3};
|
||||||
use super::SpriteTexture;
|
use super::SpriteTexture;
|
||||||
|
|
||||||
pub struct Sprite {
|
pub struct Sprite {
|
||||||
/// Name of the sprite to draw
|
/// The sprite texture to draw
|
||||||
pub texture: SpriteTexture,
|
pub texture: SpriteTexture,
|
||||||
|
|
||||||
/// This object's position, in world coordinates.
|
/// This object's position, in world coordinates.
|
||||||
|
@ -18,13 +18,26 @@ pub struct Sprite {
|
||||||
pub angle: Deg<f32>,
|
pub angle: Deg<f32>,
|
||||||
|
|
||||||
/// Sprites that should be drawn relative to this sprite.
|
/// Sprites that should be drawn relative to this sprite.
|
||||||
/// Coordinates of sprites in this array will be interpreted
|
pub children: Option<Vec<SubSprite>>,
|
||||||
/// as world units, relative to the center of this sprite,
|
}
|
||||||
/// before any rotation or scaling.
|
|
||||||
/// Children rotate with their parent sprite.
|
pub struct SubSprite {
|
||||||
///
|
/// The sprite texture to draw
|
||||||
/// Note that child sprites may NOT have children.
|
pub texture: SpriteTexture,
|
||||||
pub children: Option<Vec<Sprite>>,
|
|
||||||
|
/// This object's position, in world coordinates.
|
||||||
|
/// This is relative to this sprite's parent.
|
||||||
|
pub pos: Point3<f32>,
|
||||||
|
|
||||||
|
/// The size of this sprite,
|
||||||
|
/// given as height in world units.
|
||||||
|
pub size: f32,
|
||||||
|
|
||||||
|
/// This sprite's rotation
|
||||||
|
/// (relative to north, measured ccw)
|
||||||
|
/// Just as position, this is relative to this
|
||||||
|
/// subsprite's parent sprite.
|
||||||
|
pub angle: Deg<f32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Spriteable {
|
pub trait Spriteable {
|
||||||
|
|
|
@ -45,7 +45,7 @@ impl TextureArray {
|
||||||
});
|
});
|
||||||
|
|
||||||
let bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
let bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
||||||
label: Some("texture_bind_group_layout"),
|
label: Some("TextureArray bind group layout"),
|
||||||
entries: &[
|
entries: &[
|
||||||
// Texture data
|
// Texture data
|
||||||
wgpu::BindGroupLayoutEntry {
|
wgpu::BindGroupLayoutEntry {
|
||||||
|
@ -70,7 +70,7 @@ impl TextureArray {
|
||||||
|
|
||||||
let views: Vec<&wgpu::TextureView> = loader.texture_data.iter().map(|x| &x.view).collect();
|
let views: Vec<&wgpu::TextureView> = loader.texture_data.iter().map(|x| &x.view).collect();
|
||||||
let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
|
let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
|
||||||
label: Some("texture_bind_group"),
|
label: Some("TextureArray bind group"),
|
||||||
layout: &bind_group_layout,
|
layout: &bind_group_layout,
|
||||||
entries: &[
|
entries: &[
|
||||||
wgpu::BindGroupEntry {
|
wgpu::BindGroupEntry {
|
||||||
|
|
Loading…
Reference in New Issue