Skip to content

Commit

Permalink
Update the examples to show both num_updates and num_renders
Browse files Browse the repository at this point in the history
  • Loading branch information
tuzz committed Aug 27, 2023
1 parent 3d9010f commit e32decd
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 15 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ use the crate in a web browser. You can run it with:
cd examples/using_wasm && ./run_example
```

Then open [localhost:8000](http://localhost:8000) in your web browser.
Then open [localhost:8000](http://localhost:8000) in your web browser. The counters just tick up on the web page:

![Using WASM](./examples/using_wasm.png)

Expand All @@ -125,6 +125,8 @@ use the crate alongside a winit window. You can run it with:
cargo run --example using_winit --features winit
```

The counters just tick up on the window title:

![Using Winit](./examples/using_winit.png)

## Example 4: Using a TAO Window
Expand All @@ -136,6 +138,8 @@ crate alongside a TAO window with a native menu bar. You can run it with:
cargo run --example using_tao --features tao
```

The counters just tick up on the window title:

![Using TAO](./examples/using_tao.png)

## License
Expand Down
Binary file modified examples/using_tao.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 6 additions & 4 deletions examples/using_tao.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ fn main() {

#[derive(Default)]
struct Game {
counter: u32,
num_updates: u32,
num_renders: u32,
}

impl Game {
Expand All @@ -43,11 +44,12 @@ impl Game {
}

pub fn your_update_function(&mut self) {
self.counter += 1;
self.num_updates += 1;
}

pub fn your_render_function(&self, window: &Window) {
window.set_title(&format!("Counter: {}", self.counter));
pub fn your_render_function(&mut self, window: &Window) {
self.num_renders += 1;
window.set_title(&format!("num_updates: {}, num_renders: {}", self.num_updates, self.num_renders));
}

// A very simple handler that returns false when CloseRequested is detected.
Expand Down
Binary file modified examples/using_wasm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion examples/using_wasm/run_example
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ cargo install live-server && \
wasm-pack build --dev --target no-modules --out-dir target --out-name index && \
mv target/index_bg.wasm target/index.wasm && \
\
live-server -h 0.0.0.0
echo "Starting server at http://localhost:8000" && \
live-server -h 0.0.0.0 -p 8000
12 changes: 7 additions & 5 deletions examples/using_wasm/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ pub fn main() {

struct Game {
span: web_sys::Element,
counter: u32,
num_updates: u32,
num_renders: u32,
}

impl Game {
Expand All @@ -26,14 +27,15 @@ impl Game {

body.append_child(&span).unwrap();

Self { span, counter: 0 }
Self { span, num_updates: 0, num_renders: 0 }
}

pub fn your_update_function(&mut self) {
self.counter += 1;
self.num_updates += 1;
}

pub fn your_render_function(&self) {
self.span.set_inner_html(&format!("Counter: {}", self.counter));
pub fn your_render_function(&mut self) {
self.num_renders += 1;
self.span.set_inner_html(&format!("num_updates: {}, num_renders: {}", self.num_updates, self.num_renders));
}
}
Binary file modified examples/using_winit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 6 additions & 4 deletions examples/using_winit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ fn main() {

#[derive(Default)]
struct Game {
counter: u32,
num_updates: u32,
num_renders: u32,
}

impl Game {
Expand All @@ -36,11 +37,12 @@ impl Game {
}

pub fn your_update_function(&mut self) {
self.counter += 1;
self.num_updates += 1;
}

pub fn your_render_function(&self, window: &Window) {
window.set_title(&format!("Counter: {}", self.counter));
pub fn your_render_function(&mut self, window: &Window) {
self.num_renders += 1;
window.set_title(&format!("num_updates: {}, num_renders: {}", self.num_updates, self.num_renders));
}

// A very simple handler that returns false when CloseRequested is detected.
Expand Down

0 comments on commit e32decd

Please sign in to comment.