Browse Source

removed npm

master
Inderjit Gill 1 year ago
parent
commit
272164ac21
17 changed files with 3768 additions and 6409 deletions
  1. +3
    -6
      .gitignore
  2. +79
    -99
      client/Cargo.lock
  3. +14
    -0
      client/build.sh
  4. +0
    -6
      client/package.json
  5. +0
    -5
      client/www/bootstrap.js
  6. BIN
      client/www/favicon.ico
  7. +3003
    -0
      client/www/howler.js
  8. +20
    -1
      client/www/index.html
  9. +649
    -6
      client/www/index.js
  10. +0
    -44
      client/www/js/Audio.js
  11. +0
    -466
      client/www/js/GLRenderer.js
  12. +0
    -259
      client/www/js/Matrix.js
  13. +0
    -81
      client/www/js/Metric.js
  14. +0
    -5393
      client/www/package-lock.json
  15. +0
    -27
      client/www/package.json
  16. +0
    -2
      client/www/wasm/.gitignore
  17. +0
    -14
      client/www/webpack.config.js

+ 3
- 6
.gitignore View File

@@ -1,9 +1,6 @@
/assets/research

/client/target
/client/www/dist
/client/www/node_modules

/core/target

/server/target
/client/target
/client/www/sokoban_client.js
/client/www/sokoban_client_bg.wasm

+ 79
- 99
client/Cargo.lock View File

