@holoscript/core 1.0.0-alpha.2 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/package.json +2 -2
  2. package/src/HoloScript2DParser.js +227 -0
  3. package/src/HoloScript2DParser.ts +5 -0
  4. package/src/HoloScriptCodeParser.js +1102 -0
  5. package/src/HoloScriptCodeParser.ts +145 -20
  6. package/src/HoloScriptDebugger.js +458 -0
  7. package/src/HoloScriptParser.js +338 -0
  8. package/src/HoloScriptPlusParser.js +371 -0
  9. package/src/HoloScriptPlusParser.ts +543 -0
  10. package/src/HoloScriptRuntime.js +1399 -0
  11. package/src/HoloScriptRuntime.test.js +351 -0
  12. package/src/HoloScriptRuntime.ts +17 -3
  13. package/src/HoloScriptTypeChecker.js +356 -0
  14. package/src/__tests__/GraphicsServices.test.js +357 -0
  15. package/src/__tests__/GraphicsServices.test.ts +427 -0
  16. package/src/__tests__/HoloScriptPlusParser.test.js +317 -0
  17. package/src/__tests__/HoloScriptPlusParser.test.ts +392 -0
  18. package/src/__tests__/integration.test.js +336 -0
  19. package/src/__tests__/performance.bench.js +218 -0
  20. package/src/__tests__/type-checker.test.js +60 -0
  21. package/src/__tests__/type-checker.test.ts +73 -0
  22. package/src/index.js +217 -0
  23. package/src/index.ts +158 -18
  24. package/src/interop/Interoperability.js +413 -0
  25. package/src/interop/Interoperability.ts +494 -0
  26. package/src/logger.js +42 -0
  27. package/src/parser/EnhancedParser.js +205 -0
  28. package/src/parser/EnhancedParser.ts +251 -0
  29. package/src/parser/HoloScriptPlusParser.js +928 -0
  30. package/src/parser/HoloScriptPlusParser.ts +1089 -0
  31. package/src/runtime/HoloScriptPlusRuntime.js +674 -0
  32. package/src/runtime/HoloScriptPlusRuntime.ts +861 -0
  33. package/src/runtime/PerformanceTelemetry.js +323 -0
  34. package/src/runtime/PerformanceTelemetry.ts +467 -0
  35. package/src/runtime/RuntimeOptimization.js +361 -0
  36. package/src/runtime/RuntimeOptimization.ts +416 -0
  37. package/src/services/HololandGraphicsPipelineService.js +506 -0
  38. package/src/services/HololandGraphicsPipelineService.ts +662 -0
  39. package/src/services/PlatformPerformanceOptimizer.js +356 -0
  40. package/src/services/PlatformPerformanceOptimizer.ts +503 -0
  41. package/src/state/ReactiveState.js +427 -0
  42. package/src/state/ReactiveState.ts +572 -0
  43. package/src/tools/DeveloperExperience.js +376 -0
  44. package/src/tools/DeveloperExperience.ts +438 -0
  45. package/src/traits/AIDriverTrait.js +322 -0
  46. package/src/traits/AIDriverTrait.test.js +329 -0
  47. package/src/traits/AIDriverTrait.test.ts +357 -0
  48. package/src/traits/AIDriverTrait.ts +474 -0
  49. package/src/traits/LightingTrait.js +313 -0
  50. package/src/traits/LightingTrait.test.js +410 -0
  51. package/src/traits/LightingTrait.test.ts +462 -0
  52. package/src/traits/LightingTrait.ts +505 -0
  53. package/src/traits/MaterialTrait.js +194 -0
  54. package/src/traits/MaterialTrait.test.js +286 -0
  55. package/src/traits/MaterialTrait.test.ts +329 -0
  56. package/src/traits/MaterialTrait.ts +324 -0
  57. package/src/traits/RenderingTrait.js +356 -0
  58. package/src/traits/RenderingTrait.test.js +363 -0
  59. package/src/traits/RenderingTrait.test.ts +427 -0
  60. package/src/traits/RenderingTrait.ts +555 -0
  61. package/src/traits/VRTraitSystem.js +740 -0
  62. package/src/traits/VRTraitSystem.ts +1040 -0
  63. package/src/traits/VoiceInputTrait.js +284 -0
  64. package/src/traits/VoiceInputTrait.test.js +226 -0
  65. package/src/traits/VoiceInputTrait.test.ts +252 -0
  66. package/src/traits/VoiceInputTrait.ts +401 -0
  67. package/src/types/AdvancedTypeSystem.js +226 -0
  68. package/src/types/AdvancedTypeSystem.ts +494 -0
  69. package/src/types/HoloScriptPlus.d.ts +853 -0
  70. package/src/types.js +6 -0
  71. package/src/types.ts +96 -1
  72. package/tsconfig.json +1 -1
  73. package/tsup.config.d.ts +2 -0
  74. package/tsup.config.js +18 -0
