mirror of
https://github.com/doukutsu-rs/doukutsu-rs
synced 2024-11-28 16:22:54 +00:00
Hopefully this will improve I/O perf on Horizon
This commit is contained in:
parent
87da45192d
commit
4ee73a8793
|
@ -1,3 +1,5 @@
|
||||||
|
use std::io::{Read, Write};
|
||||||
|
|
||||||
use crate::framework::context::Context;
|
use crate::framework::context::Context;
|
||||||
use crate::framework::error::GameResult;
|
use crate::framework::error::GameResult;
|
||||||
use crate::framework::filesystem::{user_create, user_open};
|
use crate::framework::filesystem::{user_create, user_open};
|
||||||
|
@ -173,8 +175,13 @@ fn default_cutscene_skip_mode() -> CutsceneSkipMode {
|
||||||
|
|
||||||
impl Settings {
|
impl Settings {
|
||||||
pub fn load(ctx: &Context) -> GameResult<Settings> {
|
pub fn load(ctx: &Context) -> GameResult<Settings> {
|
||||||
if let Ok(file) = user_open(ctx, "/settings.json") {
|
if let Ok(mut file) = user_open(ctx, "/settings.json") {
|
||||||
match serde_json::from_reader::<_, Settings>(file) {
|
// we use a buffer to avoid hammering the OS with small reads/writes
|
||||||
|
// I/O on settings was particularly VERY SLOW on Horizon (well it's based on microkernel, so IPC overhead...)
|
||||||
|
let mut buf = Vec::new();
|
||||||
|
file.read_to_end(&mut buf)?;
|
||||||
|
|
||||||
|
match serde_json::from_slice::<Settings>(&buf) {
|
||||||
Ok(settings) => return Ok(settings.upgrade()),
|
Ok(settings) => return Ok(settings.upgrade()),
|
||||||
Err(err) => log::warn!("Failed to deserialize settings: {}", err),
|
Err(err) => log::warn!("Failed to deserialize settings: {}", err),
|
||||||
}
|
}
|
||||||
|
@ -183,6 +190,14 @@ impl Settings {
|
||||||
Ok(Settings::default())
|
Ok(Settings::default())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn save(&self, ctx: &Context) -> GameResult {
|
||||||
|
// see why in load()
|
||||||
|
let buffer = serde_json::to_vec_pretty(self)?;
|
||||||
|
user_create(ctx, "/settings.json")?.write_all(&buffer)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn upgrade(mut self) -> Self {
|
fn upgrade(mut self) -> Self {
|
||||||
let initial_version = self.version;
|
let initial_version = self.version;
|
||||||
|
|
||||||
|
@ -362,13 +377,6 @@ impl Settings {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn save(&self, ctx: &Context) -> GameResult {
|
|
||||||
let file = user_create(ctx, "/settings.json")?;
|
|
||||||
serde_json::to_writer_pretty(file, self)?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn create_player1_controller(&self) -> Box<dyn PlayerController> {
|
pub fn create_player1_controller(&self) -> Box<dyn PlayerController> {
|
||||||
if self.touch_controls {
|
if self.touch_controls {
|
||||||
return Box::new(TouchPlayerController::new());
|
return Box::new(TouchPlayerController::new());
|
||||||
|
|
Loading…
Reference in a new issue