update other projects

This commit is contained in:
Corwin 2024-02-17 20:04:03 +00:00
parent fb247aa8f2
commit 7ade79e132
No known key found for this signature in database
4 changed files with 15 additions and 15 deletions

View file

@ -6,6 +6,7 @@ edition = "2021"
[dependencies] [dependencies]
agb = { version = "0.19.1", path = "../../agb" } agb = { version = "0.19.1", path = "../../agb" }
portable-atomic = { version = "1.6.0", default-features = false }
[profile.dev] [profile.dev]
opt-level = 3 opt-level = 3

View file

@ -1,8 +1,8 @@
use agb::save::{Error, SaveManager}; use agb::save::{Error, SaveManager};
use agb::sync::Static;
use agb::Gba; use agb::Gba;
use portable_atomic::{AtomicU32, Ordering};
static HIGH_SCORE: Static<u32> = Static::new(0); static HIGH_SCORE: AtomicU32 = AtomicU32::new(0);
pub fn init_save(gba: &mut Gba) -> Result<(), Error> { pub fn init_save(gba: &mut Gba) -> Result<(), Error> {
gba.save.init_sram(); gba.save.init_sram();
@ -21,24 +21,22 @@ pub fn init_save(gba: &mut Gba) -> Result<(), Error> {
access.read(1, &mut buffer)?; access.read(1, &mut buffer)?;
let high_score = u32::from_le_bytes(buffer); let high_score = u32::from_le_bytes(buffer);
if high_score > 100 { let score = if high_score > 100 { 0 } else { high_score };
HIGH_SCORE.write(0)
} else { HIGH_SCORE.store(score, Ordering::SeqCst);
HIGH_SCORE.write(high_score)
}
} }
Ok(()) Ok(())
} }
pub fn load_high_score() -> u32 { 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> { pub fn save_high_score(save: &mut SaveManager, score: u32) -> Result<(), Error> {
save.access()? save.access()?
.prepare_write(1..5)? .prepare_write(1..5)?
.write(1, &score.to_le_bytes())?; .write(1, &score.to_le_bytes())?;
HIGH_SCORE.write(score); HIGH_SCORE.store(score, Ordering::SeqCst);
Ok(()) Ok(())
} }

View file

@ -10,6 +10,7 @@ edition = "2021"
agb = { version = "0.19.1", path = "../../agb" } agb = { version = "0.19.1", path = "../../agb" }
agb_tracker = { version = "0.19.1", path = "../../tracker/agb-tracker", default-features = false, features = ["xm"] } agb_tracker = { version = "0.19.1", path = "../../tracker/agb-tracker", default-features = false, features = ["xm"] }
slotmap = { version = "1", default-features = false } slotmap = { version = "1", default-features = false }
portable-atomic = { version = "1.6.0", default-features = false }
[profile.dev] [profile.dev]
opt-level = 3 opt-level = 3

View file

@ -1,10 +1,10 @@
use agb::{ use agb::{
save::{Error, SaveManager}, save::{Error, SaveManager},
sync::Static,
Gba, Gba,
}; };
use portable_atomic::{AtomicU32, Ordering};
static MAXIMUM_LEVEL: Static<u32> = Static::new(0); static MAXIMUM_LEVEL: AtomicU32 = AtomicU32::new(0);
pub fn init_save(gba: &mut Gba) -> Result<(), Error> { pub fn init_save(gba: &mut Gba) -> Result<(), Error> {
gba.save.init_sram(); 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); let max_level = u32::from_le_bytes(buffer);
if max_level > 100 { if max_level > 100 {
MAXIMUM_LEVEL.write(0) MAXIMUM_LEVEL.store(0, Ordering::SeqCst)
} else { } 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 { 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> { pub fn save_max_level(save: &mut SaveManager, level: u32) -> Result<(), Error> {
save.access()? save.access()?
.prepare_write(1..5)? .prepare_write(1..5)?
.write(1, &level.to_le_bytes())?; .write(1, &level.to_le_bytes())?;
MAXIMUM_LEVEL.write(level); MAXIMUM_LEVEL.store(level, Ordering::SeqCst);
Ok(()) Ok(())
} }