@cazala/party 0.1.1 → 0.1.2
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.
package/dist/index.js
CHANGED
|
@@ -2366,7 +2366,35 @@ fn grid_cell_index(pos: vec2<f32>) -> u32 { let col = i32(floor((pos.x - GRID_MI
|
|
|
2366
2366
|
fn grid_cell_index_from_rc(r: i32, c: i32) -> u32 { let rr = max(0, min(r, i32(GRID_ROWS()) - 1)); let cc = max(0, min(c, i32(GRID_COLS()) - 1)); return u32(rr) * GRID_COLS() + u32(cc); }
|
|
2367
2367
|
struct NeighborIter { cx: i32, cy: i32, r: i32, c: i32, k: u32, reach: i32, maxK: u32, base: u32, emitted: u32, maxEmit: u32 }
|
|
2368
2368
|
fn neighbor_iter_init(pos: vec2<f32>, radius: f32) -> NeighborIter { let cx = i32(floor((pos.x - GRID_MINX()) / GRID_CELL_SIZE())); let cy = i32(floor((pos.y - GRID_MINY()) / GRID_CELL_SIZE())); let reach = max(1, i32(ceil(radius / GRID_CELL_SIZE()))); var it: NeighborIter; it.cx = cx; it.cy = cy; it.reach = reach; it.r = cy - reach; it.c = cx - reach; let firstCell = grid_cell_index_from_rc(it.r, it.c); let cnt = atomicLoad(&GRID_COUNTS[firstCell]); it.maxK = min(cnt, GRID_MAX_PER_CELL()); it.base = firstCell * GRID_MAX_PER_CELL(); it.k = 0u; it.emitted = 0u; it.maxEmit = max(1u, SIM_MAX_NEIGHBORS()); return it; }
|
|
2369
|
-
fn neighbor_iter_next(it: ptr<function, NeighborIter>, selfIndex: u32) -> u32 {
|
|
2369
|
+
fn neighbor_iter_next(it: ptr<function, NeighborIter>, selfIndex: u32) -> u32 {
|
|
2370
|
+
// Naga (Firefox) sometimes fails to prove that a loop always returns, so
|
|
2371
|
+
// we structure this as break + return result to keep validation happy.
|
|
2372
|
+
var result: u32 = NEIGHBOR_NONE;
|
|
2373
|
+
loop {
|
|
2374
|
+
if ((*it).emitted >= (*it).maxEmit) { break; }
|
|
2375
|
+
if ((*it).r > (*it).cy + (*it).reach) { break; }
|
|
2376
|
+
if ((*it).k < (*it).maxK) {
|
|
2377
|
+
let id = GRID_INDICES[(*it).base + (*it).k];
|
|
2378
|
+
(*it).k = (*it).k + 1u;
|
|
2379
|
+
if (id != selfIndex) {
|
|
2380
|
+
(*it).emitted = (*it).emitted + 1u;
|
|
2381
|
+
result = id;
|
|
2382
|
+
break;
|
|
2383
|
+
} else {
|
|
2384
|
+
continue;
|
|
2385
|
+
}
|
|
2386
|
+
}
|
|
2387
|
+
(*it).c = (*it).c + 1;
|
|
2388
|
+
if ((*it).c > (*it).cx + (*it).reach) { (*it).c = (*it).cx - (*it).reach; (*it).r = (*it).r + 1; }
|
|
2389
|
+
if ((*it).r > (*it).cy + (*it).reach) { break; }
|
|
2390
|
+
let cell = grid_cell_index_from_rc((*it).r, (*it).c);
|
|
2391
|
+
let cnt = atomicLoad(&GRID_COUNTS[cell]);
|
|
2392
|
+
(*it).maxK = min(cnt, GRID_MAX_PER_CELL());
|
|
2393
|
+
(*it).base = cell * GRID_MAX_PER_CELL();
|
|
2394
|
+
(*it).k = 0u;
|
|
2395
|
+
}
|
|
2396
|
+
return result;
|
|
2397
|
+
}`);
|
|
2370
2398
|
// Optional: allow force modules to inject globals
|
|
2371
2399
|
const addGlobal = (module, descriptor) => {
|
|
2372
2400
|
if (module.role !== ModuleRole.Force)
|