@zaisma/effects 0.0.0-stage → 1.0.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/EFFECT-FILES.md +301 -0
- package/LICENSE.txt +93 -0
- package/README.md +63 -2
- package/batches/chunks.js +294 -0
- package/batches/marks.js +160 -0
- package/batches/ribbons.js +233 -0
- package/batches/shared.js +155 -0
- package/batches/sprites.js +447 -0
- package/batches/warps.js +222 -0
- package/budget.js +115 -0
- package/debris.js +173 -0
- package/emit.js +143 -0
- package/flashes.js +113 -0
- package/format.js +365 -0
- package/index.d.ts +373 -0
- package/index.js +1168 -0
- package/library/bubbles_rising.json +47 -0
- package/library/bullet_impact.json +588 -0
- package/library/campfire.json +235 -0
- package/library/candle_flame.json +100 -0
- package/library/confetti.json +165 -0
- package/library/dash_burst.json +73 -0
- package/library/debris_glass.json +96 -0
- package/library/debris_metal.json +106 -0
- package/library/debris_stone.json +106 -0
- package/library/debris_wood.json +101 -0
- package/library/dust_motes.json +51 -0
- package/library/dust_puff.json +49 -0
- package/library/electric_sparks.json +175 -0
- package/library/embers_drift.json +55 -0
- package/library/exhaust_puff.json +62 -0
- package/library/explosion_air.json +232 -0
- package/library/explosion_large.json +373 -0
- package/library/explosion_magic.json +266 -0
- package/library/explosion_medium.json +289 -0
- package/library/explosion_small.json +289 -0
- package/library/explosion_water.json +177 -0
- package/library/falling_leaves.json +54 -0
- package/library/fire_burst.json +185 -0
- package/library/fire_large.json +279 -0
- package/library/fireball.json +288 -0
- package/library/fireflies.json +51 -0
- package/library/firework_burst.json +127 -0
- package/library/footstep.json +270 -0
- package/library/fountain_spray.json +80 -0
- package/library/frost_burst.json +202 -0
- package/library/ground_mist.json +50 -0
- package/library/ground_slam.json +122 -0
- package/library/heat_haze.json +24 -0
- package/library/hit_blade.json +150 -0
- package/library/hit_block.json +157 -0
- package/library/hit_critical.json +293 -0
- package/library/hit_heavy.json +211 -0
- package/library/hit_light.json +122 -0
- package/library/hit_magic.json +114 -0
- package/library/impact.json +417 -0
- package/library/impact_heavy.json +279 -0
- package/library/index.json +464 -0
- package/library/jump_puff.json +46 -0
- package/library/landing_heavy.json +105 -0
- package/library/landing_puff.json +75 -0
- package/library/level_up.json +164 -0
- package/library/lightning_arc.json +90 -0
- package/library/lightning_strike.json +387 -0
- package/library/magic_aura.json +127 -0
- package/library/magic_bolt.json +107 -0
- package/library/magic_bolt_impact.json +181 -0
- package/library/magic_cast.json +115 -0
- package/library/magic_charge.json +91 -0
- package/library/magic_heal.json +123 -0
- package/library/magic_shield.json +89 -0
- package/library/magic_teleport.json +177 -0
- package/library/mark_bullet_hole.json +20 -0
- package/library/mark_crack.json +18 -0
- package/library/mark_footprint.json +20 -0
- package/library/mark_frost.json +18 -0
- package/library/mark_puddle.json +18 -0
- package/library/mark_scorch.json +18 -0
- package/library/mark_slash.json +18 -0
- package/library/mark_splat.json +18 -0
- package/library/pickup_collect.json +117 -0
- package/library/pickup_glow.json +76 -0
- package/library/poison_cloud.json +107 -0
- package/library/portal.json +328 -0
- package/library/shockwave_air.json +71 -0
- package/library/shockwave_ground.json +95 -0
- package/library/slide_dust.json +48 -0
- package/library/smoke_column.json +93 -0
- package/library/smoke_puff.json +48 -0
- package/library/smoke_screen.json +87 -0
- package/library/sparks_burst.json +85 -0
- package/library/sparks_fountain.json +93 -0
- package/library/sparks_shower.json +89 -0
- package/library/splash_large.json +181 -0
- package/library/splash_small.json +111 -0
- package/library/steam_vent.json +64 -0
- package/library/summon_circle.json +494 -0
- package/library/swim_splash.json +77 -0
- package/library/torch_flame.json +219 -0
- package/library/trail_blade.json +39 -0
- package/library/trail_blade_fire.json +90 -0
- package/library/trail_dash.json +80 -0
- package/library/trail_magic.json +94 -0
- package/library/trail_projectile.json +31 -0
- package/library/trail_smoke.json +125 -0
- package/library/warp_pulse.json +22 -0
- package/library/warp_ripple.json +23 -0
- package/library/water_ripple.json +69 -0
- package/library/waterfall_mist.json +95 -0
- package/looks.js +162 -0
- package/motion.js +145 -0
- package/online.d.ts +79 -0
- package/online.js +32 -0
- package/package.json +69 -4
- package/partners.js +255 -0
- package/piece.json +415 -0
- package/piece.json.js +416 -0
- package/server.d.ts +55 -0
- package/server.js +26 -0
- package/shapes.js +269 -0
- package/sync.js +528 -0
- package/tables.js +109 -0
- package/weather.js +289 -0
package/index.js
ADDED
|
@@ -0,0 +1,1168 @@
|
|
|
1
|
+
// @zaisma/effects: spectacle for three.js that holds a phone's frame rate. A game adds it, loads effects (small
|
|
2
|
+
// files; about seventy come with it) and plays them: effects.play("explosion_large", { positionM }). The reference
|
|
3
|
+
// is index.d.ts and the effect file's format is EFFECT-FILES.md.
|
|
4
|
+
//
|
|
5
|
+
// How it stays cheap: a particle is written once, as it's born, and the graphics chip works out where it is from
|
|
6
|
+
// the time alone (motion.js), so the page does work only for particles born this frame. Which particles an effect
|
|
7
|
+
// gives off follows from its seed and the time alone (emit.js), so every player sees the same effect, a device that
|
|
8
|
+
// draws fewer draws some of the same ones, and anything here can be thrown away and filled again exactly: that's how
|
|
9
|
+
// the look or the quality level changes while effects play. Everything is drawn in a handful of draw calls
|
|
10
|
+
// (batches/), whatever plays.
|
|
11
|
+
|
|
12
|
+
import * as THREE from "three";
|
|
13
|
+
import { openPiece } from "../piece/index.js";
|
|
14
|
+
import statement from "./piece.json.js";
|
|
15
|
+
import { CHUNK_BUDGET_SHARE, QUALITY_BUDGETS, QUALITY_ORDER, createFillGuard, createFrameWatcher, isTouchDevice, particleBudget, planEmitter, startingQualityLevel } from "./budget.js";
|
|
16
|
+
import { createChunkBatch } from "./batches/chunks.js";
|
|
17
|
+
import { createMarkBatch } from "./batches/marks.js";
|
|
18
|
+
import { createRibbonBatch } from "./batches/ribbons.js";
|
|
19
|
+
import { createSharedUniforms } from "./batches/shared.js";
|
|
20
|
+
import { ELEMENT_ROW, createSpriteBatch } from "./batches/sprites.js";
|
|
21
|
+
import { createWarpBatch } from "./batches/warps.js";
|
|
22
|
+
import { createDebris } from "./debris.js";
|
|
23
|
+
import { birthSecOf, bornCountAt, isParticleKept, makeParticle } from "./emit.js";
|
|
24
|
+
import { createFlashes } from "./flashes.js";
|
|
25
|
+
import {
|
|
26
|
+
COMMON_ELEMENT_FIELDS,
|
|
27
|
+
EFFECT_FIELDS,
|
|
28
|
+
EFFECT_FORMAT_VERSION_NUMBER,
|
|
29
|
+
ELEMENT_FIELDS,
|
|
30
|
+
ELEMENT_KINDS,
|
|
31
|
+
FAMILY_NAMES,
|
|
32
|
+
LOOK_NAMES,
|
|
33
|
+
MATERIAL_NAMES,
|
|
34
|
+
SHAPE_NAMES,
|
|
35
|
+
SURFACE_KINDS,
|
|
36
|
+
checkEffect,
|
|
37
|
+
completeEffect,
|
|
38
|
+
hashNumbers,
|
|
39
|
+
listElementFields,
|
|
40
|
+
randomFrom,
|
|
41
|
+
} from "./format.js";
|
|
42
|
+
import { CHUNK_SHAPE_NAMES, LOOKS, LOOK_STYLE_FIELDS, ownLookProblem, resolveOwnLook } from "./looks.js";
|
|
43
|
+
import { GRAVITY_M_PER_SEC2 } from "./motion.js";
|
|
44
|
+
import { connectPartners } from "./partners.js";
|
|
45
|
+
import { FILM_FRAME_COUNT, canRendererDraw, createShapeAtlas, filmCell, markCell, shapeCell } from "./shapes.js";
|
|
46
|
+
import { ELEMENT_ROW_TEXEL_COUNT, MAXIMUM_ELEMENT_ROW_COUNT, MAXIMUM_PLAY_ROW_COUNT, PLAY_ROW_TEXEL_COUNT, createTable } from "./tables.js";
|
|
47
|
+
import { createWeather } from "./weather.js";
|
|
48
|
+
|
|
49
|
+
export { COMMON_ELEMENT_FIELDS, EFFECT_FIELDS, EFFECT_FORMAT_VERSION_NUMBER, ELEMENT_FIELDS, ELEMENT_KINDS, FAMILY_NAMES, LOOK_NAMES, MATERIAL_NAMES, SHAPE_NAMES, SURFACE_KINDS, checkEffect, completeEffect, listElementFields };
|
|
50
|
+
export { LOOKS, LOOK_STYLE_FIELDS, QUALITY_BUDGETS, isTouchDevice, startingQualityLevel };
|
|
51
|
+
|
|
52
|
+
const GIVEN_FIELDS = ["settings", "hooks", "scene", "renderer", "lighting", "physics", "character", "camera", "castRay"];
|
|
53
|
+
const AT_FIELDS = ["positionM", "direction", "normal", "toPositionM", "scalePct", "strengthPct", "color", "surfaceKind", "follow", "seedNumber", "startedAgoSec"];
|
|
54
|
+
const FACING_NUMBERS = { camera: 0, velocity: 1, ground: 2, along: 3 };
|
|
55
|
+
const RAD_PER_DEG = Math.PI / 180;
|
|
56
|
+
const UPRIGHT_SHAPE_NAMES = ["flame", "angular_flame", "drop"];
|
|
57
|
+
const HEX_COLOR_PATTERN = /^#[0-9a-f]{6}$/;
|
|
58
|
+
const UP = new THREE.Vector3(0, 1, 0);
|
|
59
|
+
/** The clock the graphics chip counts on starts over after this long, so a particle's age stays exact however long a game runs. */
|
|
60
|
+
const CLOCK_RESTART_SEC = 600;
|
|
61
|
+
const CLOCK_RESTART_SPAN_SEC = 512;
|
|
62
|
+
/** How often an emitter that found no room looks again, and how often the scene's own lights are looked for. */
|
|
63
|
+
const RETRY_INTERVAL_SEC = 0.5;
|
|
64
|
+
const LIGHT_SEARCH_INTERVAL_SEC = 3;
|
|
65
|
+
/** Each see-through particle that covers more of the screen than this is one the fill guard may thin. */
|
|
66
|
+
const GUARDED_SCREEN_SHARE = 0.002;
|
|
67
|
+
const MAXIMUM_LANDING_EFFECTS_PER_FRAME = 6;
|
|
68
|
+
const LIBRARY_URL = new URL("./library/", import.meta.url);
|
|
69
|
+
|
|
70
|
+
const isPoint = (given) => given !== null && typeof given === "object" && Number.isFinite(given.x) && Number.isFinite(given.y) && Number.isFinite(given.z);
|
|
71
|
+
const isNumberIn = (given, minimumNumber, maximumNumber) => typeof given === "number" && given >= minimumNumber && given <= maximumNumber;
|
|
72
|
+
const padKeys = (keys, scale) => [0, 1, 2, 3].map((index) => keys[Math.min(index, keys.length - 1)] * scale);
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Makes the effects. Give it the scene and the renderer, and any of the game's other pieces (lighting, physics,
|
|
76
|
+
* character, camera) for what comes free with each. Call effects.update(camera) every frame, before rendering.
|
|
77
|
+
*/
|
|
78
|
+
export function createEffects(given = {}) {
|
|
79
|
+
const { settings, hooks, hasHandlers, tell, ask, refuse } = openPiece(statement, { settings: given.settings, hooks: given.hooks });
|
|
80
|
+
for (const field of Object.keys(given)) {
|
|
81
|
+
if (!GIVEN_FIELDS.includes(field)) refuse("unknown_argument", { message: `createEffects has no argument "${field}".`, field, fix: `Give only: ${GIVEN_FIELDS.join(", ")}. A setting goes inside settings.` });
|
|
82
|
+
}
|
|
83
|
+
const { scene, renderer } = given;
|
|
84
|
+
const lighting = given.lighting ?? null;
|
|
85
|
+
const physics = given.physics ?? null;
|
|
86
|
+
if (!(scene instanceof THREE.Scene)) refuse("scene_needed", { message: "createEffects needs the three.js scene the effects play in.", field: "scene", fix: "Give createEffects({ scene, renderer }), with scene a THREE.Scene." });
|
|
87
|
+
if (!renderer || typeof renderer.render !== "function") refuse("renderer_needed", { message: "createEffects needs the three.js renderer that draws the scene.", field: "renderer", fix: "Give createEffects({ scene, renderer }), with renderer a THREE.WebGLRenderer." });
|
|
88
|
+
if (given.castRay !== undefined && typeof given.castRay !== "function") refuse("bad_cast_ray", { message: "castRay isn't a function.", field: "castRay", fix: "Give a function taking { fromM, directionM, maximumDistanceM } and answering { pointM, normal } or null: the level's own ray test." });
|
|
89
|
+
const canDraw = canRendererDraw(renderer);
|
|
90
|
+
|
|
91
|
+
// ---- What every batch reads ----
|
|
92
|
+
const sharedUniforms = createSharedUniforms();
|
|
93
|
+
const elementTable = createTable(ELEMENT_ROW_TEXEL_COUNT, MAXIMUM_ELEMENT_ROW_COUNT);
|
|
94
|
+
const playTable = createTable(PLAY_ROW_TEXEL_COUNT, MAXIMUM_PLAY_ROW_COUNT);
|
|
95
|
+
sharedUniforms.uElements.value = elementTable.texture;
|
|
96
|
+
sharedUniforms.uPlays.value = playTable.texture;
|
|
97
|
+
const group = new THREE.Group();
|
|
98
|
+
group.name = "zaisma_effects";
|
|
99
|
+
scene.add(group);
|
|
100
|
+
|
|
101
|
+
// ---- The clock ----
|
|
102
|
+
// Effects count their own seconds, which the game can slow or stop. The batches count from a start that moves
|
|
103
|
+
// forward now and then (batchStartSec), so what the graphics chip subtracts stays small and exact.
|
|
104
|
+
let nowSec = 0;
|
|
105
|
+
let batchStartSec = 0;
|
|
106
|
+
let lastUpdateMs = null;
|
|
107
|
+
const toBatchSec = (sec) => sec - batchStartSec;
|
|
108
|
+
|
|
109
|
+
// ---- The look ----
|
|
110
|
+
let ownLook = null;
|
|
111
|
+
let lookName = "cartoon";
|
|
112
|
+
/** The look names an element's look_names is matched against: the look in use, or the one a look of the game's own is based on. */
|
|
113
|
+
let statedLookName = "cartoon";
|
|
114
|
+
let styles = LOOKS.cartoon;
|
|
115
|
+
function readLook() {
|
|
116
|
+
const wanted = settings.get("look");
|
|
117
|
+
if (wanted === "own" && ownLook) {
|
|
118
|
+
lookName = "own";
|
|
119
|
+
statedLookName = ownLook.basedOnLookName;
|
|
120
|
+
styles = resolveOwnLook(ownLook);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
// "own" before a look is defined draws as the default does.
|
|
124
|
+
lookName = wanted === "own" ? "cartoon" : wanted;
|
|
125
|
+
statedLookName = lookName;
|
|
126
|
+
styles = LOOKS[lookName];
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// ---- Quality ----
|
|
130
|
+
const frameWatcher = createFrameWatcher();
|
|
131
|
+
const fillGuard = createFillGuard();
|
|
132
|
+
const startingLevel = () => lighting?.qualityLevel ?? startingQualityLevel();
|
|
133
|
+
let qualityLevel = settings.get("qualityLevel") === "auto" ? startingLevel() : settings.get("qualityLevel");
|
|
134
|
+
if (!QUALITY_ORDER.includes(qualityLevel)) qualityLevel = "medium";
|
|
135
|
+
|
|
136
|
+
// ---- Batches ----
|
|
137
|
+
let atlas = null;
|
|
138
|
+
let atlasSizePx = 0;
|
|
139
|
+
let sprites = null;
|
|
140
|
+
let chunks = null;
|
|
141
|
+
const marks = createMarkBatch({ markCount: 0, sharedUniforms });
|
|
142
|
+
const ribbons = createRibbonBatch();
|
|
143
|
+
const warps = createWarpBatch({ sharedUniforms });
|
|
144
|
+
const flashes = createFlashes({ scene, sharedUniforms });
|
|
145
|
+
group.add(marks.mesh, ribbons.mesh, warps.mesh);
|
|
146
|
+
|
|
147
|
+
// ---- The level, for marks and debris ----
|
|
148
|
+
const rayQuery = { fromM: { x: 0, y: 0, z: 0 }, directionM: { x: 0, y: 0, z: 0 }, maximumDistanceM: 0 };
|
|
149
|
+
/** Whether a ray meets the level, writing where and the surface's normal there. */
|
|
150
|
+
function findSurface(fromX, fromY, fromZ, wayX, wayY, wayZ, distanceM, into) {
|
|
151
|
+
const castRay = given.castRay ?? (physics && typeof physics.castRay === "function" ? (query) => physics.castRay(query) : null);
|
|
152
|
+
if (castRay) {
|
|
153
|
+
rayQuery.fromM.x = fromX;
|
|
154
|
+
rayQuery.fromM.y = fromY;
|
|
155
|
+
rayQuery.fromM.z = fromZ;
|
|
156
|
+
rayQuery.directionM.x = wayX;
|
|
157
|
+
rayQuery.directionM.y = wayY;
|
|
158
|
+
rayQuery.directionM.z = wayZ;
|
|
159
|
+
rayQuery.maximumDistanceM = distanceM;
|
|
160
|
+
const hit = castRay(rayQuery);
|
|
161
|
+
if (!hit || !isPoint(hit.pointM)) return false;
|
|
162
|
+
into.x = hit.pointM.x;
|
|
163
|
+
into.y = hit.pointM.y;
|
|
164
|
+
into.z = hit.pointM.z;
|
|
165
|
+
into.normalX = hit.normal?.x ?? 0;
|
|
166
|
+
into.normalY = hit.normal?.y ?? 1;
|
|
167
|
+
into.normalZ = hit.normal?.z ?? 0;
|
|
168
|
+
into.materialName = hit.materialName ?? null;
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
// With no level to ask, the flat ground at the height the game set.
|
|
172
|
+
const groundY = settings.get("groundHeightM");
|
|
173
|
+
if (wayY >= -1e-6 || fromY < groundY) return false;
|
|
174
|
+
const alongM = (groundY - fromY) / wayY;
|
|
175
|
+
if (alongM > distanceM) return false;
|
|
176
|
+
into.x = fromX + wayX * alongM;
|
|
177
|
+
into.y = groundY;
|
|
178
|
+
into.z = fromZ + wayZ * alongM;
|
|
179
|
+
into.normalX = 0;
|
|
180
|
+
into.normalY = 1;
|
|
181
|
+
into.normalZ = 0;
|
|
182
|
+
into.materialName = null;
|
|
183
|
+
return true;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
let landingEffectCount = 0;
|
|
187
|
+
const debris = createDebris({
|
|
188
|
+
chunks: () => chunks,
|
|
189
|
+
findSurface,
|
|
190
|
+
onLanded(chunk, met) {
|
|
191
|
+
if (!chunk.bounceEffectName || !registry.has(chunk.bounceEffectName) || landingEffectCount >= MAXIMUM_LANDING_EFFECTS_PER_FRAME) return;
|
|
192
|
+
landingEffectCount += 1;
|
|
193
|
+
startPlay(chunk.bounceEffectName, { positionM: { x: met.x, y: met.y, z: met.z }, normal: { x: met.normalX, y: met.normalY, z: met.normalZ }, scalePct: Math.min(Math.max(chunk.halfSizeM * 800, 25), 200), seedNumber: hashNumbers(chunk.play.seedNumber, chunk.offset, 31) }, "chunk_landed");
|
|
194
|
+
},
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
// ---- The weather ----
|
|
198
|
+
const weatherPlayRow = playTable.takeRow();
|
|
199
|
+
playTable.write(weatherPlayRow, 0, 0, 0, 0, 1);
|
|
200
|
+
playTable.write(weatherPlayRow, 1, 0, 0, 0, 1);
|
|
201
|
+
playTable.write(weatherPlayRow, 2, 1, 1, 1, 1);
|
|
202
|
+
playTable.write(weatherPlayRow, 3, 0, 0, 0, 0);
|
|
203
|
+
const weather = createWeather({ sprites: null, sharedUniforms, scene, renderer, playRow: weatherPlayRow });
|
|
204
|
+
const weatherRows = weather.elements.map(() => elementTable.takeRow());
|
|
205
|
+
const weatherTarget = () => ({
|
|
206
|
+
rainPct: settings.get("rainPct"),
|
|
207
|
+
snowPct: settings.get("snowPct"),
|
|
208
|
+
fogPct: settings.get("fogPct"),
|
|
209
|
+
windSpeedMPerSec: settings.get("windSpeedMPerSec"),
|
|
210
|
+
windDirectionDeg: settings.get("windDirectionDeg"),
|
|
211
|
+
windGustPct: settings.get("windGustPct"),
|
|
212
|
+
});
|
|
213
|
+
let weatherToldSec = -Infinity;
|
|
214
|
+
let wasWeatherTurning = false;
|
|
215
|
+
|
|
216
|
+
// ---- Effects, as added ----
|
|
217
|
+
/** name -> { name, file (every field there), elements: what each element needs to play }. */
|
|
218
|
+
const registry = new Map();
|
|
219
|
+
const color = new THREE.Color();
|
|
220
|
+
const linearColors = (hexColors) => hexColors.map((hex) => new THREE.Color(hex));
|
|
221
|
+
|
|
222
|
+
function writeParticleRow(row, element, style, weatherLayerNumber) {
|
|
223
|
+
const { move, fade } = element;
|
|
224
|
+
elementTable.write(row, ELEMENT_ROW.motionA, move.drag_per_sec, (move.gravity_pct / 100) * GRAVITY_M_PER_SEC2, move.wind_pct / 100, move.turbulence_m);
|
|
225
|
+
elementTable.write(row, ELEMENT_ROW.motionB, move.turbulence_per_sec, move.swirl_deg_per_sec * RAD_PER_DEG, move.pull_pct / 100, move.is_attached ? 1 : 0);
|
|
226
|
+
elementTable.write(row, ELEMENT_ROW.sizeKeys, ...padKeys(fade.size_over_life_m, style.sizePct / 100));
|
|
227
|
+
elementTable.write(row, ELEMENT_ROW.opacityKeys, ...padKeys(fade.opacity_over_life_pct, style.opacityPct / 10000).map((share) => Math.min(share, 1)));
|
|
228
|
+
elementTable.write(row, ELEMENT_ROW.keyCounts, fade.size_over_life_m.length, fade.opacity_over_life_pct.length, fade.colors_over_life.length, fade.size_variation_pct / 100);
|
|
229
|
+
const fourth = [(fade.glow_pct / 100) * (style.glowPct / 100), style.addPct / 100, style.litPct / 100, style.toneStepCount];
|
|
230
|
+
for (let index = 0; index < 4; index += 1) {
|
|
231
|
+
color.set(fade.colors_over_life[Math.min(index, fade.colors_over_life.length - 1)]);
|
|
232
|
+
// A look that draws a material solid lightens it: what reads as grey smoke when see-through is coal when it isn't.
|
|
233
|
+
const lightenShare = style.lightenPct / 100;
|
|
234
|
+
elementTable.write(row, ELEMENT_ROW.colorKeys + index, color.r + (1 - color.r) * lightenShare, color.g + (1 - color.g) * lightenShare, color.b + (1 - color.b) * lightenShare, fourth[index]);
|
|
235
|
+
}
|
|
236
|
+
// A shape the element names is drawn as named; otherwise the look's own, which may be a moving picture.
|
|
237
|
+
const filmName = element.shape === null ? style.filmName : null;
|
|
238
|
+
const shapeName = element.shape ?? style.shapeName;
|
|
239
|
+
const cell = filmName ? filmCell(filmName) : shapeCell(shapeName);
|
|
240
|
+
// A flame or a drop stands upright and sways, however the element says its particles turn, unless it says not to.
|
|
241
|
+
const spinRadPerSec = !filmName && fade.is_upright && UPRIGHT_SHAPE_NAMES.includes(shapeName) && fade.facing_kind === "camera" ? -1 : fade.spin_deg_per_sec * RAD_PER_DEG;
|
|
242
|
+
elementTable.write(row, ELEMENT_ROW.cell, cell.u, cell.v, cell.sizeNumber, filmName ? FILM_FRAME_COUNT : 0);
|
|
243
|
+
elementTable.write(row, ELEMENT_ROW.facing, FACING_NUMBERS[fade.facing_kind], fade.streak_duration_sec, spinRadPerSec, style.roundPct / 100);
|
|
244
|
+
elementTable.write(row, ELEMENT_ROW.style, style.hardPct / 100, style.outlinePct / 100, weatherLayerNumber, Math.max(CHUNK_SHAPE_NAMES.indexOf(style.chunkShapeName), 0));
|
|
245
|
+
elementTable.write(row, ELEMENT_ROW.tone, style.corePct / 100, filmName ? 1 : atlas.depthOf(shapeName), 0, 0);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** What a particles element needs in the look in use: how it's drawn, and its emitter as emit.js takes it. */
|
|
249
|
+
function styleParticles(compiled, file) {
|
|
250
|
+
const { element } = compiled;
|
|
251
|
+
const { emit, move, fade } = element;
|
|
252
|
+
// A look sizes and thins what an effect leaves open. A shape the effect names (a ring, a bubble, a star) is a
|
|
253
|
+
// figure it drew on purpose: it keeps its own size and count in every look.
|
|
254
|
+
const style = element.shape === null ? styles[element.material] : { ...styles[element.material], countPct: 100, sizePct: 100 };
|
|
255
|
+
const countShare = style.countPct / 100;
|
|
256
|
+
// A look that asks for more particles gets more; one that asks for fewer draws a share of the same ones.
|
|
257
|
+
const more = Math.max(countShare, 1);
|
|
258
|
+
const loopDurationSec = file.is_looping ? file.duration_sec : 0;
|
|
259
|
+
const emitDurationSec = emit.emit_duration_sec ?? file.duration_sec;
|
|
260
|
+
const maxLifeSec = fade.life_sec * (1 + fade.life_variation_pct / 100);
|
|
261
|
+
compiled.style = style;
|
|
262
|
+
compiled.isChunk = style.chunkShapeName !== null && element.shape === null && (fade.facing_kind === "camera" || fade.facing_kind === "velocity");
|
|
263
|
+
compiled.lookCountShare = Math.min(countShare, 1);
|
|
264
|
+
compiled.maxLifeSec = maxLifeSec;
|
|
265
|
+
compiled.isAttached = move.is_attached;
|
|
266
|
+
compiled.emitter = {
|
|
267
|
+
elementIndex: compiled.elementIndex,
|
|
268
|
+
burstCount: Math.round(emit.burst_count * more),
|
|
269
|
+
perSec: emit.per_sec * more,
|
|
270
|
+
emitDurationSec,
|
|
271
|
+
loopDurationSec,
|
|
272
|
+
fromKind: emit.from_kind,
|
|
273
|
+
fromRadiusM: emit.from_radius_m,
|
|
274
|
+
fromSizeM: emit.from_size_m,
|
|
275
|
+
isFromEdge: emit.is_from_edge,
|
|
276
|
+
directionKind: move.direction_kind,
|
|
277
|
+
spreadRad: move.spread_deg * RAD_PER_DEG,
|
|
278
|
+
speedMPerSec: move.speed_m_per_sec,
|
|
279
|
+
speedVariationShare: move.speed_variation_pct / 100,
|
|
280
|
+
lifeSec: fade.life_sec,
|
|
281
|
+
lifeVariationShare: fade.life_variation_pct / 100,
|
|
282
|
+
};
|
|
283
|
+
compiled.isNeverThinned = emit.burst_count <= 3 && emit.per_sec === 0;
|
|
284
|
+
compiled.isSeeThrough = !compiled.isChunk && style.addPct < 50;
|
|
285
|
+
compiled.fillSizeM = Math.max(...fade.size_over_life_m) * (style.sizePct / 100);
|
|
286
|
+
// How many are alive at once, drawing every one.
|
|
287
|
+
const flowSec = loopDurationSec > 0 ? Math.min(emitDurationSec, loopDurationSec) : emitDurationSec;
|
|
288
|
+
const runCount = loopDurationSec > 0 ? Math.ceil(maxLifeSec / loopDurationSec) : 1;
|
|
289
|
+
compiled.wantedCount = Math.min(compiled.emitter.burstCount * runCount + Math.ceil(compiled.emitter.perSec * Math.min(maxLifeSec, flowSec * runCount)), 20000);
|
|
290
|
+
writeParticleRow(compiled.row, element, style, 0);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function styleDebris(compiled) {
|
|
294
|
+
const { element } = compiled;
|
|
295
|
+
const style = styles[element.material];
|
|
296
|
+
compiled.rows.forEach((row, index) => {
|
|
297
|
+
elementTable.write(row, ELEMENT_ROW.motionA, 0, 0, 0, 0);
|
|
298
|
+
elementTable.write(row, ELEMENT_ROW.motionB, 1, 0, 0, 0);
|
|
299
|
+
elementTable.write(row, ELEMENT_ROW.sizeKeys, element.size_m, element.size_m, element.size_m, element.size_m);
|
|
300
|
+
// A chunk shrinks away at the end of its life.
|
|
301
|
+
elementTable.write(row, ELEMENT_ROW.opacityKeys, 1, 1, 1, 0);
|
|
302
|
+
elementTable.write(row, ELEMENT_ROW.keyCounts, 2, 4, 1, element.size_variation_pct / 100);
|
|
303
|
+
color.set(element.colors[index]);
|
|
304
|
+
const fourth = [style.glowPct / 100, 0, Math.max(style.litPct, 60) / 100, 0];
|
|
305
|
+
for (let key = 0; key < 4; key += 1) elementTable.write(row, ELEMENT_ROW.colorKeys + key, color.r, color.g, color.b, fourth[key]);
|
|
306
|
+
elementTable.write(row, ELEMENT_ROW.cell, 0, 0, 0, 0);
|
|
307
|
+
elementTable.write(row, ELEMENT_ROW.facing, 0, 0, 0, 0);
|
|
308
|
+
elementTable.write(row, ELEMENT_ROW.style, 1, 0, 0, Math.max(CHUNK_SHAPE_NAMES.indexOf(style.chunkShapeName ?? "cube"), 0));
|
|
309
|
+
});
|
|
310
|
+
compiled.emitter = {
|
|
311
|
+
elementIndex: compiled.elementIndex,
|
|
312
|
+
burstCount: element.count,
|
|
313
|
+
perSec: 0,
|
|
314
|
+
emitDurationSec: 0,
|
|
315
|
+
loopDurationSec: 0,
|
|
316
|
+
fromKind: element.from_radius_m > 0 ? "sphere" : "point",
|
|
317
|
+
fromRadiusM: element.from_radius_m,
|
|
318
|
+
fromSizeM: [0, 0, 0],
|
|
319
|
+
isFromEdge: false,
|
|
320
|
+
directionKind: element.direction_kind,
|
|
321
|
+
spreadRad: element.spread_deg * RAD_PER_DEG,
|
|
322
|
+
speedMPerSec: element.speed_m_per_sec,
|
|
323
|
+
speedVariationShare: element.speed_variation_pct / 100,
|
|
324
|
+
lifeSec: element.life_sec,
|
|
325
|
+
lifeVariationShare: 0,
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
function styleEntry(entry) {
|
|
330
|
+
for (const compiled of entry.elements) {
|
|
331
|
+
if (compiled.elementKind === "particles") styleParticles(compiled, entry.file);
|
|
332
|
+
else if (compiled.elementKind === "debris") styleDebris(compiled);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/** How long after it starts a play's emitters and passing elements are all over, in seconds. */
|
|
337
|
+
function runSecOf(file) {
|
|
338
|
+
let runSec = file.duration_sec;
|
|
339
|
+
for (const element of file.elements) {
|
|
340
|
+
if (element.element_kind === "particles") runSec = Math.max(runSec, element.start_delay_sec + (element.emit.emit_duration_sec ?? file.duration_sec));
|
|
341
|
+
}
|
|
342
|
+
return runSec;
|
|
343
|
+
}
|
|
344
|
+
function lingerSecOf(file) {
|
|
345
|
+
let lingerSec = 0;
|
|
346
|
+
for (const element of file.elements) {
|
|
347
|
+
const ownSec = element.element_kind === "flash" || element.element_kind === "shake" ? element.duration_sec : element.element_kind === "warp" || element.element_kind === "beam" ? element.life_sec : 0;
|
|
348
|
+
lingerSec = Math.max(lingerSec, element.start_delay_sec + ownSec);
|
|
349
|
+
}
|
|
350
|
+
return lingerSec;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/** Adds an effect file, or puts a changed one in the place of the one with its name. Answers its name. */
|
|
354
|
+
function add(effectFile) {
|
|
355
|
+
const problems = checkEffect(effectFile);
|
|
356
|
+
if (problems.length > 0) {
|
|
357
|
+
const first = problems[0];
|
|
358
|
+
const name = typeof effectFile?.name === "string" ? `"${effectFile.name}"` : "The effect file";
|
|
359
|
+
refuse(first.code, { message: `${name} can't play: ${first.message}${problems.length > 1 ? ` (and ${problems.length - 1} more: checkEffect lists every one)` : ""}`, field: first.field, fix: first.fix });
|
|
360
|
+
}
|
|
361
|
+
const file = completeEffect(effectFile);
|
|
362
|
+
const earlier = registry.get(file.name);
|
|
363
|
+
// A changed file takes the rows of the one before it, as far as they go.
|
|
364
|
+
const spareRows = earlier ? earlier.elements.flatMap((compiled) => (compiled.elementKind === "particles" ? [compiled.row] : compiled.elementKind === "debris" ? compiled.rows : [])) : [];
|
|
365
|
+
const neededCount = file.elements.reduce((count, element) => count + (element.element_kind === "particles" ? 1 : element.element_kind === "debris" ? element.colors.length : 0), 0);
|
|
366
|
+
if (neededCount > spareRows.length + elementTable.freeRowCount) {
|
|
367
|
+
refuse("too_many_effects", { message: `There's no room left for "${file.name}": the effects added hold ${MAXIMUM_ELEMENT_ROW_COUNT} particle and debris elements between them.`, field: "name", fix: "Add only the effects the game plays: load them by name instead of all of them." });
|
|
368
|
+
}
|
|
369
|
+
const takeRow = () => (spareRows.length > 0 ? spareRows.pop() : elementTable.takeRow());
|
|
370
|
+
const entry = {
|
|
371
|
+
name: file.name,
|
|
372
|
+
file,
|
|
373
|
+
runSec: runSecOf(file),
|
|
374
|
+
lingerSec: lingerSecOf(file),
|
|
375
|
+
ribbonTailSec: Math.max(0, ...file.elements.map((element) => (element.element_kind === "ribbon" ? element.life_sec : 0))),
|
|
376
|
+
elements: file.elements.map((element, elementIndex) => {
|
|
377
|
+
const compiled = { elementKind: element.element_kind, element, elementIndex, startDelaySec: element.start_delay_sec };
|
|
378
|
+
if (element.element_kind === "particles") compiled.row = takeRow();
|
|
379
|
+
if (element.element_kind === "debris") compiled.rows = element.colors.map(takeRow);
|
|
380
|
+
return compiled;
|
|
381
|
+
}),
|
|
382
|
+
};
|
|
383
|
+
for (const row of spareRows) elementTable.giveRow(row);
|
|
384
|
+
styleEntry(entry);
|
|
385
|
+
registry.set(file.name, entry);
|
|
386
|
+
if (earlier) {
|
|
387
|
+
// What's playing of the earlier file plays on as the new one, from where it is.
|
|
388
|
+
for (const play of plays) if (play.entry === earlier) restartPlay(play, entry);
|
|
389
|
+
}
|
|
390
|
+
return file.name;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
async function fetchJson(url) {
|
|
394
|
+
const answer = await fetch(url);
|
|
395
|
+
if (!answer.ok) refuse("effect_not_loaded", { message: `${url} answered ${answer.status}.`, field: "names", fix: "Give an effect's name from the piece's library, or the address of an effect file of the game's own." });
|
|
396
|
+
return answer.json();
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/** Loads effects: "all" for the piece's whole library, or a list of its effects' names and addresses of the game's own files. Answers their names. */
|
|
400
|
+
async function load(names) {
|
|
401
|
+
let wanted = names;
|
|
402
|
+
if (names === "all") wanted = (await fetchJson(new URL("index.json", LIBRARY_URL))).effects.map((listed) => listed.name);
|
|
403
|
+
if (!Array.isArray(wanted) || wanted.some((name) => typeof name !== "string" || name.length === 0)) {
|
|
404
|
+
refuse("bad_effect_names", { message: "load takes \"all\" or a list of names.", field: "names", fix: 'Give "all", or a list like ["explosion_large", "./effects/my_spell.json"].' });
|
|
405
|
+
}
|
|
406
|
+
const files = await Promise.all(wanted.map((name) => fetchJson(name.includes("/") || name.endsWith(".json") ? new URL(name, globalThis.location?.href ?? LIBRARY_URL) : new URL(`${name}.json`, LIBRARY_URL))));
|
|
407
|
+
return files.map(add);
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
// ---- Plays ----
|
|
411
|
+
const plays = new Set();
|
|
412
|
+
let nextPlayId = 1;
|
|
413
|
+
const followPlace = new THREE.Vector3();
|
|
414
|
+
const followTurn = new THREE.Quaternion();
|
|
415
|
+
const turned = new THREE.Vector3();
|
|
416
|
+
const born = { x: 0, y: 0, z: 0, velocityX: 0, velocityY: 0, velocityZ: 0, lifeSec: 0, seedNumber: 0 };
|
|
417
|
+
const surface = { x: 0, y: 0, z: 0, normalX: 0, normalY: 1, normalZ: 0, materialName: null };
|
|
418
|
+
let thinnedToldSec = -Infinity;
|
|
419
|
+
|
|
420
|
+
function toldThinned(effectName, keptShare) {
|
|
421
|
+
if (nowSec - thinnedToldSec < 1) return;
|
|
422
|
+
thinnedToldSec = nowSec;
|
|
423
|
+
tell("effectsThinned", { effectName, keptPct: Math.round(keptShare * 100) });
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
function writePlayRow(play) {
|
|
427
|
+
playTable.write(play.row, 0, play.place.x, play.place.y, play.place.z, play.scaleShare);
|
|
428
|
+
playTable.write(play.row, 1, play.turn.x, play.turn.y, play.turn.z, play.turn.w);
|
|
429
|
+
playTable.write(play.row, 2, play.tint.r, play.tint.g, play.tint.b, play.strengthShare);
|
|
430
|
+
playTable.write(play.row, 3, play.surface.x, play.surface.y, play.surface.z, play.surface.w);
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
function placePlay(play) {
|
|
434
|
+
if (play.follow) {
|
|
435
|
+
play.follow.updateWorldMatrix(true, false);
|
|
436
|
+
play.follow.getWorldPosition(followPlace);
|
|
437
|
+
play.follow.getWorldQuaternion(followTurn);
|
|
438
|
+
play.place.copy(play.offset).applyQuaternion(followTurn).add(followPlace);
|
|
439
|
+
play.turn.copy(followTurn).multiply(play.ownTurn);
|
|
440
|
+
} else {
|
|
441
|
+
play.place.copy(play.offset);
|
|
442
|
+
play.turn.copy(play.ownTurn);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
/** Whether an element plays at all: in this look, at this quality, on this surface. */
|
|
447
|
+
function isElementPlayed(play, element) {
|
|
448
|
+
if (element.look_names !== null && !element.look_names.includes(statedLookName)) return false;
|
|
449
|
+
if (QUALITY_ORDER.indexOf(element.minimum_quality_level) > QUALITY_ORDER.indexOf(qualityLevel)) return false;
|
|
450
|
+
return element.surface_kinds === null || element.surface_kinds.includes(play.surfaceKind ?? "stone");
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
/** The elements that are over in a moment: flashes, beams, warps, marks, debris and shakes. */
|
|
454
|
+
function startPassingElements(play, isRestart) {
|
|
455
|
+
const sinceStartSec = nowSec - play.startSec;
|
|
456
|
+
const loopDurationSec = play.entry.file.is_looping ? play.entry.file.duration_sec : 0;
|
|
457
|
+
const quality = QUALITY_BUDGETS[qualityLevel];
|
|
458
|
+
for (const compiled of play.entry.elements) {
|
|
459
|
+
const { element, elementIndex } = compiled;
|
|
460
|
+
if (compiled.elementKind === "particles" || !isElementPlayed(play, element)) continue;
|
|
461
|
+
const startSec = play.startSec + compiled.startDelaySec;
|
|
462
|
+
const seedNumber = hashNumbers(play.seedNumber, elementIndex, 17);
|
|
463
|
+
const next = randomFrom(seedNumber);
|
|
464
|
+
if (compiled.elementKind === "flash") {
|
|
465
|
+
flashes.add({ play: play.view, offset: new THREE.Vector3(...element.offset_m), color: new THREE.Color(element.color), strengthLux: element.strength_lux, radiusM: element.radius_m, startSec, durationSec: element.duration_sec, strengthKeys: element.strength_over_life_pct, flickerShare: element.flicker_pct / 100, loopDurationSec });
|
|
466
|
+
} else if (compiled.elementKind === "warp") {
|
|
467
|
+
warps.add({ play: play.view, warpKind: element.warp_kind, startSec, lifeSec: element.life_sec, radiusKeys: element.radius_over_life_m, strengthKeys: element.strength_over_life_pct, thicknessShare: element.thickness_pct / 100, loopDurationSec, seedNumber: next() });
|
|
468
|
+
} else if (compiled.elementKind === "ribbon") {
|
|
469
|
+
const style = styles.energy;
|
|
470
|
+
const fromOffset = new THREE.Vector3(...element.from_offset_m);
|
|
471
|
+
const toOffset = new THREE.Vector3(...element.to_offset_m);
|
|
472
|
+
ribbons.addRibbon({ play: play.view, lifeSec: element.life_sec, widthKeys: element.width_over_length_m, colors: linearColors(element.colors_over_length), opacityKeys: element.opacity_over_length_pct, glowShare: (element.glow_pct / 100) * (style.glowPct / 100), addShare: style.addPct / 100, minimumStepM: element.minimum_step_m, fromOffset, toOffset, isBlade: fromOffset.distanceToSquared(toOffset) > 1e-8, startSec });
|
|
473
|
+
} else if (compiled.elementKind === "beam") {
|
|
474
|
+
if (sinceStartSec - compiled.startDelaySec < element.life_sec || loopDurationSec > 0) addBeam(play, compiled, startSec + (loopDurationSec > 0 ? Math.floor(Math.max(sinceStartSec, 0) / loopDurationSec) * loopDurationSec : 0));
|
|
475
|
+
} else if (isRestart) {
|
|
476
|
+
// What's left on the level or already thrown stays as it is when a play starts over.
|
|
477
|
+
} else if (compiled.elementKind === "mark") {
|
|
478
|
+
if (settings.get("marksEnabled") && marks.capacity > 0 && sinceStartSec - compiled.startDelaySec < element.life_sec) layMark(play, compiled, startSec, next);
|
|
479
|
+
} else if (compiled.elementKind === "debris") {
|
|
480
|
+
// Chunks already in the air when a player joins aren't thrown again: where each would be can't be known.
|
|
481
|
+
if (sinceStartSec - compiled.startDelaySec < 0.25) {
|
|
482
|
+
debris.throwChunks({ emitter: compiled.emitter, count: Math.max(Math.round((element.count * quality.keptPct) / 100), 1), play, playSeedNumber: play.seedNumber, startSec, gravityMPerSec2: (element.gravity_pct / 100) * GRAVITY_M_PER_SEC2, bounceShare: element.bounce_pct / 100, gripShare: element.grip_pct / 100, sizeM: element.size_m, lifeSec: element.life_sec, spinRadPerSec: element.spin_deg_per_sec * RAD_PER_DEG, elementRows: compiled.rows, bounceEffectName: element.bounce_effect_name });
|
|
483
|
+
}
|
|
484
|
+
} else if (compiled.elementKind === "shake") {
|
|
485
|
+
if (settings.get("shakesEnabled") && sinceStartSec - compiled.startDelaySec < element.duration_sec) shakes.add({ play, startSec, durationSec: element.duration_sec, strengthShare: element.strength_pct / 100, radiusM: element.radius_m, isTold: false });
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
function addBeam(play, compiled, startSec) {
|
|
491
|
+
const { element } = compiled;
|
|
492
|
+
const style = styles.energy;
|
|
493
|
+
ribbons.addBeam({ play: play.view, to: play.toPlace, lifeSec: element.life_sec, widthM: element.width_m, segmentCount: element.segment_count, jitterM: element.jitter_m, rejitterPerSec: element.rejitter_per_sec, reachM: element.reach_m, spreadRad: (element.spread_deg * Math.PI) / 180, tipWidthShare: element.tip_width_pct / 100, colors: linearColors(element.colors_over_life), opacityKeys: element.opacity_over_life_pct, glowShare: (element.glow_pct / 100) * (style.glowPct / 100), addShare: style.addPct / 100, startSec, seedNumber: hashNumbers(play.seedNumber, compiled.elementIndex, Math.round(startSec * 16)) });
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
function layMark(play, compiled, startSec, next) {
|
|
497
|
+
const { element } = compiled;
|
|
498
|
+
if (play.hasNormal) {
|
|
499
|
+
surface.x = play.place.x;
|
|
500
|
+
surface.y = play.place.y;
|
|
501
|
+
surface.z = play.place.z;
|
|
502
|
+
surface.normalX = play.normal.x;
|
|
503
|
+
surface.normalY = play.normal.y;
|
|
504
|
+
surface.normalZ = play.normal.z;
|
|
505
|
+
} else if (!findSurface(play.place.x, play.place.y + 0.05, play.place.z, 0, -1, 0, element.search_distance_m + 0.05, surface)) return;
|
|
506
|
+
const cell = markCell(element.shape);
|
|
507
|
+
marks.add({
|
|
508
|
+
x: surface.x,
|
|
509
|
+
y: surface.y,
|
|
510
|
+
z: surface.z,
|
|
511
|
+
normalX: surface.normalX,
|
|
512
|
+
normalY: surface.normalY,
|
|
513
|
+
normalZ: surface.normalZ,
|
|
514
|
+
sizeM: element.size_m * (1 + (element.size_variation_pct / 100) * (next() * 2 - 1)) * play.scaleShare,
|
|
515
|
+
turnRad: next() * Math.PI * 2,
|
|
516
|
+
birthSec: toBatchSec(startSec),
|
|
517
|
+
lifeSec: element.life_sec,
|
|
518
|
+
cellU: cell.u,
|
|
519
|
+
cellV: cell.v,
|
|
520
|
+
color: new THREE.Color(element.color),
|
|
521
|
+
opacityShare: (element.opacity_pct / 100) * Math.min(play.strengthShare, 1),
|
|
522
|
+
glowColor: new THREE.Color(element.glow_color),
|
|
523
|
+
glowDurationSec: element.glow_duration_sec,
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
/** Gives a play its emitters, one for each particles element that plays. */
|
|
528
|
+
function makeEmitters(play) {
|
|
529
|
+
play.emitters = [];
|
|
530
|
+
for (const compiled of play.entry.elements) {
|
|
531
|
+
if (compiled.elementKind !== "particles" || !isElementPlayed(play, compiled.element)) continue;
|
|
532
|
+
play.emitters.push({ compiled, slab: null, batch: null, bornCount: 0, keptShare: 1, isGuarded: false, isDone: false, isFinished: false, retrySec: -Infinity });
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
function dropEmitters(play) {
|
|
537
|
+
for (const state of play.emitters) if (state.slab) state.batch.giveSlab(state.slab);
|
|
538
|
+
play.emitters = [];
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
/** A play starts over as it is now: after the look, the quality level or its file changed. Its particles are filled in again, the same ones. */
|
|
542
|
+
function restartPlay(play, entry = play.entry) {
|
|
543
|
+
dropEmitters(play);
|
|
544
|
+
play.entry = entry;
|
|
545
|
+
makeEmitters(play);
|
|
546
|
+
// What followed the play as it was (its flashes, warps, trails and beams) lets go, and follows it as it is now.
|
|
547
|
+
play.view.isEnded = true;
|
|
548
|
+
play.view = Object.create(play);
|
|
549
|
+
startPassingElements(play, true);
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
const standsOn = { x: 0, y: 0, z: 0, normalX: 0, normalY: 1, normalZ: 0, materialName: null };
|
|
553
|
+
const inertHandle = Object.freeze({ playId: 0, effectName: null, isEnded: true, stop() {}, moveTo() {}, set() {} });
|
|
554
|
+
|
|
555
|
+
function startPlay(effectName, at = {}, reason = "play") {
|
|
556
|
+
if (at === null || typeof at !== "object" || Array.isArray(at)) refuse("bad_play", { message: "play takes where to play as an object.", field: "at", fix: "Give { positionM: { x, y, z } }." });
|
|
557
|
+
for (const field of Object.keys(at)) {
|
|
558
|
+
if (!AT_FIELDS.includes(field)) refuse("unknown_argument", { message: `play has no "${field}".`, field, fix: `Give only: ${AT_FIELDS.join(", ")}.` });
|
|
559
|
+
}
|
|
560
|
+
let name = effectName;
|
|
561
|
+
let scalePct = at.scalePct ?? 100;
|
|
562
|
+
let strengthPct = at.strengthPct ?? 100;
|
|
563
|
+
let tintHex = at.color ?? null;
|
|
564
|
+
let surfaceKind = at.surfaceKind ?? null;
|
|
565
|
+
if (at.follow !== undefined && at.follow !== null && !(at.follow instanceof THREE.Object3D)) refuse("bad_play", { message: "follow isn't a three.js object.", field: "follow", fix: "Give the object the effect rides on (any THREE.Object3D), or leave it out." });
|
|
566
|
+
const follow = at.follow ?? null;
|
|
567
|
+
if (!follow && !isPoint(at.positionM)) refuse("bad_play", { message: "play needs where to play.", field: "positionM", fix: "Give positionM: { x, y, z } in metres, or follow: an object the effect rides on." });
|
|
568
|
+
if (at.positionM !== undefined && !isPoint(at.positionM)) refuse("bad_play", { message: "positionM isn't a place.", field: "positionM", fix: "Give { x, y, z } in metres." });
|
|
569
|
+
for (const field of ["direction", "normal", "toPositionM"]) {
|
|
570
|
+
if (at[field] !== undefined && at[field] !== null && !isPoint(at[field])) refuse("bad_play", { message: `${field} isn't { x, y, z }.`, field, fix: "Give { x, y, z }." });
|
|
571
|
+
}
|
|
572
|
+
if (!isNumberIn(scalePct, 0.01, 10000)) refuse("bad_play", { message: "scalePct isn't a number above 0, up to 10000.", field: "scalePct", fix: "Give how big to play it against its file: 100 is as written." });
|
|
573
|
+
if (!isNumberIn(strengthPct, 0, 1000)) refuse("bad_play", { message: "strengthPct isn't a number from 0 to 1000.", field: "strengthPct", fix: "Give how strong to play it: 100 is as written, 50 half as solid and bright." });
|
|
574
|
+
if (tintHex !== null && !(typeof tintHex === "string" && HEX_COLOR_PATTERN.test(tintHex))) refuse("bad_play", { message: "color isn't a colour.", field: "color", fix: 'Give a colour as six hex digits in lowercase, like "#ff7a1a", or leave it out.' });
|
|
575
|
+
if (surfaceKind !== null && !SURFACE_KINDS.includes(surfaceKind)) refuse("bad_play", { message: `surfaceKind is ${JSON.stringify(surfaceKind)}, which isn't a surface kind.`, field: "surfaceKind", fix: `Give one of: ${SURFACE_KINDS.join(", ")}.` });
|
|
576
|
+
const startedAgoSec = at.startedAgoSec ?? 0;
|
|
577
|
+
if (!isNumberIn(startedAgoSec, 0, Infinity)) refuse("bad_play", { message: "startedAgoSec isn't a number from 0 up.", field: "startedAgoSec", fix: "Give how long ago the effect started, in seconds: 0 starts it now." });
|
|
578
|
+
|
|
579
|
+
if (hasHandlers("beforeEffect")) {
|
|
580
|
+
const position = at.positionM ?? { x: 0, y: 0, z: 0 };
|
|
581
|
+
const answer = ask("beforeEffect", { effectName: name, positionM: { x: position.x, y: position.y, z: position.z }, scalePct, strengthPct, color: tintHex, surfaceKind, reason });
|
|
582
|
+
if (answer === null) return inertHandle;
|
|
583
|
+
if (answer && typeof answer === "object") {
|
|
584
|
+
if (typeof answer.effectName === "string") name = answer.effectName;
|
|
585
|
+
if (isNumberIn(answer.scalePct, 0.01, 10000)) scalePct = answer.scalePct;
|
|
586
|
+
if (isNumberIn(answer.strengthPct, 0, 1000)) strengthPct = answer.strengthPct;
|
|
587
|
+
if (answer.color === null || (typeof answer.color === "string" && HEX_COLOR_PATTERN.test(answer.color))) tintHex = answer.color;
|
|
588
|
+
if (answer.surfaceKind === null || SURFACE_KINDS.includes(answer.surfaceKind)) surfaceKind = answer.surfaceKind;
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
const entry = registry.get(name);
|
|
592
|
+
if (!entry) refuse("unknown_effect", { message: `There's no effect "${name}".`, field: "effectName", fix: `Load it first: await effects.load(["${name}"]) for one of the piece's library, or effects.add(file) for the game's own. Loaded now: ${registry.size > 0 ? [...registry.keys()].slice(0, 12).join(", ") : "none"}${registry.size > 12 ? ", ..." : ""}.` });
|
|
593
|
+
// A play that's already over is never started: a player who joined after it ended.
|
|
594
|
+
if (!entry.file.is_looping && startedAgoSec > entry.runSec + entry.lingerSec + 120) return inertHandle;
|
|
595
|
+
const row = playTable.takeRow();
|
|
596
|
+
if (row < 0) {
|
|
597
|
+
toldThinned(name, 0);
|
|
598
|
+
return inertHandle;
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
const way = at.direction ?? at.normal ?? null;
|
|
602
|
+
const ownTurn = new THREE.Quaternion();
|
|
603
|
+
if (way) {
|
|
604
|
+
turned.set(way.x, way.y, way.z);
|
|
605
|
+
if (turned.lengthSq() > 1e-12) ownTurn.setFromUnitVectors(UP, turned.normalize());
|
|
606
|
+
}
|
|
607
|
+
const play = {
|
|
608
|
+
playId: nextPlayId,
|
|
609
|
+
entry,
|
|
610
|
+
seedNumber: Number.isInteger(at.seedNumber) ? at.seedNumber >>> 0 : (Math.random() * 4294967296) >>> 0,
|
|
611
|
+
startSec: nowSec - startedAgoSec,
|
|
612
|
+
stopSec: null,
|
|
613
|
+
isEnded: false,
|
|
614
|
+
row,
|
|
615
|
+
follow,
|
|
616
|
+
offset: new THREE.Vector3(at.positionM?.x ?? 0, at.positionM?.y ?? 0, at.positionM?.z ?? 0),
|
|
617
|
+
ownTurn,
|
|
618
|
+
place: new THREE.Vector3(),
|
|
619
|
+
turn: new THREE.Quaternion(),
|
|
620
|
+
earlierPlace: new THREE.Vector3(),
|
|
621
|
+
earlierSec: nowSec,
|
|
622
|
+
hasMoved: false,
|
|
623
|
+
hasNormal: Boolean(at.normal),
|
|
624
|
+
// A beam runs to toPositionM when one was given; without it, out along the effect's direction.
|
|
625
|
+
hasEnd: isPoint(at.toPositionM),
|
|
626
|
+
normal: at.normal ? new THREE.Vector3(at.normal.x, at.normal.y, at.normal.z).normalize() : UP,
|
|
627
|
+
toPlace: new THREE.Vector3(),
|
|
628
|
+
// The surface it stands on, as a normal and how far along it: soft shapes fade into it. All 0 with none.
|
|
629
|
+
surface: new THREE.Vector4(0, 0, 0, 0),
|
|
630
|
+
scaleShare: scalePct / 100,
|
|
631
|
+
strengthShare: strengthPct / 100,
|
|
632
|
+
tint: tintHex ? new THREE.Color(tintHex) : new THREE.Color(1, 1, 1),
|
|
633
|
+
surfaceKind,
|
|
634
|
+
debrisCount: 0,
|
|
635
|
+
// What a flash, a warp, a trail or a beam follows: the play itself, until it starts over and they let go.
|
|
636
|
+
view: null,
|
|
637
|
+
emitters: [],
|
|
638
|
+
loopCount: 0,
|
|
639
|
+
/** Turns a point of the play's own space (+y its direction) to the world's; answers a shared vector. */
|
|
640
|
+
turnPoint(x, y, z) {
|
|
641
|
+
return turned.set(x, y, z).applyQuaternion(play.turn);
|
|
642
|
+
},
|
|
643
|
+
};
|
|
644
|
+
play.view = Object.create(play);
|
|
645
|
+
nextPlayId += 1;
|
|
646
|
+
placePlay(play);
|
|
647
|
+
play.earlierPlace.copy(play.place);
|
|
648
|
+
if (!follow) {
|
|
649
|
+
if (at.normal) play.surface.set(play.normal.x, play.normal.y, play.normal.z, play.normal.dot(play.place));
|
|
650
|
+
else if (findSurface(play.place.x, play.place.y + 0.25, play.place.z, 0, -1, 0, 0.25 + 0.75 * play.scaleShare, standsOn)) play.surface.set(standsOn.normalX, standsOn.normalY, standsOn.normalZ, standsOn.normalX * standsOn.x + standsOn.normalY * standsOn.y + standsOn.normalZ * standsOn.z);
|
|
651
|
+
}
|
|
652
|
+
if (at.toPositionM) play.toPlace.set(at.toPositionM.x, at.toPositionM.y, at.toPositionM.z);
|
|
653
|
+
else play.toPlace.copy(play.place).addScaledVector(turned.set(0, 1, 0).applyQuaternion(play.turn), 10 * play.scaleShare);
|
|
654
|
+
writePlayRow(play);
|
|
655
|
+
makeEmitters(play);
|
|
656
|
+
startPassingElements(play, false);
|
|
657
|
+
plays.add(play);
|
|
658
|
+
tell("effectStarted", { playId: play.playId, effectName: name, positionM: { x: play.place.x, y: play.place.y, z: play.place.z }, scalePct, strengthPct, surfaceKind, reason });
|
|
659
|
+
|
|
660
|
+
return {
|
|
661
|
+
playId: play.playId,
|
|
662
|
+
effectName: name,
|
|
663
|
+
get isEnded() {
|
|
664
|
+
return play.isEnded;
|
|
665
|
+
},
|
|
666
|
+
/** Stops it: nothing new is given off, and what's in the air finishes. isImmediate takes everything away at once. */
|
|
667
|
+
stop(options = {}) {
|
|
668
|
+
if (play.isEnded) return;
|
|
669
|
+
if (play.stopSec === null || play.stopSec > nowSec) play.stopSec = nowSec;
|
|
670
|
+
if (options.isImmediate) endPlay(play);
|
|
671
|
+
},
|
|
672
|
+
/** Moves it: a new place, and a new direction when one is given. With follow, the place is from what it follows. */
|
|
673
|
+
moveTo(positionM, direction = null) {
|
|
674
|
+
if (!isPoint(positionM)) refuse("bad_play", { message: "moveTo takes a place.", field: "positionM", fix: "Give { x, y, z } in metres." });
|
|
675
|
+
play.offset.set(positionM.x, positionM.y, positionM.z);
|
|
676
|
+
// It no longer stands where its surface was found.
|
|
677
|
+
play.surface.set(0, 0, 0, 0);
|
|
678
|
+
play.isRowStale = true;
|
|
679
|
+
if (isPoint(direction) && turned.set(direction.x, direction.y, direction.z).lengthSq() > 1e-12) play.ownTurn.setFromUnitVectors(UP, turned.normalize());
|
|
680
|
+
},
|
|
681
|
+
/** Changes how it plays from now: { scalePct, strengthPct, color, toPositionM }, any of them. */
|
|
682
|
+
set(changes = {}) {
|
|
683
|
+
if (isNumberIn(changes.scalePct, 0.01, 10000)) play.scaleShare = changes.scalePct / 100;
|
|
684
|
+
if (isNumberIn(changes.strengthPct, 0, 1000)) play.strengthShare = changes.strengthPct / 100;
|
|
685
|
+
if (typeof changes.color === "string" && HEX_COLOR_PATTERN.test(changes.color)) play.tint.set(changes.color);
|
|
686
|
+
if (isPoint(changes.toPositionM)) {
|
|
687
|
+
play.toPlace.set(changes.toPositionM.x, changes.toPositionM.y, changes.toPositionM.z);
|
|
688
|
+
play.hasEnd = true;
|
|
689
|
+
}
|
|
690
|
+
play.isRowStale = true;
|
|
691
|
+
},
|
|
692
|
+
};
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
function endPlay(play) {
|
|
696
|
+
if (play.isEnded) return;
|
|
697
|
+
dropEmitters(play);
|
|
698
|
+
play.isEnded = true;
|
|
699
|
+
play.stopSec ??= nowSec;
|
|
700
|
+
plays.delete(play);
|
|
701
|
+
// Its row waits a frame, so the batches that still name it let go first.
|
|
702
|
+
endedRows.push(play.row);
|
|
703
|
+
tell("effectEnded", { playId: play.playId, effectName: play.entry.name });
|
|
704
|
+
}
|
|
705
|
+
let endedRows = [];
|
|
706
|
+
let freedRows = [];
|
|
707
|
+
|
|
708
|
+
/** Takes an emitter's run of particles and says where it starts counting. Answers whether it has one. */
|
|
709
|
+
function startEmitter(play, state, sinceSec, cameraPlace) {
|
|
710
|
+
if (nowSec < state.retrySec) return false;
|
|
711
|
+
const { compiled } = state;
|
|
712
|
+
const batch = compiled.isChunk ? chunks : sprites;
|
|
713
|
+
const distanceM = play.place.distanceTo(cameraPlace);
|
|
714
|
+
const plan = planEmitter({
|
|
715
|
+
wantedCount: compiled.wantedCount,
|
|
716
|
+
isNeverThinned: compiled.isNeverThinned,
|
|
717
|
+
qualityLevel,
|
|
718
|
+
importance: play.entry.file.importance,
|
|
719
|
+
distanceM,
|
|
720
|
+
freeCount: batch.freeCount,
|
|
721
|
+
longestFreeCount: batch.freeCount,
|
|
722
|
+
lookCountShare: compiled.lookCountShare,
|
|
723
|
+
fillShare: 1,
|
|
724
|
+
});
|
|
725
|
+
const slab = plan.slotCount > 0 ? batch.takeSlab(plan.slotCount, play) : null;
|
|
726
|
+
if (!slab) {
|
|
727
|
+
state.retrySec = nowSec + RETRY_INTERVAL_SEC;
|
|
728
|
+
toldThinned(play.entry.name, 0);
|
|
729
|
+
return false;
|
|
730
|
+
}
|
|
731
|
+
state.slab = slab;
|
|
732
|
+
state.batch = batch;
|
|
733
|
+
state.keptShare = slab.capacity < plan.slotCount ? plan.keptShare * (slab.capacity / plan.slotCount) : plan.keptShare;
|
|
734
|
+
const fullShare = compiled.isNeverThinned ? 1 : (compiled.lookCountShare * QUALITY_BUDGETS[qualityLevel].keptPct) / 100;
|
|
735
|
+
if (state.keptShare < fullShare * 0.6) toldThinned(play.entry.name, state.keptShare / Math.max(fullShare, 1e-6));
|
|
736
|
+
// Only what's still alive is written: an effect a player joins partway through, or one filled in again.
|
|
737
|
+
state.bornCount = bornCountAt(compiled.emitter, sinceSec - compiled.maxLifeSec);
|
|
738
|
+
return true;
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
function emit(play, state, cameraPlace, pxPerM, screenPxCount) {
|
|
742
|
+
const { compiled } = state;
|
|
743
|
+
const base = compiled.emitter;
|
|
744
|
+
const startSec = play.startSec + compiled.startDelaySec;
|
|
745
|
+
let sinceSec = nowSec - startSec;
|
|
746
|
+
const isStopped = play.stopSec !== null && play.stopSec <= nowSec;
|
|
747
|
+
if (isStopped) sinceSec = Math.min(sinceSec, play.stopSec - startSec);
|
|
748
|
+
if (sinceSec < 0) {
|
|
749
|
+
if (isStopped) state.isDone = true;
|
|
750
|
+
return;
|
|
751
|
+
}
|
|
752
|
+
const isOver = isStopped || (base.loopDurationSec === 0 && sinceSec >= base.emitDurationSec);
|
|
753
|
+
if (!state.slab && !startEmitter(play, state, sinceSec, cameraPlace)) {
|
|
754
|
+
if (isOver && nowSec - startSec > base.emitDurationSec + compiled.maxLifeSec) state.isDone = true;
|
|
755
|
+
return;
|
|
756
|
+
}
|
|
757
|
+
const targetCount = bornCountAt(base, sinceSec);
|
|
758
|
+
let number = state.bornCount;
|
|
759
|
+
// After a long gap (a hidden tab), only what's still alive.
|
|
760
|
+
if (targetCount - number > state.slab.capacity * 2) number = Math.max(number, bornCountAt(base, sinceSec - compiled.maxLifeSec));
|
|
761
|
+
if (number < targetCount) {
|
|
762
|
+
let share = state.keptShare;
|
|
763
|
+
if (compiled.isSeeThrough && !compiled.isNeverThinned && pxPerM > 0) {
|
|
764
|
+
// A see-through particle that covers a good part of the screen is what the fill guard thins.
|
|
765
|
+
const acrossPx = (compiled.fillSizeM * play.scaleShare * pxPerM) / Math.max(play.place.distanceTo(cameraPlace), 0.5);
|
|
766
|
+
if ((acrossPx * acrossPx) / screenPxCount > GUARDED_SCREEN_SHARE) share *= fillGuard.fillShare;
|
|
767
|
+
}
|
|
768
|
+
const { slab, batch } = state;
|
|
769
|
+
const scale = play.scaleShare;
|
|
770
|
+
const turn = play.turn;
|
|
771
|
+
const spanSec = nowSec - play.earlierSec;
|
|
772
|
+
for (; number < targetCount; number += 1) {
|
|
773
|
+
if (share < 1 && !isParticleKept(play.seedNumber, base.elementIndex, number, share)) continue;
|
|
774
|
+
makeParticle(base, play.seedNumber, number, born);
|
|
775
|
+
const birthSec = startSec + birthSecOf(base, number);
|
|
776
|
+
if (birthSec + born.lifeSec <= nowSec) continue;
|
|
777
|
+
if (compiled.isAttached) {
|
|
778
|
+
batch.write(slab, born.x * scale, born.y * scale, born.z * scale, born.velocityX * scale, born.velocityY * scale, born.velocityZ * scale, toBatchSec(birthSec), born.lifeSec, born.seedNumber, compiled.row, play.row);
|
|
779
|
+
continue;
|
|
780
|
+
}
|
|
781
|
+
turned.set(born.x * scale, born.y * scale, born.z * scale).applyQuaternion(turn);
|
|
782
|
+
let x = play.place.x + turned.x;
|
|
783
|
+
let y = play.place.y + turned.y;
|
|
784
|
+
let z = play.place.z + turned.z;
|
|
785
|
+
if (play.hasMoved && spanSec > 0) {
|
|
786
|
+
// Let go where the effect was at that moment, so a fast one leaves an even trail.
|
|
787
|
+
const back = Math.min(Math.max((nowSec - birthSec) / spanSec, 0), 1);
|
|
788
|
+
x += (play.earlierPlace.x - play.place.x) * back;
|
|
789
|
+
y += (play.earlierPlace.y - play.place.y) * back;
|
|
790
|
+
z += (play.earlierPlace.z - play.place.z) * back;
|
|
791
|
+
}
|
|
792
|
+
turned.set(born.velocityX * scale, born.velocityY * scale, born.velocityZ * scale).applyQuaternion(turn);
|
|
793
|
+
batch.write(slab, x, y, z, turned.x, turned.y, turned.z, toBatchSec(birthSec), born.lifeSec, born.seedNumber, compiled.row, play.row);
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
state.bornCount = Math.max(state.bornCount, targetCount);
|
|
797
|
+
if (isOver) state.isDone = true;
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
// ---- Shakes ----
|
|
801
|
+
const shakes = new Set();
|
|
802
|
+
/** How hard the camera shakes right now, for a game with a camera of its own: strengthPct, and an offset to add to it. */
|
|
803
|
+
const shakeNow = { strengthPct: 0, offsetM: new THREE.Vector3(), rollRad: 0 };
|
|
804
|
+
function updateShakes(cameraPlace) {
|
|
805
|
+
let strength = 0;
|
|
806
|
+
for (const shake of shakes) {
|
|
807
|
+
const sinceSec = nowSec - shake.startSec;
|
|
808
|
+
if (sinceSec >= shake.durationSec || shake.play.isEnded) {
|
|
809
|
+
shakes.delete(shake);
|
|
810
|
+
continue;
|
|
811
|
+
}
|
|
812
|
+
if (sinceSec < 0) continue;
|
|
813
|
+
const nearShare = Math.max(1 - shake.play.place.distanceTo(cameraPlace) / (shake.radiusM * shake.play.scaleShare), 0);
|
|
814
|
+
const felt = shake.strengthShare * shake.play.strengthShare * nearShare;
|
|
815
|
+
if (!shake.isTold) {
|
|
816
|
+
shake.isTold = true;
|
|
817
|
+
if (felt > 0.005) tell("shake", { strengthPct: Math.min(felt * 100, 100), durationSec: shake.durationSec - sinceSec });
|
|
818
|
+
}
|
|
819
|
+
const fade = 1 - sinceSec / shake.durationSec;
|
|
820
|
+
strength = Math.max(strength, felt * fade * fade);
|
|
821
|
+
}
|
|
822
|
+
strength = Math.min(strength, 1);
|
|
823
|
+
shakeNow.strengthPct = strength * 100;
|
|
824
|
+
// Three waves that never line up on each axis: a shake, never a wobble.
|
|
825
|
+
const reachM = strength * 0.35;
|
|
826
|
+
shakeNow.offsetM.set(Math.sin(nowSec * 61.3) + Math.sin(nowSec * 37.1 + 1.3), Math.sin(nowSec * 53.7 + 2.1) + Math.sin(nowSec * 29.9 + 0.4), Math.sin(nowSec * 47.9 + 4.2) + Math.sin(nowSec * 33.3 + 2.9)).multiplyScalar(reachM * 0.5);
|
|
827
|
+
shakeNow.rollRad = strength * 0.035 * Math.sin(nowSec * 43.1 + 0.7);
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
// ---- The scene's light ----
|
|
831
|
+
let sunLight = null;
|
|
832
|
+
let fillLight = null;
|
|
833
|
+
let lightSearchedSec = -Infinity;
|
|
834
|
+
const sunTarget = new THREE.Vector3();
|
|
835
|
+
/**
|
|
836
|
+
* The sun's shadow on the particles, at high quality: read from the shadow map three already drew for the scene,
|
|
837
|
+
* so it costs no drawing of its own. Only a map three compares depths in for the shader (its usual kind) is read;
|
|
838
|
+
* with any other, or none, particles stand in open sun as before.
|
|
839
|
+
*/
|
|
840
|
+
function readSunShadow() {
|
|
841
|
+
const shadow = sunLight?.castShadow && sunLight.visible ? sunLight.shadow : null;
|
|
842
|
+
const map = shadow?.map?.depthTexture ?? null;
|
|
843
|
+
const canRead = map !== null && map.compareFunction === THREE.LessEqualCompare && renderer.shadowMap?.enabled === true && QUALITY_BUDGETS[qualityLevel].hasSunShadows && canDraw;
|
|
844
|
+
sharedUniforms.uSunShadow.value = canRead ? map : null;
|
|
845
|
+
sharedUniforms.uSunShadowShare.value = canRead ? Math.min(Math.max(shadow.intensity ?? 1, 0), 1) : 0;
|
|
846
|
+
if (!canRead) return;
|
|
847
|
+
sharedUniforms.uSunShadowMatrix.value.copy(shadow.matrix);
|
|
848
|
+
// A third of a metre between readings, as a share of the map's width.
|
|
849
|
+
const widthM = shadow.camera.right - shadow.camera.left;
|
|
850
|
+
sharedUniforms.uSunShadowSpread.value = widthM > 0 ? 0.33 / widthM : 0;
|
|
851
|
+
}
|
|
852
|
+
function readLight() {
|
|
853
|
+
if (lighting) {
|
|
854
|
+
sunLight = lighting.sun ?? null;
|
|
855
|
+
fillLight = lighting.fill ?? null;
|
|
856
|
+
} else if (nowSec - lightSearchedSec >= LIGHT_SEARCH_INTERVAL_SEC || lightSearchedSec > nowSec) {
|
|
857
|
+
lightSearchedSec = nowSec;
|
|
858
|
+
sunLight = null;
|
|
859
|
+
fillLight = null;
|
|
860
|
+
scene.traverseVisible((object) => {
|
|
861
|
+
if (object.isDirectionalLight && (!sunLight || object.intensity > sunLight.intensity)) sunLight = object;
|
|
862
|
+
if ((object.isHemisphereLight || object.isAmbientLight) && (!fillLight || (object.isHemisphereLight && !fillLight.isHemisphereLight))) fillLight = object;
|
|
863
|
+
});
|
|
864
|
+
}
|
|
865
|
+
if (sunLight) {
|
|
866
|
+
if (lighting?.lightDirection) sharedUniforms.uSunDirection.value.copy(lighting.lightDirection);
|
|
867
|
+
else {
|
|
868
|
+
sunLight.getWorldPosition(sharedUniforms.uSunDirection.value);
|
|
869
|
+
sunLight.target.getWorldPosition(sunTarget);
|
|
870
|
+
sharedUniforms.uSunDirection.value.sub(sunTarget).normalize();
|
|
871
|
+
}
|
|
872
|
+
sharedUniforms.uSunColor.value.copy(sunLight.color).multiplyScalar(sunLight.visible ? sunLight.intensity : 0);
|
|
873
|
+
} else sharedUniforms.uSunColor.value.setRGB(0, 0, 0);
|
|
874
|
+
readSunShadow();
|
|
875
|
+
if (fillLight) {
|
|
876
|
+
sharedUniforms.uSkyColor.value.copy(fillLight.color).multiplyScalar(fillLight.visible ? fillLight.intensity : 0);
|
|
877
|
+
if (fillLight.isHemisphereLight) sharedUniforms.uGroundColor.value.copy(fillLight.groundColor).multiplyScalar(fillLight.visible ? fillLight.intensity : 0);
|
|
878
|
+
else sharedUniforms.uGroundColor.value.copy(sharedUniforms.uSkyColor.value);
|
|
879
|
+
} else if (!sunLight) {
|
|
880
|
+
// A scene with no lights of its own: a plain day, so effects are never black.
|
|
881
|
+
sharedUniforms.uSunColor.value.setRGB(2.4, 2.3, 2.1);
|
|
882
|
+
sharedUniforms.uSkyColor.value.setRGB(0.9, 1, 1.15);
|
|
883
|
+
sharedUniforms.uGroundColor.value.setRGB(0.4, 0.38, 0.35);
|
|
884
|
+
} else {
|
|
885
|
+
sharedUniforms.uSkyColor.value.setRGB(0, 0, 0);
|
|
886
|
+
sharedUniforms.uGroundColor.value.setRGB(0, 0, 0);
|
|
887
|
+
}
|
|
888
|
+
// The scene's surroundings light its solids from every side; effects take about as much, so their shaded sides match.
|
|
889
|
+
if (scene.environment) {
|
|
890
|
+
const share = scene.environmentIntensity ?? 1;
|
|
891
|
+
const sky = sharedUniforms.uSkyColor.value;
|
|
892
|
+
const ground = sharedUniforms.uGroundColor.value;
|
|
893
|
+
sky.setRGB(sky.r + share * 0.7, sky.g + share * 0.8, sky.b + share * 0.95);
|
|
894
|
+
ground.setRGB(ground.r + share * 0.42, ground.g + share * 0.4, ground.b + share * 0.38);
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
// ---- Putting quality and the look in place ----
|
|
899
|
+
|
|
900
|
+
/** Makes the batches the size the quality level and the game's budget allow, and starts everything playing over in them. */
|
|
901
|
+
function applyQuality() {
|
|
902
|
+
const quality = QUALITY_BUDGETS[qualityLevel];
|
|
903
|
+
const particleCount = particleBudget(qualityLevel, settings.get("particleBudgetPct"));
|
|
904
|
+
const chunkCount = Math.max(Math.round(particleCount * CHUNK_BUDGET_SHARE), quality.debrisCount + 16);
|
|
905
|
+
if (!sprites || sprites.capacity !== particleCount || chunks.capacity !== chunkCount) {
|
|
906
|
+
for (const play of plays) for (const state of play.emitters) state.slab = null;
|
|
907
|
+
debris.setCapacity(0);
|
|
908
|
+
if (sprites) {
|
|
909
|
+
group.remove(sprites.mesh, chunks.mesh);
|
|
910
|
+
sprites.dispose();
|
|
911
|
+
chunks.dispose();
|
|
912
|
+
}
|
|
913
|
+
sprites = createSpriteBatch({ particleCount, sharedUniforms });
|
|
914
|
+
chunks = createChunkBatch({ chunkCount, sharedUniforms });
|
|
915
|
+
group.add(sprites.mesh, chunks.mesh);
|
|
916
|
+
}
|
|
917
|
+
if (debris.capacity !== quality.debrisCount) debris.setCapacity(quality.debrisCount);
|
|
918
|
+
if (marks.capacity !== quality.markCount) marks.setCapacity(quality.markCount);
|
|
919
|
+
flashes.setLightCount(settings.get("flashLightsEnabled") ? quality.flashLightCount : 0);
|
|
920
|
+
if (atlasSizePx !== quality.atlasSizePx) {
|
|
921
|
+
atlas?.dispose();
|
|
922
|
+
atlasSizePx = quality.atlasSizePx;
|
|
923
|
+
atlas = createShapeAtlas(renderer, atlasSizePx);
|
|
924
|
+
sharedUniforms.uAtlas.value = atlas.texture;
|
|
925
|
+
}
|
|
926
|
+
applyLook();
|
|
927
|
+
}
|
|
928
|
+
|
|
929
|
+
/** Draws everything in the look in use: every effect's rows are written again, and what's playing is filled in again. */
|
|
930
|
+
function applyLook() {
|
|
931
|
+
readLook();
|
|
932
|
+
for (const entry of registry.values()) styleEntry(entry);
|
|
933
|
+
weather.elements.forEach((element, index) => writeParticleRow(weatherRows[index], element, styles[element.material], index + 1));
|
|
934
|
+
weather.rebuild({ sprites, rows: weatherRows, qualityLevel, countShare: settings.get("particleBudgetPct") / 100 });
|
|
935
|
+
weather.setHidden([group, lighting?.sky ?? null, scene.getObjectByName("zaisma_sky") ?? null]);
|
|
936
|
+
for (const play of plays) restartPlay(play);
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
function changeQuality(nextLevel, reason) {
|
|
940
|
+
if (nextLevel === qualityLevel || !QUALITY_ORDER.includes(nextLevel)) return;
|
|
941
|
+
qualityLevel = nextLevel;
|
|
942
|
+
applyQuality();
|
|
943
|
+
tell("qualityChanged", { qualityLevel, reason });
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
const stopFollowingLighting = lighting?.hooks?.on ? lighting.hooks.on("qualityChanged", (change) => settings.get("qualityLevel") === "auto" && changeQuality(change.qualityLevel, "lighting_quality")) : null;
|
|
947
|
+
settings.onChange((change) => {
|
|
948
|
+
if (change.name === "qualityLevel") changeQuality(change.newValue === "auto" ? startingLevel() : change.newValue, "setting");
|
|
949
|
+
else if (change.name === "particleBudgetPct" || change.name === "flashLightsEnabled") applyQuality();
|
|
950
|
+
else if (change.name === "look") applyLook();
|
|
951
|
+
else if (change.name === "marksEnabled" && !change.newValue) marks.clear();
|
|
952
|
+
else if (["rainPct", "snowPct", "fogPct", "windSpeedMPerSec", "windDirectionDeg", "windGustPct"].includes(change.name)) wasWeatherTurning = true;
|
|
953
|
+
});
|
|
954
|
+
applyQuality();
|
|
955
|
+
|
|
956
|
+
// ---- Every frame ----
|
|
957
|
+
const cameraPlace = new THREE.Vector3();
|
|
958
|
+
const sizePx = new THREE.Vector2();
|
|
959
|
+
const stats = { particleCount: 0, particleBudgetCount: 0, playCount: 0, drawCallCount: 0, updateDurationMs: 0, keptPct: 100, markCount: 0, debrisCount: 0, flashCount: 0 };
|
|
960
|
+
const timer = typeof performance === "object" ? performance : Date;
|
|
961
|
+
|
|
962
|
+
function update(camera, nowMs = timer.now()) {
|
|
963
|
+
if (!(camera instanceof THREE.Camera)) refuse("camera_needed", { message: "update needs the camera the scene is drawn from.", field: "camera", fix: "Call effects.update(camera) every frame, before renderer.render(scene, camera)." });
|
|
964
|
+
const startedMs = timer.now();
|
|
965
|
+
const frameSec = lastUpdateMs === null ? 0 : (Math.max(nowMs - lastUpdateMs, 0) / 1000) * (settings.get("timeScalePct") / 100);
|
|
966
|
+
lastUpdateMs = nowMs;
|
|
967
|
+
nowSec += frameSec;
|
|
968
|
+
if (nowSec - batchStartSec > CLOCK_RESTART_SEC) {
|
|
969
|
+
batchStartSec += CLOCK_RESTART_SPAN_SEC;
|
|
970
|
+
sprites.shiftTime(CLOCK_RESTART_SPAN_SEC);
|
|
971
|
+
chunks.shiftTime(CLOCK_RESTART_SPAN_SEC);
|
|
972
|
+
marks.shiftTime(CLOCK_RESTART_SPAN_SEC);
|
|
973
|
+
}
|
|
974
|
+
const batchNowSec = toBatchSec(nowSec);
|
|
975
|
+
sharedUniforms.uTime.value = batchNowSec;
|
|
976
|
+
sharedUniforms.uGroundHeightM.value = settings.get("groundHeightM");
|
|
977
|
+
|
|
978
|
+
if (settings.get("qualityLevel") === "auto" && !lighting && frameWatcher.count(nowMs) && qualityLevel !== "low") changeQuality(QUALITY_ORDER[QUALITY_ORDER.indexOf(qualityLevel) - 1], "slow_frames");
|
|
979
|
+
const quality = QUALITY_BUDGETS[qualityLevel];
|
|
980
|
+
|
|
981
|
+
camera.getWorldPosition(cameraPlace);
|
|
982
|
+
let pxPerM = 0;
|
|
983
|
+
let screenPxCount = 1;
|
|
984
|
+
if (canDraw) {
|
|
985
|
+
renderer.getDrawingBufferSize(sizePx);
|
|
986
|
+
screenPxCount = Math.max(sizePx.x * sizePx.y, 1);
|
|
987
|
+
if (camera.isPerspectiveCamera) pxPerM = 0.5 * sizePx.y * camera.projectionMatrix.elements[5];
|
|
988
|
+
}
|
|
989
|
+
sharedUniforms.uPxPerM.value = pxPerM;
|
|
990
|
+
readLight();
|
|
991
|
+
|
|
992
|
+
// Rows of plays that ended last frame are free now; the ones that ended this frame wait one more.
|
|
993
|
+
for (const row of freedRows) playTable.giveRow(row);
|
|
994
|
+
freedRows = endedRows;
|
|
995
|
+
endedRows = [];
|
|
996
|
+
|
|
997
|
+
landingEffectCount = 0;
|
|
998
|
+
let coveredScreenCount = 0;
|
|
999
|
+
for (const play of plays) {
|
|
1000
|
+
const { file } = play.entry;
|
|
1001
|
+
play.earlierPlace.copy(play.place);
|
|
1002
|
+
placePlay(play);
|
|
1003
|
+
play.hasMoved = play.earlierPlace.distanceToSquared(play.place) > 1e-10;
|
|
1004
|
+
if (play.hasMoved || play.follow || play.isRowStale) {
|
|
1005
|
+
writePlayRow(play);
|
|
1006
|
+
play.isRowStale = false;
|
|
1007
|
+
}
|
|
1008
|
+
// An effect that plays once is over when its emitters have run.
|
|
1009
|
+
if (!file.is_looping && play.stopSec === null && nowSec - play.startSec >= play.entry.runSec) play.stopSec = play.startSec + play.entry.runSec;
|
|
1010
|
+
if (file.is_looping && play.stopSec === null) {
|
|
1011
|
+
// A looping effect's beams strike again each time it starts over.
|
|
1012
|
+
const loopCount = Math.floor((nowSec - play.startSec) / file.duration_sec);
|
|
1013
|
+
if (loopCount > play.loopCount) {
|
|
1014
|
+
play.loopCount = loopCount;
|
|
1015
|
+
for (const compiled of play.entry.elements) if (compiled.elementKind === "beam" && isElementPlayed(play, compiled.element)) addBeam(play, compiled, play.startSec + loopCount * file.duration_sec + compiled.startDelaySec);
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
for (const state of play.emitters) {
|
|
1019
|
+
if (state.isFinished) continue;
|
|
1020
|
+
if (!state.isDone) emit(play, state, cameraPlace, pxPerM, screenPxCount);
|
|
1021
|
+
if (state.slab && state.compiled.isSeeThrough && pxPerM > 0 && state.batch === sprites) {
|
|
1022
|
+
const acrossPx = (state.compiled.fillSizeM * play.scaleShare * pxPerM) / Math.max(play.place.distanceTo(cameraPlace), 0.5);
|
|
1023
|
+
coveredScreenCount += state.slab.liveCount * Math.min((acrossPx * acrossPx * 0.5) / screenPxCount, 1);
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
play.earlierSec = nowSec;
|
|
1027
|
+
}
|
|
1028
|
+
stats.keptPct = Math.round(fillGuard.count(coveredScreenCount, qualityLevel) * 100);
|
|
1029
|
+
|
|
1030
|
+
debris.update(nowSec, frameSec, toBatchSec);
|
|
1031
|
+
flashes.update(nowSec, cameraPlace, settings.get("flashLightsEnabled"));
|
|
1032
|
+
ribbons.update(nowSec, cameraPlace);
|
|
1033
|
+
marks.update(batchNowSec);
|
|
1034
|
+
warps.update(nowSec, settings.get("warpsEnabled") && quality.hasWarps);
|
|
1035
|
+
updateShakes(cameraPlace);
|
|
1036
|
+
const isWeatherTurning = weather.update({ nowSec, frameSec, camera, target: weatherTarget(), changeDurationSec: settings.get("weatherChangeDurationSec"), groundHeightM: settings.get("groundHeightM"), hasShelter: quality.hasRainShelter && settings.get("rainShelterEnabled") });
|
|
1037
|
+
if ((isWeatherTurning && nowSec - weatherToldSec >= 0.25) || (wasWeatherTurning && !isWeatherTurning)) {
|
|
1038
|
+
weatherToldSec = nowSec;
|
|
1039
|
+
const { rainPct, snowPct, fogPct, windSpeedMPerSec, windDirectionDeg, isSettled } = weather.now;
|
|
1040
|
+
tell("weatherChanged", { rainPct, snowPct, fogPct, windSpeedMPerSec, windDirectionDeg, isSettled });
|
|
1041
|
+
}
|
|
1042
|
+
wasWeatherTurning = isWeatherTurning;
|
|
1043
|
+
sprites.update(batchNowSec, cameraPlace);
|
|
1044
|
+
chunks.update(batchNowSec);
|
|
1045
|
+
partners.update(nowSec, frameSec, camera);
|
|
1046
|
+
|
|
1047
|
+
// An emitter lets go of its particles once the last is gone; a play ends once all of it is.
|
|
1048
|
+
for (const play of plays) {
|
|
1049
|
+
let isAllFinished = true;
|
|
1050
|
+
for (const state of play.emitters) {
|
|
1051
|
+
if (state.isFinished) continue;
|
|
1052
|
+
const isEmpty = !state.slab || (state.batch === sprites ? state.slab.liveCount === 0 : state.slab.lastEndSec <= batchNowSec);
|
|
1053
|
+
if (state.isDone && isEmpty) {
|
|
1054
|
+
if (state.slab) state.batch.giveSlab(state.slab);
|
|
1055
|
+
state.slab = null;
|
|
1056
|
+
state.isFinished = true;
|
|
1057
|
+
} else isAllFinished = false;
|
|
1058
|
+
}
|
|
1059
|
+
if (!isAllFinished || play.stopSec === null || play.debrisCount > 0) continue;
|
|
1060
|
+
const lingerUntilSec = Math.max(play.entry.file.is_looping ? 0 : play.startSec + play.entry.lingerSec, play.stopSec + play.entry.ribbonTailSec);
|
|
1061
|
+
if (nowSec >= lingerUntilSec) endPlay(play);
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
stats.particleCount = sprites.liveCount + chunks.liveCount;
|
|
1065
|
+
stats.particleBudgetCount = sprites.capacity;
|
|
1066
|
+
stats.playCount = plays.size;
|
|
1067
|
+
stats.markCount = marks.liveCount;
|
|
1068
|
+
stats.debrisCount = debris.liveCount;
|
|
1069
|
+
stats.flashCount = flashes.liveCount;
|
|
1070
|
+
stats.drawCallCount = group.children.reduce((count, mesh) => count + (mesh.visible ? 1 : 0), 0);
|
|
1071
|
+
stats.updateDurationMs = timer.now() - startedMs;
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
const effects = {
|
|
1075
|
+
settings,
|
|
1076
|
+
hooks,
|
|
1077
|
+
/** three's own objects the effects are drawn with, for anything the settings don't reach. */
|
|
1078
|
+
group,
|
|
1079
|
+
add,
|
|
1080
|
+
load,
|
|
1081
|
+
/** Whether an effect is loaded. */
|
|
1082
|
+
has: (effectName) => registry.has(effectName),
|
|
1083
|
+
/** An effect's file as loaded, every field there, or null. */
|
|
1084
|
+
get: (effectName) => (registry.has(effectName) ? structuredClone(registry.get(effectName).file) : null),
|
|
1085
|
+
/** Every effect loaded: { name, family, summary, importance, isLooping }. */
|
|
1086
|
+
list: () => [...registry.values()].map(({ file }) => ({ name: file.name, family: file.family, summary: file.summary, importance: file.importance, isLooping: file.is_looping })),
|
|
1087
|
+
/** Plays an effect. at: { positionM, direction, normal, toPositionM, scalePct, strengthPct, color, surfaceKind, follow, seedNumber, startedAgoSec }. */
|
|
1088
|
+
play: (effectName, at) => startPlay(effectName, at, "play"),
|
|
1089
|
+
/** What the online kind calls for an effect another player's game or the game server played: as play, told with the reason shared. */
|
|
1090
|
+
playShared: (effectName, at) => startPlay(effectName, at, "shared"),
|
|
1091
|
+
/** Stops everything playing. { isImmediate } takes what's on screen away at once. */
|
|
1092
|
+
stopAll(options = {}) {
|
|
1093
|
+
for (const play of [...plays]) {
|
|
1094
|
+
if (play.stopSec === null || play.stopSec > nowSec) play.stopSec = nowSec;
|
|
1095
|
+
if (options.isImmediate) endPlay(play);
|
|
1096
|
+
}
|
|
1097
|
+
},
|
|
1098
|
+
/** Takes every mark off the level: a level starting over. */
|
|
1099
|
+
clearMarks: () => marks.clear(),
|
|
1100
|
+
update,
|
|
1101
|
+
/** For a game that draws through the lighting effects at high quality: call after its last draw, and warps are laid on the picture. */
|
|
1102
|
+
drawWarps(camera) {
|
|
1103
|
+
warps.drawOnScreen(renderer, camera);
|
|
1104
|
+
},
|
|
1105
|
+
/** Defines the game's own look, { basedOnLookName, materials }, and draws in it. */
|
|
1106
|
+
defineOwnLook(look) {
|
|
1107
|
+
const found = ownLookProblem(look);
|
|
1108
|
+
if (found) refuse("bad_look", found);
|
|
1109
|
+
ownLook = structuredClone(look);
|
|
1110
|
+
if (settings.get("look") === "own") applyLook();
|
|
1111
|
+
else settings.set({ look: "own" });
|
|
1112
|
+
},
|
|
1113
|
+
/** The look in use: cartoon, glowing, faceted, realistic or own. */
|
|
1114
|
+
get lookName() {
|
|
1115
|
+
return lookName;
|
|
1116
|
+
},
|
|
1117
|
+
/** The quality level in use, with auto worked out: low, medium or high. */
|
|
1118
|
+
get qualityLevel() {
|
|
1119
|
+
return qualityLevel;
|
|
1120
|
+
},
|
|
1121
|
+
/** The weather right now, as it eases toward its settings, and the wind in metres a second. */
|
|
1122
|
+
weather: {
|
|
1123
|
+
get rainPct() {
|
|
1124
|
+
return weather.now.rainPct;
|
|
1125
|
+
},
|
|
1126
|
+
get snowPct() {
|
|
1127
|
+
return weather.now.snowPct;
|
|
1128
|
+
},
|
|
1129
|
+
get fogPct() {
|
|
1130
|
+
return weather.now.fogPct;
|
|
1131
|
+
},
|
|
1132
|
+
get windSpeedMPerSec() {
|
|
1133
|
+
return weather.now.windSpeedMPerSec;
|
|
1134
|
+
},
|
|
1135
|
+
get windDirectionDeg() {
|
|
1136
|
+
return weather.now.windDirectionDeg;
|
|
1137
|
+
},
|
|
1138
|
+
get windGustPct() {
|
|
1139
|
+
return weather.now.windGustPct;
|
|
1140
|
+
},
|
|
1141
|
+
get isSettled() {
|
|
1142
|
+
return weather.now.isSettled;
|
|
1143
|
+
},
|
|
1144
|
+
windM: weather.windM,
|
|
1145
|
+
},
|
|
1146
|
+
shake: shakeNow,
|
|
1147
|
+
/** What the effects cost this frame: live particles against the budget, plays, draw calls, and the time update took. */
|
|
1148
|
+
stats,
|
|
1149
|
+
/** The seconds the effects have counted, which time_scale_pct slows. */
|
|
1150
|
+
get timeSec() {
|
|
1151
|
+
return nowSec;
|
|
1152
|
+
},
|
|
1153
|
+
dispose() {
|
|
1154
|
+
for (const play of [...plays]) endPlay(play);
|
|
1155
|
+
stopFollowingLighting?.();
|
|
1156
|
+
partners.dispose();
|
|
1157
|
+
weather.dispose();
|
|
1158
|
+
flashes.dispose();
|
|
1159
|
+
scene.remove(group);
|
|
1160
|
+
for (const batch of [sprites, chunks, marks, ribbons, warps]) batch.dispose();
|
|
1161
|
+
atlas?.dispose();
|
|
1162
|
+
elementTable.dispose();
|
|
1163
|
+
playTable.dispose();
|
|
1164
|
+
},
|
|
1165
|
+
};
|
|
1166
|
+
const partners = connectPartners({ effects, given, settings, startPlay, findSurface, ask, hasHandlers, shakeNow });
|
|
1167
|
+
return effects;
|
|
1168
|
+
}
|