Skip to content
Closed
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
6 changes: 6 additions & 0 deletions Cargo.lock

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

32 changes: 31 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"
rust-version = "1.83.0"

[dependencies]
bevy = "0.15.1"
bevy = { version = "0.15.1", features = ["wayland"] }
bevy_fps_controller = "0.15.0"
bevy_mod_raycast = { git = "https://github.com/CuddlyBunion341/bevy_mod_raycast.git", branch = "main" }
bevy_rapier3d = "0.28.0"
Expand All @@ -26,13 +26,34 @@ renet_visualizer = { git = "https://github.com/CuddlyBunion341/renet.git", featu
"bevy",
] }
egui_plot = "0.30.0"
getrandom = { version = "0.2", features = ["js"] }

# WASM specific dependencies
[target.'cfg(target_arch = "wasm32")'.dependencies]
console_error_panic_hook = "0.1.7"
wasm-bindgen = "0.2.92"
wasm-bindgen-futures = "0.4.42"
web-sys = { version = "0.3.69", features = [
"Document",
"Window",
"Element",
"Location",
]}
js-sys = "0.3.69"

[profile.dev.package."*"]
opt-level = 3

[profile.release]
opt-level = 3

# WASM optimizations
[profile.wasm-release]
inherits = "release"
opt-level = "z" # Optimize for size
lto = true # Link Time Optimization
codegen-units = 1 # More effective optimizations

[[bin]]
name = "client"
path = "src/client/main.rs"
Expand All @@ -41,6 +62,12 @@ path = "src/client/main.rs"
name = "server"
path = "src/server/main.rs"

# For WASM builds
[lib]
name = "rsmc_wasm"
crate-type = ["cdylib", "rlib"]
path = "src/wasm/lib.rs"

[features]
default = ["chat"]
dynamic_linking = ["bevy/dynamic_linking"]
Expand All @@ -63,3 +90,6 @@ physics_debug = []
raycast_debug = []
skip_terrain = []
visual_debug = ["wireframe", "physics_debug", "raycast_debug"]

# wasm
wasm = ["bevy/webgl2"]
72 changes: 72 additions & 0 deletions build/wasm/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>RSMC Web</title>
<style>
body {
margin: 0;
padding: 0;
width: 100%;
height: 100vh;
background-color: #2b2b2b;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
color: white;
font-family: Arial, sans-serif;
}

canvas {
background-color: #000;
width: 800px;
height: 600px;
max-width: 100%;
max-height: 100vh;
display: block;
}

#loading {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 24px;
font-weight: bold;
}

.controls {
margin-top: 20px;
text-align: center;
}
</style>
</head>
<body>
<div id="loading">Loading...</div>
<canvas id="bevy-canvas"></canvas>
<div class="controls">
<p>RSMC Web Version</p>
</div>

<script type="module">
import init from './rsmc_wasm.js';

async function run() {
try {
// Initialize the WASM module
await init();

// Hide loading message
document.getElementById('loading').style.display = 'none';
} catch (e) {
console.error("Error initializing WASM:", e);
document.getElementById('loading').textContent = 'Error loading WASM: ' + e.message;
}
}

run();
</script>
</body>
</html>
Loading