webxos commited on
Commit
f31a8cb
·
verified ·
1 Parent(s): d17d383

Upload webXOS_datastrike_gym.html

Browse files
Files changed (1) hide show
  1. webXOS_datastrike_gym.html +2015 -0
webXOS_datastrike_gym.html ADDED
@@ -0,0 +1,2015 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>DATASTRIKE v4.0 | by webXOS 2026</title>
7
+
8
+ <!-- Required Libraries -->
9
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
10
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
11
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2.0.5/FileSaver.min.js"></script>
12
+
13
+ <style>
14
+ * {
15
+ margin: 0;
16
+ padding: 0;
17
+ box-sizing: border-box;
18
+ -webkit-tap-highlight-color: transparent;
19
+ }
20
+
21
+ body {
22
+ background: #000;
23
+ color: #0f0;
24
+ font-family: 'Courier New', monospace;
25
+ overflow: hidden;
26
+ cursor: none;
27
+ height: 100vh;
28
+ width: 100vw;
29
+ position: fixed;
30
+ touch-action: none;
31
+ }
32
+
33
+ #gameContainer {
34
+ position: fixed;
35
+ top: 0;
36
+ left: 0;
37
+ width: 100%;
38
+ height: 100%;
39
+ z-index: 1;
40
+ image-rendering: pixelated;
41
+ }
42
+
43
+ canvas {
44
+ display: block;
45
+ }
46
+
47
+ /* === MINIMAL UI === */
48
+ #ui {
49
+ position: fixed;
50
+ top: 0;
51
+ left: 0;
52
+ width: 100%;
53
+ height: 100%;
54
+ pointer-events: none;
55
+ z-index: 2;
56
+ padding: 10px;
57
+ font-size: 12px;
58
+ }
59
+
60
+ .stat-row {
61
+ display: flex;
62
+ justify-content: space-between;
63
+ margin-bottom: 4px;
64
+ padding: 4px 8px;
65
+ background: rgba(0, 20, 0, 0.7);
66
+ border: 1px solid #0a0;
67
+ border-radius: 2px;
68
+ font-size: 11px;
69
+ }
70
+
71
+ .stat-label {
72
+ color: #0a0;
73
+ }
74
+
75
+ .stat-value {
76
+ color: #0f0;
77
+ font-weight: bold;
78
+ }
79
+
80
+ /* === CROSSHAIR === */
81
+ #crosshair {
82
+ position: fixed;
83
+ top: 50%;
84
+ left: 50%;
85
+ transform: translate(-50%, -50%);
86
+ width: 20px;
87
+ height: 20px;
88
+ pointer-events: none;
89
+ z-index: 3;
90
+ }
91
+
92
+ .crosshair-dot {
93
+ position: absolute;
94
+ width: 4px;
95
+ height: 4px;
96
+ background: #0f0;
97
+ border-radius: 50%;
98
+ top: 50%;
99
+ left: 50%;
100
+ transform: translate(-50%, -50%);
101
+ }
102
+
103
+ .crosshair-line {
104
+ position: absolute;
105
+ background: #0f0;
106
+ }
107
+
108
+ .horizontal {
109
+ width: 8px;
110
+ height: 1px;
111
+ top: 50%;
112
+ transform: translateY(-50%);
113
+ }
114
+
115
+ .horizontal.left {
116
+ left: 0;
117
+ }
118
+
119
+ .horizontal.right {
120
+ right: 0;
121
+ }
122
+
123
+ .vertical {
124
+ width: 1px;
125
+ height: 8px;
126
+ left: 50%;
127
+ transform: translateX(-50%);
128
+ }
129
+
130
+ .vertical.top {
131
+ top: 0;
132
+ }
133
+
134
+ .vertical.bottom {
135
+ bottom: 0;
136
+ }
137
+
138
+ /* === BUTTONS === */
139
+ button {
140
+ pointer-events: auto;
141
+ background: rgba(0, 40, 0, 0.9);
142
+ border: 1px solid #0f0;
143
+ color: #0f0;
144
+ padding: 8px 16px;
145
+ margin: 4px;
146
+ cursor: pointer;
147
+ font-family: 'Courier New', monospace;
148
+ font-size: 11px;
149
+ border-radius: 3px;
150
+ }
151
+
152
+ button:hover {
153
+ background: rgba(0, 60, 0, 0.9);
154
+ }
155
+
156
+ .button-row {
157
+ display: flex;
158
+ justify-content: center;
159
+ gap: 8px;
160
+ margin-top: 8px;
161
+ }
162
+
163
+ /* === LOADING SCREEN === */
164
+ #loadingOverlay {
165
+ position: fixed;
166
+ top: 0;
167
+ left: 0;
168
+ width: 100%;
169
+ height: 100%;
170
+ background: #000;
171
+ display: flex;
172
+ flex-direction: column;
173
+ justify-content: center;
174
+ align-items: center;
175
+ z-index: 100;
176
+ }
177
+
178
+ .loader-text {
179
+ color: #0f0;
180
+ font-size: 14px;
181
+ margin-top: 20px;
182
+ text-align: center;
183
+ }
184
+
185
+ /* === TIMELAPSE CAPTURE INDICATOR === */
186
+ .timelapse-indicator {
187
+ position: fixed;
188
+ top: 10px;
189
+ right: 10px;
190
+ background: rgba(0, 20, 0, 0.8);
191
+ border: 1px solid #0f0;
192
+ border-radius: 4px;
193
+ padding: 8px;
194
+ font-size: 10px;
195
+ z-index: 5;
196
+ pointer-events: none;
197
+ }
198
+
199
+ .capture-pulse {
200
+ position: fixed;
201
+ top: 50%;
202
+ left: 50%;
203
+ transform: translate(-50%, -50%);
204
+ width: 100px;
205
+ height: 100px;
206
+ border: 3px solid #00ffff;
207
+ border-radius: 50%;
208
+ pointer-events: none;
209
+ z-index: 100;
210
+ opacity: 0;
211
+ animation: pulse 0.5s ease-out;
212
+ }
213
+
214
+ @keyframes pulse {
215
+ 0% { transform: translate(-50%, -50%) scale(0.5); opacity: 1; }
216
+ 100% { transform: translate(-50%, -50%) scale(1.5); opacity: 0; }
217
+ }
218
+
219
+ /* === CAPTURE MODE INDICATOR === */
220
+ .capture-mode {
221
+ position: fixed;
222
+ top: 10px;
223
+ left: 10px;
224
+ background: rgba(0, 20, 0, 0.8);
225
+ border: 1px solid #0f0;
226
+ border-radius: 4px;
227
+ padding: 6px 10px;
228
+ font-size: 10px;
229
+ z-index: 5;
230
+ pointer-events: none;
231
+ }
232
+
233
+ /* === MOBILE CONTROLS === */
234
+ .mobile-controls {
235
+ display: none;
236
+ position: fixed;
237
+ bottom: 20px;
238
+ left: 0;
239
+ width: 100%;
240
+ z-index: 10;
241
+ touch-action: none;
242
+ }
243
+
244
+ .mobile-joystick {
245
+ position: absolute;
246
+ bottom: 20px;
247
+ left: 20px;
248
+ width: 80px;
249
+ height: 80px;
250
+ background: rgba(0, 40, 0, 0.5);
251
+ border-radius: 50%;
252
+ border: 1px solid #0f0;
253
+ touch-action: none;
254
+ }
255
+
256
+ .mobile-joystick-thumb {
257
+ position: absolute;
258
+ width: 30px;
259
+ height: 30px;
260
+ background: rgba(0, 255, 0, 0.7);
261
+ border-radius: 50%;
262
+ top: 25px;
263
+ left: 25px;
264
+ touch-action: none;
265
+ }
266
+
267
+ .mobile-shoot {
268
+ position: absolute;
269
+ bottom: 20px;
270
+ right: 20px;
271
+ width: 60px;
272
+ height: 60px;
273
+ background: rgba(255, 0, 0, 0.5);
274
+ border-radius: 50%;
275
+ border: 1px solid #f00;
276
+ touch-action: none;
277
+ display: flex;
278
+ align-items: center;
279
+ justify-content: center;
280
+ color: white;
281
+ font-size: 11px;
282
+ }
283
+
284
+ /* === EXPORT PROGRESS === */
285
+ .export-progress {
286
+ position: fixed;
287
+ top: 50%;
288
+ left: 50%;
289
+ transform: translate(-50%, -50%);
290
+ background: rgba(0, 0, 0, 0.95);
291
+ border: 2px solid #0f0;
292
+ padding: 20px;
293
+ border-radius: 5px;
294
+ z-index: 1000;
295
+ display: none;
296
+ pointer-events: none;
297
+ }
298
+
299
+ /* === TIMELAPSE PREVIEW === */
300
+ #timelapsePreview {
301
+ position: fixed;
302
+ top: 50px;
303
+ right: 10px;
304
+ width: 160px;
305
+ height: 120px;
306
+ border: 2px solid #0f0;
307
+ background: #000;
308
+ z-index: 100;
309
+ display: none;
310
+ pointer-events: none;
311
+ }
312
+ </style>
313
+ </head>
314
+ <body>
315
+ <!-- LOADING SCREEN -->
316
+ <div id="loadingOverlay">
317
+ <div class="loader-text" id="loaderText">Initializing BCI Timelapse Capture...</div>
318
+ <div class="loader-text" id="loaderPercent">0%</div>
319
+ </div>
320
+
321
+ <!-- GAME CONTAINER -->
322
+ <div id="gameContainer"></div>
323
+
324
+ <!-- UI LAYER -->
325
+ <div id="ui">
326
+ <!-- TOP STATS -->
327
+ <div class="stat-row">
328
+ <span class="stat-label">BCI INTENT:</span>
329
+ <span id="intentStatus" class="stat-value">IDLE</span>
330
+ </div>
331
+ <div class="stat-row">
332
+ <span class="stat-label">FPS:</span>
333
+ <span id="fps" class="stat-value">60</span>
334
+ </div>
335
+ <div class="stat-row">
336
+ <span class="stat-label">TIMELAPSE:</span>
337
+ <span id="timelapseCount" class="stat-value">0</span>
338
+ </div>
339
+ <div class="stat-row">
340
+ <span class="stat-label">SEQUENCE:</span>
341
+ <span id="sequenceCount" class="stat-value">0</span>
342
+ </div>
343
+ <div class="stat-row">
344
+ <span class="stat-label">LEVEL:</span>
345
+ <span id="level" class="stat-value">1</span>
346
+ </div>
347
+ <div class="stat-row">
348
+ <span class="stat-label">AMMO:</span>
349
+ <span id="ammo" class="stat-value">30/∞</span>
350
+ </div>
351
+
352
+ <!-- BOTTOM CONTROLS -->
353
+ <div style="position: fixed; bottom: 10px; left: 0; width: 100%;">
354
+ <div class="button-row">
355
+ <button id="recordBtn" onclick="toggleRecording()">
356
+ ⏺ TIMELAPSE REC
357
+ </button>
358
+ <button id="modeBtn" onclick="toggleCaptureMode()">
359
+ 🔄 MANUAL MODE
360
+ </button>
361
+ <button id="exportBtn" onclick="exportTimelapseDataset()">
362
+ 📤 EXPORT SEQUENCE
363
+ </button>
364
+ <button onclick="resetSession()">
365
+ 🔄 RESET
366
+ </button>
367
+ </div>
368
+ </div>
369
+ </div>
370
+
371
+ <!-- CROSSHAIR -->
372
+ <div id="crosshair">
373
+ <div class="crosshair-dot"></div>
374
+ <div class="crosshair-line horizontal left"></div>
375
+ <div class="crosshair-line horizontal right"></div>
376
+ <div class="crosshair-line vertical top"></div>
377
+ <div class="crosshair-line vertical bottom"></div>
378
+ </div>
379
+
380
+ <!-- CAPTURE MODE INDICATOR -->
381
+ <div class="capture-mode">
382
+ <span id="captureModeDisplay">MANUAL</span>
383
+ </div>
384
+
385
+ <!-- TIMELAPSE INDICATOR -->
386
+ <div class="timelapse-indicator">
387
+ <div>📽️ Sequence: <span id="currentSequence">0</span></div>
388
+ <div>⏱️ Interval: <span id="captureInterval">1000ms</span></div>
389
+ <div>🎯 Auto-Capture: <span id="autoCaptureStatus">OFF</span></div>
390
+ </div>
391
+
392
+ <!-- TIMELAPSE PREVIEW -->
393
+ <canvas id="timelapsePreview"></canvas>
394
+
395
+ <!-- MOBILE CONTROLS -->
396
+ <div class="mobile-controls">
397
+ <div class="mobile-joystick" id="joystickArea">
398
+ <div class="mobile-joystick-thumb" id="joystickThumb"></div>
399
+ </div>
400
+ <div class="mobile-shoot" id="shootButton">
401
+ FIRE
402
+ </div>
403
+ </div>
404
+
405
+ <!-- EXPORT PROGRESS -->
406
+ <div id="exportProgress" class="export-progress">
407
+ <div id="progressText">Processing timelapse sequence...</div>
408
+ <div style="width: 300px; height: 10px; background: #111; margin-top: 10px; border-radius: 5px; overflow: hidden;">
409
+ <div id="progressBar" style="width: 0%; height: 100%; background: #0f0;"></div>
410
+ </div>
411
+ </div>
412
+
413
+ <script>
414
+ // ========== ENHANCED TIMELAPSE CONFIGURATION ==========
415
+ const CONFIG = {
416
+ // Performance Settings
417
+ MAX_TOTAL_OBJECTS: 50,
418
+ MAX_ACTIVE_OBJECTS: 30,
419
+
420
+ // Game Settings
421
+ INITIAL_DRONE_COUNT: 2,
422
+ MAX_DRONES: 6,
423
+ DRONE_SPAWN_RATE: 4.0,
424
+ DRONE_SPEED: 0.015,
425
+ DRONE_HEALTH: 50,
426
+
427
+ // Player Settings
428
+ PLAYER_SPEED: 0.08,
429
+ PLAYER_HEIGHT: 1.7,
430
+ MOUSE_SENSITIVITY: 0.0015,
431
+ JUMP_FORCE: 0.12,
432
+ GRAVITY: 0.004,
433
+
434
+ // Weapon Settings
435
+ WEAPON_DAMAGE: 40,
436
+ FIRE_RATE: 8,
437
+ BULLET_SPEED: 1.5,
438
+ BULLET_LIFETIME: 1.0,
439
+ MAX_AMMO: 30,
440
+ RELOAD_TIME: 2.0,
441
+
442
+ // Timelapse Capture Settings
443
+ CAPTURE_MODES: {
444
+ MANUAL: 'manual', // LMB click to capture
445
+ AUTO: 'auto', // Automatic at interval
446
+ SEQUENCE: 'sequence' // Start/stop sequence recording
447
+ },
448
+
449
+ // Timelapse Parameters
450
+ TIMELAPSE: {
451
+ ENABLED: true,
452
+ RESOLUTION: { width: 320, height: 240 }, // Higher res for better ML training
453
+ FORMAT: 'image/jpeg',
454
+ QUALITY: 0.7,
455
+ MAX_FRAMES: 1000,
456
+ AUTO_INTERVAL: 500, // ms between auto captures
457
+ SEQUENCE_BUFFER: 60 // frames to buffer for smooth sequences
458
+ },
459
+
460
+ // BCI Intent System
461
+ BCI_INTENT_TYPES: [
462
+ 'IDLE', 'MOVE_FORWARD', 'MOVE_BACKWARD', 'MOVE_LEFT', 'MOVE_RIGHT',
463
+ 'LOOK_LEFT', 'LOOK_RIGHT', 'LOOK_UP', 'LOOK_DOWN',
464
+ 'FIRE_WEAPON', 'RELOAD', 'JUMP', 'TIMELAPSE_CAPTURE'
465
+ ],
466
+
467
+ // RLHF Settings for Timelapse
468
+ RLHF_ENABLED: true,
469
+ RLHF_EVENTS: ['FIRE_WEAPON', 'DRONE_HIT', 'DRONE_DESTROYED', 'TIMELAPSE_CAPTURE'],
470
+ RLHF_AUTO_RATINGS: {
471
+ 'FIRE_WEAPON': 0,
472
+ 'DRONE_HIT': 1,
473
+ 'DRONE_DESTROYED': 2,
474
+ 'TIMELAPSE_CAPTURE': 0.5 // Neutral for capture events
475
+ }
476
+ };
477
+
478
+ // ========== GAME STATE ==========
479
+ let scene, camera, renderer;
480
+ let player;
481
+ let drones = [];
482
+ let bullets = [];
483
+ let lastTime = 0;
484
+ let gameTime = 0;
485
+ let deltaTime = 0;
486
+ let frameCount = 0;
487
+ let fps = 60;
488
+ let lastFpsUpdate = 0;
489
+ let animationFrameId = null;
490
+
491
+ // Object pools
492
+ let bulletPool = [];
493
+
494
+ // Player stats
495
+ let level = 1;
496
+ let exp = 0;
497
+ let requiredExp = 1000;
498
+ let kills = 0;
499
+ let shotsFired = 0;
500
+ let shotsHit = 0;
501
+ let accuracy = 0;
502
+ let totalSamples = 0;
503
+
504
+ // Weapon state
505
+ let currentAmmo = CONFIG.MAX_AMMO;
506
+ let isReloading = false;
507
+ let lastFireTime = 0;
508
+
509
+ // Controls
510
+ let controls = {
511
+ w: false, a: false, s: false, d: false,
512
+ space: false
513
+ };
514
+
515
+ let mouse = {
516
+ x: 0,
517
+ y: 0,
518
+ dx: 0,
519
+ dy: 0,
520
+ sensitivity: CONFIG.MOUSE_SENSITIVITY,
521
+ locked: false,
522
+ lmbPressed: false,
523
+ lmbHoldStart: 0
524
+ };
525
+
526
+ // Player physics
527
+ let velocity = new THREE.Vector3();
528
+ let isGrounded = true;
529
+
530
+ // BCI Intent tracking
531
+ let currentIntent = 'IDLE';
532
+ let intentHistory = [];
533
+
534
+ // ========== ENHANCED TIMELAPSE SYSTEM ==========
535
+ let captureMode = CONFIG.CAPTURE_MODES.MANUAL;
536
+ let isRecordingTimelapse = false;
537
+ let timelapseSequence = [];
538
+ let currentSequence = 0;
539
+ let captureInterval = null;
540
+ let timelapseBuffer = [];
541
+ let frameCounter = 0;
542
+
543
+ // Mobile controls
544
+ let joystickActive = false;
545
+ let joystickStart = { x: 0, y: 0 };
546
+ let joystickVector = { x: 0, y: 0 };
547
+
548
+ // ========== LOADING SYSTEM ==========
549
+ function updateLoader(progress, text) {
550
+ const loaderText = document.getElementById('loaderText');
551
+ const loaderPercent = document.getElementById('loaderPercent');
552
+
553
+ if (loaderText) loaderText.textContent = text;
554
+ if (loaderPercent) loaderPercent.textContent = `${Math.round(progress)}%`;
555
+ }
556
+
557
+ async function init() {
558
+ try {
559
+ updateLoader(10, "Initializing 3D engine...");
560
+
561
+ // Create scene
562
+ scene = new THREE.Scene();
563
+ scene.background = new THREE.Color(0x000000);
564
+ updateLoader(20, "Creating scene...");
565
+
566
+ // Create camera
567
+ camera = new THREE.PerspectiveCamera(
568
+ CONFIG.FOV,
569
+ window.innerWidth / window.innerHeight,
570
+ 0.1,
571
+ CONFIG.RENDER_DISTANCE
572
+ );
573
+ camera.position.y = CONFIG.PLAYER_HEIGHT;
574
+ updateLoader(30, "Setting up camera...");
575
+
576
+ // Create renderer
577
+ renderer = new THREE.WebGLRenderer({
578
+ antialias: false,
579
+ alpha: false,
580
+ powerPreference: "low-power",
581
+ preserveDrawingBuffer: true // Required for canvas.toDataURL()
582
+ });
583
+ renderer.setSize(window.innerWidth, window.innerHeight);
584
+ renderer.setPixelRatio(window.devicePixelRatio || 1);
585
+
586
+ const gameContainer = document.getElementById('gameContainer');
587
+ if (gameContainer) {
588
+ gameContainer.appendChild(renderer.domElement);
589
+ } else {
590
+ document.body.appendChild(renderer.domElement);
591
+ }
592
+
593
+ updateLoader(40, "Configuring timelapse system...");
594
+
595
+ // Setup lighting
596
+ const ambientLight = new THREE.AmbientLight(0x00ff00, 0.1);
597
+ scene.add(ambientLight);
598
+
599
+ const directionalLight = new THREE.DirectionalLight(0x00ff00, 0.3);
600
+ directionalLight.position.set(10, 20, 5);
601
+ scene.add(directionalLight);
602
+ updateLoader(50, "Creating environment...");
603
+
604
+ // Create environment
605
+ createMinimalEnvironment();
606
+ updateLoader(60, "Setting up player...");
607
+
608
+ // Setup player
609
+ player = camera;
610
+ updateLoader(70, "Setting up controls...");
611
+
612
+ // Setup controls
613
+ setupControls();
614
+ updateLoader(80, "Initializing timelapse system...");
615
+
616
+ // Initialize timelapse system
617
+ initTimelapseSystem();
618
+
619
+ // Initialize object pools
620
+ initObjectPools();
621
+
622
+ // Create initial drones
623
+ for (let i = 0; i < CONFIG.INITIAL_DRONE_COUNT; i++) {
624
+ setTimeout(() => spawnDrone(), i * 2000);
625
+ }
626
+
627
+ // Start drone spawner
628
+ setInterval(() => {
629
+ if (drones.length < CONFIG.MAX_DRONES) {
630
+ spawnDrone();
631
+ }
632
+ }, 1000 / CONFIG.DRONE_SPAWN_RATE);
633
+
634
+ // Hide loading screen
635
+ setTimeout(() => {
636
+ const loadingOverlay = document.getElementById('loadingOverlay');
637
+ if (loadingOverlay) {
638
+ loadingOverlay.style.opacity = '0';
639
+ setTimeout(() => {
640
+ loadingOverlay.style.display = 'none';
641
+ showBCIStatus("Timelapse System Ready");
642
+ updateCaptureUI();
643
+ }, 500);
644
+ }
645
+ }, 300);
646
+
647
+ updateLoader(100, "Starting game loop...");
648
+
649
+ // Start game loop
650
+ animate();
651
+
652
+ console.log("BCI Timelapse Capture initialized successfully");
653
+
654
+ } catch (error) {
655
+ console.error("Error initializing:", error);
656
+ updateLoader(100, `Error: ${error.message}`);
657
+ alert(`Failed to start: ${error.message}. Check console for details.`);
658
+ }
659
+ }
660
+
661
+ function initObjectPools() {
662
+ // Initialize bullet pool
663
+ for (let i = 0; i < 15; i++) {
664
+ const bulletGeometry = new THREE.SphereGeometry(0.08, 4, 4);
665
+ const bulletMaterial = new THREE.MeshBasicMaterial({
666
+ color: 0xffff00
667
+ });
668
+ const bullet = new THREE.Mesh(bulletGeometry, bulletMaterial);
669
+ bullet.visible = false;
670
+ bullet.userData = { active: false };
671
+ scene.add(bullet);
672
+ bulletPool.push(bullet);
673
+ }
674
+ }
675
+
676
+ function createMinimalEnvironment() {
677
+ // Ground
678
+ const groundGeometry = new THREE.PlaneGeometry(100, 100);
679
+ const groundMaterial = new THREE.MeshBasicMaterial({
680
+ color: 0x003300
681
+ });
682
+ const ground = new THREE.Mesh(groundGeometry, groundMaterial);
683
+ ground.rotation.x = -Math.PI / 2;
684
+ scene.add(ground);
685
+
686
+ // Grid
687
+ const gridHelper = new THREE.GridHelper(100, 10, 0x00aa00, 0x003300);
688
+ gridHelper.position.y = 0.01;
689
+ scene.add(gridHelper);
690
+
691
+ // Simple buildings
692
+ const buildingGeometry = new THREE.BoxGeometry(1, 1, 1);
693
+ const buildingMaterial = new THREE.MeshBasicMaterial({
694
+ color: 0x00aa00,
695
+ wireframe: true
696
+ });
697
+
698
+ for (let i = 0; i < 5; i++) {
699
+ const height = Math.random() * 10 + 5;
700
+ const building = new THREE.Mesh(buildingGeometry, buildingMaterial);
701
+ building.scale.set(
702
+ Math.random() * 4 + 2,
703
+ height,
704
+ Math.random() * 4 + 2
705
+ );
706
+
707
+ building.position.set(
708
+ (Math.random() - 0.5) * 80,
709
+ height / 2,
710
+ (Math.random() - 0.5) * 80
711
+ );
712
+
713
+ scene.add(building);
714
+ }
715
+ }
716
+
717
+ function setupControls() {
718
+ // Mouse lock
719
+ document.addEventListener('click', () => {
720
+ if (!document.pointerLockElement) {
721
+ document.body.requestPointerLock();
722
+ }
723
+ });
724
+
725
+ // Mouse movement
726
+ document.addEventListener('mousemove', (e) => {
727
+ if (document.pointerLockElement === document.body) {
728
+ mouse.dx = e.movementX || e.mozMovementX || e.webkitMovementX || 0;
729
+ mouse.dy = e.movementY || e.mozMovementY || e.webkitMovementY || 0;
730
+
731
+ mouse.x += mouse.dx * mouse.sensitivity;
732
+ mouse.y += mouse.dy * mouse.sensitivity;
733
+
734
+ mouse.y = Math.max(-Math.PI/2, Math.min(Math.PI/2, mouse.y));
735
+
736
+ camera.rotation.order = 'YXZ';
737
+ camera.rotation.y = -mouse.x;
738
+ camera.rotation.x = -mouse.y;
739
+
740
+ // Record look intent
741
+ if (mouse.dx > 0) recordBCIIntent('LOOK_RIGHT');
742
+ else if (mouse.dx < 0) recordBCIIntent('LOOK_LEFT');
743
+ else if (mouse.dy > 0) recordBCIIntent('LOOK_DOWN');
744
+ else if (mouse.dy < 0) recordBCIIntent('LOOK_UP');
745
+ }
746
+ });
747
+
748
+ document.addEventListener('pointerlockchange', () => {
749
+ mouse.locked = document.pointerLockElement === document.body;
750
+ if (!mouse.locked) {
751
+ mouse.dx = mouse.dy = 0;
752
+ }
753
+ });
754
+
755
+ // Keyboard controls
756
+ document.addEventListener('keydown', (e) => {
757
+ let key = e.key.toLowerCase();
758
+ if (key === ' ') key = 'space';
759
+
760
+ if (key in controls) {
761
+ controls[key] = true;
762
+ recordBCIIntent(getIntentFromKey(key, true));
763
+ }
764
+
765
+ switch(key) {
766
+ case 'r':
767
+ reloadWeapon();
768
+ recordBCIIntent('RELOAD');
769
+ break;
770
+ case 'c':
771
+ toggleCaptureMode();
772
+ break;
773
+ case 'p':
774
+ toggleRecording();
775
+ break;
776
+ case 'm':
777
+ manualCapture();
778
+ break;
779
+ }
780
+ });
781
+
782
+ document.addEventListener('keyup', (e) => {
783
+ let key = e.key.toLowerCase();
784
+ if (key === ' ') key = 'space';
785
+
786
+ if (key in controls) {
787
+ controls[key] = false;
788
+ recordBCIIntent('IDLE');
789
+ }
790
+
791
+ if (key === 'space' && isGrounded) {
792
+ velocity.y = CONFIG.JUMP_FORCE;
793
+ isGrounded = false;
794
+ recordBCIIntent('JUMP');
795
+ }
796
+ });
797
+
798
+ // Enhanced LMB controls for timelapse capture
799
+ document.addEventListener('mousedown', (e) => {
800
+ if (e.button === 0) { // Left mouse button
801
+ mouse.lmbPressed = true;
802
+ mouse.lmbHoldStart = Date.now();
803
+
804
+ // Fire weapon AND capture timelapse frame
805
+ if (!isReloading && currentAmmo > 0) {
806
+ fireWeapon();
807
+
808
+ // Capture timelapse based on mode
809
+ if (captureMode === CONFIG.CAPTURE_MODES.MANUAL) {
810
+ captureTimelapseFrame('LMB_MANUAL');
811
+ } else if (captureMode === CONFIG.CAPTURE_MODES.SEQUENCE && isRecordingTimelapse) {
812
+ captureTimelapseFrame('SEQUENCE_LMB');
813
+ }
814
+ } else if (currentAmmo === 0) {
815
+ reloadWeapon();
816
+ }
817
+ }
818
+ });
819
+
820
+ document.addEventListener('mouseup', (e) => {
821
+ if (e.button === 0) {
822
+ mouse.lmbPressed = false;
823
+ const holdDuration = Date.now() - mouse.lmbHoldStart;
824
+
825
+ // If LMB was held for > 500ms, trigger burst capture
826
+ if (holdDuration > 500 && captureMode === CONFIG.CAPTURE_MODES.MANUAL) {
827
+ captureBurstFrames(3);
828
+ }
829
+ }
830
+ });
831
+
832
+ // Setup mobile controls
833
+ setupMobileControls();
834
+
835
+ // Window resize
836
+ window.addEventListener('resize', () => {
837
+ camera.aspect = window.innerWidth / window.innerHeight;
838
+ camera.updateProjectionMatrix();
839
+ renderer.setSize(window.innerWidth, window.innerHeight);
840
+ });
841
+ }
842
+
843
+ function setupMobileControls() {
844
+ const joystickArea = document.getElementById('joystickArea');
845
+ const joystickThumb = document.getElementById('joystickThumb');
846
+ const shootButton = document.getElementById('shootButton');
847
+
848
+ if (!joystickArea) return;
849
+
850
+ // Joystick touch
851
+ joystickArea.addEventListener('touchstart', (e) => {
852
+ e.preventDefault();
853
+ joystickActive = true;
854
+ const touch = e.touches[0];
855
+ const rect = joystickArea.getBoundingClientRect();
856
+ joystickStart.x = rect.left + 40;
857
+ joystickStart.y = rect.top + 40;
858
+ });
859
+
860
+ document.addEventListener('touchmove', (e) => {
861
+ if (!joystickActive) return;
862
+ e.preventDefault();
863
+ const touch = e.touches[0];
864
+
865
+ let dx = touch.clientX - joystickStart.x;
866
+ let dy = touch.clientY - joystickStart.y;
867
+
868
+ // Limit to joystick area
869
+ const distance = Math.sqrt(dx * dx + dy * dy);
870
+ if (distance > 30) {
871
+ dx = (dx / distance) * 30;
872
+ dy = (dy / distance) * 30;
873
+ }
874
+
875
+ joystickVector.x = dx / 30;
876
+ joystickVector.y = dy / 30;
877
+
878
+ // Update visual
879
+ joystickThumb.style.transform = `translate(${dx}px, ${dy}px)`;
880
+
881
+ // Simulate keyboard controls
882
+ controls.w = dy < -10;
883
+ controls.s = dy > 10;
884
+ controls.a = dx < -10;
885
+ controls.d = dx > 10;
886
+
887
+ // Record BCI intent
888
+ let intent = 'IDLE';
889
+ if (dy < -10) intent = 'MOVE_FORWARD';
890
+ if (dy > 10) intent = 'MOVE_BACKWARD';
891
+ if (dx < -10) intent = 'MOVE_LEFT';
892
+ if (dx > 10) intent = 'MOVE_RIGHT';
893
+ recordBCIIntent(intent);
894
+ });
895
+
896
+ document.addEventListener('touchend', (e) => {
897
+ if (joystickActive) {
898
+ joystickActive = false;
899
+ joystickVector.x = 0;
900
+ joystickVector.y = 0;
901
+ joystickThumb.style.transform = 'translate(0, 0)';
902
+
903
+ controls.w = controls.s = controls.a = controls.d = false;
904
+ recordBCIIntent('IDLE');
905
+ }
906
+ });
907
+
908
+ // Shoot button
909
+ shootButton.addEventListener('touchstart', (e) => {
910
+ e.preventDefault();
911
+ if (!isReloading && currentAmmo > 0) {
912
+ fireWeapon();
913
+ if (captureMode === CONFIG.CAPTURE_MODES.MANUAL) {
914
+ captureTimelapseFrame('MOBILE_MANUAL');
915
+ }
916
+ }
917
+ });
918
+ }
919
+
920
+ function getIntentFromKey(key, isDown) {
921
+ if (!isDown) return 'IDLE';
922
+
923
+ switch(key) {
924
+ case 'w': return 'MOVE_FORWARD';
925
+ case 's': return 'MOVE_BACKWARD';
926
+ case 'a': return 'MOVE_LEFT';
927
+ case 'd': return 'MOVE_RIGHT';
928
+ case ' ': return 'JUMP';
929
+ case 'r': return 'RELOAD';
930
+ case 'm': return 'TIMELAPSE_CAPTURE';
931
+ default: return 'IDLE';
932
+ }
933
+ }
934
+
935
+ function spawnDrone() {
936
+ if (drones.length >= CONFIG.MAX_DRONES) return;
937
+
938
+ const geometry = new THREE.BoxGeometry(1, 1, 1);
939
+ const material = new THREE.MeshBasicMaterial({
940
+ color: 0xff3300,
941
+ wireframe: true
942
+ });
943
+ const drone = new THREE.Mesh(geometry, material);
944
+
945
+ const angle = Math.random() * Math.PI * 2;
946
+ const distance = 20 + Math.random() * 30;
947
+ drone.position.set(
948
+ camera.position.x + Math.cos(angle) * distance,
949
+ 5 + Math.random() * 10,
950
+ camera.position.z + Math.sin(angle) * distance
951
+ );
952
+
953
+ drone.userData = {
954
+ type: 'drone',
955
+ health: CONFIG.DRONE_HEALTH,
956
+ speed: CONFIG.DRONE_SPEED,
957
+ target: camera.position.clone()
958
+ };
959
+
960
+ scene.add(drone);
961
+ drones.push(drone);
962
+ }
963
+
964
+ function fireWeapon() {
965
+ const now = Date.now();
966
+ if (now - lastFireTime < 1000 / CONFIG.FIRE_RATE) return;
967
+ if (isReloading || currentAmmo <= 0) return;
968
+
969
+ lastFireTime = now;
970
+ currentAmmo--;
971
+ shotsFired++;
972
+
973
+ // Update UI
974
+ document.getElementById('ammo').textContent = `${currentAmmo}/∞`;
975
+
976
+ // Get bullet from pool
977
+ const bullet = getBulletFromPool();
978
+ if (!bullet) return;
979
+
980
+ // Configure bullet
981
+ const bulletDirection = new THREE.Vector3(0, 0, -1);
982
+ bulletDirection.applyQuaternion(camera.quaternion);
983
+
984
+ bullet.position.copy(camera.position);
985
+ bullet.position.y -= 0.2;
986
+
987
+ bullet.userData = {
988
+ velocity: bulletDirection.multiplyScalar(CONFIG.BULLET_SPEED),
989
+ damage: CONFIG.WEAPON_DAMAGE,
990
+ spawnTime: gameTime,
991
+ active: true
992
+ };
993
+
994
+ bullet.visible = true;
995
+ bullets.push(bullet);
996
+
997
+ // Simple hit detection
998
+ const raycaster = new THREE.Raycaster();
999
+ raycaster.set(camera.position, bulletDirection);
1000
+ const intersects = raycaster.intersectObjects(drones);
1001
+
1002
+ if (intersects.length > 0) {
1003
+ const drone = intersects[0].object;
1004
+ handleDroneHit(drone, bullet.userData.damage);
1005
+ }
1006
+
1007
+ if (currentAmmo === 0) {
1008
+ reloadWeapon();
1009
+ }
1010
+ }
1011
+
1012
+ function getBulletFromPool() {
1013
+ for (let i = 0; i < bulletPool.length; i++) {
1014
+ if (!bulletPool[i].visible) {
1015
+ bulletPool[i].visible = true;
1016
+ bulletPool[i].userData.active = true;
1017
+ return bulletPool[i];
1018
+ }
1019
+ }
1020
+ return null;
1021
+ }
1022
+
1023
+ function recycleBullet(bullet) {
1024
+ bullet.visible = false;
1025
+ bullet.userData.active = false;
1026
+ const index = bullets.indexOf(bullet);
1027
+ if (index > -1) {
1028
+ bullets.splice(index, 1);
1029
+ }
1030
+ }
1031
+
1032
+ function handleDroneHit(drone, damage) {
1033
+ shotsHit++;
1034
+ accuracy = shotsFired > 0 ? Math.round((shotsHit / shotsFired) * 100) : 0;
1035
+
1036
+ drone.userData.health -= damage;
1037
+
1038
+ // Capture timelapse on hit
1039
+ if (captureMode === CONFIG.CAPTURE_MODES.SEQUENCE || captureMode === CONFIG.CAPTURE_MODES.AUTO) {
1040
+ captureTimelapseFrame('DRONE_HIT');
1041
+ }
1042
+
1043
+ if (drone.userData.health <= 0) {
1044
+ destroyDrone(drone);
1045
+ }
1046
+ }
1047
+
1048
+ function destroyDrone(drone) {
1049
+ const index = drones.indexOf(drone);
1050
+ if (index > -1) {
1051
+ scene.remove(drone);
1052
+ drones.splice(index, 1);
1053
+ }
1054
+
1055
+ kills++;
1056
+ exp += 30;
1057
+ checkLevelUp();
1058
+
1059
+ // Capture timelapse on destroy
1060
+ if (captureMode !== CONFIG.CAPTURE_MODES.MANUAL) {
1061
+ captureTimelapseFrame('DRONE_DESTROYED');
1062
+ }
1063
+
1064
+ showBCIStatus(`DRONE DESTROYED +30XP`);
1065
+
1066
+ setTimeout(spawnDrone, 3000);
1067
+ }
1068
+
1069
+ function reloadWeapon() {
1070
+ if (isReloading || currentAmmo === CONFIG.MAX_AMMO) return;
1071
+
1072
+ isReloading = true;
1073
+ showBCIStatus("RELOADING...");
1074
+
1075
+ setTimeout(() => {
1076
+ currentAmmo = CONFIG.MAX_AMMO;
1077
+ isReloading = false;
1078
+ document.getElementById('ammo').textContent = `${currentAmmo}/∞`;
1079
+
1080
+ showBCIStatus("WEAPON RELOADED");
1081
+ }, CONFIG.RELOAD_TIME * 1000);
1082
+ }
1083
+
1084
+ function animate(time = 0) {
1085
+ animationFrameId = requestAnimationFrame(animate);
1086
+
1087
+ const currentTime = performance.now();
1088
+ deltaTime = (currentTime - lastTime) / 1000;
1089
+ lastTime = currentTime;
1090
+ gameTime += deltaTime;
1091
+ frameCount++;
1092
+
1093
+ // Calculate FPS every second
1094
+ if (currentTime - lastFpsUpdate > 1000) {
1095
+ fps = Math.round((frameCount * 1000) / (currentTime - lastFpsUpdate));
1096
+ frameCount = 0;
1097
+ lastFpsUpdate = currentTime;
1098
+ document.getElementById('fps').textContent = fps;
1099
+ }
1100
+
1101
+ // Update game systems
1102
+ updatePlayerMovement(deltaTime);
1103
+ updateDrones(deltaTime);
1104
+ updateBullets(deltaTime);
1105
+ updateUI();
1106
+
1107
+ // Buffer frames for sequence mode
1108
+ if (isRecordingTimelapse && captureMode === CONFIG.CAPTURE_MODES.SEQUENCE) {
1109
+ bufferGameFrame();
1110
+ }
1111
+
1112
+ // Render scene
1113
+ renderer.render(scene, camera);
1114
+ }
1115
+
1116
+ function updatePlayerMovement(delta) {
1117
+ if (!player || !mouse.locked) return;
1118
+
1119
+ const forward = new THREE.Vector3(0, 0, -1);
1120
+ const right = new THREE.Vector3(1, 0, 0);
1121
+
1122
+ forward.applyQuaternion(camera.quaternion);
1123
+ right.applyQuaternion(camera.quaternion);
1124
+
1125
+ forward.y = 0;
1126
+ right.y = 0;
1127
+ forward.normalize();
1128
+ right.normalize();
1129
+
1130
+ velocity.set(0, velocity.y, 0);
1131
+
1132
+ // Keyboard controls
1133
+ if (controls.w) velocity.add(forward.multiplyScalar(CONFIG.PLAYER_SPEED));
1134
+ if (controls.s) velocity.add(forward.multiplyScalar(-CONFIG.PLAYER_SPEED));
1135
+ if (controls.a) velocity.add(right.multiplyScalar(-CONFIG.PLAYER_SPEED));
1136
+ if (controls.d) velocity.add(right.multiplyScalar(CONFIG.PLAYER_SPEED));
1137
+
1138
+ // Mobile joystick controls
1139
+ if (joystickActive) {
1140
+ velocity.add(forward.multiplyScalar(joystickVector.y * CONFIG.PLAYER_SPEED));
1141
+ velocity.add(right.multiplyScalar(joystickVector.x * CONFIG.PLAYER_SPEED));
1142
+ }
1143
+
1144
+ // Gravity
1145
+ if (!isGrounded) {
1146
+ velocity.y -= CONFIG.GRAVITY;
1147
+ }
1148
+
1149
+ camera.position.add(velocity);
1150
+
1151
+ // Ground check
1152
+ if (camera.position.y < CONFIG.PLAYER_HEIGHT) {
1153
+ camera.position.y = CONFIG.PLAYER_HEIGHT;
1154
+ velocity.y = 0;
1155
+ isGrounded = true;
1156
+ }
1157
+
1158
+ // Keep in bounds
1159
+ camera.position.x = Math.max(-40, Math.min(40, camera.position.x));
1160
+ camera.position.z = Math.max(-40, Math.min(40, camera.position.z));
1161
+ }
1162
+
1163
+ function updateDrones(delta) {
1164
+ for (let i = drones.length - 1; i >= 0; i--) {
1165
+ const drone = drones[i];
1166
+
1167
+ // Move toward player
1168
+ const direction = new THREE.Vector3().subVectors(
1169
+ drone.userData.target,
1170
+ drone.position
1171
+ ).normalize();
1172
+
1173
+ drone.position.add(direction.multiplyScalar(drone.userData.speed));
1174
+
1175
+ // Simple rotation
1176
+ drone.rotation.y += 0.01;
1177
+
1178
+ // Check collision
1179
+ if (drone.position.distanceTo(camera.position) < 2) {
1180
+ resetSession();
1181
+ showBCIStatus("MISSION FAILED", "error");
1182
+ }
1183
+ }
1184
+ }
1185
+
1186
+ function updateBullets(delta) {
1187
+ for (let i = bullets.length - 1; i >= 0; i--) {
1188
+ const bullet = bullets[i];
1189
+
1190
+ if (!bullet.userData.active) continue;
1191
+
1192
+ bullet.position.add(bullet.userData.velocity);
1193
+
1194
+ // Check lifetime
1195
+ if (gameTime - bullet.userData.spawnTime > CONFIG.BULLET_LIFETIME) {
1196
+ recycleBullet(bullet);
1197
+ continue;
1198
+ }
1199
+
1200
+ // Check collisions
1201
+ for (let j = drones.length - 1; j >= 0; j--) {
1202
+ const drone = drones[j];
1203
+ if (bullet.position.distanceTo(drone.position) < 1.2) {
1204
+ handleDroneHit(drone, bullet.userData.damage);
1205
+ recycleBullet(bullet);
1206
+ break;
1207
+ }
1208
+ }
1209
+ }
1210
+ }
1211
+
1212
+ function updateUI() {
1213
+ document.getElementById('level').textContent = level;
1214
+ document.getElementById('timelapseCount').textContent = timelapseSequence.length;
1215
+ document.getElementById('sequenceCount').textContent = currentSequence;
1216
+ document.getElementById('intentStatus').textContent = currentIntent;
1217
+
1218
+ // Update ammo color
1219
+ const ammoEl = document.getElementById('ammo');
1220
+ if (currentAmmo === 0) {
1221
+ ammoEl.style.color = '#f00';
1222
+ } else if (currentAmmo <= 10) {
1223
+ ammoEl.style.color = '#ff0';
1224
+ } else {
1225
+ ammoEl.style.color = '#0f0';
1226
+ }
1227
+
1228
+ if (isReloading) {
1229
+ ammoEl.textContent = "RELOADING";
1230
+ } else {
1231
+ ammoEl.textContent = `${currentAmmo}/∞`;
1232
+ }
1233
+ }
1234
+
1235
+ function checkLevelUp() {
1236
+ while (exp >= requiredExp && level < 20) {
1237
+ level++;
1238
+ exp -= requiredExp;
1239
+ requiredExp = Math.floor(requiredExp * 1.2);
1240
+
1241
+ showBCIStatus(`LEVEL UP! Now Level ${level}`);
1242
+ }
1243
+ }
1244
+
1245
+ function resetSession() {
1246
+ camera.position.set(0, CONFIG.PLAYER_HEIGHT, 0);
1247
+ camera.rotation.set(0, 0, 0);
1248
+ mouse.x = mouse.y = 0;
1249
+
1250
+ currentAmmo = CONFIG.MAX_AMMO;
1251
+ shotsFired = 0;
1252
+ shotsHit = 0;
1253
+ accuracy = 0;
1254
+ isReloading = false;
1255
+
1256
+ // Remove all drones
1257
+ drones.forEach(drone => scene.remove(drone));
1258
+ drones = [];
1259
+
1260
+ // Remove all bullets
1261
+ bullets.forEach(bullet => recycleBullet(bullet));
1262
+ bullets = [];
1263
+
1264
+ // Reset BCI intent
1265
+ currentIntent = 'IDLE';
1266
+ intentHistory = [];
1267
+
1268
+ // Reset timelapse data
1269
+ timelapseSequence = [];
1270
+ timelapseBuffer = [];
1271
+ currentSequence = 0;
1272
+ frameCounter = 0;
1273
+
1274
+ // Update UI
1275
+ document.getElementById('timelapseCount').textContent = '0';
1276
+ document.getElementById('sequenceCount').textContent = '0';
1277
+
1278
+ // Spawn initial drones
1279
+ for (let i = 0; i < CONFIG.INITIAL_DRONE_COUNT; i++) {
1280
+ setTimeout(() => spawnDrone(), i * 1500);
1281
+ }
1282
+
1283
+ showBCIStatus("Session Reset");
1284
+ }
1285
+
1286
+ function showBCIStatus(message, type = "info") {
1287
+ const intentStatus = document.getElementById('intentStatus');
1288
+ if (intentStatus) {
1289
+ intentStatus.textContent = message;
1290
+
1291
+ if (type === "error") {
1292
+ intentStatus.style.color = '#f00';
1293
+ setTimeout(() => {
1294
+ intentStatus.style.color = '#0f0';
1295
+ }, 2000);
1296
+ }
1297
+ }
1298
+ }
1299
+
1300
+ function recordBCIIntent(intent) {
1301
+ if (intent !== currentIntent) {
1302
+ currentIntent = intent;
1303
+ intentHistory.push({
1304
+ intent: intent,
1305
+ timestamp: Date.now(),
1306
+ gameTime: gameTime,
1307
+ position: camera.position.toArray(),
1308
+ rotation: [camera.rotation.x, camera.rotation.y, camera.rotation.z]
1309
+ });
1310
+
1311
+ // Keep history limited
1312
+ if (intentHistory.length > 1000) {
1313
+ intentHistory = intentHistory.slice(-500);
1314
+ }
1315
+ }
1316
+ }
1317
+
1318
+ // ========== ENHANCED TIMELAPSE CAPTURE SYSTEM ==========
1319
+ function initTimelapseSystem() {
1320
+ console.log("Timelapse capture system initialized");
1321
+ updateCaptureUI();
1322
+ }
1323
+
1324
+ function toggleCaptureMode() {
1325
+ const modes = Object.values(CONFIG.CAPTURE_MODES);
1326
+ const currentIndex = modes.indexOf(captureMode);
1327
+ captureMode = modes[(currentIndex + 1) % modes.length];
1328
+
1329
+ // Stop any ongoing auto-capture
1330
+ if (captureInterval) {
1331
+ clearInterval(captureInterval);
1332
+ captureInterval = null;
1333
+ }
1334
+
1335
+ // Stop sequence recording
1336
+ if (isRecordingTimelapse) {
1337
+ stopTimelapseRecording();
1338
+ }
1339
+
1340
+ // Start auto-capture if in AUTO mode
1341
+ if (captureMode === CONFIG.CAPTURE_MODES.AUTO) {
1342
+ startAutoCapture();
1343
+ }
1344
+
1345
+ updateCaptureUI();
1346
+ showBCIStatus(`Capture Mode: ${captureMode.toUpperCase()}`);
1347
+ }
1348
+
1349
+ function updateCaptureUI() {
1350
+ const modeDisplay = document.getElementById('captureModeDisplay');
1351
+ const intervalDisplay = document.getElementById('captureInterval');
1352
+ const autoCaptureDisplay = document.getElementById('autoCaptureStatus');
1353
+
1354
+ if (modeDisplay) modeDisplay.textContent = captureMode.toUpperCase();
1355
+
1356
+ if (captureMode === CONFIG.CAPTURE_MODES.AUTO) {
1357
+ intervalDisplay.textContent = `${CONFIG.TIMELAPSE.AUTO_INTERVAL}ms`;
1358
+ autoCaptureDisplay.textContent = 'ON';
1359
+ autoCaptureDisplay.style.color = '#0f0';
1360
+ } else {
1361
+ intervalDisplay.textContent = 'N/A';
1362
+ autoCaptureDisplay.textContent = 'OFF';
1363
+ autoCaptureDisplay.style.color = '#f00';
1364
+ }
1365
+
1366
+ // Update button
1367
+ const modeBtn = document.getElementById('modeBtn');
1368
+ modeBtn.textContent = `🔄 ${captureMode.toUpperCase()} MODE`;
1369
+ }
1370
+
1371
+ function startAutoCapture() {
1372
+ captureInterval = setInterval(() => {
1373
+ if (timelapseSequence.length < CONFIG.TIMELAPSE.MAX_FRAMES) {
1374
+ captureTimelapseFrame('AUTO_INTERVAL');
1375
+ } else {
1376
+ clearInterval(captureInterval);
1377
+ }
1378
+ }, CONFIG.TIMELAPSE.AUTO_INTERVAL);
1379
+ }
1380
+
1381
+ function toggleRecording() {
1382
+ if (captureMode !== CONFIG.CAPTURE_MODES.SEQUENCE) {
1383
+ showBCIStatus("Switch to SEQUENCE mode first", "error");
1384
+ return;
1385
+ }
1386
+
1387
+ isRecordingTimelapse = !isRecordingTimelapse;
1388
+ const button = document.getElementById('recordBtn');
1389
+
1390
+ if (isRecordingTimelapse) {
1391
+ button.innerHTML = '⏹️ STOP SEQUENCE';
1392
+ button.style.background = 'rgba(255, 0, 0, 0.7)';
1393
+ showBCIStatus("Sequence Recording Started");
1394
+ timelapseBuffer = []; // Clear buffer
1395
+ currentSequence++;
1396
+ document.getElementById('currentSequence').textContent = currentSequence;
1397
+ } else {
1398
+ button.innerHTML = '⏺️ START SEQUENCE';
1399
+ button.style.background = 'rgba(0, 40, 0, 0.9)';
1400
+ showBCIStatus("Sequence Recording Stopped");
1401
+
1402
+ // Finalize sequence
1403
+ finalizeSequence();
1404
+ }
1405
+ }
1406
+
1407
+ function bufferGameFrame() {
1408
+ // Buffer game state for smooth sequence
1409
+ if (timelapseBuffer.length >= CONFIG.TIMELAPSE.SEQUENCE_BUFFER) {
1410
+ timelapseBuffer.shift();
1411
+ }
1412
+
1413
+ timelapseBuffer.push({
1414
+ frameNumber: frameCounter++,
1415
+ gameTime: gameTime,
1416
+ timestamp: Date.now(),
1417
+ bciIntent: currentIntent,
1418
+ playerState: {
1419
+ position: camera.position.toArray(),
1420
+ rotation: [camera.rotation.x, camera.rotation.y, camera.rotation.z],
1421
+ velocity: velocity.toArray()
1422
+ },
1423
+ gameState: {
1424
+ level: level,
1425
+ ammo: currentAmmo,
1426
+ kills: kills,
1427
+ drones: drones.length
1428
+ }
1429
+ });
1430
+ }
1431
+
1432
+ function captureTimelapseFrame(triggerType = 'MANUAL') {
1433
+ if (timelapseSequence.length >= CONFIG.TIMELAPSE.MAX_FRAMES) {
1434
+ showBCIStatus("Max frames reached", "error");
1435
+ return null;
1436
+ }
1437
+
1438
+ try {
1439
+ const timestamp = Date.now();
1440
+ const frameId = `frame_${timestamp}_${timelapseSequence.length}`;
1441
+
1442
+ // Capture canvas frame
1443
+ const imageData = captureCanvasFrame();
1444
+
1445
+ if (!imageData) return null;
1446
+
1447
+ // Get buffered game state
1448
+ const recentState = timelapseBuffer.length > 0 ?
1449
+ timelapseBuffer[timelapseBuffer.length - 1] :
1450
+ getCurrentGameState();
1451
+
1452
+ // Create timelapse frame
1453
+ const frame = {
1454
+ frame_id: frameId,
1455
+ sequence_id: currentSequence,
1456
+ frame_number: timelapseSequence.length,
1457
+ timestamp: timestamp,
1458
+ game_time: gameTime,
1459
+ trigger_type: triggerType,
1460
+ bci_intent: currentIntent,
1461
+
1462
+ // Image data
1463
+ image_data: imageData,
1464
+ image_format: CONFIG.TIMELAPSE.FORMAT,
1465
+ image_resolution: CONFIG.TIMELAPSE.RESOLUTION,
1466
+
1467
+ // Game state synchronized with frame
1468
+ game_state: {
1469
+ player_position: camera.position.toArray(),
1470
+ player_rotation: [camera.rotation.x, camera.rotation.y, camera.rotation.z],
1471
+ velocity: velocity.toArray(),
1472
+ is_grounded: isGrounded,
1473
+
1474
+ combat_state: {
1475
+ ammo: currentAmmo,
1476
+ is_reloading: isReloading,
1477
+ shots_fired: shotsFired,
1478
+ shots_hit: shotsHit,
1479
+ accuracy: accuracy
1480
+ },
1481
+
1482
+ game_stats: {
1483
+ level: level,
1484
+ exp: exp,
1485
+ required_exp: requiredExp,
1486
+ kills: kills
1487
+ },
1488
+
1489
+ environment: {
1490
+ drones_active: drones.length,
1491
+ bullets_active: bullets.length
1492
+ }
1493
+ },
1494
+
1495
+ // Input data for RLHF
1496
+ input_data: {
1497
+ mouse_position: { x: mouse.x, y: mouse.y },
1498
+ mouse_movement: { dx: mouse.dx, dy: mouse.dy },
1499
+ mouse_buttons: {
1500
+ lmb: mouse.lmbPressed,
1501
+ lmb_hold_duration: mouse.lmbPressed ? Date.now() - mouse.lmbHoldStart : 0
1502
+ },
1503
+ controls: {
1504
+ forward: controls.w,
1505
+ backward: controls.s,
1506
+ left: controls.a,
1507
+ right: controls.d,
1508
+ jump: controls.space
1509
+ },
1510
+ joystick: {
1511
+ active: joystickActive,
1512
+ vector: { x: joystickVector.x, y: joystickVector.y }
1513
+ }
1514
+ },
1515
+
1516
+ // RLHF data
1517
+ rlhf_data: {
1518
+ is_rlhf_event: CONFIG.RLHF_EVENTS.includes(triggerType),
1519
+ auto_rating: CONFIG.RLHF_AUTO_RATINGS[triggerType] || null,
1520
+ trigger_type: triggerType
1521
+ }
1522
+ };
1523
+
1524
+ timelapseSequence.push(frame);
1525
+
1526
+ // Show capture indicator
1527
+ showCapturePulse();
1528
+
1529
+ // Update UI
1530
+ document.getElementById('timelapseCount').textContent = timelapseSequence.length;
1531
+
1532
+ // Show preview
1533
+ showTimelapsePreview(imageData);
1534
+
1535
+ // Record intent
1536
+ recordBCIIntent('TIMELAPSE_CAPTURE');
1537
+
1538
+ console.log(`Timelapse frame captured: ${frameId} (${triggerType})`);
1539
+ return frame;
1540
+
1541
+ } catch (error) {
1542
+ console.error('Error capturing timelapse frame:', error);
1543
+ return null;
1544
+ }
1545
+ }
1546
+
1547
+ function captureBurstFrames(count) {
1548
+ if (captureMode !== CONFIG.CAPTURE_MODES.MANUAL) return;
1549
+
1550
+ showBCIStatus(`Burst capture: ${count} frames`);
1551
+
1552
+ let captured = 0;
1553
+ const burstInterval = setInterval(() => {
1554
+ if (captured < count && timelapseSequence.length < CONFIG.TIMELAPSE.MAX_FRAMES) {
1555
+ captureTimelapseFrame('BURST_MANUAL');
1556
+ captured++;
1557
+ } else {
1558
+ clearInterval(burstInterval);
1559
+ }
1560
+ }, 100); // 10 FPS burst
1561
+ }
1562
+
1563
+ function manualCapture() {
1564
+ if (captureMode === CONFIG.CAPTURE_MODES.MANUAL) {
1565
+ captureTimelapseFrame('KEYBOARD_MANUAL');
1566
+ }
1567
+ }
1568
+
1569
+ function captureCanvasFrame() {
1570
+ try {
1571
+ const canvas = renderer.domElement;
1572
+
1573
+ // Create off-screen canvas for resizing
1574
+ const offscreen = document.createElement('canvas');
1575
+ offscreen.width = CONFIG.TIMELAPSE.RESOLUTION.width;
1576
+ offscreen.height = CONFIG.TIMELAPSE.RESOLUTION.height;
1577
+
1578
+ const ctx = offscreen.getContext('2d');
1579
+
1580
+ // Draw and resize canvas
1581
+ ctx.drawImage(canvas,
1582
+ 0, 0, canvas.width, canvas.height,
1583
+ 0, 0, offscreen.width, offscreen.height);
1584
+
1585
+ // Convert to Base64
1586
+ return offscreen.toDataURL(CONFIG.TIMELAPSE.FORMAT, CONFIG.TIMELAPSE.QUALITY);
1587
+
1588
+ } catch (error) {
1589
+ console.error('Error capturing canvas frame:', error);
1590
+ return null;
1591
+ }
1592
+ }
1593
+
1594
+ function getCurrentGameState() {
1595
+ return {
1596
+ frameNumber: timelapseSequence.length,
1597
+ gameTime: gameTime,
1598
+ timestamp: Date.now(),
1599
+ bciIntent: currentIntent,
1600
+ playerState: {
1601
+ position: camera.position.toArray(),
1602
+ rotation: [camera.rotation.x, camera.rotation.y, camera.rotation.z],
1603
+ velocity: velocity.toArray()
1604
+ },
1605
+ gameState: {
1606
+ level: level,
1607
+ ammo: currentAmmo,
1608
+ kills: kills,
1609
+ drones: drones.length
1610
+ }
1611
+ };
1612
+ }
1613
+
1614
+ function showCapturePulse() {
1615
+ const pulse = document.createElement('div');
1616
+ pulse.className = 'capture-pulse';
1617
+ document.body.appendChild(pulse);
1618
+
1619
+ setTimeout(() => {
1620
+ if (pulse.parentNode) {
1621
+ pulse.parentNode.removeChild(pulse);
1622
+ }
1623
+ }, 500);
1624
+ }
1625
+
1626
+ function showTimelapsePreview(imageData) {
1627
+ const preview = document.getElementById('timelapsePreview');
1628
+ if (!preview) return;
1629
+
1630
+ const img = new Image();
1631
+ img.onload = function() {
1632
+ const ctx = preview.getContext('2d');
1633
+ ctx.clearRect(0, 0, preview.width, preview.height);
1634
+ ctx.drawImage(img, 0, 0, preview.width, preview.height);
1635
+
1636
+ preview.style.display = 'block';
1637
+ setTimeout(() => {
1638
+ preview.style.display = 'none';
1639
+ }, 2000);
1640
+ };
1641
+ img.src = imageData;
1642
+ }
1643
+
1644
+ function finalizeSequence() {
1645
+ if (timelapseBuffer.length === 0) return;
1646
+
1647
+ // Create sequence summary
1648
+ const sequence = {
1649
+ sequence_id: currentSequence,
1650
+ start_time: timelapseBuffer[0].timestamp,
1651
+ end_time: timelapseBuffer[timelapseBuffer.length - 1].timestamp,
1652
+ duration: timelapseBuffer[timelapseBuffer.length - 1].timestamp - timelapseBuffer[0].timestamp,
1653
+ frame_count: timelapseBuffer.length,
1654
+ frames: [...timelapseBuffer]
1655
+ };
1656
+
1657
+ console.log(`Sequence ${currentSequence} finalized: ${sequence.frame_count} frames`);
1658
+ showBCIStatus(`Sequence ${currentSequence}: ${sequence.frame_count} frames`);
1659
+ }
1660
+
1661
+ function stopTimelapseRecording() {
1662
+ if (captureInterval) {
1663
+ clearInterval(captureInterval);
1664
+ captureInterval = null;
1665
+ }
1666
+ isRecordingTimelapse = false;
1667
+ }
1668
+
1669
+ // ========== EXPORT SYSTEM ==========
1670
+ async function exportTimelapseDataset() {
1671
+ if (timelapseSequence.length < 10) {
1672
+ showBCIStatus("Need at least 10 timelapse frames", "error");
1673
+ return;
1674
+ }
1675
+
1676
+ try {
1677
+ // Show progress
1678
+ const progressDiv = document.getElementById('exportProgress');
1679
+ const progressBar = document.getElementById('progressBar');
1680
+ const progressText = document.getElementById('progressText');
1681
+
1682
+ progressDiv.style.display = 'block';
1683
+ progressText.textContent = "Preparing timelapse dataset...";
1684
+ progressBar.style.width = '0%';
1685
+
1686
+ // Create ZIP
1687
+ const zip = new JSZip();
1688
+ const sessionId = `bci_timelapse_${Date.now()}`;
1689
+
1690
+ // 1. Export timelapse frames metadata
1691
+ progressText.textContent = "Exporting frame metadata...";
1692
+ progressBar.style.width = '20%';
1693
+
1694
+ const framesJsonl = timelapseSequence.map(frame => {
1695
+ const frameCopy = { ...frame };
1696
+ frameCopy.image_filename = `frames/${frame.frame_id}.jpg`;
1697
+ delete frameCopy.image_data;
1698
+ return JSON.stringify(frameCopy);
1699
+ }).join('\n');
1700
+
1701
+ zip.file("timelapse_frames.jsonl", framesJsonl);
1702
+
1703
+ // 2. Export sequence data
1704
+ progressText.textContent = "Exporting sequence data...";
1705
+ progressBar.style.width = '35%';
1706
+
1707
+ const sequences = groupFramesBySequence();
1708
+ const sequencesJson = JSON.stringify(sequences, null, 2);
1709
+ zip.file("sequences.json", sequencesJson);
1710
+
1711
+ // 3. Export BCI intents
1712
+ progressText.textContent = "Exporting BCI intents...";
1713
+ progressBar.style.width = '45%';
1714
+
1715
+ const intentsJsonl = intentHistory.map(i => JSON.stringify(i)).join('\n');
1716
+ zip.file("bci_intents.jsonl", intentsJsonl);
1717
+
1718
+ // 4. Export frames as images
1719
+ progressText.textContent = "Processing frames...";
1720
+ progressBar.style.width = '60%';
1721
+
1722
+ const framesFolder = zip.folder("frames");
1723
+ let frameCount = 0;
1724
+ const totalFrames = timelapseSequence.length;
1725
+
1726
+ for (let i = 0; i < timelapseSequence.length; i++) {
1727
+ const frame = timelapseSequence[i];
1728
+ if (frame.image_data) {
1729
+ // Convert Base64 to binary
1730
+ const base64Data = frame.image_data.split(',')[1];
1731
+ const binaryData = atob(base64Data);
1732
+ const array = new Uint8Array(binaryData.length);
1733
+ for (let j = 0; j < binaryData.length; j++) {
1734
+ array[j] = binaryData.charCodeAt(j);
1735
+ }
1736
+ framesFolder.file(`${frame.frame_id}.jpg`, array);
1737
+ frameCount++;
1738
+
1739
+ // Update progress
1740
+ if (i % 10 === 0) {
1741
+ progressBar.style.width = `${60 + (i / totalFrames * 30)}%`;
1742
+ }
1743
+ }
1744
+ }
1745
+
1746
+ // 5. Export metadata
1747
+ progressText.textContent = "Generating metadata...";
1748
+ progressBar.style.width = '90%';
1749
+
1750
+ const metadata = generateTimelapseMetadata();
1751
+ zip.file("metadata.json", JSON.stringify(metadata, null, 2));
1752
+
1753
+ // 6. Export README
1754
+ const readme = generateTimelapseREADME();
1755
+ zip.file("README.md", readme);
1756
+
1757
+ // Generate ZIP
1758
+ progressText.textContent = "Creating ZIP archive...";
1759
+ progressBar.style.width = '95%';
1760
+
1761
+ const zipBlob = await zip.generateAsync({
1762
+ type: "blob",
1763
+ compression: "DEFLATE",
1764
+ compressionOptions: { level: 5 }
1765
+ });
1766
+
1767
+ // Download
1768
+ saveAs(zipBlob, `${sessionId}_timelapse_dataset.zip`);
1769
+
1770
+ // Complete
1771
+ progressText.textContent = "Export complete!";
1772
+ progressBar.style.width = '100%';
1773
+
1774
+ setTimeout(() => {
1775
+ progressDiv.style.display = 'none';
1776
+ showBCIStatus(`Dataset exported (${(zipBlob.size/1024/1024).toFixed(2)}MB)`);
1777
+ }, 1000);
1778
+
1779
+ } catch (error) {
1780
+ console.error('Export failed:', error);
1781
+ showBCIStatus(`Export failed: ${error.message}`, "error");
1782
+
1783
+ const progressDiv = document.getElementById('exportProgress');
1784
+ if (progressDiv) {
1785
+ progressDiv.style.display = 'none';
1786
+ }
1787
+ }
1788
+ }
1789
+
1790
+ function groupFramesBySequence() {
1791
+ const sequences = {};
1792
+
1793
+ timelapseSequence.forEach(frame => {
1794
+ const seqId = frame.sequence_id;
1795
+ if (!sequences[seqId]) {
1796
+ sequences[seqId] = {
1797
+ sequence_id: seqId,
1798
+ frames: [],
1799
+ start_time: frame.timestamp,
1800
+ end_time: frame.timestamp,
1801
+ trigger_types: new Set()
1802
+ };
1803
+ }
1804
+
1805
+ sequences[seqId].frames.push({
1806
+ frame_id: frame.frame_id,
1807
+ frame_number: frame.frame_number,
1808
+ timestamp: frame.timestamp,
1809
+ game_time: frame.game_time,
1810
+ trigger_type: frame.trigger_type,
1811
+ bci_intent: frame.bci_intent
1812
+ });
1813
+
1814
+ sequences[seqId].end_time = frame.timestamp;
1815
+ sequences[seqId].trigger_types.add(frame.trigger_type);
1816
+ });
1817
+
1818
+ // Convert sets to arrays
1819
+ Object.values(sequences).forEach(seq => {
1820
+ seq.trigger_types = Array.from(seq.trigger_types);
1821
+ seq.duration = seq.end_time - seq.start_time;
1822
+ seq.frame_count = seq.frames.length;
1823
+ });
1824
+
1825
+ return sequences;
1826
+ }
1827
+
1828
+ function generateTimelapseMetadata() {
1829
+ const sequences = groupFramesBySequence();
1830
+ const rlhfEvents = timelapseSequence.filter(f => f.rlhf_data.is_rlhf_event);
1831
+
1832
+ return {
1833
+ dataset_info: {
1834
+ name: "DATASTRIKE_BCI_TIMELAPSE_DATASET",
1835
+ version: "4.0.0",
1836
+ description: "Time-synchronized multimodal BCI dataset with frame-by-frame timelapse capture",
1837
+ license: "MIT",
1838
+ created_at: new Date().toISOString()
1839
+ },
1840
+
1841
+ timelapse_info: {
1842
+ total_frames: timelapseSequence.length,
1843
+ sequences: Object.keys(sequences).length,
1844
+ frame_resolution: CONFIG.TIMELAPSE.RESOLUTION,
1845
+ frame_format: "jpg",
1846
+ quality: CONFIG.TIMELAPSE.QUALITY,
1847
+ max_frames: CONFIG.TIMELAPSE.MAX_FRAMES,
1848
+ capture_modes: Object.values(CONFIG.CAPTURE_MODES),
1849
+ current_mode: captureMode
1850
+ },
1851
+
1852
+ rlhf_data: {
1853
+ total_events: rlhfEvents.length,
1854
+ event_types: Array.from(new Set(rlhfEvents.map(f => f.trigger_type))),
1855
+ coverage: (rlhfEvents.length / Math.max(1, timelapseSequence.length)) * 100
1856
+ },
1857
+
1858
+ bci_data: {
1859
+ intent_categories: CONFIG.BCI_INTENT_TYPES,
1860
+ intent_samples: intentHistory.length,
1861
+ current_intent: currentIntent
1862
+ },
1863
+
1864
+ game_stats: {
1865
+ session_duration: formatTime(gameTime),
1866
+ player_level: level,
1867
+ total_kills: kills,
1868
+ accuracy_percentage: accuracy,
1869
+ shots_fired: shotsFired,
1870
+ shots_hit: shotsHit
1871
+ },
1872
+
1873
+ performance: {
1874
+ average_fps: fps,
1875
+ frame_counter: frameCounter
1876
+ }
1877
+ };
1878
+ }
1879
+
1880
+ function generateTimelapseREADME() {
1881
+ const date = new Date().toISOString().split('T')[0];
1882
+ const duration = formatTime(gameTime);
1883
+ const sequences = groupFramesBySequence();
1884
+
1885
+ return `# DATASTRIKE BCI Timelapse Dataset
1886
+
1887
+ ## Description
1888
+ Time-synchronized multimodal dataset for BCI intent recognition, collected with frame-by-frame timelapse capture during FPS gameplay.
1889
+
1890
+ ## Key Features
1891
+ - **Frame-by-Frame Timelapse**: Synchronized image sequences at 320x240 resolution
1892
+ - **Multiple Capture Modes**: Manual (LMB), Auto-interval, and Sequence recording
1893
+ - **BCI Intent Labels**: 13 intent categories including timelapse capture events
1894
+ - **Time-Synced Game State**: Every frame includes synchronized game state data
1895
+ - **RLHF Data**: Automated ratings for combat events and capture actions
1896
+ - **Sequence Analysis**: Grouped frames into temporal sequences for time-series analysis
1897
+
1898
+ ## Dataset Structure
1899
+ - \`timelapse_frames.jsonl\`: Frame metadata (one per line)
1900
+ - \`frames/\`: JPG images for each frame
1901
+ - \`sequences.json\`: Temporal grouping of frames
1902
+ - \`bci_intents.jsonl\`: BCI intent transition history
1903
+ - \`metadata.json\`: Dataset statistics and configuration
1904
+ - \`README.md\`: This documentation
1905
+
1906
+ ## Capture Modes
1907
+ 1. **MANUAL**: LMB click captures single frame (hold for burst)
1908
+ 2. **AUTO**: Automatic capture at ${CONFIG.TIMELAPSE.AUTO_INTERVAL}ms intervals
1909
+ 3. **SEQUENCE**: Start/stop recording for continuous frame sequences
1910
+
1911
+ ## Dataset Statistics
1912
+ - **Total Frames**: ${timelapseSequence.length}
1913
+ - **Sequences**: ${Object.keys(sequences).length}
1914
+ - **Session Duration**: ${duration}
1915
+ - **Player Level**: ${level}
1916
+ - **Accuracy**: ${accuracy}%
1917
+ - **Total Kills**: ${kills}
1918
+
1919
+ ## Frame Data Structure
1920
+ Each frame includes:
1921
+ - Image data (320x240 JPG)
1922
+ - Timestamp and game time
1923
+ - BCI intent label
1924
+ - Full game state (position, rotation, velocity, ammo, etc.)
1925
+ - Input data (mouse movements, keyboard state)
1926
+ - RLHF rating (if applicable)
1927
+
1928
+ ## Usage for BCI Research
1929
+ \`\`\`python
1930
+ import json
1931
+ import cv2
1932
+ import numpy as np
1933
+
1934
+ # Load frame metadata
1935
+ frames = []
1936
+ with open('timelapse_frames.jsonl', 'r') as f:
1937
+ for line in f:
1938
+ frames.append(json.loads(line))
1939
+
1940
+ # Create time-series dataset
1941
+ X_images = []
1942
+ X_game_state = []
1943
+ y_intents = []
1944
+
1945
+ for frame in frames:
1946
+ # Load image
1947
+ img_path = f"frames/{frame['image_filename'].split('/')[1]}"
1948
+ img = cv2.imread(img_path)
1949
+ X_images.append(img)
1950
+
1951
+ # Game state features
1952
+ game_state = frame['game_state']
1953
+ features = [
1954
+ game_state['player_position'][0], # x
1955
+ game_state['player_position'][2], # z
1956
+ game_state['combat_state']['ammo'],
1957
+ game_state['game_stats']['level']
1958
+ ]
1959
+ X_game_state.append(features)
1960
+
1961
+ # BCI intent label
1962
+ y_intents.append(frame['bci_intent'])
1963
+
1964
+ # For sequence modeling
1965
+ sequences = json.load(open('sequences.json', 'r'))
1966
+ for seq_id, sequence in sequences.items():
1967
+ seq_frames = [f for f in frames if f['sequence_id'] == int(seq_id)]
1968
+ # Process as temporal sequence for LSTM/Transformer models
1969
+ \`\`\`
1970
+
1971
+ ## Citation
1972
+ \`\`\`
1973
+ @dataset{datastrike_bci_timelapse_2026,
1974
+ title={DATASTRIKE BCI Timelapse Dataset},
1975
+ author={DATASTRIKE Team},
1976
+ year={2026},
1977
+ url={https://github.com/webxos/datastrike-bci},
1978
+ note={Frame-by-frame timelapse capture for BCI intent recognition}
1979
+ }
1980
+ \`\`\`
1981
+
1982
+ Generated on ${date} by DATASTRIKE BCI Timelapse v4.0
1983
+ `;
1984
+ }
1985
+
1986
+ function formatTime(seconds) {
1987
+ const mins = Math.floor(seconds / 60);
1988
+ const secs = Math.floor(seconds % 60);
1989
+ return `${mins.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`;
1990
+ }
1991
+
1992
+ // ========== INITIALIZATION ==========
1993
+ window.addEventListener('load', () => {
1994
+ let progress = 0;
1995
+ const loadInterval = setInterval(() => {
1996
+ progress += Math.random() * 15;
1997
+ if (progress > 85) {
1998
+ progress = 85;
1999
+ }
2000
+ updateLoader(progress, "Loading BCI Timelapse Capture...");
2001
+ }, 150);
2002
+
2003
+ setTimeout(() => {
2004
+ clearInterval(loadInterval);
2005
+ init();
2006
+ }, 1200);
2007
+ });
2008
+
2009
+ // Mobile detection
2010
+ if ('ontouchstart' in window || navigator.maxTouchPoints) {
2011
+ document.querySelector('.mobile-controls').style.display = 'block';
2012
+ }
2013
+ </script>
2014
+ </body>
2015
+ </html>