Basic file loading

This commit is contained in:
2022-12-10 19:06:26 -05:00
parent f19b9bdfeb
commit c2c4cab19e
3 changed files with 52 additions and 1 deletions
+2
View File
@@ -6,11 +6,13 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
snes-core = { path = "../snes-core" }
winit = "0.26.1"
imgui = "0.8.2"
wgpu = "0.12.0"
imgui-wgpu = "0.19.0"
pollster = "0.2.5"
rfd = "0.10.0"
[dependencies.imgui-winit-support]
version = "0.8.2"
features = ["winit-26"]
+34 -1
View File
@@ -1,5 +1,6 @@
extern crate imgui_winit_support;
use rfd::FileDialog;
use imgui::*;
use imgui_wgpu::{Renderer, RendererConfig};
use pollster::block_on;
@@ -13,10 +14,13 @@ use winit::{
};
use snes_frontend::state::State;
extern crate snes_core;
use snes_core::emulator::Emulator;
fn main() {
// Windowing state
let mut state = State::new();
let mut emulator = Emulator::new();
// Set up window and GPU
@@ -203,6 +207,19 @@ fn main() {
if imgui::MenuItem::new("Load ROM")
.build(&ui)
{
if let Some(path) = FileDialog::new()
.pick_file()
{
match emulator.rom.load(&String::from(path.to_str().unwrap())) {
Ok(_) => {},
Err(err) => {
state.error_message.show = true;
state.error_message.message = format!(
"Could not load rom: {}", err,
);
}
}
}
}
ui.separator();
});
@@ -227,18 +244,34 @@ fn main() {
);
});
}
// Render emulator framebuffer
{
let tex = renderer.textures.get_mut(texture_id).unwrap();
tex.write(&queue, &vec![0xAA; 400 * 400 * 4], 400, 400);
let game_window = imgui::Window::new("Game");
game_window
.size([400.0, 400.0], Condition::FirstUseEver)
.size([600.0, 600.0], Condition::FirstUseEver)
.collapsible(false)
.build(&ui, || {
let game_image = imgui::Image::new(texture_id, [400.0, 400.0]);
game_image.build(&ui);
});
}
if state.error_message.show {
let window = imgui::Window::new("Error");
window
.size([300.0, 100.0], Condition::Always)
.collapsible(false)
.build(&ui, || {
ui.text(&state.error_message.message);
if ui.button("Ok") {
state.error_message.show = false
}
});
}
}
let mut encoder: wgpu::CommandEncoder =
+16
View File
@@ -16,14 +16,30 @@ impl DebugOptions {
}
}
pub struct ErrorMessage {
pub show: bool,
pub message: String,
}
impl ErrorMessage {
pub fn new() -> Self {
Self {
show: false,
message: String::from(""),
}
}
}
pub struct State {
pub debug_options: DebugOptions,
pub error_message: ErrorMessage,
}
impl State {
pub fn new() -> Self {
Self {
debug_options: DebugOptions::new(),
error_message: ErrorMessage::new(),
}
}
}