Skip to content

Commit

Permalink
Merge pull request #106 from julienbrs/wasm-noise
Browse files Browse the repository at this point in the history
Conversion of simplex to WASM
  • Loading branch information
ponderingdemocritus authored Feb 1, 2024
2 parents 7e713f8 + 4ddc4f3 commit ed9dd24
Show file tree
Hide file tree
Showing 19 changed files with 3,469 additions and 10 deletions.
2 changes: 1 addition & 1 deletion examples/dojo-starter
2 changes: 1 addition & 1 deletion examples/react/react-phaser-example/.env.development
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
VITE_PUBLIC_ETH_CONTRACT_ADDRESS=0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7
VITE_PUBLIC_ACCOUNT_CLASS_HASH=0x04d07e40e93398ed3c76981e72dd1fd22557a78ce36c0515f679e27f0bb5bc5f
VITE_PUBLIC_MASTER_ADDRESS=0x517ececd29116499f4a1b64b094da79ba08dfd54a3edaa316134c41f8160973
VITE_PUBLIC_MASTER_ADDRESS=0x6162896d1d7ab204c7ccac6dd5f8e9e7c25ecd5ae4fcb4ad32e57786bb46e03
VITE_PUBLIC_MASTER_PRIVATE_KEY=0x1800000000300000180000000000030000000000003006001800006600
VITE_PUBLIC_WORLD_ADDRESS=0x33ac2f528bb97cc7b79148fd1756dc368be0e95d391d8c6d6473ecb60b4560e
VITE_PUBLIC_NODE_URL=http://localhost:5050
Expand Down
7 changes: 4 additions & 3 deletions examples/react/react-phaser-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
"dependencies": {
"@dojoengine/core": "^0.5.0",
"@dojoengine/create-burner": "^0.5.0",
"@dojoengine/react": "^0.5.0",
"@dojoengine/recs": "0.1.35",
"@dojoengine/state": "^0.5.0",
"@dojoengine/torii-client": "^0.5.0",
"@dojoengine/torii-wasm": "^0.5.0",
"@dojoengine/utils": "^0.5.0",
"@dojoengine/react": "^0.5.0",
"@dojoengine/state": "^0.5.0",
"@dojoengine/recs": "0.1.35",
"@dojoengine/utils-wasm": "^0.3.3",
"@latticexyz/phaserx": "^2.0.0-next.14",
"@latticexyz/utils": "^2.0.0-next.14",
"@radix-ui/react-slot": "^1.0.2",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Tileset } from "../../assets/world";
import { PhaserLayer } from "../createPhaserLayer";
import { snoise } from "@dojoengine/utils";
import { snoise } from "@dojoengine/utils-wasm";
import { MAP_AMPLITUDE } from "../config/constants";

export function mapSystem(layer: PhaserLayer) {
Expand All @@ -17,11 +17,13 @@ export function mapSystem(layer: PhaserLayer) {
for (let x = 0; x < 50; x++) {
for (let y = 0; y < 50; y++) {
const coord = { x, y };
const noiseInput = new Float64Array([
x / MAP_AMPLITUDE,
0,
y / MAP_AMPLITUDE,
]);
// Get a noise value between 0 and 100
const seed = Math.floor(
((snoise([x / MAP_AMPLITUDE, 0, y / MAP_AMPLITUDE]) + 1) / 2) *
100
);
const seed = Math.floor(((snoise(noiseInput) + 1) / 2) * 100);

if (seed > 70) {
// This would be the highest 'elevation'
Expand Down
3 changes: 3 additions & 0 deletions packages/utils-wasm/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
dist
target
7 changes: 7 additions & 0 deletions packages/utils-wasm/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
*

!pkg/**
!dist/**
!package.json
!readme.md
!changelog.md
303 changes: 303 additions & 0 deletions packages/utils-wasm/crate/Cargo.lock

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

25 changes: 25 additions & 0 deletions packages/utils-wasm/crate/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[package]
name = "utils-wasm"
version = "0.3.3"
edition = "2021"

[dependencies]
wasm-bindgen = "0.2.88"
serde = { version = "1.0.192", features = ["derive"] }
serde-wasm-bindgen = "0.6.0"

# The `console_error_panic_hook` crate provides better debugging of panics by
# logging them with `console.error`. This is great for development, but requires
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
# code size when deploying.
console_error_panic_hook = { version = "0.1.7", optional = true }
tsify = "0.4.5"

[dev-dependencies]
wasm-bindgen-test = "0.3.39"

[lib]
crate-type = ["cdylib", "rlib"]

[features]
console-error-panic = ["console_error_panic_hook"]
Loading

0 comments on commit ed9dd24

Please sign in to comment.