mirror of
https://git.triforceproject.com/triforce/source
synced 2026-11-25 18:48:51 -04:00
Triforce v0.8.0
Evil HD (SMAA Ultra, 16x filtering, full textures, ambient occlusion with bounce light, sunlight shafts, foliage drawn 4x as far, the remastered texture pack's loader and the launcher's download of it), FSR 3.1 frame generation for every GPU, Intel XeSS, FSR 4 model choice, ReShade presets, Auto (this PC), HUD placement, the options menu in 13 languages, a second input for every control, hold to toggle, DualSense speaker and haptics, NFC from the player's own dumps, the above-60 fps game fixes, the Debug tab's flight and Inventory fixes, the launcher's full settings, and over 250 fixes.
This commit is contained in:
@@ -39,6 +39,9 @@ int hos_mouse_take(int32_t *dx, int32_t *dy) {
|
||||
return mouse_captured;
|
||||
}
|
||||
|
||||
/* (nn_hid.c) the game's menus do not take the mouse here: its capture, and with it its buttons, stay the game's */
|
||||
int hos_mouse_in_game_menu(void) { return 0; }
|
||||
|
||||
/* (mouse_native.c) motion taken and not used, put back for the next taker (the player camera's) */
|
||||
void hos_mouse_give_back(int32_t dx, int32_t dy) {
|
||||
InterlockedExchangeAdd(&mouse_dx, dx);
|
||||
@@ -112,11 +115,17 @@ static volatile int refresh_now;
|
||||
static int refresh_mhz(void *w) { (void)w; return __atomic_load_n(&refresh_now, __ATOMIC_RELAXED); }
|
||||
static MkwVkWindow vk_window = {MKWVK_WINDOW_VERSION, create_surface, drawable_size, NULL, refresh_mhz};
|
||||
|
||||
/* Esc let the captured mouse go just before it opened the Insert menu (Menu shortcut "Insert, F1 or Esc"): the capture
|
||||
that comes back when the menu closes. Spent by the next capture or menu */
|
||||
static int esc_had_capture;
|
||||
static void mouse_capture(int on) {
|
||||
int rx_option(int id, int otherwise);
|
||||
if (on && rx_option(6, 0) == 2) return; /* ((Triforce) Mouse camera Off: the mouse plays no part, a click does not capture it) */
|
||||
if (on == (int)mouse_captured) return;
|
||||
mouse_captured = on;
|
||||
InterlockedExchange(&mouse_dx, 0);
|
||||
InterlockedExchange(&mouse_dy, 0);
|
||||
if (on) esc_had_capture = 0;
|
||||
hos_sdl_relative_mouse(window, on);
|
||||
}
|
||||
static void set_fullscreen(int on) {
|
||||
@@ -127,10 +136,18 @@ static void set_fullscreen(int on) {
|
||||
hos_log("display: %s", on ? "fullscreen" : "windowed");
|
||||
}
|
||||
|
||||
static volatile int renderer_failed; /* ((Triforce, 11-24) rx_start answered 0: the window's thread says so and ends the game) */
|
||||
static DWORD WINAPI renderer_main(void *p) {
|
||||
(void)p;
|
||||
const int ok = rx_start(&vk_window);
|
||||
if (!ok) hos_log("display: the renderer did not start: the window stays black");
|
||||
if (!ok) {
|
||||
/* ((Triforce, 11-24) as host/display.c on Windows: the game ends at once and says why. Behind a black window it
|
||||
played on, sound and all, until the player closed it. The message is the window's thread's to show (SDL's
|
||||
window calls belong there: hos_display_loop); the game's first work for the GPU goes on waiting meanwhile
|
||||
(hos_renderer_wait: renderer_up is never set) */
|
||||
__atomic_store_n(&renderer_failed, 1, __ATOMIC_RELEASE);
|
||||
return 0;
|
||||
}
|
||||
renderer = ok;
|
||||
if (ok) { /* (a size change while it started) */
|
||||
int w = 0, h = 0;
|
||||
@@ -167,11 +184,14 @@ __attribute__((visibility("default"))) void hos_posix_post_message(uint32_t msg,
|
||||
void hos_window_close(void) { __atomic_store_n(&close_asked, 1, __ATOMIC_RELEASE); }
|
||||
/* the menu opened: the mouse let go (its capture kept for later); closed: the capture back, if the window still has the focus */
|
||||
static int captured_before_menu;
|
||||
void hos_input_clear_toggles(void); /* ((Triforce) 11-24: host/nn_hid.c, hold-to-toggle's latches) */
|
||||
static void menu_mouse(int open) {
|
||||
if (open == menu_open) return;
|
||||
menu_open = open;
|
||||
if (open) {
|
||||
captured_before_menu = (int)mouse_captured;
|
||||
hos_input_clear_toggles();
|
||||
captured_before_menu = (int)mouse_captured || esc_had_capture; /* (opened by Esc, which let it go) */
|
||||
esc_had_capture = 0;
|
||||
mouse_capture(0);
|
||||
InterlockedExchange(&ptr_pressed, 0), InterlockedExchange(&ptr_wheel, 0);
|
||||
} else {
|
||||
@@ -229,6 +249,12 @@ int hos_display_init(void) {
|
||||
const int gamescope = desktop && strstr(desktop, "gamescope");
|
||||
if (!getenv("SDL_VIDEODRIVER") && !getenv("SDL_VIDEO_DRIVER") && !gamescope)
|
||||
hos_sdl_hint(hos_sdl_load() == 3 ? "SDL_VIDEO_DRIVER" : "SDL_VIDEODRIVER", "wayland,x11");
|
||||
/* (SDL2 on Wayland: libdecor from the start. SDL2 2.32 asks for the compositor's decorations before the window's first
|
||||
configure, and a compositor that answers "the client draws them" (COSMIC) has it unmap and map the window again
|
||||
with libdecor inside that wait, which then waits forever on a field the switch cleared: no window, no renderer.
|
||||
libdecor takes the compositor's decorations itself where they are offered; with no libdecor SDL keeps
|
||||
its own. SDL3 waits on the window's state and is left alone; SDL_VIDEO_WAYLAND_PREFER_LIBDECOR still wins) */
|
||||
if (hos_sdl_load() == 2) hos_sdl_hint("SDL_VIDEO_WAYLAND_PREFER_LIBDECOR", "1");
|
||||
if (!hos_sdl_init(HOS_SDL_VIDEO | HOS_SDL_EVENTS)) {
|
||||
hos_log("display: SDL_Init: %s: no window", hos_sdl_error());
|
||||
fprintf(stderr, "display: SDL_Init: %s: no window\n", hos_sdl_error());
|
||||
@@ -275,6 +301,7 @@ void hos_display_loop(void) {
|
||||
hos_log("display: SDL_CreateWindow: %s: no window", hos_sdl_error());
|
||||
fprintf(stderr, "display: SDL_CreateWindow: %s: no window\n", hos_sdl_error());
|
||||
hos_log_flush();
|
||||
{ void hos_crash_clean_end(void); hos_crash_clean_end(); } /* ((Triforce) no unclean-end record: host/hos_crash_record.c */
|
||||
ExitProcess(1);
|
||||
}
|
||||
vk_window.window = window;
|
||||
@@ -317,6 +344,7 @@ void hos_display_loop(void) {
|
||||
case HOS_SDL_EV_FOCUS_LOST:
|
||||
hos_posix_window[0] = 0;
|
||||
mouse_capture(0);
|
||||
hos_input_clear_toggles();
|
||||
ptr_in = 0, ptr_held = 0;
|
||||
break;
|
||||
case HOS_SDL_EV_MOUSE_LEAVE:
|
||||
@@ -331,7 +359,10 @@ void hos_display_loop(void) {
|
||||
break;
|
||||
case HOS_SDL_EV_KEY_DOWN: {
|
||||
const int scancode = e.scancode, mod = e.mod;
|
||||
if (e.scancode == 41) mouse_capture(0); /* Esc */
|
||||
if (e.scancode == 41) { /* Esc (it may open the Insert menu too: the capture comes back) */
|
||||
if (!menu_open && mouse_captured) esc_had_capture = 1;
|
||||
mouse_capture(0);
|
||||
}
|
||||
if (!e.repeat && ((scancode == 67 && !(mod & 0x0FC3)) || (scancode == 40 && (mod & 0x300)))) set_fullscreen(!fullscreen); /* F10, Alt+Enter (Triforce: F11 is off) */
|
||||
break;
|
||||
}
|
||||
@@ -375,6 +406,33 @@ void hos_display_loop(void) {
|
||||
rx_close_asked();
|
||||
hos_window_closed_exit();
|
||||
}
|
||||
if (__atomic_load_n(&renderer_failed, __ATOMIC_ACQUIRE)) {
|
||||
/* ((Triforce, 11-24) no renderer started (Vulkan lists no graphics card it can use, or triforce_vk.so is not
|
||||
there): said in the log, on stderr and in a message window, and the game ends. The renderer's own lines
|
||||
are in the log ("vk: no Vulkan 1.3 GPU", "rx: ... did not load"). A test's run (HOS_WINDOW_NOACTIVATE)
|
||||
has nobody to read a message: it only ends */
|
||||
static const char text[] =
|
||||
"Triforce could not start its renderer, so the game cannot show a picture and ends here.
|
||||
|
||||
"
|
||||
"It needs a graphics card with Vulkan 1.3 and a current driver (Mesa or the vendor's): update your "
|
||||
"graphics driver and start the game again. If triforce_vk.so is missing from the game folder, run "
|
||||
"Triforce Setup again.
|
||||
|
||||
triforce_log.txt in the game folder says what was found.";
|
||||
hos_log("display: the renderer did not start: the game ends");
|
||||
fprintf(stderr, "display: the renderer did not start: the game ends
|
||||
");
|
||||
hos_log_flush();
|
||||
{ void hos_fs_save_finish(void); hos_fs_save_finish(); } /* (host/nn_fs.c: as every other end of the game) */
|
||||
mouse_capture(0);
|
||||
if (!getenv("HOS_WINDOW_NOACTIVATE") && !hos_sdl_message_box(window, "Triforce", text))
|
||||
hos_log("display: the message could not be shown (%s)", hos_sdl_error());
|
||||
hos_log_flush();
|
||||
/* ((Triforce) said already: no unclean-end record, and no second window after it (host/hos_crash_dialog.h) */
|
||||
{ void hos_crash_clean_end(void); hos_crash_clean_end(); }
|
||||
ExitProcess(1);
|
||||
}
|
||||
keys_update();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ typedef UINT MMRESULT;
|
||||
typedef void *HWAVEOUT;
|
||||
#define MMSYSERR_NOERROR 0
|
||||
#define MMSYSERR_ERROR 1
|
||||
#define MMSYSERR_NODRIVER 6
|
||||
#define WAVE_MAPPER ((UINT)-1)
|
||||
#define WAVE_FORMAT_PCM 1
|
||||
#define CALLBACK_NULL 0
|
||||
|
||||
@@ -335,6 +335,9 @@ static DWORD WINAPI sample_all_thread(void *p) {
|
||||
int nt = 0;
|
||||
int64_t t0 = 0;
|
||||
const int self = (int)syscall(SYS_gettid);
|
||||
/* ((Triforce) with HOS_CHAIN: "# at <ns>" before each sample, when it was taken: the threads are sampled one after another,
|
||||
a millisecond or more apart, and scripts/chain.py lays the samples on its exact path) */
|
||||
const int at = getenv("HOS_CHAIN") != NULL;
|
||||
for (;;) {
|
||||
if (access(go, F_OK)) {
|
||||
if (out) { fclose(out); out = NULL; hos_log("prof: all-thread sampling stopped"); }
|
||||
@@ -355,6 +358,7 @@ static DWORD WINAPI sample_all_thread(void *p) {
|
||||
nt++;
|
||||
}
|
||||
t0 = hos_now_ns();
|
||||
fprintf(out, "# t0_ns %lld\n", (long long)t0); /* ((Triforce) the clock of HOS_CHAIN's records: scripts/chain.py) */
|
||||
hos_log("prof: all-thread sampling of %d threads into %s", nt, path);
|
||||
}
|
||||
Sleep(2);
|
||||
@@ -363,6 +367,7 @@ static DWORD WINAPI sample_all_thread(void *p) {
|
||||
uintptr_t pcs[16];
|
||||
const int n = sample_one(th[i], pcs, 16);
|
||||
if (n < 0) continue;
|
||||
if (at) fprintf(out, "# at %lld\n", (long long)hos_now_ns());
|
||||
char line[1024];
|
||||
int len = snprintf(line, sizeof line, "%ld %s|", ms, tn[i]);
|
||||
for (int depth = 0; depth < n && len < (int)sizeof line - 96; depth++) {
|
||||
|
||||
@@ -85,20 +85,24 @@ static struct timespec rel_ms(DWORD ms) {
|
||||
struct timespec ts = {(time_t)(ms / 1000), (long)(ms % 1000) * 1000000L};
|
||||
return ts;
|
||||
}
|
||||
void WakeConditionVariable(CONDITION_VARIABLE *cv) {
|
||||
/* ((Triforce) a wake with no sleeper makes no system call: a sleeper counts itself in (waiters) under its lock, before it
|
||||
reads seq and lets the lock go, so a waker that changed what the sleeper waits for under that lock sees it counted, and one
|
||||
that finds none has nobody to wake. Most of the game's wakes have no sleeper: each was a futex call for nothing) */
|
||||
static void cv_wake(CONDITION_VARIABLE *cv, int count) {
|
||||
if (!__atomic_load_n(&cv->waiters, __ATOMIC_SEQ_CST)) return;
|
||||
__atomic_add_fetch(&cv->seq, 1, __ATOMIC_SEQ_CST);
|
||||
futex(&cv->seq, FUTEX_WAKE_PRIVATE, 1, NULL);
|
||||
}
|
||||
void WakeAllConditionVariable(CONDITION_VARIABLE *cv) {
|
||||
__atomic_add_fetch(&cv->seq, 1, __ATOMIC_SEQ_CST);
|
||||
futex(&cv->seq, FUTEX_WAKE_PRIVATE, INT_MAX, NULL);
|
||||
futex(&cv->seq, FUTEX_WAKE_PRIVATE, count, NULL);
|
||||
}
|
||||
void WakeConditionVariable(CONDITION_VARIABLE *cv) { cv_wake(cv, 1); }
|
||||
void WakeAllConditionVariable(CONDITION_VARIABLE *cv) { cv_wake(cv, INT_MAX); }
|
||||
static BOOL cv_wait(CONDITION_VARIABLE *cv, DWORD ms, void (*unlock)(void *), void (*relock)(void *, ULONG), void *l, ULONG flags) {
|
||||
__atomic_add_fetch(&cv->waiters, 1, __ATOMIC_SEQ_CST);
|
||||
const uint32_t seq = __atomic_load_n(&cv->seq, __ATOMIC_SEQ_CST);
|
||||
unlock(l);
|
||||
struct timespec ts = rel_ms(ms);
|
||||
const long r = futex(&cv->seq, FUTEX_WAIT_PRIVATE, seq, ms == INFINITE ? NULL : &ts);
|
||||
const int timed_out = r == -1 && errno == ETIMEDOUT;
|
||||
__atomic_sub_fetch(&cv->waiters, 1, __ATOMIC_SEQ_CST);
|
||||
relock(l, flags);
|
||||
if (timed_out) { last_error = ERROR_TIMEOUT; return FALSE; }
|
||||
return TRUE;
|
||||
@@ -171,6 +175,7 @@ typedef struct {
|
||||
pthread_mutex_t mu;
|
||||
pthread_cond_t cv;
|
||||
int done, priority;
|
||||
int pinned; /* (SetThreadAffinityMask set its affinity: thread_entry leaves it; under mu) */
|
||||
DWORD code;
|
||||
volatile int refs;
|
||||
LPTHREAD_START_ROUTINE fn;
|
||||
@@ -191,6 +196,30 @@ static HThread *thread_new(void) {
|
||||
monitor_init(&t->mu, &t->cv);
|
||||
return t;
|
||||
}
|
||||
/* The process's affinity as the process started: Windows keeps a process mask apart from its threads' masks, Linux has
|
||||
only the threads'. Read from the asking thread each time, it was that thread's own mask, which shrank once hos_thread_pin
|
||||
pinned it off the reserved core: the Presentation Thread's pin, asked for from a game thread kept off that core, then
|
||||
saw no reserved core in the "process" mask and kept the Presentation Thread off it too, against render_thread_on_reserved
|
||||
(host/hos_thread.c; Ryzen 9 9950X3D, 2026-11-09). Taken once, before main, when no thread is pinned yet.
|
||||
Also applied when a thread first registers here (CreateThread's thread_entry, or a std::thread in thread_self on its
|
||||
first GetCurrentThread call in SetThreadDescription / SetThreadPriority), so a thread made inside a pinned replay
|
||||
(ReplayPin in gpu/vk/vk_replay.cpp) starts with the process's affinity as on Windows rather than inheriting the pin.
|
||||
(A thread that never registers here, a std::thread that calls none of these or a library's, keeps what it inherited) */
|
||||
static DWORD_PTR process_affinity;
|
||||
__attribute__((constructor)) static void init_process_affinity(void) {
|
||||
cpu_set_t s;
|
||||
CPU_ZERO(&s);
|
||||
if (sched_getaffinity(0, sizeof s, &s) == 0)
|
||||
for (int i = 0; i < 64; i++) if (CPU_ISSET(i, &s)) process_affinity |= (DWORD_PTR)1 << i;
|
||||
}
|
||||
static void apply_process_affinity(pthread_t th) {
|
||||
if (!process_affinity) init_process_affinity();
|
||||
if (!process_affinity) return;
|
||||
cpu_set_t want;
|
||||
CPU_ZERO(&want);
|
||||
for (int i = 0; i < 64; i++) if (process_affinity >> i & 1) CPU_SET(i, &want);
|
||||
pthread_setaffinity_np(th, sizeof want, &want);
|
||||
}
|
||||
static HThread *thread_self(void) {
|
||||
if (!self_thread) { /* (a thread this file did not start: the main thread, a library's) */
|
||||
HThread *t = thread_new();
|
||||
@@ -198,6 +227,7 @@ static HThread *thread_self(void) {
|
||||
t->tid = (pid_t)syscall(SYS_gettid);
|
||||
t->refs = 1; /* (kept for the thread's life) */
|
||||
self_thread = t;
|
||||
apply_process_affinity(t->th);
|
||||
}
|
||||
return self_thread;
|
||||
}
|
||||
@@ -220,6 +250,11 @@ static void *thread_entry(void *p) {
|
||||
HThread *t = (HThread *)p;
|
||||
self_thread = t;
|
||||
t->tid = (pid_t)syscall(SYS_gettid);
|
||||
/* (Triforce: unless its maker has pinned it by its handle already, hos_thread_start's hos_thread_pin right after
|
||||
CreateThread: the reset coming second would have put a game thread back on the reserved core) */
|
||||
pthread_mutex_lock(&t->mu);
|
||||
if (!t->pinned) apply_process_affinity(t->th);
|
||||
pthread_mutex_unlock(&t->mu);
|
||||
thread_finish(t->fn(t->arg));
|
||||
return NULL;
|
||||
}
|
||||
@@ -274,7 +309,10 @@ BOOL SetThreadPriority(HANDLE h, int p) {
|
||||
if (!t) { last_error = ERROR_INVALID_HANDLE; return FALSE; }
|
||||
t->priority = p;
|
||||
const int nice = p <= THREAD_PRIORITY_IDLE ? 19 : p <= THREAD_PRIORITY_LOWEST ? 10 : p == THREAD_PRIORITY_BELOW_NORMAL ? 5 : 0;
|
||||
if (nice && t->tid) setpriority(PRIO_PROCESS, (id_t)t->tid, nice);
|
||||
if (!nice) return TRUE;
|
||||
/* (a thread just made has no id until it runs: hos_thread_start lowers it right after CreateThread) */
|
||||
while (!t->tid && !t->done) sched_yield();
|
||||
if (t->tid) setpriority(PRIO_PROCESS, (id_t)t->tid, nice);
|
||||
return TRUE;
|
||||
}
|
||||
int GetThreadPriority(HANDLE h) {
|
||||
@@ -289,23 +327,15 @@ DWORD_PTR SetThreadAffinityMask(HANDLE h, DWORD_PTR mask) {
|
||||
pthread_getaffinity_np(t->th, sizeof old, &old);
|
||||
CPU_ZERO(&want);
|
||||
for (int i = 0; i < 64; i++) if (mask >> i & 1) CPU_SET(i, &want);
|
||||
if (pthread_setaffinity_np(t->th, sizeof want, &want)) { last_error = ERROR_INVALID_PARAMETER; return 0; }
|
||||
pthread_mutex_lock(&t->mu); /* (with thread_entry's reset to the process's affinity: whichever comes first, this one stays) */
|
||||
const int failed = pthread_setaffinity_np(t->th, sizeof want, &want);
|
||||
if (!failed) t->pinned = 1;
|
||||
pthread_mutex_unlock(&t->mu);
|
||||
if (failed) { last_error = ERROR_INVALID_PARAMETER; return 0; }
|
||||
DWORD_PTR r = 0;
|
||||
for (int i = 0; i < 64; i++) if (CPU_ISSET(i, &old)) r |= (DWORD_PTR)1 << i;
|
||||
return r ? r : 1;
|
||||
}
|
||||
/* The process's affinity as the process started: Windows keeps a process mask apart from its threads' masks, Linux has
|
||||
only the threads'. Read from the asking thread each time, it was that thread's own mask, which shrank once hos_thread_pin
|
||||
pinned it off the reserved core: the Presentation Thread's pin, asked for from a game thread kept off that core, then
|
||||
saw no reserved core in the "process" mask and kept the Presentation Thread off it too, against render_thread_on_reserved
|
||||
(host/hos_thread.c; Ryzen 9 9950X3D, 2026-11-09). Taken once, before main, when no thread is pinned yet. */
|
||||
static DWORD_PTR process_affinity;
|
||||
__attribute__((constructor)) static void init_process_affinity(void) {
|
||||
cpu_set_t s;
|
||||
CPU_ZERO(&s);
|
||||
if (sched_getaffinity(0, sizeof s, &s) == 0)
|
||||
for (int i = 0; i < 64; i++) if (CPU_ISSET(i, &s)) process_affinity |= (DWORD_PTR)1 << i;
|
||||
}
|
||||
BOOL GetProcessAffinityMask(HANDLE p, DWORD_PTR *proc, DWORD_PTR *sys) {
|
||||
(void)p;
|
||||
if (!process_affinity) init_process_affinity(); /* (the constructor did not run, or the call failed then) */
|
||||
@@ -756,7 +786,9 @@ static const char *linux_name(const char *base) {
|
||||
if (!strcasecmp(base, map[i][0])) return map[i][1];
|
||||
return NULL;
|
||||
}
|
||||
static __thread char load_error[512]; /* ((Triforce) dlerror()'s text for this thread's last failure: hos_load_error) */
|
||||
HMODULE LoadLibraryA(LPCSTR name) {
|
||||
load_error[0] = 0;
|
||||
if (!name) return NULL;
|
||||
char path[PATH_MAX];
|
||||
snprintf(path, sizeof path, "%s", name);
|
||||
@@ -774,9 +806,14 @@ HMODULE LoadLibraryA(LPCSTR name) {
|
||||
}
|
||||
}
|
||||
HMODULE m = dlopen(path, RTLD_NOW | RTLD_LOCAL);
|
||||
if (!m) last_error = ERROR_FILE_NOT_FOUND;
|
||||
if (!m) {
|
||||
last_error = ERROR_FILE_NOT_FOUND;
|
||||
const char *why = dlerror();
|
||||
snprintf(load_error, sizeof load_error, "%s", why ? why : "");
|
||||
}
|
||||
return m;
|
||||
}
|
||||
const char *hos_load_error(void) { return load_error; }
|
||||
BOOL FreeLibrary(HMODULE m) { return m && dlclose(m) == 0; }
|
||||
FARPROC GetProcAddress(HMODULE m, LPCSTR name) { return m ? (FARPROC)dlsym(m, name) : NULL; }
|
||||
HMODULE GetModuleHandleA(LPCSTR name) {
|
||||
@@ -1133,6 +1170,10 @@ static void on_signal(int sig, siginfo_t *si, void *uctx) {
|
||||
context_to(uc, &ctx);
|
||||
return;
|
||||
}
|
||||
/* ((Triforce) the signal and its code for the local crash record (host/mkw_glue.c record_exception), in the record's
|
||||
unused tail: NumberParameters, which the CRASH lines read, is unchanged) */
|
||||
rec.ExceptionInformation[13] = (ULONG_PTR)sig;
|
||||
rec.ExceptionInformation[14] = (ULONG_PTR)(intptr_t)si->si_code;
|
||||
if (unhandled && unhandled(&ep) == EXCEPTION_CONTINUE_EXECUTION) {
|
||||
context_to(uc, &ctx);
|
||||
return;
|
||||
@@ -1148,12 +1189,16 @@ static void on_signal(int sig, siginfo_t *si, void *uctx) {
|
||||
return;
|
||||
}
|
||||
signal(sig, SIG_DFL);
|
||||
/* ((Triforce) a signal sent (abort, kill) does not come again by returning: raised again, so it still ends the process
|
||||
as it would have; a real fault comes again on return, with its own information) */
|
||||
if (si->si_code <= 0) raise(sig);
|
||||
}
|
||||
static void install_signals(void) {
|
||||
static int done;
|
||||
if (done) return;
|
||||
done = 1;
|
||||
const int sigs[] = {SIGSEGV, SIGBUS, SIGILL, SIGFPE};
|
||||
/* ((Triforce) SIGABRT too: an abort is reported (the CRASH lines, the local crash record) before it ends the game */
|
||||
const int sigs[] = {SIGSEGV, SIGBUS, SIGILL, SIGFPE, SIGABRT};
|
||||
for (size_t i = 0; i < sizeof sigs / sizeof sigs[0]; i++) {
|
||||
struct sigaction sa;
|
||||
memset(&sa, 0, sizeof sa);
|
||||
@@ -1256,13 +1301,19 @@ int MessageBoxA(HWND w, LPCSTR text, LPCSTR caption, UINT type) {
|
||||
|
||||
/* ---- waveOut on SDL's audio (host/hos_sdl.c): a callback takes the written blocks in order and marks them done ---- */
|
||||
/* (the executable's: this file is in the Vulkan back end too, which plays no sound and has no hos_sdl.c) */
|
||||
int hos_sdl_audio_open(int freq, int channels, int s16, void (*pull)(void *user, uint8_t *out, int len), void *user)
|
||||
__attribute__((weak));
|
||||
/* ((Triforce) the device: WAVE_MAPPER the default, else the Output device row's token (host/audio_output_devices.c
|
||||
resolves its id). A device gone is told at the next write (MMSYSERR_NODRIVER: host/nn_audio.c's au_device_gone opens
|
||||
the default meanwhile and tries the chosen one again); the stream is closed with the handle, its callbacks stopped first) */
|
||||
void *hos_sdl_audio_open_device(unsigned device, int freq, int channels, int s16, int frames,
|
||||
void (*pull)(void *user, uint8_t *out, int len), void *user) __attribute__((weak));
|
||||
void hos_sdl_audio_close(void *audio) __attribute__((weak));
|
||||
int hos_sdl_audio_alive(void *audio) __attribute__((weak));
|
||||
typedef struct {
|
||||
pthread_mutex_t mu;
|
||||
WAVEHDR *q[64];
|
||||
int head, count;
|
||||
DWORD pos;
|
||||
void *audio; /* (hos_sdl.c's stream) */
|
||||
} WaveOut;
|
||||
static void wave_pull(void *user, uint8_t *out, int len) {
|
||||
WaveOut *w = (WaveOut *)user;
|
||||
@@ -1282,12 +1333,15 @@ static void wave_pull(void *user, uint8_t *out, int len) {
|
||||
if (len > 0) memset(out, 0, (size_t)len); /* (behind: silence) */
|
||||
}
|
||||
MMRESULT waveOutOpen(HWAVEOUT *out, UINT device, const WAVEFORMATEX *f, DWORD_PTR cb, DWORD_PTR inst, DWORD flags) {
|
||||
(void)device, (void)cb, (void)inst, (void)flags;
|
||||
(void)cb, (void)inst, (void)flags;
|
||||
/* (the same SDL as the window's and the controllers', beside the executable first: hos_sdl.c) */
|
||||
if (!hos_sdl_audio_open) return MMSYSERR_ERROR;
|
||||
if (!hos_sdl_audio_open_device || !hos_sdl_audio_close || !hos_sdl_audio_alive || !out || !f) return MMSYSERR_ERROR;
|
||||
WaveOut *w = (WaveOut *)calloc(1, sizeof *w);
|
||||
pthread_mutex_init(&w->mu, NULL);
|
||||
if (!hos_sdl_audio_open((int)f->nSamplesPerSec, (int)f->nChannels, f->wBitsPerSample == 16, wave_pull, w)) {
|
||||
if (!w) return MMSYSERR_ERROR;
|
||||
if (pthread_mutex_init(&w->mu, NULL)) { free(w); return MMSYSERR_ERROR; }
|
||||
w->audio = hos_sdl_audio_open_device(device, (int)f->nSamplesPerSec, (int)f->nChannels, f->wBitsPerSample == 16, 0,
|
||||
wave_pull, w);
|
||||
if (!w->audio) {
|
||||
pthread_mutex_destroy(&w->mu);
|
||||
free(w);
|
||||
return MMSYSERR_ERROR;
|
||||
@@ -1300,8 +1354,15 @@ MMRESULT waveOutUnprepareHeader(HWAVEOUT w, WAVEHDR *h, UINT size) { (void)w, (v
|
||||
MMRESULT waveOutWrite(HWAVEOUT hw, WAVEHDR *h, UINT size) {
|
||||
(void)size;
|
||||
WaveOut *w = (WaveOut *)hw;
|
||||
if (!hos_sdl_audio_alive(w->audio)) return MMSYSERR_NODRIVER; /* ((Triforce) its device is gone) */
|
||||
pthread_mutex_lock(&w->mu);
|
||||
if (w->count == 64) { pthread_mutex_unlock(&w->mu); return MMSYSERR_ERROR; }
|
||||
if (w->count >= 60) {
|
||||
WAVEHDR *old = w->q[w->head];
|
||||
__atomic_store_n(&old->dwFlags, (old->dwFlags & ~(DWORD)WHDR_INQUEUE) | WHDR_DONE, __ATOMIC_RELEASE);
|
||||
w->head = (w->head + 1) % 64;
|
||||
w->count--;
|
||||
w->pos = 0;
|
||||
}
|
||||
h->dwFlags = (h->dwFlags & ~(DWORD)WHDR_DONE) | WHDR_INQUEUE;
|
||||
w->q[(w->head + w->count) % 64] = h;
|
||||
w->count++;
|
||||
@@ -1319,4 +1380,13 @@ MMRESULT waveOutReset(HWAVEOUT hw) {
|
||||
pthread_mutex_unlock(&w->mu);
|
||||
return 0;
|
||||
}
|
||||
MMRESULT waveOutClose(HWAVEOUT hw) { waveOutReset(hw); return 0; }
|
||||
/* ((Triforce) the stream closed with it: it was left playing silence before, one more each time the output reopened) */
|
||||
MMRESULT waveOutClose(HWAVEOUT hw) {
|
||||
WaveOut *w = (WaveOut *)hw;
|
||||
if (!w) return MMSYSERR_ERROR;
|
||||
hos_sdl_audio_close(w->audio); /* (waits for a callback under way, which takes mu: never called holding it) */
|
||||
waveOutReset(hw);
|
||||
pthread_mutex_destroy(&w->mu);
|
||||
free(w);
|
||||
return MMSYSERR_NOERROR;
|
||||
}
|
||||
|
||||
@@ -154,8 +154,8 @@ void SetLastError(DWORD e);
|
||||
word, so they wait with either an SRW lock or a critical section ---- */
|
||||
typedef pthread_rwlock_t SRWLOCK, *PSRWLOCK;
|
||||
#define SRWLOCK_INIT PTHREAD_RWLOCK_INITIALIZER
|
||||
typedef struct { volatile uint32_t seq; } CONDITION_VARIABLE, *PCONDITION_VARIABLE;
|
||||
#define CONDITION_VARIABLE_INIT {0}
|
||||
typedef struct { volatile uint32_t seq, waiters; } CONDITION_VARIABLE, *PCONDITION_VARIABLE; /* (waiters: win32_posix.c cv_wake) */
|
||||
#define CONDITION_VARIABLE_INIT {0, 0}
|
||||
#define CONDITION_VARIABLE_LOCKMODE_SHARED 0x1
|
||||
typedef pthread_mutex_t CRITICAL_SECTION, *LPCRITICAL_SECTION;
|
||||
static inline void InitializeSRWLock(SRWLOCK *l) { pthread_rwlock_init(l, NULL); }
|
||||
@@ -171,7 +171,7 @@ static inline void EnterCriticalSection(CRITICAL_SECTION *cs) { pthread_mutex_lo
|
||||
static inline void LeaveCriticalSection(CRITICAL_SECTION *cs) { pthread_mutex_unlock(cs); }
|
||||
static inline BOOL TryEnterCriticalSection(CRITICAL_SECTION *cs) { return pthread_mutex_trylock(cs) == 0; }
|
||||
static inline void DeleteCriticalSection(CRITICAL_SECTION *cs) { pthread_mutex_destroy(cs); }
|
||||
static inline void InitializeConditionVariable(CONDITION_VARIABLE *cv) { cv->seq = 0; }
|
||||
static inline void InitializeConditionVariable(CONDITION_VARIABLE *cv) { cv->waiters = 0, cv->seq = 0; }
|
||||
void WakeConditionVariable(CONDITION_VARIABLE *cv);
|
||||
void WakeAllConditionVariable(CONDITION_VARIABLE *cv);
|
||||
BOOL SleepConditionVariableSRW(CONDITION_VARIABLE *cv, SRWLOCK *l, DWORD ms, ULONG flags);
|
||||
@@ -337,6 +337,9 @@ static inline SIZE_T GetLargePageMinimum(void) { return 0; }
|
||||
#define GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT 0x2
|
||||
#define GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS 0x4
|
||||
HMODULE LoadLibraryA(LPCSTR name);
|
||||
/* ((Triforce) why this thread's last LoadLibraryA failed, as dlerror() said (a missing file, or a symbol the library needs
|
||||
and nothing loaded has); "" when it did not. GetLastError() is ERROR_FILE_NOT_FOUND for every failure) */
|
||||
const char *hos_load_error(void);
|
||||
#define LoadLibrary LoadLibraryA
|
||||
BOOL FreeLibrary(HMODULE m);
|
||||
FARPROC GetProcAddress(HMODULE m, LPCSTR name);
|
||||
|
||||
Reference in New Issue
Block a user