Skip to content

Commit

Permalink
make viewer fields private and use getters
Browse files Browse the repository at this point in the history
  • Loading branch information
Miwgt committed Jul 13, 2024
1 parent 74320a7 commit 85b6cce
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 45 deletions.
39 changes: 9 additions & 30 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use macroquad::{prelude::*, ui::root_ui};
use mmu::MemoryOperations;
use rendering::{
line_rendering::{self},
tiles::*,
tiles::{self, *},
views::*,
};
use rfd::FileDialog;
Expand Down Expand Up @@ -49,34 +49,13 @@ async fn main() {
];
const SCALING: f32 = 4.0;

let mut gb_display = GbDisplay {
offset_x: 5.0,
offset_y: 5.0,
scaling: SCALING,
gb_image: Image::gen_image_color(160, 144, GREEN)
};
let gb_display_size = gb_display.size();

let mut background_viewer = BackgroundViewer {
offset_x: gb_display_size.x + 10.0,
offset_y: 5.0,
scaling: SCALING / 2.0,
image: Image::gen_image_color(32 * 8, 32 * 8, PINK)
};

let background_viewer_size = background_viewer.size();

let mut tile_viewer = TileViewer {
offset_x: gb_display_size.x + background_viewer_size.x + 15.0,
offset_y: 5.0,
scaling: SCALING,
atlas: Image::gen_image_color(8 * 16, 8 * 24, WHITE)
};
let tile_viewer_size = tile_viewer.size();
let mut gb_display = GbDisplay::new(5.0, 5.0, SCALING);
let mut background_viewer = BackgroundViewer::new(gb_display.size().x + 10.0, 5.0, SCALING / 2.0);
let mut tile_viewer = TileViewer::new(gb_display.size().x + background_viewer.size().x + 15.0, 5.0, SCALING);

request_new_screen_size(
background_viewer_size.x + tile_viewer_size.x + gb_display_size.x + 20.0,
tile_viewer_size.y + 10.0,
background_viewer.size().x + tile_viewer.size().x + gb_display.size().x + 20.0,
tile_viewer.size().y + 10.0,
);

let filedialog = FileDialog::new()
Expand Down Expand Up @@ -141,7 +120,7 @@ async fn main() {
log::debug!("🔢 Following Word (PC): {:#06X}", pc_following_word);

for _ in 0..=cpu_cycles_taken {
ppu.step(&mut cpu, &mut gb_display.gb_image, &PALETTE);
ppu.step(&mut cpu, &mut gb_display.get_gb_image(), &PALETTE);


// Alternatively Redraw UI at 30 frames per second: (ppu_time.elapsed().as_millis() as f32) >= TIME_PER_FRAME
Expand All @@ -168,8 +147,8 @@ async fn main() {
last_frame_time = time::Instant::now();

// Update Debugging Views
update_atlas_from_memory(&cpu, 16 * 24, &mut tile_viewer.atlas, &PALETTE);
update_background_from_memory(&cpu, &mut background_viewer.image, &PALETTE, false, true);
update_atlas_from_memory(&cpu, 16 * 24, &mut tile_viewer.get_atlas(), &PALETTE);
update_background_from_memory(&cpu, &mut background_viewer.get_image(), &PALETTE, false, true);
background_viewer.draw();
tile_viewer.draw();

Expand Down
76 changes: 61 additions & 15 deletions src/rendering/views.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,25 @@ pub trait Draw {
}

pub struct GbDisplay {
pub offset_x: f32,
pub offset_y: f32,
pub scaling: f32,
pub gb_image: Image
offset_x: f32,
offset_y: f32,
scaling: f32,
gb_image: Image
}

impl GbDisplay {
pub fn new(offset_x: f32, offset_y: f32, scaling: f32) -> GbDisplay {
GbDisplay {
offset_x,
offset_y,
scaling,
gb_image: Image::gen_image_color(160, 144, GREEN)
}
}

pub fn get_gb_image(&mut self) -> &mut Image {
&mut self.gb_image
}
}

impl Draw for GbDisplay {
Expand Down Expand Up @@ -40,10 +55,26 @@ impl Draw for GbDisplay {
}

pub struct TileViewer {
pub offset_x: f32,
pub offset_y: f32,
pub scaling: f32,
pub atlas: Image
offset_x: f32,
offset_y: f32,
scaling: f32,
atlas: Image
}

impl TileViewer {
pub fn new(offset_x: f32, offset_y: f32, scaling: f32) -> TileViewer {
TileViewer {
offset_x,
offset_y,
scaling,
atlas: Image::gen_image_color(8 * 16, 8 * 24, WHITE)
}
}

pub fn get_atlas(&mut self) -> &mut Image {
&mut self.atlas
}

}

impl Draw for TileViewer {
Expand Down Expand Up @@ -100,10 +131,25 @@ impl Draw for TileViewer {
}

pub struct BackgroundViewer {
pub offset_x: f32,
pub offset_y: f32,
pub scaling: f32,
pub image: Image
offset_x: f32,
offset_y: f32,
scaling: f32,
image: Image
}

impl BackgroundViewer {
pub fn new(offset_x: f32, offset_y: f32, scaling: f32) -> BackgroundViewer {
BackgroundViewer {
offset_x,
offset_y,
scaling,
image: Image::gen_image_color(32 * 8, 32 * 8, WHITE)
}
}

pub fn get_image(&mut self) -> &mut Image {
&mut self.image
}
}

impl Draw for BackgroundViewer {
Expand Down Expand Up @@ -134,9 +180,9 @@ impl Draw for BackgroundViewer {
}

pub struct EmulationControls {
pub offset_x: f32,
pub offset_y: f32,
pub scaling: f32,
offset_x: f32,
offset_y: f32,
scaling: f32,

play_active: Texture2D,
play_inactive: Texture2D,
Expand Down

0 comments on commit 85b6cce

Please sign in to comment.