@@ -4,7 +4,7 @@ version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"backtrace-sys 0.1.24 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-demangle 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -26,7 +26,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "cfg-if"
version = "0.1.5"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
@@ -34,28 +34,28 @@ name = "console_error_panic_hook"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen 0.2.28 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "failure"
version = "0.1.2"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"backtrace 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
"failure_derive 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"failure_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "failure_derive"
version = "0.1.2"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.14.9 (registry+https://github.com/rust-lang/crates.io-index)",
"synstructure 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.21 (registry+https://github.com/rust-lang/crates.io-index)",
"synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
@@ -65,19 +65,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "js-sys"
version = "0.3.4"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"wasm-bindgen 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen 0.2.28 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "lazy_static"
version = "1.1.0"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "libc"
@@ -86,10 +83,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "log"
version = "0.4.5"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
@@ -99,7 +96,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "proc-macro2"
version = "0.4.20"
version = "0.4.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -107,10 +104,10 @@ dependencies = [

[[package]]
name = "quote"
version = "0.6.8"
version = "0.6.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
@@ -127,11 +124,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
name = "sokoban-client"
version = "0.1.0"
dependencies = [
"cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"console_error_panic_hook 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"sokoban-core 0.1.0",
"wasm-bindgen 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-test 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen 0.2.28 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-test 0.2.28 (registry+https://github.com/rust-lang/crates.io-index)",
"wee_alloc 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
]

@@ -139,37 +136,27 @@ dependencies = [
name = "sokoban-core"
version = "0.1.0"
dependencies = [
"failure 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "syn"
version = "0.14.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "syn"
version = "0.15.9"
version = "0.15.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "synstructure"
version = "0.9.0"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.14.9 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.21 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]

@@ -187,93 +174,88 @@ dependencies = [
]

[[package]]
name = "version_check"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "void"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "wasm-bindgen"
version = "0.2.27"
version = "0.2.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"wasm-bindgen-macro 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-macro 0.2.28 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "wasm-bindgen-backend"
version = "0.2.27"
version = "0.2.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.9 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-shared 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.21 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-shared 0.2.28 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "wasm-bindgen-futures"
version = "0.3.4"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
"js-sys 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)",
"js-sys 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen 0.2.28 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "wasm-bindgen-macro"
version = "0.2.27"
version = "0.2.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-macro-support 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-macro-support 0.2.28 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.27"
version = "0.2.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.9 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-backend 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-shared 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.21 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-backend 0.2.28 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-shared 0.2.28 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "wasm-bindgen-shared"
version = "0.2.27"
version = "0.2.28"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "wasm-bindgen-test"
version = "0.2.27"
version = "0.2.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"console_error_panic_hook 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
"js-sys 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"js-sys 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"scoped-tls 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-futures 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-test-macro 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen 0.2.28 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-futures 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-test-macro 0.2.28 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "wasm-bindgen-test-macro"
version = "0.2.27"
version = "0.2.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
@@ -281,7 +263,7 @@ name = "wee_alloc"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
"memory_units 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -311,35 +293,33 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum backtrace 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "89a47830402e9981c5c41223151efcced65a0510c13097c769cede7efb34782a"
"checksum backtrace-sys 0.1.24 (registry+https://github.com/rust-lang/crates.io-index)" = "c66d56ac8dabd07f6aacdaf633f4b8262f5b3601a810a0dcddffd5c22c69daa0"
"checksum cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)" = "f159dfd43363c4d08055a07703eb7a3406b0dac4d0584d96965a3262db3c9d16"
"checksum cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0c4e7bb64a8ebb0d856483e1e682ea3422f883c5f5615a90d51a2c82fe87fdd3"
"checksum cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "082bb9b28e00d3c9d39cc03e64ce4cea0f1bb9b3fde493f0cbc008472d22bdf4"
"checksum console_error_panic_hook 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6c5dd2c094474ec60a6acaf31780af270275e3153bafff2db5995b715295762e"
"checksum failure 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7efb22686e4a466b1ec1a15c2898f91fa9cb340452496dca654032de20ff95b9"
"checksum failure_derive 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "946d0e98a50d9831f5d589038d2ca7f8f455b1c21028c0db0e84116a12696426"
"checksum failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6dd377bcc1b1b7ce911967e3ec24fa19c3224394ec05b54aa7b083d498341ac7"
"checksum failure_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "64c2d913fe8ed3b6c6518eedf4538255b989945c14c2a7d5cbff62a5e2120596"
"checksum futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)" = "49e7653e374fe0d0c12de4250f0bdb60680b8c80eed558c5c7538eec9c89e21b"
"checksum js-sys 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8398e64a4381e93044f63287109e5f1cb65122e63ad2f0607ec6a239d9e13464"
"checksum lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca488b89a5657b0a2ecd45b95609b3e848cf1755da332a0da46e2b2b1cb371a7"
"checksum js-sys 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "9f476e674d55cc43a57dfd1d3986c7c305e41827ead21ff6373652804f728afe"
"checksum lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a374c89b9db55895453a74c1e38861d9deec0b01b405a82516e9d5de4820dea1"
"checksum libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)" = "76e3a3ef172f1a0b9a9ff0dd1491ae5e6c948b94479a3021819ba7d860c8645d"
"checksum log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "d4fcce5fa49cc693c312001daf1d13411c4a5283796bac1084299ea3e567113f"
"checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6"
"checksum memory_units 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3"
"checksum proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)" = "3d7b7eaaa90b4a90a932a9ea6666c95a389e424eff347f0f793979289429feee"
"checksum quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)" = "dd636425967c33af890042c483632d33fa7a18f19ad1d7ea72e8998c6ef8dea5"
"checksum proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)" = "77619697826f31a02ae974457af0b29b723e5619e113e9397b8b82c6bd253f09"
"checksum quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "53fa22a1994bd0f9372d7a816207d8a2677ad0325b073f5c5332760f0fb62b5c"
"checksum rustc-demangle 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "bcfe5b13211b4d78e5c2cadfebd7769197d95c639c35a50057eb4c05de811395"
"checksum scoped-tls 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "332ffa32bf586782a3efaeb58f127980944bbc8c4d6913a86107ac2a5ab24b28"
"checksum syn 0.14.9 (registry+https://github.com/rust-lang/crates.io-index)" = "261ae9ecaa397c42b960649561949d69311f08eeaea86a65696e6e46517cf741"
"checksum syn 0.15.9 (registry+https://github.com/rust-lang/crates.io-index)" = "b10ee269228fb723234fce98e9aac0eaed2bd5f1ad2f6930e8d5b93f04445a1a"
"checksum synstructure 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "85bb9b7550d063ea184027c9b8c20ac167cd36d3e06b3a40bceb9d746dc1a7b7"
"checksum syn 0.15.21 (registry+https://github.com/rust-lang/crates.io-index)" = "816b7af21405b011a23554ea2dc3f6576dc86ca557047c34098c1d741f10f823"
"checksum synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015"
"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
"checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56"
"checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd"
"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
"checksum wasm-bindgen 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)" = "ddabe7a233fc293b35f9754067580906c14b5a14b68da67d21ac109f8624c3fe"
"checksum wasm-bindgen-backend 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)" = "4420cb4101491fa91a0aa488584bf359ec4d805667982d3de37ad18c1adc6c62"
"checksum wasm-bindgen-futures 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "510541c3a3e13763785f6066ad8823f522fc214f867c1af9469092a5f740230f"
"checksum wasm-bindgen-macro 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)" = "83b50f7b3fad6acd49da239daf5a7a358c554e94e904549f4fd2d7a34d692fb0"
"checksum wasm-bindgen-macro-support 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)" = "a0970181097265052ae1822d0203412ab7ca5a0f05b8d6581c23ec31e9b99b95"
"checksum wasm-bindgen-shared 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)" = "251fcb2edbdc5baace161ed8ab680c6cd0ff35b50bdf3eb21afb81fd42c0eb78"
"checksum wasm-bindgen-test 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)" = "0cb421c529d70602b52be2ae5bf0260a718e2f69514d3841cb43e094f5c3f0f1"
"checksum wasm-bindgen-test-macro 0.2.27 (registry+https://github.com/rust-lang/crates.io-index)" = "0068543ec0dd625181605c62da925b06e8a3e51aac1c4035943717cb3c91bed2"
"checksum wasm-bindgen 0.2.28 (registry+https://github.com/rust-lang/crates.io-index)" = "dcefd48aa89f1319c61780595be0d378c5de5ccefd9d4e55c282aad4245a256c"
"checksum wasm-bindgen-backend 0.2.28 (registry+https://github.com/rust-lang/crates.io-index)" = "9b12e4c544f22adf78c7bc06fa605ac084566adc88bcbbe8857f0ceb0a12613a"
"checksum wasm-bindgen-futures 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e681f39732ced443d8ae6cc866ba00fdebc4482f6e0e7e96ef0c415681be83d0"
"checksum wasm-bindgen-macro 0.2.28 (registry+https://github.com/rust-lang/crates.io-index)" = "d0c71b31dc194560c8696348975abc32ed134742c19a865601db3d7eb01a1c56"
"checksum wasm-bindgen-macro-support 0.2.28 (registry+https://github.com/rust-lang/crates.io-index)" = "890018bb4a49c4c977c66e0c6a5f633d82766f6e78a57e2bc8f611a22f72dc18"
"checksum wasm-bindgen-shared 0.2.28 (registry+https://github.com/rust-lang/crates.io-index)" = "0e38e79a1881e09015aaf8db197b04d97439e06da0f50a213608e93247f5ecfc"
"checksum wasm-bindgen-test 0.2.28 (registry+https://github.com/rust-lang/crates.io-index)" = "aae7dcae1123854b20b06288ea930153d6fa0fa75948aa0218fb50f81cac1a1d"
"checksum wasm-bindgen-test-macro 0.2.28 (registry+https://github.com/rust-lang/crates.io-index)" = "d7341ddac1babc9790b0647769f772d1dba217c9b16f204a55f82910853dca5b"
"checksum wee_alloc 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "27875be1daf838fa18f3e94fd19fd12638e34615b42f56da2610c8f46be80cc6"
"checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0"
"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"

+ 14
- 0
client/build.sh View File

@@ -0,0 +1,14 @@
#!/bin/sh

if [ "$1" = "release" ]
then
cargo +nightly build --release --target wasm32-unknown-unknown
wasm-bindgen target/wasm32-unknown-unknown/release/sokoban_client.wasm --out-dir www --no-typescript --no-modules

sed -i "s/__exports.BridgeConfig = BridgeConfig;/__exports.BridgeConfig = BridgeConfig;\n\/\/ ISG HACK\n__exports.wasm = wasm;/g" www/sokoban_client.js
else
cargo +nightly build --target wasm32-unknown-unknown
wasm-bindgen target/wasm32-unknown-unknown/debug/sokoban_client.wasm --out-dir www --no-typescript --no-modules

sed -i "s/__exports.BridgeConfig = BridgeConfig;/__exports.BridgeConfig = BridgeConfig;\n\/\/ ISG HACK\n__exports.wasm = wasm;/g" www/sokoban_client.js
fi

+ 0
- 6
client/package.json View File

@@ -1,6 +0,0 @@
{
"scripts": {
"build:dev": "cargo +nightly build --target wasm32-unknown-unknown && wasm-bindgen target/wasm32-unknown-unknown/debug/sokoban_client.wasm --out-dir www/wasm --no-typescript --browser",
"build:release": "cargo +nightly build --release --target wasm32-unknown-unknown && wasm-bindgen target/wasm32-unknown-unknown/release/sokoban_client.wasm --out-dir www/wasm --no-typescript --browser"
}
}

+ 0
- 5
client/www/bootstrap.js View File

@@ -1,5 +0,0 @@
// A dependency graph that contains any wasm must all be imported
// asynchronously. This `bootstrap.js` file does the single async import, so
// that no one else needs to worry about it again.
import("./index.js")
.catch(e => console.error("Error importing `index.js`:", e));

BIN
client/www/favicon.ico View File

Before After

+ 3003
- 0
client/www/howler.js
File diff suppressed because it is too large
View File


+ 20
- 1
client/www/index.html View File

@@ -22,6 +22,25 @@
</head>
<body>
<canvas id="render-canvas"></canvas>
<script src='bootstrap.js'></script>
<script src='howler.js'></script>


<script>
// The `--no-modules`-generated JS from `wasm-bindgen` attempts to use
// `WebAssembly.instantiateStreaming` to instantiate the wasm module,
// but this doesn't work with `file://` urls. This example is frequently
// viewed by simply opening `index.html` in a browser (with a `file://`
// url), so it would fail if we were to call this function!
//
// Work around this for now by deleting the function to ensure that the
// `no_modules.js` script doesn't have access to it. You won't need this
// hack when deploying over HTTP.
delete WebAssembly.instantiateStreaming;
</script>

<!-- this is the JS generated by the `wasm-bindgen` CLI tool -->
<script src='./sokoban_client.js'></script>

<script src='index.js'></script>
</body>
</html>

+ 649
- 6
client/www/index.js View File

@@ -1,9 +1,642 @@
import { Bridge, BridgeConfig } from "./wasm/sokoban_client";
import { memory } from "./wasm/sokoban_client_bg";
const { Bridge, BridgeConfig } = wasm_bindgen;
let memory = undefined;

function matrixCreate() {
const out = new Float32Array(16);
out[0] = 1;
out[1] = 0;
out[2] = 0;
out[3] = 0;
out[4] = 0;
out[5] = 1;
out[6] = 0;
out[7] = 0;
out[8] = 0;
out[9] = 0;
out[10] = 1;
out[11] = 0;
out[12] = 0;
out[13] = 0;
out[14] = 0;
out[15] = 1;

return out;
}

function matrixOrtho(out, left, right, bottom, top, near, far) {
const lr = 1 / (left - right);
const bt = 1 / (bottom - top);
const nf = 1 / (near - far);

out[0] = -2 * lr;
out[1] = 0;
out[2] = 0;
out[3] = 0;
out[4] = 0;
out[5] = -2 * bt;
out[6] = 0;
out[7] = 0;
out[8] = 0;
out[9] = 0;
out[10] = 2 * nf;
out[11] = 0;
out[12] = (left + right) * lr;
out[13] = (top + bottom) * bt;
out[14] = (far + near) * nf;
out[15] = 1;

return out;
}

const logToConsole = false;

function memorySubArray(mem, ptr, length) {
const nByte = 4;
const pos = ptr / nByte;
return mem.subarray(pos, pos + length);
}

function initGL(canvas) {
try {
const gl = canvas.getContext('experimental-webgl', {
alpha: false,
preserveDrawingBuffer: true
});

if (!gl) {
alert('Could not initialise WebGL, sorry :-(');
}

return gl;
} catch (e) {
return undefined;
}
}

function compileShader(gl, type, src) {
const shader = gl.createShader(type);
gl.shaderSource(shader, src);
gl.compileShader(shader);

if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
let lastError = gl.getShaderInfoLog(shader);
console.log(`Error compiling shader ${shader} : ${lastError}`);
gl.deleteShader(shader);
return null;
}
return shader;
}

function setupInGameShader(gl) {
const shader = {};

shader.program = gl.createProgram();

const fragmentSrc = `
precision mediump float;
varying vec4 vColor;
varying highp vec2 vTextureCoord;

uniform sampler2D uSampler;

void main(void) {
vec4 tex = texture2D(uSampler, vTextureCoord);

gl_FragColor.r = tex.r * vColor.a * vColor.r;
gl_FragColor.g = tex.g * vColor.a * vColor.g;
gl_FragColor.b = tex.b * vColor.a * vColor.b;
gl_FragColor.a = tex.a * vColor.a;

}
`;

const vertexSrc = `
attribute vec2 aVertexPosition;
attribute vec4 aVertexColor;
attribute vec2 aVertexTexture;

uniform mat4 uMVMatrix;
uniform mat4 uPMatrix;

varying vec4 vColor;
varying highp vec2 vTextureCoord;

void main(void) {
gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 0.0, 1.0);
vColor = aVertexColor;
vTextureCoord = aVertexTexture;
}
`;

const vertexShader = compileShader(gl, gl.VERTEX_SHADER, vertexSrc);
const fragmentShader = compileShader(gl, gl.FRAGMENT_SHADER, fragmentSrc);

gl.attachShader(shader.program, vertexShader);
gl.attachShader(shader.program, fragmentShader);

gl.linkProgram(shader.program);

if (!gl.getProgramParameter(shader.program, gl.LINK_STATUS)) {
let lastError = gl.getProgramInfoLog(shader.program);

alert(`Could not initialise shaders: ${lastError}`);;
gl.deleteProgram(shader.program);
return null;
}

shader.positionLocation = gl.getAttribLocation(shader.program, 'aVertexPosition');
shader.colourLocation = gl.getAttribLocation(shader.program, 'aVertexColor');
shader.texCoordLocation = gl.getAttribLocation(shader.program, 'aVertexTexture');

shader.pMatrixLocation = gl.getUniformLocation(shader.program, 'uPMatrix');
shader.mvMatrixLocation = gl.getUniformLocation(shader.program, 'uMVMatrix');
shader.textureLocation = gl.getUniformLocation(shader.program, 'uSampler');

return shader;
}

function setupCRTShader(gl) {
const shader = {};

shader.program = gl.createProgram();

const fragmentSrc = `
precision highp float;
varying vec2 tex_coord;

uniform sampler2D texture;
uniform vec2 res;
uniform vec2 uv_max;
uniform vec2 warp2;

// Amount of shadow mask.
float maskDark=0.7;
float maskLight=1.4;

// Distortion of scanlines, and end of screen alpha.
vec2 Warp(vec2 pos) {
pos = pos * 2.0 - 1.0;
pos *= vec2(1.0 + (pos.y * pos.y) * warp2.x, 1.0 + (pos.x * pos.x) * warp2.y);
return pos * 0.5 + 0.5;
}

// Shadow mask.
vec3 Mask(vec2 pos) {
pos.x += pos.y * 3.0;
vec3 mask = vec3(maskDark, maskDark, maskDark);
pos.x = fract(pos.x / 6.0);
if (pos.x < 0.333) mask.r = maskLight;
else if(pos.x < 0.666) mask.g=maskLight;
else mask.b = maskLight;
return mask;
}

void main(void) {
vec2 normalised_tex_coord = tex_coord / uv_max;
vec2 pos=Warp(normalised_tex_coord);
pos *= uv_max;
vec4 tex = texture2D(texture, pos);

vec2 pixel = res * pos;
gl_FragColor.rgb=tex.rgb;// * Mask(pixel.xy);
gl_FragColor.a = 1.0;
}
`;

const vertexSrc = `
attribute vec2 v_pos;
attribute vec2 v_tex_coord;

uniform mat4 m_mv;
uniform mat4 m_p;

varying highp vec2 tex_coord;

void main(void) {
gl_Position = m_p * m_mv * vec4(v_pos, 0.0, 1.0);
tex_coord = v_tex_coord;
}
`;

const vertexShader = compileShader(gl, gl.VERTEX_SHADER, vertexSrc);
const fragmentShader = compileShader(gl, gl.FRAGMENT_SHADER, fragmentSrc);

gl.attachShader(shader.program, vertexShader);
gl.attachShader(shader.program, fragmentShader);

gl.linkProgram(shader.program);

if (!gl.getProgramParameter(shader.program, gl.LINK_STATUS)) {
let lastError = gl.getProgramInfoLog(shader.program);

alert(`Could not initialise shaders: ${lastError}`);;
gl.deleteProgram(shader.program);
return null;
}

shader.positionLocation = gl.getAttribLocation(shader.program, 'v_pos');
shader.texCoordLocation = gl.getAttribLocation(shader.program, 'v_tex_coord');

shader.pMatrixLocation = gl.getUniformLocation(shader.program, 'm_p');
shader.mvMatrixLocation = gl.getUniformLocation(shader.program, 'm_mv');

shader.textureLocation = gl.getUniformLocation(shader.program, 'texture');

shader.resolutionLocation = gl.getUniformLocation(shader.program, 'res');
shader.uvMaxLocation = gl.getUniformLocation(shader.program, 'uv_max');
shader.warp2 = gl.getUniformLocation(shader.program, 'warp2');

return shader;
}

function setupGLState(gl) {
gl.clearColor(0.0, 0.0, 0.0, 0.0);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
gl.enable(gl.BLEND);

// assuming that we'll be using pre-multiplied alpha
// see http://www.realtimerendering.com/blog/gpus-prefer-premultiplication/
gl.blendEquation(gl.FUNC_ADD);
gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);

// gl.disable(gl.DEPTH_TEST);
}

function createRenderTexture(gl, config) {
// create to render to
const targetTextureWidth = config.render_texture_width;
const targetTextureHeight = config.render_texture_height;

const targetTexture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, targetTexture);

// define size and format of level 0
const level = 0;
const internalFormat = gl.RGBA;
const border = 0;
const format = gl.RGBA;
const type = gl.UNSIGNED_BYTE;
const data = null;
gl.texImage2D(gl.TEXTURE_2D, level, internalFormat,
targetTextureWidth, targetTextureHeight, border,
format, type, data);

gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
// gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
// gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);

return targetTexture;
}

function createFrameBuffer(gl, targetTexture) {
// Create and bind the framebuffer
const fb = gl.createFramebuffer();
gl.bindFramebuffer(gl.FRAMEBUFFER, fb);

// attach the texture as the first color attachment
const attachmentPoint = gl.COLOR_ATTACHMENT0;
const level = 0;
gl.framebufferTexture2D(gl.FRAMEBUFFER, attachmentPoint, gl.TEXTURE_2D, targetTexture, level);

return fb;
}

function checkFramebufferStatus(gl) {
let res = gl.checkFramebufferStatus(gl.FRAMEBUFFER);
switch(res) {
case gl.FRAMEBUFFER_COMPLETE: console.log("gl.FRAMEBUFFER_COMPLETE"); break;
case gl.FRAMEBUFFER_INCOMPLETE_ATTACHMENT: console.log("gl.FRAMEBUFFER_INCOMPLETE_ATTACHMENT"); break;
case gl.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: console.log("gl.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT"); break;
case gl.FRAMEBUFFER_INCOMPLETE_DIMENSIONS: console.log("gl.FRAMEBUFFER_INCOMPLETE_DIMENSIONS"); break;
case gl.FRAMEBUFFER_UNSUPPORTED: console.log("gl.FRAMEBUFFER_UNSUPPORTED"); break;
case gl.FRAMEBUFFER_INCOMPLETE_MULTISAMPLE: console.log("gl.FRAMEBUFFER_INCOMPLETE_MULTISAMPLE"); break;
case gl.RENDERBUFFER_SAMPLES: console.log("gl.RENDERBUFFER_SAMPLE"); break;
}
}

class GLRenderer {
constructor(config, canvasElement) {
this.glDomElement = canvasElement;

// webgl setup
const gl = initGL(this.glDomElement);
this.gl = gl;

this.inGameShader = setupInGameShader(gl);
this.crtShader = setupCRTShader(gl);

setupGLState(gl);

this.glVertexBuffer = gl.createBuffer();
this.glColourBuffer = gl.createBuffer();
this.glTextureBuffer = gl.createBuffer();

this.mvMatrix = matrixCreate();
this.pMatrix = matrixCreate();
// Matrix.ortho(this.pMatrix, 0, config.canvas_width, 0, config.canvas_height, 10, -10);

this.tilesetTexture = this.gl.createTexture();
this.renderTexture = createRenderTexture(gl, config);
this.framebuffer = createFrameBuffer(gl, this.renderTexture);

// render to the canvas
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
}

loadTileset(src) {
let gl = this.gl;
let tex = this.tilesetTexture;

return new Promise(function(resolve, reject) {
const image = new Image();

import { GLRenderer } from "./js/GLRenderer";
import { Audio } from "./js/Audio";
import { Metric } from "./js/Metric";
image.addEventListener('load', () => {
gl.bindTexture(gl.TEXTURE_2D, tex);
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);

gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);

resolve([image.width, image.height]);
});

image.addEventListener('error', () => {
reject();
});

image.src = src;
});
}

renderGeometryToTexture(destTextureWidth, destTextureHeight, memoryF32, geo_len, geo_ptr) {
const gl = this.gl;

let shader = this.inGameShader;

// render to texture attached to framebuffer

gl.bindFramebuffer(gl.FRAMEBUFFER, this.framebuffer);
// gl.bindFramebuffer(gl.FRAMEBUFFER, null);

gl.bindTexture(gl.TEXTURE_2D, this.tilesetTexture);
gl.viewport(0, 0, destTextureWidth, destTextureHeight);

gl.useProgram(shader.program);

gl.enableVertexAttribArray(shader.positionLocation);
gl.enableVertexAttribArray(shader.colourLocation);
gl.enableVertexAttribArray(shader.texCoordLocation);

// gl.clearColor(0.0, 0.0, 1.0, 1.0);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);


// render the entirety of the scene
matrixOrtho(this.pMatrix, 0, destTextureWidth, 0, destTextureHeight, 10, -10);

gl.uniformMatrix4fv(shader.pMatrixLocation,
false,
this.pMatrix);

gl.uniformMatrix4fv(shader.mvMatrixLocation,
false,
this.mvMatrix);

gl.uniform1i(shader.textureLocation, 0);


const glVertexBuffer = this.glVertexBuffer;
const glColourBuffer = this.glColourBuffer;
const glTextureBuffer = this.glTextureBuffer;

const bytesin32bit = 4;

const vertexItemSize = 2;
const colourItemSize = 4;
const textureItemSize = 2;
const totalSize = (vertexItemSize + colourItemSize + textureItemSize);

const gbuf = memorySubArray(memoryF32, geo_ptr, geo_len);

gl.bindBuffer(gl.ARRAY_BUFFER, glVertexBuffer);
gl.bufferData(gl.ARRAY_BUFFER, gbuf, gl.STATIC_DRAW);
gl.vertexAttribPointer(shader.positionLocation,
vertexItemSize,
gl.FLOAT, false, totalSize * bytesin32bit,
0 * bytesin32bit);

gl.bindBuffer(gl.ARRAY_BUFFER, glColourBuffer);
gl.bufferData(gl.ARRAY_BUFFER, gbuf, gl.STATIC_DRAW);
gl.vertexAttribPointer(shader.colourLocation,
colourItemSize,
gl.FLOAT, false, totalSize * bytesin32bit,
vertexItemSize * bytesin32bit);

gl.bindBuffer(gl.ARRAY_BUFFER, glTextureBuffer);
gl.bufferData(gl.ARRAY_BUFFER, gbuf, gl.STATIC_DRAW);
gl.vertexAttribPointer(shader.texCoordLocation,
textureItemSize,
gl.FLOAT, false, totalSize * bytesin32bit,
(vertexItemSize + colourItemSize) * bytesin32bit);

gl.drawArrays(gl.TRIANGLE_STRIP, 0, geo_len / totalSize);
}

renderTextureToScreen(canvasWidth, canvasHeight, memoryF32, geo_len, geo_ptr, curvature) {
const gl = this.gl;

let shader = this.crtShader;
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
gl.bindTexture(gl.TEXTURE_2D, this.renderTexture);
gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);

gl.useProgram(shader.program);

gl.enableVertexAttribArray(shader.positionLocation);
gl.enableVertexAttribArray(shader.texCoordLocation);

// gl.clearColor(0.0, 0.0, 1.0, 1.0);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);

// render the entirety of the scene
matrixOrtho(this.pMatrix, 0, canvasWidth, 0, canvasHeight, 10, -10);

// add some uniforms for canvas width and height

gl.uniformMatrix4fv(shader.pMatrixLocation,
false,
this.pMatrix);

gl.uniformMatrix4fv(shader.mvMatrixLocation,
false,
this.mvMatrix);

gl.uniform1i(shader.textureLocation, 0);

gl.uniform2f(shader.resolutionLocation, canvasWidth, canvasHeight);
gl.uniform2f(shader.uvMaxLocation, 1.0, 1.0);
gl.uniform2f(shader.warp2, curvature, curvature);

// todo: why is it this.glVertexBuffer for both render to texture and render to screen?
const glVertexBuffer = this.glVertexBuffer;
const glTextureBuffer = this.glTextureBuffer;

const bytesin32bit = 4;

const vertexItemSize = 2;
const textureItemSize = 2;
const totalSize = (vertexItemSize + textureItemSize);

const gbuf = memorySubArray(memoryF32, geo_ptr, geo_len);

gl.bindBuffer(gl.ARRAY_BUFFER, glVertexBuffer);
gl.bufferData(gl.ARRAY_BUFFER, gbuf, gl.STATIC_DRAW);
gl.vertexAttribPointer(shader.positionLocation,
vertexItemSize,
gl.FLOAT, false, totalSize * bytesin32bit,
0 * bytesin32bit);

gl.bindBuffer(gl.ARRAY_BUFFER, glTextureBuffer);
gl.bufferData(gl.ARRAY_BUFFER, gbuf, gl.STATIC_DRAW);
gl.vertexAttribPointer(shader.texCoordLocation,
textureItemSize,
gl.FLOAT, false, totalSize * bytesin32bit,
(vertexItemSize) * bytesin32bit);

gl.drawArrays(gl.TRIANGLE_STRIP, 0, geo_len / totalSize);
}
}

// import { Howl, Howler } from "howler";

class Audio {
constructor(config) {
this.loadedAudioTracks = false;
}

loadAudioTracks(bridge) {
this.track_info = {};

const num_audio_tracks = bridge.get_num_audio_tracks();

for (let i = 0; i < num_audio_tracks; i++) {
const audio_track_id = bridge.get_audio_track_id(i);
const audio_track_path = bridge.get_audio_track_path(i);

this.track_info[audio_track_id] = new Howl({
src: [audio_track_path]
});

}

this.loadedAudioTracks = true;
}

play(track_id) {
if (!this.loadedAudioTracks) {
console.error('Audio.js: Audio.play called before tracks have been loaded');
return;
}

const track = this.track_info[track_id];
if (track) {
track.play();
} else {
console.error(`unknown track_id: ${track_id}`);
}
}

volume(amount) {
// volume is in range 0..1
Howler.volume(amount);
}
}

class Metric {
constructor(maxSamples) {
this.maxSamples = maxSamples;
// the active counters
this.active = {};

this.measurement = {};
}

start(label) {
this.active[label] = performance.now();
}

stop(label) {
const start = this.active[label];
if (!start) {
console.error(`stop called on ${label} without a start`);
return;
}

const finish = performance.now();
const duration = finish - start;

this.add_measurement(label, duration);
}

add_measurement(label, duration) {
const measurement = this.measurement[label];
if (!measurement) {
this.measurement[label] = new Measurement(label, this.maxSamples);
}
this.measurement[label].add(duration);
}

report_all() {
let labels = Object.keys(this.measurement);
labels.forEach(label => this.measurement[label].report());
console.log("");
}
}

class Measurement {
constructor(label, maxSamples) {
this.label = label;
this.maxSamples = maxSamples;
this.samples = [];

this.all_sum = 0;
this.all_samples = 0;
}

add(duration) {

this.all_sum += duration;
this.all_samples++;

if (this.samples.length >= this.maxSamples) {
this.samples.shift();
}
this.samples.push(duration);
}

all_average() {
return this.all_sum / this.all_samples;
}

rolling_average() {
if (this.samples.length === 0) {
return 0;
}
const sum = this.samples.reduce((a, b) => a + b, 0);
return sum / this.samples.length;
}

report() {
console.log(`${this.label}: ${this.rolling_average()}ms (${this.samples.length})`);
// console.log(`${this.label}: ${this.rolling_average()} (${this.samples.length}) ${this.all_average()} (${this.all_samples})`);
}
}

let gState = {
canvasId: 'render-canvas',
@@ -199,4 +832,14 @@ function main() {
// gState.bridge.free();
}

main();
document.addEventListener('DOMContentLoaded', () => {
wasm_bindgen('./sokoban_client_bg.wasm')
.then(() => {
// hack to access the memory
// the build.sh has a sed command to export the wasm object
// replace the js renderer with a rust implmentation to get rid of this hack
memory = wasm_bindgen.wasm.memory;
main();
})
.catch(console.error);
});

+ 0
- 44
client/www/js/Audio.js View File

@@ -1,44 +0,0 @@
import { Howl, Howler } from "howler";

export class Audio {
constructor(config) {
this.loadedAudioTracks = false;
}

loadAudioTracks(bridge) {
this.track_info = {};

const num_audio_tracks = bridge.get_num_audio_tracks();

for (let i = 0; i < num_audio_tracks; i++) {
const audio_track_id = bridge.get_audio_track_id(i);
const audio_track_path = bridge.get_audio_track_path(i);

this.track_info[audio_track_id] = new Howl({
src: [audio_track_path]
});

}

this.loadedAudioTracks = true;
}

play(track_id) {
if (!this.loadedAudioTracks) {
console.error('Audio.js: Audio.play called before tracks have been loaded');
return;
}

const track = this.track_info[track_id];
if (track) {
track.play();
} else {
console.error(`unknown track_id: ${track_id}`);
}
}

volume(amount) {
// volume is in range 0..1
Howler.volume(amount);
}
}

+ 0
- 466
client/www/js/GLRenderer.js View File

@@ -1,466 +0,0 @@
import Matrix from './Matrix';

const logToConsole = false;

function memorySubArray(mem, ptr, length) {
const nByte = 4;
const pos = ptr / nByte;
return mem.subarray(pos, pos + length);
}

function initGL(canvas) {
try {
const gl = canvas.getContext('experimental-webgl', {
alpha: false,
preserveDrawingBuffer: true
});

if (!gl) {
alert('Could not initialise WebGL, sorry :-(');
}

return gl;
} catch (e) {
return undefined;
}
}

function compileShader(gl, type, src) {
const shader = gl.createShader(type);
gl.shaderSource(shader, src);
gl.compileShader(shader);

if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
let lastError = gl.getShaderInfoLog(shader);
console.log(`Error compiling shader ${shader} : ${lastError}`);
gl.deleteShader(shader);
return null;
}
return shader;
}

function setupInGameShader(gl) {
const shader = {};

shader.program = gl.createProgram();

const fragmentSrc = `
precision mediump float;
varying vec4 vColor;
varying highp vec2 vTextureCoord;

uniform sampler2D uSampler;

void main(void) {
vec4 tex = texture2D(uSampler, vTextureCoord);

gl_FragColor.r = tex.r * vColor.a * vColor.r;
gl_FragColor.g = tex.g * vColor.a * vColor.g;
gl_FragColor.b = tex.b * vColor.a * vColor.b;
gl_FragColor.a = tex.a * vColor.a;

}
`;

const vertexSrc = `
attribute vec2 aVertexPosition;
attribute vec4 aVertexColor;
attribute vec2 aVertexTexture;

uniform mat4 uMVMatrix;
uniform mat4 uPMatrix;

varying vec4 vColor;
varying highp vec2 vTextureCoord;

void main(void) {
gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 0.0, 1.0);
vColor = aVertexColor;
vTextureCoord = aVertexTexture;
}
`;

const vertexShader = compileShader(gl, gl.VERTEX_SHADER, vertexSrc);
const fragmentShader = compileShader(gl, gl.FRAGMENT_SHADER, fragmentSrc);

gl.attachShader(shader.program, vertexShader);
gl.attachShader(shader.program, fragmentShader);

gl.linkProgram(shader.program);

if (!gl.getProgramParameter(shader.program, gl.LINK_STATUS)) {
let lastError = gl.getProgramInfoLog(shader.program);

alert(`Could not initialise shaders: ${lastError}`);;
gl.deleteProgram(shader.program);
return null;
}

shader.positionLocation = gl.getAttribLocation(shader.program, 'aVertexPosition');
shader.colourLocation = gl.getAttribLocation(shader.program, 'aVertexColor');
shader.texCoordLocation = gl.getAttribLocation(shader.program, 'aVertexTexture');

shader.pMatrixLocation = gl.getUniformLocation(shader.program, 'uPMatrix');
shader.mvMatrixLocation = gl.getUniformLocation(shader.program, 'uMVMatrix');
shader.textureLocation = gl.getUniformLocation(shader.program, 'uSampler');

return shader;
}

function setupCRTShader(gl) {
const shader = {};

shader.program = gl.createProgram();

const fragmentSrc = `
precision highp float;
varying vec2 tex_coord;

uniform sampler2D texture;
uniform vec2 res;
uniform vec2 uv_max;
uniform vec2 warp2;

// Amount of shadow mask.
float maskDark=0.7;
float maskLight=1.4;

// Distortion of scanlines, and end of screen alpha.
vec2 Warp(vec2 pos) {
pos = pos * 2.0 - 1.0;
pos *= vec2(1.0 + (pos.y * pos.y) * warp2.x, 1.0 + (pos.x * pos.x) * warp2.y);
return pos * 0.5 + 0.5;
}

// Shadow mask.
vec3 Mask(vec2 pos) {
pos.x += pos.y * 3.0;
vec3 mask = vec3(maskDark, maskDark, maskDark);
pos.x = fract(pos.x / 6.0);
if (pos.x < 0.333) mask.r = maskLight;
else if(pos.x < 0.666) mask.g=maskLight;
else mask.b = maskLight;
return mask;
}

void main(void) {
vec2 normalised_tex_coord = tex_coord / uv_max;
vec2 pos=Warp(normalised_tex_coord);
pos *= uv_max;
vec4 tex = texture2D(texture, pos);

vec2 pixel = res * pos;
gl_FragColor.rgb=tex.rgb;// * Mask(pixel.xy);
gl_FragColor.a = 1.0;
}
`;

const vertexSrc = `
attribute vec2 v_pos;
attribute vec2 v_tex_coord;

uniform mat4 m_mv;
uniform mat4 m_p;

varying highp vec2 tex_coord;

void main(void) {
gl_Position = m_p * m_mv * vec4(v_pos, 0.0, 1.0);
tex_coord = v_tex_coord;
}
`;

const vertexShader = compileShader(gl, gl.VERTEX_SHADER, vertexSrc);
const fragmentShader = compileShader(gl, gl.FRAGMENT_SHADER, fragmentSrc);

gl.attachShader(shader.program, vertexShader);
gl.attachShader(shader.program, fragmentShader);

gl.linkProgram(shader.program);

if (!gl.getProgramParameter(shader.program, gl.LINK_STATUS)) {
let lastError = gl.getProgramInfoLog(shader.program);

alert(`Could not initialise shaders: ${lastError}`);;
gl.deleteProgram(shader.program);
return null;
}

shader.positionLocation = gl.getAttribLocation(shader.program, 'v_pos');
shader.texCoordLocation = gl.getAttribLocation(shader.program, 'v_tex_coord');

shader.pMatrixLocation = gl.getUniformLocation(shader.program, 'm_p');
shader.mvMatrixLocation = gl.getUniformLocation(shader.program, 'm_mv');

shader.textureLocation = gl.getUniformLocation(shader.program, 'texture');

shader.resolutionLocation = gl.getUniformLocation(shader.program, 'res');
shader.uvMaxLocation = gl.getUniformLocation(shader.program, 'uv_max');
shader.warp2 = gl.getUniformLocation(shader.program, 'warp2');

return shader;
}

function setupGLState(gl) {
gl.clearColor(0.0, 0.0, 0.0, 0.0);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
gl.enable(gl.BLEND);

// assuming that we'll be using pre-multiplied alpha
// see http://www.realtimerendering.com/blog/gpus-prefer-premultiplication/
gl.blendEquation(gl.FUNC_ADD);
gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);

// gl.disable(gl.DEPTH_TEST);
}

function createRenderTexture(gl, config) {
// create to render to
const targetTextureWidth = config.render_texture_width;
const targetTextureHeight = config.render_texture_height;

const targetTexture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, targetTexture);

// define size and format of level 0
const level = 0;
const internalFormat = gl.RGBA;
const border = 0;
const format = gl.RGBA;
const type = gl.UNSIGNED_BYTE;
const data = null;
gl.texImage2D(gl.TEXTURE_2D, level, internalFormat,
targetTextureWidth, targetTextureHeight, border,
format, type, data);

gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
// gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
// gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);

return targetTexture;
}

function createFrameBuffer(gl, targetTexture) {
// Create and bind the framebuffer
const fb = gl.createFramebuffer();
gl.bindFramebuffer(gl.FRAMEBUFFER, fb);

// attach the texture as the first color attachment
const attachmentPoint = gl.COLOR_ATTACHMENT0;
const level = 0;
gl.framebufferTexture2D(gl.FRAMEBUFFER, attachmentPoint, gl.TEXTURE_2D, targetTexture, level);

return fb;
}

function checkFramebufferStatus(gl) {
let res = gl.checkFramebufferStatus(gl.FRAMEBUFFER);
switch(res) {
case gl.FRAMEBUFFER_COMPLETE: console.log("gl.FRAMEBUFFER_COMPLETE"); break;
case gl.FRAMEBUFFER_INCOMPLETE_ATTACHMENT: console.log("gl.FRAMEBUFFER_INCOMPLETE_ATTACHMENT"); break;
case gl.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: console.log("gl.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT"); break;
case gl.FRAMEBUFFER_INCOMPLETE_DIMENSIONS: console.log("gl.FRAMEBUFFER_INCOMPLETE_DIMENSIONS"); break;
case gl.FRAMEBUFFER_UNSUPPORTED: console.log("gl.FRAMEBUFFER_UNSUPPORTED"); break;
case gl.FRAMEBUFFER_INCOMPLETE_MULTISAMPLE: console.log("gl.FRAMEBUFFER_INCOMPLETE_MULTISAMPLE"); break;
case gl.RENDERBUFFER_SAMPLES: console.log("gl.RENDERBUFFER_SAMPLE"); break;
}
}

export class GLRenderer {
constructor(config, canvasElement) {
this.glDomElement = canvasElement;

// webgl setup
const gl = initGL(this.glDomElement);
this.gl = gl;

this.inGameShader = setupInGameShader(gl);
this.crtShader = setupCRTShader(gl);

setupGLState(gl);

this.glVertexBuffer = gl.createBuffer();
this.glColourBuffer = gl.createBuffer();
this.glTextureBuffer = gl.createBuffer();

this.mvMatrix = Matrix.create();
this.pMatrix = Matrix.create();
// Matrix.ortho(this.pMatrix, 0, config.canvas_width, 0, config.canvas_height, 10, -10);

this.tilesetTexture = this.gl.createTexture();
this.renderTexture = createRenderTexture(gl, config);
this.framebuffer = createFrameBuffer(gl, this.renderTexture);

// render to the canvas
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
}

loadTileset(src) {
let gl = this.gl;
let tex = this.tilesetTexture;

return new Promise(function(resolve, reject) {
const image = new Image();

image.addEventListener('load', () => {
gl.bindTexture(gl.TEXTURE_2D, tex);
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);

gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);

resolve([image.width, image.height]);
});

image.addEventListener('error', () => {
reject();
});

image.src = src;
});
}

renderGeometryToTexture(destTextureWidth, destTextureHeight, memoryF32, geo_len, geo_ptr) {
const gl = this.gl;

let shader = this.inGameShader;

// render to texture attached to framebuffer

gl.bindFramebuffer(gl.FRAMEBUFFER, this.framebuffer);
// gl.bindFramebuffer(gl.FRAMEBUFFER, null);

gl.bindTexture(gl.TEXTURE_2D, this.tilesetTexture);
gl.viewport(0, 0, destTextureWidth, destTextureHeight);

gl.useProgram(shader.program);

gl.enableVertexAttribArray(shader.positionLocation);
gl.enableVertexAttribArray(shader.colourLocation);
gl.enableVertexAttribArray(shader.texCoordLocation);

// gl.clearColor(0.0, 0.0, 1.0, 1.0);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);


// render the entirety of the scene
Matrix.ortho(this.pMatrix, 0, destTextureWidth, 0, destTextureHeight, 10, -10);

gl.uniformMatrix4fv(shader.pMatrixLocation,
false,
this.pMatrix);

gl.uniformMatrix4fv(shader.mvMatrixLocation,
false,
this.mvMatrix);

gl.uniform1i(shader.textureLocation, 0);


const glVertexBuffer = this.glVertexBuffer;
const glColourBuffer = this.glColourBuffer;
const glTextureBuffer = this.glTextureBuffer;

const bytesin32bit = 4;

const vertexItemSize = 2;
const colourItemSize = 4;
const textureItemSize = 2;
const totalSize = (vertexItemSize + colourItemSize + textureItemSize);

const gbuf = memorySubArray(memoryF32, geo_ptr, geo_len);

gl.bindBuffer(gl.ARRAY_BUFFER, glVertexBuffer);
gl.bufferData(gl.ARRAY_BUFFER, gbuf, gl.STATIC_DRAW);
gl.vertexAttribPointer(shader.positionLocation,
vertexItemSize,
gl.FLOAT, false, totalSize * bytesin32bit,
0 * bytesin32bit);

gl.bindBuffer(gl.ARRAY_BUFFER, glColourBuffer);
gl.bufferData(gl.ARRAY_BUFFER, gbuf, gl.STATIC_DRAW);
gl.vertexAttribPointer(shader.colourLocation,
colourItemSize,
gl.FLOAT, false, totalSize * bytesin32bit,
vertexItemSize * bytesin32bit);

gl.bindBuffer(gl.ARRAY_BUFFER, glTextureBuffer);
gl.bufferData(gl.ARRAY_BUFFER, gbuf, gl.STATIC_DRAW);
gl.vertexAttribPointer(shader.texCoordLocation,
textureItemSize,
gl.FLOAT, false, totalSize * bytesin32bit,
(vertexItemSize + colourItemSize) * bytesin32bit);

gl.drawArrays(gl.TRIANGLE_STRIP, 0, geo_len / totalSize);
}

renderTextureToScreen(canvasWidth, canvasHeight, memoryF32, geo_len, geo_ptr, curvature) {
const gl = this.gl;

let shader = this.crtShader;
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
gl.bindTexture(gl.TEXTURE_2D, this.renderTexture);
gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);

gl.useProgram(shader.program);

gl.enableVertexAttribArray(shader.positionLocation);
gl.enableVertexAttribArray(shader.texCoordLocation);

// gl.clearColor(0.0, 0.0, 1.0, 1.0);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);

// render the entirety of the scene
Matrix.ortho(this.pMatrix, 0, canvasWidth, 0, canvasHeight, 10, -10);

// add some uniforms for canvas width and height

gl.uniformMatrix4fv(shader.pMatrixLocation,
false,
this.pMatrix);

gl.uniformMatrix4fv(shader.mvMatrixLocation,
false,
this.mvMatrix);

gl.uniform1i(shader.textureLocation, 0);

gl.uniform2f(shader.resolutionLocation, canvasWidth, canvasHeight);
gl.uniform2f(shader.uvMaxLocation, 1.0, 1.0);
gl.uniform2f(shader.warp2, curvature, curvature);

// todo: why is it this.glVertexBuffer for both render to texture and render to screen?
const glVertexBuffer = this.glVertexBuffer;
const glTextureBuffer = this.glTextureBuffer;

const bytesin32bit = 4;

const vertexItemSize = 2;
const textureItemSize = 2;
const totalSize = (vertexItemSize + textureItemSize);

const gbuf = memorySubArray(memoryF32, geo_ptr, geo_len);

gl.bindBuffer(gl.ARRAY_BUFFER, glVertexBuffer);
gl.bufferData(gl.ARRAY_BUFFER, gbuf, gl.STATIC_DRAW);
gl.vertexAttribPointer(shader.positionLocation,
vertexItemSize,
gl.FLOAT, false, totalSize * bytesin32bit,
0 * bytesin32bit);

gl.bindBuffer(gl.ARRAY_BUFFER, glTextureBuffer);
gl.bufferData(gl.ARRAY_BUFFER, gbuf, gl.STATIC_DRAW);
gl.vertexAttribPointer(shader.texCoordLocation,
textureItemSize,
gl.FLOAT, false, totalSize * bytesin32bit,
(vertexItemSize) * bytesin32bit);

gl.drawArrays(gl.TRIANGLE_STRIP, 0, geo_len / totalSize);
}
}

+ 0
- 259
client/www/js/Matrix.js View File

@@ -1,259 +0,0 @@
/**
* Code taken from gl-matrix (http://glmatrix.net/)

Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
**/

function create() {
const out = new Float32Array(16);
out[0] = 1;
out[1] = 0;
out[2] = 0;
out[3] = 0;
out[4] = 0;
out[5] = 1;
out[6] = 0;
out[7] = 0;
out[8] = 0;
out[9] = 0;
out[10] = 1;
out[11] = 0;
out[12] = 0;
out[13] = 0;
out[14] = 0;
out[15] = 1;

return out;
}

function identity(out) {
out[0] = 1;
out[1] = 0;
out[2] = 0;
out[3] = 0;
out[4] = 0;
out[5] = 1;
out[6] = 0;
out[7] = 0;
out[8] = 0;
out[9] = 0;
out[10] = 1;
out[11] = 0;
out[12] = 0;
out[13] = 0;
out[14] = 0;
out[15] = 1;

return out;
}

function ortho(out, left, right, bottom, top, near, far) {
const lr = 1 / (left - right);
const bt = 1 / (bottom - top);
const nf = 1 / (near - far);

out[0] = -2 * lr;
out[1] = 0;
out[2] = 0;
out[3] = 0;
out[4] = 0;
out[5] = -2 * bt;
out[6] = 0;
out[7] = 0;
out[8] = 0;
out[9] = 0;
out[10] = 2 * nf;
out[11] = 0;
out[12] = (left + right) * lr;
out[13] = (top + bottom) * bt;
out[14] = (far + near) * nf;
out[15] = 1;

return out;
}

function clone(a) {
const out = new Float32Array(16);
out[0] = a[0];
out[1] = a[1];
out[2] = a[2];
out[3] = a[3];
out[4] = a[4];
out[5] = a[5];
out[6] = a[6];
out[7] = a[7];
out[8] = a[8];
out[9] = a[9];
out[10] = a[10];
out[11] = a[11];
out[12] = a[12];
out[13] = a[13];
out[14] = a[14];
out[15] = a[15];

return out;
}

function scale(out, a, v) {
const x = v[0], y = v[1], z = v[2];

out[0] = a[0] * x;
out[1] = a[1] * x;
out[2] = a[2] * x;
out[3] = a[3] * x;
out[4] = a[4] * y;
out[5] = a[5] * y;
out[6] = a[6] * y;
out[7] = a[7] * y;
out[8] = a[8] * z;
out[9] = a[9] * z;
out[10] = a[10] * z;
out[11] = a[11] * z;
out[12] = a[12];
out[13] = a[13];
out[14] = a[14];
out[15] = a[15];

return out;
}

