Added constants
parent
1661b5c3af
commit
b848515420
10
src/main.rs
10
src/main.rs
|
@ -16,6 +16,16 @@ mod render;
|
||||||
mod ship;
|
mod ship;
|
||||||
mod system;
|
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::{
|
use crate::{
|
||||||
doodad::Doodad,
|
doodad::Doodad,
|
||||||
inputstatus::InputStatus,
|
inputstatus::InputStatus,
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use bytemuck;
|
use bytemuck;
|
||||||
use cgmath::{EuclideanSpace, Matrix2, Point2};
|
use cgmath::{EuclideanSpace, Matrix2, Point2, Vector2};
|
||||||
use std::{iter, rc::Rc};
|
use std::{iter, rc::Rc};
|
||||||
use wgpu;
|
use wgpu;
|
||||||
use winit::{self, dpi::PhysicalSize, window::Window};
|
use winit::{self, dpi::PhysicalSize, window::Window};
|
||||||
|
|
||||||
use crate::Game;
|
use crate::{Game, STARFIELD_COUNT, STARFIELD_SIZE};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
globaldata::{GlobalData, GlobalDataContent},
|
globaldata::{GlobalData, GlobalDataContent},
|
||||||
|
@ -45,7 +45,7 @@ impl GPUState {
|
||||||
// We can draw at most this many sprites on the screen.
|
// We can draw at most this many sprites on the screen.
|
||||||
// TODO: compile-time option
|
// TODO: compile-time option
|
||||||
pub const SPRITE_INSTANCE_LIMIT: u64 = 100;
|
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> {
|
pub async fn new(window: Window) -> Result<Self> {
|
||||||
let window_size = window.inner_size();
|
let window_size = window.inner_size();
|
||||||
|
@ -326,7 +326,7 @@ impl GPUState {
|
||||||
camera_zoom: game.camera.zoom,
|
camera_zoom: game.camera.zoom,
|
||||||
window_aspect: self.window_aspect,
|
window_aspect: self.window_aspect,
|
||||||
starfield_texture: 1,
|
starfield_texture: 1,
|
||||||
starfield_tile_size: 80000.0,
|
starfield_tile_size: STARFIELD_SIZE as f32,
|
||||||
padding: Default::default(),
|
padding: Default::default(),
|
||||||
}]),
|
}]),
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
physics::{Pfloat, Polar},
|
physics::{Pfloat, Polar},
|
||||||
Doodad, Sprite, Spriteable,
|
Doodad, Sprite, Spriteable, STARFIELD_COUNT, STARFIELD_PARALLAX_MAX, STARFIELD_PARALLAX_MIN,
|
||||||
|
STARFIELD_SIZE,
|
||||||
};
|
};
|
||||||
use cgmath::{Deg, Point2};
|
use cgmath::{Deg, Point2};
|
||||||
use rand::{self, Rng};
|
use rand::{self, Rng};
|
||||||
|
@ -21,15 +22,16 @@ pub struct System {
|
||||||
impl System {
|
impl System {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::thread_rng();
|
||||||
|
let sz = STARFIELD_SIZE as f32 / 2.0;
|
||||||
let mut s = System {
|
let mut s = System {
|
||||||
bodies: Vec::new(),
|
bodies: Vec::new(),
|
||||||
starfield: (0..1000)
|
starfield: (0..STARFIELD_COUNT)
|
||||||
.map(|_| StarfieldStar {
|
.map(|_| StarfieldStar {
|
||||||
pos: Point2 {
|
pos: Point2 {
|
||||||
x: rng.gen_range(-40000.0..40000.0),
|
x: rng.gen_range(-sz..=sz),
|
||||||
y: rng.gen_range(-40000.0..40000.0),
|
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),
|
height: rng.gen_range(1.0..2.0),
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
|
|
Loading…
Reference in New Issue