Skip to content

Commit

Permalink
add wasm-platform example
Browse files Browse the repository at this point in the history
  • Loading branch information
leondejong committed Jun 18, 2024
1 parent b759b95 commit 5478f13
Show file tree
Hide file tree
Showing 22 changed files with 6,407 additions and 68 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.DS_Store
**/target
.DS_Store
**/node_modules
**/pkg
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
- `graphics/nannou-platform` -> Basic platform example with `nannou`
- `graphics/macroquad-platform` -> Basic platform example with `macroquad`
- `graphics/minifb-platform` -> Basic platform example with `minifb`
- `graphics/wasm-platform` -> Basic platform example with `wasm`
- `graphics/winit-softbuffer` -> Pixel drawing example with `winit` and `softbuffer`
- `graphics/winit-pixels` -> Pixel drawing example with `winit` and `pixels`
- `graphics/minifb-example` -> Pixel drawing example with `minifb`
2 changes: 1 addition & 1 deletion graphics/minifb-example/src/logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::state::State;
pub const FPS: usize = 60;
pub const WIDTH: usize = 576;
pub const HEIGHT: usize = 512;
pub const TITLE: &str = "MiniFB Example";
pub const TITLE: &str = "MiniFB";

pub fn run(state: &mut State) {
let mut buffer: Vec<u32> = vec![0; WIDTH * HEIGHT];
Expand Down
14 changes: 7 additions & 7 deletions graphics/minifb-example/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ pub fn render_rectangle(
let sxw = (sx + rectangle.width as usize * s).clamp(0, w);
let syh = (sy + rectangle.height as usize * s).clamp(0, h);

for j in sy..syh {
for i in sx..sxw {
buffer[i + j * w] = value;
for y in sy..syh {
for x in sx..sxw {
buffer[x + y * w] = value;
}
}
}
Expand Down Expand Up @@ -86,11 +86,11 @@ pub fn render_image(
let cx = s * (image_x as i32).clamp(0, w);
let cy = s * (image_y as i32).clamp(0, h);

let sxw = (sx + sw).clamp(0, w);
let syh = (sy + sh).clamp(0, h);
let cw = (sx + sw).clamp(0, w);
let ch = (sy + sh).clamp(0, h);

for y in cy..syh {
for x in cx..sxw {
for y in cy..ch {
for x in cx..cw {
let index = (x + y * w) as usize;
let point = (x / s - ix + (y / s - iy) * iw) as usize;
if image.data[point] & ALPHA_MASK > 0 {
Expand Down
24 changes: 0 additions & 24 deletions graphics/minifb-platform/src/logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,30 +84,6 @@ pub fn update(state: &mut State) {
}
}

// pub fn render(state: &State) {
// let text = format!("fps: {}", state.fps);

// draw_background(BACKGROUND);
// draw_text(&text, 28, 24, 20, TEXT);
// draw_rectangle(
// state.x as i32,
// state.y as i32,
// state.width as i32,
// state.height as i32,
// CONTENT,
// );

// for rectangle in state.field.iter() {
// draw_rectangle(
// rectangle.x as i32,
// rectangle.y as i32,
// rectangle.width as i32,
// rectangle.height as i32,
// FOREGROUND,
// );
// }
// }

pub fn render(state: &mut State, buffer: &mut Vec<u32>, scale: f64, width: u32, height: u32) {
let background = Graphic::background(BACKGROUND);

Expand Down
14 changes: 7 additions & 7 deletions graphics/minifb-platform/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ pub fn render_rectangle(
let sxw = (sx + rectangle.width as usize * s).clamp(0, w);
let syh = (sy + rectangle.height as usize * s).clamp(0, h);

for j in sy..syh {
for i in sx..sxw {
buffer[i + j * w] = value;
for y in sy..syh {
for x in sx..sxw {
buffer[x + y * w] = value;
}
}
}
Expand Down Expand Up @@ -92,11 +92,11 @@ pub fn render_image(
let cx = s * (image_x as i32).clamp(0, w);
let cy = s * (image_y as i32).clamp(0, h);

let sxw = (sx + sw).clamp(0, w);
let syh = (sy + sh).clamp(0, h);
let cw = (sx + sw).clamp(0, w);
let ch = (sy + sh).clamp(0, h);

for y in cy..syh {
for x in cx..sxw {
for y in cy..ch {
for x in cx..cw {
let index = (x + y * w) as usize;
let point = (x / s - ix + (y / s - iy) * iw) as usize;
if image.data[point] & ALPHA_MASK > 0 {
Expand Down
2 changes: 1 addition & 1 deletion graphics/minifb-platform/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::color::Color;
use crate::logic::{render, update};
use crate::rectangle::Rectangle;

pub const TITLE: &str = "MiniFB Example";
pub const TITLE: &str = "MiniFB";

pub const WIDTH: usize = 768;
pub const HEIGHT: usize = 576;
Expand Down
Loading

0 comments on commit 5478f13

Please sign in to comment.