diff --git a/src/main.rs b/src/main.rs index dc87eb9..0e86499 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,18 +16,23 @@ mod render; mod ship; mod system; +pub const ZOOM_MIN: Pfloat = 200.0; +pub const ZOOM_MAX: Pfloat = 2000.0; + // Z-axis range for starfield stars pub const STARFIELD_PARALLAX_MIN: f32 = 100.0; pub const STARFIELD_PARALLAX_MAX: f32 = 200.0; -// Number of stars in one starfield tile -pub const STARFIELD_COUNT: u64 = 100; // Size of a square starfield tile, in game units. // A tile of size PARALLAX_MAX * screen-size-in-game-units // will completely cover a (square) screen. This depends on zoom! -pub const STARFIELD_SIZE: u64 = STARFIELD_PARALLAX_MAX as u64 * 500; - -pub const ZOOM_MIN: Pfloat = 200.0; -pub const ZOOM_MAX: Pfloat = 2000.0; +// +// Use a value smaller than zoom_max for debug. +pub const STARFIELD_SIZE: u64 = STARFIELD_PARALLAX_MAX as u64 * ZOOM_MAX as u64; +// Average number of stars per game unit +pub const STARFIELD_DENSITY: f64 = 0.01; +// Number of stars in one starfield tile +// Must fit inside an i32 +pub const STARFIELD_COUNT: u64 = (STARFIELD_SIZE as f64 * STARFIELD_DENSITY) as u64; use crate::{ doodad::Doodad, diff --git a/src/render/gpustate.rs b/src/render/gpustate.rs index 99bc378..4b8b7f1 100644 --- a/src/render/gpustate.rs +++ b/src/render/gpustate.rs @@ -5,7 +5,7 @@ use std::{iter, rc::Rc}; use wgpu; use winit::{self, dpi::PhysicalSize, window::Window}; -use crate::{Game, STARFIELD_COUNT, STARFIELD_PARALLAX_MIN, STARFIELD_SIZE, ZOOM_MAX}; +use crate::{Game, STARFIELD_COUNT, STARFIELD_PARALLAX_MIN, STARFIELD_SIZE, ZOOM_MAX, ZOOM_MIN}; use super::{ globaldata::{GlobalData, GlobalDataContent}, @@ -217,7 +217,8 @@ impl GPUState { for s in game.sprites() { // Parallax is computed here, so we can check if this sprite is visible. - let pos = (s.pos - game.camera.pos.to_vec()) / s.parallax; + let pos = + (s.pos - game.camera.pos.to_vec()) / (s.parallax + game.camera.zoom / ZOOM_MIN); let texture = self.texture_array.get_texture(&s.name[..]); // Game dimensions of this sprite post-scale.