remove old display size constants as well as cargo feature flags
we'll be introducing variable display size features next, so these screen dimension compile-time constants are not going to be useful. the "low_res" and "wide" features were also tied to the idea of compile-time constants for display sizing so these need to go too, and will be brought back via runtime configuration
This commit is contained in:
parent
806725654a
commit
e503cfb718
|
@ -47,8 +47,8 @@ fn main() -> Result<()> {
|
||||||
for _ in 0..NUM_BALLS {
|
for _ in 0..NUM_BALLS {
|
||||||
let speed = rnd_value(1, 3);
|
let speed = rnd_value(1, 3);
|
||||||
let ball = Ball {
|
let ball = Ball {
|
||||||
x: rnd_value(0, SCREEN_WIDTH as i32 - 1),
|
x: rnd_value(0, system.res.video.width() as i32 - 1),
|
||||||
y: rnd_value(0, SCREEN_HEIGHT as i32 - 1),
|
y: rnd_value(0, system.res.video.height() as i32 - 1),
|
||||||
dir_x: if rnd_value(0, 1) == 0 { -speed } else { speed },
|
dir_x: if rnd_value(0, 1) == 0 { -speed } else { speed },
|
||||||
dir_y: if rnd_value(0, 1) == 0 { -speed } else { speed },
|
dir_y: if rnd_value(0, 1) == 0 { -speed } else { speed },
|
||||||
sprite: rnd_value(0, NUM_BALL_SPRITES - 1),
|
sprite: rnd_value(0, NUM_BALL_SPRITES - 1),
|
||||||
|
@ -73,9 +73,9 @@ fn main() -> Result<()> {
|
||||||
ball.x = 0;
|
ball.x = 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ball.x >= (SCREEN_WIDTH - BALL_WIDTH) as i32 {
|
if ball.x >= (system.res.video.width() - BALL_WIDTH) as i32 {
|
||||||
ball.dir_x = -ball.dir_x;
|
ball.dir_x = -ball.dir_x;
|
||||||
ball.x = (SCREEN_WIDTH - BALL_WIDTH) as i32;
|
ball.x = (system.res.video.width() - BALL_WIDTH) as i32;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,9 +85,9 @@ fn main() -> Result<()> {
|
||||||
ball.y = 0;
|
ball.y = 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ball.y >= (SCREEN_HEIGHT - BALL_HEIGHT) as i32 {
|
if ball.y >= (system.res.video.height() - BALL_HEIGHT) as i32 {
|
||||||
ball.dir_y = -ball.dir_y;
|
ball.dir_y = -ball.dir_y;
|
||||||
ball.y = (SCREEN_HEIGHT - BALL_HEIGHT) as i32;
|
ball.y = (system.res.video.height() - BALL_HEIGHT) as i32;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,8 +73,8 @@ fn new_bounce_particles(entities: &mut Entities, x: f32, y: f32) {
|
||||||
fn new_ball_entity(entities: &mut Entities) {
|
fn new_ball_entity(entities: &mut Entities) {
|
||||||
let id = entities.new_entity();
|
let id = entities.new_entity();
|
||||||
|
|
||||||
let x: i32 = rnd_value(SCREEN_LEFT as i32 + 1, SCREEN_RIGHT as i32 - BALL_SIZE - 1);
|
let x: i32 = rnd_value(1, 319 - BALL_SIZE - 1);
|
||||||
let y: i32 = rnd_value(SCREEN_TOP as i32 + 1, SCREEN_BOTTOM as i32 - BALL_SIZE - 1);
|
let y: i32 = rnd_value(1, 239 - BALL_SIZE - 1);
|
||||||
|
|
||||||
let speed = rnd_value(1, 3) * BALL_BASE_SPEED;
|
let speed = rnd_value(1, 3) * BALL_BASE_SPEED;
|
||||||
let vx = if rnd_value(0, 1) == 0 { -speed } else { speed };
|
let vx = if rnd_value(0, 1) == 0 { -speed } else { speed };
|
||||||
|
@ -110,12 +110,12 @@ fn update_system_collision(context: &mut Context) {
|
||||||
let mut velocity = velocities.get_mut(&entity).unwrap();
|
let mut velocity = velocities.get_mut(&entity).unwrap();
|
||||||
|
|
||||||
let mut bounced = false;
|
let mut bounced = false;
|
||||||
if position.0.x as i32 <= SCREEN_LEFT as i32 || position.0.x as i32 + BALL_SIZE >= SCREEN_RIGHT as i32 {
|
if position.0.x as i32 <= 0 || position.0.x as i32 + BALL_SIZE >= context.system.res.video.right() as i32 {
|
||||||
position.0.x -= velocity.0.x * context.delta;
|
position.0.x -= velocity.0.x * context.delta;
|
||||||
velocity.0.x = -velocity.0.x;
|
velocity.0.x = -velocity.0.x;
|
||||||
bounced = true;
|
bounced = true;
|
||||||
}
|
}
|
||||||
if position.0.y as i32 <= SCREEN_TOP as i32 || position.0.y as i32 + BALL_SIZE >= SCREEN_BOTTOM as i32 {
|
if position.0.y as i32 <= 0 || position.0.y as i32 + BALL_SIZE >= context.system.res.video.bottom() as i32 {
|
||||||
position.0.y -= velocity.0.y * context.delta;
|
position.0.y -= velocity.0.y * context.delta;
|
||||||
velocity.0.y = -velocity.0.y;
|
velocity.0.y = -velocity.0.y;
|
||||||
bounced = true;
|
bounced = true;
|
||||||
|
|
|
@ -529,14 +529,14 @@ fn update_system_camera_follows_player(context: &mut Core) {
|
||||||
let positions = context.entities.components::<Position>().unwrap();
|
let positions = context.entities.components::<Position>().unwrap();
|
||||||
let position = positions.get(player_entity).unwrap();
|
let position = positions.get(player_entity).unwrap();
|
||||||
|
|
||||||
let camera_x = position.0.x as i32 - (SCREEN_WIDTH as i32 / 2) + 8;
|
let camera_x = position.0.x as i32 - (context.system.res.video.width() as i32 / 2) + 8;
|
||||||
let camera_y = position.0.y as i32 - (SCREEN_HEIGHT as i32 / 2) + 8;
|
let camera_y = position.0.y as i32 - (context.system.res.video.height() as i32 / 2) + 8;
|
||||||
|
|
||||||
// clamp camera position to the map boundaries
|
// clamp camera position to the map boundaries
|
||||||
let map_pixel_width = context.tilemap.width() * TILE_WIDTH;
|
let map_pixel_width = context.tilemap.width() * TILE_WIDTH;
|
||||||
let map_pixel_height = context.tilemap.height() * TILE_HEIGHT;
|
let map_pixel_height = context.tilemap.height() * TILE_HEIGHT;
|
||||||
let max_camera_x = map_pixel_width - SCREEN_WIDTH;
|
let max_camera_x = map_pixel_width - context.system.res.video.width();
|
||||||
let max_camera_y = map_pixel_height - SCREEN_HEIGHT;
|
let max_camera_y = map_pixel_height - context.system.res.video.height();
|
||||||
|
|
||||||
camera.x = camera_x.clamp(0, max_camera_x as i32);
|
camera.x = camera_x.clamp(0, max_camera_x as i32);
|
||||||
camera.y = camera_y.clamp(0, max_camera_y as i32);
|
camera.y = camera_y.clamp(0, max_camera_y as i32);
|
||||||
|
|
|
@ -18,8 +18,8 @@ pub fn event_listener(event: &Event, context: &mut Core) -> bool {
|
||||||
Event::SpawnPixel => {
|
Event::SpawnPixel => {
|
||||||
let speed = rnd_value(1, 10) as f32 * 10.0;
|
let speed = rnd_value(1, 10) as f32 * 10.0;
|
||||||
let angle = (rnd_value(0, 359) as f32).to_radians();
|
let angle = (rnd_value(0, 359) as f32).to_radians();
|
||||||
let x = (SCREEN_WIDTH / 2) as f32;
|
let x = (context.system.res.video.width() / 2) as f32;
|
||||||
let y = (SCREEN_HEIGHT / 2) as f32;
|
let y = (context.system.res.video.height() / 2) as f32;
|
||||||
let color = rnd_value(0, 255);
|
let color = rnd_value(0, 255);
|
||||||
let id = context.entities.new_entity();
|
let id = context.entities.new_entity();
|
||||||
context.entities.add_component(id, Position(Vector2::new(x, y)));
|
context.entities.add_component(id, Position(Vector2::new(x, y)));
|
||||||
|
|
|
@ -19,8 +19,8 @@ fn main() -> Result<()> {
|
||||||
|
|
||||||
system.update()?;
|
system.update()?;
|
||||||
|
|
||||||
let x = rnd_value(0, SCREEN_RIGHT) as i32;
|
let x = rnd_value(0, system.res.video.right()) as i32;
|
||||||
let y = rnd_value(0, SCREEN_BOTTOM) as i32;
|
let y = rnd_value(0, system.res.video.bottom()) as i32;
|
||||||
let color = rnd_value(0, 255);
|
let color = rnd_value(0, 255);
|
||||||
system.res.video.set_pixel(x, y, color);
|
system.res.video.set_pixel(x, y, color);
|
||||||
|
|
||||||
|
|
|
@ -5,10 +5,6 @@ version = "0.1.0"
|
||||||
authors = ["Gered King <gered@blarg.ca>"]
|
authors = ["Gered King <gered@blarg.ca>"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[features]
|
|
||||||
low_res = []
|
|
||||||
wide = []
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
byte-slice-cast = "1.2.1"
|
byte-slice-cast = "1.2.1"
|
||||||
byteorder = "1.4.3"
|
byteorder = "1.4.3"
|
||||||
|
|
|
@ -3,8 +3,11 @@ use criterion::{black_box, Criterion, criterion_group, criterion_main};
|
||||||
use ggdt::prelude::*;
|
use ggdt::prelude::*;
|
||||||
|
|
||||||
pub fn criterion_benchmark(c: &mut Criterion) {
|
pub fn criterion_benchmark(c: &mut Criterion) {
|
||||||
let mut source = IndexedBitmap::new(SCREEN_WIDTH, SCREEN_HEIGHT).unwrap();
|
let width = 320;
|
||||||
let mut dest = vec![0u32; (SCREEN_WIDTH * SCREEN_HEIGHT * 4) as usize].into_boxed_slice();
|
let height = 240;
|
||||||
|
|
||||||
|
let mut source = IndexedBitmap::new(width, height).unwrap();
|
||||||
|
let mut dest = vec![0u32; (width * height * 4) as usize].into_boxed_slice();
|
||||||
let palette = Palette::new_vga_palette().unwrap();
|
let palette = Palette::new_vga_palette().unwrap();
|
||||||
|
|
||||||
c.bench_function("deindex_bitmap_pixels", |b| {
|
c.bench_function("deindex_bitmap_pixels", |b| {
|
||||||
|
|
|
@ -9,9 +9,10 @@ use thiserror::Error;
|
||||||
|
|
||||||
use crate::graphics::bitmap::indexed::IndexedBitmap;
|
use crate::graphics::bitmap::indexed::IndexedBitmap;
|
||||||
use crate::graphics::color::{from_rgb32, lerp_rgb32, to_argb32, to_rgb32};
|
use crate::graphics::color::{from_rgb32, lerp_rgb32, to_argb32, to_rgb32};
|
||||||
use crate::NUM_COLORS;
|
|
||||||
use crate::utils::abs_diff;
|
use crate::utils::abs_diff;
|
||||||
|
|
||||||
|
const NUM_COLORS: usize = 256;
|
||||||
|
|
||||||
/// Common trait to represent a range of indexed colour values.
|
/// Common trait to represent a range of indexed colour values.
|
||||||
pub trait ColorRange: RangeBounds<u8> + Iterator<Item=u8> {}
|
pub trait ColorRange: RangeBounds<u8> + Iterator<Item=u8> {}
|
||||||
impl<T> ColorRange for T where T: RangeBounds<u8> + Iterator<Item=u8> {}
|
impl<T> ColorRange for T where T: RangeBounds<u8> + Iterator<Item=u8> {}
|
||||||
|
|
|
@ -13,49 +13,6 @@ pub mod utils;
|
||||||
|
|
||||||
pub mod prelude;
|
pub mod prelude;
|
||||||
|
|
||||||
pub const LOW_RES: bool = if cfg!(feature = "low_res") {
|
|
||||||
true
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
};
|
|
||||||
pub const WIDE_SCREEN: bool = if cfg!(feature = "wide") {
|
|
||||||
true
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
};
|
|
||||||
|
|
||||||
pub const SCREEN_WIDTH: u32 = if cfg!(feature = "low_res") {
|
|
||||||
if cfg!(feature = "wide") {
|
|
||||||
214
|
|
||||||
} else {
|
|
||||||
160
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if cfg!(feature = "wide") {
|
|
||||||
428
|
|
||||||
} else {
|
|
||||||
320
|
|
||||||
}
|
|
||||||
};
|
|
||||||
pub const SCREEN_HEIGHT: u32 = if cfg!(feature = "low_res") {
|
|
||||||
120
|
|
||||||
} else {
|
|
||||||
240
|
|
||||||
};
|
|
||||||
|
|
||||||
pub const SCREEN_TOP: u32 = 0;
|
|
||||||
pub const SCREEN_LEFT: u32 = 0;
|
|
||||||
pub const SCREEN_RIGHT: u32 = SCREEN_WIDTH - 1;
|
|
||||||
pub const SCREEN_BOTTOM: u32 = SCREEN_HEIGHT - 1;
|
|
||||||
|
|
||||||
pub const DEFAULT_SCALE_FACTOR: u32 = if cfg!(feature = "low_res") {
|
|
||||||
6
|
|
||||||
} else {
|
|
||||||
3
|
|
||||||
};
|
|
||||||
|
|
||||||
pub const NUM_COLORS: usize = 256; // i mean ... the number of colors is really defined by the size of u8 ...
|
|
||||||
|
|
||||||
// using this to hold common unit test helper functions
|
// using this to hold common unit test helper functions
|
||||||
// (since apparently rust doesn't really have a great alternative ... ?)
|
// (since apparently rust doesn't really have a great alternative ... ?)
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -28,7 +28,6 @@
|
||||||
|
|
||||||
use byte_slice_cast::AsByteSlice;
|
use byte_slice_cast::AsByteSlice;
|
||||||
|
|
||||||
use crate::{DEFAULT_SCALE_FACTOR, SCREEN_HEIGHT, SCREEN_WIDTH};
|
|
||||||
use crate::audio::{Audio, TARGET_AUDIO_CHANNELS, TARGET_AUDIO_FREQUENCY};
|
use crate::audio::{Audio, TARGET_AUDIO_CHANNELS, TARGET_AUDIO_FREQUENCY};
|
||||||
use crate::audio::queue::AudioQueue;
|
use crate::audio::queue::AudioQueue;
|
||||||
use crate::graphics::font::BitmaskFont;
|
use crate::graphics::font::BitmaskFont;
|
||||||
|
@ -41,6 +40,10 @@ use crate::system::input_devices::mouse::cursor::CustomMouseCursor;
|
||||||
use crate::system::input_devices::mouse::Mouse;
|
use crate::system::input_devices::mouse::Mouse;
|
||||||
use crate::system::res::{SystemResources, SystemResourcesConfig, SystemResourcesError};
|
use crate::system::res::{SystemResources, SystemResourcesConfig, SystemResourcesError};
|
||||||
|
|
||||||
|
const DEFAULT_SCREEN_WIDTH: u32 = 320;
|
||||||
|
const DEFAULT_SCREEN_HEIGHT: u32 = 240;
|
||||||
|
const DEFAULT_SCALE_FACTOR: u32 = 3;
|
||||||
|
|
||||||
/// Configuration / builder for configuring and constructing an instance of [`DosLike`].
|
/// Configuration / builder for configuring and constructing an instance of [`DosLike`].
|
||||||
pub struct DosLikeConfig {
|
pub struct DosLikeConfig {
|
||||||
screen_width: u32,
|
screen_width: u32,
|
||||||
|
@ -53,8 +56,8 @@ impl DosLikeConfig {
|
||||||
/// Returns a new [`DosLikeConfig`] with a default configuration.
|
/// Returns a new [`DosLikeConfig`] with a default configuration.
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
DosLikeConfig {
|
DosLikeConfig {
|
||||||
screen_width: SCREEN_WIDTH,
|
screen_width: DEFAULT_SCREEN_WIDTH,
|
||||||
screen_height: SCREEN_HEIGHT,
|
screen_height: DEFAULT_SCREEN_HEIGHT,
|
||||||
initial_scale_factor: DEFAULT_SCALE_FACTOR,
|
initial_scale_factor: DEFAULT_SCALE_FACTOR,
|
||||||
integer_scaling: false,
|
integer_scaling: false,
|
||||||
}
|
}
|
||||||
|
@ -140,7 +143,7 @@ impl SystemResourcesConfig for DosLikeConfig {
|
||||||
// create the Bitmap object that will be exposed to the application acting as the system
|
// create the Bitmap object that will be exposed to the application acting as the system
|
||||||
// backbuffer
|
// backbuffer
|
||||||
|
|
||||||
let framebuffer = match IndexedBitmap::new(SCREEN_WIDTH, SCREEN_HEIGHT) {
|
let framebuffer = match IndexedBitmap::new(self.screen_width, self.screen_height) {
|
||||||
Ok(bmp) => bmp,
|
Ok(bmp) => bmp,
|
||||||
Err(error) => return Err(SystemResourcesError::SDLError(error.to_string())),
|
Err(error) => return Err(SystemResourcesError::SDLError(error.to_string())),
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use byte_slice_cast::AsByteSlice;
|
use byte_slice_cast::AsByteSlice;
|
||||||
|
|
||||||
use crate::{DEFAULT_SCALE_FACTOR, SCREEN_HEIGHT, SCREEN_WIDTH};
|
|
||||||
use crate::audio::{Audio, TARGET_AUDIO_CHANNELS, TARGET_AUDIO_FREQUENCY};
|
use crate::audio::{Audio, TARGET_AUDIO_CHANNELS, TARGET_AUDIO_FREQUENCY};
|
||||||
use crate::audio::queue::AudioQueue;
|
use crate::audio::queue::AudioQueue;
|
||||||
use crate::graphics::bitmap::rgb::RgbaBitmap;
|
use crate::graphics::bitmap::rgb::RgbaBitmap;
|
||||||
|
@ -12,6 +11,10 @@ use crate::system::input_devices::mouse::cursor::CustomMouseCursor;
|
||||||
use crate::system::input_devices::mouse::Mouse;
|
use crate::system::input_devices::mouse::Mouse;
|
||||||
use crate::system::res::{SystemResources, SystemResourcesConfig, SystemResourcesError};
|
use crate::system::res::{SystemResources, SystemResourcesConfig, SystemResourcesError};
|
||||||
|
|
||||||
|
const DEFAULT_SCREEN_WIDTH: u32 = 320;
|
||||||
|
const DEFAULT_SCREEN_HEIGHT: u32 = 240;
|
||||||
|
const DEFAULT_SCALE_FACTOR: u32 = 3;
|
||||||
|
|
||||||
pub struct StandardConfig {
|
pub struct StandardConfig {
|
||||||
screen_width: u32,
|
screen_width: u32,
|
||||||
screen_height: u32,
|
screen_height: u32,
|
||||||
|
@ -23,8 +26,8 @@ impl StandardConfig {
|
||||||
/// Returns a new [`DosLikeConfig`] with a default configuration.
|
/// Returns a new [`DosLikeConfig`] with a default configuration.
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
StandardConfig {
|
StandardConfig {
|
||||||
screen_width: SCREEN_WIDTH,
|
screen_width: DEFAULT_SCREEN_WIDTH,
|
||||||
screen_height: SCREEN_HEIGHT,
|
screen_height: DEFAULT_SCREEN_HEIGHT,
|
||||||
initial_scale_factor: DEFAULT_SCALE_FACTOR,
|
initial_scale_factor: DEFAULT_SCALE_FACTOR,
|
||||||
integer_scaling: false,
|
integer_scaling: false,
|
||||||
}
|
}
|
||||||
|
@ -103,7 +106,7 @@ impl SystemResourcesConfig for StandardConfig {
|
||||||
// create the Bitmap object that will be exposed to the application acting as the system
|
// create the Bitmap object that will be exposed to the application acting as the system
|
||||||
// backbuffer
|
// backbuffer
|
||||||
|
|
||||||
let framebuffer = match RgbaBitmap::new(SCREEN_WIDTH, SCREEN_HEIGHT) {
|
let framebuffer = match RgbaBitmap::new(self.screen_width, self.screen_height) {
|
||||||
Ok(bmp) => bmp,
|
Ok(bmp) => bmp,
|
||||||
Err(error) => return Err(SystemResourcesError::SDLError(error.to_string())),
|
Err(error) => return Err(SystemResourcesError::SDLError(error.to_string())),
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,6 +6,9 @@ use helpers::test_assets_file;
|
||||||
|
|
||||||
pub mod helpers;
|
pub mod helpers;
|
||||||
|
|
||||||
|
const SCREEN_WIDTH: u32 = 320;
|
||||||
|
const SCREEN_HEIGHT: u32 = 240;
|
||||||
|
|
||||||
const BASE_PATH: &str = "./tests/ref/indexed/";
|
const BASE_PATH: &str = "./tests/ref/indexed/";
|
||||||
|
|
||||||
fn reference_file(file: &Path) -> PathBuf {
|
fn reference_file(file: &Path) -> PathBuf {
|
||||||
|
|
|
@ -24,6 +24,9 @@ pub const COLOR_BRIGHT_MAGENTA_HALF_ALPHA: u32 = 0x7fff55ff;
|
||||||
pub const COLOR_BRIGHT_YELLOW_HALF_ALPHA: u32 = 0x7fffff55;
|
pub const COLOR_BRIGHT_YELLOW_HALF_ALPHA: u32 = 0x7fffff55;
|
||||||
pub const COLOR_BRIGHT_WHITE_HALF_ALPHA: u32 = 0x7fffffff;
|
pub const COLOR_BRIGHT_WHITE_HALF_ALPHA: u32 = 0x7fffffff;
|
||||||
|
|
||||||
|
const SCREEN_WIDTH: u32 = 320;
|
||||||
|
const SCREEN_HEIGHT: u32 = 240;
|
||||||
|
|
||||||
const BASE_PATH: &str = "./tests/ref/rgba/";
|
const BASE_PATH: &str = "./tests/ref/rgba/";
|
||||||
|
|
||||||
fn reference_file(file: &Path) -> PathBuf {
|
fn reference_file(file: &Path) -> PathBuf {
|
||||||
|
|
Loading…
Reference in a new issue