@zaisma/effects 1.0.1 → 1.2.0

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/tables.js CHANGED
@@ -20,7 +20,7 @@ export function createTable(texelCount, rowCount) {
20
20
  texture.generateMipmaps = false;
21
21
  texture.needsUpdate = true;
22
22
  const freeRows = [];
23
- for (let row = rowCount - 1; row >= 0; row -= 1) freeRows.push(row);
23
+ for (let rowIndex = rowCount - 1; rowIndex >= 0; rowIndex -= 1) freeRows.push(rowIndex);
24
24
 
25
25
  return {
26
26
  texture,
@@ -37,11 +37,11 @@ export function createTable(texelCount, rowCount) {
37
37
  },
38
38
  /** Writes one texel of a row. */
39
39
  write(row, texelIndex, first, second, third, fourth) {
40
- const at = (row * texelCount + texelIndex) * 4;
41
- values[at] = first;
42
- values[at + 1] = second;
43
- values[at + 2] = third;
44
- values[at + 3] = fourth;
40
+ const floatIndex = (row * texelCount + texelIndex) * 4;
41
+ values[floatIndex] = first;
42
+ values[floatIndex + 1] = second;
43
+ values[floatIndex + 2] = third;
44
+ values[floatIndex + 3] = fourth;
45
45
  texture.needsUpdate = true;
46
46
  },
47
47
  dispose() {
@@ -66,32 +66,32 @@ export function createSlotPool(slotCount) {
66
66
  return freeCount;
67
67
  },
68
68
  /** The start of a free run of `count` slots (the first that fits), or -1. */
69
- take(count) {
69
+ take(wantedCount) {
70
70
  for (let index = 0; index < freeRuns.length; index += 1) {
71
71
  const run = freeRuns[index];
72
- if (run.count < count) continue;
73
- const start = run.start;
74
- run.start += count;
75
- run.count -= count;
72
+ if (run.count < wantedCount) continue;
73
+ const startIndex = run.start;
74
+ run.start += wantedCount;
75
+ run.count -= wantedCount;
76
76
  if (run.count === 0) freeRuns.splice(index, 1);
77
- freeCount -= count;
78
- return start;
77
+ freeCount -= wantedCount;
78
+ return startIndex;
79
79
  }
80
80
  return -1;
81
81
  },
82
82
  /** The longest free run's length: the most one emitter can still take. */
83
83
  longestFreeCount() {
84
- let longest = 0;
85
- for (const run of freeRuns) if (run.count > longest) longest = run.count;
86
- return longest;
84
+ let longestCount = 0;
85
+ for (const run of freeRuns) if (run.count > longestCount) longestCount = run.count;
86
+ return longestCount;
87
87
  },
88
- give(start, count) {
88
+ give(start, givenCount) {
89
89
  let index = 0;
90
90
  while (index < freeRuns.length && freeRuns[index].start < start) index += 1;
91
- freeRuns.splice(index, 0, { start, count });
92
- freeCount += count;
91
+ freeRuns.splice(index, 0, { start, count: givenCount });
92
+ freeCount += givenCount;
93
93
  const next = freeRuns[index + 1];
94
- if (next && start + count === next.start) {
94
+ if (next && start + givenCount === next.start) {
95
95
  freeRuns[index].count += next.count;
96
96
  freeRuns.splice(index + 1, 1);
97
97
  }
package/weather.js CHANGED
@@ -91,7 +91,7 @@ void main() {
91
91
  }`;
92
92
 
93
93
  const easeToward = (current, target, share, snap) => (Math.abs(target - current) <= snap ? target : current + (target - current) * share);
94
- const wrapInto = (value, size) => ((value % size) + size) % size;
94
+ const wrapInto = (positionM, sizeM) => ((positionM % sizeM) + sizeM) % sizeM;
95
95
 
96
96
  /**
97
97
  * Makes the weather. Its layers are elements like any effect's: index.js gives each a row and writes it in the look
@@ -212,16 +212,16 @@ export function createWeather({ sprites, sharedUniforms, scene, renderer, playRo
212
212
  */
213
213
  function update({ nowSec, frameSec, camera, target, changeDurationSec, groundHeightM, hasShelter }) {
214
214
  // What's set as the effects are made is the weather at once; later changes are eased to.
215
- const share = hasStarted && changeDurationSec > 0 ? Math.min((frameSec * 3) / changeDurationSec, 1) : 1;
215
+ const shareNumber = hasStarted && changeDurationSec > 0 ? Math.min((frameSec * 3) / changeDurationSec, 1) : 1;
216
216
  hasStarted = true;
217
- now.rainPct = easeToward(now.rainPct, target.rainPct, share, 0.5);
218
- now.snowPct = easeToward(now.snowPct, target.snowPct, share, 0.5);
219
- now.fogPct = easeToward(now.fogPct, target.fogPct, share, 0.5);
220
- now.windSpeedMPerSec = easeToward(now.windSpeedMPerSec, target.windSpeedMPerSec, share, 0.05);
221
- now.windGustPct = easeToward(now.windGustPct, target.windGustPct, share, 0.5);
217
+ now.rainPct = easeToward(now.rainPct, target.rainPct, shareNumber, 0.5);
218
+ now.snowPct = easeToward(now.snowPct, target.snowPct, shareNumber, 0.5);
219
+ now.fogPct = easeToward(now.fogPct, target.fogPct, shareNumber, 0.5);
220
+ now.windSpeedMPerSec = easeToward(now.windSpeedMPerSec, target.windSpeedMPerSec, shareNumber, 0.05);
221
+ now.windGustPct = easeToward(now.windGustPct, target.windGustPct, shareNumber, 0.5);
222
222
  // The wind turns the short way round.
223
223
  const turnDeg = ((((target.windDirectionDeg - now.windDirectionDeg) % 360) + 540) % 360) - 180;
224
- now.windDirectionDeg = Math.abs(turnDeg) <= 0.5 ? target.windDirectionDeg : wrapInto(now.windDirectionDeg + turnDeg * share, 360);
224
+ now.windDirectionDeg = Math.abs(turnDeg) <= 0.5 ? target.windDirectionDeg : wrapInto(now.windDirectionDeg + turnDeg * shareNumber, 360);
225
225
  now.isSettled = now.rainPct === target.rainPct && now.snowPct === target.snowPct && now.fogPct === target.fogPct && now.windSpeedMPerSec === target.windSpeedMPerSec && now.windGustPct === target.windGustPct && now.windDirectionDeg === target.windDirectionDeg;
226
226
 
227
227
  windAt(now, nowSec, windM);
@@ -231,29 +231,29 @@ export function createWeather({ sprites, sharedUniforms, scene, renderer, playRo
231
231
  camera.getWorldPosition(cameraPlace);
232
232
  camera.getWorldDirection(cameraWay);
233
233
  for (const layer of layers) {
234
- const layerShare = shareOf(layer);
235
- if (layerShare <= 0) {
234
+ const layerShareNumber = shareOf(layer);
235
+ if (layerShareNumber <= 0) {
236
236
  dropLayer(layer);
237
237
  continue;
238
238
  }
239
239
  fillLayer(layer);
240
- const [width, height, depth] = layer.boxM;
240
+ const [widthM, heightM, depthM] = layer.boxM;
241
241
  const index = layer.layerIndex;
242
- sharedUniforms.uWrapShare.value[index] = layerShare;
243
- sharedUniforms.uWrapBox.value[index].set(width, height, depth);
242
+ sharedUniforms.uWrapShare.value[index] = layerShareNumber;
243
+ sharedUniforms.uWrapBox.value[index].set(widthM, heightM, depthM);
244
244
  if (index === LANDING_LAYER_INDEX) {
245
- sharedUniforms.uWrapCenter.value[index].set(cameraPlace.x + cameraWay.x * width * 0.3, cameraPlace.y, cameraPlace.z + cameraWay.z * depth * 0.3);
245
+ sharedUniforms.uWrapCenter.value[index].set(cameraPlace.x + cameraWay.x * widthM * 0.3, cameraPlace.y, cameraPlace.z + cameraWay.z * depthM * 0.3);
246
246
  sharedUniforms.uWrapVelocity.value[index].set(LANDINGS_PER_SEC, 0, 0);
247
247
  continue;
248
248
  }
249
249
  const velocityX = windM.x * layer.windShare;
250
250
  const velocityZ = windM.z * layer.windShare;
251
- layer.shift.set(wrapInto(layer.shift.x + velocityX * frameSec, width), wrapInto(layer.shift.y - layer.fallMPerSec * frameSec, height), wrapInto(layer.shift.z + velocityZ * frameSec, depth));
251
+ layer.shift.set(wrapInto(layer.shift.x + velocityX * frameSec, widthM), wrapInto(layer.shift.y - layer.fallMPerSec * frameSec, heightM), wrapInto(layer.shift.z + velocityZ * frameSec, depthM));
252
252
  sharedUniforms.uWrapShift.value[index].copy(layer.shift);
253
253
  sharedUniforms.uWrapVelocity.value[index].set(velocityX, -layer.fallMPerSec, velocityZ);
254
254
  // The box sits a little ahead of the camera, so more of it is in view; fog lies on the ground.
255
- const centerY = layer.layerName === "fog" ? groundHeightM + height * 0.5 : cameraPlace.y + height * 0.2;
256
- sharedUniforms.uWrapCenter.value[index].set(cameraPlace.x + cameraWay.x * width * 0.25, centerY, cameraPlace.z + cameraWay.z * depth * 0.25);
255
+ const centerY = layer.layerName === "fog" ? groundHeightM + heightM * 0.5 : cameraPlace.y + heightM * 0.2;
256
+ sharedUniforms.uWrapCenter.value[index].set(cameraPlace.x + cameraWay.x * widthM * 0.25, centerY, cameraPlace.z + cameraWay.z * depthM * 0.25);
257
257
  }
258
258
 
259
259
  const isFalling = now.rainPct > 0 || now.snowPct > 0;