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:
parent
75401cb5c7
commit
2e57311fe0
|
@ -2,11 +2,7 @@ use std::path::Path;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
|
||||||
use ggdt::audio::*;
|
use ggdt::prelude::dos_like::*;
|
||||||
use ggdt::graphics::*;
|
|
||||||
use ggdt::graphics::indexed::*;
|
|
||||||
use ggdt::system::*;
|
|
||||||
use ggdt::utils::rnd_value;
|
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
struct AudioChannelStatus {
|
struct AudioChannelStatus {
|
||||||
|
|
|
@ -2,12 +2,7 @@ use std::path::Path;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
|
||||||
use ggdt::*;
|
use ggdt::prelude::dos_like::*;
|
||||||
use ggdt::graphics::*;
|
|
||||||
use ggdt::graphics::indexed::*;
|
|
||||||
use ggdt::math::*;
|
|
||||||
use ggdt::system::*;
|
|
||||||
use ggdt::utils::*;
|
|
||||||
|
|
||||||
const NUM_BALLS: usize = 128;
|
const NUM_BALLS: usize = 128;
|
||||||
const NUM_BALL_SPRITES: usize = 16;
|
const NUM_BALL_SPRITES: usize = 16;
|
||||||
|
|
|
@ -1,9 +1,4 @@
|
||||||
use ggdt::*;
|
use ggdt::prelude::dos_like::*;
|
||||||
use ggdt::entities::*;
|
|
||||||
use ggdt::events::*;
|
|
||||||
use ggdt::graphics::indexed::*;
|
|
||||||
use ggdt::math::*;
|
|
||||||
use ggdt::utils::*;
|
|
||||||
|
|
||||||
use crate::states::*;
|
use crate::states::*;
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,7 @@ use std::path::Path;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
|
||||||
use ggdt::states::*;
|
use ggdt::prelude::dos_like::*;
|
||||||
use ggdt::system::*;
|
|
||||||
|
|
||||||
use crate::entities::*;
|
use crate::entities::*;
|
||||||
use crate::states::*;
|
use crate::states::*;
|
||||||
|
|
|
@ -1,10 +1,4 @@
|
||||||
use ggdt::entities::*;
|
use ggdt::prelude::dos_like::*;
|
||||||
use ggdt::events::*;
|
|
||||||
use ggdt::graphics::*;
|
|
||||||
use ggdt::graphics::indexed::*;
|
|
||||||
use ggdt::math::*;
|
|
||||||
use ggdt::states::*;
|
|
||||||
use ggdt::system::*;
|
|
||||||
|
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use ggdt::entities::*;
|
use ggdt::prelude::dos_like::*;
|
||||||
use ggdt::events::*;
|
|
||||||
|
|
||||||
use crate::Core;
|
use crate::Core;
|
||||||
use crate::entities::*;
|
use crate::entities::*;
|
||||||
|
|
|
@ -2,11 +2,7 @@ use std::collections::HashMap;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
use ggdt::entities::*;
|
use ggdt::prelude::dos_like::*;
|
||||||
use ggdt::graphics::*;
|
|
||||||
use ggdt::graphics::indexed::*;
|
|
||||||
use ggdt::math::*;
|
|
||||||
use ggdt::utils::rnd_value;
|
|
||||||
|
|
||||||
use crate::{Core, Game, TILE_HEIGHT, TILE_WIDTH, TileMap};
|
use crate::{Core, Game, TILE_HEIGHT, TILE_WIDTH, TileMap};
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
use ggdt::{SCREEN_HEIGHT, SCREEN_WIDTH};
|
use ggdt::prelude::dos_like::*;
|
||||||
use ggdt::entities::*;
|
|
||||||
use ggdt::math::*;
|
|
||||||
|
|
||||||
use crate::{Core, TILE_HEIGHT, TILE_WIDTH};
|
use crate::{Core, TILE_HEIGHT, TILE_WIDTH};
|
||||||
use crate::entities::*;
|
use crate::entities::*;
|
||||||
|
@ -704,7 +702,7 @@ fn render_system_sprites(context: &mut Core) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_system_pixels(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>();
|
let positions = context.entities.components::<Position>();
|
||||||
|
|
||||||
if let Some((_, camera)) = context.entities.components::<Camera>().single() {
|
if let Some((_, camera)) = context.entities.components::<Camera>().single() {
|
||||||
|
|
|
@ -6,13 +6,7 @@ use std::rc::Rc;
|
||||||
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
|
|
||||||
use ggdt::base::*;
|
use ggdt::prelude::dos_like::*;
|
||||||
use ggdt::entities::*;
|
|
||||||
use ggdt::events::*;
|
|
||||||
use ggdt::graphics::*;
|
|
||||||
use ggdt::graphics::indexed::*;
|
|
||||||
use ggdt::math::*;
|
|
||||||
use ggdt::system::*;
|
|
||||||
|
|
||||||
use crate::entities::*;
|
use crate::entities::*;
|
||||||
use crate::states::*;
|
use crate::states::*;
|
||||||
|
|
|
@ -1,11 +1,6 @@
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use ggdt::base::*;
|
use ggdt::prelude::dos_like::*;
|
||||||
use ggdt::entities::*;
|
|
||||||
use ggdt::graphics::font::*;
|
|
||||||
use ggdt::graphics::indexed::*;
|
|
||||||
use ggdt::states::*;
|
|
||||||
use ggdt::system::*;
|
|
||||||
|
|
||||||
use crate::entities::*;
|
use crate::entities::*;
|
||||||
use crate::Game;
|
use crate::Game;
|
||||||
|
|
|
@ -2,9 +2,7 @@ use std::path::Path;
|
||||||
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
|
|
||||||
use ggdt::graphics::*;
|
use ggdt::prelude::dos_like::*;
|
||||||
use ggdt::graphics::indexed::*;
|
|
||||||
use ggdt::states::*;
|
|
||||||
|
|
||||||
use crate::{Game, TILE_HEIGHT, TILE_WIDTH};
|
use crate::{Game, TILE_HEIGHT, TILE_WIDTH};
|
||||||
|
|
||||||
|
|
|
@ -5,10 +5,7 @@ use std::path::Path;
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
use ggdt::graphics::*;
|
use ggdt::prelude::dos_like::*;
|
||||||
use ggdt::graphics::indexed::*;
|
|
||||||
use ggdt::math::*;
|
|
||||||
use ggdt::utils::rnd_value;
|
|
||||||
|
|
||||||
use crate::{TILE_HEIGHT, TILE_WIDTH};
|
use crate::{TILE_HEIGHT, TILE_WIDTH};
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,6 @@
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
|
|
||||||
use ggdt::{SCREEN_HEIGHT, SCREEN_WIDTH};
|
use ggdt::prelude::dos_like::*;
|
||||||
use ggdt::base::*;
|
|
||||||
use ggdt::entities::*;
|
|
||||||
use ggdt::events::*;
|
|
||||||
use ggdt::math::*;
|
|
||||||
use ggdt::states::*;
|
|
||||||
use ggdt::system::*;
|
|
||||||
use ggdt::utils::rnd_value;
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
|
||||||
use ggdt::{SCREEN_BOTTOM, SCREEN_RIGHT};
|
use ggdt::prelude::dos_like::*;
|
||||||
use ggdt::graphics::*;
|
|
||||||
use ggdt::graphics::indexed::*;
|
|
||||||
use ggdt::system::*;
|
|
||||||
use ggdt::utils::rnd_value;
|
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
let config = DosLikeConfig::new();
|
let config = DosLikeConfig::new();
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use criterion::{black_box, Criterion, criterion_group, criterion_main};
|
use criterion::{black_box, Criterion, criterion_group, criterion_main};
|
||||||
|
|
||||||
use ggdt::{SCREEN_HEIGHT, SCREEN_WIDTH};
|
use ggdt::prelude::dos_like::*;
|
||||||
use ggdt::graphics::indexed::*;
|
|
||||||
|
|
||||||
pub fn criterion_benchmark(c: &mut Criterion) {
|
pub fn criterion_benchmark(c: &mut Criterion) {
|
||||||
let mut source = Bitmap::new(SCREEN_WIDTH, SCREEN_HEIGHT).unwrap();
|
let mut source = Bitmap::new(SCREEN_WIDTH, SCREEN_HEIGHT).unwrap();
|
||||||
|
|
|
@ -2,8 +2,7 @@ use std::path::Path;
|
||||||
|
|
||||||
use criterion::{black_box, Criterion, criterion_group, criterion_main};
|
use criterion::{black_box, Criterion, criterion_group, criterion_main};
|
||||||
|
|
||||||
use ggdt::graphics::indexed::*;
|
use ggdt::prelude::dos_like::*;
|
||||||
use ggdt::math::*;
|
|
||||||
|
|
||||||
pub fn criterion_benchmark(c: &mut Criterion) {
|
pub fn criterion_benchmark(c: &mut Criterion) {
|
||||||
let mut framebuffer = Bitmap::new(320, 240).unwrap();
|
let mut framebuffer = Bitmap::new(320, 240).unwrap();
|
||||||
|
|
|
@ -2,7 +2,7 @@ use std::io::Cursor;
|
||||||
|
|
||||||
use criterion::{black_box, Criterion, criterion_group, criterion_main};
|
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 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");
|
pub static LARGE_GIF_FILE_BYTES: &[u8] = include_bytes!("../test-assets/test_image.gif");
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::audio::*;
|
use thiserror::Error;
|
||||||
|
|
||||||
pub use self::wav::*;
|
use crate::audio::AudioSpec;
|
||||||
|
|
||||||
pub mod wav;
|
pub mod wav;
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ pub struct AudioBuffer {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Debug for 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")
|
f.debug_struct("AudioBuffer")
|
||||||
.field("spec", &self.spec)
|
.field("spec", &self.spec)
|
||||||
.field("data.len()", &self.data.len())
|
.field("data.len()", &self.data.len())
|
||||||
|
|
|
@ -7,7 +7,8 @@ use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
||||||
use sdl2::audio::AudioFormat;
|
use sdl2::audio::AudioFormat;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
use crate::audio::*;
|
use crate::audio::AudioSpec;
|
||||||
|
use crate::audio::buffer::AudioBuffer;
|
||||||
use crate::utils::io::StreamSize;
|
use crate::utils::io::StreamSize;
|
||||||
|
|
||||||
#[derive(Error, Debug)]
|
#[derive(Error, Debug)]
|
||||||
|
@ -298,7 +299,7 @@ impl AudioBuffer {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::audio::*;
|
use crate::audio::{AUDIO_FREQUENCY_22KHZ, AUDIO_FREQUENCY_44KHZ};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,8 @@ use std::ops::{Index, IndexMut};
|
||||||
use sdl2::audio::AudioCallback;
|
use sdl2::audio::AudioCallback;
|
||||||
use thiserror::Error;
|
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
|
/// 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.
|
/// actively playing audio channels to get the final audio playback.
|
||||||
|
@ -30,7 +31,7 @@ pub struct AudioChannel {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Debug for 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")
|
f.debug_struct("AudioChannel")
|
||||||
.field("playing", &self.playing)
|
.field("playing", &self.playing)
|
||||||
.field("loops", &self.loops)
|
.field("loops", &self.loops)
|
||||||
|
|
|
@ -1,17 +1,15 @@
|
||||||
use std::fmt::Formatter;
|
|
||||||
|
|
||||||
use sdl2::audio::{AudioFormat, AudioFormatNum, AudioSpecDesired};
|
use sdl2::audio::{AudioFormat, AudioFormatNum, AudioSpecDesired};
|
||||||
use sdl2::AudioSubsystem;
|
use sdl2::AudioSubsystem;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
pub use self::buffer::*;
|
use crate::audio::device::AudioDevice;
|
||||||
pub use self::device::*;
|
|
||||||
pub use self::queue::*;
|
|
||||||
|
|
||||||
pub mod buffer;
|
pub mod buffer;
|
||||||
pub mod device;
|
pub mod device;
|
||||||
pub mod queue;
|
pub mod queue;
|
||||||
|
|
||||||
|
pub mod prelude;
|
||||||
|
|
||||||
/// The number of simultaneously playing audio channels supported by this library currently.
|
/// The number of simultaneously playing audio channels supported by this library currently.
|
||||||
pub const NUM_CHANNELS: usize = 8;
|
pub const NUM_CHANNELS: usize = 8;
|
||||||
|
|
||||||
|
@ -99,7 +97,7 @@ pub struct Audio {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Debug for 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")
|
f.debug_struct("Audio")
|
||||||
.field("spec", &self.spec)
|
.field("spec", &self.spec)
|
||||||
.finish_non_exhaustive()
|
.finish_non_exhaustive()
|
||||||
|
|
7
ggdt/src/audio/prelude.rs
Normal file
7
ggdt/src/audio/prelude.rs
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
pub use crate::{
|
||||||
|
audio::*,
|
||||||
|
audio::buffer::*,
|
||||||
|
audio::buffer::wav::*,
|
||||||
|
audio::device::*,
|
||||||
|
audio::queue::*,
|
||||||
|
};
|
|
@ -1,7 +1,9 @@
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
use std::rc::Rc;
|
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 {
|
pub enum AudioCommand {
|
||||||
StopChannel(usize),
|
StopChannel(usize),
|
||||||
|
@ -36,7 +38,7 @@ pub enum AudioCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Debug for 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::*;
|
use AudioCommand::*;
|
||||||
match self {
|
match self {
|
||||||
StopChannel(n) => write!(f, "StopChannel({})", n),
|
StopChannel(n) => write!(f, "StopChannel({})", n),
|
||||||
|
|
|
@ -16,14 +16,17 @@
|
||||||
//! context" grab bag:
|
//! context" grab bag:
|
||||||
//!
|
//!
|
||||||
//! ```
|
//! ```
|
||||||
|
//! use ggdt::prelude::*;
|
||||||
|
//!
|
||||||
//! pub enum Event { /* .. various events here .. */ }
|
//! pub enum Event { /* .. various events here .. */ }
|
||||||
|
//!
|
||||||
//! struct App {
|
//! struct App {
|
||||||
//! pub delta: f32,
|
//! pub delta: f32,
|
||||||
//! pub system: ggdt::system::System<ggdt::system::DosLike>,
|
//! pub system: System<DosLike>,
|
||||||
//! pub entities: ggdt::entities::Entities,
|
//! pub entities: Entities,
|
||||||
//! pub component_systems: ggdt::entities::ComponentSystems<App, App>, // oh no! :'(
|
//! pub component_systems: ComponentSystems<App, App>, // oh no! :'(
|
||||||
//! pub event_publisher: ggdt::events::EventPublisher<Event>,
|
//! pub event_publisher: EventPublisher<Event>,
|
||||||
//! pub event_listeners: ggdt::events::EventListeners<Event, App>, // oh no again! :'(
|
//! 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:
|
//! initially went with a parent-child split, which seemed logical to me at the time:
|
||||||
//!
|
//!
|
||||||
//! ```
|
//! ```
|
||||||
|
//! use ggdt::prelude::*;
|
||||||
|
//!
|
||||||
//! pub enum Event { /* .. various events here .. */ }
|
//! pub enum Event { /* .. various events here .. */ }
|
||||||
//!
|
//!
|
||||||
//! // "core" because what the heck else do i call this? "InnerContext"? "InnerApp"? ...
|
//! // "core" because what the heck else do i call this? "InnerContext"? "InnerApp"? ...
|
||||||
//! struct Core {
|
//! struct Core {
|
||||||
//! pub delta: f32,
|
//! pub delta: f32,
|
||||||
//! pub system: ggdt::system::System<ggdt::system::DosLike>,
|
//! pub system: System<DosLike>,
|
||||||
//! pub entities: ggdt::entities::Entities,
|
//! pub entities: Entities,
|
||||||
//! pub event_publisher: ggdt::events::EventPublisher<Event>,
|
//! 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
|
//! // i guess this is a bit more obvious what to call it, but still ... doesn't sit right with me
|
||||||
//! struct App {
|
//! struct App {
|
||||||
//! pub core: Core,
|
//! pub core: Core,
|
||||||
//! pub component_systems: ggdt::entities::ComponentSystems<Core, Core>,
|
//! pub component_systems: ComponentSystems<Core, Core>,
|
||||||
//! pub event_listeners: ggdt::events::EventListeners<Event, Core>,
|
//! pub event_listeners: EventListeners<Event, Core>,
|
||||||
//! }
|
//! }
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
|
@ -75,22 +80,24 @@
|
||||||
//! But again, better naming still eludes me here!
|
//! But again, better naming still eludes me here!
|
||||||
//!
|
//!
|
||||||
//! ```
|
//! ```
|
||||||
|
//! use ggdt::prelude::*;
|
||||||
|
//!
|
||||||
//! pub enum Event { /* .. various events here .. */ }
|
//! pub enum Event { /* .. various events here .. */ }
|
||||||
//!
|
//!
|
||||||
//! // "Core" because it contains the things that probably 90% of game/app code will need to work
|
//! // "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.
|
//! // with. you'd probably want to put your game/app resources/assets on this struct too.
|
||||||
//! struct Core {
|
//! struct Core {
|
||||||
//! pub delta: f32,
|
//! pub delta: f32,
|
||||||
//! pub system: ggdt::system::System<ggdt::system::DosLike>,
|
//! pub system: System<DosLike>,
|
||||||
//! pub entities: ggdt::entities::Entities,
|
//! pub entities: Entities,
|
||||||
//! pub event_publisher: ggdt::events::EventPublisher<Event>,
|
//! pub event_publisher: EventPublisher<Event>,
|
||||||
//! }
|
//! }
|
||||||
//!
|
//!
|
||||||
//! // "Support" because it contains things that support the main/core game state?
|
//! // "Support" because it contains things that support the main/core game state?
|
||||||
//! // kinda grasping at straws here maybe ...
|
//! // kinda grasping at straws here maybe ...
|
||||||
//! struct Support {
|
//! struct Support {
|
||||||
//! pub component_systems: ggdt::entities::ComponentSystems<Core, Core>,
|
//! pub component_systems: ComponentSystems<Core, Core>,
|
||||||
//! pub event_listeners: ggdt::events::EventListeners<Event, Core>,
|
//! pub event_listeners: EventListeners<Event, Core>,
|
||||||
//! }
|
//! }
|
||||||
//!
|
//!
|
||||||
//! // better, maybe?
|
//! // better, maybe?
|
||||||
|
@ -124,10 +131,11 @@
|
||||||
|
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
use crate::audio::*;
|
use crate::audio::device::AudioDeviceError;
|
||||||
use crate::events::*;
|
use crate::events::{EventListeners, EventPublisher};
|
||||||
use crate::states::*;
|
use crate::states::{AppState, StateError, States};
|
||||||
use crate::system::*;
|
use crate::system::{System, SystemError};
|
||||||
|
use crate::system::res::SystemResources;
|
||||||
|
|
||||||
pub trait CoreState<SystemResType>
|
pub trait CoreState<SystemResType>
|
||||||
where SystemResType: SystemResources {
|
where SystemResType: SystemResources {
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use std::any::TypeId;
|
use std::any::TypeId;
|
||||||
use std::cell::{Ref, RefCell, RefMut};
|
use std::cell::{Ref, RefCell, RefMut};
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
use std::fmt::Formatter;
|
|
||||||
|
|
||||||
use crate::utils::AsAny;
|
use crate::utils::AsAny;
|
||||||
|
|
||||||
|
@ -71,7 +70,7 @@ pub struct Entities {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Debug for 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")
|
f.debug_struct("Entities")
|
||||||
.field("entities.len()", &self.entities.len())
|
.field("entities.len()", &self.entities.len())
|
||||||
.field("component_stores.keys()", &self.component_stores.keys())
|
.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> {
|
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")
|
f.debug_struct("ComponentSystems")
|
||||||
.field("update_systems.len()", &self.update_systems.len())
|
.field("update_systems.len()", &self.update_systems.len())
|
||||||
.field("render_systems.len()", &self.render_systems.len())
|
.field("render_systems.len()", &self.render_systems.len())
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
use std::fmt::Formatter;
|
|
||||||
|
|
||||||
/// An event listener/handler function that returns true if it handled the event and no other
|
/// 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
|
/// 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> {
|
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")
|
f.debug_struct("EventPublisher")
|
||||||
.field("queue.len()", &self.queue.len())
|
.field("queue.len()", &self.queue.len())
|
||||||
.finish_non_exhaustive()
|
.finish_non_exhaustive()
|
||||||
|
@ -68,7 +67,7 @@ pub struct EventListeners<EventType, ContextType> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<EventType, ContextType> std::fmt::Debug for 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")
|
f.debug_struct("EventListeners")
|
||||||
.field("listeners.len()", &self.listeners.len())
|
.field("listeners.len()", &self.listeners.len())
|
||||||
.field("dispatch_queue.len()", &self.dispatch_queue.len())
|
.field("dispatch_queue.len()", &self.dispatch_queue.len())
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
|
||||||
use crate::graphics::{indexed, Pixel};
|
use crate::graphics::{indexed, Pixel};
|
||||||
use crate::math::Rect;
|
use crate::math::rect::Rect;
|
||||||
|
|
||||||
#[derive(Clone, PartialEq)]
|
#[derive(Clone, PartialEq)]
|
||||||
pub enum GeneralBlitMethod<PixelType: Pixel> {
|
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 PixelType = u8;
|
||||||
type ErrorType = indexed::BitmapError;
|
type ErrorType = indexed::bitmap::BitmapError;
|
||||||
|
|
||||||
fn new(width: u32, height: u32) -> Result<Self, Self::ErrorType> {
|
fn new(width: u32, height: u32) -> Result<Self, Self::ErrorType> {
|
||||||
Self::new(width, height)
|
Self::new(width, height)
|
||||||
|
@ -179,9 +179,11 @@ impl GeneralBitmap for indexed::Bitmap {
|
||||||
dest_x: i32,
|
dest_x: i32,
|
||||||
dest_y: i32
|
dest_y: i32
|
||||||
) {
|
) {
|
||||||
|
use indexed::bitmap::blit::BlitMethod;
|
||||||
|
|
||||||
let blit_method = match method {
|
let blit_method = match method {
|
||||||
GeneralBlitMethod::Solid => indexed::BlitMethod::Solid,
|
GeneralBlitMethod::Solid => BlitMethod::Solid,
|
||||||
GeneralBlitMethod::Transparent(color) => indexed::BlitMethod::Transparent(color),
|
GeneralBlitMethod::Transparent(color) => BlitMethod::Transparent(color),
|
||||||
};
|
};
|
||||||
self.blit_region(blit_method, src, src_region, dest_x, dest_y)
|
self.blit_region(blit_method, src, src_region, dest_x, dest_y)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,8 @@ use std::ops::Index;
|
||||||
|
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
use crate::graphics::*;
|
use crate::graphics::bitmap::GeneralBitmap;
|
||||||
use crate::math::*;
|
use crate::math::rect::Rect;
|
||||||
|
|
||||||
#[derive(Error, Debug)]
|
#[derive(Error, Debug)]
|
||||||
pub enum BitmapAtlasError {
|
pub enum BitmapAtlasError {
|
||||||
|
@ -134,13 +134,13 @@ where
|
||||||
pub mod tests {
|
pub mod tests {
|
||||||
use claim::*;
|
use claim::*;
|
||||||
|
|
||||||
use super::*;
|
use crate::graphics::indexed::bitmap::Bitmap;
|
||||||
|
|
||||||
use crate::graphics::indexed;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
pub fn adding_rects() {
|
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 mut atlas = BitmapAtlas::new(bmp);
|
||||||
|
|
||||||
let rect = Rect::new(0, 0, 16, 16);
|
let rect = Rect::new(0, 0, 16, 16);
|
||||||
|
@ -174,7 +174,7 @@ pub mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
pub fn adding_grid() {
|
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);
|
let mut atlas = BitmapAtlas::new(bmp);
|
||||||
|
|
||||||
assert_eq!(3, atlas.add_custom_grid(0, 0, 8, 8, 2, 2, 0).unwrap());
|
assert_eq!(3, atlas.add_custom_grid(0, 0, 8, 8, 2, 2, 0).unwrap());
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
use std::fmt::Formatter;
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{BufReader, BufWriter, Cursor};
|
use std::io::{BufReader, BufWriter, Cursor};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
@ -6,8 +5,9 @@ use std::path::Path;
|
||||||
use byteorder::{ReadBytesExt, WriteBytesExt};
|
use byteorder::{ReadBytesExt, WriteBytesExt};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
use crate::graphics::*;
|
use crate::graphics::bitmap::GeneralBitmap;
|
||||||
use crate::math::*;
|
use crate::graphics::Pixel;
|
||||||
|
use crate::math::rect::Rect;
|
||||||
|
|
||||||
pub static VGA_FONT_BYTES: &[u8] = include_bytes!("../../assets/vga.fnt");
|
pub static VGA_FONT_BYTES: &[u8] = include_bytes!("../../assets/vga.fnt");
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ pub struct BitmaskFont {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Debug for 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")
|
f.debug_struct("BitmaskFont")
|
||||||
.field("line_height", &self.line_height)
|
.field("line_height", &self.line_height)
|
||||||
.field("space_width", &self.space_width)
|
.field("space_width", &self.space_width)
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use crate::graphics::BitmapAtlas;
|
|
||||||
|
|
||||||
use crate::graphics::indexed::*;
|
use crate::graphics::bitmapatlas::BitmapAtlas;
|
||||||
use crate::math::*;
|
use crate::graphics::indexed::bitmap::Bitmap;
|
||||||
|
use crate::graphics::indexed::blendmap::BlendMap;
|
||||||
|
use crate::math::rect::Rect;
|
||||||
|
|
||||||
#[derive(Clone, PartialEq)]
|
#[derive(Clone, PartialEq)]
|
||||||
pub enum BlitMethod {
|
pub enum BlitMethod {
|
||||||
|
|
|
@ -5,8 +5,9 @@ use std::path::Path;
|
||||||
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
use crate::graphics::indexed::*;
|
use crate::graphics::indexed::bitmap::Bitmap;
|
||||||
use crate::utils::lzwgif::*;
|
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`
|
const BITS_FOR_256_COLORS: u32 = 7; // formula is `2 ^ (bits + 1) = num_colors`
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,9 @@ use std::path::Path;
|
||||||
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
|
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
use crate::graphics::indexed::*;
|
use crate::graphics::indexed::bitmap::Bitmap;
|
||||||
use crate::utils::packbits::*;
|
use crate::graphics::indexed::palette::{Palette, PaletteError, PaletteFormat};
|
||||||
|
use crate::utils::packbits::{pack_bits, PackBitsError, unpack_bits};
|
||||||
|
|
||||||
#[derive(Error, Debug)]
|
#[derive(Error, Debug)]
|
||||||
pub enum IffError {
|
pub enum IffError {
|
||||||
|
|
|
@ -1,17 +1,10 @@
|
||||||
use std::fmt::Formatter;
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::slice;
|
use std::slice;
|
||||||
|
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
use crate::graphics::indexed::*;
|
use crate::graphics::indexed::palette::Palette;
|
||||||
use crate::math::*;
|
use crate::math::rect::Rect;
|
||||||
|
|
||||||
pub use self::blit::*;
|
|
||||||
pub use self::gif::*;
|
|
||||||
pub use self::iff::*;
|
|
||||||
pub use self::pcx::*;
|
|
||||||
pub use self::primitives::*;
|
|
||||||
|
|
||||||
pub mod blit;
|
pub mod blit;
|
||||||
pub mod gif;
|
pub mod gif;
|
||||||
|
@ -55,7 +48,7 @@ pub struct Bitmap {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Debug for 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")
|
f.debug_struct("Bitmap")
|
||||||
.field("width", &self.width)
|
.field("width", &self.width)
|
||||||
.field("height", &self.height)
|
.field("height", &self.height)
|
||||||
|
|
|
@ -5,7 +5,8 @@ use std::path::Path;
|
||||||
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
||||||
use thiserror::Error;
|
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;
|
use crate::utils::bytes::ReadFixedLengthByteArray;
|
||||||
|
|
||||||
#[derive(Error, Debug)]
|
#[derive(Error, Debug)]
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
use std::mem::swap;
|
use std::mem::swap;
|
||||||
|
|
||||||
use crate::graphics::*;
|
use crate::graphics::font::{Character, Font, FontRenderOpts};
|
||||||
use crate::graphics::indexed::*;
|
use crate::graphics::indexed::bitmap::Bitmap;
|
||||||
use crate::math::*;
|
use crate::graphics::indexed::blendmap::BlendMap;
|
||||||
|
use crate::math::rect::Rect;
|
||||||
|
|
||||||
impl Bitmap {
|
impl Bitmap {
|
||||||
/// Fills the entire bitmap with the given color.
|
/// Fills the entire bitmap with the given color.
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
use std::fmt::Formatter;
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{BufReader, BufWriter};
|
use std::io::{BufReader, BufWriter};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
@ -6,8 +5,8 @@ use std::path::Path;
|
||||||
use byteorder::{ReadBytesExt, WriteBytesExt};
|
use byteorder::{ReadBytesExt, WriteBytesExt};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
use crate::graphics::indexed::*;
|
use crate::graphics::indexed::palette::{from_rgb32, luminance, Palette};
|
||||||
use crate::math::*;
|
use crate::math::lerp;
|
||||||
use crate::utils::bytes::ReadFixedLengthByteArray;
|
use crate::utils::bytes::ReadFixedLengthByteArray;
|
||||||
|
|
||||||
#[derive(Error, Debug)]
|
#[derive(Error, Debug)]
|
||||||
|
@ -45,7 +44,7 @@ pub struct BlendMap {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Debug for 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")
|
f.debug_struct("BlendMap")
|
||||||
.field("start_color", &self.start_color)
|
.field("start_color", &self.start_color)
|
||||||
.field("end_color", &self.end_color)
|
.field("end_color", &self.end_color)
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
//! This module and all sub-modules contain graphics functionality that uses indexed colours. That is, each pixel
|
//! 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.
|
//! 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 bitmap;
|
||||||
pub mod blendmap;
|
pub mod blendmap;
|
||||||
pub mod palette;
|
pub mod palette;
|
||||||
|
|
||||||
|
pub mod prelude;
|
|
@ -7,7 +7,7 @@ use std::path::Path;
|
||||||
use byteorder::{ReadBytesExt, WriteBytesExt};
|
use byteorder::{ReadBytesExt, WriteBytesExt};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
use crate::graphics::indexed::*;
|
use crate::graphics::indexed::bitmap::Bitmap;
|
||||||
use crate::NUM_COLORS;
|
use crate::NUM_COLORS;
|
||||||
use crate::utils::abs_diff;
|
use crate::utils::abs_diff;
|
||||||
|
|
||||||
|
|
21
ggdt/src/graphics/indexed/prelude.rs
Normal file
21
ggdt/src/graphics/indexed/prelude.rs
Normal 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,
|
||||||
|
};
|
|
@ -1,15 +1,13 @@
|
||||||
use num_traits::{PrimInt, Unsigned};
|
use num_traits::{PrimInt, Unsigned};
|
||||||
|
|
||||||
pub use self::bitmap::*;
|
|
||||||
pub use self::bitmapatlas::*;
|
|
||||||
pub use self::font::*;
|
|
||||||
|
|
||||||
pub mod bitmap;
|
pub mod bitmap;
|
||||||
pub mod bitmapatlas;
|
pub mod bitmapatlas;
|
||||||
pub mod font;
|
pub mod font;
|
||||||
pub mod indexed;
|
pub mod indexed;
|
||||||
pub mod rgb;
|
pub mod rgb;
|
||||||
|
|
||||||
|
pub mod prelude;
|
||||||
|
|
||||||
/// Common trait to represent single pixel/colour values.
|
/// Common trait to represent single pixel/colour values.
|
||||||
pub trait Pixel: PrimInt + Unsigned {}
|
pub trait Pixel: PrimInt + Unsigned {}
|
||||||
impl<T> Pixel for T where T: PrimInt + Unsigned {}
|
impl<T> Pixel for T where T: PrimInt + Unsigned {}
|
||||||
|
|
8
ggdt/src/graphics/prelude.rs
Normal file
8
ggdt/src/graphics/prelude.rs
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
pub use crate::graphics::{
|
||||||
|
*,
|
||||||
|
bitmap::*,
|
||||||
|
bitmapatlas::*,
|
||||||
|
font::*,
|
||||||
|
indexed::prelude::*,
|
||||||
|
rgb::prelude::*,
|
||||||
|
};
|
|
@ -1,2 +1,4 @@
|
||||||
//! This module and all sub-modules contain graphics functionality that uses 32-bit colour data. That is, each pixel
|
//! 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.
|
//! is a `u32` and contains full RGBA information.
|
||||||
|
|
||||||
|
pub mod prelude;
|
||||||
|
|
13
ggdt/src/graphics/rgb/prelude.rs
Normal file
13
ggdt/src/graphics/rgb/prelude.rs
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
// include all things useable for 32-bit colour graphics
|
||||||
|
|
||||||
|
pub use crate::graphics::{
|
||||||
|
bitmap::*,
|
||||||
|
bitmapatlas::*,
|
||||||
|
font::*,
|
||||||
|
Pixel,
|
||||||
|
rgb::{
|
||||||
|
*,
|
||||||
|
// todo
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
|
@ -11,6 +11,8 @@ pub mod states;
|
||||||
pub mod system;
|
pub mod system;
|
||||||
pub mod utils;
|
pub mod utils;
|
||||||
|
|
||||||
|
pub mod prelude;
|
||||||
|
|
||||||
pub const LOW_RES: bool = if cfg!(feature = "low_res") {
|
pub const LOW_RES: bool = if cfg!(feature = "low_res") {
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -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.
|
/// Represents a 2D circle, using integer center coordinates and radius.
|
||||||
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use std::ops::{Mul, MulAssign};
|
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.
|
/// Represents a 3x3 column-major matrix and provides common methods for matrix math.
|
||||||
#[derive(Debug, Copy, Clone, PartialEq)]
|
#[derive(Debug, Copy, Clone, PartialEq)]
|
||||||
|
@ -284,6 +285,8 @@ impl Mul<Vector2> for Matrix3x3 {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub mod tests {
|
pub mod tests {
|
||||||
|
use crate::math::*;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -1,15 +1,12 @@
|
||||||
use std::ops::{Add, Div, Mul, Sub};
|
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 circle;
|
||||||
pub mod matrix3x3;
|
pub mod matrix3x3;
|
||||||
pub mod rect;
|
pub mod rect;
|
||||||
pub mod vector2;
|
pub mod vector2;
|
||||||
|
|
||||||
|
pub mod prelude;
|
||||||
|
|
||||||
pub const PI: f32 = std::f32::consts::PI;
|
pub const PI: f32 = std::f32::consts::PI;
|
||||||
// 180 degrees
|
// 180 degrees
|
||||||
pub const HALF_PI: f32 = PI / 2.0;
|
pub const HALF_PI: f32 = PI / 2.0;
|
||||||
|
|
8
ggdt/src/math/prelude.rs
Normal file
8
ggdt/src/math/prelude.rs
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
pub use crate::math::{
|
||||||
|
*,
|
||||||
|
circle::*,
|
||||||
|
matrix3x3::*,
|
||||||
|
rect::*,
|
||||||
|
vector2::*,
|
||||||
|
};
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
|
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.
|
/// Represents a 2D vector and provides common methods for vector math.
|
||||||
#[derive(Debug, Copy, Clone, PartialEq)]
|
#[derive(Debug, Copy, Clone, PartialEq)]
|
||||||
|
@ -251,6 +252,8 @@ impl MulAssign<Matrix3x3> for Vector2 {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub mod tests {
|
pub mod tests {
|
||||||
|
use crate::math::*;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
42
ggdt/src/prelude.rs
Normal file
42
ggdt/src/prelude.rs
Normal 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::*,
|
||||||
|
};
|
||||||
|
}
|
|
@ -1,5 +1,4 @@
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
use std::fmt::Formatter;
|
|
||||||
use std::ops::DerefMut;
|
use std::ops::DerefMut;
|
||||||
|
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
@ -36,7 +35,7 @@ pub enum StateChange<ContextType> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<ContextType> std::fmt::Debug for 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::*;
|
use StateChange::*;
|
||||||
match *self {
|
match *self {
|
||||||
Push(..) => write!(f, "Push"),
|
Push(..) => write!(f, "Push"),
|
||||||
|
@ -71,7 +70,7 @@ struct StateContainer<ContextType> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<ContextType> std::fmt::Debug for 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")
|
f.debug_struct("StateContainer")
|
||||||
.field("current_state", &self.current_state)
|
.field("current_state", &self.current_state)
|
||||||
.field("pending_state_change", &self.pending_state_change)
|
.field("pending_state_change", &self.pending_state_change)
|
||||||
|
@ -185,7 +184,7 @@ pub struct States<ContextType> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<ContextType> std::fmt::Debug for 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")
|
f.debug_struct("States")
|
||||||
.field("states", &self.states)
|
.field("states", &self.states)
|
||||||
.field("command", &self.command)
|
.field("command", &self.command)
|
||||||
|
|
|
@ -11,8 +11,9 @@
|
||||||
|
|
||||||
use bitflags::bitflags;
|
use bitflags::bitflags;
|
||||||
|
|
||||||
use crate::system::{Keycode, MouseButton, MouseButtons, Scancode};
|
use crate::system::input_devices::keyboard::codes::Keycode;
|
||||||
use crate::system::MouseEvent::MouseButtonUp;
|
use crate::system::input_devices::keyboard::scancodes::Scancode;
|
||||||
|
use crate::system::input_devices::mouse::buttons::{MouseButton, MouseButtons};
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub enum WindowEvent {
|
pub enum WindowEvent {
|
||||||
|
@ -175,7 +176,7 @@ impl From<sdl2::event::Event> for SystemEvent {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
sdl2::event::Event::MouseButtonUp { mouse_btn, clicks, x, y, .. } => {
|
sdl2::event::Event::MouseButtonUp { mouse_btn, clicks, x, y, .. } => {
|
||||||
SystemEvent::Mouse(MouseButtonUp {
|
SystemEvent::Mouse(MouseEvent::MouseButtonUp {
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
clicks,
|
clicks,
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
use crate::system::event::{KeyboardEvent, SystemEvent};
|
use crate::system::event::{KeyboardEvent, SystemEvent, SystemEventHandler};
|
||||||
|
use crate::system::input_devices::{ButtonState, InputDevice};
|
||||||
use super::*;
|
use crate::system::input_devices::keyboard::scancodes::Scancode;
|
||||||
|
|
||||||
pub use self::codes::*;
|
|
||||||
pub use self::scancodes::*;
|
|
||||||
|
|
||||||
pub mod codes;
|
pub mod codes;
|
||||||
pub mod scancodes;
|
pub mod scancodes;
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
use crate::system::{SystemEvent, SystemEventHandler};
|
|
||||||
|
|
||||||
pub mod keyboard;
|
pub mod keyboard;
|
||||||
pub mod mouse;
|
pub mod mouse;
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
use crate::graphics::*;
|
use crate::graphics::bitmap::{GeneralBitmap, GeneralBlitMethod};
|
||||||
use crate::graphics::indexed::*;
|
use crate::graphics::indexed;
|
||||||
use crate::math::*;
|
use crate::math::rect::Rect;
|
||||||
|
use crate::system::input_devices::mouse::Mouse;
|
||||||
use super::*;
|
|
||||||
|
|
||||||
const DEFAULT_MOUSE_CURSOR_HOTSPOT_X: u32 = 0;
|
const DEFAULT_MOUSE_CURSOR_HOTSPOT_X: u32 = 0;
|
||||||
const DEFAULT_MOUSE_CURSOR_HOTSPOT_Y: u32 = 0;
|
const DEFAULT_MOUSE_CURSOR_HOTSPOT_Y: u32 = 0;
|
||||||
|
@ -206,8 +205,8 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DefaultMouseCursorBitmaps<indexed::Bitmap> for CustomMouseCursor<indexed::Bitmap> {
|
impl DefaultMouseCursorBitmaps<indexed::bitmap::Bitmap> for CustomMouseCursor<indexed::bitmap::Bitmap> {
|
||||||
fn get_default() -> MouseCursorBitmap<indexed::Bitmap> {
|
fn get_default() -> MouseCursorBitmap<indexed::bitmap::Bitmap> {
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
const CURSOR_PIXELS: [u8; DEFAULT_MOUSE_CURSOR_WIDTH * DEFAULT_MOUSE_CURSOR_HEIGHT] = [
|
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,
|
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
|
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_WIDTH as u32,
|
||||||
DEFAULT_MOUSE_CURSOR_HEIGHT as u32,
|
DEFAULT_MOUSE_CURSOR_HEIGHT as u32,
|
||||||
).unwrap();
|
).unwrap();
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
use crate::math::*;
|
use crate::system::event::{MouseEvent, SystemEvent, SystemEventHandler};
|
||||||
use crate::system::MouseEvent;
|
use crate::system::input_devices::{ButtonState, InputDevice};
|
||||||
|
use crate::system::input_devices::mouse::buttons::{MouseButton, MouseButtons};
|
||||||
use super::*;
|
|
||||||
|
|
||||||
pub use self::buttons::*;
|
|
||||||
pub use self::cursor::*;
|
|
||||||
|
|
||||||
pub mod buttons;
|
pub mod buttons;
|
||||||
pub mod cursor;
|
pub mod cursor;
|
||||||
|
|
|
@ -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 thiserror::Error;
|
||||||
|
|
||||||
use crate::{DEFAULT_SCALE_FACTOR, SCREEN_HEIGHT, SCREEN_WIDTH};
|
use crate::audio::AudioError;
|
||||||
use crate::audio::*;
|
use crate::system::event::{SystemEvent, SystemEventPump};
|
||||||
|
use crate::system::res::{SystemResources, SystemResourcesConfig, SystemResourcesError};
|
||||||
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::*;
|
|
||||||
|
|
||||||
pub mod event;
|
pub mod event;
|
||||||
pub mod input_devices;
|
pub mod input_devices;
|
||||||
pub mod res;
|
pub mod res;
|
||||||
|
|
||||||
|
pub mod prelude;
|
||||||
|
|
||||||
fn is_x11_compositor_skipping_problematic() -> bool {
|
fn is_x11_compositor_skipping_problematic() -> bool {
|
||||||
/*
|
/*
|
||||||
this is _probably_ a bit of a hack.
|
this is _probably_ a bit of a hack.
|
||||||
|
@ -233,10 +222,10 @@ impl SystemBuilder {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub struct System<SystemResType>
|
pub struct System<SystemResType>
|
||||||
where SystemResType: SystemResources {
|
where SystemResType: SystemResources {
|
||||||
sdl_context: Sdl,
|
sdl_context: sdl2::Sdl,
|
||||||
sdl_audio_subsystem: AudioSubsystem,
|
sdl_audio_subsystem: sdl2::AudioSubsystem,
|
||||||
sdl_video_subsystem: VideoSubsystem,
|
sdl_video_subsystem: sdl2::VideoSubsystem,
|
||||||
sdl_timer_subsystem: TimerSubsystem,
|
sdl_timer_subsystem: sdl2::TimerSubsystem,
|
||||||
|
|
||||||
vsync: bool,
|
vsync: bool,
|
||||||
target_framerate: Option<u32>,
|
target_framerate: Option<u32>,
|
||||||
|
@ -250,7 +239,7 @@ where SystemResType: SystemResources {
|
||||||
|
|
||||||
impl<SystemResType> std::fmt::Debug for System<SystemResType>
|
impl<SystemResType> std::fmt::Debug for System<SystemResType>
|
||||||
where SystemResType: SystemResources {
|
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")
|
f.debug_struct("System")
|
||||||
.field("res", &self.res)
|
.field("res", &self.res)
|
||||||
.field("vsync", &self.vsync)
|
.field("vsync", &self.vsync)
|
||||||
|
@ -305,7 +294,7 @@ where SystemResType: SystemResources {
|
||||||
/// should quit. Otherwise, returns false.
|
/// should quit. Otherwise, returns false.
|
||||||
///
|
///
|
||||||
/// ```no_run
|
/// ```no_run
|
||||||
/// use ggdt::system::*;
|
/// use ggdt::prelude::*;
|
||||||
///
|
///
|
||||||
/// let config = DosLikeConfig::new();
|
/// let config = DosLikeConfig::new();
|
||||||
/// let mut system = SystemBuilder::new().window_title("Example").build(config).unwrap();
|
/// let mut system = SystemBuilder::new().window_title("Example").build(config).unwrap();
|
||||||
|
@ -320,7 +309,7 @@ where SystemResType: SystemResources {
|
||||||
/// main loop. For example:
|
/// main loop. For example:
|
||||||
///
|
///
|
||||||
/// ```no_run
|
/// ```no_run
|
||||||
/// use ggdt::system::*;
|
/// use ggdt::prelude::*;
|
||||||
///
|
///
|
||||||
/// let config = DosLikeConfig::new();
|
/// let config = DosLikeConfig::new();
|
||||||
/// let mut system = SystemBuilder::new().window_title("Example").build(config).unwrap();
|
/// let mut system = SystemBuilder::new().window_title("Example").build(config).unwrap();
|
||||||
|
|
22
ggdt/src/system/prelude.rs
Normal file
22
ggdt/src/system/prelude.rs
Normal 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
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
|
@ -2,9 +2,7 @@
|
||||||
//! instance to provide something resembling an old DOS VGA mode 13h style experience (there are differences, however).
|
//! instance to provide something resembling an old DOS VGA mode 13h style experience (there are differences, however).
|
||||||
//!
|
//!
|
||||||
//! ```no_run
|
//! ```no_run
|
||||||
//! use ggdt::graphics::*;
|
//! use ggdt::prelude::*;
|
||||||
//! use ggdt::graphics::indexed::*;
|
|
||||||
//! use ggdt::system::*;
|
|
||||||
//!
|
//!
|
||||||
//! let config = DosLikeConfig::new();
|
//! let config = DosLikeConfig::new();
|
||||||
//! let mut system = SystemBuilder::new()
|
//! let mut system = SystemBuilder::new()
|
||||||
|
@ -28,11 +26,20 @@
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
|
|
||||||
use sdl2::video::Window;
|
use byte_slice_cast::AsByteSlice;
|
||||||
|
|
||||||
use crate::system::*;
|
use crate::{DEFAULT_SCALE_FACTOR, SCREEN_HEIGHT, SCREEN_WIDTH};
|
||||||
use crate::graphics::*;
|
use crate::audio::{Audio, TARGET_AUDIO_CHANNELS, TARGET_AUDIO_FREQUENCY};
|
||||||
use crate::graphics::indexed::*;
|
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`].
|
/// Configuration / builder for configuring and constructing an instance of [`DosLike`].
|
||||||
pub struct DosLikeConfig {
|
pub struct DosLikeConfig {
|
||||||
|
@ -75,9 +82,9 @@ impl SystemResourcesConfig for DosLikeConfig {
|
||||||
|
|
||||||
fn build(
|
fn build(
|
||||||
self,
|
self,
|
||||||
_video_subsystem: &VideoSubsystem,
|
_video_subsystem: &sdl2::VideoSubsystem,
|
||||||
audio_subsystem: &AudioSubsystem,
|
audio_subsystem: &sdl2::AudioSubsystem,
|
||||||
mut window: Window,
|
mut window: sdl2::video::Window,
|
||||||
) -> Result<Self::SystemResourcesType, SystemResourcesError> {
|
) -> Result<Self::SystemResourcesType, SystemResourcesError> {
|
||||||
let texture_pixel_size = 4; // 32-bit ARGB format
|
let texture_pixel_size = 4; // 32-bit ARGB format
|
||||||
|
|
||||||
|
@ -114,7 +121,7 @@ impl SystemResourcesConfig for DosLikeConfig {
|
||||||
// application's framebuffer
|
// application's framebuffer
|
||||||
|
|
||||||
let sdl_texture = match sdl_canvas.create_texture_streaming(
|
let sdl_texture = match sdl_canvas.create_texture_streaming(
|
||||||
Some(PixelFormatEnum::ARGB8888),
|
Some(sdl2::pixels::PixelFormatEnum::ARGB8888),
|
||||||
self.screen_width,
|
self.screen_width,
|
||||||
self.screen_height,
|
self.screen_height,
|
||||||
) {
|
) {
|
||||||
|
@ -155,7 +162,7 @@ impl SystemResourcesConfig for DosLikeConfig {
|
||||||
|
|
||||||
// create audio device and queue
|
// create audio device and queue
|
||||||
|
|
||||||
let audio_spec = AudioSpecDesired {
|
let audio_spec = sdl2::audio::AudioSpecDesired {
|
||||||
freq: Some(TARGET_AUDIO_FREQUENCY as i32),
|
freq: Some(TARGET_AUDIO_FREQUENCY as i32),
|
||||||
channels: Some(TARGET_AUDIO_CHANNELS),
|
channels: Some(TARGET_AUDIO_CHANNELS),
|
||||||
samples: None,
|
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
|
/// A [`SystemResources`] implementation that provides indexed-colour [`Bitmap`]s for graphics, simple 8-bit / 22khz
|
||||||
/// audio via [`Audio`] and keyboard/mouse input.
|
/// audio via [`Audio`] and keyboard/mouse input.
|
||||||
pub struct DosLike {
|
pub struct DosLike {
|
||||||
sdl_canvas: WindowCanvas,
|
sdl_canvas: sdl2::render::WindowCanvas,
|
||||||
sdl_texture: Texture,
|
sdl_texture: sdl2::render::Texture,
|
||||||
sdl_texture_pitch: usize,
|
sdl_texture_pitch: usize,
|
||||||
texture_pixels: Box<[u32]>,
|
texture_pixels: Box<[u32]>,
|
||||||
|
|
||||||
|
@ -230,7 +237,7 @@ pub struct DosLike {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Debug for 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")
|
f.debug_struct("DosLike")
|
||||||
.field("audio", &self.audio)
|
.field("audio", &self.audio)
|
||||||
.field("audio_queue", &self.audio_queue)
|
.field("audio_queue", &self.audio_queue)
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
use crate::audio::*;
|
use crate::audio::AudioError;
|
||||||
use crate::system::*;
|
use crate::audio::device::AudioDeviceError;
|
||||||
|
use crate::system::event::SystemEvent;
|
||||||
|
|
||||||
pub mod dos_like;
|
pub mod dos_like;
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,8 @@ pub mod io;
|
||||||
pub mod lzwgif;
|
pub mod lzwgif;
|
||||||
pub mod packbits;
|
pub mod packbits;
|
||||||
|
|
||||||
|
pub mod prelude;
|
||||||
|
|
||||||
pub fn rnd_value<N: SampleUniform + PartialOrd>(low: N, high: N) -> N {
|
pub fn rnd_value<N: SampleUniform + PartialOrd>(low: N, high: N) -> N {
|
||||||
rand::thread_rng().gen_range(low..=high)
|
rand::thread_rng().gen_range(low..=high)
|
||||||
}
|
}
|
||||||
|
|
8
ggdt/src/utils/prelude.rs
Normal file
8
ggdt/src/utils/prelude.rs
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
pub use crate::utils::{
|
||||||
|
*,
|
||||||
|
bytes::*,
|
||||||
|
io::*,
|
||||||
|
lzwgif::*,
|
||||||
|
packbits::*,
|
||||||
|
};
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
use ggdt::{SCREEN_HEIGHT, SCREEN_WIDTH};
|
use ggdt::prelude::*;
|
||||||
use ggdt::graphics::*;
|
|
||||||
use ggdt::graphics::indexed::*;
|
|
||||||
|
|
||||||
fn setup() -> (Bitmap, Palette) {
|
fn setup() -> (Bitmap, Palette) {
|
||||||
let palette = Palette::new_vga_palette().unwrap();
|
let palette = Palette::new_vga_palette().unwrap();
|
||||||
|
|
Loading…
Reference in a new issue