Browse Source

removing npm junk

Inderjit Gill 4 months ago
parent
commit
41be4ab7e7

+ 2
- 6
.gitignore View File

@@ -1,9 +1,5 @@
1
-/dist
2 1
 /target
3 2
 **/*.rs.bk
3
+xxxCargo.lock
4 4
 
5
-/node_modules/
6
-/web/wasm_tetris*
7
-
8
-serve.exe
9
-serve
5
+/www/wasm_tetris*

+ 0
- 268
Cargo.lock View File

@@ -1,268 +0,0 @@
1
-[[package]]
2
-name = "backtrace"
3
-version = "0.3.9"
4
-source = "registry+https://github.com/rust-lang/crates.io-index"
5
-dependencies = [
6
- "backtrace-sys 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)",
7
- "cfg-if 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
8
- "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)",
9
- "rustc-demangle 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
10
- "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
11
-]
12
-
13
-[[package]]
14
-name = "backtrace-sys"
15
-version = "0.1.23"
16
-source = "registry+https://github.com/rust-lang/crates.io-index"
17
-dependencies = [
18
- "cc 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)",
19
- "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)",
20
-]
21
-
22
-[[package]]
23
-name = "cc"
24
-version = "1.0.18"
25
-source = "registry+https://github.com/rust-lang/crates.io-index"
26
-
27
-[[package]]
28
-name = "cfg-if"
29
-version = "0.1.4"
30
-source = "registry+https://github.com/rust-lang/crates.io-index"
31
-
32
-[[package]]
33
-name = "dtoa"
34
-version = "0.4.3"
35
-source = "registry+https://github.com/rust-lang/crates.io-index"
36
-
37
-[[package]]
38
-name = "failure"
39
-version = "0.1.2"
40
-source = "registry+https://github.com/rust-lang/crates.io-index"
41
-dependencies = [
42
- "backtrace 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
43
- "failure_derive 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
44
-]
45
-
46
-[[package]]
47
-name = "failure_derive"
48
-version = "0.1.2"
49
-source = "registry+https://github.com/rust-lang/crates.io-index"
50
-dependencies = [
51
- "proc-macro2 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)",
52
- "quote 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
53
- "syn 0.14.5 (registry+https://github.com/rust-lang/crates.io-index)",
54
- "synstructure 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
55
-]
56
-
57
-[[package]]
58
-name = "itoa"
59
-version = "0.4.2"
60
-source = "registry+https://github.com/rust-lang/crates.io-index"
61
-
62
-[[package]]
63
-name = "lazy_static"
64
-version = "1.1.0"
65
-source = "registry+https://github.com/rust-lang/crates.io-index"
66
-dependencies = [
67
- "version_check 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
68
-]
69
-
70
-[[package]]
71
-name = "libc"
72
-version = "0.2.42"
73
-source = "registry+https://github.com/rust-lang/crates.io-index"
74
-
75
-[[package]]
76
-name = "log"
77
-version = "0.4.3"
78
-source = "registry+https://github.com/rust-lang/crates.io-index"
79
-dependencies = [
80
- "cfg-if 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
81
-]
82
-
83
-[[package]]
84
-name = "proc-macro2"
85
-version = "0.4.9"
86
-source = "registry+https://github.com/rust-lang/crates.io-index"
87
-dependencies = [
88
- "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
89
-]
90
-
91
-[[package]]
92
-name = "quote"
93
-version = "0.6.4"
94
-source = "registry+https://github.com/rust-lang/crates.io-index"
95
-dependencies = [
96
- "proc-macro2 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)",
97
-]
98
-
99
-[[package]]
100
-name = "rustc-demangle"
101
-version = "0.1.9"
102
-source = "registry+https://github.com/rust-lang/crates.io-index"
103
-
104
-[[package]]
105
-name = "serde"
106
-version = "1.0.70"
107
-source = "registry+https://github.com/rust-lang/crates.io-index"
108
-
109
-[[package]]
110
-name = "serde_derive"
111
-version = "1.0.70"
112
-source = "registry+https://github.com/rust-lang/crates.io-index"
113
-dependencies = [
114
- "proc-macro2 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)",
115
- "quote 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
116
- "syn 0.14.5 (registry+https://github.com/rust-lang/crates.io-index)",
117
-]
118
-
119
-[[package]]
120
-name = "serde_json"
121
-version = "1.0.24"
122
-source = "registry+https://github.com/rust-lang/crates.io-index"
123
-dependencies = [
124
- "dtoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
125
- "itoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
126
- "serde 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)",
127
-]
128
-
129
-[[package]]
130
-name = "syn"
131
-version = "0.14.5"
132
-source = "registry+https://github.com/rust-lang/crates.io-index"
133
-dependencies = [
134
- "proc-macro2 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)",
135
- "quote 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
136
- "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
137
-]
138
-
139
-[[package]]
140
-name = "synstructure"
141
-version = "0.9.0"
142
-source = "registry+https://github.com/rust-lang/crates.io-index"
143
-dependencies = [
144
- "proc-macro2 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)",
145
- "quote 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
146
- "syn 0.14.5 (registry+https://github.com/rust-lang/crates.io-index)",
147
- "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
148
-]
149
-
150
-[[package]]
151
-name = "unicode-xid"
152
-version = "0.1.0"
153
-source = "registry+https://github.com/rust-lang/crates.io-index"
154
-
155
-[[package]]
156
-name = "version_check"
157
-version = "0.1.4"
158
-source = "registry+https://github.com/rust-lang/crates.io-index"
159
-
160
-[[package]]
161
-name = "wasm-bindgen"
162
-version = "0.2.17"
163
-source = "registry+https://github.com/rust-lang/crates.io-index"
164
-dependencies = [
165
- "wasm-bindgen-macro 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)",
166
-]
167
-
168
-[[package]]
169
-name = "wasm-bindgen-backend"
170
-version = "0.2.17"
171
-source = "registry+https://github.com/rust-lang/crates.io-index"
172
-dependencies = [
173
- "lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
174
- "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
175
- "proc-macro2 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)",
176
- "quote 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
177
- "serde_json 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)",
178
- "syn 0.14.5 (registry+https://github.com/rust-lang/crates.io-index)",
179
- "wasm-bindgen-shared 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)",
180
-]
181
-
182
-[[package]]
183
-name = "wasm-bindgen-macro"
184
-version = "0.2.17"
185
-source = "registry+https://github.com/rust-lang/crates.io-index"
186
-dependencies = [
187
- "quote 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
188
- "wasm-bindgen-macro-support 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)",
189
-]
190
-
191
-[[package]]
192
-name = "wasm-bindgen-macro-support"
193
-version = "0.2.17"
194
-source = "registry+https://github.com/rust-lang/crates.io-index"
195
-dependencies = [
196
- "proc-macro2 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)",
197
- "quote 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
198
- "syn 0.14.5 (registry+https://github.com/rust-lang/crates.io-index)",
199
- "wasm-bindgen-backend 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)",
200
- "wasm-bindgen-shared 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)",
201
-]
202
-
203
-[[package]]
204
-name = "wasm-bindgen-shared"
205
-version = "0.2.17"
206
-source = "registry+https://github.com/rust-lang/crates.io-index"
207
-dependencies = [
208
- "serde 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)",
209
- "serde_derive 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)",
210
-]
211
-
212
-[[package]]
213
-name = "wasm_tetris"
214
-version = "0.1.0"
215
-dependencies = [
216
- "failure 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
217
- "wasm-bindgen 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)",
218
-]
219
-
220
-[[package]]
221
-name = "winapi"
222
-version = "0.3.5"
223
-source = "registry+https://github.com/rust-lang/crates.io-index"
224
-dependencies = [
225
- "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
226
- "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
227
-]
228
-
229
-[[package]]
230
-name = "winapi-i686-pc-windows-gnu"
231
-version = "0.4.0"
232
-source = "registry+https://github.com/rust-lang/crates.io-index"
233
-
234
-[[package]]
235
-name = "winapi-x86_64-pc-windows-gnu"
236
-version = "0.4.0"
237
-source = "registry+https://github.com/rust-lang/crates.io-index"
238
-
239
-[metadata]
240
-"checksum backtrace 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "89a47830402e9981c5c41223151efcced65a0510c13097c769cede7efb34782a"
241
-"checksum backtrace-sys 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)" = "bff67d0c06556c0b8e6b5f090f0eac52d950d9dfd1d35ba04e4ca3543eaf6a7e"
242
-"checksum cc 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)" = "2119ea4867bd2b8ed3aecab467709720b2d55b1bcfe09f772fd68066eaf15275"
243
-"checksum cfg-if 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "efe5c877e17a9c717a0bf3613b2709f723202c4e4675cc8f12926ded29bcb17e"
244
-"checksum dtoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6d301140eb411af13d3115f9a562c85cc6b541ade9dfa314132244aaee7489dd"
245
-"checksum failure 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7efb22686e4a466b1ec1a15c2898f91fa9cb340452496dca654032de20ff95b9"
246
-"checksum failure_derive 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "946d0e98a50d9831f5d589038d2ca7f8f455b1c21028c0db0e84116a12696426"
247
-"checksum itoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5adb58558dcd1d786b5f0bd15f3226ee23486e24b7b58304b60f64dc68e62606"
248
-"checksum lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca488b89a5657b0a2ecd45b95609b3e848cf1755da332a0da46e2b2b1cb371a7"
249
-"checksum libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)" = "b685088df2b950fccadf07a7187c8ef846a959c142338a48f9dc0b94517eb5f1"
250
-"checksum log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "61bd98ae7f7b754bc53dca7d44b604f733c6bba044ea6f41bc8d89272d8161d2"
251
-"checksum proc-macro2 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)" = "cccdc7557a98fe98453030f077df7f3a042052fae465bb61d2c2c41435cfd9b6"
252
-"checksum quote 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b71f9f575d55555aa9c06188be9d4e2bfc83ed02537948ac0d520c24d0419f1a"
253
-"checksum rustc-demangle 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "bcfe5b13211b4d78e5c2cadfebd7769197d95c639c35a50057eb4c05de811395"
254
-"checksum serde 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)" = "0c3adf19c07af6d186d91dae8927b83b0553d07ca56cbf7f2f32560455c91920"
255
-"checksum serde_derive 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)" = "3525a779832b08693031b8ecfb0de81cd71cfd3812088fafe9a7496789572124"
256
-"checksum serde_json 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)" = "c3c6908c7b925cd6c590358a4034de93dbddb20c45e1d021931459fd419bf0e2"
257
-"checksum syn 0.14.5 (registry+https://github.com/rust-lang/crates.io-index)" = "4bad7abdf6633f07c7046b90484f1d9dc055eca39f8c991177b1046ce61dba9a"
258
-"checksum synstructure 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "85bb9b7550d063ea184027c9b8c20ac167cd36d3e06b3a40bceb9d746dc1a7b7"
259
-"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
260
-"checksum version_check 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "7716c242968ee87e5542f8021178248f267f295a5c4803beae8b8b7fd9bc6051"
261
-"checksum wasm-bindgen 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)" = "18435dd2cabae856f7ce0530798d1b9d0f9fe52f0948abb4b002d5d6042aa479"
262
-"checksum wasm-bindgen-backend 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)" = "d86e94290104554e5e4b9030ed90623033707fb0275151325faff4e4953bcfee"
263
-"checksum wasm-bindgen-macro 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)" = "e240c96a612f131b87a1925c15ba73ce9f71b7e443c42c8ec9c77cfdc06c58a1"
264
-"checksum wasm-bindgen-macro-support 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)" = "40b6edde67171a5a8514243049e85593e4a776446fe952d9e1873b828e28ecc0"
265
-"checksum wasm-bindgen-shared 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)" = "19647b4790a288a74d4a9911fbf6e66719a3eca36d2ea755412fe2cd615bec93"
266
-"checksum winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "773ef9dcc5f24b7d850d0ff101e542ff24c3b090a9768e03ff889fdef41f00fd"
267
-"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
268
-"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 @@
1
-#![feature(test)]
2
-
3
-extern crate test;
4
-extern crate wasm_tetris;
5
-
6
-#[bench]
7
-fn universe_ticks(b: &mut test::Bencher) {
8
-    let mut universe = wasm_game_of_life::Universe::new();
9
-
10
-    b.iter(|| {
11
-        universe.tick();
12
-    });
13
-}

+ 10
- 0
build.sh View File

@@ -0,0 +1,10 @@
1
+#!/bin/sh
2
+
3
+if [ "$1" = "release" ]
4
+then
5
+    cargo build --release --target wasm32-unknown-unknown
6
+    wasm-bindgen target/wasm32-unknown-unknown/release/wasm_tetris.wasm --out-dir www --no-typescript --no-modules
7
+else
8
+    cargo build --target wasm32-unknown-unknown
9
+    wasm-bindgen target/wasm32-unknown-unknown/debug/wasm_tetris.wasm --out-dir www --no-typescript --no-modules
10
+fi

+ 0
- 26
index.html View File

@@ -1,26 +0,0 @@
1
-<html>
2
-  <head>
3
-    <meta content="text/html;charset=utf-8" http-equiv="Content-Type"/>
4
-    <style>
5
-      body {
6
-      width: 100%;
7
-      height: 100%;
8
-      display: flex;
9
-      flex-direction: column;
10
-      align-items: center;
11
-      justify-content: center;
12
-      font-family: monospace;
13
-      white-space: pre;
14
-      background: #000;
15
-      }
16
-      #render-canvas {
17
-        background: #000;
18
-        padding: 0;
19
-      }
20
-    </style>
21
-  </head>
22
-  <body>
23
-    <canvas id="render-canvas"></canvas>
24
-    <script src='bootstrap.js'></script>
25
-  </body>
26
-</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 @@
1
-{
2
-  "scripts": {
3
-    "serve:dev": "webpack-dev-server",
4
-    "serve:release": "serve",
5
-    "build:dev": "webpack --mode=development --progress",
6
-    "build:dev:wasm": "cargo +nightly build --target wasm32-unknown-unknown && wasm-bindgen target/wasm32-unknown-unknown/debug/wasm_tetris.wasm --out-dir web",
7
-    "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",
8
-    "build:server": "go build serve.go"
9
-  },
10
-  "devDependencies": {
11
-    "webpack": "4.16.1",
12
-    "webpack-cli": "3.1.0",
13
-    "webpack-dev-server": "3.1.4",
14
-    "mkdirp": "0.5.1"
15
-  },
16
-  "dependencies": {
17
-    "howler": "2.0.14"
18
-  }
19
-}

+ 0
- 41
serve.go View File

@@ -1,41 +0,0 @@
1
-package main
2
-
3
-import (
4
-	"fmt"
5
-	"net/http"
6
-	"regexp"
7
-)
8
-
9
-/*
10
-build this file once:
11
-  $ go build serve.go
12
-
13
-build the release version with:
14
-  $ npm run build:release
15
-
16
-serve everything from /dist with:
17
-  $ ./serve
18
-*/
19
-
20
-var wasmFile = regexp.MustCompile("\\.wasm$")
21
-
22
-func maxAgeHandler(seconds int, h http.Handler) http.Handler {
23
-	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
24
-		w.Header().Add("Cache-Control", fmt.Sprintf("max-age=%d, public, must-revalidate, proxy-revalidate", seconds))
25
-
26
-		ruri := r.RequestURI
27
-		if wasmFile.MatchString(ruri) {
28
-			w.Header().Set("Content-Type", "application/wasm")
29
-		}
30
-
31
-		h.ServeHTTP(w, r)
32
-	})
33
-}
34
-
35
-func main() {
36
-	fs := http.FileServer(http.Dir("dist"))
37
-	http.Handle("/", maxAgeHandler(0, fs))
38
-
39
-	fmt.Printf("Serving localhost:3000\n")
40
-	http.ListenAndServe(":3000", nil)
41
-}

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

