@buley/hexgrid-3d 1.1.0 → 1.1.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.
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Adapter for Zero-Copy Data Sync between Dash 2.0 and HexGrid-3D.
3
+ *
4
+ * This adapter subscribes to a Dash "LiveQuery" which returns pointers to shared memory (SharedArrayBuffer)
5
+ * or Float32Arrays. It then syncs this data directly to the HexGridWasm instance.
6
+ */
7
+
8
+ // Placeholder types until we link the actual Dash package
9
+ interface DashQueryHandle {
10
+ ptr: number;
11
+ size: number;
12
+ buffer: SharedArrayBuffer | ArrayBuffer;
13
+ }
14
+
15
+ export class DashAdapter {
16
+ private dash: any; // Will be typed when we link @buley/dash
17
+
18
+ constructor(dashInstance: any) {
19
+ this.dash = dashInstance;
20
+ }
21
+
22
+ /**
23
+ * Subscribe to a semantic query in Dash and sync results to HexGrid.
24
+ *
25
+ * @param query The vector search query
26
+ * @param gridInstance The WASM instance of the HexGrid
27
+ */
28
+ bindSemanticSearch(query: string, particleSystem: any) {
29
+ console.log('[DashAdapter] Binding semantic search:', query);
30
+
31
+ // Hypothetical Zero-Copy API from Dash 2.0
32
+ if (this.dash.liveQueryPtr) {
33
+ this.dash.liveQueryPtr(`SELECT embedding FROM dash_vec_idx WHERE embedding MATCH '${query}'`).subscribe((handle: DashQueryHandle) => {
34
+ console.log(`[DashAdapter] Received ${handle.size} bytes from Dash.`);
35
+
36
+ // Assume the handle.buffer contains [pos, color, scale] interleaved or tightly packed
37
+ // For this MVP, we treat it as just positions
38
+ const floatView = new Float32Array(handle.buffer);
39
+
40
+ // Zero-Copy Injection logic would go here
41
+ // We can't strictly "inject" one buffer into 3 separate Float32Arrays unless they are contiguous in the SAB
42
+ // or we create views into offsets.
43
+
44
+ // Hypothetical offset logic:
45
+ const count = handle.size / 4 / 7; // pos + color + scale = 3+3+1 = 7 floats
46
+
47
+ // particleSystem.setSharedBuffers({
48
+ // positions: floatView.subarray(0, count * 3),
49
+ // colors: floatView.subarray(count * 3, count * 6),
50
+ // scales: floatView.subarray(count * 6, count * 7)
51
+ // });
52
+ });
53
+ } else {
54
+ console.warn('[DashAdapter] Dash instance does not support Zero-Copy liveQueryPtr yet.');
55
+ }
56
+ }
57
+ }
@@ -88,6 +88,12 @@ export interface ParticleSystem3DConfig {
88
88
  boundsCenter?: Vector3;
89
89
  /** Bounce factor when hitting bounds (0 = absorb, 1 = perfect bounce) */
90
90
  bounceFactor?: number;
91
+ /** Zero-copy shared buffers */
92
+ sharedBuffers?: {
93
+ positions: Float32Array;
94
+ colors: Float32Array;
95
+ scales: Float32Array;
96
+ };
91
97
  }
92
98
 
93
99
  /**
@@ -134,10 +140,25 @@ export class ParticleSystem3D {
134
140
  this.boundsCenter = config.boundsCenter ?? new Vector3(0, 0, 0);
135
141
  this.bounceFactor = config.bounceFactor ?? 0.5;
136
142
 
137
- // Pre-allocate buffers
138
- this.positionBuffer = new Float32Array(this.maxParticles * 3);
139
- this.colorBuffer = new Float32Array(this.maxParticles * 3);
140
- this.scaleBuffer = new Float32Array(this.maxParticles);
143
+ // Pre-allocate buffers (unless provided via config for zero-copy)
144
+ if (config.sharedBuffers) {
145
+ this.positionBuffer = config.sharedBuffers.positions;
146
+ this.colorBuffer = config.sharedBuffers.colors;
147
+ this.scaleBuffer = config.sharedBuffers.scales;
148
+ } else {
149
+ this.positionBuffer = new Float32Array(this.maxParticles * 3);
150
+ this.colorBuffer = new Float32Array(this.maxParticles * 3);
151
+ this.scaleBuffer = new Float32Array(this.maxParticles);
152
+ }
153
+ }
154
+
155
+ /**
156
+ * Zero-Copy Binding: Inject shared buffers from WASM/Dash
157
+ */
158
+ setSharedBuffers(buffers: { positions: Float32Array, colors: Float32Array, scales: Float32Array }) {
159
+ this.positionBuffer = buffers.positions;
160
+ this.colorBuffer = buffers.colors;
161
+ this.scaleBuffer = buffers.scales;
141
162
  }
142
163
 
143
164
  /**
@@ -197,7 +197,7 @@ export const NarrationOverlay: React.FC<NarrationOverlayProps> = ({
197
197
  borderRadius: 4,
198
198
  }}
199
199
  >
200
- {leaderboard.map((entry, i) => (
200
+ {leaderboard.map((entry: any, i: number) => (
201
201
  <div
202
202
  key={entry.photoId}
203
203
  style={{
@@ -0,0 +1,17 @@
1
+ export interface NarrationMessage {
2
+ generation: number;
3
+ timestamp: string;
4
+ priority: number;
5
+ text: string;
6
+ eventType?: string;
7
+ sparkline?: string;
8
+ }
9
+
10
+ export class NarrationManager {
11
+ static getInstance(): any {
12
+ return {
13
+ subscribe: () => () => {},
14
+ getState: () => ({})
15
+ };
16
+ }
17
+ }
@@ -0,0 +1,25 @@
1
+ export class StatsTracker {
2
+ static getInstance(): StatsTracker {
3
+ return new StatsTracker();
4
+ }
5
+
6
+ getCurrentStats(): any {
7
+ return {
8
+ generation: 1,
9
+ activeMemesCount: 10,
10
+ totalHexesInfected: 100,
11
+ populationStability: 0.5
12
+ };
13
+ }
14
+
15
+ getAllTimeRecords(): any {
16
+ return {
17
+ highestTerritory: { value: 100 },
18
+ longestSurvivalStreak: { value: 50 }
19
+ };
20
+ }
21
+
22
+ getLeaderboard(limit: number): any[] {
23
+ return [];
24
+ }
25
+ }
@@ -0,0 +1,12 @@
1
+ export const ThemeColors = {
2
+ primary: '#000000',
3
+ secondary: '#ffffff'
4
+ };
5
+
6
+ export function getAccentRgba(alpha: number = 1): string {
7
+ return `rgba(0, 255, 255, ${alpha})`;
8
+ }
9
+
10
+ export function getAccentHex(): string {
11
+ return '#00ffff';
12
+ }