diff --git a/src/consts.rs b/src/consts.rs index d7b64a0..4c3c9cd 100644 --- a/src/consts.rs +++ b/src/consts.rs @@ -1,7 +1,5 @@ -use crate::physics::Pfloat; - -pub const ZOOM_MIN: Pfloat = 200.0; -pub const ZOOM_MAX: Pfloat = 2000.0; +pub const ZOOM_MIN: f32 = 200.0; +pub const ZOOM_MAX: f32 = 2000.0; /// Z-axis range for starfield stars /// This does not affect scale. diff --git a/src/content/syntax/system.rs b/src/content/syntax/system.rs index 6cb3e1d..595469c 100644 --- a/src/content/syntax/system.rs +++ b/src/content/syntax/system.rs @@ -2,11 +2,10 @@ use anyhow::{bail, Context, Result}; use cgmath::{Deg, Point3}; use std::collections::{HashMap, HashSet}; -use crate::physics::{Pfloat, Polar}; +use crate::physics::Polar; /// Toml file syntax pub(in crate::content) mod toml { - use super::Pfloat; use serde::Deserialize; use std::collections::HashMap; @@ -26,10 +25,10 @@ pub(in crate::content) mod toml { pub sprite: String, pub position: Position, - pub size: Pfloat, + pub size: f32, - pub radius: Option, - pub angle: Option, + pub radius: Option, + pub angle: Option, } #[derive(Debug, Deserialize)] @@ -42,16 +41,16 @@ pub(in crate::content) mod toml { #[derive(Debug, Deserialize)] pub struct PolarCoords { pub center: CoordinatesTwo, - pub radius: Pfloat, - pub angle: Pfloat, - pub z: Pfloat, + pub radius: f32, + pub angle: f32, + pub z: f32, } #[derive(Debug, Deserialize)] #[serde(untagged)] pub enum CoordinatesTwo { Label(String), - Coords([Pfloat; 2]), + Coords([f32; 2]), } impl ToString for CoordinatesTwo { @@ -67,7 +66,7 @@ pub(in crate::content) mod toml { #[serde(untagged)] pub enum CoordinatesThree { Label(String), - Coords([Pfloat; 3]), + Coords([f32; 3]), } impl ToString for CoordinatesThree { @@ -90,8 +89,8 @@ pub struct System { pub struct Object { pub sprite: String, pub position: Point3, - pub size: Pfloat, - pub angle: Deg, + pub size: f32, + pub angle: Deg, } // Helper function for resolve_position, never called on its own. diff --git a/src/game/camera.rs b/src/game/camera.rs index 617e2ba..afe19a7 100644 --- a/src/game/camera.rs +++ b/src/game/camera.rs @@ -1,13 +1,11 @@ use cgmath::Point2; -use crate::physics::Pfloat; - #[derive(Debug, Clone, Copy)] pub struct Camera { /// Camera center - pub pos: Point2, + pub pos: Point2, /// Camera zoom /// (How many game units tall is the viewport?) - pub zoom: Pfloat, + pub zoom: f32, } diff --git a/src/game/game.rs b/src/game/game.rs index e5f28da..4c1e216 100644 --- a/src/game/game.rs +++ b/src/game/game.rs @@ -3,7 +3,7 @@ use std::time::Instant; use winit::event::{ElementState, MouseButton, MouseScrollDelta, TouchPhase, VirtualKeyCode}; use super::{ship::ShipKind, Camera, InputStatus, Ship, System}; -use crate::{consts, content::Content, physics::Pfloat, render::Sprite, render::Spriteable}; +use crate::{consts, content::Content, render::Sprite, render::Spriteable}; pub struct Game { pub input: InputStatus, @@ -40,7 +40,7 @@ impl Game { } pub fn update(&mut self) { - let t: Pfloat = self.last_update.elapsed().as_secs_f32(); + let t: f32 = self.last_update.elapsed().as_secs_f32(); if self.input.key_thrust { self.player.physicsbody.thrust(50.0 * t); diff --git a/src/game/ship.rs b/src/game/ship.rs index c1febe4..382e2f8 100644 --- a/src/game/ship.rs +++ b/src/game/ship.rs @@ -1,9 +1,6 @@ use cgmath::Point2; -use crate::{ - physics::Pfloat, physics::PhysicsBody, render::Sprite, render::SpriteTexture, - render::Spriteable, -}; +use crate::{physics::PhysicsBody, render::Sprite, render::SpriteTexture, render::Spriteable}; pub enum ShipKind { Gypsum, @@ -18,7 +15,7 @@ impl ShipKind { return SpriteTexture(name.to_owned()); } - fn size(&self) -> Pfloat { + fn size(&self) -> f32 { match self { Self::Gypsum => 100.0, } @@ -31,7 +28,7 @@ pub struct Ship { } impl Ship { - pub fn new(kind: ShipKind, pos: Point2) -> Self { + pub fn new(kind: ShipKind, pos: Point2) -> Self { Ship { physicsbody: PhysicsBody::new(pos), kind, diff --git a/src/game/system.rs b/src/game/system.rs index 0367e86..2e4f852 100644 --- a/src/game/system.rs +++ b/src/game/system.rs @@ -2,22 +2,20 @@ use cgmath::{Point3, Vector2}; use rand::{self, Rng}; use super::SystemObject; -use crate::{ - consts, content, physics::Pfloat, render::Sprite, render::SpriteTexture, render::Spriteable, -}; +use crate::{consts, content, render::Sprite, render::SpriteTexture, render::Spriteable}; pub struct StarfieldStar { /// Star coordinates, in world space. /// These are relative to the center of a starfield tile. - pub pos: Point3, + pub pos: Point3, /// Height in game units. /// Will be scaled for zoom, but not for distance. - pub size: Pfloat, + pub size: f32, /// Color/brightness variation. Random between 0 and 1. /// Used in starfield shader. - pub tint: Vector2, + pub tint: Vector2, } pub struct System { diff --git a/src/game/systemobject.rs b/src/game/systemobject.rs index 4cd2349..f43b2ff 100644 --- a/src/game/systemobject.rs +++ b/src/game/systemobject.rs @@ -1,12 +1,12 @@ use cgmath::{Deg, Point3}; -use crate::{physics::Pfloat, render::Sprite, render::SpriteTexture, render::Spriteable}; +use crate::{render::Sprite, render::SpriteTexture, render::Spriteable}; pub struct SystemObject { pub sprite: SpriteTexture, - pub pos: Point3, - pub size: Pfloat, - pub angle: Deg, + pub pos: Point3, + pub size: f32, + pub angle: Deg, } impl Spriteable for SystemObject { diff --git a/src/physics/body.rs b/src/physics/body.rs index bb41062..8b68ddd 100644 --- a/src/physics/body.rs +++ b/src/physics/body.rs @@ -1,15 +1,14 @@ -use super::Pfloat; use cgmath::{Angle, Deg, Point2, Vector2}; pub struct PhysicsBody { - pub pos: Point2, - pub vel: Vector2, - pub mass: Pfloat, - pub angle: Deg, + pub pos: Point2, + pub vel: Vector2, + pub mass: f32, + pub angle: Deg, } impl PhysicsBody { - pub fn new(pos: Point2) -> Self { + pub fn new(pos: Point2) -> Self { return PhysicsBody { pos, vel: (0.0, 0.0).into(), @@ -19,17 +18,17 @@ impl PhysicsBody { } /// Calculate the position of this body after t seconds. - pub fn tick(&mut self, t: Pfloat) { + pub fn tick(&mut self, t: f32) { self.pos += self.vel * t; } /// Apply an instantaneous force to this object - pub fn force(&mut self, v: Vector2) { + pub fn force(&mut self, v: Vector2) { self.vel += v / self.mass; } /// Apply a force in the direction this object is pointing. - pub fn thrust(&mut self, f: Pfloat) { + pub fn thrust(&mut self, f: f32) { let l = Vector2 { x: -self.angle.sin(), y: self.angle.cos(), @@ -38,7 +37,7 @@ impl PhysicsBody { } // Rotate this object - pub fn rot(&mut self, a: Deg) { + pub fn rot(&mut self, a: Deg) { self.angle -= a; // Wrap angles diff --git a/src/physics/mod.rs b/src/physics/mod.rs index 76ebe5b..99738e4 100644 --- a/src/physics/mod.rs +++ b/src/physics/mod.rs @@ -2,7 +2,5 @@ mod body; mod polar; // What kind of float shoud we use for physics? -pub type Pfloat = f32; - pub use body::PhysicsBody; pub use polar::Polar; diff --git a/src/physics/polar.rs b/src/physics/polar.rs index 3d83134..fe67707 100644 --- a/src/physics/polar.rs +++ b/src/physics/polar.rs @@ -1,15 +1,14 @@ -use super::Pfloat; use cgmath::{Angle, Deg, Point2, Vector2}; #[derive(Debug, Clone, Copy)] pub struct Polar { - pub center: Point2, - pub radius: Pfloat, - pub angle: Deg, + pub center: Point2, + pub radius: f32, + pub angle: Deg, } impl Polar { - pub fn to_cartesian(self) -> Point2 { + pub fn to_cartesian(self) -> Point2 { let v = Vector2 { x: self.radius * self.angle.sin(), y: self.radius * self.angle.cos(), diff --git a/src/render/gpustate.rs b/src/render/gpustate.rs index 46e4c00..4dc3690 100644 --- a/src/render/gpustate.rs +++ b/src/render/gpustate.rs @@ -16,7 +16,7 @@ use super::{ VertexBuffer, }, }; -use crate::{consts, game::Game, physics::Pfloat}; +use crate::{consts, game::Game}; pub struct GPUState { device: wgpu::Device, @@ -211,7 +211,7 @@ impl GPUState { for s in game.get_sprites() { // Compute post-parallax position and distance-adjusted scale. // We do this here so we can check if a sprite is on the screen. - let pos: Point2 = { + let pos: Point2 = { (Point2 { x: s.pos.x, y: s.pos.y, diff --git a/src/render/sprite.rs b/src/render/sprite.rs index a0e0785..f597a22 100644 --- a/src/render/sprite.rs +++ b/src/render/sprite.rs @@ -1,26 +1,25 @@ use cgmath::{Deg, Point3}; use super::SpriteTexture; -use crate::physics::Pfloat; pub struct Sprite { /// Name of the sprite to draw pub texture: SpriteTexture, /// This object's position, in world coordinates. - pub pos: Point3, + pub pos: Point3, /// The size of this sprite, /// given as height in world units. - pub size: Pfloat, + pub size: f32, /// Scale factor. /// if this is 1, sprite height is exactly self.size. - pub scale: Pfloat, + pub scale: f32, /// This sprite's rotation /// (relative to north, measured ccw) - pub angle: Deg, + pub angle: Deg, } pub trait Spriteable {