Added constants

master
Mark 2023-12-24 07:32:07 -08:00
parent 1661b5c3af
commit b848515420
Signed by: Mark
GPG Key ID: C6D63995FE72FD80
3 changed files with 21 additions and 9 deletions

View File

@ -16,6 +16,16 @@ mod render;
mod ship;
mod system;
// 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;
use crate::{
doodad::Doodad,
inputstatus::InputStatus,

View File

@ -1,11 +1,11 @@
use anyhow::Result;
use bytemuck;
use cgmath::{EuclideanSpace, Matrix2, Point2};
use cgmath::{EuclideanSpace, Matrix2, Point2, Vector2};
use std::{iter, rc::Rc};
use wgpu;
use winit::{self, dpi::PhysicalSize, window::Window};
use crate::Game;
use crate::{Game, STARFIELD_COUNT, STARFIELD_SIZE};
use super::{
globaldata::{GlobalData, GlobalDataContent},
@ -45,7 +45,7 @@ impl GPUState {
// We can draw at most this many sprites on the screen.
// TODO: compile-time option
pub const SPRITE_INSTANCE_LIMIT: u64 = 100;
pub const STARFIELD_INSTANCE_LIMIT: u64 = 501 * 9;
pub const STARFIELD_INSTANCE_LIMIT: u64 = STARFIELD_COUNT * 9;
pub async fn new(window: Window) -> Result<Self> {
let window_size = window.inner_size();
@ -326,7 +326,7 @@ impl GPUState {
camera_zoom: game.camera.zoom,
window_aspect: self.window_aspect,
starfield_texture: 1,
starfield_tile_size: 80000.0,
starfield_tile_size: STARFIELD_SIZE as f32,
padding: Default::default(),
}]),
);

View File

@ -1,6 +1,7 @@
use crate::{
physics::{Pfloat, Polar},
Doodad, Sprite, Spriteable,
Doodad, Sprite, Spriteable, STARFIELD_COUNT, STARFIELD_PARALLAX_MAX, STARFIELD_PARALLAX_MIN,
STARFIELD_SIZE,
};
use cgmath::{Deg, Point2};
use rand::{self, Rng};
@ -21,15 +22,16 @@ pub struct System {
impl System {
pub fn new() -> Self {
let mut rng = rand::thread_rng();
let sz = STARFIELD_SIZE as f32 / 2.0;
let mut s = System {
bodies: Vec::new(),
starfield: (0..1000)
starfield: (0..STARFIELD_COUNT)
.map(|_| StarfieldStar {
pos: Point2 {
x: rng.gen_range(-40000.0..40000.0),
y: rng.gen_range(-40000.0..40000.0),
x: rng.gen_range(-sz..=sz),
y: rng.gen_range(-sz..=sz),
},
parallax: rng.gen_range(100.0..150.0),
parallax: rng.gen_range(STARFIELD_PARALLAX_MIN..STARFIELD_PARALLAX_MAX),
height: rng.gen_range(1.0..2.0),
})
.collect(),