Skip to content
This repository was archived by the owner on Jun 4, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions client/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,9 @@ impl Client {
}
PluginData::Download(data) => {
log::info!("Downloaded {}, saving...", name);
plugin_cache.add_file(&name, &data)?;
bytecode = data;
let decompressed = cimvr_engine::decompress(&data).context("Decompressing wasm")?;
plugin_cache.add_file(&name, &decompressed)?;
bytecode = decompressed;
}
}

Expand Down Expand Up @@ -188,6 +189,7 @@ impl Client {
// Load hotloaded plugins
for (name, bytecode) in recv.hotload {
log::info!("Reloading {}", name);
let bytecode = cimvr_engine::decompress(&bytecode).context("Decompressing wasm")?;
self.engine.reload(name, &bytecode)?;
}

Expand Down
1 change: 1 addition & 0 deletions engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ ahash = "0.8.2"
log = "0.4.17"
notify = "5.0.0"
xxhash-rust = { version = "0.8.5", features = ["xxh3"] }
miniz_oxide = "0.7.1"
10 changes: 10 additions & 0 deletions engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,3 +358,13 @@ impl Engine {
pub fn calculate_digest(data: &[u8]) -> Digest {
Digest(xxhash_rust::xxh3::xxh3_128(data))
}

/// Compress some data
pub fn compress(data: &[u8]) -> Vec<u8> {
miniz_oxide::deflate::compress_to_vec(data, 6)
}

/// Decompress some data
pub fn decompress(data: &[u8]) -> Result<Vec<u8>> {
miniz_oxide::inflate::decompress_to_vec(data).map_err(|e| format_err!("{:#}", e))
}
5 changes: 4 additions & 1 deletion server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ impl Server {

// Remember which plugins were hotloaded, so that we can send code to
// the clients!
let bytecode = cimvr_engine::compress(&bytecode);
hotloaded.push((name, bytecode));
}

Expand All @@ -190,7 +191,9 @@ impl Server {
if req.plugin_manifest.contains(&digest) {
response_plugins.push((name.clone(), PluginData::Cached(*digest)));
} else {
response_plugins.push((name.clone(), PluginData::Download(code.clone())));
// TODO: Do this only once!
let bytecode = cimvr_engine::compress(&code);
response_plugins.push((name.clone(), PluginData::Download(bytecode)));
}
}

Expand Down