try to clean up module 'use' stuff with new prelude modules

though i am not sure how good an idea my approach was with a bunch of
intermediate preludes. i was thinking it might be nice to be able to
only pick out the preludes that you wanted (if not all), but ... would
i ever really need to do that? somehow i am thinking, no, but i will
give it some more thought
This commit is contained in:
Gered 2023-03-09 19:10:11 -05:00
parent 75401cb5c7
commit 2e57311fe0
63 changed files with 316 additions and 246 deletions

View file

@ -2,11 +2,7 @@ use std::path::Path;
use anyhow::Result;
use ggdt::audio::*;
use ggdt::graphics::*;
use ggdt::graphics::indexed::*;
use ggdt::system::*;
use ggdt::utils::rnd_value;
use ggdt::prelude::dos_like::*;
#[derive(Debug, Copy, Clone)]
struct AudioChannelStatus {

View file

@ -2,12 +2,7 @@ use std::path::Path;
use anyhow::Result;
use ggdt::*;
use ggdt::graphics::*;
use ggdt::graphics::indexed::*;
use ggdt::math::*;
use ggdt::system::*;
use ggdt::utils::*;
use ggdt::prelude::dos_like::*;
const NUM_BALLS: usize = 128;
const NUM_BALL_SPRITES: usize = 16;

View file

@ -1,9 +1,4 @@
use ggdt::*;
use ggdt::entities::*;
use ggdt::events::*;
use ggdt::graphics::indexed::*;
use ggdt::math::*;
use ggdt::utils::*;
use ggdt::prelude::dos_like::*;
use crate::states::*;

View file

@ -2,8 +2,7 @@ use std::path::Path;
use anyhow::Result;
use ggdt::states::*;
use ggdt::system::*;
use ggdt::prelude::dos_like::*;
use crate::entities::*;
use crate::states::*;

View file

@ -1,10 +1,4 @@
use ggdt::entities::*;
use ggdt::events::*;
use ggdt::graphics::*;
use ggdt::graphics::indexed::*;
use ggdt::math::*;
use ggdt::states::*;
use ggdt::system::*;
use ggdt::prelude::dos_like::*;
use crate::*;

View file

@ -1,5 +1,4 @@
use ggdt::entities::*;
use ggdt::events::*;
use ggdt::prelude::dos_like::*;
use crate::Core;
use crate::entities::*;

View file

@ -2,11 +2,7 @@ use std::collections::HashMap;
use std::path::Path;
use std::rc::Rc;
use ggdt::entities::*;
use ggdt::graphics::*;
use ggdt::graphics::indexed::*;
use ggdt::math::*;
use ggdt::utils::rnd_value;
use ggdt::prelude::dos_like::*;
use crate::{Core, Game, TILE_HEIGHT, TILE_WIDTH, TileMap};

View file

@ -1,6 +1,4 @@
use ggdt::{SCREEN_HEIGHT, SCREEN_WIDTH};
use ggdt::entities::*;
use ggdt::math::*;
use ggdt::prelude::dos_like::*;
use crate::{Core, TILE_HEIGHT, TILE_WIDTH};
use crate::entities::*;
@ -704,7 +702,7 @@ fn render_system_sprites(context: &mut Core) {
}
fn render_system_pixels(context: &mut Core) {
let pixels = context.entities.components::<Pixel>().unwrap();
let pixels = context.entities.components::<crate::entities::Pixel>().unwrap();
let positions = context.entities.components::<Position>();
if let Some((_, camera)) = context.entities.components::<Camera>().single() {

View file

@ -6,13 +6,7 @@ use std::rc::Rc;
use anyhow::{Context, Result};
use ggdt::base::*;
use ggdt::entities::*;
use ggdt::events::*;
use ggdt::graphics::*;
use ggdt::graphics::indexed::*;
use ggdt::math::*;
use ggdt::system::*;
use ggdt::prelude::dos_like::*;
use crate::entities::*;
use crate::states::*;

View file

@ -1,11 +1,6 @@
use std::path::Path;
use ggdt::base::*;
use ggdt::entities::*;
use ggdt::graphics::font::*;
use ggdt::graphics::indexed::*;
use ggdt::states::*;
use ggdt::system::*;
use ggdt::prelude::dos_like::*;
use crate::entities::*;
use crate::Game;

View file

@ -2,9 +2,7 @@ use std::path::Path;
use anyhow::{Context, Result};
use ggdt::graphics::*;
use ggdt::graphics::indexed::*;
use ggdt::states::*;
use ggdt::prelude::dos_like::*;
use crate::{Game, TILE_HEIGHT, TILE_WIDTH};

View file

@ -5,10 +5,7 @@ use std::path::Path;
use anyhow::{Context, Result};
use serde::Deserialize;
use ggdt::graphics::*;
use ggdt::graphics::indexed::*;
use ggdt::math::*;
use ggdt::utils::rnd_value;
use ggdt::prelude::dos_like::*;
use crate::{TILE_HEIGHT, TILE_WIDTH};

View file

@ -1,13 +1,6 @@
use anyhow::{Context, Result};
use ggdt::{SCREEN_HEIGHT, SCREEN_WIDTH};
use ggdt::base::*;
use ggdt::entities::*;
use ggdt::events::*;
use ggdt::math::*;
use ggdt::states::*;
use ggdt::system::*;
use ggdt::utils::rnd_value;
use ggdt::prelude::dos_like::*;
//////////////////////////////////////////////////////////////////////////////////////////////////

View file

@ -1,10 +1,6 @@
use anyhow::Result;
use ggdt::{SCREEN_BOTTOM, SCREEN_RIGHT};
use ggdt::graphics::*;
use ggdt::graphics::indexed::*;
use ggdt::system::*;
use ggdt::utils::rnd_value;
use ggdt::prelude::dos_like::*;
fn main() -> Result<()> {
let config = DosLikeConfig::new();

View file

@ -1,7 +1,6 @@
use criterion::{black_box, Criterion, criterion_group, criterion_main};
use ggdt::{SCREEN_HEIGHT, SCREEN_WIDTH};
use ggdt::graphics::indexed::*;
use ggdt::prelude::dos_like::*;
pub fn criterion_benchmark(c: &mut Criterion) {
let mut source = Bitmap::new(SCREEN_WIDTH, SCREEN_HEIGHT).unwrap();

View file

@ -2,8 +2,7 @@ use std::path::Path;
use criterion::{black_box, Criterion, criterion_group, criterion_main};
use ggdt::graphics::indexed::*;
use ggdt::math::*;
use ggdt::prelude::dos_like::*;
pub fn criterion_benchmark(c: &mut Criterion) {
let mut framebuffer = Bitmap::new(320, 240).unwrap();

View file

@ -2,7 +2,7 @@ use std::io::Cursor;
use criterion::{black_box, Criterion, criterion_group, criterion_main};
use ggdt::graphics::indexed::*;
use ggdt::prelude::dos_like::*;
pub static SMALL_GIF_FILE_BYTES: &[u8] = include_bytes!("../test-assets/test.gif");
pub static LARGE_GIF_FILE_BYTES: &[u8] = include_bytes!("../test-assets/test_image.gif");

View file

@ -1,6 +1,6 @@
use crate::audio::*;
use thiserror::Error;
pub use self::wav::*;
use crate::audio::AudioSpec;
pub mod wav;
@ -18,7 +18,7 @@ pub struct AudioBuffer {
}
impl std::fmt::Debug for AudioBuffer {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("AudioBuffer")
.field("spec", &self.spec)
.field("data.len()", &self.data.len())

View file

@ -7,7 +7,8 @@ use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
use sdl2::audio::AudioFormat;
use thiserror::Error;
use crate::audio::*;
use crate::audio::AudioSpec;
use crate::audio::buffer::AudioBuffer;
use crate::utils::io::StreamSize;
#[derive(Error, Debug)]
@ -298,7 +299,7 @@ impl AudioBuffer {
#[cfg(test)]
mod tests {
use crate::audio::*;
use crate::audio::{AUDIO_FREQUENCY_22KHZ, AUDIO_FREQUENCY_44KHZ};
use super::*;

View file

@ -3,7 +3,8 @@ use std::ops::{Index, IndexMut};
use sdl2::audio::AudioCallback;
use thiserror::Error;
use crate::audio::*;
use crate::audio::{AudioGenerator, AudioSpec, NUM_CHANNELS};
use crate::audio::buffer::AudioBuffer;
/// Represents a "channel" of audio playback that will be mixed together with all of the other
/// actively playing audio channels to get the final audio playback.
@ -30,7 +31,7 @@ pub struct AudioChannel {
}
impl std::fmt::Debug for AudioChannel {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("AudioChannel")
.field("playing", &self.playing)
.field("loops", &self.loops)

View file

@ -1,17 +1,15 @@
use std::fmt::Formatter;
use sdl2::audio::{AudioFormat, AudioFormatNum, AudioSpecDesired};
use sdl2::AudioSubsystem;
use thiserror::Error;
pub use self::buffer::*;
pub use self::device::*;
pub use self::queue::*;
use crate::audio::device::AudioDevice;
pub mod buffer;
pub mod device;
pub mod queue;
pub mod prelude;
/// The number of simultaneously playing audio channels supported by this library currently.
pub const NUM_CHANNELS: usize = 8;
@ -99,7 +97,7 @@ pub struct Audio {
}
impl std::fmt::Debug for Audio {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Audio")
.field("spec", &self.spec)
.finish_non_exhaustive()

View file

@ -0,0 +1,7 @@
pub use crate::{
audio::*,
audio::buffer::*,
audio::buffer::wav::*,
audio::device::*,
audio::queue::*,
};

View file

@ -1,7 +1,9 @@
use std::collections::VecDeque;
use std::rc::Rc;
use crate::audio::*;
use crate::audio::{Audio, AudioGenerator, AudioSpec, NUM_CHANNELS};
use crate::audio::buffer::AudioBuffer;
use crate::audio::device::{AudioDevice, AudioDeviceError};
pub enum AudioCommand {
StopChannel(usize),
@ -36,7 +38,7 @@ pub enum AudioCommand {
}
impl std::fmt::Debug for AudioCommand {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
use AudioCommand::*;
match self {
StopChannel(n) => write!(f, "StopChannel({})", n),

View file

@ -16,14 +16,17 @@
//! context" grab bag:
//!
//! ```
//! use ggdt::prelude::*;
//!
//! pub enum Event { /* .. various events here .. */ }
//!
//! struct App {
//! pub delta: f32,
//! pub system: ggdt::system::System<ggdt::system::DosLike>,
//! pub entities: ggdt::entities::Entities,
//! pub component_systems: ggdt::entities::ComponentSystems<App, App>, // oh no! :'(
//! pub event_publisher: ggdt::events::EventPublisher<Event>,
//! pub event_listeners: ggdt::events::EventListeners<Event, App>, // oh no again! :'(
//! pub system: System<DosLike>,
//! pub entities: Entities,
//! pub component_systems: ComponentSystems<App, App>, // oh no! :'(
//! pub event_publisher: EventPublisher<Event>,
//! pub event_listeners: EventListeners<Event, App>, // oh no again! :'(
//! }
//! ```
//!
@ -37,21 +40,23 @@
//! initially went with a parent-child split, which seemed logical to me at the time:
//!
//! ```
//! use ggdt::prelude::*;
//!
//! pub enum Event { /* .. various events here .. */ }
//!
//! // "core" because what the heck else do i call this? "InnerContext"? "InnerApp"? ...
//! struct Core {
//! pub delta: f32,
//! pub system: ggdt::system::System<ggdt::system::DosLike>,
//! pub entities: ggdt::entities::Entities,
//! pub event_publisher: ggdt::events::EventPublisher<Event>,
//! pub system: System<DosLike>,
//! pub entities: Entities,
//! pub event_publisher: EventPublisher<Event>,
//! }
//!
//! // i guess this is a bit more obvious what to call it, but still ... doesn't sit right with me
//! struct App {
//! pub core: Core,
//! pub component_systems: ggdt::entities::ComponentSystems<Core, Core>,
//! pub event_listeners: ggdt::events::EventListeners<Event, Core>,
//! pub component_systems: ComponentSystems<Core, Core>,
//! pub event_listeners: EventListeners<Event, Core>,
//! }
//! ```
//!
@ -75,22 +80,24 @@
//! But again, better naming still eludes me here!
//!
//! ```
//! use ggdt::prelude::*;
//!
//! pub enum Event { /* .. various events here .. */ }
//!
//! // "Core" because it contains the things that probably 90% of game/app code will need to work
//! // with. you'd probably want to put your game/app resources/assets on this struct too.
//! struct Core {
//! pub delta: f32,
//! pub system: ggdt::system::System<ggdt::system::DosLike>,
//! pub entities: ggdt::entities::Entities,
//! pub event_publisher: ggdt::events::EventPublisher<Event>,
//! pub system: System<DosLike>,
//! pub entities: Entities,
//! pub event_publisher: EventPublisher<Event>,
//! }
//!
//! // "Support" because it contains things that support the main/core game state?
//! // kinda grasping at straws here maybe ...
//! struct Support {
//! pub component_systems: ggdt::entities::ComponentSystems<Core, Core>,
//! pub event_listeners: ggdt::events::EventListeners<Event, Core>,
//! pub component_systems: ComponentSystems<Core, Core>,
//! pub event_listeners: EventListeners<Event, Core>,
//! }
//!
//! // better, maybe?
@ -124,10 +131,11 @@
use thiserror::Error;
use crate::audio::*;
use crate::events::*;
use crate::states::*;
use crate::system::*;
use crate::audio::device::AudioDeviceError;
use crate::events::{EventListeners, EventPublisher};
use crate::states::{AppState, StateError, States};
use crate::system::{System, SystemError};
use crate::system::res::SystemResources;
pub trait CoreState<SystemResType>
where SystemResType: SystemResources {

View file

@ -1,7 +1,6 @@
use std::any::TypeId;
use std::cell::{Ref, RefCell, RefMut};
use std::collections::{HashMap, HashSet};
use std::fmt::Formatter;
use crate::utils::AsAny;
@ -71,7 +70,7 @@ pub struct Entities {
}
impl std::fmt::Debug for Entities {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Entities")
.field("entities.len()", &self.entities.len())
.field("component_stores.keys()", &self.component_stores.keys())
@ -435,7 +434,7 @@ pub struct ComponentSystems<U, R> {
}
impl<U, R> std::fmt::Debug for ComponentSystems<U, R> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("ComponentSystems")
.field("update_systems.len()", &self.update_systems.len())
.field("render_systems.len()", &self.render_systems.len())

View file

@ -1,5 +1,4 @@
use std::collections::VecDeque;
use std::fmt::Formatter;
/// An event listener/handler function that returns true if it handled the event and no other
/// listeners/handlers should be called next with the same event, or false if the event was not
@ -14,7 +13,7 @@ pub struct EventPublisher<EventType> {
}
impl<EventType> std::fmt::Debug for EventPublisher<EventType> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("EventPublisher")
.field("queue.len()", &self.queue.len())
.finish_non_exhaustive()
@ -68,7 +67,7 @@ pub struct EventListeners<EventType, ContextType> {
}
impl<EventType, ContextType> std::fmt::Debug for EventListeners<EventType, ContextType> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("EventListeners")
.field("listeners.len()", &self.listeners.len())
.field("dispatch_queue.len()", &self.dispatch_queue.len())

View file

@ -9,7 +9,7 @@
use std::error::Error;
use crate::graphics::{indexed, Pixel};
use crate::math::Rect;
use crate::math::rect::Rect;
#[derive(Clone, PartialEq)]
pub enum GeneralBlitMethod<PixelType: Pixel> {
@ -94,9 +94,9 @@ pub trait GeneralBitmap: Sized + Clone {
}
}
impl GeneralBitmap for indexed::Bitmap {
impl GeneralBitmap for indexed::bitmap::Bitmap {
type PixelType = u8;
type ErrorType = indexed::BitmapError;
type ErrorType = indexed::bitmap::BitmapError;
fn new(width: u32, height: u32) -> Result<Self, Self::ErrorType> {
Self::new(width, height)
@ -179,9 +179,11 @@ impl GeneralBitmap for indexed::Bitmap {
dest_x: i32,
dest_y: i32
) {
use indexed::bitmap::blit::BlitMethod;
let blit_method = match method {
GeneralBlitMethod::Solid => indexed::BlitMethod::Solid,
GeneralBlitMethod::Transparent(color) => indexed::BlitMethod::Transparent(color),
GeneralBlitMethod::Solid => BlitMethod::Solid,
GeneralBlitMethod::Transparent(color) => BlitMethod::Transparent(color),
};
self.blit_region(blit_method, src, src_region, dest_x, dest_y)
}

View file

@ -2,8 +2,8 @@ use std::ops::Index;
use thiserror::Error;
use crate::graphics::*;
use crate::math::*;
use crate::graphics::bitmap::GeneralBitmap;
use crate::math::rect::Rect;
#[derive(Error, Debug)]
pub enum BitmapAtlasError {
@ -134,13 +134,13 @@ where
pub mod tests {
use claim::*;
use super::*;
use crate::graphics::indexed::bitmap::Bitmap;
use crate::graphics::indexed;
use super::*;
#[test]
pub fn adding_rects() {
let bmp = indexed::Bitmap::new(64, 64).unwrap();
let bmp = Bitmap::new(64, 64).unwrap();
let mut atlas = BitmapAtlas::new(bmp);
let rect = Rect::new(0, 0, 16, 16);
@ -174,7 +174,7 @@ pub mod tests {
#[test]
pub fn adding_grid() {
let bmp = indexed::Bitmap::new(64, 64).unwrap();
let bmp = Bitmap::new(64, 64).unwrap();
let mut atlas = BitmapAtlas::new(bmp);
assert_eq!(3, atlas.add_custom_grid(0, 0, 8, 8, 2, 2, 0).unwrap());

View file

@ -1,4 +1,3 @@
use std::fmt::Formatter;
use std::fs::File;
use std::io::{BufReader, BufWriter, Cursor};
use std::path::Path;
@ -6,8 +5,9 @@ use std::path::Path;
use byteorder::{ReadBytesExt, WriteBytesExt};
use thiserror::Error;
use crate::graphics::*;
use crate::math::*;
use crate::graphics::bitmap::GeneralBitmap;
use crate::graphics::Pixel;
use crate::math::rect::Rect;
pub static VGA_FONT_BYTES: &[u8] = include_bytes!("../../assets/vga.fnt");
@ -103,7 +103,7 @@ pub struct BitmaskFont {
}
impl std::fmt::Debug for BitmaskFont {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("BitmaskFont")
.field("line_height", &self.line_height)
.field("space_width", &self.space_width)

View file

@ -1,8 +1,9 @@
use std::rc::Rc;
use crate::graphics::BitmapAtlas;
use crate::graphics::indexed::*;
use crate::math::*;
use crate::graphics::bitmapatlas::BitmapAtlas;
use crate::graphics::indexed::bitmap::Bitmap;
use crate::graphics::indexed::blendmap::BlendMap;
use crate::math::rect::Rect;
#[derive(Clone, PartialEq)]
pub enum BlitMethod {

View file

@ -5,8 +5,9 @@ use std::path::Path;
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
use thiserror::Error;
use crate::graphics::indexed::*;
use crate::utils::lzwgif::*;
use crate::graphics::indexed::bitmap::Bitmap;
use crate::graphics::indexed::palette::{Palette, PaletteError, PaletteFormat};
use crate::utils::lzwgif::{lzw_decode, lzw_encode, LzwError};
const BITS_FOR_256_COLORS: u32 = 7; // formula is `2 ^ (bits + 1) = num_colors`

View file

@ -6,8 +6,9 @@ use std::path::Path;
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use thiserror::Error;
use crate::graphics::indexed::*;
use crate::utils::packbits::*;
use crate::graphics::indexed::bitmap::Bitmap;
use crate::graphics::indexed::palette::{Palette, PaletteError, PaletteFormat};
use crate::utils::packbits::{pack_bits, PackBitsError, unpack_bits};
#[derive(Error, Debug)]
pub enum IffError {

View file

@ -1,17 +1,10 @@
use std::fmt::Formatter;
use std::path::Path;
use std::slice;
use thiserror::Error;
use crate::graphics::indexed::*;
use crate::math::*;
pub use self::blit::*;
pub use self::gif::*;
pub use self::iff::*;
pub use self::pcx::*;
pub use self::primitives::*;
use crate::graphics::indexed::palette::Palette;
use crate::math::rect::Rect;
pub mod blit;
pub mod gif;
@ -55,7 +48,7 @@ pub struct Bitmap {
}
impl std::fmt::Debug for Bitmap {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Bitmap")
.field("width", &self.width)
.field("height", &self.height)

View file

@ -5,7 +5,8 @@ use std::path::Path;
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
use thiserror::Error;
use crate::graphics::indexed::*;
use crate::graphics::indexed::bitmap::Bitmap;
use crate::graphics::indexed::palette::{from_rgb32, Palette, PaletteError, PaletteFormat};
use crate::utils::bytes::ReadFixedLengthByteArray;
#[derive(Error, Debug)]

View file

@ -1,8 +1,9 @@
use std::mem::swap;
use crate::graphics::*;
use crate::graphics::indexed::*;
use crate::math::*;
use crate::graphics::font::{Character, Font, FontRenderOpts};
use crate::graphics::indexed::bitmap::Bitmap;
use crate::graphics::indexed::blendmap::BlendMap;
use crate::math::rect::Rect;
impl Bitmap {
/// Fills the entire bitmap with the given color.

View file

@ -1,4 +1,3 @@
use std::fmt::Formatter;
use std::fs::File;
use std::io::{BufReader, BufWriter};
use std::path::Path;
@ -6,8 +5,8 @@ use std::path::Path;
use byteorder::{ReadBytesExt, WriteBytesExt};
use thiserror::Error;
use crate::graphics::indexed::*;
use crate::math::*;
use crate::graphics::indexed::palette::{from_rgb32, luminance, Palette};
use crate::math::lerp;
use crate::utils::bytes::ReadFixedLengthByteArray;
#[derive(Error, Debug)]
@ -45,7 +44,7 @@ pub struct BlendMap {
}
impl std::fmt::Debug for BlendMap {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("BlendMap")
.field("start_color", &self.start_color)
.field("end_color", &self.end_color)

View file

@ -1,10 +1,8 @@
//! This module and all sub-modules contain graphics functionality that uses indexed colours. That is, each pixel
//! is a `u8` and treated as index into a [`Palette`], so 256 maximum colours are possible.
pub use self::bitmap::*;
pub use self::blendmap::*;
pub use self::palette::*;
pub mod bitmap;
pub mod blendmap;
pub mod palette;
pub mod palette;
pub mod prelude;

View file

@ -7,7 +7,7 @@ use std::path::Path;
use byteorder::{ReadBytesExt, WriteBytesExt};
use thiserror::Error;
use crate::graphics::indexed::*;
use crate::graphics::indexed::bitmap::Bitmap;
use crate::NUM_COLORS;
use crate::utils::abs_diff;

View file

@ -0,0 +1,21 @@
// include all things useable for indexed colour graphics
pub use crate::graphics::{
bitmap::*,
bitmapatlas::*,
font::*,
indexed::{
*,
bitmap::{
*,
blit::*,
gif::*,
iff::*,
pcx::*,
primitives::*,
},
blendmap::*,
palette::*,
},
Pixel,
};

View file

@ -1,15 +1,13 @@
use num_traits::{PrimInt, Unsigned};
pub use self::bitmap::*;
pub use self::bitmapatlas::*;
pub use self::font::*;
pub mod bitmap;
pub mod bitmapatlas;
pub mod font;
pub mod indexed;
pub mod rgb;
pub mod prelude;
/// Common trait to represent single pixel/colour values.
pub trait Pixel: PrimInt + Unsigned {}
impl<T> Pixel for T where T: PrimInt + Unsigned {}

View file

@ -0,0 +1,8 @@
pub use crate::graphics::{
*,
bitmap::*,
bitmapatlas::*,
font::*,
indexed::prelude::*,
rgb::prelude::*,
};

View file

@ -1,2 +1,4 @@
//! This module and all sub-modules contain graphics functionality that uses 32-bit colour data. That is, each pixel
//! is a `u32` and contains full RGBA information.
pub mod prelude;

View file

@ -0,0 +1,13 @@
// include all things useable for 32-bit colour graphics
pub use crate::graphics::{
bitmap::*,
bitmapatlas::*,
font::*,
Pixel,
rgb::{
*,
// todo
},
};

View file

@ -11,6 +11,8 @@ pub mod states;
pub mod system;
pub mod utils;
pub mod prelude;
pub const LOW_RES: bool = if cfg!(feature = "low_res") {
true
} else {

View file

@ -1,4 +1,5 @@
use crate::math::*;
use crate::math::{distance_between, distance_squared_between};
use crate::math::vector2::Vector2;
/// Represents a 2D circle, using integer center coordinates and radius.
#[derive(Debug, Copy, Clone, Eq, PartialEq)]

View file

@ -1,6 +1,7 @@
use std::ops::{Mul, MulAssign};
use crate::math::*;
use crate::math::nearly_equal;
use crate::math::vector2::Vector2;
/// Represents a 3x3 column-major matrix and provides common methods for matrix math.
#[derive(Debug, Copy, Clone, PartialEq)]
@ -284,6 +285,8 @@ impl Mul<Vector2> for Matrix3x3 {
#[cfg(test)]
pub mod tests {
use crate::math::*;
use super::*;
#[test]

View file

@ -1,15 +1,12 @@
use std::ops::{Add, Div, Mul, Sub};
pub use self::circle::*;
pub use self::matrix3x3::*;
pub use self::rect::*;
pub use self::vector2::*;
pub mod circle;
pub mod matrix3x3;
pub mod rect;
pub mod vector2;
pub mod prelude;
pub const PI: f32 = std::f32::consts::PI;
// 180 degrees
pub const HALF_PI: f32 = PI / 2.0;

8
ggdt/src/math/prelude.rs Normal file
View file

@ -0,0 +1,8 @@
pub use crate::math::{
*,
circle::*,
matrix3x3::*,
rect::*,
vector2::*,
};

View file

@ -1,6 +1,7 @@
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
use crate::math::*;
use crate::math::{angle_between, angle_to_direction, nearly_equal, NearlyEqual};
use crate::math::matrix3x3::Matrix3x3;
/// Represents a 2D vector and provides common methods for vector math.
#[derive(Debug, Copy, Clone, PartialEq)]
@ -251,6 +252,8 @@ impl MulAssign<Matrix3x3> for Vector2 {
#[cfg(test)]
pub mod tests {
use crate::math::*;
use super::*;
#[test]

42
ggdt/src/prelude.rs Normal file
View file

@ -0,0 +1,42 @@
// to get everything this library has to offer, including all `SystemResources` implementations
pub use crate::{
*,
audio::prelude::*,
base::*,
entities::*,
events::*,
graphics::prelude::*,
math::prelude::*,
states::*,
system::{
prelude::*,
res::{
dos_like::*,
},
},
utils::prelude::*,
};
// specific module preludes that can be used instead that grab everything relevant to a specific `SystemResources`
// implementation only, since most applications will only use one and not care about the rest
pub mod dos_like {
pub use crate::{
*,
audio::prelude::*,
base::*,
entities::*,
events::*,
graphics::indexed::prelude::*,
math::prelude::*,
states::*,
system::{
prelude::*,
res::{
dos_like::*,
},
},
utils::prelude::*,
};
}

View file

@ -1,5 +1,4 @@
use std::collections::VecDeque;
use std::fmt::Formatter;
use std::ops::DerefMut;
use thiserror::Error;
@ -36,7 +35,7 @@ pub enum StateChange<ContextType> {
}
impl<ContextType> std::fmt::Debug for StateChange<ContextType> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
use StateChange::*;
match *self {
Push(..) => write!(f, "Push"),
@ -71,7 +70,7 @@ struct StateContainer<ContextType> {
}
impl<ContextType> std::fmt::Debug for StateContainer<ContextType> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("StateContainer")
.field("current_state", &self.current_state)
.field("pending_state_change", &self.pending_state_change)
@ -185,7 +184,7 @@ pub struct States<ContextType> {
}
impl<ContextType> std::fmt::Debug for States<ContextType> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("States")
.field("states", &self.states)
.field("command", &self.command)

View file

@ -11,8 +11,9 @@
use bitflags::bitflags;
use crate::system::{Keycode, MouseButton, MouseButtons, Scancode};
use crate::system::MouseEvent::MouseButtonUp;
use crate::system::input_devices::keyboard::codes::Keycode;
use crate::system::input_devices::keyboard::scancodes::Scancode;
use crate::system::input_devices::mouse::buttons::{MouseButton, MouseButtons};
#[derive(Debug, Clone, PartialEq)]
pub enum WindowEvent {
@ -175,7 +176,7 @@ impl From<sdl2::event::Event> for SystemEvent {
})
}
sdl2::event::Event::MouseButtonUp { mouse_btn, clicks, x, y, .. } => {
SystemEvent::Mouse(MouseButtonUp {
SystemEvent::Mouse(MouseEvent::MouseButtonUp {
x,
y,
clicks,

View file

@ -1,9 +1,6 @@
use crate::system::event::{KeyboardEvent, SystemEvent};
use super::*;
pub use self::codes::*;
pub use self::scancodes::*;
use crate::system::event::{KeyboardEvent, SystemEvent, SystemEventHandler};
use crate::system::input_devices::{ButtonState, InputDevice};
use crate::system::input_devices::keyboard::scancodes::Scancode;
pub mod codes;
pub mod scancodes;

View file

@ -1,5 +1,3 @@
use crate::system::{SystemEvent, SystemEventHandler};
pub mod keyboard;
pub mod mouse;

View file

@ -1,8 +1,7 @@
use crate::graphics::*;
use crate::graphics::indexed::*;
use crate::math::*;
use super::*;
use crate::graphics::bitmap::{GeneralBitmap, GeneralBlitMethod};
use crate::graphics::indexed;
use crate::math::rect::Rect;
use crate::system::input_devices::mouse::Mouse;
const DEFAULT_MOUSE_CURSOR_HOTSPOT_X: u32 = 0;
const DEFAULT_MOUSE_CURSOR_HOTSPOT_Y: u32 = 0;
@ -206,8 +205,8 @@ where
}
}
impl DefaultMouseCursorBitmaps<indexed::Bitmap> for CustomMouseCursor<indexed::Bitmap> {
fn get_default() -> MouseCursorBitmap<indexed::Bitmap> {
impl DefaultMouseCursorBitmaps<indexed::bitmap::Bitmap> for CustomMouseCursor<indexed::bitmap::Bitmap> {
fn get_default() -> MouseCursorBitmap<indexed::bitmap::Bitmap> {
#[rustfmt::skip]
const CURSOR_PIXELS: [u8; DEFAULT_MOUSE_CURSOR_WIDTH * DEFAULT_MOUSE_CURSOR_HEIGHT] = [
0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
@ -228,7 +227,7 @@ impl DefaultMouseCursorBitmaps<indexed::Bitmap> for CustomMouseCursor<indexed::B
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
];
let mut cursor = Bitmap::new(
let mut cursor = indexed::bitmap::Bitmap::new(
DEFAULT_MOUSE_CURSOR_WIDTH as u32,
DEFAULT_MOUSE_CURSOR_HEIGHT as u32,
).unwrap();

View file

@ -1,10 +1,6 @@
use crate::math::*;
use crate::system::MouseEvent;
use super::*;
pub use self::buttons::*;
pub use self::cursor::*;
use crate::system::event::{MouseEvent, SystemEvent, SystemEventHandler};
use crate::system::input_devices::{ButtonState, InputDevice};
use crate::system::input_devices::mouse::buttons::{MouseButton, MouseButtons};
pub mod buttons;
pub mod cursor;

View file

@ -1,26 +1,15 @@
use std::fmt::Formatter;
use byte_slice_cast::AsByteSlice;
use sdl2::{AudioSubsystem, Sdl, TimerSubsystem, VideoSubsystem};
use sdl2::audio::AudioSpecDesired;
use sdl2::pixels::PixelFormatEnum;
use sdl2::render::{Texture, WindowCanvas};
use thiserror::Error;
use crate::{DEFAULT_SCALE_FACTOR, SCREEN_HEIGHT, SCREEN_WIDTH};
use crate::audio::*;
pub use self::event::*;
pub use self::input_devices::*;
pub use self::input_devices::keyboard::*;
pub use self::input_devices::mouse::*;
pub use self::res::*;
pub use self::res::dos_like::*;
use crate::audio::AudioError;
use crate::system::event::{SystemEvent, SystemEventPump};
use crate::system::res::{SystemResources, SystemResourcesConfig, SystemResourcesError};
pub mod event;
pub mod input_devices;
pub mod res;
pub mod prelude;
fn is_x11_compositor_skipping_problematic() -> bool {
/*
this is _probably_ a bit of a hack.
@ -233,10 +222,10 @@ impl SystemBuilder {
#[allow(dead_code)]
pub struct System<SystemResType>
where SystemResType: SystemResources {
sdl_context: Sdl,
sdl_audio_subsystem: AudioSubsystem,
sdl_video_subsystem: VideoSubsystem,
sdl_timer_subsystem: TimerSubsystem,
sdl_context: sdl2::Sdl,
sdl_audio_subsystem: sdl2::AudioSubsystem,
sdl_video_subsystem: sdl2::VideoSubsystem,
sdl_timer_subsystem: sdl2::TimerSubsystem,
vsync: bool,
target_framerate: Option<u32>,
@ -250,7 +239,7 @@ where SystemResType: SystemResources {
impl<SystemResType> std::fmt::Debug for System<SystemResType>
where SystemResType: SystemResources {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("System")
.field("res", &self.res)
.field("vsync", &self.vsync)
@ -305,7 +294,7 @@ where SystemResType: SystemResources {
/// should quit. Otherwise, returns false.
///
/// ```no_run
/// use ggdt::system::*;
/// use ggdt::prelude::*;
///
/// let config = DosLikeConfig::new();
/// let mut system = SystemBuilder::new().window_title("Example").build(config).unwrap();
@ -320,7 +309,7 @@ where SystemResType: SystemResources {
/// main loop. For example:
///
/// ```no_run
/// use ggdt::system::*;
/// use ggdt::prelude::*;
///
/// let config = DosLikeConfig::new();
/// let mut system = SystemBuilder::new().window_title("Example").build(config).unwrap();

View file

@ -0,0 +1,22 @@
pub use crate::system::{
*,
event::*,
input_devices::{
*,
keyboard::{
*,
codes::*,
scancodes::*,
},
mouse::{
*,
buttons::*,
cursor::*,
},
},
res::{
*,
// note: we are intentionally not including the `SystemResources` implementation modules here
},
};

View file

@ -2,9 +2,7 @@
//! instance to provide something resembling an old DOS VGA mode 13h style experience (there are differences, however).
//!
//! ```no_run
//! use ggdt::graphics::*;
//! use ggdt::graphics::indexed::*;
//! use ggdt::system::*;
//! use ggdt::prelude::*;
//!
//! let config = DosLikeConfig::new();
//! let mut system = SystemBuilder::new()
@ -28,11 +26,20 @@
//! ```
//!
use sdl2::video::Window;
use byte_slice_cast::AsByteSlice;
use crate::system::*;
use crate::graphics::*;
use crate::graphics::indexed::*;
use crate::{DEFAULT_SCALE_FACTOR, SCREEN_HEIGHT, SCREEN_WIDTH};
use crate::audio::{Audio, TARGET_AUDIO_CHANNELS, TARGET_AUDIO_FREQUENCY};
use crate::audio::queue::AudioQueue;
use crate::graphics::font::BitmaskFont;
use crate::graphics::indexed::bitmap::Bitmap;
use crate::graphics::indexed::palette::Palette;
use crate::system::event::{SystemEvent, SystemEventHandler};
use crate::system::input_devices::InputDevice;
use crate::system::input_devices::keyboard::Keyboard;
use crate::system::input_devices::mouse::cursor::CustomMouseCursor;
use crate::system::input_devices::mouse::Mouse;
use crate::system::res::{SystemResources, SystemResourcesConfig, SystemResourcesError};
/// Configuration / builder for configuring and constructing an instance of [`DosLike`].
pub struct DosLikeConfig {
@ -75,9 +82,9 @@ impl SystemResourcesConfig for DosLikeConfig {
fn build(
self,
_video_subsystem: &VideoSubsystem,
audio_subsystem: &AudioSubsystem,
mut window: Window,
_video_subsystem: &sdl2::VideoSubsystem,
audio_subsystem: &sdl2::AudioSubsystem,
mut window: sdl2::video::Window,
) -> Result<Self::SystemResourcesType, SystemResourcesError> {
let texture_pixel_size = 4; // 32-bit ARGB format
@ -114,7 +121,7 @@ impl SystemResourcesConfig for DosLikeConfig {
// application's framebuffer
let sdl_texture = match sdl_canvas.create_texture_streaming(
Some(PixelFormatEnum::ARGB8888),
Some(sdl2::pixels::PixelFormatEnum::ARGB8888),
self.screen_width,
self.screen_height,
) {
@ -155,7 +162,7 @@ impl SystemResourcesConfig for DosLikeConfig {
// create audio device and queue
let audio_spec = AudioSpecDesired {
let audio_spec = sdl2::audio::AudioSpecDesired {
freq: Some(TARGET_AUDIO_FREQUENCY as i32),
channels: Some(TARGET_AUDIO_CHANNELS),
samples: None,
@ -190,8 +197,8 @@ impl SystemResourcesConfig for DosLikeConfig {
/// A [`SystemResources`] implementation that provides indexed-colour [`Bitmap`]s for graphics, simple 8-bit / 22khz
/// audio via [`Audio`] and keyboard/mouse input.
pub struct DosLike {
sdl_canvas: WindowCanvas,
sdl_texture: Texture,
sdl_canvas: sdl2::render::WindowCanvas,
sdl_texture: sdl2::render::Texture,
sdl_texture_pitch: usize,
texture_pixels: Box<[u32]>,
@ -230,7 +237,7 @@ pub struct DosLike {
}
impl std::fmt::Debug for DosLike {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("DosLike")
.field("audio", &self.audio)
.field("audio_queue", &self.audio_queue)

View file

@ -1,7 +1,8 @@
use thiserror::Error;
use crate::audio::*;
use crate::system::*;
use crate::audio::AudioError;
use crate::audio::device::AudioDeviceError;
use crate::system::event::SystemEvent;
pub mod dos_like;

View file

@ -9,6 +9,8 @@ pub mod io;
pub mod lzwgif;
pub mod packbits;
pub mod prelude;
pub fn rnd_value<N: SampleUniform + PartialOrd>(low: N, high: N) -> N {
rand::thread_rng().gen_range(low..=high)
}

View file

@ -0,0 +1,8 @@
pub use crate::utils::{
*,
bytes::*,
io::*,
lzwgif::*,
packbits::*,
};

View file

@ -1,9 +1,7 @@
use std::path::Path;
use std::rc::Rc;
use ggdt::{SCREEN_HEIGHT, SCREEN_WIDTH};
use ggdt::graphics::*;
use ggdt::graphics::indexed::*;
use ggdt::prelude::*;
fn setup() -> (Bitmap, Palette) {
let palette = Palette::new_vga_palette().unwrap();