mirror of
https://github.com/zyllian/classics.git
synced 2025-01-17 19:22:37 -08:00
save level on stop (loading soon)
This commit is contained in:
parent
d5530a1449
commit
fae40178af
5 changed files with 40 additions and 3 deletions
26
Cargo.lock
generated
26
Cargo.lock
generated
|
@ -56,6 +56,25 @@ dependencies = [
|
|||
"rustc-demangle",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bincode"
|
||||
version = "2.0.0-rc.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f11ea1a0346b94ef188834a65c068a03aec181c94896d481d7a0a40d85b0ce95"
|
||||
dependencies = [
|
||||
"bincode_derive",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bincode_derive"
|
||||
version = "2.0.0-rc.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7e30759b3b99a1b802a7a3aa21c85c3ded5c28e1c83170d82d70f08bbf7f3e4c"
|
||||
dependencies = [
|
||||
"virtue",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "1.3.2"
|
||||
|
@ -84,6 +103,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
|||
name = "classics"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bincode",
|
||||
"bytes",
|
||||
"flate2",
|
||||
"half",
|
||||
|
@ -535,6 +555,12 @@ version = "0.9.4"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
|
||||
|
||||
[[package]]
|
||||
name = "virtue"
|
||||
version = "0.0.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9dcc60c0624df774c82a0ef104151231d37da4962957d691c011c852b2473314"
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.11.0+wasi-snapshot-preview1"
|
||||
|
|
|
@ -4,6 +4,7 @@ name = "classics"
|
|||
version = "0.1.0"
|
||||
|
||||
[dependencies]
|
||||
bincode = "2.0.0-rc.3"
|
||||
bytes = "1"
|
||||
flate2 = "1"
|
||||
half = "2"
|
||||
|
|
BIN
level.clw
Normal file
BIN
level.clw
Normal file
Binary file not shown.
|
@ -1,5 +1,7 @@
|
|||
use std::collections::BTreeSet;
|
||||
|
||||
use bincode::{Decode, Encode};
|
||||
|
||||
use crate::{packet::server::ServerPacket, util::neighbors};
|
||||
|
||||
use self::block::BLOCK_INFO;
|
||||
|
@ -8,7 +10,7 @@ pub mod block;
|
|||
pub mod generation;
|
||||
|
||||
/// a classic level
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, Encode, Decode)]
|
||||
pub struct Level {
|
||||
/// the size of the level in the X direction
|
||||
pub x_size: usize,
|
||||
|
@ -91,7 +93,7 @@ impl Level {
|
|||
}
|
||||
|
||||
/// struct describing a block update for the level to handle
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, Encode, Decode)]
|
||||
pub struct BlockUpdate {
|
||||
/// the index of the block to be updated
|
||||
pub index: usize,
|
||||
|
|
|
@ -94,12 +94,20 @@ impl Server {
|
|||
});
|
||||
}
|
||||
});
|
||||
handle_ticks(self.data).await;
|
||||
handle_ticks(self.data.clone()).await;
|
||||
tokio::time::sleep(std::time::Duration::from_millis(1)).await;
|
||||
|
||||
// TODO: cancel pending tasks/send out "Server is stopping" messages *here* instead of elsewhere
|
||||
// rn the message isn't guaranteed to actually go out........
|
||||
|
||||
let data = self.data.read().await;
|
||||
let mut encoder = flate2::write::GzEncoder::new(Vec::new(), flate2::Compression::best());
|
||||
bincode::encode_into_std_write(&data.level, &mut encoder, bincode::config::standard())
|
||||
.unwrap();
|
||||
tokio::fs::write("level.clw", encoder.finish().unwrap())
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue