Browse Source

removing npm junk

master
Inderjit Gill 8 months ago
parent
commit
41be4ab7e7
27 changed files with 3345 additions and 6769 deletions
  1. +2
    -6
      .gitignore
  2. +0
    -268
      Cargo.lock
  3. +0
    -13
      benches/bench.rs
  4. +10
    -0
      build.sh
  5. +0
    -26
      index.html
  6. +0
    -5885
      package-lock.json
  7. +0
    -19
      package.json
  8. +0
    -41
      serve.go
  9. +0
    -54
      web/js/Audio.js
  10. +0
    -259
      web/js/Matrix.js
  11. +0
    -4
      web/js/bootstrap.js
  12. +0
    -179
      web/js/index.js
  13. +0
    -13
      webpack.config.js
  14. BIN
      www/favicon.ico
  15. +3003
    -0
      www/howler.js
  16. +0
    -0
      www/img/tileset.png
  17. +46
    -0
      www/index.html
  18. +284
    -2
      www/index.js
  19. +0
    -0
      www/sfx/fanfare1.mp3
  20. +0
    -0
      www/sfx/impact1.mp3
  21. +0
    -0
      www/sfx/menu_move4.mp3
  22. +0
    -0
      www/sfx/negative1.mp3
  23. +0
    -0
      www/sfx/pause2_in.mp3
  24. +0
    -0
      www/sfx/pause2_out.mp3
  25. +0
    -0
      www/sfx/powerup16.mp3
  26. +0
    -0
      www/sfx/powerup18.mp3
  27. +0
    -0
      www/sfx/powerup9.mp3

+ 2
- 6
.gitignore View File

@@ -1,9 +1,5 @@
/dist
/target
**/*.rs.bk
xxxCargo.lock

/node_modules/
/web/wasm_tetris*

serve.exe
serve
/www/wasm_tetris*

+ 0
- 268
Cargo.lock View File

@@ -1,268 +0,0 @@
[[package]]
name = "backtrace"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"backtrace-sys 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.42 (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.5 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "backtrace-sys"
version = "0.1.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cc 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)",
]

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

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

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

[[package]]
name = "failure"
version = "0.1.2"
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)",
]

[[package]]
name = "failure_derive"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.14.5 (registry+https://github.com/rust-lang/crates.io-index)",
"synstructure 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
]

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

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

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

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

[[package]]
name = "proc-macro2"
version = "0.4.9"
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)",
]

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

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

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

[[package]]
name = "serde_derive"
version = "1.0.70"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.14.5 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "serde_json"
version = "1.0.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"dtoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
"itoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "syn"
version = "0.14.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.4 (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"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.14.5 (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 = "unicode-xid"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"

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

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

[[package]]
name = "wasm-bindgen-backend"
version = "0.2.17"
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.3 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.14.5 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-shared 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)",
]

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

[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.14.5 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-backend 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-shared 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "wasm-bindgen-shared"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"serde 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "wasm_tetris"
version = "0.1.0"
dependencies = [
"failure 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "winapi"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"

[metadata]
"checksum backtrace 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "89a47830402e9981c5c41223151efcced65a0510c13097c769cede7efb34782a"
"checksum backtrace-sys 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)" = "bff67d0c06556c0b8e6b5f090f0eac52d950d9dfd1d35ba04e4ca3543eaf6a7e"
"checksum cc 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)" = "2119ea4867bd2b8ed3aecab467709720b2d55b1bcfe09f772fd68066eaf15275"
"checksum cfg-if 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "efe5c877e17a9c717a0bf3613b2709f723202c4e4675cc8f12926ded29bcb17e"
"checksum dtoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6d301140eb411af13d3115f9a562c85cc6b541ade9dfa314132244aaee7489dd"
"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 itoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5adb58558dcd1d786b5f0bd15f3226ee23486e24b7b58304b60f64dc68e62606"
"checksum lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca488b89a5657b0a2ecd45b95609b3e848cf1755da332a0da46e2b2b1cb371a7"
"checksum libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)" = "b685088df2b950fccadf07a7187c8ef846a959c142338a48f9dc0b94517eb5f1"
"checksum log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "61bd98ae7f7b754bc53dca7d44b604f733c6bba044ea6f41bc8d89272d8161d2"
"checksum proc-macro2 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)" = "cccdc7557a98fe98453030f077df7f3a042052fae465bb61d2c2c41435cfd9b6"
"checksum quote 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b71f9f575d55555aa9c06188be9d4e2bfc83ed02537948ac0d520c24d0419f1a"
"checksum rustc-demangle 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "bcfe5b13211b4d78e5c2cadfebd7769197d95c639c35a50057eb4c05de811395"
"checksum serde 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)" = "0c3adf19c07af6d186d91dae8927b83b0553d07ca56cbf7f2f32560455c91920"
"checksum serde_derive 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)" = "3525a779832b08693031b8ecfb0de81cd71cfd3812088fafe9a7496789572124"
"checksum serde_json 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)" = "c3c6908c7b925cd6c590358a4034de93dbddb20c45e1d021931459fd419bf0e2"
"checksum syn 0.14.5 (registry+https://github.com/rust-lang/crates.io-index)" = "4bad7abdf6633f07c7046b90484f1d9dc055eca39f8c991177b1046ce61dba9a"
"checksum synstructure 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "85bb9b7550d063ea184027c9b8c20ac167cd36d3e06b3a40bceb9d746dc1a7b7"
"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
"checksum version_check 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "7716c242968ee87e5542f8021178248f267f295a5c4803beae8b8b7fd9bc6051"
"checksum wasm-bindgen 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)" = "18435dd2cabae856f7ce0530798d1b9d0f9fe52f0948abb4b002d5d6042aa479"
"checksum wasm-bindgen-backend 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)" = "d86e94290104554e5e4b9030ed90623033707fb0275151325faff4e4953bcfee"
"checksum wasm-bindgen-macro 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)" = "e240c96a612f131b87a1925c15ba73ce9f71b7e443c42c8ec9c77cfdc06c58a1"
"checksum wasm-bindgen-macro-support 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)" = "40b6edde67171a5a8514243049e85593e4a776446fe952d9e1873b828e28ecc0"
"checksum wasm-bindgen-shared 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)" = "19647b4790a288a74d4a9911fbf6e66719a3eca36d2ea755412fe2cd615bec93"
"checksum winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "773ef9dcc5f24b7d850d0ff101e542ff24c3b090a9768e03ff889fdef41f00fd"
"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

+ 0
- 13
benches/bench.rs View File

@@ -1,13 +0,0 @@
#![feature(test)]

extern crate test;
extern crate wasm_tetris;

#[bench]
fn universe_ticks(b: &mut test::Bencher) {
let mut universe = wasm_game_of_life::Universe::new();

b.iter(|| {
universe.tick();
});
}

+ 10
- 0
build.sh View File

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

if [ "$1" = "release" ]
then
cargo build --release --target wasm32-unknown-unknown
wasm-bindgen target/wasm32-unknown-unknown/release/wasm_tetris.wasm --out-dir www --no-typescript --no-modules
else
cargo build --target wasm32-unknown-unknown
wasm-bindgen target/wasm32-unknown-unknown/debug/wasm_tetris.wasm --out-dir www --no-typescript --no-modules
fi

+ 0
- 26
index.html View File

@@ -1,26 +0,0 @@
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type"/>
<style>
body {
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-family: monospace;
white-space: pre;
background: #000;
}
#render-canvas {
background: #000;
padding: 0;
}
</style>
</head>
<body>
<canvas id="render-canvas"></canvas>
<script src='bootstrap.js'></script>
</body>
</html>

+ 0
- 5885
package-lock.json
File diff suppressed because it is too large
View File


+ 0
- 19
package.json View File

@@ -1,19 +0,0 @@
{
"scripts": {
"serve:dev": "webpack-dev-server",
"serve:release": "serve",
"build:dev": "webpack --mode=development --progress",
"build:dev:wasm": "cargo +nightly build --target wasm32-unknown-unknown && wasm-bindgen target/wasm32-unknown-unknown/debug/wasm_tetris.wasm --out-dir web",
"build:release": "cargo +nightly build --release --target wasm32-unknown-unknown && wasm-bindgen target/wasm32-unknown-unknown/release/wasm_tetris.wasm --out-dir web && webpack --mode=production --progress && cp index.html dist/index.html && mkdirp dist/web && cp -r web/img dist/web/img && cp -r web/sfx dist/web/sfx",
"build:server": "go build serve.go"
},
"devDependencies": {
"webpack": "4.16.1",
"webpack-cli": "3.1.0",
"webpack-dev-server": "3.1.4",
"mkdirp": "0.5.1"
},
"dependencies": {
"howler": "2.0.14"
}
}

+ 0
- 41
serve.go View File

@@ -1,41 +0,0 @@
package main

import (
"fmt"
"net/http"
"regexp"
)

/*
build this file once:
$ go build serve.go

build the release version with:
$ npm run build:release

serve everything from /dist with:
$ ./serve
*/

