25 lines
855 B
Java
25 lines
855 B
Java
package com.projectsacrifice.game;
|
|
|
|
import java.util.Arrays;
|
|
|
|
/** Small deterministic variant chooser with independent no-repeat history per cue. */
|
|
public final class AudioCueSequencer {
|
|
private final int[] previous = new int[AudioCue.values().length];
|
|
private long state;
|
|
|
|
public AudioCueSequencer(long seed) {
|
|
Arrays.fill(previous, -1);
|
|
state = seed == 0L ? 0x6d2b79f5L : seed;
|
|
}
|
|
|
|
public int nextVariant(AudioCue cue) {
|
|
if (cue == null || cue.variants() <= 1) return 0;
|
|
state = state * 6364136223846793005L + 1442695040888963407L;
|
|
int candidate = (int) Math.floorMod(state >>> 24, cue.variants());
|
|
int index = cue.ordinal();
|
|
if (candidate == previous[index]) candidate = (candidate + 1) % cue.variants();
|
|
previous[index] = candidate;
|
|
return candidate;
|
|
}
|
|
}
|