-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from griffi-gh/save-files
Save files
- Loading branch information
Showing
24 changed files
with
643 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use kubi_shared::data::{io_thread::IOThreadManager, open_local_save_file}; | ||
use shipyard::{AllStoragesView, UniqueView, UniqueViewMut}; | ||
use crate::config::ConfigTable; | ||
use super::{ | ||
tasks::{ChunkTask, ChunkTaskManager}, | ||
ChunkManager, | ||
}; | ||
|
||
pub fn init_save_file(storages: &AllStoragesView) -> Option<IOThreadManager> { | ||
let config = storages.borrow::<UniqueView<ConfigTable>>().unwrap(); | ||
if let Some(file_path) = &config.world.file { | ||
log::info!("Initializing save file from {:?}", file_path); | ||
let save = open_local_save_file(&file_path).unwrap(); | ||
Some(IOThreadManager::new(save)) | ||
} else { | ||
log::warn!("No save file specified, world will not be saved"); | ||
None | ||
} | ||
} | ||
|
||
pub fn save_modified( | ||
mut chunks: UniqueViewMut<ChunkManager>, | ||
ctm: UniqueView<ChunkTaskManager>, | ||
) { | ||
log::info!("Saving..."); | ||
let mut amount_saved = 0; | ||
for (position, chunk) in chunks.chunks.iter_mut() { | ||
if chunk.data_modified { | ||
let Some(data) = chunk.blocks.clone() else { | ||
continue | ||
}; | ||
ctm.run(ChunkTask::SaveChunk { | ||
position: *position, | ||
data: data, | ||
}); | ||
chunk.data_modified = false; | ||
amount_saved += 1; | ||
} | ||
} | ||
if amount_saved > 0 { | ||
log::info!("Queued {} chunks for saving", amount_saved); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.