-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbrowser.worker.ts
43 lines (37 loc) · 1.12 KB
/
browser.worker.ts
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
import ClientStore from './ClientStore';
import RootStore from './RootStore';
import { glMatrix } from 'gl-matrix';
import { configure } from "mobx";
import actionMap from './actionMap';
configure({
computedRequiresReaction: true
});
// Use Arrays for glmatrix constructors
glMatrix.setMatrixArrayType(Array);
const rootState = new ClientStore({
actionMap,
debug: {
dispatchLog: (actionType: string) => {
if (actionType.match(/tick/)) return false;
if (actionType.match(/INPUT/)) return false;
return true;
},
render: process.env.NODE_ENV === 'production' ? false : true,
network: process.env.NODE_ENV === 'production' ? false : true,
collisions: process.env.NODE_ENV === 'production' ? false : true,
debugCamera: process.env.NODE_ENV === 'production' ? false : true
}
});
declare global {
interface Window {
rootState: RootStore
}
}
self.rootState = rootState;
self.addEventListener('message', (event) => {
if (event.data && event.data.type) {
rootState.dispatch(event.data);
} else {
console.warn('unsure what to do with message passed to worker...', event);
}
});