@@ -1,54 +0,0 @@
1
-import { Howl, Howler } from "howler";
2
-
3
-export class Audio {
4
-  constructor(config) {
5
-    this.impact = new Howl({
6
-      src: ['web/sfx/impact1.mp3']
7
-    });
8
-    this.game_over = new Howl({
9
-      src: ['web/sfx/negative1.mp3']
10
-    });
11
-    this.line1 = new Howl({
12
-      src: ['web/sfx/fanfare1.mp3']
13
-    });
14
-    this.line2 = new Howl({
15
-      src: ['web/sfx/powerup16.mp3']
16
-    });
17
-    this.line3 = new Howl({
18
-      src: ['web/sfx/powerup18.mp3']
19
-    });
20
-    this.line4 = new Howl({
21
-      src: ['web/sfx/powerup9.mp3']
22
-    });
23
-    this.pause_in = new Howl({
24
-      src: ['web/sfx/pause2_in.mp3']
25
-    });
26
-    this.pause_out = new Howl({
27
-      src: ['web/sfx/pause2_out.mp3']
28
-    });
29
-    this.menu_move = new Howl({
30
-      src: ['web/sfx/menu_move4.mp3']
31
-    });
32
-  }
33
-
34
-  play(label) {
35
-    // console.log(`audio: play ${label}`);
36
-    switch(label) {
37
-    case 1: this.impact.play(); break;
38
-    case 2: this.game_over.play(); break;
39
-    case 3: this.line1.play(); break;
40
-    case 4: this.line2.play(); break;
41
-    case 5: this.line3.play(); break;
42
-    case 6: this.line4.play(); break;
43
-    case 7: this.pause_in.play(); break;
44
-    case 8: this.pause_out.play(); break;
45
-    case 9: this.menu_move.play(); break;
46
-    default: console.error(`Audio: unable to play: ${label}`);
47
-    }
48
-  }
49
-
50
-  volume(amount) {
51
-    // volume is in range 0..1
52
-    Howler.volume(amount);
53
-  }
54
-}

