mirror of
https://github.com/FranLMSP/snes.git
synced 2026-10-02 07:25:19 -04:00
Basic file loading
This commit is contained in:
@@ -6,11 +6,13 @@ edition = "2021"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
snes-core = { path = "../snes-core" }
|
||||||
winit = "0.26.1"
|
winit = "0.26.1"
|
||||||
imgui = "0.8.2"
|
imgui = "0.8.2"
|
||||||
wgpu = "0.12.0"
|
wgpu = "0.12.0"
|
||||||
imgui-wgpu = "0.19.0"
|
imgui-wgpu = "0.19.0"
|
||||||
pollster = "0.2.5"
|
pollster = "0.2.5"
|
||||||
|
rfd = "0.10.0"
|
||||||
[dependencies.imgui-winit-support]
|
[dependencies.imgui-winit-support]
|
||||||
version = "0.8.2"
|
version = "0.8.2"
|
||||||
features = ["winit-26"]
|
features = ["winit-26"]
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
extern crate imgui_winit_support;
|
extern crate imgui_winit_support;
|
||||||
|
|
||||||
|
use rfd::FileDialog;
|
||||||
use imgui::*;
|
use imgui::*;
|
||||||
use imgui_wgpu::{Renderer, RendererConfig};
|
use imgui_wgpu::{Renderer, RendererConfig};
|
||||||
use pollster::block_on;
|
use pollster::block_on;
|
||||||
@@ -13,10 +14,13 @@ use winit::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use snes_frontend::state::State;
|
use snes_frontend::state::State;
|
||||||
|
extern crate snes_core;
|
||||||
|
use snes_core::emulator::Emulator;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// Windowing state
|
// Windowing state
|
||||||
let mut state = State::new();
|
let mut state = State::new();
|
||||||
|
let mut emulator = Emulator::new();
|
||||||
|
|
||||||
|
|
||||||
// Set up window and GPU
|
// Set up window and GPU
|
||||||
@@ -203,6 +207,19 @@ fn main() {
|
|||||||
if imgui::MenuItem::new("Load ROM")
|
if imgui::MenuItem::new("Load ROM")
|
||||||
.build(&ui)
|
.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();
|
ui.separator();
|
||||||
});
|
});
|
||||||
@@ -227,18 +244,34 @@ fn main() {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Render emulator framebuffer
|
||||||
{
|
{
|
||||||
let tex = renderer.textures.get_mut(texture_id).unwrap();
|
let tex = renderer.textures.get_mut(texture_id).unwrap();
|
||||||
tex.write(&queue, &vec![0xAA; 400 * 400 * 4], 400, 400);
|
tex.write(&queue, &vec![0xAA; 400 * 400 * 4], 400, 400);
|
||||||
let game_window = imgui::Window::new("Game");
|
let game_window = imgui::Window::new("Game");
|
||||||
game_window
|
game_window
|
||||||
.size([400.0, 400.0], Condition::FirstUseEver)
|
.size([600.0, 600.0], Condition::FirstUseEver)
|
||||||
.collapsible(false)
|
.collapsible(false)
|
||||||
.build(&ui, || {
|
.build(&ui, || {
|
||||||
let game_image = imgui::Image::new(texture_id, [400.0, 400.0]);
|
let game_image = imgui::Image::new(texture_id, [400.0, 400.0]);
|
||||||
game_image.build(&ui);
|
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 =
|
let mut encoder: wgpu::CommandEncoder =
|
||||||
|
|||||||
@@ -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 struct State {
|
||||||
pub debug_options: DebugOptions,
|
pub debug_options: DebugOptions,
|
||||||
|
pub error_message: ErrorMessage,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl State {
|
impl State {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
debug_options: DebugOptions::new(),
|
debug_options: DebugOptions::new(),
|
||||||
|
error_message: ErrorMessage::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user