Add FPS display, get webassembly build working
This commit is contained in:
parent
3a9ad932e4
commit
2c0f2408a6
4
.gitignore
vendored
4
.gitignore
vendored
@ -142,3 +142,7 @@ Cargo.lock
|
|||||||
|
|
||||||
# Ignore save game file
|
# Ignore save game file
|
||||||
savegame.json
|
savegame.json
|
||||||
|
|
||||||
|
# Webassembly
|
||||||
|
wasm/*.wasm
|
||||||
|
wasm/*js
|
10
Cargo.toml
10
Cargo.toml
@ -6,11 +6,17 @@ edition = "2021"
|
|||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = ["rltk/opengl", "rltk/serde", "rltk/threaded"]
|
||||||
|
curses = ["rltk/curses", "rltk/serde"]
|
||||||
|
js = ["getrandom/js", "rltk/opengl", "rltk/serde"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
getrandom = { version = "0.2.4" }
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
regex = "1.5.4"
|
regex = "1.5.4"
|
||||||
rltk = { version = "0.8.0", features=["serde"] }
|
rltk = { version = "0.8.1", default-features = false }
|
||||||
specs = { version = "0.16.1", features = ["serde"] }
|
specs = { version = "0.16.1", features = ["serde"] }
|
||||||
specs-derive = "0.4.1"
|
specs-derive = "0.4.1"
|
||||||
serde = { version = "1.0.93", features = ["derive"] }
|
serde = { version = "1.0.93", features = ["derive"] }
|
||||||
serde_json = "1.0.39"
|
serde_json = "1.0.44"
|
21
Makefile
21
Makefile
@ -6,6 +6,20 @@ run: $(call print-help, run, Runs the binary in develop mode)
|
|||||||
run-pi: $(call print-help, run-pi, Sets appropriate flags so that the game runs on a Raspberry Pi)
|
run-pi: $(call print-help, run-pi, Sets appropriate flags so that the game runs on a Raspberry Pi)
|
||||||
MESA_GL_VERSION_OVERRIDE=3.0 MESA_GLSL_VERSION_OVERRIDE=330 cargo run
|
MESA_GL_VERSION_OVERRIDE=3.0 MESA_GLSL_VERSION_OVERRIDE=330 cargo run
|
||||||
|
|
||||||
|
run-curses: $(call print-help, run-curses, Run the game in a console window via the curses library)
|
||||||
|
cargo run --features curses --no-default-features
|
||||||
|
|
||||||
|
build:
|
||||||
|
cargo build
|
||||||
|
|
||||||
|
build-wasm: $(call print-help, build-wasm, Build the webassembly version of the game)
|
||||||
|
cargo build --release --target wasm32-unknown-unknown --features js
|
||||||
|
wasm-bindgen target/wasm32-unknown-unknown/release/roguelike_tutorial.wasm --out-dir wasm --no-modules --no-typescript
|
||||||
|
|
||||||
|
build-wasm-dev: $(call print-help, build-wasm-dev, Build the webassembly version of the game (dev version))
|
||||||
|
cargo build --target wasm32-unknown-unknown --features js
|
||||||
|
wasm-bindgen target/wasm32-unknown-unknown/debug/roguelike_tutorial.wasm --out-dir wasm --no-modules --no-typescript
|
||||||
|
|
||||||
clean: $(call print-help, clean, Removes save file and compilation artifacts)
|
clean: $(call print-help, clean, Removes save file and compilation artifacts)
|
||||||
rm -f savegame.json
|
rm -f savegame.json
|
||||||
cargo clean
|
cargo clean
|
||||||
@ -13,6 +27,9 @@ clean: $(call print-help, clean, Removes save file and compilation artifacts)
|
|||||||
check: $(call print-help, check, Check code syntax)
|
check: $(call print-help, check, Check code syntax)
|
||||||
cargo check
|
cargo check
|
||||||
|
|
||||||
|
check-wasm: $(call print-help, check-wasm, Check code syntax for webassembly build)
|
||||||
|
cargo check --target wasm32-unknown-unknown --features js
|
||||||
|
|
||||||
lint: $(call print-help, lint, Check code syntax and style)
|
lint: $(call print-help, lint, Check code syntax and style)
|
||||||
cargo clippy
|
cargo clippy
|
||||||
|
|
||||||
@ -21,9 +38,9 @@ fmt: $(call print-help, fmt, Runs formatter on code)
|
|||||||
|
|
||||||
fix: $(call print-help, fix, Fixes some warnings, then runs the formatter)
|
fix: $(call print-help, fix, Fixes some warnings, then runs the formatter)
|
||||||
cargo fix --allow-dirty --allow-staged
|
cargo fix --allow-dirty --allow-staged
|
||||||
cargo +nightly fmt
|
make fmt
|
||||||
|
|
||||||
docs: $(call print-help, docs, Generates code docs)
|
docs: $(call print-help, docs, Generates code docs)
|
||||||
cargo doc
|
cargo doc
|
||||||
|
|
||||||
.phony: run-pi clean check run fmt fix lint docs
|
.phony: run-pi clean check run fmt fix lint docs build build-wasm check-wasm build-wasm-dev
|
@ -192,6 +192,7 @@ fn main() -> ::rltk::BError {
|
|||||||
.with_title("Roguelike Tutorial")
|
.with_title("Roguelike Tutorial")
|
||||||
.with_font("vga8x16.png", 8, 16)
|
.with_font("vga8x16.png", 8, 16)
|
||||||
.with_sparse_console(80, 30, "vga8x16.png")
|
.with_sparse_console(80, 30, "vga8x16.png")
|
||||||
|
.with_vsync(false)
|
||||||
.build()?;
|
.build()?;
|
||||||
|
|
||||||
main_loop(context, init_state())
|
main_loop(context, init_state())
|
||||||
|
@ -13,6 +13,9 @@ use crate::{camera, colors, damage_system, gamelog, player, saveload_system, spa
|
|||||||
/// Whether to show a visual representation of map generation
|
/// Whether to show a visual representation of map generation
|
||||||
pub const SHOW_MAPGEN_VISUALIZER: bool = false;
|
pub const SHOW_MAPGEN_VISUALIZER: bool = false;
|
||||||
|
|
||||||
|
/// Whether to show an FPS counter
|
||||||
|
pub const SHOW_FPS: bool = true;
|
||||||
|
|
||||||
/// The main actions possible with a vendor
|
/// The main actions possible with a vendor
|
||||||
#[derive(PartialEq, Copy, Clone)]
|
#[derive(PartialEq, Copy, Clone)]
|
||||||
pub enum VendorMode {
|
pub enum VendorMode {
|
||||||
@ -546,5 +549,8 @@ impl GameState for State {
|
|||||||
|
|
||||||
damage_system::delete_the_dead(&mut self.ecs);
|
damage_system::delete_the_dead(&mut self.ecs);
|
||||||
::rltk::render_draw_buffer(ctx).expect("Failed to render the Rltk buffer");
|
::rltk::render_draw_buffer(ctx).expect("Failed to render the Rltk buffer");
|
||||||
|
if SHOW_FPS {
|
||||||
|
ctx.print(1, 59, &format!("FPS: {}", ctx.fps));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,12 @@ pub use single_thread::*;
|
|||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
pub trait UnifiedDispatcher {
|
||||||
|
fn run_now(&mut self, ecs: &mut World);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_arch = "wasm32")]
|
||||||
pub trait UnifiedDispatcher {
|
pub trait UnifiedDispatcher {
|
||||||
fn run_now(&mut self, ecs: *mut World);
|
fn run_now(&mut self, ecs: *mut World);
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ macro_rules! construct_dispatcher {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
let dispatch = MultiThreadedDispatcher {
|
let dispatch = MultiThreadedDispatcher {
|
||||||
dispatcher: dispatcher
|
dispatcher
|
||||||
};
|
};
|
||||||
|
|
||||||
return Box::new(dispatch);
|
return Box::new(dispatch);
|
||||||
@ -35,10 +35,8 @@ pub struct MultiThreadedDispatcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> UnifiedDispatcher for MultiThreadedDispatcher {
|
impl<'a> UnifiedDispatcher for MultiThreadedDispatcher {
|
||||||
fn run_now(&mut self, ecs: *mut World) {
|
fn run_now(&mut self, ecs: &mut World) {
|
||||||
unsafe {
|
self.dispatcher.dispatch(ecs);
|
||||||
self.dispatcher.dispatch(&mut *ecs);
|
crate::effects::run_effects_queue(ecs);
|
||||||
crate::effects::run_effects_queue(&mut *ecs);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
16
wasm/index.html
Normal file
16
wasm/index.html
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<title>Roguelike-game</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<canvas id="canvas" width="640" height="480"></canvas>
|
||||||
|
<script src="roguelike_tutorial.js"></script>
|
||||||
|
<script>
|
||||||
|
window.addEventListener('load', async () => {
|
||||||
|
await wasm_bindgen('roguelike_tutorial_bg.wasm');
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in New Issue
Block a user