From fa9af3227e734d01b7052976f4ea2d0b057ef3cc Mon Sep 17 00:00:00 2001 From: yksoft1 Date: Thu, 14 May 2020 23:47:00 +0800 Subject: [PATCH 01/30] Make the code buildable on MinGW.org (not mingw-w64) and MSYS1. --- include/PR/ultratypes.h | 4 ++++ include/ultra64.h | 6 ++++++ src/pc/gfx/gfx_pc.c | 14 ++++++++++++++ tools/utils.h | 3 ++- 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/include/PR/ultratypes.h b/include/PR/ultratypes.h index 8a00490..8d59054 100644 --- a/include/PR/ultratypes.h +++ b/include/PR/ultratypes.h @@ -38,7 +38,11 @@ typedef s32 ptrdiff_t; #else #include #include +#if defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR) +typedef long ssize_t; +#else typedef ptrdiff_t ssize_t; #endif +#endif #endif diff --git a/include/ultra64.h b/include/ultra64.h index 409a3cf..94bbc38 100644 --- a/include/ultra64.h +++ b/include/ultra64.h @@ -30,4 +30,10 @@ #include #include +#if defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR) +#include +#define bzero(b,len) (memset((b), '\0', (len)), (void) 0) +#define bcopy(s1, s2, n) memmove((s2), (s1), (n)) +#endif + #endif diff --git a/src/pc/gfx/gfx_pc.c b/src/pc/gfx/gfx_pc.c index d674a4d..7214788 100644 --- a/src/pc/gfx/gfx_pc.c +++ b/src/pc/gfx/gfx_pc.c @@ -153,7 +153,21 @@ static size_t buf_vbo_num_tris; static struct GfxWindowManagerAPI *gfx_wapi; static struct GfxRenderingAPI *gfx_rapi; +#if defined(_WIN32) && !defined(__MINGW64_VERSION_MAJOR) +#include +#define CLOCK_MONOTONIC 0 +//https://stackoverflow.com/questions/5404277/porting-clock-gettime-to-windows +struct timespec { long tv_sec; long tv_nsec; }; //header part +int clock_gettime(int arg, struct timespec *spec) //C-file part +{ __int64 wintime; GetSystemTimeAsFileTime((FILETIME*)&wintime); + wintime -=116444736000000000LL; //1jan1601 to 1jan1970 + spec->tv_sec =wintime / 10000000LL; //seconds + spec->tv_nsec =wintime % 10000000LL*100; //nano-seconds + return 0; +} +#else #include +#endif static unsigned long get_time(void) { struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); diff --git a/tools/utils.h b/tools/utils.h index dff1d6a..03f482d 100644 --- a/tools/utils.h +++ b/tools/utils.h @@ -7,8 +7,9 @@ // printing size_t varies by compiler #if defined(_MSC_VER) || defined(__MINGW32__) + #include #define SIZE_T_FORMAT "%Iu" - #define realpath(N,R) _fullpath((R),(N),_MAX_PATH) + #define realpath(N,R) _fullpath((R),(N),MAX_PATH) #else #define SIZE_T_FORMAT "%zu" #endif From 1b03e251bb59b205fc277877306ebd81c454f5d4 Mon Sep 17 00:00:00 2001 From: yksoft1 Date: Fri, 15 May 2020 00:26:56 +0800 Subject: [PATCH 02/30] Better way to detect mingw-w64; fix bettercamera for mingw.org; close .assets-local.txt before deleting it. --- extract_assets.py | 1 + include/PR/ultratypes.h | 5 ++++- include/ultra64.h | 5 ++++- src/game/bettercamera.inc.h | 5 ++++- src/pc/gfx/gfx_pc.c | 5 ++++- 5 files changed, 17 insertions(+), 4 deletions(-) diff --git a/extract_assets.py b/extract_assets.py index 706fc72..7c29358 100755 --- a/extract_assets.py +++ b/extract_assets.py @@ -47,6 +47,7 @@ def remove_file(fname): def clean_assets(local_asset_file): assets = set(read_asset_map().keys()) assets.update(read_local_asset_list(local_asset_file)) + local_asset_file.close() for fname in list(assets) + [".assets-local.txt"]: if fname.startswith("@"): continue diff --git a/include/PR/ultratypes.h b/include/PR/ultratypes.h index 8d59054..62f14f3 100644 --- a/include/PR/ultratypes.h +++ b/include/PR/ultratypes.h @@ -38,11 +38,14 @@ typedef s32 ptrdiff_t; #else #include #include -#if defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR) +#if defined(__MINGW32__) +#include <_mingw.h> +#if !defined(__MINGW64_VERSION_MAJOR) typedef long ssize_t; #else typedef ptrdiff_t ssize_t; #endif #endif +#endif #endif diff --git a/include/ultra64.h b/include/ultra64.h index 94bbc38..e78ded4 100644 --- a/include/ultra64.h +++ b/include/ultra64.h @@ -30,10 +30,13 @@ #include #include -#if defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR) +#if defined(__MINGW32__) +#include <_mingw.h> +#if !defined(__MINGW64_VERSION_MAJOR) #include #define bzero(b,len) (memset((b), '\0', (len)), (void) 0) #define bcopy(s1, s2, n) memmove((s2), (s1), (n)) #endif +#endif #endif diff --git a/src/game/bettercamera.inc.h b/src/game/bettercamera.inc.h index 6c9592b..b48f5d4 100644 --- a/src/game/bettercamera.inc.h +++ b/src/game/bettercamera.inc.h @@ -9,8 +9,11 @@ #include "include/text_strings.h" #include "engine/surface_collision.h" #include "pc/configfile.h" +#if defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR) +//quick and dirty fix for some older MinGW.org mingwrt +#else #include - +#endif /** diff --git a/src/pc/gfx/gfx_pc.c b/src/pc/gfx/gfx_pc.c index 7214788..570c530 100644 --- a/src/pc/gfx/gfx_pc.c +++ b/src/pc/gfx/gfx_pc.c @@ -153,7 +153,9 @@ static size_t buf_vbo_num_tris; static struct GfxWindowManagerAPI *gfx_wapi; static struct GfxRenderingAPI *gfx_rapi; -#if defined(_WIN32) && !defined(__MINGW64_VERSION_MAJOR) +#if defined(__MINGW32__) +#include <_mingw.h> +#if !defined(__MINGW64_VERSION_MAJOR) #include #define CLOCK_MONOTONIC 0 //https://stackoverflow.com/questions/5404277/porting-clock-gettime-to-windows @@ -168,6 +170,7 @@ int clock_gettime(int arg, struct timespec *spec) //C-file part #else #include #endif +#endif static unsigned long get_time(void) { struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); From c8a5d2ec68b5b46167955d6cfb1fcec3e1b3da3c Mon Sep 17 00:00:00 2001 From: "Colton G. Rushton" Date: Sun, 17 May 2020 05:49:34 -0300 Subject: [PATCH 03/30] Fix unused code --- src/game/spawn_object.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/game/spawn_object.c b/src/game/spawn_object.c index cc15c8e..79f930f 100644 --- a/src/game/spawn_object.c +++ b/src/game/spawn_object.c @@ -161,8 +161,7 @@ void clear_object_lists(struct ObjectNode *objLists) { } /** - * This function looks broken, but it appears to attempt to delete the leaf - * graph nodes under obj and obj's siblings. + * Delete the leaf graph nodes under obj and obj's siblings. */ static void unused_delete_leaf_nodes(struct Object *obj) { struct Object *children; @@ -176,8 +175,7 @@ static void unused_delete_leaf_nodes(struct Object *obj) { mark_obj_for_deletion(obj); } - // Probably meant to be != - while ((sibling = (struct Object *) obj->header.gfx.node.next) == obj0) { + while ((sibling = (struct Object *) obj->header.gfx.node.next) != obj0) { unused_delete_leaf_nodes(sibling); obj = (struct Object *) sibling->header.gfx.node.next; } From 072025d24339661af332ce2cce213d77d843b385 Mon Sep 17 00:00:00 2001 From: yksoft1 Date: Sun, 17 May 2020 19:01:13 +0800 Subject: [PATCH 04/30] Fix cliopts on MinGW.org. --- src/pc/cliopts.c | 1 + src/pc/cliopts.h | 1 + 2 files changed, 2 insertions(+) diff --git a/src/pc/cliopts.c b/src/pc/cliopts.c index 1e3b29c..5048713 100644 --- a/src/pc/cliopts.c +++ b/src/pc/cliopts.c @@ -1,6 +1,7 @@ #include "cliopts.h" #include #include +#define __NO_MINGW_LFS //Mysterious error in MinGW.org stdio.h #include struct PCCLIOptions gCLIOpts; diff --git a/src/pc/cliopts.h b/src/pc/cliopts.h index 1844c44..75d78e8 100644 --- a/src/pc/cliopts.h +++ b/src/pc/cliopts.h @@ -1,3 +1,4 @@ +#include #include "sm64.h" struct PCCLIOptions From b52560869ca41888c80825b89b037437d6edf34a Mon Sep 17 00:00:00 2001 From: "Colton G. Rushton" Date: Sun, 17 May 2020 08:17:37 -0300 Subject: [PATCH 05/30] The last of TARGET_N64 finally gets thanos'd --- src/game/crash_screen.c | 386 ---------------------------------------- 1 file changed, 386 deletions(-) delete mode 100644 src/game/crash_screen.c diff --git a/src/game/crash_screen.c b/src/game/crash_screen.c deleted file mode 100644 index 613956d..0000000 --- a/src/game/crash_screen.c +++ /dev/null @@ -1,386 +0,0 @@ -#include -#include -#include - -#include "sm64.h" - -#if defined(TARGET_N64) && (defined(VERSION_EU) || defined(VERSION_SH)) - -s32 _Printf(char *(*prout)(char *, const char *, size_t), char *dst, const char *fmt, va_list args); - -u8 gCrashScreenCharToGlyph[128] = { - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 41, -1, -1, -1, 43, -1, -1, 37, 38, -1, 42, - -1, 39, 44, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 36, -1, -1, -1, -1, 40, -1, 10, - 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, - 33, 34, 35, -1, -1, -1, -1, -1, -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, - 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1, -}; - -// Bit-compressed font. '#' = 1, '.' = 0 -u32 gCrashScreenFont[7 * 9 + 1] = { - 0x70871c30, // .###.. ..#... .###.. .###.. ..##.. .. - 0x8988a250, // #...#. .##... #...#. #...#. .#.#.. .. - 0x88808290, // #...#. ..#... ....#. ....#. #..#.. .. - 0x88831c90, // #...#. ..#... ..##.. .###.. #..#.. .. - 0x888402f8, // #...#. ..#... .#.... ....#. #####. .. - 0x88882210, // #...#. ..#... #..... #...#. ...#.. .. - 0x71cf9c10, // .###.. .###.. #####. .###.. ...#.. .. - - 0xf9cf9c70, // #####. .###.. #####. .###.. .###.. .. - 0x8228a288, // #..... #...#. #...#. #...#. #...#. .. - 0xf200a288, // ####.. #..... ....#. #...#. #...#. .. - 0x0bc11c78, // ....#. ####.. ...#.. .###.. .####. .. - 0x0a222208, // ....#. #...#. ..#... #...#. ....#. .. - 0x8a222288, // #...#. #...#. ..#... #...#. #...#. .. - 0x71c21c70, // .###.. .###.. ..#... .###.. .###.. .. - - 0x23c738f8, // ..#... ####.. .###.. ###... #####. .. - 0x5228a480, // .#.#.. #...#. #...#. #..#.. #..... .. - 0x8a282280, // #...#. #...#. #..... #...#. #..... .. - 0x8bc822f0, // #...#. ####.. #..... #...#. ####.. .. - 0xfa282280, // #####. #...#. #..... #...#. #..... .. - 0x8a28a480, // #...#. #...#. #...#. #..#.. #..... .. - 0x8bc738f8, // #...#. ####.. .###.. ###... #####. .. - - 0xf9c89c08, // #####. .###.. #...#. .###.. ....#. .. - 0x82288808, // #..... #...#. #...#. ..#... ....#. .. - 0x82088808, // #..... #..... #...#. ..#... ....#. .. - 0xf2ef8808, // ####.. #.###. #####. ..#... ....#. .. - 0x82288888, // #..... #...#. #...#. ..#... #...#. .. - 0x82288888, // #..... #...#. #...#. ..#... #...#. .. - 0x81c89c70, // #..... .###.. #...#. .###.. .###.. .. - - 0x8a08a270, // #...#. #..... #...#. #...#. .###.. .. - 0x920da288, // #..#.. #..... ##.##. #...#. #...#. .. - 0xa20ab288, // #.#... #..... #.#.#. ##..#. #...#. .. - 0xc20aaa88, // ##.... #..... #.#.#. #.#.#. #...#. .. - 0xa208a688, // #.#... #..... #...#. #..##. #...#. .. - 0x9208a288, // #..#.. #..... #...#. #...#. #...#. .. - 0x8be8a270, // #...#. #####. #...#. #...#. .###.. .. - - 0xf1cf1cf8, // ####.. .###.. ####.. .###.. #####. .. - 0x8a28a220, // #...#. #...#. #...#. #...#. ..#... .. - 0x8a28a020, // #...#. #...#. #...#. #..... ..#... .. - 0xf22f1c20, // ####.. #...#. ####.. .###.. ..#... .. - 0x82aa0220, // #..... #.#.#. #.#... ....#. ..#... .. - 0x82492220, // #..... #..#.. #..#.. #...#. ..#... .. - 0x81a89c20, // #..... .##.#. #...#. .###.. ..#... .. - - 0x8a28a288, // #...#. #...#. #...#. #...#. #...#. .. - 0x8a28a288, // #...#. #...#. #...#. #...#. #...#. .. - 0x8a289488, // #...#. #...#. #...#. .#.#.. #...#. .. - 0x8a2a8850, // #...#. #...#. #.#.#. ..#... .#.#.. .. - 0x894a9420, // #...#. .#.#.. #.#.#. .#.#.. ..#... .. - 0x894aa220, // #...#. .#.#.. #.#.#. #...#. ..#... .. - 0x70852220, // .###.. ..#... .#.#.. #...#. ..#... .. - - 0xf8011000, // #####. ...... ...#.. .#.... ...... .. - 0x08020800, // ....#. ...... ..#... ..#... ...... .. - 0x10840400, // ...#.. ..#... .#.... ...#.. ...... .. - 0x20040470, // ..#... ...... .#.... ...#.. .###.. .. - 0x40840400, // .#.... ..#... .#.... ...#.. ...... .. - 0x80020800, // #..... ...... ..#... ..#... ...... .. - 0xf8011000, // #####. ...... ...#.. .#.... ...... .. - - 0x70800000, // .###.. ..#... ...... ...... ...... .. - 0x88822200, // #...#. ..#... ..#... #...#. ...... .. - 0x08820400, // ....#. ..#... ..#... ...#.. ...... .. - 0x108f8800, // ...#.. ..#... #####. ..#... ...... .. - 0x20821000, // ..#... ..#... ..#... .#.... ...... .. - 0x00022200, // ...... ...... ..#... #...#. ...... .. - 0x20800020, // ..#... ..#... ...... ...... ..#... .. - 0x00000000, -}; - - -char *gCauseDesc[18] = { - "Interrupt", - "TLB modification", - "TLB exception on load", - "TLB exception on store", - "Address error on load", - "Address error on store", - "Bus error on inst.", - "Bus error on data", - "System call exception", - "Breakpoint exception", - "Reserved instruction", - "Coprocessor unusable", - "Arithmetic overflow", - "Trap exception", - "Virtual coherency on inst.", - "Floating point exception", - "Watchpoint exception", - "Virtual coherency on data", -}; - -char *gFpcsrDesc[6] = { - "Unimplemented operation", "Invalid operation", "Division by zero", "Overflow", "Underflow", - "Inexact operation", -}; - - - -extern u64 osClockRate; - -struct { - OSThread thread; - u64 stack[0x800 / sizeof(u64)]; - OSMesgQueue mesgQueue; - OSMesg mesg; - u16 *framebuffer; - u16 width; - u16 height; -} gCrashScreen; - -void crash_screen_draw_rect(s32 x, s32 y, s32 w, s32 h) { - u16 *ptr; - s32 i, j; - - ptr = gCrashScreen.framebuffer + gCrashScreen.width * y + x; - for (i = 0; i < h; i++) { - for (j = 0; j < w; j++) { - // 0xe738 = 0b1110011100111000 - *ptr = ((*ptr & 0xe738) >> 2) | 1; - ptr++; - } - ptr += gCrashScreen.width - w; - } -} - -void crash_screen_draw_glyph(s32 x, s32 y, s32 glyph) { - const u32 *data; - u16 *ptr; - u32 bit; - u32 rowMask; - s32 i, j; - - data = &gCrashScreenFont[glyph / 5 * 7]; - ptr = gCrashScreen.framebuffer + gCrashScreen.width * y + x; - - for (i = 0; i < 7; i++) { - bit = 0x80000000U >> ((glyph % 5) * 6); - rowMask = *data++; - - for (j = 0; j < 6; j++) { - *ptr++ = (bit & rowMask) ? 0xffff : 1; - bit >>= 1; - } - ptr += gCrashScreen.width - 6; - } -} - -static char *write_to_buf(char *buffer, const char *data, size_t size) { - return (char *) memcpy(buffer, data, size) + size; -} - -void crash_screen_print(s32 x, s32 y, const char *fmt, ...) { - char *ptr; - u32 glyph; - s32 size; - char buf[0x100]; - - va_list args; - va_start(args, fmt); - - size = _Printf(write_to_buf, buf, fmt, args); - - if (size > 0) { - ptr = buf; - -#ifdef VERSION_SH - while (size > 0) { -#else - while (*ptr) { -#endif - - glyph = gCrashScreenCharToGlyph[*ptr & 0x7f]; - - if (glyph != 0xff) { - crash_screen_draw_glyph(x, y, glyph); - } - -#ifdef VERSION_SH - size--; -#endif - - ptr++; - x += 6; - } - } - - va_end(args); -} - -void crash_screen_sleep(s32 ms) { - u64 cycles = ms * 1000LL * osClockRate / 1000000ULL; - osSetTime(0); - while (osGetTime() < cycles) { - } -} - -void crash_screen_print_float_reg(s32 x, s32 y, s32 regNum, void *addr) { - u32 bits; - s32 exponent; - - bits = *(u32 *) addr; - exponent = ((bits & 0x7f800000U) >> 0x17) - 0x7f; - if ((exponent >= -0x7e && exponent <= 0x7f) || bits == 0) { - crash_screen_print(x, y, "F%02d:%.3e", regNum, *(f32 *) addr); - } else { - crash_screen_print(x, y, "F%02d:---------", regNum); - } -} - -void crash_screen_print_fpcsr(u32 fpcsr) { - s32 i; - u32 bit; - - bit = 1 << 17; - crash_screen_print(30, 155, "FPCSR:%08XH", fpcsr); - for (i = 0; i < 6; i++) { - if (fpcsr & bit) { - crash_screen_print(132, 155, "(%s)", gFpcsrDesc[i]); - return; - } - bit >>= 1; - } -} - -void draw_crash_screen(OSThread *thread) { - s16 cause; - __OSThreadContext *tc = &thread->context; - - cause = (tc->cause >> 2) & 0x1f; - if (cause == 23) // EXC_WATCH - { - cause = 16; - } - if (cause == 31) // EXC_VCED - { - cause = 17; - } - -#ifdef VERSION_SH - osWritebackDCacheAll(); -#endif - - crash_screen_draw_rect(25, 20, 270, 25); - crash_screen_print(30, 25, "THREAD:%d (%s)", thread->id, gCauseDesc[cause]); - crash_screen_print(30, 35, "PC:%08XH SR:%08XH VA:%08XH", tc->pc, tc->sr, tc->badvaddr); -#ifdef VERSION_EU - osWritebackDCacheAll(); -#endif - crash_screen_sleep(2000); - crash_screen_draw_rect(25, 45, 270, 185); - crash_screen_print(30, 50, "AT:%08XH V0:%08XH V1:%08XH", (u32) tc->at, (u32) tc->v0, - (u32) tc->v1); - crash_screen_print(30, 60, "A0:%08XH A1:%08XH A2:%08XH", (u32) tc->a0, (u32) tc->a1, - (u32) tc->a2); - crash_screen_print(30, 70, "A3:%08XH T0:%08XH T1:%08XH", (u32) tc->a3, (u32) tc->t0, - (u32) tc->t1); - crash_screen_print(30, 80, "T2:%08XH T3:%08XH T4:%08XH", (u32) tc->t2, (u32) tc->t3, - (u32) tc->t4); - crash_screen_print(30, 90, "T5:%08XH T6:%08XH T7:%08XH", (u32) tc->t5, (u32) tc->t6, - (u32) tc->t7); - crash_screen_print(30, 100, "S0:%08XH S1:%08XH S2:%08XH", (u32) tc->s0, (u32) tc->s1, - (u32) tc->s2); - crash_screen_print(30, 110, "S3:%08XH S4:%08XH S5:%08XH", (u32) tc->s3, (u32) tc->s4, - (u32) tc->s5); - crash_screen_print(30, 120, "S6:%08XH S7:%08XH T8:%08XH", (u32) tc->s6, (u32) tc->s7, - (u32) tc->t8); - crash_screen_print(30, 130, "T9:%08XH GP:%08XH SP:%08XH", (u32) tc->t9, (u32) tc->gp, - (u32) tc->sp); - crash_screen_print(30, 140, "S8:%08XH RA:%08XH", (u32) tc->s8, (u32) tc->ra); - crash_screen_print_fpcsr(tc->fpcsr); -#ifdef VERSION_EU - osWritebackDCacheAll(); -#endif - crash_screen_print_float_reg(30, 170, 0, &tc->fp0.f.f_even); - crash_screen_print_float_reg(120, 170, 2, &tc->fp2.f.f_even); - crash_screen_print_float_reg(210, 170, 4, &tc->fp4.f.f_even); - crash_screen_print_float_reg(30, 180, 6, &tc->fp6.f.f_even); - crash_screen_print_float_reg(120, 180, 8, &tc->fp8.f.f_even); - crash_screen_print_float_reg(210, 180, 10, &tc->fp10.f.f_even); - crash_screen_print_float_reg(30, 190, 12, &tc->fp12.f.f_even); - crash_screen_print_float_reg(120, 190, 14, &tc->fp14.f.f_even); - crash_screen_print_float_reg(210, 190, 16, &tc->fp16.f.f_even); - crash_screen_print_float_reg(30, 200, 18, &tc->fp18.f.f_even); - crash_screen_print_float_reg(120, 200, 20, &tc->fp20.f.f_even); - crash_screen_print_float_reg(210, 200, 22, &tc->fp22.f.f_even); - crash_screen_print_float_reg(30, 210, 24, &tc->fp24.f.f_even); - crash_screen_print_float_reg(120, 210, 26, &tc->fp26.f.f_even); - crash_screen_print_float_reg(210, 210, 28, &tc->fp28.f.f_even); - crash_screen_print_float_reg(30, 220, 30, &tc->fp30.f.f_even); -#ifdef VERSION_EU - osWritebackDCacheAll(); -#endif - osViBlack(FALSE); - osViSwapBuffer(gCrashScreen.framebuffer); -} - -OSThread *get_crashed_thread(void) { - OSThread *thread; - - thread = __osGetCurrFaultedThread(); - while (thread->priority != -1) { - if (thread->priority > OS_PRIORITY_IDLE && thread->priority < OS_PRIORITY_APPMAX - && (thread->flags & 3) != 0) { - return thread; - } - thread = thread->tlnext; - } - return NULL; -} - -void thread2_crash_screen(UNUSED void *arg) { - OSMesg mesg; - OSThread *thread; - - osSetEventMesg(OS_EVENT_CPU_BREAK, &gCrashScreen.mesgQueue, (OSMesg) 1); - osSetEventMesg(OS_EVENT_FAULT, &gCrashScreen.mesgQueue, (OSMesg) 2); - do { - osRecvMesg(&gCrashScreen.mesgQueue, &mesg, 1); - thread = get_crashed_thread(); - } while (thread == NULL); - draw_crash_screen(thread); - for (;;) { - } -} - -void crash_screen_set_framebuffer(u16 *framebuffer, s16 width, s16 height) { -#ifdef VERSION_EU - gCrashScreen.framebuffer = framebuffer; -#else - gCrashScreen.framebuffer = (u16 *)((uintptr_t)framebuffer | 0xa0000000); -#endif - gCrashScreen.width = width; - gCrashScreen.height = height; -} - -void crash_screen_init(void) { -#ifdef VERSION_EU - gCrashScreen.framebuffer = (u16 *) (osMemSize | 0x80000000) - SCREEN_WIDTH * SCREEN_HEIGHT; -#else - gCrashScreen.framebuffer = (u16 *) (osMemSize | 0xA0000000) - SCREEN_WIDTH * SCREEN_HEIGHT; -#endif - gCrashScreen.width = SCREEN_WIDTH; -#ifdef VERSION_EU - gCrashScreen.height = SCREEN_HEIGHT; -#else - gCrashScreen.height = 0x10; -#endif - osCreateMesgQueue(&gCrashScreen.mesgQueue, &gCrashScreen.mesg, 1); - osCreateThread(&gCrashScreen.thread, 2, thread2_crash_screen, NULL, - (u8 *) gCrashScreen.stack + sizeof(gCrashScreen.stack), -#ifdef VERSION_EU - OS_PRIORITY_APPMAX -#else - OS_PRIORITY_RMON -#endif - ); - osStartThread(&gCrashScreen.thread); -} - -#endif From 71d7750d45f26cab132c9e2a4ed568091ad7e655 Mon Sep 17 00:00:00 2001 From: "Colton G. Rushton" Date: Sun, 17 May 2020 08:19:04 -0300 Subject: [PATCH 06/30] Makefile updated to thanos TARGET_N64 --- Makefile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Makefile b/Makefile index 6767bf8..00aae4c 100644 --- a/Makefile +++ b/Makefile @@ -18,8 +18,6 @@ GRUCODE ?= f3d_old COMPARE ?= 1 # If NON_MATCHING is 1, define the NON_MATCHING and AVOID_UB macros when building (recommended) NON_MATCHING ?= 1 -# Sane default until N64 build scripts rm'd -TARGET_N64 = 0 # Build and optimize for Raspberry Pi(s) TARGET_RPI ?= 0 From 1ede50c1a541e8843773a68e0d29e9d244e68957 Mon Sep 17 00:00:00 2001 From: Alex Burnett Date: Mon, 18 May 2020 03:34:27 -0700 Subject: [PATCH 07/30] Fix text being wrapped in fullscreen --- bin/segment2.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/segment2.c b/bin/segment2.c index d7e807f..5d5398a 100644 --- a/bin/segment2.c +++ b/bin/segment2.c @@ -2107,7 +2107,7 @@ const Gfx dl_hud_img_load_tex_block[] = { gsDPSetTile(G_IM_FMT_RGBA, G_IM_SIZ_16b, 0, 0, G_TX_LOADTILE, 0, G_TX_WRAP | G_TX_NOMIRROR, 4, G_TX_NOLOD, G_TX_WRAP | G_TX_NOMIRROR, 4, G_TX_NOLOD), gsDPLoadSync(), gsDPLoadBlock(G_TX_LOADTILE, 0, 0, 16 * 16 - 1, CALC_DXT(16, G_IM_SIZ_16b_BYTES)), - gsDPSetTile(G_IM_FMT_RGBA, G_IM_SIZ_16b, 4, 0, G_TX_RENDERTILE, 0, G_TX_WRAP | G_TX_NOMIRROR, 4, G_TX_NOLOD, G_TX_WRAP | G_TX_NOMIRROR, 4, G_TX_NOLOD), + gsDPSetTile(G_IM_FMT_RGBA, G_IM_SIZ_16b, 4, 0, G_TX_RENDERTILE, 0, G_TX_CLAMP, 4, G_TX_NOLOD, G_TX_CLAMP, 4, G_TX_NOLOD), gsDPSetTileSize(0, 0, 0, (16 - 1) << G_TEXTURE_IMAGE_FRAC, (16 - 1) << G_TEXTURE_IMAGE_FRAC), gsSPEndDisplayList(), }; @@ -2144,7 +2144,7 @@ const Gfx dl_rgba16_load_tex_block[] = { gsDPSetTile(G_IM_FMT_RGBA, G_IM_SIZ_16b, 0, 0, G_TX_LOADTILE, 0, G_TX_WRAP | G_TX_NOMIRROR, 4, G_TX_NOLOD, G_TX_WRAP | G_TX_NOMIRROR, 4, G_TX_NOLOD), gsDPLoadSync(), gsDPLoadBlock(G_TX_LOADTILE, 0, 0, 16 * 16 - 1, CALC_DXT(16, G_IM_SIZ_16b_BYTES)), - gsDPSetTile(G_IM_FMT_RGBA, G_IM_SIZ_16b, 4, 0, G_TX_RENDERTILE, 0, G_TX_WRAP | G_TX_NOMIRROR, 4, G_TX_NOLOD, G_TX_WRAP | G_TX_NOMIRROR, 4, G_TX_NOLOD), + gsDPSetTile(G_IM_FMT_RGBA, G_IM_SIZ_16b, 4, 0, G_TX_RENDERTILE, 0, G_TX_CLAMP, 4, G_TX_NOLOD, G_TX_CLAMP, 4, G_TX_NOLOD), gsDPSetTileSize(0, 0, 0, (16 - 1) << G_TEXTURE_IMAGE_FRAC, (16 - 1) << G_TEXTURE_IMAGE_FRAC), gsSPEndDisplayList(), }; From 8586c7657ae804d845bf03a8b577068658b1ee05 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 18 May 2020 17:51:53 +0100 Subject: [PATCH 08/30] Added "Exit course at any time", "Huge Mario" and "Tiny Mario" cheats The exit course at any time cheat clears up one of the TODO items while keeping purists happy since it's optional :) --- include/text_strings.h.in | 4 +++- src/game/ingame_menu.c | 6 ++++-- src/game/mario.c | 17 ++++++++++++++++- src/game/options_menu.c | 6 ++++++ src/pc/cheats.h | 3 +++ 5 files changed, 32 insertions(+), 4 deletions(-) diff --git a/include/text_strings.h.in b/include/text_strings.h.in index 0617369..50c4778 100644 --- a/include/text_strings.h.in +++ b/include/text_strings.h.in @@ -53,7 +53,9 @@ #define TEXT_OPT_CHEAT4 _("Infinite lives") #define TEXT_OPT_CHEAT5 _("Super speed") #define TEXT_OPT_CHEAT6 _("Super responsive controls") - +#define TEXT_OPT_CHEAT7 _("Exit course at any time") +#define TEXT_OPT_CHEAT8 _("Huge Mario") +#define TEXT_OPT_CHEAT9 _("Tiny Mario") /** * Global Symbols */ diff --git a/src/game/ingame_menu.c b/src/game/ingame_menu.c index baaeaf7..4ef6ecf 100644 --- a/src/game/ingame_menu.c +++ b/src/game/ingame_menu.c @@ -19,6 +19,7 @@ #include "print.h" #include "engine/math_util.h" #include "course_table.h" +#include "pc/cheats.h" #ifdef BETTERCAMERA #include "bettercamera.h" #endif @@ -2629,8 +2630,9 @@ s16 render_pause_courses_and_castle(void) { shade_screen(); render_pause_my_score_coins(); render_pause_red_coins(); - - if (gMarioStates[0].action & ACT_FLAG_PAUSE_EXIT) { + +/* Added support for the "Exit course at any time" cheat */ + if ((gMarioStates[0].action & ACT_FLAG_PAUSE_EXIT) || (Cheats.EnableCheats && Cheats.ExitAnywhere)) { render_pause_course_options(99, 93, &gDialogLineNum, 15); } diff --git a/src/game/mario.c b/src/game/mario.c index afeab9a..e00d6e6 100644 --- a/src/game/mario.c +++ b/src/game/mario.c @@ -1215,8 +1215,23 @@ u8 sSquishScaleOverTime[16] = { 0x46, 0x32, 0x32, 0x3C, 0x46, 0x50, 0x50, 0x3C, void squish_mario_model(struct MarioState *m) { if (m->squishTimer != 0xFF) { // If no longer squished, scale back to default. + // Also handles the Tiny Mario and Huge Mario cheats. if (m->squishTimer == 0) { - vec3f_set(m->marioObj->header.gfx.scale, 1.0f, 1.0f, 1.0f); + if (Cheats.EnableCheats) { + if (Cheats.HugeMario) { + vec3f_set(m->marioObj->header.gfx.scale, 2.5f, 2.5f, 2.5f); + } + else if (Cheats.TinyMario) { + vec3f_set(m->marioObj->header.gfx.scale, 0.2f, 0.2f, 0.2f); + } + else { + vec3f_set(m->marioObj->header.gfx.scale, 1.0f, 1.0f, 1.0f); + } + } + else { + vec3f_set(m->marioObj->header.gfx.scale, 1.0f, 1.0f, 1.0f); + } + } // If timer is less than 16, rubber-band Mario's size scale up and down. else if (m->squishTimer <= 16) { diff --git a/src/game/options_menu.c b/src/game/options_menu.c index b9033be..f8c2af3 100644 --- a/src/game/options_menu.c +++ b/src/game/options_menu.c @@ -86,6 +86,9 @@ static const u8 optsCheatsStr[][64] = { { TEXT_OPT_CHEAT4 }, { TEXT_OPT_CHEAT5 }, { TEXT_OPT_CHEAT6 }, + { TEXT_OPT_CHEAT7 }, + { TEXT_OPT_CHEAT8 }, + { TEXT_OPT_CHEAT9 }, }; static const u8 bindStr[][32] = { @@ -232,6 +235,9 @@ static struct Option optsCheats[] = { DEF_OPT_TOGGLE( optsCheatsStr[3], &Cheats.InfiniteLives ), DEF_OPT_TOGGLE( optsCheatsStr[4], &Cheats.SuperSpeed), DEF_OPT_TOGGLE( optsCheatsStr[5], &Cheats.Responsive), + DEF_OPT_TOGGLE( optsCheatsStr[6], &Cheats.ExitAnywhere), + DEF_OPT_TOGGLE( optsCheatsStr[7], &Cheats.HugeMario), + DEF_OPT_TOGGLE( optsCheatsStr[8], &Cheats.TinyMario), }; diff --git a/src/pc/cheats.h b/src/pc/cheats.h index 01a7264..4941a46 100644 --- a/src/pc/cheats.h +++ b/src/pc/cheats.h @@ -8,6 +8,9 @@ struct CheatList bool InfiniteLives; bool SuperSpeed; bool Responsive; + bool ExitAnywhere; + bool HugeMario; + bool TinyMario; }; extern struct CheatList Cheats; From 2bd840a299ec0298e8eef57c0485eaaca57233ad Mon Sep 17 00:00:00 2001 From: fgsfds Date: Mon, 18 May 2020 23:03:04 +0300 Subject: [PATCH 09/30] (hopefully) fix the timing crap; add vsync option --- include/text_strings.h.in | 2 ++ src/game/options_menu.c | 27 ++++++++++++++------ src/pc/configfile.c | 4 ++- src/pc/configfile.h | 3 ++- src/pc/gfx/gfx_sdl2.c | 53 ++++++++++++--------------------------- 5 files changed, 43 insertions(+), 46 deletions(-) diff --git a/include/text_strings.h.in b/include/text_strings.h.in index 0617369..b77a51c 100644 --- a/include/text_strings.h.in +++ b/include/text_strings.h.in @@ -27,6 +27,8 @@ #define TEXT_OPT_NEAREST _("Nearest") #define TEXT_OPT_LINEAR _("Linear") #define TEXT_OPT_MVOLUME _("Master Volume") +#define TEXT_OPT_VSYNC _("Vertical Sync") +#define TEXT_OPT_DOUBLE _("Double") #define TEXT_RESET_WINDOW _("Reset Window") #define TEXT_OPT_UNBOUND _("NONE") diff --git a/src/game/options_menu.c b/src/game/options_menu.c index b9033be..7b8d9f7 100644 --- a/src/game/options_menu.c +++ b/src/game/options_menu.c @@ -72,7 +72,9 @@ static const u8 optsVideoStr[][32] = { { TEXT_OPT_TEXFILTER }, { TEXT_OPT_NEAREST }, { TEXT_OPT_LINEAR }, - { TEXT_RESET_WINDOW } + { TEXT_RESET_WINDOW }, + { TEXT_OPT_VSYNC }, + { TEXT_OPT_DOUBLE }, }; static const u8 optsAudioStr[][32] = { @@ -112,6 +114,12 @@ static const u8 *filterChoices[] = { optsVideoStr[3], }; +static const u8 *vsyncChoices[] = { + toggleStr[0], + toggleStr[1], + optsVideoStr[6], +}; + enum OptType { OPT_INVALID = 0, OPT_TOGGLE, @@ -178,8 +186,12 @@ static void optmenu_act_exit(UNUSED struct Option *self, s32 arg) { if (!arg) game_exit(); // only exit on A press and not directions } -static void optvide_reset_window(UNUSED struct Option *self, s32 arg) { - if (!arg) configWindow.reset = true;; // Restrict reset to A press and not directions +static void optvideo_reset_window(UNUSED struct Option *self, s32 arg) { + if (!arg) { + // Restrict reset to A press and not directions + configWindow.reset = true; + configWindow.settings_changed = true; + } } /* submenu option lists */ @@ -217,8 +229,9 @@ static struct Option optsControls[] = { static struct Option optsVideo[] = { DEF_OPT_TOGGLE( optsVideoStr[0], &configWindow.fullscreen ), + DEF_OPT_CHOICE( optsVideoStr[5], &configWindow.vsync, vsyncChoices ), DEF_OPT_CHOICE( optsVideoStr[1], &configFiltering, filterChoices ), - DEF_OPT_BUTTON( optsVideoStr[4], optvide_reset_window ), + DEF_OPT_BUTTON( optsVideoStr[4], optvideo_reset_window ), }; static struct Option optsAudio[] = { @@ -230,8 +243,8 @@ static struct Option optsCheats[] = { DEF_OPT_TOGGLE( optsCheatsStr[1], &Cheats.MoonJump ), DEF_OPT_TOGGLE( optsCheatsStr[2], &Cheats.GodMode ), DEF_OPT_TOGGLE( optsCheatsStr[3], &Cheats.InfiniteLives ), - DEF_OPT_TOGGLE( optsCheatsStr[4], &Cheats.SuperSpeed), - DEF_OPT_TOGGLE( optsCheatsStr[5], &Cheats.Responsive), + DEF_OPT_TOGGLE( optsCheatsStr[4], &Cheats.SuperSpeed ), + DEF_OPT_TOGGLE( optsCheatsStr[5], &Cheats.Responsive ), }; @@ -243,7 +256,7 @@ static struct SubMenu menuCamera = DEF_SUBMENU( menuStr[4], optsCamera ); static struct SubMenu menuControls = DEF_SUBMENU( menuStr[5], optsControls ); static struct SubMenu menuVideo = DEF_SUBMENU( menuStr[6], optsVideo ); static struct SubMenu menuAudio = DEF_SUBMENU( menuStr[7], optsAudio ); -static struct SubMenu menuCheats = DEF_SUBMENU( menuStr[9], optsCheats ); +static struct SubMenu menuCheats = DEF_SUBMENU( menuStr[9], optsCheats ); /* main options menu definition */ diff --git a/src/pc/configfile.c b/src/pc/configfile.c index 0b6fe37..ce9a08a 100644 --- a/src/pc/configfile.c +++ b/src/pc/configfile.c @@ -40,10 +40,11 @@ ConfigWindow configWindow = { .y = SDL_WINDOWPOS_CENTERED, .w = DESIRED_SCREEN_WIDTH, .h = DESIRED_SCREEN_HEIGHT, + .vsync = 1, .reset = false, - .vsync = false, .fullscreen = false, .exiting_fullscreen = false, + .settings_changed = false, }; unsigned int configFiltering = 1; // 0=force nearest, 1=linear, (TODO) 2=three-point unsigned int configMasterVolume = MAX_VOLUME; // 0 - MAX_VOLUME @@ -84,6 +85,7 @@ static const struct ConfigOption options[] = { {.name = "window_y", .type = CONFIG_TYPE_UINT, .uintValue = &configWindow.y}, {.name = "window_w", .type = CONFIG_TYPE_UINT, .uintValue = &configWindow.w}, {.name = "window_h", .type = CONFIG_TYPE_UINT, .uintValue = &configWindow.h}, + {.name = "vsync", .type = CONFIG_TYPE_UINT, .uintValue = &configWindow.vsync}, {.name = "texture_filtering", .type = CONFIG_TYPE_UINT, .uintValue = &configFiltering}, {.name = "master_volume", .type = CONFIG_TYPE_UINT, .uintValue = &configMasterVolume}, {.name = "key_a", .type = CONFIG_TYPE_BIND, .uintValue = configKeyA}, diff --git a/src/pc/configfile.h b/src/pc/configfile.h index 4343ebd..5238b17 100644 --- a/src/pc/configfile.h +++ b/src/pc/configfile.h @@ -9,10 +9,11 @@ typedef struct { unsigned int x, y, w, h; + unsigned int vsync; bool reset; - bool vsync; bool fullscreen; bool exiting_fullscreen; + bool settings_changed; } ConfigWindow; extern ConfigWindow configWindow; diff --git a/src/pc/gfx/gfx_sdl2.c b/src/pc/gfx/gfx_sdl2.c index 363d920..cc660d7 100644 --- a/src/pc/gfx/gfx_sdl2.c +++ b/src/pc/gfx/gfx_sdl2.c @@ -39,9 +39,12 @@ # define FRAMERATE 30 #endif +static const Uint32 FRAME_TIME = 1000 / FRAMERATE; + static SDL_Window *wnd; static SDL_GLContext ctx = NULL; static int inverted_scancode_table[512]; +static Uint32 frame_start = 0; const SDL_Scancode windows_scancode_table[] = { @@ -110,9 +113,9 @@ static void gfx_sdl_set_fullscreen() { } static void gfx_sdl_reset_dimension_and_pos() { - if (configWindow.exiting_fullscreen) + if (configWindow.exiting_fullscreen) { configWindow.exiting_fullscreen = false; - else if (configWindow.reset) { + } else if (configWindow.reset) { configWindow.x = SDL_WINDOWPOS_CENTERED; configWindow.y = SDL_WINDOWPOS_CENTERED; configWindow.w = DESIRED_SCREEN_WIDTH; @@ -123,29 +126,14 @@ static void gfx_sdl_reset_dimension_and_pos() { configWindow.fullscreen = false; return; } - } else + } else if (!configWindow.settings_changed) { return; + } + configWindow.settings_changed = false; SDL_SetWindowSize(wnd, configWindow.w, configWindow.h); SDL_SetWindowPosition(wnd, configWindow.x, configWindow.y); -} - -static bool test_vsync(void) { - // Even if SDL_GL_SetSwapInterval succeeds, it doesn't mean that VSync actually works. - // A 60 Hz monitor should have a swap interval of 16.67 milliseconds. - // If it takes less than 12 milliseconds, assume that VSync is not working. - // SDL_GetTicks() probably does not offer enough precision for this kind of shit. - Uint32 start, end; - - // do an extra swap, sometimes the first one takes longer (maybe creates buffers?) - SDL_GL_SwapWindow(wnd); - - SDL_GL_SwapWindow(wnd); - start = SDL_GetTicks(); - SDL_GL_SwapWindow(wnd); - end = SDL_GetTicks(); - - return (end - start >= 12); + SDL_GL_SetSwapInterval(configWindow.vsync); // in case vsync changed } static void gfx_sdl_init(void) { @@ -165,11 +153,9 @@ static void gfx_sdl_init(void) { if (gCLIOpts.FullScreen == 1) configWindow.fullscreen = true; - - if (gCLIOpts.FullScreen == 2) + else if (gCLIOpts.FullScreen == 2) configWindow.fullscreen = false; - const char* window_title = #ifndef USE_GLES "Super Mario 64 PC port (OpenGL)"; @@ -183,14 +169,11 @@ static void gfx_sdl_init(void) { SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE ); ctx = SDL_GL_CreateContext(wnd); - SDL_GL_SetSwapInterval(2); + + SDL_GL_SetSwapInterval(configWindow.vsync); gfx_sdl_set_fullscreen(); - configWindow.vsync = test_vsync(); - if (!configWindow.vsync) - printf("Warning: VSync is not enabled or not working. Falling back to timer for synchronization\n"); - for (size_t i = 0; i < sizeof(windows_scancode_table) / sizeof(SDL_Scancode); i++) { inverted_scancode_table[windows_scancode_table[i]] = i; } @@ -275,23 +258,19 @@ static void gfx_sdl_handle_events(void) { } static bool gfx_sdl_start_frame(void) { + frame_start = SDL_GetTicks(); return true; } static void sync_framerate_with_timer(void) { - // Number of milliseconds a frame should take (30 fps) - const Uint32 FRAME_TIME = 1000 / FRAMERATE; - static Uint32 last_time; - - Uint32 elapsed = SDL_GetTicks() - last_time; + Uint32 elapsed = SDL_GetTicks() - frame_start; if (elapsed < FRAME_TIME) SDL_Delay(FRAME_TIME - elapsed); - - last_time = SDL_GetTicks(); } static void gfx_sdl_swap_buffers_begin(void) { - if (!configWindow.vsync) + // if vsync is set to 2, depend only on SwapInterval to sync + if (configWindow.vsync <= 1) sync_framerate_with_timer(); SDL_GL_SwapWindow(wnd); } From 952495ae085d900213f3f88d4bf7209733d06ab5 Mon Sep 17 00:00:00 2001 From: fgsfds Date: Mon, 18 May 2020 23:31:19 +0300 Subject: [PATCH 10/30] clean up cliopts --- src/pc/cliopts.c | 93 +++++++++++++++++++++------------------------ src/pc/cliopts.h | 14 ++++--- src/pc/configfile.h | 2 + 3 files changed, 54 insertions(+), 55 deletions(-) diff --git a/src/pc/cliopts.c b/src/pc/cliopts.c index ee9bc13..234660b 100644 --- a/src/pc/cliopts.c +++ b/src/pc/cliopts.c @@ -1,4 +1,7 @@ #include "cliopts.h" +#include "configfile.h" +#include "pc_main.h" + #include #include #include @@ -6,53 +9,45 @@ struct PCCLIOptions gCLIOpts; -void parse_cli_opts(int argc, char* argv[]) -{ - // Initialize options with false values. - gCLIOpts.SkipIntro = 0; - gCLIOpts.FullScreen = 0; - gCLIOpts.ConfigFile = malloc(31); - strncpy(gCLIOpts.ConfigFile, "sm64config.txt", strlen("sm64config.txt")); - gCLIOpts.ConfigFile[strlen("sm64config.txt")] = '\0'; - - // Scan arguments for options - if (argc > 1) - { - int i; - for (i = 1; i < argc; i++) - { - if (strcmp(argv[i], "--skip-intro") == 0) // Skip Peach Intro - gCLIOpts.SkipIntro = 1; - - if (strcmp(argv[i], "--fullscreen") == 0) // Open game in fullscreen - gCLIOpts.FullScreen = 1; - - if (strcmp(argv[i], "--windowed") == 0) // Open game in windowed mode - gCLIOpts.FullScreen = 2; - - if (strcmp(argv[i], "--help") == 0) // Print help - { - printf("Super Mario 64 PC Port\n"); - printf("%-20s\tSkips the Peach and Castle intro when starting a new game.\n", "--skip-intro"); - printf("%-20s\tStarts the game in full screen mode.\n", "--fullscreen"); - printf("%-20s\tStarts the game in windowed mode.\n", "--windowed"); - printf("%-20s\tSaves the configuration file as CONFIGNAME.\n", "--configfile CONFIGNAME"); - exit(0); - } - - if (strncmp(argv[i], "--configfile", strlen("--configfile")) == 0) - { - if (i+1 < argc) - { - if (strlen(argv[i]) > 30) { - fprintf(stderr, "Configuration file supplied has a name too long.\n"); - } else { - memset(gCLIOpts.ConfigFile, 0, 30); - strncpy(gCLIOpts.ConfigFile, argv[i+1], strlen(argv[i+1])); - gCLIOpts.ConfigFile[strlen(argv[i+1])] = '\0'; - } - } - } - } - } +static void print_help(void) { + printf("Super Mario 64 PC Port\n"); + printf("%-20s\tSkips the Peach and Castle intro when starting a new game.\n", "--skip-intro"); + printf("%-20s\tStarts the game in full screen mode.\n", "--fullscreen"); + printf("%-20s\tStarts the game in windowed mode.\n", "--windowed"); + printf("%-20s\tSaves the configuration file as CONFIGNAME.\n", "--configfile CONFIGNAME"); +} + +void parse_cli_opts(int argc, char* argv[]) { + // Initialize options with false values. + memset(&gCLIOpts, 0, sizeof(gCLIOpts)); + strncpy(gCLIOpts.ConfigFile, CONFIGFILE_DEFAULT, sizeof(gCLIOpts.ConfigFile)); + + for (int i = 1; i < argc; i++) { + if (strcmp(argv[i], "--skip-intro") == 0) // Skip Peach Intro + gCLIOpts.SkipIntro = 1; + + else if (strcmp(argv[i], "--fullscreen") == 0) // Open game in fullscreen + gCLIOpts.FullScreen = 1; + + else if (strcmp(argv[i], "--windowed") == 0) // Open game in windowed mode + gCLIOpts.FullScreen = 2; + + // Print help + else if (strcmp(argv[i], "--help") == 0) { + print_help(); + game_exit(); + } + + else if (strcmp(argv[i], "--configfile") == 0) { + if (i+1 < argc) { + const unsigned int arglen = strlen(argv[i+1]); + if (arglen >= sizeof(gCLIOpts.ConfigFile)) { + fprintf(stderr, "Configuration file supplied has a name too long.\n"); + } else { + strncpy(gCLIOpts.ConfigFile, argv[i+1], arglen); + gCLIOpts.ConfigFile[arglen] = '\0'; + } + } + } + } } diff --git a/src/pc/cliopts.h b/src/pc/cliopts.h index 1844c44..d20dcb4 100644 --- a/src/pc/cliopts.h +++ b/src/pc/cliopts.h @@ -1,12 +1,14 @@ -#include "sm64.h" +#ifndef _CLIOPTS_H +#define _CLIOPTS_H -struct PCCLIOptions -{ - u8 SkipIntro; - u8 FullScreen; - char * ConfigFile; +struct PCCLIOptions { + unsigned int SkipIntro; + unsigned int FullScreen; + char ConfigFile[1024]; }; extern struct PCCLIOptions gCLIOpts; void parse_cli_opts(int argc, char* argv[]); + +#endif // _CLIOPTS_H diff --git a/src/pc/configfile.h b/src/pc/configfile.h index 5238b17..cafd272 100644 --- a/src/pc/configfile.h +++ b/src/pc/configfile.h @@ -3,6 +3,8 @@ #include +#define CONFIGFILE_DEFAULT "sm64config.txt" + #define MAX_BINDS 3 #define MAX_VOLUME 127 #define VOLUME_SHIFT 7 From 36cef2ef5d26b4738d9607cfff1c71ecf19ac565 Mon Sep 17 00:00:00 2001 From: Leon422 Date: Mon, 18 May 2020 22:10:37 +0100 Subject: [PATCH 11/30] Added the cheats menu to the list of features --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 1ba6977..dadc0b7 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ Please contribute **first** to the [nightly branch](https://github.com/sm64pc/sm * An option to disable drawing distances. (Activate with `make NODRAWINGDISTANCE=1`.) * In-game control binding, currently available on the `testing` branch. * Skip introductory Peach & Lakitu cutscenes with the `--skip-intro` CLI option + * Cheats menu, accessible from the "Options" menu. Please note that if a cheat asks you to press "L" it's referring to the N64 button. Check your bindings and make sure you have the "L" button mapped to a button in your controller. ## Building For building instructions, please refer to the [wiki](https://github.com/sm64pc/sm64pc/wiki). From 7ad1b1f12bd7bbb914385c9accb703fce8452962 Mon Sep 17 00:00:00 2001 From: Leon422 Date: Mon, 18 May 2020 22:13:00 +0100 Subject: [PATCH 12/30] *commits in Spanish* --- README_es_ES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README_es_ES.md b/README_es_ES.md index 7426486..02ac0b4 100644 --- a/README_es_ES.md +++ b/README_es_ES.md @@ -13,6 +13,7 @@ Ejecuta `./extract_assets.py --clean && make clean` o `make distclean` para borr * Opción para desactivar el límite de distancia de renderizado. (Se activa con `make NODRAWINGDISTANCE=1`.) * Configurar los controles desde el juego, actualmente solo en la rama `testing`. * Posibilidad de saltarte la intro con la opción de línea de comandos `--skip-intro`, actualmente solo en las ramas `testing` y `skip-intro`. + * Menú de trucos, al cual se accede a través del menú "Options". Ten en cuenta que si un cheat te pide pulsar el botón "L", se refiere al botón de N64, el cual tendrá que estar asignado a un botón de tu mando. Ve a los ajustes de control y asegúrate de que tienes "L" mapeado a un botón de tu mando. ## Compilar en Windows **No intentes compilar ejecutables para Windows bajo Linux usando `WINDOWS_BUILD=1`. No va a funcionar. Sigue la guía.** From 1d9398abb399c46814d7873a9df03a17ff6c7d4d Mon Sep 17 00:00:00 2001 From: Leon422 Date: Mon, 18 May 2020 22:15:06 +0100 Subject: [PATCH 13/30] *commits in Spanish again* Added the cheats menu to the feature list, and updated the feature list in general to match the English version. --- README_es_ES.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README_es_ES.md b/README_es_ES.md index 02ac0b4..fa7ba3c 100644 --- a/README_es_ES.md +++ b/README_es_ES.md @@ -11,8 +11,8 @@ Ejecuta `./extract_assets.py --clean && make clean` o `make distclean` para borr * Soporte nativo para mandos XInput. En Linux, se ha confirmado que el DualShock 4 funciona sin más. * Cámara analógica y cámara controlada con el ratón. (Se activa con `make BETTERCAMERA=1`.) * Opción para desactivar el límite de distancia de renderizado. (Se activa con `make NODRAWINGDISTANCE=1`.) - * Configurar los controles desde el juego, actualmente solo en la rama `testing`. - * Posibilidad de saltarte la intro con la opción de línea de comandos `--skip-intro`, actualmente solo en las ramas `testing` y `skip-intro`. + * Configurar los controles desde el juego. + * Posibilidad de saltarte la intro con la opción de línea de comandos `--skip-intro` * Menú de trucos, al cual se accede a través del menú "Options". Ten en cuenta que si un cheat te pide pulsar el botón "L", se refiere al botón de N64, el cual tendrá que estar asignado a un botón de tu mando. Ve a los ajustes de control y asegúrate de que tienes "L" mapeado a un botón de tu mando. ## Compilar en Windows From c3c2451c6a9d8417e1e7f83ddac3a85e34949b28 Mon Sep 17 00:00:00 2001 From: fgsfds Date: Mon, 18 May 2020 23:03:04 +0300 Subject: [PATCH 14/30] Revert "(hopefully) fix the timing crap; add vsync option" This reverts commit 2bd840a299ec0298e8eef57c0485eaaca57233ad. --- include/text_strings.h.in | 2 -- src/game/options_menu.c | 27 ++++++-------------- src/pc/configfile.c | 4 +-- src/pc/configfile.h | 3 +-- src/pc/gfx/gfx_sdl2.c | 53 +++++++++++++++++++++++++++------------ 5 files changed, 46 insertions(+), 43 deletions(-) diff --git a/include/text_strings.h.in b/include/text_strings.h.in index b77a51c..0617369 100644 --- a/include/text_strings.h.in +++ b/include/text_strings.h.in @@ -27,8 +27,6 @@ #define TEXT_OPT_NEAREST _("Nearest") #define TEXT_OPT_LINEAR _("Linear") #define TEXT_OPT_MVOLUME _("Master Volume") -#define TEXT_OPT_VSYNC _("Vertical Sync") -#define TEXT_OPT_DOUBLE _("Double") #define TEXT_RESET_WINDOW _("Reset Window") #define TEXT_OPT_UNBOUND _("NONE") diff --git a/src/game/options_menu.c b/src/game/options_menu.c index 7b8d9f7..b9033be 100644 --- a/src/game/options_menu.c +++ b/src/game/options_menu.c @@ -72,9 +72,7 @@ static const u8 optsVideoStr[][32] = { { TEXT_OPT_TEXFILTER }, { TEXT_OPT_NEAREST }, { TEXT_OPT_LINEAR }, - { TEXT_RESET_WINDOW }, - { TEXT_OPT_VSYNC }, - { TEXT_OPT_DOUBLE }, + { TEXT_RESET_WINDOW } }; static const u8 optsAudioStr[][32] = { @@ -114,12 +112,6 @@ static const u8 *filterChoices[] = { optsVideoStr[3], }; -static const u8 *vsyncChoices[] = { - toggleStr[0], - toggleStr[1], - optsVideoStr[6], -}; - enum OptType { OPT_INVALID = 0, OPT_TOGGLE, @@ -186,12 +178,8 @@ static void optmenu_act_exit(UNUSED struct Option *self, s32 arg) { if (!arg) game_exit(); // only exit on A press and not directions } -static void optvideo_reset_window(UNUSED struct Option *self, s32 arg) { - if (!arg) { - // Restrict reset to A press and not directions - configWindow.reset = true; - configWindow.settings_changed = true; - } +static void optvide_reset_window(UNUSED struct Option *self, s32 arg) { + if (!arg) configWindow.reset = true;; // Restrict reset to A press and not directions } /* submenu option lists */ @@ -229,9 +217,8 @@ static struct Option optsControls[] = { static struct Option optsVideo[] = { DEF_OPT_TOGGLE( optsVideoStr[0], &configWindow.fullscreen ), - DEF_OPT_CHOICE( optsVideoStr[5], &configWindow.vsync, vsyncChoices ), DEF_OPT_CHOICE( optsVideoStr[1], &configFiltering, filterChoices ), - DEF_OPT_BUTTON( optsVideoStr[4], optvideo_reset_window ), + DEF_OPT_BUTTON( optsVideoStr[4], optvide_reset_window ), }; static struct Option optsAudio[] = { @@ -243,8 +230,8 @@ static struct Option optsCheats[] = { DEF_OPT_TOGGLE( optsCheatsStr[1], &Cheats.MoonJump ), DEF_OPT_TOGGLE( optsCheatsStr[2], &Cheats.GodMode ), DEF_OPT_TOGGLE( optsCheatsStr[3], &Cheats.InfiniteLives ), - DEF_OPT_TOGGLE( optsCheatsStr[4], &Cheats.SuperSpeed ), - DEF_OPT_TOGGLE( optsCheatsStr[5], &Cheats.Responsive ), + DEF_OPT_TOGGLE( optsCheatsStr[4], &Cheats.SuperSpeed), + DEF_OPT_TOGGLE( optsCheatsStr[5], &Cheats.Responsive), }; @@ -256,7 +243,7 @@ static struct SubMenu menuCamera = DEF_SUBMENU( menuStr[4], optsCamera ); static struct SubMenu menuControls = DEF_SUBMENU( menuStr[5], optsControls ); static struct SubMenu menuVideo = DEF_SUBMENU( menuStr[6], optsVideo ); static struct SubMenu menuAudio = DEF_SUBMENU( menuStr[7], optsAudio ); -static struct SubMenu menuCheats = DEF_SUBMENU( menuStr[9], optsCheats ); +static struct SubMenu menuCheats = DEF_SUBMENU( menuStr[9], optsCheats ); /* main options menu definition */ diff --git a/src/pc/configfile.c b/src/pc/configfile.c index ce9a08a..0b6fe37 100644 --- a/src/pc/configfile.c +++ b/src/pc/configfile.c @@ -40,11 +40,10 @@ ConfigWindow configWindow = { .y = SDL_WINDOWPOS_CENTERED, .w = DESIRED_SCREEN_WIDTH, .h = DESIRED_SCREEN_HEIGHT, - .vsync = 1, .reset = false, + .vsync = false, .fullscreen = false, .exiting_fullscreen = false, - .settings_changed = false, }; unsigned int configFiltering = 1; // 0=force nearest, 1=linear, (TODO) 2=three-point unsigned int configMasterVolume = MAX_VOLUME; // 0 - MAX_VOLUME @@ -85,7 +84,6 @@ static const struct ConfigOption options[] = { {.name = "window_y", .type = CONFIG_TYPE_UINT, .uintValue = &configWindow.y}, {.name = "window_w", .type = CONFIG_TYPE_UINT, .uintValue = &configWindow.w}, {.name = "window_h", .type = CONFIG_TYPE_UINT, .uintValue = &configWindow.h}, - {.name = "vsync", .type = CONFIG_TYPE_UINT, .uintValue = &configWindow.vsync}, {.name = "texture_filtering", .type = CONFIG_TYPE_UINT, .uintValue = &configFiltering}, {.name = "master_volume", .type = CONFIG_TYPE_UINT, .uintValue = &configMasterVolume}, {.name = "key_a", .type = CONFIG_TYPE_BIND, .uintValue = configKeyA}, diff --git a/src/pc/configfile.h b/src/pc/configfile.h index cafd272..01d657c 100644 --- a/src/pc/configfile.h +++ b/src/pc/configfile.h @@ -11,11 +11,10 @@ typedef struct { unsigned int x, y, w, h; - unsigned int vsync; bool reset; + bool vsync; bool fullscreen; bool exiting_fullscreen; - bool settings_changed; } ConfigWindow; extern ConfigWindow configWindow; diff --git a/src/pc/gfx/gfx_sdl2.c b/src/pc/gfx/gfx_sdl2.c index cc660d7..363d920 100644 --- a/src/pc/gfx/gfx_sdl2.c +++ b/src/pc/gfx/gfx_sdl2.c @@ -39,12 +39,9 @@ # define FRAMERATE 30 #endif -static const Uint32 FRAME_TIME = 1000 / FRAMERATE; - static SDL_Window *wnd; static SDL_GLContext ctx = NULL; static int inverted_scancode_table[512]; -static Uint32 frame_start = 0; const SDL_Scancode windows_scancode_table[] = { @@ -113,9 +110,9 @@ static void gfx_sdl_set_fullscreen() { } static void gfx_sdl_reset_dimension_and_pos() { - if (configWindow.exiting_fullscreen) { + if (configWindow.exiting_fullscreen) configWindow.exiting_fullscreen = false; - } else if (configWindow.reset) { + else if (configWindow.reset) { configWindow.x = SDL_WINDOWPOS_CENTERED; configWindow.y = SDL_WINDOWPOS_CENTERED; configWindow.w = DESIRED_SCREEN_WIDTH; @@ -126,14 +123,29 @@ static void gfx_sdl_reset_dimension_and_pos() { configWindow.fullscreen = false; return; } - } else if (!configWindow.settings_changed) { + } else return; - } - configWindow.settings_changed = false; SDL_SetWindowSize(wnd, configWindow.w, configWindow.h); SDL_SetWindowPosition(wnd, configWindow.x, configWindow.y); - SDL_GL_SetSwapInterval(configWindow.vsync); // in case vsync changed +} + +static bool test_vsync(void) { + // Even if SDL_GL_SetSwapInterval succeeds, it doesn't mean that VSync actually works. + // A 60 Hz monitor should have a swap interval of 16.67 milliseconds. + // If it takes less than 12 milliseconds, assume that VSync is not working. + // SDL_GetTicks() probably does not offer enough precision for this kind of shit. + Uint32 start, end; + + // do an extra swap, sometimes the first one takes longer (maybe creates buffers?) + SDL_GL_SwapWindow(wnd); + + SDL_GL_SwapWindow(wnd); + start = SDL_GetTicks(); + SDL_GL_SwapWindow(wnd); + end = SDL_GetTicks(); + + return (end - start >= 12); } static void gfx_sdl_init(void) { @@ -153,9 +165,11 @@ static void gfx_sdl_init(void) { if (gCLIOpts.FullScreen == 1) configWindow.fullscreen = true; - else if (gCLIOpts.FullScreen == 2) + + if (gCLIOpts.FullScreen == 2) configWindow.fullscreen = false; + const char* window_title = #ifndef USE_GLES "Super Mario 64 PC port (OpenGL)"; @@ -169,11 +183,14 @@ static void gfx_sdl_init(void) { SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE ); ctx = SDL_GL_CreateContext(wnd); - - SDL_GL_SetSwapInterval(configWindow.vsync); + SDL_GL_SetSwapInterval(2); gfx_sdl_set_fullscreen(); + configWindow.vsync = test_vsync(); + if (!configWindow.vsync) + printf("Warning: VSync is not enabled or not working. Falling back to timer for synchronization\n"); + for (size_t i = 0; i < sizeof(windows_scancode_table) / sizeof(SDL_Scancode); i++) { inverted_scancode_table[windows_scancode_table[i]] = i; } @@ -258,19 +275,23 @@ static void gfx_sdl_handle_events(void) { } static bool gfx_sdl_start_frame(void) { - frame_start = SDL_GetTicks(); return true; } static void sync_framerate_with_timer(void) { - Uint32 elapsed = SDL_GetTicks() - frame_start; + // Number of milliseconds a frame should take (30 fps) + const Uint32 FRAME_TIME = 1000 / FRAMERATE; + static Uint32 last_time; + + Uint32 elapsed = SDL_GetTicks() - last_time; if (elapsed < FRAME_TIME) SDL_Delay(FRAME_TIME - elapsed); + + last_time = SDL_GetTicks(); } static void gfx_sdl_swap_buffers_begin(void) { - // if vsync is set to 2, depend only on SwapInterval to sync - if (configWindow.vsync <= 1) + if (!configWindow.vsync) sync_framerate_with_timer(); SDL_GL_SwapWindow(wnd); } From c6961b8606d63d33c8ffebf001b932b0ddb3ff16 Mon Sep 17 00:00:00 2001 From: fgsfds Date: Mon, 18 May 2020 23:03:04 +0300 Subject: [PATCH 15/30] Revert "(hopefully) fix the timing crap; add vsync option" This reverts commit 2bd840a299ec0298e8eef57c0485eaaca57233ad. --- include/text_strings.h.in | 2 -- src/game/options_menu.c | 27 ++++++-------------- src/pc/configfile.c | 4 +-- src/pc/configfile.h | 3 +-- src/pc/gfx/gfx_sdl2.c | 53 +++++++++++++++++++++++++++------------ 5 files changed, 46 insertions(+), 43 deletions(-) diff --git a/include/text_strings.h.in b/include/text_strings.h.in index b77a51c..0617369 100644 --- a/include/text_strings.h.in +++ b/include/text_strings.h.in @@ -27,8 +27,6 @@ #define TEXT_OPT_NEAREST _("Nearest") #define TEXT_OPT_LINEAR _("Linear") #define TEXT_OPT_MVOLUME _("Master Volume") -#define TEXT_OPT_VSYNC _("Vertical Sync") -#define TEXT_OPT_DOUBLE _("Double") #define TEXT_RESET_WINDOW _("Reset Window") #define TEXT_OPT_UNBOUND _("NONE") diff --git a/src/game/options_menu.c b/src/game/options_menu.c index 7b8d9f7..b9033be 100644 --- a/src/game/options_menu.c +++ b/src/game/options_menu.c @@ -72,9 +72,7 @@ static const u8 optsVideoStr[][32] = { { TEXT_OPT_TEXFILTER }, { TEXT_OPT_NEAREST }, { TEXT_OPT_LINEAR }, - { TEXT_RESET_WINDOW }, - { TEXT_OPT_VSYNC }, - { TEXT_OPT_DOUBLE }, + { TEXT_RESET_WINDOW } }; static const u8 optsAudioStr[][32] = { @@ -114,12 +112,6 @@ static const u8 *filterChoices[] = { optsVideoStr[3], }; -static const u8 *vsyncChoices[] = { - toggleStr[0], - toggleStr[1], - optsVideoStr[6], -}; - enum OptType { OPT_INVALID = 0, OPT_TOGGLE, @@ -186,12 +178,8 @@ static void optmenu_act_exit(UNUSED struct Option *self, s32 arg) { if (!arg) game_exit(); // only exit on A press and not directions } -static void optvideo_reset_window(UNUSED struct Option *self, s32 arg) { - if (!arg) { - // Restrict reset to A press and not directions - configWindow.reset = true; - configWindow.settings_changed = true; - } +static void optvide_reset_window(UNUSED struct Option *self, s32 arg) { + if (!arg) configWindow.reset = true;; // Restrict reset to A press and not directions } /* submenu option lists */ @@ -229,9 +217,8 @@ static struct Option optsControls[] = { static struct Option optsVideo[] = { DEF_OPT_TOGGLE( optsVideoStr[0], &configWindow.fullscreen ), - DEF_OPT_CHOICE( optsVideoStr[5], &configWindow.vsync, vsyncChoices ), DEF_OPT_CHOICE( optsVideoStr[1], &configFiltering, filterChoices ), - DEF_OPT_BUTTON( optsVideoStr[4], optvideo_reset_window ), + DEF_OPT_BUTTON( optsVideoStr[4], optvide_reset_window ), }; static struct Option optsAudio[] = { @@ -243,8 +230,8 @@ static struct Option optsCheats[] = { DEF_OPT_TOGGLE( optsCheatsStr[1], &Cheats.MoonJump ), DEF_OPT_TOGGLE( optsCheatsStr[2], &Cheats.GodMode ), DEF_OPT_TOGGLE( optsCheatsStr[3], &Cheats.InfiniteLives ), - DEF_OPT_TOGGLE( optsCheatsStr[4], &Cheats.SuperSpeed ), - DEF_OPT_TOGGLE( optsCheatsStr[5], &Cheats.Responsive ), + DEF_OPT_TOGGLE( optsCheatsStr[4], &Cheats.SuperSpeed), + DEF_OPT_TOGGLE( optsCheatsStr[5], &Cheats.Responsive), }; @@ -256,7 +243,7 @@ static struct SubMenu menuCamera = DEF_SUBMENU( menuStr[4], optsCamera ); static struct SubMenu menuControls = DEF_SUBMENU( menuStr[5], optsControls ); static struct SubMenu menuVideo = DEF_SUBMENU( menuStr[6], optsVideo ); static struct SubMenu menuAudio = DEF_SUBMENU( menuStr[7], optsAudio ); -static struct SubMenu menuCheats = DEF_SUBMENU( menuStr[9], optsCheats ); +static struct SubMenu menuCheats = DEF_SUBMENU( menuStr[9], optsCheats ); /* main options menu definition */ diff --git a/src/pc/configfile.c b/src/pc/configfile.c index ce9a08a..0b6fe37 100644 --- a/src/pc/configfile.c +++ b/src/pc/configfile.c @@ -40,11 +40,10 @@ ConfigWindow configWindow = { .y = SDL_WINDOWPOS_CENTERED, .w = DESIRED_SCREEN_WIDTH, .h = DESIRED_SCREEN_HEIGHT, - .vsync = 1, .reset = false, + .vsync = false, .fullscreen = false, .exiting_fullscreen = false, - .settings_changed = false, }; unsigned int configFiltering = 1; // 0=force nearest, 1=linear, (TODO) 2=three-point unsigned int configMasterVolume = MAX_VOLUME; // 0 - MAX_VOLUME @@ -85,7 +84,6 @@ static const struct ConfigOption options[] = { {.name = "window_y", .type = CONFIG_TYPE_UINT, .uintValue = &configWindow.y}, {.name = "window_w", .type = CONFIG_TYPE_UINT, .uintValue = &configWindow.w}, {.name = "window_h", .type = CONFIG_TYPE_UINT, .uintValue = &configWindow.h}, - {.name = "vsync", .type = CONFIG_TYPE_UINT, .uintValue = &configWindow.vsync}, {.name = "texture_filtering", .type = CONFIG_TYPE_UINT, .uintValue = &configFiltering}, {.name = "master_volume", .type = CONFIG_TYPE_UINT, .uintValue = &configMasterVolume}, {.name = "key_a", .type = CONFIG_TYPE_BIND, .uintValue = configKeyA}, diff --git a/src/pc/configfile.h b/src/pc/configfile.h index cafd272..01d657c 100644 --- a/src/pc/configfile.h +++ b/src/pc/configfile.h @@ -11,11 +11,10 @@ typedef struct { unsigned int x, y, w, h; - unsigned int vsync; bool reset; + bool vsync; bool fullscreen; bool exiting_fullscreen; - bool settings_changed; } ConfigWindow; extern ConfigWindow configWindow; diff --git a/src/pc/gfx/gfx_sdl2.c b/src/pc/gfx/gfx_sdl2.c index cc660d7..363d920 100644 --- a/src/pc/gfx/gfx_sdl2.c +++ b/src/pc/gfx/gfx_sdl2.c @@ -39,12 +39,9 @@ # define FRAMERATE 30 #endif -static const Uint32 FRAME_TIME = 1000 / FRAMERATE; - static SDL_Window *wnd; static SDL_GLContext ctx = NULL; static int inverted_scancode_table[512]; -static Uint32 frame_start = 0; const SDL_Scancode windows_scancode_table[] = { @@ -113,9 +110,9 @@ static void gfx_sdl_set_fullscreen() { } static void gfx_sdl_reset_dimension_and_pos() { - if (configWindow.exiting_fullscreen) { + if (configWindow.exiting_fullscreen) configWindow.exiting_fullscreen = false; - } else if (configWindow.reset) { + else if (configWindow.reset) { configWindow.x = SDL_WINDOWPOS_CENTERED; configWindow.y = SDL_WINDOWPOS_CENTERED; configWindow.w = DESIRED_SCREEN_WIDTH; @@ -126,14 +123,29 @@ static void gfx_sdl_reset_dimension_and_pos() { configWindow.fullscreen = false; return; } - } else if (!configWindow.settings_changed) { + } else return; - } - configWindow.settings_changed = false; SDL_SetWindowSize(wnd, configWindow.w, configWindow.h); SDL_SetWindowPosition(wnd, configWindow.x, configWindow.y); - SDL_GL_SetSwapInterval(configWindow.vsync); // in case vsync changed +} + +static bool test_vsync(void) { + // Even if SDL_GL_SetSwapInterval succeeds, it doesn't mean that VSync actually works. + // A 60 Hz monitor should have a swap interval of 16.67 milliseconds. + // If it takes less than 12 milliseconds, assume that VSync is not working. + // SDL_GetTicks() probably does not offer enough precision for this kind of shit. + Uint32 start, end; + + // do an extra swap, sometimes the first one takes longer (maybe creates buffers?) + SDL_GL_SwapWindow(wnd); + + SDL_GL_SwapWindow(wnd); + start = SDL_GetTicks(); + SDL_GL_SwapWindow(wnd); + end = SDL_GetTicks(); + + return (end - start >= 12); } static void gfx_sdl_init(void) { @@ -153,9 +165,11 @@ static void gfx_sdl_init(void) { if (gCLIOpts.FullScreen == 1) configWindow.fullscreen = true; - else if (gCLIOpts.FullScreen == 2) + + if (gCLIOpts.FullScreen == 2) configWindow.fullscreen = false; + const char* window_title = #ifndef USE_GLES "Super Mario 64 PC port (OpenGL)"; @@ -169,11 +183,14 @@ static void gfx_sdl_init(void) { SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE ); ctx = SDL_GL_CreateContext(wnd); - - SDL_GL_SetSwapInterval(configWindow.vsync); + SDL_GL_SetSwapInterval(2); gfx_sdl_set_fullscreen(); + configWindow.vsync = test_vsync(); + if (!configWindow.vsync) + printf("Warning: VSync is not enabled or not working. Falling back to timer for synchronization\n"); + for (size_t i = 0; i < sizeof(windows_scancode_table) / sizeof(SDL_Scancode); i++) { inverted_scancode_table[windows_scancode_table[i]] = i; } @@ -258,19 +275,23 @@ static void gfx_sdl_handle_events(void) { } static bool gfx_sdl_start_frame(void) { - frame_start = SDL_GetTicks(); return true; } static void sync_framerate_with_timer(void) { - Uint32 elapsed = SDL_GetTicks() - frame_start; + // Number of milliseconds a frame should take (30 fps) + const Uint32 FRAME_TIME = 1000 / FRAMERATE; + static Uint32 last_time; + + Uint32 elapsed = SDL_GetTicks() - last_time; if (elapsed < FRAME_TIME) SDL_Delay(FRAME_TIME - elapsed); + + last_time = SDL_GetTicks(); } static void gfx_sdl_swap_buffers_begin(void) { - // if vsync is set to 2, depend only on SwapInterval to sync - if (configWindow.vsync <= 1) + if (!configWindow.vsync) sync_framerate_with_timer(); SDL_GL_SwapWindow(wnd); } From 59913a9beb3d902d277377663610a4813167ef26 Mon Sep 17 00:00:00 2001 From: fgsfds Date: Tue, 19 May 2020 01:25:59 +0300 Subject: [PATCH 16/30] Revert "Revert "(hopefully) fix the timing crap; add vsync option"" This reverts commit c6961b8606d63d33c8ffebf001b932b0ddb3ff16. --- include/text_strings.h.in | 2 ++ src/game/options_menu.c | 27 ++++++++++++++------ src/pc/configfile.c | 4 ++- src/pc/configfile.h | 3 ++- src/pc/gfx/gfx_sdl2.c | 53 ++++++++++++--------------------------- 5 files changed, 43 insertions(+), 46 deletions(-) diff --git a/include/text_strings.h.in b/include/text_strings.h.in index 0617369..b77a51c 100644 --- a/include/text_strings.h.in +++ b/include/text_strings.h.in @@ -27,6 +27,8 @@ #define TEXT_OPT_NEAREST _("Nearest") #define TEXT_OPT_LINEAR _("Linear") #define TEXT_OPT_MVOLUME _("Master Volume") +#define TEXT_OPT_VSYNC _("Vertical Sync") +#define TEXT_OPT_DOUBLE _("Double") #define TEXT_RESET_WINDOW _("Reset Window") #define TEXT_OPT_UNBOUND _("NONE") diff --git a/src/game/options_menu.c b/src/game/options_menu.c index b9033be..7b8d9f7 100644 --- a/src/game/options_menu.c +++ b/src/game/options_menu.c @@ -72,7 +72,9 @@ static const u8 optsVideoStr[][32] = { { TEXT_OPT_TEXFILTER }, { TEXT_OPT_NEAREST }, { TEXT_OPT_LINEAR }, - { TEXT_RESET_WINDOW } + { TEXT_RESET_WINDOW }, + { TEXT_OPT_VSYNC }, + { TEXT_OPT_DOUBLE }, }; static const u8 optsAudioStr[][32] = { @@ -112,6 +114,12 @@ static const u8 *filterChoices[] = { optsVideoStr[3], }; +static const u8 *vsyncChoices[] = { + toggleStr[0], + toggleStr[1], + optsVideoStr[6], +}; + enum OptType { OPT_INVALID = 0, OPT_TOGGLE, @@ -178,8 +186,12 @@ static void optmenu_act_exit(UNUSED struct Option *self, s32 arg) { if (!arg) game_exit(); // only exit on A press and not directions } -static void optvide_reset_window(UNUSED struct Option *self, s32 arg) { - if (!arg) configWindow.reset = true;; // Restrict reset to A press and not directions +static void optvideo_reset_window(UNUSED struct Option *self, s32 arg) { + if (!arg) { + // Restrict reset to A press and not directions + configWindow.reset = true; + configWindow.settings_changed = true; + } } /* submenu option lists */ @@ -217,8 +229,9 @@ static struct Option optsControls[] = { static struct Option optsVideo[] = { DEF_OPT_TOGGLE( optsVideoStr[0], &configWindow.fullscreen ), + DEF_OPT_CHOICE( optsVideoStr[5], &configWindow.vsync, vsyncChoices ), DEF_OPT_CHOICE( optsVideoStr[1], &configFiltering, filterChoices ), - DEF_OPT_BUTTON( optsVideoStr[4], optvide_reset_window ), + DEF_OPT_BUTTON( optsVideoStr[4], optvideo_reset_window ), }; static struct Option optsAudio[] = { @@ -230,8 +243,8 @@ static struct Option optsCheats[] = { DEF_OPT_TOGGLE( optsCheatsStr[1], &Cheats.MoonJump ), DEF_OPT_TOGGLE( optsCheatsStr[2], &Cheats.GodMode ), DEF_OPT_TOGGLE( optsCheatsStr[3], &Cheats.InfiniteLives ), - DEF_OPT_TOGGLE( optsCheatsStr[4], &Cheats.SuperSpeed), - DEF_OPT_TOGGLE( optsCheatsStr[5], &Cheats.Responsive), + DEF_OPT_TOGGLE( optsCheatsStr[4], &Cheats.SuperSpeed ), + DEF_OPT_TOGGLE( optsCheatsStr[5], &Cheats.Responsive ), }; @@ -243,7 +256,7 @@ static struct SubMenu menuCamera = DEF_SUBMENU( menuStr[4], optsCamera ); static struct SubMenu menuControls = DEF_SUBMENU( menuStr[5], optsControls ); static struct SubMenu menuVideo = DEF_SUBMENU( menuStr[6], optsVideo ); static struct SubMenu menuAudio = DEF_SUBMENU( menuStr[7], optsAudio ); -static struct SubMenu menuCheats = DEF_SUBMENU( menuStr[9], optsCheats ); +static struct SubMenu menuCheats = DEF_SUBMENU( menuStr[9], optsCheats ); /* main options menu definition */ diff --git a/src/pc/configfile.c b/src/pc/configfile.c index 0b6fe37..ce9a08a 100644 --- a/src/pc/configfile.c +++ b/src/pc/configfile.c @@ -40,10 +40,11 @@ ConfigWindow configWindow = { .y = SDL_WINDOWPOS_CENTERED, .w = DESIRED_SCREEN_WIDTH, .h = DESIRED_SCREEN_HEIGHT, + .vsync = 1, .reset = false, - .vsync = false, .fullscreen = false, .exiting_fullscreen = false, + .settings_changed = false, }; unsigned int configFiltering = 1; // 0=force nearest, 1=linear, (TODO) 2=three-point unsigned int configMasterVolume = MAX_VOLUME; // 0 - MAX_VOLUME @@ -84,6 +85,7 @@ static const struct ConfigOption options[] = { {.name = "window_y", .type = CONFIG_TYPE_UINT, .uintValue = &configWindow.y}, {.name = "window_w", .type = CONFIG_TYPE_UINT, .uintValue = &configWindow.w}, {.name = "window_h", .type = CONFIG_TYPE_UINT, .uintValue = &configWindow.h}, + {.name = "vsync", .type = CONFIG_TYPE_UINT, .uintValue = &configWindow.vsync}, {.name = "texture_filtering", .type = CONFIG_TYPE_UINT, .uintValue = &configFiltering}, {.name = "master_volume", .type = CONFIG_TYPE_UINT, .uintValue = &configMasterVolume}, {.name = "key_a", .type = CONFIG_TYPE_BIND, .uintValue = configKeyA}, diff --git a/src/pc/configfile.h b/src/pc/configfile.h index 01d657c..cafd272 100644 --- a/src/pc/configfile.h +++ b/src/pc/configfile.h @@ -11,10 +11,11 @@ typedef struct { unsigned int x, y, w, h; + unsigned int vsync; bool reset; - bool vsync; bool fullscreen; bool exiting_fullscreen; + bool settings_changed; } ConfigWindow; extern ConfigWindow configWindow; diff --git a/src/pc/gfx/gfx_sdl2.c b/src/pc/gfx/gfx_sdl2.c index 363d920..cc660d7 100644 --- a/src/pc/gfx/gfx_sdl2.c +++ b/src/pc/gfx/gfx_sdl2.c @@ -39,9 +39,12 @@ # define FRAMERATE 30 #endif +static const Uint32 FRAME_TIME = 1000 / FRAMERATE; + static SDL_Window *wnd; static SDL_GLContext ctx = NULL; static int inverted_scancode_table[512]; +static Uint32 frame_start = 0; const SDL_Scancode windows_scancode_table[] = { @@ -110,9 +113,9 @@ static void gfx_sdl_set_fullscreen() { } static void gfx_sdl_reset_dimension_and_pos() { - if (configWindow.exiting_fullscreen) + if (configWindow.exiting_fullscreen) { configWindow.exiting_fullscreen = false; - else if (configWindow.reset) { + } else if (configWindow.reset) { configWindow.x = SDL_WINDOWPOS_CENTERED; configWindow.y = SDL_WINDOWPOS_CENTERED; configWindow.w = DESIRED_SCREEN_WIDTH; @@ -123,29 +126,14 @@ static void gfx_sdl_reset_dimension_and_pos() { configWindow.fullscreen = false; return; } - } else + } else if (!configWindow.settings_changed) { return; + } + configWindow.settings_changed = false; SDL_SetWindowSize(wnd, configWindow.w, configWindow.h); SDL_SetWindowPosition(wnd, configWindow.x, configWindow.y); -} - -static bool test_vsync(void) { - // Even if SDL_GL_SetSwapInterval succeeds, it doesn't mean that VSync actually works. - // A 60 Hz monitor should have a swap interval of 16.67 milliseconds. - // If it takes less than 12 milliseconds, assume that VSync is not working. - // SDL_GetTicks() probably does not offer enough precision for this kind of shit. - Uint32 start, end; - - // do an extra swap, sometimes the first one takes longer (maybe creates buffers?) - SDL_GL_SwapWindow(wnd); - - SDL_GL_SwapWindow(wnd); - start = SDL_GetTicks(); - SDL_GL_SwapWindow(wnd); - end = SDL_GetTicks(); - - return (end - start >= 12); + SDL_GL_SetSwapInterval(configWindow.vsync); // in case vsync changed } static void gfx_sdl_init(void) { @@ -165,11 +153,9 @@ static void gfx_sdl_init(void) { if (gCLIOpts.FullScreen == 1) configWindow.fullscreen = true; - - if (gCLIOpts.FullScreen == 2) + else if (gCLIOpts.FullScreen == 2) configWindow.fullscreen = false; - const char* window_title = #ifndef USE_GLES "Super Mario 64 PC port (OpenGL)"; @@ -183,14 +169,11 @@ static void gfx_sdl_init(void) { SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE ); ctx = SDL_GL_CreateContext(wnd); - SDL_GL_SetSwapInterval(2); + + SDL_GL_SetSwapInterval(configWindow.vsync); gfx_sdl_set_fullscreen(); - configWindow.vsync = test_vsync(); - if (!configWindow.vsync) - printf("Warning: VSync is not enabled or not working. Falling back to timer for synchronization\n"); - for (size_t i = 0; i < sizeof(windows_scancode_table) / sizeof(SDL_Scancode); i++) { inverted_scancode_table[windows_scancode_table[i]] = i; } @@ -275,23 +258,19 @@ static void gfx_sdl_handle_events(void) { } static bool gfx_sdl_start_frame(void) { + frame_start = SDL_GetTicks(); return true; } static void sync_framerate_with_timer(void) { - // Number of milliseconds a frame should take (30 fps) - const Uint32 FRAME_TIME = 1000 / FRAMERATE; - static Uint32 last_time; - - Uint32 elapsed = SDL_GetTicks() - last_time; + Uint32 elapsed = SDL_GetTicks() - frame_start; if (elapsed < FRAME_TIME) SDL_Delay(FRAME_TIME - elapsed); - - last_time = SDL_GetTicks(); } static void gfx_sdl_swap_buffers_begin(void) { - if (!configWindow.vsync) + // if vsync is set to 2, depend only on SwapInterval to sync + if (configWindow.vsync <= 1) sync_framerate_with_timer(); SDL_GL_SwapWindow(wnd); } From 6a79a9af99748b6caad82377a3eb1929205c3df6 Mon Sep 17 00:00:00 2001 From: fgsfds Date: Tue, 19 May 2020 01:32:49 +0300 Subject: [PATCH 17/30] bring back the old frame timing method (if vsync != 2) --- src/pc/gfx/gfx_sdl2.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/pc/gfx/gfx_sdl2.c b/src/pc/gfx/gfx_sdl2.c index cc660d7..e86a100 100644 --- a/src/pc/gfx/gfx_sdl2.c +++ b/src/pc/gfx/gfx_sdl2.c @@ -189,8 +189,14 @@ static void gfx_sdl_init(void) { } static void gfx_sdl_main_loop(void (*run_one_game_iter)(void)) { - while (1) + Uint32 t; + while (1) { + t = SDL_GetTicks(); run_one_game_iter(); + t = SDL_GetTicks() - t; + if (t < FRAME_TIME && configWindow.vsync <= 1) + SDL_Delay(FRAME_TIME - t); + } } static void gfx_sdl_get_dimensions(uint32_t *width, uint32_t *height) { @@ -262,16 +268,7 @@ static bool gfx_sdl_start_frame(void) { return true; } -static void sync_framerate_with_timer(void) { - Uint32 elapsed = SDL_GetTicks() - frame_start; - if (elapsed < FRAME_TIME) - SDL_Delay(FRAME_TIME - elapsed); -} - static void gfx_sdl_swap_buffers_begin(void) { - // if vsync is set to 2, depend only on SwapInterval to sync - if (configWindow.vsync <= 1) - sync_framerate_with_timer(); SDL_GL_SwapWindow(wnd); } From 26705aed7a3b83103606a1e0e847055aba065d8a Mon Sep 17 00:00:00 2001 From: fgsfds Date: Tue, 19 May 2020 01:59:29 +0300 Subject: [PATCH 18/30] disable cheats by default; use --cheats CLI option to enable for now --- src/game/options_menu.c | 15 +++++++++++++-- src/pc/cheats.c | 1 + src/pc/cheats.h | 10 +++++++--- src/pc/cliopts.c | 4 ++++ 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/game/options_menu.c b/src/game/options_menu.c index 7b8d9f7..d23223b 100644 --- a/src/game/options_menu.c +++ b/src/game/options_menu.c @@ -268,8 +268,8 @@ static struct Option optsMain[] = { DEF_OPT_SUBMENU( menuStr[6], &menuVideo ), DEF_OPT_SUBMENU( menuStr[7], &menuAudio ), DEF_OPT_BUTTON ( menuStr[8], optmenu_act_exit ), - DEF_OPT_SUBMENU( menuStr[9], &menuCheats ), - + // NOTE: always keep cheats the last option here because of the half-assed way I toggle them + DEF_OPT_SUBMENU( menuStr[9], &menuCheats ) }; static struct SubMenu menuMain = DEF_SUBMENU( menuStr[3], optsMain ); @@ -459,6 +459,17 @@ void optmenu_toggle(void) { #ifndef nosound play_sound(SOUND_MENU_CHANGE_SELECT, gDefaultSoundArgs); #endif + + // HACK: hide the last option in main if cheats are disabled + menuMain.numOpts = sizeof(optsMain) / sizeof(optsMain[0]); + if (!Cheats.EnableCheats) { + menuMain.numOpts--; + if (menuMain.select >= menuMain.numOpts) { + menuMain.select = 0; // don't bother + menuMain.scroll = 0; + } + } + currentMenu = &menuMain; optmenu_open = 1; } else { diff --git a/src/pc/cheats.c b/src/pc/cheats.c index 5663d77..adcc4ef 100644 --- a/src/pc/cheats.c +++ b/src/pc/cheats.c @@ -1,2 +1,3 @@ #include "cheats.h" + struct CheatList Cheats; diff --git a/src/pc/cheats.h b/src/pc/cheats.h index 01a7264..531c392 100644 --- a/src/pc/cheats.h +++ b/src/pc/cheats.h @@ -1,9 +1,11 @@ +#ifndef _CHEATS_H +#define _CHEATS_H + #include -struct CheatList -{ +struct CheatList { bool EnableCheats; - bool MoonJump; + bool MoonJump; bool GodMode; bool InfiniteLives; bool SuperSpeed; @@ -11,3 +13,5 @@ struct CheatList }; extern struct CheatList Cheats; + +#endif // _CHEATS_H diff --git a/src/pc/cliopts.c b/src/pc/cliopts.c index 234660b..727de38 100644 --- a/src/pc/cliopts.c +++ b/src/pc/cliopts.c @@ -1,5 +1,6 @@ #include "cliopts.h" #include "configfile.h" +#include "cheats.h" #include "pc_main.h" #include @@ -32,6 +33,9 @@ void parse_cli_opts(int argc, char* argv[]) { else if (strcmp(argv[i], "--windowed") == 0) // Open game in windowed mode gCLIOpts.FullScreen = 2; + else if (strcmp(argv[i], "--cheats") == 0) // Enable cheats menu + Cheats.EnableCheats = true; + // Print help else if (strcmp(argv[i], "--help") == 0) { print_help(); From 8e60f9960ea6452011bd33cc833ee309adc91700 Mon Sep 17 00:00:00 2001 From: Leon422 Date: Tue, 19 May 2020 00:02:03 +0100 Subject: [PATCH 19/30] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index dadc0b7..0e28a0b 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Please contribute **first** to the [nightly branch](https://github.com/sm64pc/sm * An option to disable drawing distances. (Activate with `make NODRAWINGDISTANCE=1`.) * In-game control binding, currently available on the `testing` branch. * Skip introductory Peach & Lakitu cutscenes with the `--skip-intro` CLI option - * Cheats menu, accessible from the "Options" menu. Please note that if a cheat asks you to press "L" it's referring to the N64 button. Check your bindings and make sure you have the "L" button mapped to a button in your controller. + * Cheats menu in Options. (Activate with `--cheats`) Please note that if a cheat asks you to press "L" it's referring to the N64 button. Check your bindings and make sure you have the "L" button mapped to a button in your controller. ## Building For building instructions, please refer to the [wiki](https://github.com/sm64pc/sm64pc/wiki). From 18c197dbff6c3932688ec6f56d81cf8f1fbe1ca7 Mon Sep 17 00:00:00 2001 From: Leon422 Date: Tue, 19 May 2020 00:04:07 +0100 Subject: [PATCH 20/30] Update README_es_ES.md --- README_es_ES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README_es_ES.md b/README_es_ES.md index fa7ba3c..44a34a1 100644 --- a/README_es_ES.md +++ b/README_es_ES.md @@ -13,7 +13,7 @@ Ejecuta `./extract_assets.py --clean && make clean` o `make distclean` para borr * Opción para desactivar el límite de distancia de renderizado. (Se activa con `make NODRAWINGDISTANCE=1`.) * Configurar los controles desde el juego. * Posibilidad de saltarte la intro con la opción de línea de comandos `--skip-intro` - * Menú de trucos, al cual se accede a través del menú "Options". Ten en cuenta que si un cheat te pide pulsar el botón "L", se refiere al botón de N64, el cual tendrá que estar asignado a un botón de tu mando. Ve a los ajustes de control y asegúrate de que tienes "L" mapeado a un botón de tu mando. + * Menú de trucos (_cheats_) en _options_. (Se activa con la opción de línea de comandos `--cheats`) Ten en cuenta que si un cheat te pide pulsar el botón "L", se refiere al botón de N64, el cual tendrá que estar asignado a un botón de tu mando. Ve a los ajustes de control y asegúrate de que tienes "L" mapeado a un botón de tu mando. ## Compilar en Windows **No intentes compilar ejecutables para Windows bajo Linux usando `WINDOWS_BUILD=1`. No va a funcionar. Sigue la guía.** From c18e70f44eaf628f5795002c29166bbfc4835238 Mon Sep 17 00:00:00 2001 From: fgsfds Date: Tue, 19 May 2020 02:38:59 +0300 Subject: [PATCH 21/30] Revert "Merge branch 'nightly' into master" This reverts commit 2e8a821fa3c48df20223312df815d4d41b34b1c9, reversing changes made to d499f5540291020e2eeed6053a9e06f7d80e960c. --- bin/segment2.c | 4 ++-- include/text_strings.h.in | 2 ++ src/game/options_menu.c | 27 ++++++++++++++++++------- src/pc/configfile.c | 4 +++- src/pc/configfile.h | 3 ++- src/pc/gfx/gfx_sdl2.c | 42 ++++++++++++--------------------------- 6 files changed, 42 insertions(+), 40 deletions(-) diff --git a/bin/segment2.c b/bin/segment2.c index 5d5398a..d7e807f 100644 --- a/bin/segment2.c +++ b/bin/segment2.c @@ -2107,7 +2107,7 @@ const Gfx dl_hud_img_load_tex_block[] = { gsDPSetTile(G_IM_FMT_RGBA, G_IM_SIZ_16b, 0, 0, G_TX_LOADTILE, 0, G_TX_WRAP | G_TX_NOMIRROR, 4, G_TX_NOLOD, G_TX_WRAP | G_TX_NOMIRROR, 4, G_TX_NOLOD), gsDPLoadSync(), gsDPLoadBlock(G_TX_LOADTILE, 0, 0, 16 * 16 - 1, CALC_DXT(16, G_IM_SIZ_16b_BYTES)), - gsDPSetTile(G_IM_FMT_RGBA, G_IM_SIZ_16b, 4, 0, G_TX_RENDERTILE, 0, G_TX_CLAMP, 4, G_TX_NOLOD, G_TX_CLAMP, 4, G_TX_NOLOD), + gsDPSetTile(G_IM_FMT_RGBA, G_IM_SIZ_16b, 4, 0, G_TX_RENDERTILE, 0, G_TX_WRAP | G_TX_NOMIRROR, 4, G_TX_NOLOD, G_TX_WRAP | G_TX_NOMIRROR, 4, G_TX_NOLOD), gsDPSetTileSize(0, 0, 0, (16 - 1) << G_TEXTURE_IMAGE_FRAC, (16 - 1) << G_TEXTURE_IMAGE_FRAC), gsSPEndDisplayList(), }; @@ -2144,7 +2144,7 @@ const Gfx dl_rgba16_load_tex_block[] = { gsDPSetTile(G_IM_FMT_RGBA, G_IM_SIZ_16b, 0, 0, G_TX_LOADTILE, 0, G_TX_WRAP | G_TX_NOMIRROR, 4, G_TX_NOLOD, G_TX_WRAP | G_TX_NOMIRROR, 4, G_TX_NOLOD), gsDPLoadSync(), gsDPLoadBlock(G_TX_LOADTILE, 0, 0, 16 * 16 - 1, CALC_DXT(16, G_IM_SIZ_16b_BYTES)), - gsDPSetTile(G_IM_FMT_RGBA, G_IM_SIZ_16b, 4, 0, G_TX_RENDERTILE, 0, G_TX_CLAMP, 4, G_TX_NOLOD, G_TX_CLAMP, 4, G_TX_NOLOD), + gsDPSetTile(G_IM_FMT_RGBA, G_IM_SIZ_16b, 4, 0, G_TX_RENDERTILE, 0, G_TX_WRAP | G_TX_NOMIRROR, 4, G_TX_NOLOD, G_TX_WRAP | G_TX_NOMIRROR, 4, G_TX_NOLOD), gsDPSetTileSize(0, 0, 0, (16 - 1) << G_TEXTURE_IMAGE_FRAC, (16 - 1) << G_TEXTURE_IMAGE_FRAC), gsSPEndDisplayList(), }; diff --git a/include/text_strings.h.in b/include/text_strings.h.in index 0617369..b77a51c 100644 --- a/include/text_strings.h.in +++ b/include/text_strings.h.in @@ -27,6 +27,8 @@ #define TEXT_OPT_NEAREST _("Nearest") #define TEXT_OPT_LINEAR _("Linear") #define TEXT_OPT_MVOLUME _("Master Volume") +#define TEXT_OPT_VSYNC _("Vertical Sync") +#define TEXT_OPT_DOUBLE _("Double") #define TEXT_RESET_WINDOW _("Reset Window") #define TEXT_OPT_UNBOUND _("NONE") diff --git a/src/game/options_menu.c b/src/game/options_menu.c index 58b7d05..d23223b 100644 --- a/src/game/options_menu.c +++ b/src/game/options_menu.c @@ -72,7 +72,9 @@ static const u8 optsVideoStr[][32] = { { TEXT_OPT_TEXFILTER }, { TEXT_OPT_NEAREST }, { TEXT_OPT_LINEAR }, - { TEXT_RESET_WINDOW } + { TEXT_RESET_WINDOW }, + { TEXT_OPT_VSYNC }, + { TEXT_OPT_DOUBLE }, }; static const u8 optsAudioStr[][32] = { @@ -112,6 +114,12 @@ static const u8 *filterChoices[] = { optsVideoStr[3], }; +static const u8 *vsyncChoices[] = { + toggleStr[0], + toggleStr[1], + optsVideoStr[6], +}; + enum OptType { OPT_INVALID = 0, OPT_TOGGLE, @@ -178,8 +186,12 @@ static void optmenu_act_exit(UNUSED struct Option *self, s32 arg) { if (!arg) game_exit(); // only exit on A press and not directions } -static void optvide_reset_window(UNUSED struct Option *self, s32 arg) { - if (!arg) configWindow.reset = true;; // Restrict reset to A press and not directions +static void optvideo_reset_window(UNUSED struct Option *self, s32 arg) { + if (!arg) { + // Restrict reset to A press and not directions + configWindow.reset = true; + configWindow.settings_changed = true; + } } /* submenu option lists */ @@ -217,8 +229,9 @@ static struct Option optsControls[] = { static struct Option optsVideo[] = { DEF_OPT_TOGGLE( optsVideoStr[0], &configWindow.fullscreen ), + DEF_OPT_CHOICE( optsVideoStr[5], &configWindow.vsync, vsyncChoices ), DEF_OPT_CHOICE( optsVideoStr[1], &configFiltering, filterChoices ), - DEF_OPT_BUTTON( optsVideoStr[4], optvide_reset_window ), + DEF_OPT_BUTTON( optsVideoStr[4], optvideo_reset_window ), }; static struct Option optsAudio[] = { @@ -230,8 +243,8 @@ static struct Option optsCheats[] = { DEF_OPT_TOGGLE( optsCheatsStr[1], &Cheats.MoonJump ), DEF_OPT_TOGGLE( optsCheatsStr[2], &Cheats.GodMode ), DEF_OPT_TOGGLE( optsCheatsStr[3], &Cheats.InfiniteLives ), - DEF_OPT_TOGGLE( optsCheatsStr[4], &Cheats.SuperSpeed), - DEF_OPT_TOGGLE( optsCheatsStr[5], &Cheats.Responsive), + DEF_OPT_TOGGLE( optsCheatsStr[4], &Cheats.SuperSpeed ), + DEF_OPT_TOGGLE( optsCheatsStr[5], &Cheats.Responsive ), }; @@ -243,7 +256,7 @@ static struct SubMenu menuCamera = DEF_SUBMENU( menuStr[4], optsCamera ); static struct SubMenu menuControls = DEF_SUBMENU( menuStr[5], optsControls ); static struct SubMenu menuVideo = DEF_SUBMENU( menuStr[6], optsVideo ); static struct SubMenu menuAudio = DEF_SUBMENU( menuStr[7], optsAudio ); -static struct SubMenu menuCheats = DEF_SUBMENU( menuStr[9], optsCheats ); +static struct SubMenu menuCheats = DEF_SUBMENU( menuStr[9], optsCheats ); /* main options menu definition */ diff --git a/src/pc/configfile.c b/src/pc/configfile.c index 0b6fe37..ce9a08a 100644 --- a/src/pc/configfile.c +++ b/src/pc/configfile.c @@ -40,10 +40,11 @@ ConfigWindow configWindow = { .y = SDL_WINDOWPOS_CENTERED, .w = DESIRED_SCREEN_WIDTH, .h = DESIRED_SCREEN_HEIGHT, + .vsync = 1, .reset = false, - .vsync = false, .fullscreen = false, .exiting_fullscreen = false, + .settings_changed = false, }; unsigned int configFiltering = 1; // 0=force nearest, 1=linear, (TODO) 2=three-point unsigned int configMasterVolume = MAX_VOLUME; // 0 - MAX_VOLUME @@ -84,6 +85,7 @@ static const struct ConfigOption options[] = { {.name = "window_y", .type = CONFIG_TYPE_UINT, .uintValue = &configWindow.y}, {.name = "window_w", .type = CONFIG_TYPE_UINT, .uintValue = &configWindow.w}, {.name = "window_h", .type = CONFIG_TYPE_UINT, .uintValue = &configWindow.h}, + {.name = "vsync", .type = CONFIG_TYPE_UINT, .uintValue = &configWindow.vsync}, {.name = "texture_filtering", .type = CONFIG_TYPE_UINT, .uintValue = &configFiltering}, {.name = "master_volume", .type = CONFIG_TYPE_UINT, .uintValue = &configMasterVolume}, {.name = "key_a", .type = CONFIG_TYPE_BIND, .uintValue = configKeyA}, diff --git a/src/pc/configfile.h b/src/pc/configfile.h index 01d657c..cafd272 100644 --- a/src/pc/configfile.h +++ b/src/pc/configfile.h @@ -11,10 +11,11 @@ typedef struct { unsigned int x, y, w, h; + unsigned int vsync; bool reset; - bool vsync; bool fullscreen; bool exiting_fullscreen; + bool settings_changed; } ConfigWindow; extern ConfigWindow configWindow; diff --git a/src/pc/gfx/gfx_sdl2.c b/src/pc/gfx/gfx_sdl2.c index 6ff6906..e86a100 100644 --- a/src/pc/gfx/gfx_sdl2.c +++ b/src/pc/gfx/gfx_sdl2.c @@ -39,9 +39,12 @@ # define FRAMERATE 30 #endif +static const Uint32 FRAME_TIME = 1000 / FRAMERATE; + static SDL_Window *wnd; static SDL_GLContext ctx = NULL; static int inverted_scancode_table[512]; +static Uint32 frame_start = 0; const SDL_Scancode windows_scancode_table[] = { @@ -110,9 +113,9 @@ static void gfx_sdl_set_fullscreen() { } static void gfx_sdl_reset_dimension_and_pos() { - if (configWindow.exiting_fullscreen) + if (configWindow.exiting_fullscreen) { configWindow.exiting_fullscreen = false; - else if (configWindow.reset) { + } else if (configWindow.reset) { configWindow.x = SDL_WINDOWPOS_CENTERED; configWindow.y = SDL_WINDOWPOS_CENTERED; configWindow.w = DESIRED_SCREEN_WIDTH; @@ -123,29 +126,14 @@ static void gfx_sdl_reset_dimension_and_pos() { configWindow.fullscreen = false; return; } - } else + } else if (!configWindow.settings_changed) { return; + } + configWindow.settings_changed = false; SDL_SetWindowSize(wnd, configWindow.w, configWindow.h); SDL_SetWindowPosition(wnd, configWindow.x, configWindow.y); -} - -static bool test_vsync(void) { - // Even if SDL_GL_SetSwapInterval succeeds, it doesn't mean that VSync actually works. - // A 60 Hz monitor should have a swap interval of 16.67 milliseconds. - // If it takes less than 12 milliseconds, assume that VSync is not working. - // SDL_GetTicks() probably does not offer enough precision for this kind of shit. - Uint32 start, end; - - // do an extra swap, sometimes the first one takes longer (maybe creates buffers?) - SDL_GL_SwapWindow(wnd); - - SDL_GL_SwapWindow(wnd); - start = SDL_GetTicks(); - SDL_GL_SwapWindow(wnd); - end = SDL_GetTicks(); - - return (end - start >= 12); + SDL_GL_SetSwapInterval(configWindow.vsync); // in case vsync changed } static void gfx_sdl_init(void) { @@ -165,11 +153,9 @@ static void gfx_sdl_init(void) { if (gCLIOpts.FullScreen == 1) configWindow.fullscreen = true; - - if (gCLIOpts.FullScreen == 2) + else if (gCLIOpts.FullScreen == 2) configWindow.fullscreen = false; - const char* window_title = #ifndef USE_GLES "Super Mario 64 PC port (OpenGL)"; @@ -183,14 +169,11 @@ static void gfx_sdl_init(void) { SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE ); ctx = SDL_GL_CreateContext(wnd); - SDL_GL_SetSwapInterval(2); + + SDL_GL_SetSwapInterval(configWindow.vsync); gfx_sdl_set_fullscreen(); - configWindow.vsync = test_vsync(); - if (!configWindow.vsync) - printf("Warning: VSync is not enabled or not working. Falling back to timer for synchronization\n"); - for (size_t i = 0; i < sizeof(windows_scancode_table) / sizeof(SDL_Scancode); i++) { inverted_scancode_table[windows_scancode_table[i]] = i; } @@ -281,6 +264,7 @@ static void gfx_sdl_handle_events(void) { } static bool gfx_sdl_start_frame(void) { + frame_start = SDL_GetTicks(); return true; } From 1046cc1301314a029c44edf6902bff7166f36e1b Mon Sep 17 00:00:00 2001 From: fgsfds Date: Mon, 18 May 2020 22:38:19 +0300 Subject: [PATCH 22/30] Merge pull request #179 from dernett/fix-fullscreen-text Fix fullscreen text --- bin/segment2.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/segment2.c b/bin/segment2.c index d7e807f..5d5398a 100644 --- a/bin/segment2.c +++ b/bin/segment2.c @@ -2107,7 +2107,7 @@ const Gfx dl_hud_img_load_tex_block[] = { gsDPSetTile(G_IM_FMT_RGBA, G_IM_SIZ_16b, 0, 0, G_TX_LOADTILE, 0, G_TX_WRAP | G_TX_NOMIRROR, 4, G_TX_NOLOD, G_TX_WRAP | G_TX_NOMIRROR, 4, G_TX_NOLOD), gsDPLoadSync(), gsDPLoadBlock(G_TX_LOADTILE, 0, 0, 16 * 16 - 1, CALC_DXT(16, G_IM_SIZ_16b_BYTES)), - gsDPSetTile(G_IM_FMT_RGBA, G_IM_SIZ_16b, 4, 0, G_TX_RENDERTILE, 0, G_TX_WRAP | G_TX_NOMIRROR, 4, G_TX_NOLOD, G_TX_WRAP | G_TX_NOMIRROR, 4, G_TX_NOLOD), + gsDPSetTile(G_IM_FMT_RGBA, G_IM_SIZ_16b, 4, 0, G_TX_RENDERTILE, 0, G_TX_CLAMP, 4, G_TX_NOLOD, G_TX_CLAMP, 4, G_TX_NOLOD), gsDPSetTileSize(0, 0, 0, (16 - 1) << G_TEXTURE_IMAGE_FRAC, (16 - 1) << G_TEXTURE_IMAGE_FRAC), gsSPEndDisplayList(), }; @@ -2144,7 +2144,7 @@ const Gfx dl_rgba16_load_tex_block[] = { gsDPSetTile(G_IM_FMT_RGBA, G_IM_SIZ_16b, 0, 0, G_TX_LOADTILE, 0, G_TX_WRAP | G_TX_NOMIRROR, 4, G_TX_NOLOD, G_TX_WRAP | G_TX_NOMIRROR, 4, G_TX_NOLOD), gsDPLoadSync(), gsDPLoadBlock(G_TX_LOADTILE, 0, 0, 16 * 16 - 1, CALC_DXT(16, G_IM_SIZ_16b_BYTES)), - gsDPSetTile(G_IM_FMT_RGBA, G_IM_SIZ_16b, 4, 0, G_TX_RENDERTILE, 0, G_TX_WRAP | G_TX_NOMIRROR, 4, G_TX_NOLOD, G_TX_WRAP | G_TX_NOMIRROR, 4, G_TX_NOLOD), + gsDPSetTile(G_IM_FMT_RGBA, G_IM_SIZ_16b, 4, 0, G_TX_RENDERTILE, 0, G_TX_CLAMP, 4, G_TX_NOLOD, G_TX_CLAMP, 4, G_TX_NOLOD), gsDPSetTileSize(0, 0, 0, (16 - 1) << G_TEXTURE_IMAGE_FRAC, (16 - 1) << G_TEXTURE_IMAGE_FRAC), gsSPEndDisplayList(), }; From e97d25c2c67b318f53dca32fce8a114e36a48920 Mon Sep 17 00:00:00 2001 From: "U-ALTTP-PC\\ALTTP" Date: Tue, 19 May 2020 03:24:51 -0300 Subject: [PATCH 23/30] option to hide the hud --- include/text_strings.h.in | 1 + src/game/hud.c | 14 ++++++++------ src/game/options_menu.c | 2 ++ src/pc/configfile.c | 1 + src/pc/configfile.h | 1 + 5 files changed, 13 insertions(+), 6 deletions(-) diff --git a/include/text_strings.h.in b/include/text_strings.h.in index 9b70acf..d4ec173 100644 --- a/include/text_strings.h.in +++ b/include/text_strings.h.in @@ -30,6 +30,7 @@ #define TEXT_OPT_VSYNC _("Vertical Sync") #define TEXT_OPT_DOUBLE _("Double") #define TEXT_RESET_WINDOW _("Reset Window") +#define TEXT_OPT_HUD _("HUD") #define TEXT_OPT_UNBOUND _("NONE") #define TEXT_OPT_PRESSKEY _("...") diff --git a/src/game/hud.c b/src/game/hud.c index 277806b..cf3dee0 100644 --- a/src/game/hud.c +++ b/src/game/hud.c @@ -1,4 +1,5 @@ #include +#include #include "sm64.h" #include "gfx_dimensions.h" @@ -56,6 +57,7 @@ static struct UnusedHUDStruct sUnusedHUDValues = { 0x00, 0x0A, 0x00 }; static struct CameraHUD sCameraHUD = { CAM_STATUS_NONE }; +extern bool configHUD; /** * Renders a rgba16 16x16 glyph texture from a table list. */ @@ -450,28 +452,28 @@ void render_hud(void) { render_hud_cannon_reticle(); } - if (hudDisplayFlags & HUD_DISPLAY_FLAG_LIVES) { + if (hudDisplayFlags & HUD_DISPLAY_FLAG_LIVES && configHUD) { render_hud_mario_lives(); } - if (hudDisplayFlags & HUD_DISPLAY_FLAG_COIN_COUNT) { + if (hudDisplayFlags & HUD_DISPLAY_FLAG_COIN_COUNT && configHUD) { render_hud_coins(); } - if (hudDisplayFlags & HUD_DISPLAY_FLAG_STAR_COUNT) { + if (hudDisplayFlags & HUD_DISPLAY_FLAG_STAR_COUNT && configHUD) { render_hud_stars(); } - if (hudDisplayFlags & HUD_DISPLAY_FLAG_KEYS) { + if (hudDisplayFlags & HUD_DISPLAY_FLAG_KEYS && configHUD) { render_hud_keys(); } - if (hudDisplayFlags & HUD_DISPLAY_FLAG_CAMERA_AND_POWER) { + if (hudDisplayFlags & HUD_DISPLAY_FLAG_CAMERA_AND_POWER && configHUD) { render_hud_power_meter(); render_hud_camera_status(); } - if (hudDisplayFlags & HUD_DISPLAY_FLAG_TIMER) { + if (hudDisplayFlags & HUD_DISPLAY_FLAG_TIMER && configHUD) { render_hud_timer(); } } diff --git a/src/game/options_menu.c b/src/game/options_menu.c index ab7da29..37b1a5a 100644 --- a/src/game/options_menu.c +++ b/src/game/options_menu.c @@ -75,6 +75,7 @@ static const u8 optsVideoStr[][32] = { { TEXT_RESET_WINDOW }, { TEXT_OPT_VSYNC }, { TEXT_OPT_DOUBLE }, + { TEXT_OPT_HUD }, }; static const u8 optsAudioStr[][32] = { @@ -235,6 +236,7 @@ static struct Option optsVideo[] = { DEF_OPT_CHOICE( optsVideoStr[5], &configWindow.vsync, vsyncChoices ), DEF_OPT_CHOICE( optsVideoStr[1], &configFiltering, filterChoices ), DEF_OPT_BUTTON( optsVideoStr[4], optvideo_reset_window ), + DEF_OPT_TOGGLE( optsVideoStr[7], &configHUD ), }; static struct Option optsAudio[] = { diff --git a/src/pc/configfile.c b/src/pc/configfile.c index ce9a08a..2621130 100644 --- a/src/pc/configfile.c +++ b/src/pc/configfile.c @@ -78,6 +78,7 @@ bool configEnableCamera = false; bool configCameraMouse = false; #endif unsigned int configSkipIntro = 0; +bool configHUD = true; static const struct ConfigOption options[] = { {.name = "fullscreen", .type = CONFIG_TYPE_BOOL, .boolValue = &configWindow.fullscreen}, diff --git a/src/pc/configfile.h b/src/pc/configfile.h index cafd272..17a7e25 100644 --- a/src/pc/configfile.h +++ b/src/pc/configfile.h @@ -46,6 +46,7 @@ extern bool configCameraInvertY; extern bool configEnableCamera; extern bool configCameraMouse; #endif +extern bool configHUD; void configfile_load(const char *filename); void configfile_save(const char *filename); From ee795fa7af4baf6118004fda6d9b02fb44a1c6dc Mon Sep 17 00:00:00 2001 From: yksoft1 Date: Tue, 19 May 2020 20:15:25 +0800 Subject: [PATCH 24/30] My hacks to cliopts.h is not necessary anymore. --- src/pc/cliopts.h | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/pc/cliopts.h b/src/pc/cliopts.h index 75d78e8..d20dcb4 100644 --- a/src/pc/cliopts.h +++ b/src/pc/cliopts.h @@ -1,13 +1,14 @@ -#include -#include "sm64.h" +#ifndef _CLIOPTS_H +#define _CLIOPTS_H -struct PCCLIOptions -{ - u8 SkipIntro; - u8 FullScreen; - char * ConfigFile; +struct PCCLIOptions { + unsigned int SkipIntro; + unsigned int FullScreen; + char ConfigFile[1024]; }; extern struct PCCLIOptions gCLIOpts; void parse_cli_opts(int argc, char* argv[]); + +#endif // _CLIOPTS_H From 5cb3bfd2f6e66cabdd703b2e648b5cc1413adb83 Mon Sep 17 00:00:00 2001 From: yksoft1 Date: Tue, 19 May 2020 20:39:01 +0800 Subject: [PATCH 25/30] Fix types.h include guard to avoid any conflict with . --- include/types.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/types.h b/include/types.h index 483c894..870223e 100644 --- a/include/types.h +++ b/include/types.h @@ -1,5 +1,5 @@ -#ifndef _TYPES_H_ -#define _TYPES_H_ +#ifndef _SM64_TYPES_H_ +#define _SM64_TYPES_H_ // This file contains various data types used in Super Mario 64 that don't yet // have an appropriate header. From b0081e8d608451380913e02c9f1aebc3c5bf85bb Mon Sep 17 00:00:00 2001 From: Colton Rushton Date: Tue, 19 May 2020 10:14:44 -0300 Subject: [PATCH 26/30] Refactor PR #151 --- include/libc/stdlib.h | 8 ++++++++ src/engine/math_util.h | 4 ++++ src/game/mario_actions_cutscene.c | 1 - src/game/options_menu.c | 1 + 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/include/libc/stdlib.h b/include/libc/stdlib.h index c23b454..783ccf5 100644 --- a/include/libc/stdlib.h +++ b/include/libc/stdlib.h @@ -1,6 +1,8 @@ #ifndef STDLIB_H #define STDLIB_H +#ifndef TARGET_WEB + typedef struct lldiv_t { long long quot; @@ -16,4 +18,10 @@ typedef struct ldiv_t lldiv_t lldiv(long long num, long long denom); ldiv_t ldiv(long num, long denom); +#else + +#include + +#endif + #endif diff --git a/src/engine/math_util.h b/src/engine/math_util.h index b8b7f1b..99727a7 100644 --- a/src/engine/math_util.h +++ b/src/engine/math_util.h @@ -29,7 +29,11 @@ extern f32 gCosineTable[]; #define sqr(x) ((x) * (x)) +#ifndef TARGET_WEB #define abs(x) ((x) < 0 ? -(x) : (x)) +#else +#include "../../include/libc/stdlib.h" +#endif void *vec3f_copy(Vec3f dest, Vec3f src); void *vec3f_set(Vec3f dest, f32 x, f32 y, f32 z); diff --git a/src/game/mario_actions_cutscene.c b/src/game/mario_actions_cutscene.c index 6c3a8b0..ef413cd 100644 --- a/src/game/mario_actions_cutscene.c +++ b/src/game/mario_actions_cutscene.c @@ -3,7 +3,6 @@ #include "prevent_bss_reordering.h" #include "sm64.h" #include "gfx_dimensions.h" -//#include "game.h" #include "game_init.h" #include "sound_init.h" #include "level_update.h" diff --git a/src/game/options_menu.c b/src/game/options_menu.c index ab7da29..b5dbfed 100644 --- a/src/game/options_menu.c +++ b/src/game/options_menu.c @@ -23,6 +23,7 @@ #include "pc/controller/controller_api.h" #include +#include "../../include/libc/stdlib.h" u8 optmenu_open = 0; From 9230cb832dbb6646d9bedcd924164f135d249a1d Mon Sep 17 00:00:00 2001 From: Colton Rushton Date: Tue, 19 May 2020 10:32:01 -0300 Subject: [PATCH 27/30] Refactor PR #156 --- Makefile | 35 ++++++++++++++++++++++++++++------- include/PR/os_libc.h | 2 +- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 6767bf8..598320e 100644 --- a/Makefile +++ b/Makefile @@ -35,18 +35,33 @@ NODRAWINGDISTANCE ?= 0 TEXTURE_FIX ?= 0 # Enable extended options menu by default EXT_OPTIONS_MENU ?= 1 +# Disable no bzero/bcopy workaround by default +# Enable by default for MXE builds +ifeq ($(WINDOWS_BUILD),1) + ifeq ($(CROSS),i686-w64-mingw32.static-) + NO_BZERO_BCOPY := 1 + else ifeq ($(CROSS),x86_64-w64-mingw32.static-) + NO_BZERO_BCOPY := 1 + else + NO_BZERO_BCOPY ?= 0 + endif +else + NO_BZERO_BCOPY ?= 0 +endif # Build for Emscripten/WebGL TARGET_WEB ?= 0 # Specify the target you are building for, 0 means native -TARGET_ARCH ?= native - -ifeq ($(CROSS),i686-w64-mingw32.static-) - TARGET_ARCH = i386pe -else ifeq ($(CROSS),x86_64-w64-mingw32.static-) - TARGET_ARCH = i386pe +ifeq ($(WINDOWS_BUILD),1) + ifeq ($(CROSS),i686-w64-mingw32.static-) + TARGET_ARCH = i386pe + else ifeq ($(CROSS),x86_64-w64-mingw32.static-) + TARGET_ARCH = i386pe + else + TARGET_ARCH ?= native + endif else - TARGET_ARCH = native + TARGET_ARCH ?= native endif TARGET_BITS ?= 0 @@ -508,6 +523,12 @@ ifeq ($(EXT_OPTIONS_MENU),1) CFLAGS += -DEXT_OPTIONS_MENU endif +# Check for no bzero/bcopy workaround option +ifeq ($(NO_BZERO_BCOPY),1) + CC_CHECK += -DNO_BZERO_BCOPY + CFLAGS += -DNO_BZERO_BCOPY +endif + ASFLAGS := -I include -I $(BUILD_DIR) $(VERSION_ASFLAGS) ifeq ($(TARGET_WEB),1) diff --git a/include/PR/os_libc.h b/include/PR/os_libc.h index e756751..9eb872e 100644 --- a/include/PR/os_libc.h +++ b/include/PR/os_libc.h @@ -10,7 +10,7 @@ // macOS libc has them #include -#elif defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200809L) +#elif defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200809L) || defined(NO_BZERO_BCOPY) // there's no way that shit's defined, use memcpy/memset #include From 41828987f27ff28112e51367a018fdd913cf48e4 Mon Sep 17 00:00:00 2001 From: Colton Rushton Date: Tue, 19 May 2020 10:38:08 -0300 Subject: [PATCH 28/30] Made the game even easier to compile in MXE. --- Makefile | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 598320e..361e826 100644 --- a/Makefile +++ b/Makefile @@ -64,7 +64,17 @@ else TARGET_ARCH ?= native endif -TARGET_BITS ?= 0 +ifeq ($(WINDOWS_BUILD),1) + ifeq ($(CROSS),i686-w64-mingw32.static-) + TARGET_BITS = 32 + else ifeq ($(CROSS),x86_64-w64-mingw32.static-) + TARGET_BITS = 64 + else + TARGET_BITS ?= 0 + endif +else + TARGET_BITS ?= 0 +endif ifneq ($(TARGET_BITS),0) BITS := -m$(TARGET_BITS) From 08ad740b1cb85b387ff92e2561430d4bac351ca6 Mon Sep 17 00:00:00 2001 From: Colton Rushton Date: Tue, 19 May 2020 10:51:49 -0300 Subject: [PATCH 29/30] Refactor PR #176 --- src/game/bettercamera.inc.h | 4 ++-- src/pc/configfile.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/game/bettercamera.inc.h b/src/game/bettercamera.inc.h index f585447..7d0175b 100644 --- a/src/game/bettercamera.inc.h +++ b/src/game/bettercamera.inc.h @@ -216,9 +216,9 @@ static int ivrt(u8 axis) if (axis == 0) { if (newcam_invertX == 0) - return 1; - else return -1; + else + return 1; } else { diff --git a/src/pc/configfile.c b/src/pc/configfile.c index ce9a08a..c4bf889 100644 --- a/src/pc/configfile.c +++ b/src/pc/configfile.c @@ -72,7 +72,7 @@ unsigned int configCameraYSens = 50; unsigned int configCameraAggr = 0; unsigned int configCameraPan = 0; unsigned int configCameraDegrade = 10; // 0 - 100% -bool configCameraInvertX = false; +bool configCameraInvertX = true; bool configCameraInvertY = false; bool configEnableCamera = false; bool configCameraMouse = false; From 2904658341603120e675eaad7179f468d9dd9542 Mon Sep 17 00:00:00 2001 From: "Colton G. Rushton" Date: Tue, 19 May 2020 11:04:46 -0300 Subject: [PATCH 30/30] Add MSYS2 build fix/simplification Adds the CFLAG normally added during building in MSYS2 to make MSYS2 builds easier to perform. --- tools/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/Makefile b/tools/Makefile index 1809ab9..0d8e6dd 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -30,7 +30,7 @@ aifc_decode_CFLAGS := -O2 # both runs and compiles faster than -O3 aiff_extract_codebook_SOURCES := aiff_extract_codebook.c tabledesign_SOURCES := sdk-tools/tabledesign/codebook.c sdk-tools/tabledesign/estimate.c sdk-tools/tabledesign/print.c sdk-tools/tabledesign/tabledesign.c -tabledesign_CFLAGS := -Wno-uninitialized -laudiofile +tabledesign_CFLAGS := -Wno-uninitialized -laudiofile -lstdc++ vadpcm_enc_SOURCES := sdk-tools/adpcm/vadpcm_enc.c sdk-tools/adpcm/vpredictor.c sdk-tools/adpcm/quant.c sdk-tools/adpcm/util.c sdk-tools/adpcm/vencode.c vadpcm_enc_CFLAGS := -Wno-unused-result -Wno-uninitialized -Wno-sign-compare -Wno-absolute-value