From 441cb4cf817178b7c2f3e314c27cb1ddf8a7077e Mon Sep 17 00:00:00 2001 From: Able Date: Tue, 7 Mar 2023 21:52:03 -0600 Subject: [PATCH] add in other sections of the AGL that will be supported in ableOS --- Cargo.lock | 2 +- libraries/able_graphics_library/Cargo.toml | 2 +- libraries/able_graphics_library/src/color.rs | 22 +---- .../src/{ => engine3d}/buffer.rs | 0 .../src/engine3d/color.rs | 21 ++++ .../src/{ => engine3d}/commands.rs | 2 +- .../src/{ => engine3d}/display.rs | 0 .../src/{ => engine3d}/framebuffer.rs | 2 +- .../able_graphics_library/src/engine3d/mod.rs | 7 ++ .../src/{ => engine3d}/types.rs | 0 .../src/{ => engine3d}/vertex.rs | 2 +- libraries/able_graphics_library/src/lib.rs | 31 ++++-- .../src/ptmode/freeform/mod.rs | 1 + .../able_graphics_library/src/ptmode/mod.rs | 19 ++++ .../src/ptmode/true_nes/mod.rs | 99 +++++++++++++++++++ .../src/ptmode/true_snes/mod.rs | 1 + .../src/raw_pixel/lib.rs | 1 + 17 files changed, 179 insertions(+), 33 deletions(-) rename libraries/able_graphics_library/src/{ => engine3d}/buffer.rs (100%) create mode 100644 libraries/able_graphics_library/src/engine3d/color.rs rename libraries/able_graphics_library/src/{ => engine3d}/commands.rs (98%) rename libraries/able_graphics_library/src/{ => engine3d}/display.rs (100%) rename libraries/able_graphics_library/src/{ => engine3d}/framebuffer.rs (98%) create mode 100644 libraries/able_graphics_library/src/engine3d/mod.rs rename libraries/able_graphics_library/src/{ => engine3d}/types.rs (100%) rename libraries/able_graphics_library/src/{ => engine3d}/vertex.rs (95%) create mode 100644 libraries/able_graphics_library/src/ptmode/freeform/mod.rs create mode 100644 libraries/able_graphics_library/src/ptmode/mod.rs create mode 100644 libraries/able_graphics_library/src/ptmode/true_nes/mod.rs create mode 100644 libraries/able_graphics_library/src/ptmode/true_snes/mod.rs create mode 100644 libraries/able_graphics_library/src/raw_pixel/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 2b5e048..bf0fefd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,7 +4,7 @@ version = 3 [[package]] name = "able_graphics_library" -version = "0.1.1" +version = "0.1.2" dependencies = [ "versioning", ] diff --git a/libraries/able_graphics_library/Cargo.toml b/libraries/able_graphics_library/Cargo.toml index 860311b..3c9132d 100644 --- a/libraries/able_graphics_library/Cargo.toml +++ b/libraries/able_graphics_library/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "able_graphics_library" -version = "0.1.1" +version = "0.1.2" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/libraries/able_graphics_library/src/color.rs b/libraries/able_graphics_library/src/color.rs index c2ec0d6..bff17bc 100644 --- a/libraries/able_graphics_library/src/color.rs +++ b/libraries/able_graphics_library/src/color.rs @@ -1,21 +1 @@ -pub struct Color3 { - pub r: u8, - pub g: u8, - pub b: u8, -} - -impl Color3 { - /// Usage - /// The alpha value is a number between 0.0 and 1.0, which represents the transparency - /// or translucency of the other color. - pub fn blend(&self, other: &Self, alpha: f32) -> Self { - let r = (1.0 - alpha) * f32::from(self.r) + alpha * f32::from(other.r); - let g = (1.0 - alpha) * f32::from(self.g) + alpha * f32::from(other.g); - let b = (1.0 - alpha) * f32::from(self.b) + alpha * f32::from(other.b); - Self { - r: r as u8, - g: g as u8, - b: b as u8, - } - } -} +pub trait Color {} diff --git a/libraries/able_graphics_library/src/buffer.rs b/libraries/able_graphics_library/src/engine3d/buffer.rs similarity index 100% rename from libraries/able_graphics_library/src/buffer.rs rename to libraries/able_graphics_library/src/engine3d/buffer.rs diff --git a/libraries/able_graphics_library/src/engine3d/color.rs b/libraries/able_graphics_library/src/engine3d/color.rs new file mode 100644 index 0000000..c2ec0d6 --- /dev/null +++ b/libraries/able_graphics_library/src/engine3d/color.rs @@ -0,0 +1,21 @@ +pub struct Color3 { + pub r: u8, + pub g: u8, + pub b: u8, +} + +impl Color3 { + /// Usage + /// The alpha value is a number between 0.0 and 1.0, which represents the transparency + /// or translucency of the other color. + pub fn blend(&self, other: &Self, alpha: f32) -> Self { + let r = (1.0 - alpha) * f32::from(self.r) + alpha * f32::from(other.r); + let g = (1.0 - alpha) * f32::from(self.g) + alpha * f32::from(other.g); + let b = (1.0 - alpha) * f32::from(self.b) + alpha * f32::from(other.b); + Self { + r: r as u8, + g: g as u8, + b: b as u8, + } + } +} diff --git a/libraries/able_graphics_library/src/commands.rs b/libraries/able_graphics_library/src/engine3d/commands.rs similarity index 98% rename from libraries/able_graphics_library/src/commands.rs rename to libraries/able_graphics_library/src/engine3d/commands.rs index d90b466..6f5a0a3 100644 --- a/libraries/able_graphics_library/src/commands.rs +++ b/libraries/able_graphics_library/src/engine3d/commands.rs @@ -1,4 +1,4 @@ -use crate::{ +use super::{ color::Color3, framebuffer::FrameBuffer, types::{BufferID, Position2}, diff --git a/libraries/able_graphics_library/src/display.rs b/libraries/able_graphics_library/src/engine3d/display.rs similarity index 100% rename from libraries/able_graphics_library/src/display.rs rename to libraries/able_graphics_library/src/engine3d/display.rs diff --git a/libraries/able_graphics_library/src/framebuffer.rs b/libraries/able_graphics_library/src/engine3d/framebuffer.rs similarity index 98% rename from libraries/able_graphics_library/src/framebuffer.rs rename to libraries/able_graphics_library/src/engine3d/framebuffer.rs index aa3d6ed..781a2f8 100644 --- a/libraries/able_graphics_library/src/framebuffer.rs +++ b/libraries/able_graphics_library/src/engine3d/framebuffer.rs @@ -2,7 +2,7 @@ use core::ptr; use alloc::vec::Vec; -use crate::color::Color3; +use super::color::Color3; /// NOTE: Assumes the layout of RGBA pub struct FrameBuffer { pub width: u32, diff --git a/libraries/able_graphics_library/src/engine3d/mod.rs b/libraries/able_graphics_library/src/engine3d/mod.rs new file mode 100644 index 0000000..8983446 --- /dev/null +++ b/libraries/able_graphics_library/src/engine3d/mod.rs @@ -0,0 +1,7 @@ +pub mod buffer; +pub mod color; +pub mod commands; +pub mod display; +pub mod framebuffer; +pub mod types; +pub mod vertex; diff --git a/libraries/able_graphics_library/src/types.rs b/libraries/able_graphics_library/src/engine3d/types.rs similarity index 100% rename from libraries/able_graphics_library/src/types.rs rename to libraries/able_graphics_library/src/engine3d/types.rs diff --git a/libraries/able_graphics_library/src/vertex.rs b/libraries/able_graphics_library/src/engine3d/vertex.rs similarity index 95% rename from libraries/able_graphics_library/src/vertex.rs rename to libraries/able_graphics_library/src/engine3d/vertex.rs index 9148ef9..9dd7668 100644 --- a/libraries/able_graphics_library/src/vertex.rs +++ b/libraries/able_graphics_library/src/engine3d/vertex.rs @@ -1,6 +1,6 @@ use alloc::vec::Vec; -use crate::{ +use super::{ color::Color3, types::{Float2Array, Float3Array, Position3}, }; diff --git a/libraries/able_graphics_library/src/lib.rs b/libraries/able_graphics_library/src/lib.rs index 154c8f8..adb522c 100644 --- a/libraries/able_graphics_library/src/lib.rs +++ b/libraries/able_graphics_library/src/lib.rs @@ -3,16 +3,33 @@ #[macro_use] extern crate alloc; -pub mod buffer; pub mod color; -pub mod commands; -pub mod display; -pub mod framebuffer; -pub mod types; -pub mod vertex; +pub mod engine3d; +pub mod ptmode; pub const VERSION: versioning::Version = versioning::Version { major: 0, minor: 1, - patch: 1, + patch: 2, }; + +#[derive(Clone, Copy, Debug)] +pub enum GraphicsMode { + // A simple single or double buffer + RawPixels, + // The 3D engine will be the ableOS equivelent of OpenGL or Vulkan + Engine3D, + // The PTMode is a simple tile graphics mode similar to the Nintendo Entertainment System or Super Nintendo Entertainment System + // as well as providing a freeform 'Limitless' (within reason) mode + PTMode, +} + +pub struct GraphicsSettings { + mode: GraphicsMode, +} + +impl GraphicsSettings { + pub fn get_mode(&self) -> GraphicsMode { + self.mode + } +} diff --git a/libraries/able_graphics_library/src/ptmode/freeform/mod.rs b/libraries/able_graphics_library/src/ptmode/freeform/mod.rs new file mode 100644 index 0000000..3693595 --- /dev/null +++ b/libraries/able_graphics_library/src/ptmode/freeform/mod.rs @@ -0,0 +1 @@ +pub struct FreeFormColor {} diff --git a/libraries/able_graphics_library/src/ptmode/mod.rs b/libraries/able_graphics_library/src/ptmode/mod.rs new file mode 100644 index 0000000..2f20804 --- /dev/null +++ b/libraries/able_graphics_library/src/ptmode/mod.rs @@ -0,0 +1,19 @@ +pub mod freeform; +pub mod true_nes; +pub mod true_snes; + +use self::{freeform::FreeFormColor, true_nes::TrueNesColor, true_snes::TrueSnesColor}; + +pub struct NesColor(TrueNesColor); +pub struct SnesColor(TrueSnesColor); +pub struct FFColor(FreeFormColor); + +// TODO Remake sprite data enum AFTER all sprite types are made +pub enum SpriteData { + NesSprite([[NesColor; 8]; 8]), + SnesSprite([[SnesColor; 8]; 8]), + FFSprite([[FFColor; 8]; 8]), +} +pub struct Sprite { + pub sprite_data: SpriteData, +} diff --git a/libraries/able_graphics_library/src/ptmode/true_nes/mod.rs b/libraries/able_graphics_library/src/ptmode/true_nes/mod.rs new file mode 100644 index 0000000..8bc8b8d --- /dev/null +++ b/libraries/able_graphics_library/src/ptmode/true_nes/mod.rs @@ -0,0 +1,99 @@ +/// Nes colors +pub enum TrueNesColor { + Gray = 0x00, +} + +#[derive(Clone, Copy)] +pub struct Tile; +impl Tile { + pub fn blank() -> Self { + Self {} + } +} + +/// Nintendo is wrong and this is the closest approximation I will make to the scrolling logic for the NES. +#[allow(non_camel_case_types)] +#[derive(Clone, Copy)] +pub struct u9 { + pub upper_bit: bool, + pub lower_byte: u8, +} +//TODO impl a new() that takes various types +impl u9 { + pub fn new(id: u16) -> Self { + let high_byte: u8 = ((id >> 8) << 7) as u8; + let lower_byte: u8 = (id >> 8) as u8; + + let high_bit = match high_byte { + 0 => false, + _ => true, + }; + + Self { + upper_bit: high_bit, + lower_byte, + } + } +} + +pub type TileID = u9; + +/// An NES accurate tilemap. +pub type TileMap = [[TileID; 64]; 60]; + +pub struct PatternTable { + tile_data: [Tile; 256], +} +impl PatternTable { + pub fn blank() -> Self { + Self { + tile_data: [Tile; 256], + } + } +} + +pub struct BackgroundMap { + tilemap: TileMap, + // scroll_offsets: [u9; 2], +} +impl BackgroundMap { + pub fn new() -> Self { + Self { + tilemap: [[u9::new(0); 64]; 60], + } + } +} +#[derive(Clone, Copy)] +pub struct Sprite { + x: u8, + y: u8, + tile_id_a: TileID, + /// Used to make 8x16 sprites + tile_id_b: Option, +} +impl Sprite { + pub fn new() -> Self { + Self { + x: 0, + y: 0, + tile_id_a: TileID::new(0), + tile_id_b: None, + } + } +} +pub struct NesData { + sprites: [Sprite; 64], + background_map: BackgroundMap, + pattern_table_a: PatternTable, + pattern_table_b: PatternTable, +} +impl NesData { + pub fn new() -> Self { + NesData { + sprites: [Sprite::new(); 64], + background_map: BackgroundMap::new(), + pattern_table_a: PatternTable::blank(), + pattern_table_b: PatternTable::blank(), + } + } +} diff --git a/libraries/able_graphics_library/src/ptmode/true_snes/mod.rs b/libraries/able_graphics_library/src/ptmode/true_snes/mod.rs new file mode 100644 index 0000000..39537e3 --- /dev/null +++ b/libraries/able_graphics_library/src/ptmode/true_snes/mod.rs @@ -0,0 +1 @@ +pub struct TrueSnesColor {} diff --git a/libraries/able_graphics_library/src/raw_pixel/lib.rs b/libraries/able_graphics_library/src/raw_pixel/lib.rs new file mode 100644 index 0000000..0519ecb --- /dev/null +++ b/libraries/able_graphics_library/src/raw_pixel/lib.rs @@ -0,0 +1 @@ + \ No newline at end of file