Skip to content

Commit

Permalink
moved execution pause to App
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchUsr64 committed Nov 24, 2023
1 parent 7bb757d commit c3e86f7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
18 changes: 18 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use super::egui;

pub struct App {
pub paused: bool,
}

impl App {
pub fn new() -> Self {
Self { paused: false }
}
pub fn render_ui(&mut self, ctx: &egui::Context) {
egui::Window::new("Debug Controls").show(ctx, |ui| {
if ui.add(egui::Button::new("Pause Execution")).clicked() {
self.paused = !self.paused;
};
});
}
}
18 changes: 7 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ mod cpu;
use cpu::*;
use egui_macroquad::*;

mod app;
use app::App;
use log::{info, LevelFilter};

use simplelog::{ColorChoice, Config, TermLogger, TerminalMode};

use macroquad::prelude::{
clear_background, draw_rectangle, draw_rectangle_lines, draw_text, is_key_down, is_key_pressed,
is_mouse_button_pressed, next_frame, rand, screen_height, screen_width, Color, KeyCode,
MouseButton, BLACK, WHITE,
next_frame, rand, screen_height, screen_width, Color, KeyCode, BLACK, WHITE,
};
const SCREEN_MEMORY_START: usize = 0xfb00;
const INPUT_MEMORY_LOCATION: usize = 0xfb;
Expand Down Expand Up @@ -51,12 +52,9 @@ async fn main() {
let data = read_mem(&args.executable);
let mut mem = Memory::new(data);
let mut cpu = Cpu::new();
let mut paused = args.start_debug;
let mut app = App::new();
loop {
if is_mouse_button_pressed(MouseButton::Left) {
paused = !paused;
}
if !paused || is_key_pressed(KeyCode::Space) {
if !app.paused || is_key_pressed(KeyCode::Space) {
(0..args.executions_per_frame).for_each(|_| {
info!("{cpu:?}");
cpu.execute(&mut mem);
Expand Down Expand Up @@ -115,7 +113,7 @@ async fn main() {
min_screen_dimension * 0.1,
WHITE,
);
if paused {
if app.paused {
draw_text(
format!("PAUSED",).as_str(),
0.,
Expand All @@ -126,9 +124,7 @@ async fn main() {
}

egui_macroquad::ui(|egui_ctx| {
egui::Window::new("egui ❤ macroquad").show(egui_ctx, |ui| {
ui.label("Test");
});
app.render_ui(egui_ctx);
});

// Draw things before egui
Expand Down

0 comments on commit c3e86f7

Please sign in to comment.