@@ -0,0 +1,356 @@
1
+ /**
2
+ * Platform Performance Optimization System
3
+ *
4
+ * Provides adaptive quality and performance tuning for:
5
+ * - Mobile devices (battery/bandwidth constrained)
6
+ * - VR/AR platforms (latency-critical, 90 FPS required)
7
+ * - Desktop (quality-focused, high resolution)
8
+ *
9
+ * Features:
10
+ * - Automatic quality adjustment based on device
11
+ * - Performance profiling and analysis
12
+ * - Bottleneck detection and mitigation
13
+ * - Cross-platform benchmark testing
14
+ */
15
+ // ============================================================================
16
+ // Platform Performance Optimizer
17
+ // ============================================================================
18
+ export class PlatformPerformanceOptimizer {
19
+ constructor(device) {
20
+ this.currentFPS = 60;
21
+ this.frameHistory = [];
22
+ this.lastAdaptTime = 0;
23
+ this.deviceInfo = device;
24
+ this.capabilities = this.detectCapabilities(device);
25
+ this.profile = this.createProfile(device);
26
+ this.adaptiveSettings = this.getAdaptiveSettings(device.platform);
27
+ }
28
+ /**
29
+ * Detect device capabilities
30
+ */
31
+ detectCapabilities(device) {
32
+ let maxTexture = 2048;
33
+ let supportsCompression = true;
34
+ let compressionFormats = ['dxt', 'basis'];
35
+ let maxLights = 4;
36
+ let shadowsSupported = true;
37
+ let computeSupported = false;
38
+ let rayTracingSupported = false;
39
+ // Mobile capabilities
40
+ if (device.platform === 'mobile') {
41
+ maxTexture = 512;
42
+ maxLights = 2;
43
+ shadowsSupported = false;
44
+ compressionFormats = ['astc', 'pvrtc'];
45
+ // Check for low memory
46
+ if (device.gpuMemory < 1024) {
47
+ maxTexture = 256;
48
+ maxLights = 1;
49
+ supportsCompression = true;
50
+ }
51
+ }
52
+ // VR capabilities
53
+ if (device.platform === 'vr') {
54
+ maxTexture = 2048;
55
+ maxLights = 4;
56
+ shadowsSupported = true;
57
+ compressionFormats = ['basis', 'dxt'];
58
+ computeSupported = true;
59
+ }
60
+ // Desktop capabilities
61
+ if (device.platform === 'desktop') {
62
+ maxTexture = 4096;
63
+ maxLights = 8;
64
+ shadowsSupported = true;
65
+ compressionFormats = ['none', 'dxt', 'basis'];
66
+ computeSupported = true;
67
+ rayTracingSupported = true;
68
+ }
69
+ return {
70
+ maxTextureResolution: maxTexture,
71
+ supportsCompression,
72
+ compressionFormats,
73
+ maxSimultaneousLights: maxLights,
74
+ shadowsSupported,
75
+ computeShaderSupported: computeSupported,
76
+ rayTracingSupported,
77
+ estimatedMemory: Math.min(device.gpuMemory, 2048),
78
+ };
79
+ }
80
+ /**
81
+ * Create performance profile for device
82
+ */
83
+ createProfile(device) {
84
+ let qualityLevel = 'high';
85
+ let fpsTarget = 60;
86
+ let fpsMin = 30;
87
+ let cpuBudget = 16.67; // ms for 60 FPS
88
+ let gpuBudget = 16.67; // ms for 60 FPS
89
+ // Mobile
90
+ if (device.platform === 'mobile') {
91
+ qualityLevel = 'low';
92
+ fpsTarget = 30;
93
+ fpsMin = 24;
94
+ cpuBudget = 33.33; // ms for 30 FPS
95
+ gpuBudget = 33.33; // ms for 30 FPS
96
+ }
97
+ // VR (more demanding)
98
+ if (device.platform === 'vr') {
99
+ qualityLevel = 'high';
100
+ fpsTarget = 90;
101
+ fpsMin = 75;
102
+ cpuBudget = 11.11; // ms for 90 FPS
103
+ gpuBudget = 11.11; // ms for 90 FPS
104
+ }
105
+ // Desktop (quality-focused)
106
+ if (device.platform === 'desktop') {
107
+ qualityLevel = 'ultra';
108
+ fpsTarget = device.refreshRate || 120;
109
+ fpsMin = 60;
110
+ cpuBudget = 1000 / fpsTarget;
111
+ gpuBudget = 1000 / fpsTarget;
112
+ }
113
+ return {
114
+ device,
115
+ capabilities: this.capabilities,
116
+ targetFPS: fpsTarget,
117
+ qualityLevel,
118
+ adaptiveQuality: device.platform === 'mobile' || device.platform === 'vr',
119
+ fpsTarget,
120
+ fpsMin,
121
+ cpuBudget,
122
+ gpuBudget,
123
+ };
124
+ }
125
+ /**
126
+ * Get adaptive quality settings for platform
127
+ */
128
+ getAdaptiveSettings(platform) {
129
+ if (platform === 'mobile') {
130
+ return {
131
+ enabled: true,
132
+ checkInterval: 500, // Check every 500ms
133
+ fpsDeltaThreshold: 5, // Adjust if FPS changes by 5+
134
+ memoryThreshold: 80, // Adjust if above 80% memory
135
+ temperatureThreshold: 45, // Adjust if above 45C
136
+ };
137
+ }
138
+ if (platform === 'vr') {
139
+ return {
140
+ enabled: true,
141
+ checkInterval: 300, // Check every 300ms
142
+ fpsDeltaThreshold: 3, // Adjust if FPS changes by 3+
143
+ memoryThreshold: 85, // Adjust if above 85% memory
144
+ };
145
+ }
146
+ // Desktop
147
+ return {
148
+ enabled: false, // No adaptive quality needed
149
+ checkInterval: 1000,
150
+ fpsDeltaThreshold: 0,
151
+ memoryThreshold: 90,
152
+ };
153
+ }
154
+ /**
155
+ * Optimize for device - returns recommended rendering settings
156
+ */
157
+ optimizeForDevice() {
158
+ const { platform, gpuMemory, isLowPowerMode } = this.deviceInfo;
159
+ const quality = this.profile.qualityLevel;
160
+ const settings = {
161
+ quality,
162
+ platform,
163
+ textureResolution: this.capabilities.maxTextureResolution,
164
+ compression: this.selectCompression(platform),
165
+ maxLights: this.capabilities.maxSimultaneousLights,
166
+ shadowsEnabled: this.capabilities.shadowsSupported,
167
+ lodEnabled: true,
168
+ cullingEnabled: true,
169
+ instancingEnabled: true,
170
+ gpuMemoryBudget: gpuMemory > 2048 ? 1024 : gpuMemory / 2,
171
+ };
172
+ // Mobile low power adjustments
173
+ if (isLowPowerMode && platform === 'mobile') {
174
+ settings.quality = 'low';
175
+ settings.textureResolution = 256;
176
+ settings.compression = 'astc';
177
+ settings.maxLights = 1;
178
+ settings.shadowsEnabled = false;
179
+ settings.lodEnabled = true;
180
+ settings.cullingEnabled = true;
181
+ }
182
+ return settings;
183
+ }
184
+ /**
185
+ * Select best compression format for platform
186
+ */
187
+ selectCompression(platform) {
188
+ const formats = this.capabilities.compressionFormats;
189
+ if (platform === 'mobile') {
190
+ return formats.includes('astc') ? 'astc' : formats[0];
191
+ }
192
+ if (platform === 'vr') {
193
+ return formats.includes('basis') ? 'basis' : formats[0];
194
+ }
195
+ // Desktop
196
+ return formats.includes('none') ? 'none' : formats[0];
197
+ }
198
+ /**
199
+ * Update frame metrics for adaptive quality
200
+ */
201
+ updateFrameMetrics(fps, gpuMemoryUsed, gpuFrameTime) {
202
+ this.currentFPS = fps;
203
+ this.frameHistory.push(fps);
204
+ // Keep only last 30 frames
205
+ if (this.frameHistory.length > 30) {
206
+ this.frameHistory.shift();
207
+ }
208
+ // Check if adaptation is needed
209
+ if (this.adaptiveSettings.enabled) {
210
+ const now = Date.now();
211
+ if (now - this.lastAdaptTime > this.adaptiveSettings.checkInterval) {
212
+ this.checkAndAdapt(fps, gpuMemoryUsed);
213
+ this.lastAdaptTime = now;
214
+ }
215
+ }
216
+ }
217
+ /**
218
+ * Check and adapt quality settings
219
+ */
220
+ checkAndAdapt(fps, gpuMemoryUsed) {
221
+ const avgFps = this.getAverageFPS();
222
+ const memoryPercent = (gpuMemoryUsed / this.profile.capabilities.estimatedMemory) * 100;
223
+ let shouldDegrade = false;
224
+ let shouldImprove = false;
225
+ // Check FPS
226
+ if (avgFps < this.profile.fpsMin) {
227
+ shouldDegrade = true;
228
+ }
229
+ else if (avgFps > this.profile.fpsTarget + this.adaptiveSettings.fpsDeltaThreshold) {
230
+ shouldImprove = true;
231
+ }
232
+ // Check memory
233
+ if (memoryPercent > this.adaptiveSettings.memoryThreshold) {
234
+ shouldDegrade = true;
235
+ }
236
+ if (shouldDegrade) {
237
+ this.degradeQuality();
238
+ }
239
+ else if (shouldImprove) {
240
+ this.improveQuality();
241
+ }
242
+ }
243
+ /**
244
+ * Degrade quality for better performance
245
+ */
246
+ degradeQuality() {
247
+ switch (this.profile.qualityLevel) {
248
+ case 'ultra':
249
+ this.profile.qualityLevel = 'high';
250
+ break;
251
+ case 'high':
252
+ this.profile.qualityLevel = 'medium';
253
+ break;
254
+ case 'medium':
255
+ this.profile.qualityLevel = 'low';
256
+ break;
257
+ case 'low':
258
+ // Already at minimum
259
+ break;
260
+ }
261
+ }
262
+ /**
263
+ * Improve quality for better visuals
264
+ */
265
+ improveQuality() {
266
+ switch (this.profile.qualityLevel) {
267
+ case 'low':
268
+ this.profile.qualityLevel = 'medium';
269
+ break;
270
+ case 'medium':
271
+ this.profile.qualityLevel = 'high';
272
+ break;
273
+ case 'high':
274
+ if (this.profile.device.platform === 'desktop') {
275
+ this.profile.qualityLevel = 'ultra';
276
+ }
277
+ break;
278
+ case 'ultra':
279
+ // Already at maximum
280
+ break;
281
+ }
282
+ }
283
+ /**
284
+ * Get average FPS from history
285
+ */
286
+ getAverageFPS() {
287
+ if (this.frameHistory.length === 0) {
288
+ return this.currentFPS;
289
+ }
290
+ const sum = this.frameHistory.reduce((a, b) => a + b, 0);
291
+ return sum / this.frameHistory.length;
292
+ }
293
+ /**
294
+ * Run performance benchmark
295
+ */
296
+ async runBenchmark(name, renderFunc) {
297
+ const iterations = this.getBenchmarkIterations();
298
+ console.log(`Running benchmark: ${name} (${iterations} iterations)...`);
299
+ const startTime = performance.now();
300
+ const result = await renderFunc(iterations);
301
+ const totalTime = performance.now() - startTime;
302
+ const fps = result.fps;
303
+ const passed = fps >= this.profile.fpsMin;
304
+ return {
305
+ testName: name,
306
+ platform: this.deviceInfo.platform,
307
+ fps,
308
+ gpuFrameTime: result.gpuTime,
309
+ cpuFrameTime: result.cpuTime,
310
+ gpuMemoryUsed: 0, // Would be populated from actual measurement
311
+ trianglesPerSecond: result.triangles * fps,
312
+ drawCallsPerSecond: result.drawCalls * fps,
313
+ qualityLevel: this.profile.qualityLevel,
314
+ passed,
315
+ };
316
+ }
317
+ /**
318
+ * Get benchmark iterations based on platform
319
+ */
320
+ getBenchmarkIterations() {
321
+ switch (this.deviceInfo.platform) {
322
+ case 'mobile':
323
+ return 100;
324
+ case 'vr':
325
+ return 200;
326
+ case 'desktop':
327
+ return 300;
328
+ }
329
+ }
330
+ /**
331
+ * Get current performance profile
332
+ */
333
+ getProfile() {
334
+ return { ...this.profile };
335
+ }
336
+ /**
337
+ * Get optimization recommendations
338
+ */
339
+ getRecommendations() {
340
+ const recommendations = [];
341
+ const avgFps = this.getAverageFPS();
342
+ if (avgFps < this.profile.fpsMin) {
343
+ recommendations.push(`FPS below target (${Math.round(avgFps)} < ${this.profile.fpsMin})`);
344
+ recommendations.push('Consider reducing quality preset');
345
+ recommendations.push('Enable texture compression');
346
+ recommendations.push('Reduce shadow quality');
347
+ }
348
+ if (this.profile.device.isLowPowerMode) {
349
+ recommendations.push('Device in low power mode');
350
+ recommendations.push('Consider reducing quality');
351
+ recommendations.push('Disable shadows and lights');
352
+ }
353
+ return recommendations;
354
+ }
355
+ }
356
+ export default PlatformPerformanceOptimizer;