-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
108 lines (93 loc) · 3.33 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Hexagon</title>
<meta name="description" content="Hexagon">
<meta name="author" content="Fabian Michel">
<link rel="shortcut icon" href="hexagon.ico">
<link rel="stylesheet" href="css/hexagon.css">
<script language="javascript" type="text/javascript">
let FONTS_WERE_LOADED = false;
let WASM_WAS_LOADED = false;
let cMenu;
/**
* Create a 32-bit integer array
* @param {number[]} arr the JavaScript array that should be saved in WASM memory
* @return {number} the array offset in memory
*/
function WASM_CreateArr(arr) {
if (!WASM_WAS_LOADED) throw new Error('Called WASM_CreateArr before WASM was loaded!');
let offset = Module._malloc(arr.length * 4);
for (let i = 0; i < arr.length; i++) {
Module.setValue(offset + i * 4, arr[i], 'i32');
}
return offset;
}
/**
* Read the 32-bit integer array at the given offset
* @param {number} offset the offset of the array (returned by WASM_CreateArr)
* @param {number} len the length of the array to read
* @return {number[]} the array
*/
function WASM_ReadArr(offset, len) {
if (!WASM_WAS_LOADED) throw new Error('Called WASM_ReadArr before WASM was loaded!');
let res = [];
for (let i = 0; i < len; i++) {
res[i] = Module.getValue(offset + i * 4, 'i32');
}
return res;
}
/**
* Free the memory used by a WASM array
* @param {number} offset the offset of the array (returned by WASM_CreateArr)
*/
function WASM_FreeArr(offset) {
if (!WASM_WAS_LOADED) throw new Error('Called WASM_FreeArr before WASM was loaded!');
Module._free(offset);
}
/**
* Call a WASM function that receives an array as argument
* @param {string} fct the function name
* @param {number} arroffset the offset of the array that should be passed as argument (returned by WASM_CreateArr)
* @param {any} [rettype] the expected return type (null or a string like 'number')
* @return {any} the result of the function execution
*/
function WASM_CallArrFct(fct, arroffset, rettype = null) {
if (!WASM_WAS_LOADED) throw new Error('Called WASM_CallArrFct before WASM was loaded!');
return Module.ccall(fct, // name of C function
rettype, // return type
['number'], // argument types
[arroffset]); // arguments
}
var Module = {
onRuntimeInitialized: function() {
WASM_WAS_LOADED = true;
}
};
</script>
<script src="https://ajax.googleapis.com/ajax/libs/webfont/1.6.26/webfont.js"></script>
<script async type="text/javascript" src="js/bf.js"></script>
<script src="js/hexagon.js"></script>
<script src="js/AbstractHexState.js"></script>
<script src="js/HexGameState.js"></script>
<script src="js/HexGameStateOpt.js"></script>
<script src="js/HexSolver.js"></script>
<script src="js/HexGameBoard.js"></script>
<script src="js/HexMenu.js"></script>
<script language="javascript" type="text/javascript">
WebFont.load({
google: {
families: ['Merriweather']
},
active: () => fontsLoaded()
});
function fontsLoaded() {
FONTS_WERE_LOADED = true;
if (cMenu) cMenu.redraw();
}
</script>
</head>
<body onLoad="hexMain();">
</body>
</html>