forked from mbebenita/Broadway
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhooks.js
92 lines (75 loc) · 1.95 KB
/
hooks.js
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
if (FS) {
Module['FS'] = FS;
}
Module['HEAPU8'] = HEAPU8;
Module['CorrectionsMonitor'] = CorrectionsMonitor;
FS['createDataFile'] = FS.createDataFile;
// Replace main loop handler
var breakLoop = false;
_runMainLoop = function() {
window.addEventListener("message", function() {
_mainLoopIteration();
if (!breakLoop) {
window.postMessage(0, "*")
}
}, false);
}
Module['play'] = function() {
breakLoop = false;
window.postMessage(0, "*")
};
Module['stop'] = function() {
breakLoop = true;
};
Module['onFrameDecoded'] = function () { }
_broadwayOnFrameDecoded = function() {
Module['onFrameDecoded']();
}
// Module['setPosition'] = _broadwaySetPosition;
// Module['getPosition'] = _broadwayGetPosition;
Module['createStreamBuffer'] = _broadwayCreateStreamBuffer;
var patches = Module['patches'] = {};
function getGlobalScope() {
return function () { return this; }.call(null);
}
assert = function (condition, message) {
if (!condition) {
throw "Assertion: " + message;
}
}
/**
* Patches a function and remembers its old value.
*/
Module['patch'] = function (scope, name, value) {
assert (typeof(value) == "function");
if (!scope) {
scope = getGlobalScope();
}
if (Module["CC_VARIABLE_MAP"]) {
name = Module["CC_VARIABLE_MAP"][name];
}
assert (name in scope && (typeof(scope[name]) === "function" || typeof(scope[name]) === "undefined"), "Can only patch functions.");
patches[name] = scope[name];
scope[name] = value;
return patches[name];
};
/**
* Restore a previously patched function.
*/
Module['unpatch'] = function (scope, name) {
if (!scope) {
scope = getGlobalScope();
}
if (Module["CC_VARIABLE_MAP"]) {
name = Module["CC_VARIABLE_MAP"][name];
}
assert (name in scope && typeof(scope[name]) == "function");
if (name in patches) {
scope[name] = patches[name];
}
};
/* Optimizations */
_abs = Math.abs;
_clip = function clip(x, y, z) {
return z < x ? x : (z > y ? y : z);
};