use binary format for rom saves (#183)
* use binary format for rom saves * more
This commit is contained in:
parent
9e88343c6b
commit
b1bb96c7d2
@ -25,6 +25,7 @@ mimalloc = "0.1"
|
||||
regex = "1.11"
|
||||
tungstenite = "0.26"
|
||||
socket2 = "0.5"
|
||||
postcard = { version = "1.1", features = ["use-std"] }
|
||||
clap = { version = "4.4", features = ["derive"] }
|
||||
|
||||
[dependencies.reqwest]
|
||||
|
||||
@ -85,9 +85,8 @@ pub fn dma_read(
|
||||
device.rdram.mem[(dram_addr + i) as usize ^ device.byte_swap];
|
||||
|
||||
device.ui.saves.romsave.0.insert(
|
||||
(cart_addr + i).to_string(),
|
||||
serde_json::to_value(device.rdram.mem[(dram_addr + i) as usize ^ device.byte_swap])
|
||||
.unwrap(),
|
||||
cart_addr + i,
|
||||
device.rdram.mem[(dram_addr + i) as usize ^ device.byte_swap],
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -139,8 +138,7 @@ pub fn load_rom_save(device: &mut device::Device) {
|
||||
return;
|
||||
}
|
||||
for (key, value) in device.ui.saves.romsave.0.iter() {
|
||||
device.cart.rom[key.parse::<usize>().unwrap()] =
|
||||
serde_json::from_value(value.clone()).unwrap()
|
||||
device.cart.rom[*key as usize] = *value
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -142,7 +142,7 @@ impl Ui {
|
||||
sram: (Vec::new(), false),
|
||||
flash: (Vec::new(), false),
|
||||
mempak: (Vec::new(), false),
|
||||
romsave: (serde_json::Map::new(), false),
|
||||
romsave: (std::collections::HashMap::new(), false),
|
||||
},
|
||||
pak_audio: audio::PakAudio {
|
||||
mempak: include_bytes!("../data/mempak.wav").to_vec(),
|
||||
|
||||
@ -27,7 +27,7 @@ pub struct Saves {
|
||||
pub sram: (Vec<u8>, bool),
|
||||
pub flash: (Vec<u8>, bool),
|
||||
pub mempak: (Vec<u8>, bool),
|
||||
pub romsave: (serde_json::Map<String, serde_json::Value>, bool),
|
||||
pub romsave: (std::collections::HashMap<u32, u8>, bool),
|
||||
}
|
||||
|
||||
fn get_save_type(game_id: &str) -> Vec<SaveTypes> {
|
||||
@ -142,7 +142,7 @@ pub fn load_saves(ui: &mut ui::Ui, netplay: &mut Option<netplay::Netplay>) {
|
||||
// can't do romsaves with the current netplay implementation
|
||||
let romsave = std::fs::read(&mut ui.paths.romsave_file_path);
|
||||
if romsave.is_ok() {
|
||||
ui.saves.romsave.0 = serde_json::from_slice(romsave.unwrap().as_ref()).unwrap();
|
||||
ui.saves.romsave.0 = postcard::from_bytes(romsave.unwrap().as_ref()).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -203,8 +203,8 @@ pub fn load_saves(ui: &mut ui::Ui, netplay: &mut Option<netplay::Netplay>) {
|
||||
}
|
||||
|
||||
fn write_rom_save(ui: &ui::Ui) {
|
||||
let f = std::fs::File::create(ui.paths.romsave_file_path.clone()).unwrap();
|
||||
serde_json::to_writer(f, &ui.saves.romsave.0).unwrap();
|
||||
let data = postcard::to_stdvec(&ui.saves.romsave.0).unwrap();
|
||||
std::fs::write(ui.paths.romsave_file_path.clone(), data).unwrap();
|
||||
}
|
||||
|
||||
pub fn write_saves(ui: &ui::Ui, netplay: &Option<netplay::Netplay>) {
|
||||
|
||||
Reference in New Issue
Block a user