forked from unconed/fuse10
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.js
76 lines (65 loc) · 1.75 KB
/
common.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
window.Acko = window.Acko || {};
var π = Math.PI,
τ = π * 2;
// Seedable random generator
var rand = (function () {
var seed = 0;
return function (sd) {
seed = sd || seed;
// Robert Jenkins' 32 bit integer hash function.
seed = ((seed + 0x7ed55d16) + (seed << 12)) & 0xffffffff;
seed = ((seed ^ 0xc761c23c) ^ (seed >>> 19)) & 0xffffffff;
seed = ((seed + 0x165667b1) + (seed << 5)) & 0xffffffff;
seed = ((seed + 0xd3a2646c) ^ (seed << 9)) & 0xffffffff;
seed = ((seed + 0xfd7046c5) + (seed << 3)) & 0xffffffff;
seed = ((seed ^ 0xb55a4f09) ^ (seed >>> 16)) & 0xffffffff;
return (seed & 0xfffffff) / 0x10000000;
};
})();
// Sign-preserving power
function pow(x, a) {
var s = (x < 0) ? -1 : 1;
return s * Math.pow(Math.abs(x), a);
}
// Debug timer
function tick() {
var now = +new Date();
return function (label) {
var delta = (+new Date() - now);
console.log(label, delta + " ms");
return delta;
};
}
// Log that shuts up after n
var log = (function () {
var count = 0;
var limit = 500;
return function () {
if (count++ < limit) console.log.apply(console, arguments);
};
})();
// Local storage proxy
var getStorage = function (key) {
var o = localStorage[key];
if (o) try { o = JSON.parse(o) } catch (e) {};
if (!o || typeof o != 'object' || o.forEach) {
o = {};
}
return o;
};
var setStorage = function (key, value) {
localStorage[key] = JSON.stringify(value);
};
// Content scripts
Acko.Behaviors = [];
Acko.Behaviors.apply = function (el) {
el = el || document.body;
this.forEach(function (f) {
f(el);
});
}
// Helpers
var _v = function (x, y, z) { return new THREE.Vector3(x, y, z); };
var forEach = function (list, c) {
Array.prototype.forEach.call(list, c);
};