Minor cleanup

master
Mark 2023-12-31 18:48:35 -08:00
parent fc728eaf0e
commit 975d2e6590
Signed by: Mark
GPG Key ID: C6D63995FE72FD80
18 changed files with 47 additions and 54 deletions

View File

@ -5,10 +5,10 @@ use cgmath::Deg;
use crate::{handle::TextureHandle, Content}; use crate::{handle::TextureHandle, Content};
use super::OutfitSpace; use crate::OutfitSpace;
pub(crate) mod syntax { pub(crate) mod syntax {
use super::super::shared; use crate::part::shared;
use serde::Deserialize; use serde::Deserialize;
// Raw serde syntax structs. // Raw serde syntax structs.
// These are never seen by code outside this crate. // These are never seen by code outside this crate.

View File

@ -2,12 +2,10 @@ use std::collections::HashMap;
use anyhow::{bail, Result}; use anyhow::{bail, Result};
use crate::{handle::TextureHandle, Content}; use crate::{handle::TextureHandle, Content, OutfitSpace};
use super::OutfitSpace;
pub(crate) mod syntax { pub(crate) mod syntax {
use super::super::shared; use crate::part::shared;
use serde::Deserialize; use serde::Deserialize;
// Raw serde syntax structs. // Raw serde syntax structs.
// These are never seen by code outside this crate. // These are never seen by code outside this crate.

View File

@ -4,12 +4,10 @@ use anyhow::{bail, Result};
use cgmath::Point2; use cgmath::Point2;
use nalgebra::{point, Point}; use nalgebra::{point, Point};
use crate::{handle::TextureHandle, Content}; use crate::{handle::TextureHandle, Content, OutfitSpace};
use super::OutfitSpace;
pub(crate) mod syntax { pub(crate) mod syntax {
use super::super::shared; use crate::part::shared;
use serde::Deserialize; use serde::Deserialize;
// Raw serde syntax structs. // Raw serde syntax structs.

View File

@ -5,8 +5,8 @@ use std::collections::{HashMap, HashSet};
use crate::{handle::TextureHandle, util::Polar, Content}; use crate::{handle::TextureHandle, util::Polar, Content};
pub(crate) mod syntax { pub(crate) mod syntax {
use super::HashMap;
use serde::Deserialize; use serde::Deserialize;
use std::collections::HashMap;
// Raw serde syntax structs. // Raw serde syntax structs.
// These are never seen by code outside this crate. // These are never seen by code outside this crate.

View File

@ -1,7 +1,6 @@
use anyhow::Result; use anyhow::Result;
use bytemuck; use bytemuck;
use cgmath::{Deg, EuclideanSpace, Matrix4, Point2, Vector2, Vector3}; use cgmath::{Deg, EuclideanSpace, Matrix4, Point2, Vector2, Vector3};
use galactica_content::Content;
use std::{iter, rc::Rc}; use std::{iter, rc::Rc};
use wgpu; use wgpu;
use winit::{ use winit::{
@ -10,9 +9,9 @@ use winit::{
window::Window, window::Window,
}; };
use super::{ use crate::{
consts::{OPENGL_TO_WGPU_MATRIX, SPRITE_INSTANCE_LIMIT, STARFIELD_INSTANCE_LIMIT}, consts::{OPENGL_TO_WGPU_MATRIX, SPRITE_INSTANCE_LIMIT, STARFIELD_INSTANCE_LIMIT},
consts_main, consts_main, content,
globaldata::{GlobalData, GlobalDataContent}, globaldata::{GlobalData, GlobalDataContent},
pipeline::PipelineBuilder, pipeline::PipelineBuilder,
sprite::ObjectSubSprite, sprite::ObjectSubSprite,
@ -50,7 +49,7 @@ struct VertexBuffers {
} }
impl GPUState { impl GPUState {
pub async fn new(window: Window, ct: &Content) -> Result<Self> { pub async fn new(window: Window, ct: &content::Content) -> Result<Self> {
let window_size = window.inner_size(); let window_size = window.inner_size();
let window_aspect = window_size.width as f32 / window_size.height as f32; let window_aspect = window_size.width as f32 / window_size.height as f32;

View File

@ -10,6 +10,7 @@ mod vertexbuffer;
mod consts_main; mod consts_main;
use cgmath::{Point3, Vector2}; use cgmath::{Point3, Vector2};
use galactica_content as content;
pub use gpustate::GPUState; pub use gpustate::GPUState;
pub use sprite::{AnchoredUiPosition, ObjectSprite, ObjectSubSprite, UiSprite}; pub use sprite::{AnchoredUiPosition, ObjectSprite, ObjectSubSprite, UiSprite};

View File

@ -1,8 +1,8 @@
use std::rc::Rc; use std::rc::Rc;
use wgpu; use wgpu;
use super::consts::{SHADER_MAIN_FRAGMENT, SHADER_MAIN_VERTEX}; use crate::consts::{SHADER_MAIN_FRAGMENT, SHADER_MAIN_VERTEX};
use super::vertexbuffer::VertexBuffer; use crate::vertexbuffer::VertexBuffer;
pub struct PipelineBuilder<'a> { pub struct PipelineBuilder<'a> {
// These are provided with new() // These are provided with new()

View File

@ -1,5 +1,5 @@
use crate::content;
use cgmath::{Deg, Point2, Point3}; use cgmath::{Deg, Point2, Point3};
use galactica_content::TextureHandle;
/// The location of a UI element, in one of a few /// The location of a UI element, in one of a few
/// possible coordinate systems. /// possible coordinate systems.
@ -21,7 +21,7 @@ pub enum AnchoredUiPosition {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct UiSprite { pub struct UiSprite {
/// The texture to use for this sprite /// The texture to use for this sprite
pub texture: TextureHandle, pub texture: content::TextureHandle,
/// This object's position, in logical (dpi-adjusted) pixels /// This object's position, in logical (dpi-adjusted) pixels
pub pos: AnchoredUiPosition, pub pos: AnchoredUiPosition,
@ -38,7 +38,7 @@ pub struct UiSprite {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct ObjectSprite { pub struct ObjectSprite {
/// The texture to use for this sprite /// The texture to use for this sprite
pub texture: TextureHandle, pub texture: content::TextureHandle,
/// This object's center, in world coordinates. /// This object's center, in world coordinates.
pub pos: Point3<f32>, pub pos: Point3<f32>,
@ -59,7 +59,7 @@ pub struct ObjectSprite {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct ObjectSubSprite { pub struct ObjectSubSprite {
/// The sprite texture to draw /// The sprite texture to draw
pub texture: TextureHandle, pub texture: content::TextureHandle,
/// This object's position, in world coordinates. /// This object's position, in world coordinates.
/// This is relative to this sprite's parent. /// This is relative to this sprite's parent.

View File

@ -1,15 +1,15 @@
use crate::content;
use anyhow::Result; use anyhow::Result;
use galactica_content::{Content, TextureHandle};
use image::GenericImageView; use image::GenericImageView;
use std::{collections::HashMap, fs::File, io::Read, num::NonZeroU32}; use std::{collections::HashMap, fs::File, io::Read, num::NonZeroU32};
use wgpu::BindGroupLayout; use wgpu::BindGroupLayout;
pub(super) struct RawTexture { pub(crate) struct RawTexture {
pub(super) view: wgpu::TextureView, pub(crate) view: wgpu::TextureView,
} }
impl RawTexture { impl RawTexture {
pub(super) fn from_bytes( pub(crate) fn from_bytes(
device: &wgpu::Device, device: &wgpu::Device,
queue: &wgpu::Queue, queue: &wgpu::Queue,
bytes: &[u8], bytes: &[u8],
@ -19,7 +19,7 @@ impl RawTexture {
Self::from_image(device, queue, &img, Some(label)) Self::from_image(device, queue, &img, Some(label))
} }
pub(super) fn from_image( pub(crate) fn from_image(
device: &wgpu::Device, device: &wgpu::Device,
queue: &wgpu::Queue, queue: &wgpu::Queue,
img: &image::DynamicImage, img: &image::DynamicImage,
@ -76,8 +76,8 @@ pub struct Texture {
pub struct TextureArray { pub struct TextureArray {
pub bind_group: wgpu::BindGroup, pub bind_group: wgpu::BindGroup,
pub bind_group_layout: BindGroupLayout, pub bind_group_layout: BindGroupLayout,
starfield_handle: TextureHandle, starfield_handle: content::TextureHandle,
textures: HashMap<TextureHandle, Texture>, textures: HashMap<content::TextureHandle, Texture>,
} }
impl TextureArray { impl TextureArray {
@ -85,14 +85,14 @@ impl TextureArray {
*self.textures.get(&self.starfield_handle).unwrap() *self.textures.get(&self.starfield_handle).unwrap()
} }
pub fn get_texture(&self, handle: TextureHandle) -> Texture { pub fn get_texture(&self, handle: content::TextureHandle) -> Texture {
match self.textures.get(&handle) { match self.textures.get(&handle) {
Some(x) => *x, Some(x) => *x,
None => unreachable!("Tried to get a texture that doesn't exist"), None => unreachable!("Tried to get a texture that doesn't exist"),
} }
} }
pub fn new(device: &wgpu::Device, queue: &wgpu::Queue, ct: &Content) -> Result<Self> { pub fn new(device: &wgpu::Device, queue: &wgpu::Queue, ct: &content::Content) -> Result<Self> {
// Load all textures // Load all textures
let mut texture_data = Vec::new(); let mut texture_data = Vec::new();
let mut textures = HashMap::new(); let mut textures = HashMap::new();

View File

@ -1,13 +1,11 @@
use cgmath::{Deg, InnerSpace, Point2}; use cgmath::{Deg, InnerSpace, Point2};
use galactica_content as content;
use galactica_content::FactionHandle;
use galactica_render::{AnchoredUiPosition, ObjectSprite, UiSprite}; use galactica_render::{AnchoredUiPosition, ObjectSprite, UiSprite};
use std::time::Instant; use std::time::Instant;
use winit::event::{ElementState, MouseButton, MouseScrollDelta, TouchPhase, VirtualKeyCode}; use winit::event::{ElementState, MouseButton, MouseScrollDelta, TouchPhase, VirtualKeyCode};
use super::{camera::Camera, outfits, system::System}; use super::{camera::Camera, outfits, system::System};
use crate::{ use crate::{
consts, consts, content,
inputstatus::InputStatus, inputstatus::InputStatus,
physics::{util, Physics, ShipHandle}, physics::{util, Physics, ShipHandle},
shipbehavior::{self, ShipBehavior}, shipbehavior::{self, ShipBehavior},
@ -97,14 +95,14 @@ impl Game {
&ct.ships[0], &ct.ships[0],
o1, o1,
Point2 { x: 0.0, y: 0.0 }, Point2 { x: 0.0, y: 0.0 },
FactionHandle { index: 0 }, content::FactionHandle { index: 0 },
); );
let h2 = physics.add_ship( let h2 = physics.add_ship(
&ct.ships[0], &ct.ships[0],
outfits::ShipOutfits::new(&ct.ships[0]), outfits::ShipOutfits::new(&ct.ships[0]),
Point2 { x: 300.0, y: 300.0 }, Point2 { x: 300.0, y: 300.0 },
FactionHandle { index: 0 }, content::FactionHandle { index: 0 },
); );
let mut o2 = outfits::ShipOutfits::new(&ct.ships[0]); let mut o2 = outfits::ShipOutfits::new(&ct.ships[0]);
@ -117,7 +115,7 @@ impl Game {
x: -300.0, x: -300.0,
y: 300.0, y: 300.0,
}, },
FactionHandle { index: 1 }, content::FactionHandle { index: 1 },
); );
let mut shipbehaviors: Vec<Box<dyn ShipBehavior>> = Vec::new(); let mut shipbehaviors: Vec<Box<dyn ShipBehavior>> = Vec::new();

View File

@ -1,7 +1,8 @@
use cgmath::{Deg, Point3}; use cgmath::{Deg, Point3};
use galactica_content as content;
use galactica_render::ObjectSubSprite; use galactica_render::ObjectSubSprite;
use crate::content;
/// Represents a gun attached to a specific ship at a certain gunpoint. /// Represents a gun attached to a specific ship at a certain gunpoint.
#[derive(Debug)] #[derive(Debug)]
pub struct ShipGun { pub struct ShipGun {

View File

@ -1,10 +1,9 @@
use cgmath::{Point3, Vector2}; use cgmath::{Point3, Vector2};
use galactica_content as content;
use galactica_render::{ObjectSprite, StarfieldStar}; use galactica_render::{ObjectSprite, StarfieldStar};
use rand::{self, Rng}; use rand::{self, Rng};
use super::SystemObject; use super::SystemObject;
use crate::consts; use crate::{consts, content};
pub struct System { pub struct System {
pub name: String, pub name: String,

View File

@ -1,16 +1,16 @@
use crate::content;
use cgmath::{Deg, Point3}; use cgmath::{Deg, Point3};
use galactica_content::TextureHandle;
use galactica_render::ObjectSprite; use galactica_render::ObjectSprite;
pub struct SystemObject { pub struct SystemObject {
pub sprite_texture: TextureHandle, pub sprite_texture: content::TextureHandle,
pub pos: Point3<f32>, pub pos: Point3<f32>,
pub size: f32, pub size: f32,
pub angle: Deg<f32>, pub angle: Deg<f32>,
} }
impl SystemObject { impl SystemObject {
pub(super) fn get_sprite(&self) -> ObjectSprite { pub(crate) fn get_sprite(&self) -> ObjectSprite {
return ObjectSprite { return ObjectSprite {
texture: self.sprite_texture, texture: self.sprite_texture,
pos: self.pos, pos: self.pos,

View File

@ -5,9 +5,10 @@ mod objects;
mod physics; mod physics;
mod shipbehavior; mod shipbehavior;
use std::path::PathBuf; pub use galactica_content as content;
use anyhow::Result; use anyhow::Result;
use std::path::PathBuf;
use winit::{ use winit::{
event::{Event, KeyboardInput, WindowEvent}, event::{Event, KeyboardInput, WindowEvent},
event_loop::{ControlFlow, EventLoop}, event_loop::{ControlFlow, EventLoop},
@ -16,7 +17,7 @@ use winit::{
fn main() -> Result<()> { fn main() -> Result<()> {
// TODO: error if missing // TODO: error if missing
let content = galactica_content::Content::load_dir( let content = content::Content::load_dir(
PathBuf::from(consts::CONTENT_ROOT), PathBuf::from(consts::CONTENT_ROOT),
PathBuf::from(consts::TEXTURE_ROOT), PathBuf::from(consts::TEXTURE_ROOT),
consts::STARFIELD_TEXTURE_NAME.to_owned(), consts::STARFIELD_TEXTURE_NAME.to_owned(),

View File

@ -1,21 +1,20 @@
use cgmath::{Deg, InnerSpace, Point3, Vector2}; use cgmath::{Deg, InnerSpace, Point3, Vector2};
use galactica_content::{FactionHandle, TextureHandle};
use galactica_render::ObjectSprite; use galactica_render::ObjectSprite;
use rapier2d::{ use rapier2d::{
dynamics::{RigidBody, RigidBodyBuilder, RigidBodyHandle}, dynamics::{RigidBody, RigidBodyBuilder, RigidBodyHandle},
geometry::{ColliderBuilder, ColliderHandle}, geometry::{ColliderBuilder, ColliderHandle},
}; };
use crate::physics::util; use crate::{content, physics::util};
pub struct ProjectileBuilder { pub struct ProjectileBuilder {
pub rigid_body: RigidBodyBuilder, pub rigid_body: RigidBodyBuilder,
pub collider: ColliderBuilder, pub collider: ColliderBuilder,
pub sprite_texture: TextureHandle, pub sprite_texture: content::TextureHandle,
pub lifetime: f32, pub lifetime: f32,
pub size: f32, pub size: f32,
pub damage: f32, pub damage: f32,
pub faction: FactionHandle, pub faction: content::FactionHandle,
} }
impl ProjectileBuilder { impl ProjectileBuilder {
@ -36,11 +35,11 @@ impl ProjectileBuilder {
pub struct Projectile { pub struct Projectile {
pub rigid_body: RigidBodyHandle, pub rigid_body: RigidBodyHandle,
pub collider: ColliderHandle, pub collider: ColliderHandle,
pub sprite_texture: TextureHandle, pub sprite_texture: content::TextureHandle,
pub lifetime: f32, pub lifetime: f32,
pub size: f32, pub size: f32,
pub damage: f32, pub damage: f32,
pub faction: FactionHandle, pub faction: content::FactionHandle,
} }
impl Projectile { impl Projectile {

View File

@ -1,6 +1,5 @@
use cgmath::{Deg, EuclideanSpace, InnerSpace, Matrix2, Rad, Vector2}; use cgmath::{Deg, EuclideanSpace, InnerSpace, Matrix2, Rad, Vector2};
use content::{FactionHandle, TextureHandle}; use content::{FactionHandle, TextureHandle};
use galactica_content as content;
use galactica_render::ObjectSprite; use galactica_render::ObjectSprite;
use nalgebra::vector; use nalgebra::vector;
use rand::Rng; use rand::Rng;
@ -12,6 +11,7 @@ use rapier2d::{
use super::ProjectileBuilder; use super::ProjectileBuilder;
use crate::{ use crate::{
content,
game::outfits, game::outfits,
physics::{util, ShipHandle}, physics::{util, ShipHandle},
}; };

View File

@ -1,6 +1,5 @@
use cgmath::Point2; use cgmath::Point2;
use crossbeam::channel::Receiver; use crossbeam::channel::Receiver;
use galactica_content as content;
use galactica_render::ObjectSprite; use galactica_render::ObjectSprite;
use nalgebra::vector; use nalgebra::vector;
use rapier2d::{ use rapier2d::{
@ -11,7 +10,7 @@ use rapier2d::{
use std::{collections::HashMap, f32::consts::PI}; use std::{collections::HashMap, f32::consts::PI};
use super::{wrapper::Wrapper, ShipHandle}; use super::{wrapper::Wrapper, ShipHandle};
use crate::{game::outfits, objects}; use crate::{content, game::outfits, objects};
/// Keeps track of all objects in the world that we can interact with. /// Keeps track of all objects in the world that we can interact with.
/// Also wraps our physics engine /// Also wraps our physics engine

View File

@ -1,7 +1,7 @@
use cgmath::{Deg, InnerSpace}; use cgmath::{Deg, InnerSpace};
use galactica_content as content;
use crate::{ use crate::{
content,
inputstatus::InputStatus, inputstatus::InputStatus,
physics::{util, Physics, ShipHandle}, physics::{util, Physics, ShipHandle},
}; };