function multiply(out, a, b) {
const a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3];
const a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7];
const a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11];
const a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15];

// Cache only the current line of the second matrix
const b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3];
out[0] = b0*a00 + b1*a10 + b2*a20 + b3*a30;
out[1] = b0*a01 + b1*a11 + b2*a21 + b3*a31;
out[2] = b0*a02 + b1*a12 + b2*a22 + b3*a32;
out[3] = b0*a03 + b1*a13 + b2*a23 + b3*a33;

b0 = b[4]; b1 = b[5]; b2 = b[6]; b3 = b[7];
out[4] = b0*a00 + b1*a10 + b2*a20 + b3*a30;
out[5] = b0*a01 + b1*a11 + b2*a21 + b3*a31;
out[6] = b0*a02 + b1*a12 + b2*a22 + b3*a32;
out[7] = b0*a03 + b1*a13 + b2*a23 + b3*a33;

b0 = b[8]; b1 = b[9]; b2 = b[10]; b3 = b[11];
out[8] = b0*a00 + b1*a10 + b2*a20 + b3*a30;
out[9] = b0*a01 + b1*a11 + b2*a21 + b3*a31;
out[10] = b0*a02 + b1*a12 + b2*a22 + b3*a32;
out[11] = b0*a03 + b1*a13 + b2*a23 + b3*a33;

b0 = b[12]; b1 = b[13]; b2 = b[14]; b3 = b[15];
out[12] = b0*a00 + b1*a10 + b2*a20 + b3*a30;
out[13] = b0*a01 + b1*a11 + b2*a21 + b3*a31;
out[14] = b0*a02 + b1*a12 + b2*a22 + b3*a32;
out[15] = b0*a03 + b1*a13 + b2*a23 + b3*a33;

return out;
}

function translate(out, a, v) {
const x = v[0], y = v[1], z = v[2];
// let a00, a01, a02, a03, a10, a11, a12, a13, a20, a21, a22, a23;

if (a === out) {
out[12] = a[0] * x + a[4] * y + a[8] * z + a[12];
out[13] = a[1] * x + a[5] * y + a[9] * z + a[13];
out[14] = a[2] * x + a[6] * y + a[10] * z + a[14];
out[15] = a[3] * x + a[7] * y + a[11] * z + a[15];
} else {
const a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3];
const a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7];
const a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11];

out[0] = a00; out[1] = a01; out[2] = a02; out[3] = a03;
out[4] = a10; out[5] = a11; out[6] = a12; out[7] = a13;
out[8] = a20; out[9] = a21; out[10] = a22; out[11] = a23;

out[12] = a00 * x + a10 * y + a20 * z + a[12];
out[13] = a01 * x + a11 * y + a21 * z + a[13];
out[14] = a02 * x + a12 * y + a22 * z + a[14];
out[15] = a03 * x + a13 * y + a23 * z + a[15];
}

return out;
}

function rotateZ(out, a, rad) {
const s = Math.sin(rad), c = Math.cos(rad);
const a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3];
const a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7];

if (a !== out) {
out[8] = a[8];
out[9] = a[9];
out[10] = a[10];
out[11] = a[11];
out[12] = a[12];
out[13] = a[13];
out[14] = a[14];
out[15] = a[15];
}

// Perform axis-specific matrix multiplication
out[0] = a00 * c + a10 * s;
out[1] = a01 * c + a11 * s;
out[2] = a02 * c + a12 * s;
out[3] = a03 * c + a13 * s;
out[4] = a10 * c - a00 * s;
out[5] = a11 * c - a01 * s;
out[6] = a12 * c - a02 * s;
out[7] = a13 * c - a03 * s;

return out;
}

function transformVec2(out, a, m) {
const x = a[0];
const y = a[1];
out[0] = m[0] * x + m[4] * y + m[12];
out[1] = m[1] * x + m[5] * y + m[13];

return out;
}

function transformVec3(out, a, m) {
const x = a[0], y = a[1], z = a[2];
let w = m[3] * x + m[7] * y + m[11] * z + m[15];
w = w || 1.0;
out[0] = (m[0] * x + m[4] * y + m[8] * z + m[12]) / w;
out[1] = (m[1] * x + m[5] * y + m[9] * z + m[13]) / w;
out[2] = (m[2] * x + m[6] * y + m[10] * z + m[14]) / w;

return out;
}

export default {
create,
identity,
ortho,
clone,
scale,
multiply,
translate,
rotateZ,
transformVec2,
transformVec3
};

+ 0
- 81
client/www/js/Metric.js View File

@@ -1,81 +0,0 @@


export class Metric {
constructor(maxSamples) {
this.maxSamples = maxSamples;
// the active counters
this.active = {};

this.measurement = {};
}

start(label) {
this.active[label] = performance.now();
}

stop(label) {
const start = this.active[label];
if (!start) {
console.error(`stop called on ${label} without a start`);
return;
}

const finish = performance.now();
const duration = finish - start;

this.add_measurement(label, duration);
}

add_measurement(label, duration) {
const measurement = this.measurement[label];
if (!measurement) {
this.measurement[label] = new Measurement(label, this.maxSamples);
}
this.measurement[label].add(duration);
}

report_all() {
let labels = Object.keys(this.measurement);
labels.forEach(label => this.measurement[label].report());
console.log("");
}
}

class Measurement {
constructor(label, maxSamples) {
this.label = label;
this.maxSamples = maxSamples;
this.samples = [];

this.all_sum = 0;
this.all_samples = 0;
}

add(duration) {

this.all_sum += duration;
this.all_samples++;

if (this.samples.length >= this.maxSamples) {
this.samples.shift();
}
this.samples.push(duration);
}

all_average() {
return this.all_sum / this.all_samples;
}

rolling_average() {
if (this.samples.length === 0) {
return 0;
}
const sum = this.samples.reduce((a, b) => a + b, 0);
return sum / this.samples.length;
}

report() {
console.log(`${this.label}: ${this.rolling_average()}ms (${this.samples.length})`);
// console.log(`${this.label}: ${this.rolling_average()} (${this.samples.length}) ${this.all_average()} (${this.all_samples})`);
}
}

+ 0
- 5393
client/www/package-lock.json
File diff suppressed because it is too large
View File


+ 0
- 27
client/www/package.json View File

@@ -1,27 +0,0 @@
{
"name": "sokoban-client-www",
"version": "0.1.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "webpack --config webpack.config.js",
"start": "webpack-dev-server"
},
"keywords": [
"webassembly",
"wasm",
"rust",
"webpack"
],
"author": "Inderjit Gill <email@indy.io>",
"license": "(MIT OR Apache-2.0)",
"devDependencies": {
"webpack": "^4.16.3",
"webpack-cli": "^3.1.0",
"webpack-dev-server": "^3.1.5",
"copy-webpack-plugin": "^4.5.2"
},
"dependencies": {
"howler": "2.0.14"
}
}

+ 0
- 2
client/www/wasm/.gitignore View File

@@ -1,2 +0,0 @@
*
!.gitignore

+ 0
- 14
client/www/webpack.config.js View File

@@ -1,14 +0,0 @@
const CopyWebpackPlugin = require("copy-webpack-plugin");
const path = require('path');

module.exports = {
entry: "./bootstrap.js",
output: {
path: path.resolve(__dirname, "dist"),
filename: "bootstrap.js",
},
mode: "development",
plugins: [
new CopyWebpackPlugin(['index.html'])
],
};

Loading…
Cancel
Save