Skip to content

Commit

Permalink
More accurate patch time statistic
Browse files Browse the repository at this point in the history
  • Loading branch information
toasterparty committed Mar 5, 2024
1 parent 78f1221 commit 9b092bf
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
4 changes: 2 additions & 2 deletions generated/json_data/qol.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -3848,7 +3848,7 @@
},
{
"senderId": 600482, // [Relay] Relay
"targetId": 77591, // [SpecialFunction] [DEC] Ruins Entrance
"targetId": 77591, // [SpecialFunction] [DEC] Ruins Entrance
"state": "ZERO",
"message": "DECREMENT"
},
Expand Down Expand Up @@ -3997,7 +3997,7 @@
"type": "PlayerInAreaRelay"
},
{
"id": 77591, // [SpecialFunction] [DEC] Ruins Entrance
"id": 77591, // [SpecialFunction] [DEC] Ruins Entrance
"type": "ScriptLayerController",
"layerChangeRoomId": 944775450,
"layerChangeLayerId": 3
Expand Down
4 changes: 3 additions & 1 deletion src/bin/randomprime_patcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use clap::Format;
use std::{
panic,
process::Command,
time::Instant,
};

struct ProgressNotifier
Expand Down Expand Up @@ -101,9 +102,10 @@ fn maybe_pause_at_exit()

fn main_inner() -> Result<(), String>
{
let start_time = Instant::now();
let patch_config = PatchConfig::from_cli_options()?;
let pn = ProgressNotifier::new(patch_config.quiet);
patches::patch_iso(patch_config, pn)?;
patches::patch_iso(patch_config, pn, start_time)?;
println!("Done");
Ok(())
}
Expand Down
6 changes: 5 additions & 1 deletion src/c_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use std::{
panic,
path::Path,
os::raw::c_char,
time::Instant,
};

use serde::{Serialize};
Expand Down Expand Up @@ -119,13 +120,16 @@ impl structs::ProgressNotifier for ProgressNotifier
fn inner(config_json: *const c_char, cb_data: *const (), cb: extern fn(*const (), *const c_char))
-> Result<(), String>
{
let start_time = Instant::now();

let config_json = unsafe { CStr::from_ptr(config_json) }.to_str()
.map_err(|e| format!("JSON parse failed: {}", e))?;

let patch_config = PatchConfig::from_json(config_json)?;

let pn = ProgressNotifier::new(cb_data, cb);
patches::patch_iso(patch_config, pn)?;
patches::patch_iso(patch_config, pn, start_time)?;

Ok(())
}

Expand Down
8 changes: 4 additions & 4 deletions src/patches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14421,7 +14421,7 @@ fn patch_arboretum_sandstone<'a>(patcher: &mut PrimePatcher<'_, 'a>)
});
}

pub fn patch_iso<T>(config: PatchConfig, mut pn: T) -> Result<(), String>
pub fn patch_iso<T>(config: PatchConfig, mut pn: T, start_time: Instant) -> Result<(), String>
where T: structs::ProgressNotifier
{
let mut audio_override_patches: Vec<AudioOverridePatch> = Vec::new();
Expand Down Expand Up @@ -14473,7 +14473,7 @@ pub fn patch_iso<T>(config: PatchConfig, mut pn: T) -> Result<(), String>
let mut reader = Reader::new(&config.input_iso[..]);
let mut gc_disc: structs::GcDisc = reader.read(());

if gc_disc.find_file("randomprime.txt").is_some() {
if gc_disc.find_file("randomprime.json").is_some() {
Err(concat!("The input ISO has already been randomized once before. ",
"You must start from an unmodified ISO every time."
))?
Expand All @@ -14489,6 +14489,8 @@ pub fn patch_iso<T>(config: PatchConfig, mut pn: T) -> Result<(), String>

build_and_run_patches(&mut gc_disc, &config, audio_override_patches)?;

println!("Created patches in {:?}", start_time.elapsed());

{
let json_string = serde_json::to_string(&config)
.map_err(|e| format!("Failed to serialize patch config: {}", e))?;
Expand Down Expand Up @@ -17572,9 +17574,7 @@ fn build_and_run_patches<'r>(gc_disc: &mut structs::GcDisc<'r>, config: &PatchCo
);
}

let time = Instant::now();
patcher.run(gc_disc)?;
println!("Created patches in {:?}", time.elapsed());

Ok(())
}
Expand Down

0 comments on commit 9b092bf

Please sign in to comment.