-
-
Notifications
You must be signed in to change notification settings - Fork 163
/
Copy pathglobalVariables.js
97 lines (81 loc) · 2.84 KB
/
globalVariables.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
93
94
95
96
'use strict';
let unitTesting = false;
let lazyFunctionGeneration = true;
let curlevel = 0;
let curlevelTarget = null;
let hasUsedCheckpoint = false;
let levelEditorOpened = false;
let muted = 0;
let runrulesonlevelstart_phase = false;
let ignoreNotJustPressedAction = true;
let textMode = true;
function doSetupTitleScreenLevelContinue() {
try {
if (storage_has(document.URL)) {
if (storage_has(document.URL + '_checkpoint')) {
let backupStr = storage_get(document.URL + '_checkpoint');
curlevelTarget = JSON.parse(backupStr);
let arr = [];
for (let p in Object.keys(curlevelTarget.dat)) {
arr[p] = curlevelTarget.dat[p];
}
curlevelTarget.dat = new Int32Array(arr);
}
curlevel = storage_get(document.URL);
}
} catch (ex) {
}
}
doSetupTitleScreenLevelContinue();
let verbose_logging = false;
let throttle_movement = false;
let suppress_all_console_output = false;
let cache_console_messages = false;
let quittingTitleScreen = false;
let quittingMessageScreen = false;
let deltatime = 17; // this gets updated every frame; see loop()
let timer = 0;
let repeatinterval = 150;
let autotick = 0;
let autotickinterval = 0;
let winning = false;
let againing = false;
let againinterval = 150;
let norepeat_action = false;
let oldflickscreendat = [];//used for buffering old flickscreen/scrollscreen positions, in case player vanishes
let keybuffer = [];
let restarting = false;
let messageselected = false;
let textImages = {};
let level = new Level(); //just give it some starting state
function get_title_animation_frame() {
return Math.floor(((timer / 1000) / 0.3) * 10)
}
var WORKLIST_OBJECTS_TO_GENERATE_FUNCTIONS_FOR = [];
function tick_lazy_function_generation(iterative_generation = false) {
if (WORKLIST_OBJECTS_TO_GENERATE_FUNCTIONS_FOR.length === 0) {
return;
}
// spent a maximum of 10ms on lazy function generation
let start = performance.now();
var generated_count = 0;
while (
((performance.now() - start < 20) || !iterative_generation)
&& WORKLIST_OBJECTS_TO_GENERATE_FUNCTIONS_FOR.length > 0) {
const object = WORKLIST_OBJECTS_TO_GENERATE_FUNCTIONS_FOR.shift();
//depending on type of object
//if CellPattern, call generateMatchFunction
//if Rule, call generate_all_MatchFunctions
if (object instanceof CellPattern) {
object.matches = object.generateMatchFunction();
} else if (object instanceof Rule) {
object.generate_all_MatchFunctions();
} else {
throw new Error("Unknown object type: " + object);
}
generated_count++;
}
}
function lazy_function_generation_clear_backlog() {
WORKLIST_OBJECTS_TO_GENERATE_FUNCTIONS_FOR = [];
}