Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions engine/gpu/vk/vk_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,9 @@ Row rows[] = {
{TAB_GAMEPLAY, "Skip title screen", &opts.skip_title, 0, 1, 1, tx_onoff, // (HL_OPT_SKIP_TITLE, vk_opt_ids.h, host/oot_autoload.c)
"Starts a launch with the most recent saved game: presses through the title screen and its file list. Does nothing "
"until the game has a save. Applies after a restart.", nullptr, true, true},
{TAB_GAMEPLAY, "First person", &opts.first_person, 0, 1, 1, tx_onoff, // (HL_OPT_FIRST_PERSON, vk_opt_ids.h, host/hos_main.c)
"Plays from Link's eyes: the right stick looks around, Link walks the way you look, and his head is hidden. The free "
"camera, while on, takes its place.", nullptr, false, true},
{TAB_GAMEPLAY, "Send performance statistics", &opts.send_perf, 0, 1, 1, tx_telemetry,
"Off by default. On: the game counts how its frames go (frame times, stutters and what they waited on, per map) and sends "
"a summary of the counts, without your name or any ID; what is kept of it is totals for all players. Every 5 minutes of play "
Expand Down
1 change: 1 addition & 0 deletions engine/gpu/vk/vk_menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ struct Options {
int vram_mb = 0; // dynamic texture cache budget limit in MB
int mirror_mb = 0; // staging mirror limit in MB
int audio_output = 0; // (hookshot) the speakers the game mixes for: 0 Auto (the default output's), 1 Stereo, 2 5.1; read once, at the start (host/nn_audio.c; HOS_AUDIO_CHANNELS)
int first_person = 0; // the view from Link's eyes, his head hidden (host/hos_main.c; HL_OPT_FIRST_PERSON)
int skip_title = 0; // (longshot) start with the most recent save, pressing through the title and its file list (host/oot_autoload.c); read at the start
int discord = 1; // (hookshot) the Discord status (host/discord_rpc.c): 1 on, shown while a Discord client runs on this PC
int update_check = 1; // (heylisten) "Check for updates" (host/hos_update.c): 1 the offer at the start (the default), 0 off; saved as update_check=
Expand Down
4 changes: 4 additions & 0 deletions engine/gpu/vk/vk_opt_ids.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,7 @@
row on Vanilla keeps the game's R11G11B10F and the temporal upscalers, which take only that scene. 47, Longshot's id for it in
its vk_api.h, so the two agree. */
#define HL_OPT_HDR_TONEMAP 47

/* The Gameplay page's First person row (host/hos_main.c and host/nn_hid.c ask, gpu/vk/vk_replay.cpp answers 0 or 1). 120: well clear
of the 90s, which the frame rate rows use (90 to 93) */
#define HL_OPT_FIRST_PERSON 120
1 change: 1 addition & 0 deletions engine/gpu/vk/vk_replay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7095,6 +7095,7 @@ void fill_replay_table(MkwVkRenderer& t) {
if (id == HOS_OPT_HDR_WHITE) return std::clamp(opts.hdr_white, 80, 500);
if (id == HOS_OPT_DISCORD) return opts.discord != 0;
if (id == HL_OPT_SKIP_TITLE) return opts.skip_title != 0;
if (id == HL_OPT_FIRST_PERSON) return opts.first_person != 0; // (host/hos_main.c, host/nn_hid.c)
if (id == HL_OPT_HUD_LAYOUT) return opts.hud_layout;
if (id == HL_OPT_VSYNC_MODE) return opts.vsync_mode;
return id == 0 ? opts.realtime : id == 1 ? menu_is_open() : id == 2 ? resolution_auto() && !temporal_full_scale() : id == 3 ? (temporal_full_scale() ? 10000 : resolution_scale()) : id == 4 ? opts.pad_background : id == 5 ? opts.text_speed : id == 6 ? opts.mouse_native :
Expand Down
349 changes: 344 additions & 5 deletions engine/host/hos_main.c

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions engine/host/mouse_native.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ void hos_mouse_give_back(int32_t dx, int32_t dy);
int rx_option(int id, int otherwise);
extern double hos_mouse_sens;

/* The renderer's option ids this file reads, by number as 6 and 8 are (the gpu headers stay out of the host's own files;
tests/test_mouse_native.py checks them against gpu/vk/vk_opt_ids.h and gpu/vk/vk_api.h) */
enum { OPT_FIRST_PERSON = 120 /* HL_OPT_FIRST_PERSON */, OPT_CHEAT_CAMERA = 35 /* HOS_OPT_CHEAT_CAMERA */ };

enum { LIMITS_AT = 0x178, PITCH_AT = 0x18c, YAW_AT = 0x1a4, STATE_AT = 0x204 };
#define LIVE_NS 150000000LL /* (the hook ran this recently: the camera takes the mouse) */
#define DEG_PER_COUNT 0.1
Expand All @@ -50,6 +54,8 @@ static int native_on(void) {
static const char *env;
static int looked;
if (!looked) looked = 1, env = getenv("HOS_MOUSE_NATIVE");
/* first person always takes the mouse one to one, whatever the Mouse camera row says */
if (rx_option(OPT_FIRST_PERSON, 0) && !rx_option(OPT_CHEAT_CAMERA, 0)) return 1;
return env ? atoi(env) != 0 : rx_option(6, 0);
}

Expand All @@ -69,6 +75,12 @@ static int looks_like_camera(uint64_t cam) {
/* f_80644c80's first line (nx2/oot_patches.py): cam is the player camera, the game's thread */
void hos_mouse_camera(uint64_t cam) {
if (!cam || !native_on() || !looks_like_camera(cam)) return;
/* First person: the view is ours (host/hos_main.c oot_build_free_view), so the mouse's motion is left for it to
take; the hook still counts as run, so the right stick is not given the motion either */
if (rx_option(OPT_FIRST_PERSON, 0) && !rx_option(OPT_CHEAT_CAMERA, 0)) {
InterlockedExchange64(&last_hook_ns, hos_now_ns());
return;
}
/* Only while it is the view: following Link (3) or turned by the player (4). Aiming the slingshot in first person
leaves this camera updating with its state 0 while another one draws (traced at Hyrule Castle); shops are reported
the same. In any other state the mouse is the right stick, which those views turn by (the hook counts as not
Expand Down Expand Up @@ -107,6 +119,21 @@ void hos_mouse_camera(uint64_t cam) {
hos_log("mouse native: %lld moves applied; pitch %.2f yaw %.2f", applied, p, y);
}

/* First person's share of the native mouse (host/hos_main.c, once a frame of the view): the motion since the last
frame as a turn in radians, yaw falling as the view turns right and pitch rising as it tilts down, at the menu's
sensitivity and Invert mouse vertical. 0 when the native mouse is off or not captured (then the mouse is the right
stick, which turns the view too). */
int hos_mouse_first_person(double *yaw, double *pitch) {
*yaw = *pitch = 0;
if (!native_on()) return 0;
int32_t dx, dy;
if (!hos_mouse_take(&dx, &dy)) return 0;
const double k = DEG_PER_COUNT * hos_mouse_sens * 3.14159265358979 / 180.0;
*yaw = -dx * k;
*pitch = (invert_y() ? -dy : dy) * k;
return 1;
}

/* With each read of the controller (nn_hid.c, the game's threads): 0 if the mouse is not captured, 1 if the camera takes
its motion (hos_mouse_camera), -1 if no player camera runs now (the right stick takes it) */
int hos_mouse_native(void) {
Expand Down
11 changes: 9 additions & 2 deletions engine/host/nn_hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <windows.h>
#include <xinput.h>
#include "../gpu/vk/vk_api.h" /* (the controls' names: HOS_SW_*, HOS_PAD_*) */
#include "../gpu/vk/vk_opt_ids.h" /* (HL_OPT_FIRST_PERSON) */
#include "hos_motion.h"
#include "hos_atomic_file.h" /* (the sensitivity is written whole or not at all) */

Expand Down Expand Up @@ -808,7 +809,9 @@ static void read_input(uint64_t *buttons, int32_t stick[4]) {
static const char *native_env;
static int native_looked;
if (!native_looked) native_looked = 1, native_env = getenv("HOS_MOUSE_NATIVE");
const int native = native_env ? atoi(native_env) != 0 : rx_option(6, 0);
/* first person: always the native path, the view taking the mouse one to one (host/mouse_native.c) */
const int native = (rx_option(HL_OPT_FIRST_PERSON, 0) && !rx_option(HOS_OPT_CHEAT_CAMERA, 0)) ||
(native_env ? atoi(native_env) != 0 : rx_option(6, 0));
int hos_mouse_native(void);
int captured = 0, as_stick = !native;
if (native) {
Expand Down Expand Up @@ -869,8 +872,12 @@ static void npad_states(Ctx *c) {
int height = 0;
const int menu_open = rx_option(1, 0);
const int free_camera = rx_option(HOS_OPT_CHEAT_CAMERA, 0);
const int first_person = !free_camera && rx_option(HL_OPT_FIRST_PERSON, 0);
const int flying = flight_jump_shortcut(&buttons, rx_option(HOS_OPT_CHEAT_FLIGHT, -1), menu_open, free_camera);
if (free_camera && !menu_open) {
if (first_person && !menu_open) { /* (first person: the right stick turns the view, host/hos_main.c; Link walks as ever) */
for (int i = 0; i < 4; i++) axes |= (uint64_t)(uint16_t)stick[i] << (16 * i);
stick[2] = stick[3] = 0;
} else if (free_camera && !menu_open) {
for (int i = 0; i < 4; i++) axes |= (uint64_t)(uint16_t)stick[i] << (16 * i);
height = (int)(buttons >> B_R & 1) - (int)(buttons >> B_L & 1);
memset(stick, 0, sizeof stick);
Expand Down
2 changes: 2 additions & 0 deletions engine/nx2/lift.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ def main():
oot_occlusion.install(L, img)
import oot_view # (fork: the gameplay view's hook, which oot_patches.py's patch_view no longer finds; host/hos_main.c)
oot_view.install(L, img)
import oot_near # (first person's near plane, host/hos_main.c hos_oot_near)
oot_near.install(L, img)
L.discover(max_insns=a.max_func)
print("discovered %d functions (%.0fs)" % (len(L.funcs), time.time() - t0))
total = coverage(L, img, img_dir)
Expand Down
23 changes: 23 additions & 0 deletions engine/nx2/oot_near.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""First person's near plane (OoT 1.1.1): the gameplay camera's near distance, lowered while first person is on.

The camera update (the projection's build) loads the near distance from the camera at +0x134
into s0 and stores it to sead's perspective projection (+0x98). The hook after that load (host/hos_main.c hos_oot_near)
changes s0 only, never the camera's own field, so the next update starts from the game's value again.
"""

MAIN = 0x80020000
SITE = MAIN + 0x4c52d4
# ldr s0, [x19, #0x134]; mov w21, #1; fmov s1, #0.5
WORDS = (0xbd413660, 0x52800035, 0x1e2c1001)
HOOK = ("{ extern void hos_oot_near(Ctx *c, uint64_t camera); hos_oot_near(c, c->x[19]); }"
" /* (nx2/oot_near.py: first person's near plane) */")


def install(lifter, img):
"""The site into lifter.after, after what is there; left out when its words differ (another game version)"""
if any(img.word(SITE + 4 * i) != word for i, word in enumerate(WORDS)):
print("near plane: unsupported camera code, left out")
return 0
lifter.after[SITE] = (lifter.after[SITE] + "\n" if SITE in lifter.after else "") + HOOK
print("near plane: gameplay camera hooked")
return 1
3 changes: 3 additions & 0 deletions engine/tests/test_input_background.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ def main():
constants = block(hid, "enum { B_A") + ";\n" + block(api, "enum { HOS_SW_A") + ";\n"
constants += block(api, "enum { HOS_KEY_MOVE_UP") + ";\n" # (the keys-only controls)
constants += block(api, "enum { HOS_OPT_CHEAT_HEARTS") + ";\n"
# (the option ids of rows that are HeyListen's alone, gpu/vk/vk_opt_ids.h: First person's, which the input reads)
ids = (ROOT / "gpu/vk/vk_opt_ids.h").read_text(encoding="utf-8")
constants += "".join(m + "\n" for m in re.findall(r"^#define HL_OPT_\w+\s+\d+", ids, re.M))
for name in ("STATE_SIZE", "NPAD_NO1", "ATTR_CONNECTED"):
matches = re.findall(r"^#define " + name + r"\s+[^\n]+", hid, re.M)
assert len(matches) == 1, name
Expand Down
13 changes: 13 additions & 0 deletions engine/tests/test_mouse_native.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
camera draws, and the motion is then the stick's.
python -I -B tests/test_mouse_native.py (Linux: host/posix's windows.h)
"""
import re
import shutil
import subprocess
import sys
Expand Down Expand Up @@ -125,6 +126,18 @@


class MouseNativeTests(unittest.TestCase):
def test_option_ids_match_the_renderer(self):
"""mouse_native.c reads the first-person and free-camera rows by number: the renderer's ids"""
src = (ROOT / "host" / "mouse_native.c").read_text(encoding="utf-8")
ids = (ROOT / "gpu" / "vk" / "vk_opt_ids.h").read_text(encoding="utf-8")
api = (ROOT / "gpu" / "vk" / "vk_api.h").read_text(encoding="utf-8")
first = int(re.search(r"OPT_FIRST_PERSON = (\d+)", src).group(1))
camera = int(re.search(r"OPT_CHEAT_CAMERA = (\d+)", src).group(1))
self.assertEqual(first, int(re.search(r"#define HL_OPT_FIRST_PERSON (\d+)", ids).group(1)))
cheats = re.search(r"enum \{ HOS_OPT_CHEAT_HEARTS = (\d+),([^}]*)\}", api)
names = [n.strip() for n in cheats.group(2).split(",")]
self.assertEqual(camera, int(cheats.group(1)) + 1 + names.index("HOS_OPT_CHEAT_CAMERA"))

def test_turns_the_player_camera(self):
if sys.platform == "win32":
self.skipTest("host/posix's windows.h stands in for Windows here")
Expand Down
Loading