+ 0
- 259
web/js/Matrix.js View File

@@ -1,259 +0,0 @@
1
-/**
2
- * Code taken from gl-matrix (http://glmatrix.net/)
3
-
4
-Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV.
5
-
6
-Permission is hereby granted, free of charge, to any person obtaining a copy
7
-of this software and associated documentation files (the "Software"), to deal
8
-in the Software without restriction, including without limitation the rights
9
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
-copies of the Software, and to permit persons to whom the Software is
11
-furnished to do so, subject to the following conditions:
12
-
13
-The above copyright notice and this permission notice shall be included in
14
-all copies or substantial portions of the Software.
15
-
16
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
-THE SOFTWARE.
23
-**/
24
-
25
-function create() {
26
-  const out = new Float32Array(16);
27
-  out[0] = 1;
28
-  out[1] = 0;
29
-  out[2] = 0;
30
-  out[3] = 0;
31
-  out[4] = 0;
32
-  out[5] = 1;
33
-  out[6] = 0;
34
-  out[7] = 0;
35
-  out[8] = 0;
36
-  out[9] = 0;
37
-  out[10] = 1;
38
-  out[11] = 0;
39
-  out[12] = 0;
40
-  out[13] = 0;
41
-  out[14] = 0;
42
-  out[15] = 1;
43
-
44
-  return out;
45
-}
46
-
47
-function identity(out) {
48
-  out[0] = 1;
49
-  out[1] = 0;
50
-  out[2] = 0;
51
-  out[3] = 0;
52
-  out[4] = 0;
53
-  out[5] = 1;
54
-  out[6] = 0;
55
-  out[7] = 0;
56
-  out[8] = 0;
57
-  out[9] = 0;
58
-  out[10] = 1;
59
-  out[11] = 0;
60
-  out[12] = 0;
61
-  out[13] = 0;
62
-  out[14] = 0;
63
-  out[15] = 1;
64
-
65
-  return out;
66
-}
67
-
68
-function ortho(out, left, right, bottom, top, near, far) {
69
-  const lr = 1 / (left - right);
70
-  const bt = 1 / (bottom - top);
71
-  const nf = 1 / (near - far);
72
-
73
-  out[0] = -2 * lr;
74
-  out[1] = 0;
75
-  out[2] = 0;
76
-  out[3] = 0;
77
-  out[4] = 0;
78
-  out[5] = -2 * bt;
79
-  out[6] = 0;
80
-  out[7] = 0;
81
-  out[8] = 0;
82
-  out[9] = 0;
83
-  out[10] = 2 * nf;
84
-  out[11] = 0;
85
-  out[12] = (left + right) * lr;
86
-  out[13] = (top + bottom) * bt;
87
-  out[14] = (far + near) * nf;
88
-  out[15] = 1;
89
-
90
-  return out;
91
-}
92
-
93
-function clone(a) {
94
-  const out = new Float32Array(16);
95
-  out[0] = a[0];
96
-  out[1] = a[1];
97
-  out[2] = a[2];
98
-  out[3] = a[3];
99
-  out[4] = a[4];
100
-  out[5] = a[5];
101
-  out[6] = a[6];
102
-  out[7] = a[7];
103
-  out[8] = a[8];
104
-  out[9] = a[9];
105
-  out[10] = a[10];
106
-  out[11] = a[11];
107
-  out[12] = a[12];
108
-  out[13] = a[13];
109
-  out[14] = a[14];
110
-  out[15] = a[15];
111
-
112
-  return out;
113
-}
114
-
115
-function scale(out, a, v) {
116
-  const x = v[0], y = v[1], z = v[2];
117
-
118
-  out[0] = a[0] * x;
119
-  out[1] = a[1] * x;
120
-  out[2] = a[2] * x;
121
-  out[3] = a[3] * x;
122
-  out[4] = a[4] * y;
123
-  out[5] = a[5] * y;
124
-  out[6] = a[6] * y;
125
-  out[7] = a[7] * y;
126
-  out[8] = a[8] * z;
127
-  out[9] = a[9] * z;
128
-  out[10] = a[10] * z;
129
-  out[11] = a[11] * z;
130
-  out[12] = a[12];
131
-  out[13] = a[13];
132
-  out[14] = a[14];
133
-  out[15] = a[15];
134
-
135
-  return out;
136
-}
137
-
138
-function multiply(out, a, b) {
139
-  const a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3];
140
-  const a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7];
141
-  const a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11];
142
-  const a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15];
143
-
144
-  // Cache only the current line of the second matrix
145
-  const b0  = b[0], b1 = b[1], b2 = b[2], b3 = b[3];
146
-  out[0] = b0*a00 + b1*a10 + b2*a20 + b3*a30;
147
-  out[1] = b0*a01 + b1*a11 + b2*a21 + b3*a31;
148
-  out[2] = b0*a02 + b1*a12 + b2*a22 + b3*a32;
149
-  out[3] = b0*a03 + b1*a13 + b2*a23 + b3*a33;
150
-
151
-  b0 = b[4]; b1 = b[5]; b2 = b[6]; b3 = b[7];
152
-  out[4] = b0*a00 + b1*a10 + b2*a20 + b3*a30;
153
-  out[5] = b0*a01 + b1*a11 + b2*a21 + b3*a31;
154
-  out[6] = b0*a02 + b1*a12 + b2*a22 + b3*a32;
155
-  out[7] = b0*a03 + b1*a13 + b2*a23 + b3*a33;
156
-
157
-  b0 = b[8]; b1 = b[9]; b2 = b[10]; b3 = b[11];
158
-  out[8] = b0*a00 + b1*a10 + b2*a20 + b3*a30;
159
-  out[9] = b0*a01 + b1*a11 + b2*a21 + b3*a31;
160
-  out[10] = b0*a02 + b1*a12 + b2*a22 + b3*a32;
161
-  out[11] = b0*a03 + b1*a13 + b2*a23 + b3*a33;
162
-
163
-  b0 = b[12]; b1 = b[13]; b2 = b[14]; b3 = b[15];
164
-  out[12] = b0*a00 + b1*a10 + b2*a20 + b3*a30;
165
-  out[13] = b0*a01 + b1*a11 + b2*a21 + b3*a31;
166
-  out[14] = b0*a02 + b1*a12 + b2*a22 + b3*a32;
167
-  out[15] = b0*a03 + b1*a13 + b2*a23 + b3*a33;
168
-
169
-  return out;
170
-}
171
-
172
-function translate(out, a, v) {
173
-  const x = v[0], y = v[1], z = v[2];
174
-  // let a00, a01, a02, a03, a10, a11, a12, a13, a20, a21, a22, a23;
175
-
176
-  if (a === out) {
177
-    out[12] = a[0] * x + a[4] * y + a[8] * z + a[12];
178
-    out[13] = a[1] * x + a[5] * y + a[9] * z + a[13];
179
-    out[14] = a[2] * x + a[6] * y + a[10] * z + a[14];
180
-    out[15] = a[3] * x + a[7] * y + a[11] * z + a[15];
181
-  } else {
182
-    const a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3];
183
-    const a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7];
184
-    const a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11];
185
-
186
-    out[0] = a00; out[1] = a01; out[2] = a02; out[3] = a03;
187
-    out[4] = a10; out[5] = a11; out[6] = a12; out[7] = a13;
188
-    out[8] = a20; out[9] = a21; out[10] = a22; out[11] = a23;
189
-
190
-    out[12] = a00 * x + a10 * y + a20 * z + a[12];
191
-    out[13] = a01 * x + a11 * y + a21 * z + a[13];
192
-    out[14] = a02 * x + a12 * y + a22 * z + a[14];
193
-    out[15] = a03 * x + a13 * y + a23 * z + a[15];
194
-  }
195
-
196
-  return out;
197
-}
198
-
199
-function rotateZ(out, a, rad) {
200
-  const s = Math.sin(rad), c = Math.cos(rad);
201
-  const a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3];
202
-  const a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7];
203
-
204
-  if (a !== out) {
205
-    out[8] = a[8];
206
-    out[9] = a[9];
207
-    out[10] = a[10];
208
-    out[11] = a[11];
209
-    out[12] = a[12];
210
-    out[13] = a[13];
211
-    out[14] = a[14];
212
-    out[15] = a[15];
213
-  }
214
-
215
-  // Perform axis-specific matrix multiplication
216
-  out[0] = a00 * c + a10 * s;
217
-  out[1] = a01 * c + a11 * s;
218
-  out[2] = a02 * c + a12 * s;
219
-  out[3] = a03 * c + a13 * s;
220
-  out[4] = a10 * c - a00 * s;
221
-  out[5] = a11 * c - a01 * s;
222
-  out[6] = a12 * c - a02 * s;
223
-  out[7] = a13 * c - a03 * s;
224
-
225
-  return out;
226
-}
227
-
228
-function transformVec2(out, a, m) {
229
-  const x = a[0];
230
-  const y = a[1];
231
-  out[0] = m[0] * x + m[4] * y + m[12];
232
-  out[1] = m[1] * x + m[5] * y + m[13];
233
-
234
-  return out;
235
-}
236
-
237
-function transformVec3(out, a, m) {
238
-  const x = a[0], y = a[1], z = a[2];
239
-  let w = m[3] * x + m[7] * y + m[11] * z + m[15];
240
-  w = w || 1.0;
241
-  out[0] = (m[0] * x + m[4] * y + m[8] * z + m[12]) / w;
242
-  out[1] = (m[1] * x + m[5] * y + m[9] * z + m[13]) / w;
243
-  out[2] = (m[2] * x + m[6] * y + m[10] * z + m[14]) / w;
244
-
245
-  return out;
246
-}
247
-
248
-export default {
249
-  create,
250
-  identity,
251
-  ortho,
252
-  clone,
253
-  scale,
254
-  multiply,
255
-  translate,
256
-  rotateZ,
257
-  transformVec2,
258
-  transformVec3
259
-};

