diff --git a/examples/hyperspace-roll/Cargo.toml b/examples/hyperspace-roll/Cargo.toml index d84b04d0..7ed75561 100644 --- a/examples/hyperspace-roll/Cargo.toml +++ b/examples/hyperspace-roll/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" [dependencies] agb = { version = "0.19.1", path = "../../agb" } +portable-atomic = { version = "1.6.0", default-features = false } [profile.dev] opt-level = 3 diff --git a/examples/hyperspace-roll/src/save.rs b/examples/hyperspace-roll/src/save.rs index e2154a87..1554e195 100644 --- a/examples/hyperspace-roll/src/save.rs +++ b/examples/hyperspace-roll/src/save.rs @@ -1,8 +1,8 @@ use agb::save::{Error, SaveManager}; -use agb::sync::Static; use agb::Gba; +use portable_atomic::{AtomicU32, Ordering}; -static HIGH_SCORE: Static = Static::new(0); +static HIGH_SCORE: AtomicU32 = AtomicU32::new(0); pub fn init_save(gba: &mut Gba) -> Result<(), Error> { gba.save.init_sram(); @@ -21,24 +21,22 @@ pub fn init_save(gba: &mut Gba) -> Result<(), Error> { access.read(1, &mut buffer)?; let high_score = u32::from_le_bytes(buffer); - if high_score > 100 { - HIGH_SCORE.write(0) - } else { - HIGH_SCORE.write(high_score) - } + let score = if high_score > 100 { 0 } else { high_score }; + + HIGH_SCORE.store(score, Ordering::SeqCst); } Ok(()) } pub fn load_high_score() -> u32 { - HIGH_SCORE.read() + HIGH_SCORE.load(Ordering::SeqCst) } pub fn save_high_score(save: &mut SaveManager, score: u32) -> Result<(), Error> { save.access()? .prepare_write(1..5)? .write(1, &score.to_le_bytes())?; - HIGH_SCORE.write(score); + HIGH_SCORE.store(score, Ordering::SeqCst); Ok(()) } diff --git a/examples/the-dungeon-puzzlers-lament/Cargo.toml b/examples/the-dungeon-puzzlers-lament/Cargo.toml index 90644ac3..9865ba2a 100644 --- a/examples/the-dungeon-puzzlers-lament/Cargo.toml +++ b/examples/the-dungeon-puzzlers-lament/Cargo.toml @@ -10,6 +10,7 @@ edition = "2021" agb = { version = "0.19.1", path = "../../agb" } agb_tracker = { version = "0.19.1", path = "../../tracker/agb-tracker", default-features = false, features = ["xm"] } slotmap = { version = "1", default-features = false } +portable-atomic = { version = "1.6.0", default-features = false } [profile.dev] opt-level = 3 diff --git a/examples/the-dungeon-puzzlers-lament/src/save.rs b/examples/the-dungeon-puzzlers-lament/src/save.rs index a47a510d..d6830b9d 100644 --- a/examples/the-dungeon-puzzlers-lament/src/save.rs +++ b/examples/the-dungeon-puzzlers-lament/src/save.rs @@ -1,10 +1,10 @@ use agb::{ save::{Error, SaveManager}, - sync::Static, Gba, }; +use portable_atomic::{AtomicU32, Ordering}; -static MAXIMUM_LEVEL: Static = Static::new(0); +static MAXIMUM_LEVEL: AtomicU32 = AtomicU32::new(0); pub fn init_save(gba: &mut Gba) -> Result<(), Error> { gba.save.init_sram(); @@ -24,9 +24,9 @@ pub fn init_save(gba: &mut Gba) -> Result<(), Error> { let max_level = u32::from_le_bytes(buffer); if max_level > 100 { - MAXIMUM_LEVEL.write(0) + MAXIMUM_LEVEL.store(0, Ordering::SeqCst) } else { - MAXIMUM_LEVEL.write(max_level) + MAXIMUM_LEVEL.store(max_level, Ordering::SeqCst) } } @@ -34,13 +34,13 @@ pub fn init_save(gba: &mut Gba) -> Result<(), Error> { } pub fn load_max_level() -> u32 { - MAXIMUM_LEVEL.read() + MAXIMUM_LEVEL.load(Ordering::SeqCst) } pub fn save_max_level(save: &mut SaveManager, level: u32) -> Result<(), Error> { save.access()? .prepare_write(1..5)? .write(1, &level.to_le_bytes())?; - MAXIMUM_LEVEL.write(level); + MAXIMUM_LEVEL.store(level, Ordering::SeqCst); Ok(()) }