mirror of
https://git.triforceproject.com/triforce/source
synced 2026-11-29 04:18:49 -04:00
Triforce v0.8.5
A Randomizer page in the launcher, a new title screen with Mods and Save Select tabs, scaling changes applied in game, the Jabu-Jabu bars fixed, renderer frame-time work and the brightness-flash fix, and fixes from the 0.8.4 reports.
This commit is contained in:
@@ -25,11 +25,16 @@
|
||||
the mix moved the new sound on by a block it never played (or ended one shorter than a block unheard). Here both
|
||||
run on the sound thread, one after the other.
|
||||
|
||||
((Triforce, 11-25) Whose sound: the settings' tabs, the Mods screen and the step back to the pause menu's System list
|
||||
have a sound each for moving, choosing and going back (HOS_MENU_SOUND_SETTINGS_NAVIGATE and the six after it), the
|
||||
system menu's files unless the environment names another (roles, roles_from_env).)
|
||||
|
||||
The level: the Audio tab's Menu sounds row (menu_sounds= in triforce_options.ini, 0 to 100, 80 unless set; 0
|
||||
silent), read at each block, and the Master volume over it as over the game's own sound (the sounds are added before
|
||||
render_frame applies it). They are added after the game's limiter, and the block is clipped as it is made 16-bit. */
|
||||
#include <stdatomic.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -64,7 +69,7 @@ typedef struct {
|
||||
uint32_t frames;
|
||||
} Sound;
|
||||
|
||||
static const char *const files[SOUNDS] = {
|
||||
static const char *files[SOUNDS] = { /* (a role's is another's when the environment says so: roles_from_env) */
|
||||
[HOS_MENU_SOUND_OPEN] = "Sound/Resource/Stream/SE_Sys_PlusMenu_Open00.bwav",
|
||||
[HOS_MENU_SOUND_CLOSE] = "Sound/Resource/Stream/SE_Sys_PlusMenu_Close00.bwav",
|
||||
[HOS_MENU_SOUND_CURSOR] = "Sound/Resource/Stream/SE_Sys_Cursor00.bwav",
|
||||
@@ -79,8 +84,75 @@ static const char *const files[SOUNDS] = {
|
||||
file opens: the title's cursor, its Continue and the Load list's choice) */
|
||||
[HOS_MENU_SOUND_SYS_CURSOR] = "Sound/Resource/Stream/SE_Sys_SysMenu_Cursor00.bwav",
|
||||
[HOS_MENU_SOUND_SYS_DECIDE] = "Sound/Resource/Stream/SE_Sys_SysMenu_DecideL00.bwav",
|
||||
/* ((Triforce, 11-25) the owner: "The SFX are incorrect. They should be using the title screen's SFX instead of the
|
||||
in-game Menu SFX." The settings' tabs, the Mods screen and the step back to the pause menu's System list, a sound
|
||||
each: the system menu's cursor, its decide and its cancel (Cansel: the file's own spelling), as the owner chose them
|
||||
from the game's own (the settings' Select the large decide, the title's Continue's; the Mods screen's the small
|
||||
one). The in-game menu's three above, the cursor's, decide's and cancel's, are what these were until then) */
|
||||
[HOS_MENU_SOUND_SETTINGS_NAVIGATE] = "Sound/Resource/Stream/SE_Sys_SysMenu_Cursor00.bwav",
|
||||
[HOS_MENU_SOUND_SETTINGS_SELECT] = "Sound/Resource/Stream/SE_Sys_SysMenu_DecideL00.bwav",
|
||||
[HOS_MENU_SOUND_SETTINGS_BACK] = "Sound/Resource/Stream/SE_Sys_SysMenu_Cansel00.bwav",
|
||||
[HOS_MENU_SOUND_MODS_NAVIGATE] = "Sound/Resource/Stream/SE_Sys_SysMenu_Cursor00.bwav",
|
||||
[HOS_MENU_SOUND_MODS_SELECT] = "Sound/Resource/Stream/SE_Sys_SysMenu_DecideS00.bwav",
|
||||
[HOS_MENU_SOUND_MODS_BACK] = "Sound/Resource/Stream/SE_Sys_SysMenu_Cansel00.bwav",
|
||||
[HOS_MENU_SOUND_PAUSE_BACK] = "Sound/Resource/Stream/SE_Sys_SysMenu_Cansel00.bwav",
|
||||
/* ((Triforce, 11-25) a toggle of the settings' tabs switched On, and Off (the owner, in the lab: 'In the display, the
|
||||
on and off SFX are incorrect ... let me pick the correct SFX for the on and off selection for the settings'): as the
|
||||
owner chose them, On the system menu's small decide, Off its cancel */
|
||||
[HOS_MENU_SOUND_SETTINGS_ON] = "Sound/Resource/Stream/SE_Sys_SysMenu_DecideS00.bwav",
|
||||
[HOS_MENU_SOUND_SETTINGS_OFF] = "Sound/Resource/Stream/SE_Sys_SysMenu_Cansel00.bwav",
|
||||
};
|
||||
|
||||
/* ((Triforce, 11-25) the seven roles above, each with the variable of the environment that names another sound for it, so
|
||||
that one can be tried without a build: HOS_MENU_SOUND_SETTINGS_NAVIGATE=SE_Sys_Cursor00, in the environment or in
|
||||
triforce_env.txt (host/hos_main.c env_line_allowed takes these names and a sound's bare name). The value is a file's
|
||||
name in Sound/Resource/Stream without its .bwav: letters, digits and _, 64 at most, so it names nothing outside that
|
||||
folder; any other value is left out with a line in the log. Read once, when the files are (load_all) */
|
||||
static const struct { int id; const char *env; } roles[] = {
|
||||
{HOS_MENU_SOUND_SETTINGS_NAVIGATE, "HOS_MENU_SOUND_SETTINGS_NAVIGATE"},
|
||||
{HOS_MENU_SOUND_SETTINGS_SELECT, "HOS_MENU_SOUND_SETTINGS_SELECT"},
|
||||
{HOS_MENU_SOUND_SETTINGS_BACK, "HOS_MENU_SOUND_SETTINGS_BACK"},
|
||||
{HOS_MENU_SOUND_MODS_NAVIGATE, "HOS_MENU_SOUND_MODS_NAVIGATE"},
|
||||
{HOS_MENU_SOUND_MODS_SELECT, "HOS_MENU_SOUND_MODS_SELECT"},
|
||||
{HOS_MENU_SOUND_MODS_BACK, "HOS_MENU_SOUND_MODS_BACK"},
|
||||
{HOS_MENU_SOUND_PAUSE_BACK, "HOS_MENU_SOUND_PAUSE_BACK"},
|
||||
{HOS_MENU_SOUND_SETTINGS_ON, "HOS_MENU_SOUND_SETTINGS_ON"},
|
||||
{HOS_MENU_SOUND_SETTINGS_OFF, "HOS_MENU_SOUND_SETTINGS_OFF"},
|
||||
};
|
||||
#define ROLES (int)(sizeof roles / sizeof *roles)
|
||||
#define ROLE_NAME_MOST 64
|
||||
static char role_files[ROLES][sizeof "Sound/Resource/Stream/.bwav" + ROLE_NAME_MOST];
|
||||
static const char *role_own[ROLES]; /* (a role's own file while the environment's is in files[]; NULL: files[] has its own) */
|
||||
|
||||
/* 1 when name is a sound's bare name: letters, digits and _, 1 to ROLE_NAME_MOST of them */
|
||||
static int role_name_ok(const char *name) {
|
||||
size_t n = 0;
|
||||
for (; name[n]; n++) {
|
||||
const char c = name[n];
|
||||
if (n >= ROLE_NAME_MOST) return 0;
|
||||
if (!((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '_')) return 0;
|
||||
}
|
||||
return n > 0;
|
||||
}
|
||||
#ifndef MENU_SOUND_ENV /* (tests/menu_sound_test.c: the environment the test says) */
|
||||
#define MENU_SOUND_ENV(name) getenv(name)
|
||||
#endif
|
||||
static void roles_from_env(void) {
|
||||
for (int k = 0; k < ROLES; k++) {
|
||||
const char *name = MENU_SOUND_ENV(roles[k].env);
|
||||
if (!name || !*name) continue;
|
||||
if (!role_name_ok(name)) {
|
||||
hos_log("menu sounds: %s: its value is not a sound's name (letters, digits and _, 64 at most, as SE_Sys_Cursor00): "
|
||||
"left out", roles[k].env);
|
||||
continue;
|
||||
}
|
||||
snprintf(role_files[k], sizeof role_files[k], "Sound/Resource/Stream/%s.bwav", name);
|
||||
if (!strcmp(role_files[k], files[roles[k].id])) continue; /* (its own: nothing to say) */
|
||||
role_own[k] = files[roles[k].id], files[roles[k].id] = role_files[k];
|
||||
hos_log("menu sounds: %s: %s, the environment's (its own: %s)", roles[k].env, role_files[k], role_own[k]);
|
||||
}
|
||||
}
|
||||
|
||||
static Sound sounds[SOUNDS];
|
||||
static atomic_int loaded; /* 0 not yet, 1 being read (sounds[] is written before the release store of 2), 2 ready */
|
||||
|
||||
@@ -201,22 +273,40 @@ float *hos_menu_sound_decode_long(const uint8_t *b, uint64_t size, uint32_t *fra
|
||||
return decode_most(b, size, frames_out, seconds);
|
||||
}
|
||||
|
||||
/* sounds[id] from files[id]: 1 when it plays. ((Triforce, 11-25) a file a sound before it has is not read again, and its
|
||||
samples are both sounds': the roles' seven are three files, and one of them the system menu's cursor's) */
|
||||
static int load_sound(int id) {
|
||||
for (int k = 1; k < id; k++)
|
||||
if (!strcmp(files[k], files[id])) return sounds[id] = sounds[k], sounds[id].pcm != NULL;
|
||||
uint64_t size = 0;
|
||||
uint8_t *b = hos_fs_rom_file(files[id], FILE_MOST, &size);
|
||||
if (!b) return 0;
|
||||
uint32_t frames = 0;
|
||||
float *pcm = hos_menu_sound_decode(b, size, &frames);
|
||||
free(b);
|
||||
if (!pcm) {
|
||||
hos_log("menu sounds: %s is not a BWAV file the options play (PCM16 or DSP-ADPCM, one or two channels, at most 10 s): "
|
||||
"left out", files[id]);
|
||||
return 0;
|
||||
}
|
||||
sounds[id] = (Sound){pcm, frames};
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void load_all(void) { /* (once: hos_menu_sound_frame's store of 1 into loaded starts it) */
|
||||
int n = 0;
|
||||
roles_from_env();
|
||||
for (int id = 1; id < SOUNDS; id++) {
|
||||
uint64_t size = 0;
|
||||
uint8_t *b = hos_fs_rom_file(files[id], FILE_MOST, &size);
|
||||
if (!b) continue;
|
||||
uint32_t frames = 0;
|
||||
float *pcm = hos_menu_sound_decode(b, size, &frames);
|
||||
free(b);
|
||||
if (!pcm) {
|
||||
hos_log("menu sounds: %s is not a BWAV file the options play (PCM16 or DSP-ADPCM, one or two channels, at most 10 s): "
|
||||
"left out", files[id]);
|
||||
continue;
|
||||
}
|
||||
sounds[id] = (Sound){pcm, frames};
|
||||
n++;
|
||||
int ok = load_sound(id);
|
||||
/* ((Triforce, 11-25) a role's sound from the environment that the game's files do not have, or that is not a
|
||||
sound: the role's own again, and said: not a role gone silent for a name typed wrong) */
|
||||
for (int k = 0; !ok && k < ROLES; k++)
|
||||
if (roles[k].id == id && role_own[k]) {
|
||||
hos_log("menu sounds: %s: no sound %s in the game's files: its own, %s", roles[k].env, files[id], role_own[k]);
|
||||
files[id] = role_own[k], role_own[k] = NULL;
|
||||
ok = load_sound(id);
|
||||
}
|
||||
n += ok;
|
||||
}
|
||||
for (int i = 0; i < VOICES; i++) atomic_store(&voices[i].at, -1);
|
||||
hos_log("menu sounds: %d of %d interface sounds from the game's files", n, SOUNDS - 1);
|
||||
@@ -225,36 +315,55 @@ static void load_all(void) { /* (once: hos_menu_sound_frame's store of 1 into
|
||||
|
||||
float hos_menu_sound_gain(int percent) { return percent <= 0 ? 0.0f : percent >= 100 ? 1.0f : (float)percent / 100.0f; }
|
||||
|
||||
/* The least time between a cursor tick and the sound before it. Moving down a list or changing a value asks for a tick
|
||||
at every step, up to 30 a second while a direction is held, and the focus moving with a press or a tab change is
|
||||
part of that sound: at most five ticks a second are heard. */
|
||||
#define CURSOR_GAP_NS 180000000ll
|
||||
#define CURSOR_GAIN 0.6f /* the tick under the sounds of a decision */
|
||||
static _Atomic int64_t last_start_ns = -CURSOR_GAP_NS;
|
||||
/* ((Triforce, 11-26) The navigation sounds: the cursor's tick, the settings' tabs' and the Mods screen's own, and the system
|
||||
menu's cursor, as the game's own Options screen plays its cursor. The owner sent a clip of the game's Options and ours
|
||||
navigated quickly: "match the game's vanilla's navigation effects" and "Increase to the same exact volume as the vanilla
|
||||
navigation sound effect". Measured in it: the game's cursor sound starts with each move and the one before rings on under
|
||||
it (none is cut), at 0.70 of the file's level; ours were cut short by the next (11-25) and played at 0.43, the 0.6 the
|
||||
ticks had under the other sounds. Now each plays whole, at the whole level, beside the ones before it; a held direction
|
||||
moves at the game's own pace (vk_menu.cpp: 330 ms, then each 135 ms), so they ring over one another no more than the
|
||||
game's do. Only an ask within NAV_GAP_NS of the sound before is left out: one press that asks twice, or a move that comes
|
||||
with a tab's or a page's own sound */
|
||||
#define NAV_GAP_NS 45000000ll
|
||||
static _Atomic int64_t last_start_ns = -NAV_GAP_NS;
|
||||
/* ((Triforce, 11-25) the ticks: the cursor's, and the settings' tabs' and the Mods screen's own now that each has a sound of
|
||||
its own) */
|
||||
static int is_tick(int id) {
|
||||
return id == HOS_MENU_SOUND_CURSOR || id == HOS_MENU_SOUND_SETTINGS_NAVIGATE || id == HOS_MENU_SOUND_MODS_NAVIGATE;
|
||||
}
|
||||
/* (the navigation sounds: the ticks and the system menu's cursor) */
|
||||
static int is_nav(int id) { return is_tick(id) || id == HOS_MENU_SOUND_SYS_CURSOR; }
|
||||
|
||||
void hos_menu_sound_play(int id, int64_t now_ns) {
|
||||
if (id <= 0 || id >= SOUNDS) return;
|
||||
if (id == HOS_MENU_SOUND_CURSOR && now_ns - atomic_load(&last_start_ns) < CURSOR_GAP_NS) return;
|
||||
if (is_nav(id) && now_ns - atomic_load(&last_start_ns) < NAV_GAP_NS) return;
|
||||
atomic_store(&last_start_ns, now_ns);
|
||||
if (atomic_load_explicit(&loaded, memory_order_acquire) != 2 || !sounds[id].pcm) return;
|
||||
int pick = 0;
|
||||
uint64_t oldest = UINT64_MAX;
|
||||
for (int i = 0; i < VOICES; i++) {
|
||||
if (atomic_load_explicit(&voices[i].at, memory_order_acquire) < 0) { pick = i; break; }
|
||||
if (voices[i].started < oldest) oldest = voices[i].started, pick = i;
|
||||
}
|
||||
/* A sound that replaces itself restarts instead of stacking up, and a decision replaces the tick of the same press
|
||||
(a row changes its value in the tick the press is seen). ((Triforce, 11-19) the system menu's tick too: the mouse
|
||||
onto Mods or Quit and its click in one tick is their decide alone) */
|
||||
for (int i = 0; i < VOICES; i++) {
|
||||
/* A decision replaces the tick of the same press (a row changes its value in the tick the press is seen), and a sound
|
||||
that replaces itself restarts instead of stacking up. ((Triforce, 11-19) the system menu's tick too: the mouse onto
|
||||
Mods or Quit and its click in one tick is their decide alone.) ((Triforce, 11-26) A navigation sound never takes
|
||||
another's voice this way: the one before rings on beside it, as the game's) */
|
||||
int pick = -1;
|
||||
for (int i = 0; !is_nav(id) && i < VOICES; i++) {
|
||||
const int64_t at = atomic_load_explicit(&voices[i].at, memory_order_acquire);
|
||||
const int was = atomic_load(&voices[i].sound);
|
||||
if (at >= 0 && (was == id || was == HOS_MENU_SOUND_CURSOR || was == HOS_MENU_SOUND_SYS_CURSOR) &&
|
||||
AT_FRAME(at) < 2400) { /* started under 50 ms ago */
|
||||
if (at >= 0 && (was == id || is_nav(was)) && AT_FRAME(at) < 2400) { /* started under 50 ms ago */
|
||||
pick = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* else a free voice; else the oldest navigation sound's (with all eight playing, the first of a held run, near its end),
|
||||
so that a longer sound (the Mods screen's fanfare, the options' opening) is not cut by a tick; else the oldest */
|
||||
if (pick < 0) {
|
||||
int nav = -1, oldest = 0;
|
||||
for (int i = 0; i < VOICES && pick < 0; i++) {
|
||||
const int64_t at = atomic_load_explicit(&voices[i].at, memory_order_acquire);
|
||||
if (at < 0) { pick = i; break; }
|
||||
if (is_nav(atomic_load(&voices[i].sound)) && (nav < 0 || voices[i].started < voices[nav].started)) nav = i;
|
||||
if (voices[i].started < voices[oldest].started) oldest = i;
|
||||
}
|
||||
if (pick < 0) pick = nav >= 0 ? nav : oldest;
|
||||
}
|
||||
atomic_store_explicit(&voices[pick].at, -1, memory_order_release);
|
||||
atomic_store_explicit(&voices[pick].sound, id, memory_order_relaxed);
|
||||
voices[pick].started = __atomic_add_fetch(&started_n, 1, __ATOMIC_RELAXED);
|
||||
@@ -281,12 +390,13 @@ void hos_menu_sound_mix(float *left, float *right, uint32_t frames, float gain)
|
||||
atomic_compare_exchange_strong(&voices[v].at, &at, -1);
|
||||
continue;
|
||||
}
|
||||
const float vg = which == HOS_MENU_SOUND_CURSOR ? gain * CURSOR_GAIN : gain;
|
||||
/* ((Triforce, 11-26) every sound at the whole level, the cursor's ticks too: the game's own cursor sound is (the
|
||||
owner's clip) as loud as the rest of its menu's) */
|
||||
const uint32_t n = s->frames - pos < frames ? s->frames - pos : frames;
|
||||
const float *src = s->pcm + (size_t)pos * 2;
|
||||
for (uint32_t i = 0; vg != 0.0f && i < n; i++) {
|
||||
left[i] += src[2 * (size_t)i] * vg;
|
||||
right[i] += src[2 * (size_t)i + 1] * vg;
|
||||
for (uint32_t i = 0; gain != 0.0f && i < n; i++) {
|
||||
left[i] += src[2 * (size_t)i] * gain;
|
||||
right[i] += src[2 * (size_t)i + 1] * gain;
|
||||
}
|
||||
MENU_SOUND_BETWEEN(1);
|
||||
/* Only advance if the voice was not restarted meanwhile. */
|
||||
|
||||
Reference in New Issue
Block a user