var wasmFile = regexp.MustCompile("\\.wasm$")

func maxAgeHandler(seconds int, h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Cache-Control", fmt.Sprintf("max-age=%d, public, must-revalidate, proxy-revalidate", seconds))

ruri := r.RequestURI
if wasmFile.MatchString(ruri) {
w.Header().Set("Content-Type", "application/wasm")
}

h.ServeHTTP(w, r)
})
}

func main() {
fs := http.FileServer(http.Dir("dist"))
http.Handle("/", maxAgeHandler(0, fs))

fmt.Printf("Serving localhost:3000\n")
http.ListenAndServe(":3000", nil)
}

+ 0
- 54
web/js/Audio.js View File

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

export class Audio {
constructor(config) {
this.impact = new Howl({
src: ['web/sfx/impact1.mp3']
});
this.game_over = new Howl({
src: ['web/sfx/negative1.mp3']
});
this.line1 = new Howl({
src: ['web/sfx/fanfare1.mp3']
});
this.line2 = new Howl({
src: ['web/sfx/powerup16.mp3']
});
this.line3 = new Howl({
src: ['web/sfx/powerup18.mp3']
});
this.line4 = new Howl({
src: ['web/sfx/powerup9.mp3']
});
this.pause_in = new Howl({
src: ['web/sfx/pause2_in.mp3']
});
this.pause_out = new Howl({
src: ['web/sfx/pause2_out.mp3']
});
this.menu_move = new Howl({
src: ['web/sfx/menu_move4.mp3']
});
}

play(label) {
// console.log(`audio: play ${label}`);
switch(label) {
case 1: this.impact.play(); break;
case 2: this.game_over.play(); break;
case 3: this.line1.play(); break;
case 4: this.line2.play(); break;
case 5: this.line3.play(); break;
case 6: this.line4.play(); break;
case 7: this.pause_in.play(); break;
case 8: this.pause_out.play(); break;
case 9: this.menu_move.play(); break;
default: console.error(`Audio: unable to play: ${label}`);
}
}

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

+ 0
- 259
web/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
- 4
web/js/bootstrap.js View File

@@ -1,4 +0,0 @@
const index = import("./index");
index.then(() => {
console.log("Loaded...");
});

+ 0
- 179
web/js/index.js View File

@@ -1,179 +0,0 @@
import { Bridge, Config } from "../wasm_tetris";
import { memory } from "../wasm_tetris_bg";
import { GLRenderer } from "./GLRenderer";
import { Audio } from "./Audio";

let gState = {
canvasId: 'render-canvas',

config: new Config(),

tileset: 'web/img/tileset.png',

bridge: undefined,
animationId: undefined,
renderer: undefined,
audio: undefined,

performanceNow: performance.now()
};

const tick = () => {
const now = performance.now();
const delta = now - gState.performanceNow;
gState.performanceNow = now;

const bridge = gState.bridge;

// game state + time + user input -> game state
const tickAgain = bridge.tick(delta, Math.random());

render();

if (tickAgain) {
gState.animationId = requestAnimationFrame(tick);
}
};

const render = () => {
const bridge = gState.bridge;
const renderer = gState.renderer;

// bridge state -> geometry
bridge.update_geometry();

// render geometry
const memoryF32 = new Float32Array(memory.buffer);

const geo_len = bridge.geo_len();
const geo_ptr = bridge.geo_ptr();
renderer.renderGeometryToTexture(gState.config.render_texture_width, gState.config.render_texture_height,
memoryF32, geo_len, geo_ptr);

// apply a CRT effect
const crt_len = bridge.crt_len();
const crt_ptr = bridge.crt_ptr();
const curvature = bridge.crt_curvature();
renderer.renderTextureToScreen(gState.config.canvas_width, gState.config.canvas_height,
memoryF32, crt_len, crt_ptr, curvature);
};

function reconfigure() {
gState.bridge.reconfigure(gState.config);
}

function audio_play(id) {
gState.audio.play(id);
}

function audio_volume(volume) {
gState.audio.volume(volume);
}

window.reconfigure = reconfigure;
window.config = gState.config;
window.audio_play = audio_play;
window.audio_volume = audio_volume;

function get_canvas_aspect_ratio(config) {

const block_width = config.render_texture_width / config.block_size;
const block_height = config.render_texture_height / config.block_size;

const max_u = (block_width * config.block_limit_x) / config.render_texture_width;
const max_v = (block_height * config.block_limit_y) / config.render_texture_height;

return max_u / max_v;
}

// maximise the canvas element within it's parent whilst retaining the required aspect ratio
//
function resize_canvas_element(canvasElement, config) {
const width = canvasElement.parentNode.parentElement.clientWidth;
const height = canvasElement.parentNode.parentElement.clientHeight;

const canvas_aspect_ratio = get_canvas_aspect_ratio(config);
config.canvas_width = height * canvas_aspect_ratio;
config.canvas_height = height;

if (config.canvas_width > width) {
// the window has been resized to a very narrow aspect ratio
// the constraining dimension is now the width, not height
config.canvas_width = width;
config.canvas_height = width / canvas_aspect_ratio;
}

canvasElement.width = config.canvas_width;
canvasElement.height = config.canvas_height;
}

function main() {
// - The game is rendered on a square rendertexture so that the gamecode can
// assume that we're working with square pixels.
// - The canvas will be rectangular and will only use the part of the
// rendertexture that actually contains the game.
// - To ensure that square pixels remain square, we have to make sure that
// the aspect ratio of the canvas is the same as the uv co-ordinates used
// in mapping the rendertexture onto the canvas
//

const canvasElement = document.getElementById(gState.canvasId);

resize_canvas_element(canvasElement, gState.config);

gState.audio = new Audio(config);

let renderer = new GLRenderer(gState.config, canvasElement);
renderer.loadTexture(gState.tileset).then(([tilesetWidth, tilesetHeight]) => {

gState.config.tileset_texture_width = tilesetWidth;
gState.config.tileset_texture_height = tilesetHeight;

gState.bridge = new Bridge(gState.config);

gState.renderer = renderer;

document.addEventListener('keydown', event => {
let key_event_return = gState.bridge.event_key_down(event.key);

if (key_event_return.prevent_default()) {
event.preventDefault();
}
if (key_event_return.call_tick()) {
tick();
}

key_event_return.free();
});

document.addEventListener('keyup', event => {
let key_event_return = gState.bridge.event_key_up(event.key);

if (key_event_return.prevent_default()) {
event.preventDefault();
}
if (key_event_return.call_tick()) {
tick();
}

key_event_return.free();
});

window.addEventListener("resize", () => {
resize_canvas_element(canvasElement, gState.config);
gState.bridge.event_resize(gState.config.canvas_width, gState.config.canvas_height);
render();

});

gState.bridge.init(Math.random());
tick();
}).catch(error => console.error(error));

// isg: NOTE: remember to free Bridge
// gState.bridge.free();
}



main();

+ 0
- 13
webpack.config.js View File

@@ -1,13 +0,0 @@
const path = require("path");

module.exports = {
entry: "./web/js/bootstrap.js",
output: {
path: path.resolve(__dirname, "dist"),
filename: "bootstrap.js",
},
optimization: {
minimize: false
},
mode: "development"
};

BIN
www/favicon.ico View File

Before After

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


web/img/tileset.png → www/img/tileset.png View File


+ 46
- 0
www/index.html View File

@@ -0,0 +1,46 @@
<!DOCTYPE html>
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type"/>
<style>
body {
width: 97%;
height: 97%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-family: monospace;
white-space: pre;
background: #333333;
}
#render-canvas {
background: #101010;
padding: 0;
}
</style>
</head>
<body>
<canvas id="render-canvas"></canvas>
<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='./wasm_tetris.js'></script>

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

