Time is an argument, so speed scales it and a prewarm offsets it (#87)
game-maker / suite (push) Successful in 9m48s
game-maker / suite (push) Successful in 9m48s
Speed and Prewarm are not state and not a second loop: both are arithmetic on the clock argument the field already passes to every particle formula. fieldTime = elapsed * timeScale + prewarmOffset, a pure rule next to liveRange, called at the one place ParticleField.sync forms its time, so preview and world inherit it together. Prewarm offsets by one lifetime because that is the smallest offset which fills a continuous emitter; a burst is dead at time >= lifetime, so the same offset would skip it entirely and it is suppressed there. The tab's slider counts wall-clock seconds, so its span divides by the scale. A missing row falls back to 1 / off, so old project files need no migration. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
fbb2d157f0
commit
8ae20d044f
8 files changed
+191
-10
No files matched your search
@@ -9,6 +9,10 @@ export interface EmitterSettings {
|
||||
count: number;
|
||||
/** Seconds one particle lives. */
|
||||
lifetime: number;
|
||||
/** How fast the source's own clock runs against the world's: 2 is twice the speed. */
|
||||
timeScale: number;
|
||||
/** Start a lifetime in, so the field is already full at second 0. */
|
||||
prewarm: boolean;
|
||||
/** The most that may be alive at once; the oldest are the ones dropped. */
|
||||
max: number;
|
||||
}
|
||||
@@ -31,6 +35,24 @@ export function birthTime(settings: EmitterSettings, index: number): number {
|
||||
return settings.rate > 0 ? index / settings.rate : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* The clock the formulas are handed, from the seconds the source has been alive: a factor and a
|
||||
* summand on that one argument rather than any state, which is what lets a prewarmed field be shown
|
||||
* at its first frame without simulating the way there.
|
||||
*/
|
||||
export function fieldTime(settings: EmitterSettings, elapsed: number): number {
|
||||
return elapsed * settings.timeScale + prewarmOffset(settings);
|
||||
}
|
||||
|
||||
/**
|
||||
* A lifetime, which is the smallest offset that makes a continuous field full: at that second the
|
||||
* oldest particle alive is exactly the one about to die. A burst has nothing left by then, so the
|
||||
* offset would hide it altogether – prewarm means nothing there.
|
||||
*/
|
||||
export function prewarmOffset(settings: EmitterSettings): number {
|
||||
return settings.prewarm && settings.mode === 'continuous' ? Math.max(0, settings.lifetime) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* The particles alive at `time`. `emitUntil` is how far the source was still emitting: switched off,
|
||||
* it stops taking in new ones while the ones in flight live out their lives.
|
||||
|
||||
Reference in new issue
Block a user