+ 0
- 4
web/js/bootstrap.js View File

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

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

@@ -1,179 +0,0 @@
1
-import { Bridge, Config } from "../wasm_tetris";
2
-import { memory } from "../wasm_tetris_bg";
3
-import { GLRenderer } from "./GLRenderer";
4
-import { Audio } from "./Audio";
5
-
6
-let gState = {
7
-  canvasId: 'render-canvas',
8
-
9
-  config: new Config(),
10
-
11
-  tileset: 'web/img/tileset.png',
12
-
13
-  bridge: undefined,
14
-  animationId: undefined,
15
-  renderer: undefined,
16
-  audio: undefined,
17
-
18
-  performanceNow: performance.now()
19
-};
20
-
21
-const tick = () => {
22
-  const now = performance.now();
23
-  const delta = now - gState.performanceNow;
24
-  gState.performanceNow = now;
25
-
26
-  const bridge = gState.bridge;
27
-
28
-  // game state + time + user input -> game state
29
-  const tickAgain = bridge.tick(delta, Math.random());
30
-
31
-  render();
32
-
33
-  if (tickAgain) {
34
-    gState.animationId = requestAnimationFrame(tick);
35
-  }
36
-};
37
-
38
-const render = () => {
39
-  const bridge = gState.bridge;
40
-  const renderer = gState.renderer;
41
-
42
-  // bridge state -> geometry
43
-  bridge.update_geometry();
44
-
45
-  // render geometry
46
-  const memoryF32 = new Float32Array(memory.buffer);
47
-
48
-  const geo_len = bridge.geo_len();
49
-  const geo_ptr = bridge.geo_ptr();
50
-  renderer.renderGeometryToTexture(gState.config.render_texture_width, gState.config.render_texture_height,
51
-                                   memoryF32, geo_len, geo_ptr);
52
-
53
-  // apply a CRT effect
54
-  const crt_len = bridge.crt_len();
55
-  const crt_ptr = bridge.crt_ptr();
56
-  const curvature = bridge.crt_curvature();
57
-  renderer.renderTextureToScreen(gState.config.canvas_width, gState.config.canvas_height,
58
-                                 memoryF32, crt_len, crt_ptr, curvature);
59
-};
60
-
61
-function reconfigure() {
62
-  gState.bridge.reconfigure(gState.config);
63
-}
64
-
65
-function audio_play(id) {
66
-  gState.audio.play(id);
67
-}
68
-
69
-function audio_volume(volume) {
70
-  gState.audio.volume(volume);
71
-}
72
-
73
-window.reconfigure = reconfigure;
74
-window.config = gState.config;
75
-window.audio_play = audio_play;
76
-window.audio_volume = audio_volume;
77
-
78
-function get_canvas_aspect_ratio(config) {
79
-
80
-  const block_width = config.render_texture_width / config.block_size;
81
-  const block_height = config.render_texture_height / config.block_size;
82
-
83
-  const max_u = (block_width * config.block_limit_x) / config.render_texture_width;
84
-  const max_v = (block_height * config.block_limit_y) / config.render_texture_height;
85
-
86
-  return max_u / max_v;
87
-}
88
-
89
-// maximise the canvas element within it's parent whilst retaining the required aspect ratio
90
-//
91
-function resize_canvas_element(canvasElement, config) {
92
-  const width = canvasElement.parentNode.parentElement.clientWidth;
93
-  const height = canvasElement.parentNode.parentElement.clientHeight;
94
-
95
-  const canvas_aspect_ratio = get_canvas_aspect_ratio(config);
96
-  config.canvas_width = height * canvas_aspect_ratio;
97
-  config.canvas_height = height;
98
-
99
-  if (config.canvas_width > width) {
100
-    // the window has been resized to a very narrow aspect ratio
101
-    // the constraining dimension is now the width, not height
102
-    config.canvas_width = width;
103
-    config.canvas_height = width / canvas_aspect_ratio;
104
-  }
105
-
106
-  canvasElement.width = config.canvas_width;
107
-  canvasElement.height = config.canvas_height;
108
-}
109
-
110
-function main() {
111
-  // - The game is rendered on a square rendertexture so that the gamecode can
112
-  //   assume that we're working with square pixels.
113
-  // - The canvas will be rectangular and will only use the part of the
114
-  //   rendertexture that actually contains the game.
115
-  // - To ensure that square pixels remain square, we have to make sure that
116
-  //   the aspect ratio of the canvas is the same as the uv co-ordinates used
117
-  //   in mapping the rendertexture onto the canvas
118
-  //
119
-
120
-  const canvasElement = document.getElementById(gState.canvasId);
121
-
122
-  resize_canvas_element(canvasElement, gState.config);
123
-
124
-  gState.audio = new Audio(config);
125
-
126
-  let renderer = new GLRenderer(gState.config, canvasElement);
127
-  renderer.loadTexture(gState.tileset).then(([tilesetWidth, tilesetHeight]) => {
128
-
129
-    gState.config.tileset_texture_width = tilesetWidth;
130
-    gState.config.tileset_texture_height = tilesetHeight;
131
-
132
-    gState.bridge = new Bridge(gState.config);
133
-
134
-    gState.renderer = renderer;
135
-
136
-    document.addEventListener('keydown', event => {
137
-      let key_event_return = gState.bridge.event_key_down(event.key);
138
-
139
-      if (key_event_return.prevent_default()) {
140
-        event.preventDefault();
141
-      }
142
-      if (key_event_return.call_tick()) {
143
-        tick();
144
-      }
145
-
146
-      key_event_return.free();
147
-    });
148
-
149
-    document.addEventListener('keyup', event => {
150
-      let key_event_return = gState.bridge.event_key_up(event.key);
151
-
152
-      if (key_event_return.prevent_default()) {
153
-        event.preventDefault();
154
-      }
155
-      if (key_event_return.call_tick()) {
156
-        tick();
157
-      }
158
-
159
-      key_event_return.free();
160
-    });
161
-
162
-    window.addEventListener("resize", () => {
163
-      resize_canvas_element(canvasElement, gState.config);
164
-      gState.bridge.event_resize(gState.config.canvas_width, gState.config.canvas_height);
165
-      render();
166
-
167
-    });
168
-
169
-    gState.bridge.init(Math.random());
170
-    tick();
171
-  }).catch(error => console.error(error));
172
-
173
-  // isg: NOTE: remember to free Bridge
174
-  // gState.bridge.free();
175
-}
176
-
177
-
178
-
179
-main();