web/js/GLRenderer.js → www/index.js View File

@@ -1,4 +1,52 @@
import Matrix from './Matrix';
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;

@@ -305,7 +353,7 @@ function checkFramebufferStatus(gl) {
}
}

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

@@ -500,3 +548,237 @@ export class GLRenderer {
gl.drawArrays(gl.TRIANGLE_STRIP, 0, geo_len / totalSize);
}
}

class Audio {
constructor(config) {
this.impact = new Howl({
src: ['sfx/impact1.mp3']
});
this.game_over = new Howl({
src: ['sfx/negative1.mp3']
});
this.line1 = new Howl({
src: ['sfx/fanfare1.mp3']
});
this.line2 = new Howl({
src: ['sfx/powerup16.mp3']
});
this.line3 = new Howl({
src: ['sfx/powerup18.mp3']
});
this.line4 = new Howl({
src: ['sfx/powerup9.mp3']
});
this.pause_in = new Howl({
src: ['sfx/pause2_in.mp3']
});
this.pause_out = new Howl({
src: ['sfx/pause2_out.mp3']
});
this.menu_move = new Howl({
src: ['sfx/menu_move4.mp3']
});
}

play(label) {
// console.log(`audio: play ${label}`);
switch(label) {
case 1: this.impact.play(); break;
case 2: this.game_over.play(); break;
case 3: this.line1.play(); break;
case 4: this.line2.play(); break;
case 5: this.line3.play(); break;
case 6: this.line4.play(); break;
case 7: this.pause_in.play(); break;
case 8: this.pause_out.play(); break;
case 9: this.menu_move.play(); break;
default: console.error(`Audio: unable to play: ${label}`);
}
}

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

let gState = {
canvasId: 'render-canvas',

config: new Config(),

tileset: 'img/tileset.png',

bridge: undefined,
animationId: undefined,
renderer: undefined,
audio: undefined,

performanceNow: performance.now()
};

const tick = () => {
const now = performance.now();
const delta = now - gState.performanceNow;
gState.performanceNow = now;

const bridge = gState.bridge;

// game state + time + user input -> game state
const tickAgain = bridge.tick(delta, Math.random());

render();

if (tickAgain) {
gState.animationId = requestAnimationFrame(tick);
}
};

const render = () => {
const bridge = gState.bridge;
const renderer = gState.renderer;

// bridge state -> geometry
bridge.update_geometry();

// render geometry
const memoryF32 = new Float32Array(memory.buffer);

const geo_len = bridge.geo_len();
const geo_ptr = bridge.geo_ptr();
renderer.renderGeometryToTexture(gState.config.render_texture_width, gState.config.render_texture_height,
memoryF32, geo_len, geo_ptr);

// apply a CRT effect
const crt_len = bridge.crt_len();
const crt_ptr = bridge.crt_ptr();
const curvature = bridge.crt_curvature();
renderer.renderTextureToScreen(gState.config.canvas_width, gState.config.canvas_height,
memoryF32, crt_len, crt_ptr, curvature);
};

function reconfigure() {
gState.bridge.reconfigure(gState.config);
}

function audio_play(id) {
gState.audio.play(id);
}

function audio_volume(volume) {
gState.audio.volume(volume);
}

window.reconfigure = reconfigure;
window.config = gState.config;
window.audio_play = audio_play;
window.audio_volume = audio_volume;

function get_canvas_aspect_ratio(config) {

const block_width = config.render_texture_width / config.block_size;
const block_height = config.render_texture_height / config.block_size;

const max_u = (block_width * config.block_limit_x) / config.render_texture_width;
const max_v = (block_height * config.block_limit_y) / config.render_texture_height;

return max_u / max_v;
}

// maximise the canvas element within it's parent whilst retaining the required aspect ratio
//
function resize_canvas_element(canvasElement, config) {
const width = canvasElement.parentNode.parentElement.clientWidth;
const height = canvasElement.parentNode.parentElement.clientHeight;

const canvas_aspect_ratio = get_canvas_aspect_ratio(config);
config.canvas_width = height * canvas_aspect_ratio;
config.canvas_height = height;

if (config.canvas_width > width) {
// the window has been resized to a very narrow aspect ratio
// the constraining dimension is now the width, not height
config.canvas_width = width;
config.canvas_height = width / canvas_aspect_ratio;
}

canvasElement.width = config.canvas_width;
canvasElement.height = config.canvas_height;
}

function main() {
// - The game is rendered on a square rendertexture so that the gamecode can
// assume that we're working with square pixels.
// - The canvas will be rectangular and will only use the part of the
// rendertexture that actually contains the game.
// - To ensure that square pixels remain square, we have to make sure that
// the aspect ratio of the canvas is the same as the uv co-ordinates used
// in mapping the rendertexture onto the canvas
//

const canvasElement = document.getElementById(gState.canvasId);

resize_canvas_element(canvasElement, gState.config);

gState.audio = new Audio(config);

let renderer = new GLRenderer(gState.config, canvasElement);
renderer.loadTexture(gState.tileset).then(([tilesetWidth, tilesetHeight]) => {

gState.config.tileset_texture_width = tilesetWidth;
gState.config.tileset_texture_height = tilesetHeight;

gState.bridge = new Bridge(gState.config);

gState.renderer = renderer;

document.addEventListener('keydown', event => {
let key_event_return = gState.bridge.event_key_down(event.key);

if (key_event_return.prevent_default()) {
event.preventDefault();
}
if (key_event_return.call_tick()) {
tick();
}

key_event_return.free();
});

document.addEventListener('keyup', event => {
let key_event_return = gState.bridge.event_key_up(event.key);

if (key_event_return.prevent_default()) {
event.preventDefault();
}
if (key_event_return.call_tick()) {
tick();
}

key_event_return.free();
});

window.addEventListener("resize", () => {
resize_canvas_element(canvasElement, gState.config);
gState.bridge.event_resize(gState.config.canvas_width, gState.config.canvas_height);
render();

});

gState.bridge.init(Math.random());
tick();
}).catch(error => console.error(error));

// isg: NOTE: remember to free Bridge
// gState.bridge.free();
}


document.addEventListener('DOMContentLoaded', () => {
wasm_bindgen('./wasm_tetris_bg.wasm')
.then(client_bg => {
memory = client_bg.memory;
main();
})
.catch(console.error);
});

web/sfx/fanfare1.mp3 → www/sfx/fanfare1.mp3 View File


web/sfx/impact1.mp3 → www/sfx/impact1.mp3 View File


web/sfx/menu_move4.mp3 → www/sfx/menu_move4.mp3 View File


web/sfx/negative1.mp3 → www/sfx/negative1.mp3 View File


web/sfx/pause2_in.mp3 → www/sfx/pause2_in.mp3 View File


web/sfx/pause2_out.mp3 → www/sfx/pause2_out.mp3 View File


web/sfx/powerup16.mp3 → www/sfx/powerup16.mp3 View File


web/sfx/powerup18.mp3 → www/sfx/powerup18.mp3 View File


web/sfx/powerup9.mp3 → www/sfx/powerup9.mp3 View File


Loading…
Cancel
Save