+ 0
- 13
webpack.config.js View File

@@ -1,13 +0,0 @@
1
-const path = require("path");
2
-
3
-module.exports = {
4
-  entry: "./web/js/bootstrap.js",
5
-  output: {
6
-    path: path.resolve(__dirname, "dist"),
7
-    filename: "bootstrap.js",
8
-  },
9
-  optimization: {
10
-    minimize: false
11
-  },
12
-  mode: "development"
13
-};

BIN
www/favicon.ico View File


+ 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 @@
1
+<!DOCTYPE html>
2
+<html>
3
+  <head>
4
+    <meta content="text/html;charset=utf-8" http-equiv="Content-Type"/>
5
+    <style>
6
+      body {
7
+      width: 97%;
8
+      height: 97%;
9
+      display: flex;
10
+      flex-direction: column;
11
+      align-items: center;
12
+      justify-content: center;
13
+      font-family: monospace;
14
+      white-space: pre;
15
+      background: #333333;
16
+      }
17
+      #render-canvas {
18
+        background: #101010;
19
+        padding: 0;
20
+      }
21
+    </style>
22
+  </head>
23
+  <body>
24
+    <canvas id="render-canvas"></canvas>
25
+    <script src='howler.js'></script>
26
+
27
+
28
+    <script>
29
+      // The `--no-modules`-generated JS from `wasm-bindgen` attempts to use
30
+      // `WebAssembly.instantiateStreaming` to instantiate the wasm module,
31
+      // but this doesn't work with `file://` urls. This example is frequently
32
+      // viewed by simply opening `index.html` in a browser (with a `file://`
33
+      // url), so it would fail if we were to call this function!
34
+      //
35
+      // Work around this for now by deleting the function to ensure that the
36
+      // `no_modules.js` script doesn't have access to it. You won't need this
37
+      // hack when deploying over HTTP.
38
+      delete WebAssembly.instantiateStreaming;
39
+    </script>
40
+
41
+    <!-- this is the JS generated by the `wasm-bindgen` CLI tool -->
42
+    <script src='./wasm_tetris.js'></script>
43
+
44
+    <script src='index.js'></script>
45
+  </body>
46
+</html>

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

@@ -1,4 +1,52 @@
1
-import Matrix from './Matrix';
1
+const { Bridge, BridgeConfig } = wasm_bindgen;
2
+let memory = undefined;
3
+
4
+function matrixCreate() {
5
+  const out = new Float32Array(16);
6
+  out[0] = 1;
7
+  out[1] = 0;
8
+  out[2] = 0;
9
+  out[3] = 0;
10
+  out[4] = 0;
11
+  out[5] = 1;
12
+  out[6] = 0;
13
+  out[7] = 0;
14
+  out[8] = 0;
15
+  out[9] = 0;
16
+  out[10] = 1;
17
+  out[11] = 0;
18
+  out[12] = 0;
19
+  out[13] = 0;
20
+  out[14] = 0;
21
+  out[15] = 1;
22
+
23
+  return out;
24
+}
25
+
26
+function matrixOrtho(out, left, right, bottom, top, near, far) {
27
+  const lr = 1 / (left - right);
28
+  const bt = 1 / (bottom - top);
29
+  const nf = 1 / (near - far);
30
+
31
+  out[0] = -2 * lr;
32
+  out[1] = 0;
33
+  out[2] = 0;
34
+  out[3] = 0;
35
+  out[4] = 0;
36
+  out[5] = -2 * bt;
37
+  out[6] = 0;
38
+  out[7] = 0;
39
+  out[8] = 0;
40
+  out[9] = 0;
41
+  out[10] = 2 * nf;
42
+  out[11] = 0;
43
+  out[12] = (left + right) * lr;
44
+  out[13] = (top + bottom) * bt;
45
+  out[14] = (far + near) * nf;
46
+  out[15] = 1;
47
+
48
+  return out;
49
+}
2 50
 
3 51
 const logToConsole = false;
4 52
 
@@ -305,7 +353,7 @@ function checkFramebufferStatus(gl) {
305 353
   }
306 354
 }
307 355
 
308
-export class GLRenderer {
356
+class GLRenderer {
309 357
   constructor(config, canvasElement) {
310 358
     this.glDomElement = canvasElement;
311 359
 
@@ -500,3 +548,237 @@ export class GLRenderer {
500 548
     gl.drawArrays(gl.TRIANGLE_STRIP, 0, geo_len / totalSize);
501 549
   }
502 550
 }
551
+
552
+class Audio {
553
+  constructor(config) {
554
+    this.impact = new Howl({
555
+      src: ['sfx/impact1.mp3']
556
+    });
557
+    this.game_over = new Howl({
558
+      src: ['sfx/negative1.mp3']
559
+    });
560
+    this.line1 = new Howl({
561
+      src: ['sfx/fanfare1.mp3']
562
+    });
563
+    this.line2 = new Howl({
564
+      src: ['sfx/powerup16.mp3']
565
+    });
566
+    this.line3 = new Howl({
567
+      src: ['sfx/powerup18.mp3']
568
+    });
569
+    this.line4 = new Howl({
570
+      src: ['sfx/powerup9.mp3']
571
+    });
572
+    this.pause_in = new Howl({
573
+      src: ['sfx/pause2_in.mp3']
574
+    });
575
+    this.pause_out = new Howl({
576
+      src: ['sfx/pause2_out.mp3']
577
+    });
578
+    this.menu_move = new Howl({
579
+      src: ['sfx/menu_move4.mp3']
580
+    });
581
+  }
582
+
583
+  play(label) {
584
+    // console.log(`audio: play ${label}`);
585
+    switch(label) {
586
+    case 1: this.impact.play(); break;
587
+    case 2: this.game_over.play(); break;
588
+    case 3: this.line1.play(); break;
589
+    case 4: this.line2.play(); break;
590
+    case 5: this.line3.play(); break;
591
+    case 6: this.line4.play(); break;
592
+    case 7: this.pause_in.play(); break;
593
+    case 8: this.pause_out.play(); break;
594
+    case 9: this.menu_move.play(); break;
595
+    default: console.error(`Audio: unable to play: ${label}`);
596
+    }
597
+  }
598
+
599
+  volume(amount) {
600
+    // volume is in range 0..1
601
+    Howler.volume(amount);
602
+  }
603
+}
604
+
605
+let gState = {
606
+  canvasId: 'render-canvas',
607
+
608
+  config: new Config(),
609
+
610
+  tileset: 'img/tileset.png',
611
+
612
+  bridge: undefined,
613
+  animationId: undefined,
614
+  renderer: undefined,
615
+  audio: undefined,
616
+
617
+  performanceNow: performance.now()
618
+};
619
+
620
+const tick = () => {
621
+  const now = performance.now();
622
+  const delta = now - gState.performanceNow;
623
+  gState.performanceNow = now;
624
+
625
+  const bridge = gState.bridge;
626
+
627
+  // game state + time + user input -> game state
628
+  const tickAgain = bridge.tick(delta, Math.random());
629
+
630
+  render();
631
+
632
+  if (tickAgain) {
633
+    gState.animationId = requestAnimationFrame(tick);
634
+  }
635
+};
636
+
637
+const render = () => {
638
+  const bridge = gState.bridge;
639
+  const renderer = gState.renderer;
640
+
641
+  // bridge state -> geometry
642
+  bridge.update_geometry();
643
+
644
+  // render geometry
645
+  const memoryF32 = new Float32Array(memory.buffer);
646
+
647
+  const geo_len = bridge.geo_len();
648
+  const geo_ptr = bridge.geo_ptr();
649
+  renderer.renderGeometryToTexture(gState.config.render_texture_width, gState.config.render_texture_height,
650
+                                   memoryF32, geo_len, geo_ptr);
651
+
652
+  // apply a CRT effect
653
+  const crt_len = bridge.crt_len();
654
+  const crt_ptr = bridge.crt_ptr();
655
+  const curvature = bridge.crt_curvature();
656
+  renderer.renderTextureToScreen(gState.config.canvas_width, gState.config.canvas_height,
657
+                                 memoryF32, crt_len, crt_ptr, curvature);
658
+};
659
+
660
+function reconfigure() {
661
+  gState.bridge.reconfigure(gState.config);
662
+}
663
+
664
+function audio_play(id) {
665
+  gState.audio.play(id);
666
+}
667
+
668
+function audio_volume(volume) {
669
+  gState.audio.volume(volume);
670
+}
671
+
672
+window.reconfigure = reconfigure;
673
+window.config = gState.config;
674
+window.audio_play = audio_play;
675
+window.audio_volume = audio_volume;
676
+
677
+function get_canvas_aspect_ratio(config) {
678
+
679
+  const block_width = config.render_texture_width / config.block_size;
680
+  const block_height = config.render_texture_height / config.block_size;
681
+
682
+  const max_u = (block_width * config.block_limit_x) / config.render_texture_width;
683
+  const max_v = (block_height * config.block_limit_y) / config.render_texture_height;
684
+
685
+  return max_u / max_v;
686
+}
687
+
688
+// maximise the canvas element within it's parent whilst retaining the required aspect ratio
689
+//
690
+function resize_canvas_element(canvasElement, config) {
691
+  const width = canvasElement.parentNode.parentElement.clientWidth;
692
+  const height = canvasElement.parentNode.parentElement.clientHeight;
693
+
694
+  const canvas_aspect_ratio = get_canvas_aspect_ratio(config);
695
+  config.canvas_width = height * canvas_aspect_ratio;
696
+  config.canvas_height = height;
697
+
698
+  if (config.canvas_width > width) {
699
+    // the window has been resized to a very narrow aspect ratio
700
+    // the constraining dimension is now the width, not height
701
+    config.canvas_width = width;
702
+    config.canvas_height = width / canvas_aspect_ratio;
703
+  }
704
+
705
+  canvasElement.width = config.canvas_width;
706
+  canvasElement.height = config.canvas_height;
707
+}
708
+
709
+function main() {
710
+  // - The game is rendered on a square rendertexture so that the gamecode can
711
+  //   assume that we're working with square pixels.
712
+  // - The canvas will be rectangular and will only use the part of the
713
+  //   rendertexture that actually contains the game.
714
+  // - To ensure that square pixels remain square, we have to make sure that
715
+  //   the aspect ratio of the canvas is the same as the uv co-ordinates used
716
+  //   in mapping the rendertexture onto the canvas
717
+  //
718
+
719
+  const canvasElement = document.getElementById(gState.canvasId);
720
+
721
+  resize_canvas_element(canvasElement, gState.config);
722
+
723
+  gState.audio = new Audio(config);
724
+
725
+  let renderer = new GLRenderer(gState.config, canvasElement);
726
+  renderer.loadTexture(gState.tileset).then(([tilesetWidth, tilesetHeight]) => {
727
+
728
+    gState.config.tileset_texture_width = tilesetWidth;
729
+    gState.config.tileset_texture_height = tilesetHeight;
730
+
731
+    gState.bridge = new Bridge(gState.config);
732
+
733
+    gState.renderer = renderer;
734
+
735
+    document.addEventListener('keydown', event => {
736
+      let key_event_return = gState.bridge.event_key_down(event.key);
737
+
738
+      if (key_event_return.prevent_default()) {
739
+        event.preventDefault();
740
+      }
741
+      if (key_event_return.call_tick()) {
742
+        tick();
743
+      }
744
+
745
+      key_event_return.free();
746
+    });
747
+
748
+    document.addEventListener('keyup', event => {
749
+      let key_event_return = gState.bridge.event_key_up(event.key);
750
+
751
+      if (key_event_return.prevent_default()) {
752
+        event.preventDefault();
753
+      }
754
+      if (key_event_return.call_tick()) {
755
+        tick();
756
+      }
757
+
758
+      key_event_return.free();
759
+    });
760
+
761
+    window.addEventListener("resize", () => {
762
+      resize_canvas_element(canvasElement, gState.config);
763
+      gState.bridge.event_resize(gState.config.canvas_width, gState.config.canvas_height);
764
+      render();
765
+
766
+    });
767
+
768
+    gState.bridge.init(Math.random());
769
+    tick();
770
+  }).catch(error => console.error(error));
771
+
772
+  // isg: NOTE: remember to free Bridge
773
+  // gState.bridge.free();
774
+}
775
+
776
+
777
+document.addEventListener('DOMContentLoaded', () => {
778
+  wasm_bindgen('./wasm_tetris_bg.wasm')
779
+    .then(client_bg => {
780
+      memory = client_bg.memory;
781
+      main();
782
+    })
783
+    .catch(console.error);
784
+});

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