From e65d27d075db279cf04c688da9662012f25cf5d2 Mon Sep 17 00:00:00 2001 From: Tyler Wilding Date: Mon, 14 Mar 2022 00:20:05 -0400 Subject: [PATCH 01/12] cmake: reduce warning spam especially from libs --- CMakeLists.txt | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ce7fd8bd03..fd4a2f149a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,7 +19,7 @@ if(MSVC AND (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")) -Xclang -std=c++17 \ -Xclang -D_CRT_SECURE_NO_WARNINGS \ -mavx \ - -Wno-c++11-narrowing -W3") + -Wno-c++11-narrowing -Wno-c++98-compat -W3") # additional c++ flags for release mode for our projects if(CMAKE_BUILD_TYPE MATCHES "Release") @@ -80,23 +80,8 @@ if(ASAN_BUILD) message(STATUS "Doing ASAN build") endif() -# if(WIN32) -# find_program(buildcache_program buildcache ${PROJECT_SOURCE_DIR}/bin/windows/) -# if(buildcache_program) -# message("Found Windows BuildCache, gonna use it!") -# set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${buildcache_program}") -# else() -# message("Windows Buildcache not found!") -# endif() -# else() -# find_program(buildcache_program buildcache ${PROJECT_SOURCE_DIR}/bin/linux/) -# if(buildcache_program) -# message("Found Linux BuildCache, gonna use it!") -# set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${buildcache_program}") -# else() -# message("Linux Buildcache not found!") -# endif() -# endif() +# preserve CXX Flags +set(SAVE_CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) option(CODE_COVERAGE "Enable Code Coverage Compiler Flags" OFF) set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/third-party/cmake/modules/) @@ -125,14 +110,16 @@ add_subdirectory(common) add_subdirectory(decompiler) # build glfw library +string(REPLACE " -W3" " -W0" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") +string(REPLACE " -Wall" " -w" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") add_subdirectory(third-party/glfw) - add_subdirectory(third-party/zstd) # build imgui include_directories(third-party/glad/include) include_directories(third-party/glfw/include) add_subdirectory(third-party/imgui) +set(CMAKE_CXX_FLAGS "${SAVE_CMAKE_CXX_FLAGS}") # build the game code in C++ add_subdirectory(game) @@ -147,18 +134,22 @@ add_subdirectory(tools) if(WIN32) set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) endif() +string(REPLACE " -W3" " -W0" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") +string(REPLACE " -Wall" " -w" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") add_subdirectory(third-party/googletest EXCLUDE_FROM_ALL) include(GoogleTest) +set(CMAKE_CXX_FLAGS "${SAVE_CMAKE_CXX_FLAGS}") # build tests include(test/CMakeLists.txt) # build lzokay library +string(REPLACE " -W3" " -W0" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") +string(REPLACE " -Wall" " -w" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") add_subdirectory(third-party/lzokay EXCLUDE_FROM_ALL) # build format library add_subdirectory(third-party/fmt EXCLUDE_FROM_ALL) - # discord rich presence include_directories(third-party/discord-rpc/include) add_subdirectory(third-party/discord-rpc EXCLUDE_FROM_ALL) @@ -170,8 +161,9 @@ option(ZYDIS_BUILD_EXAMPLES "Zydis: Build examples" OFF) option(ZYDIS_BUILD_SHARED_LIB "Zydis: Build shared library" ON) add_subdirectory(third-party/zydis EXCLUDE_FROM_ALL) - # windows memory management lib if(WIN32) add_subdirectory(third-party/mman) endif() + +set(CMAKE_CXX_FLAGS "${SAVE_CMAKE_CXX_FLAGS}") From 06a2b52ee8bbf533e9eeaad3fccf8c1c287e5213 Mon Sep 17 00:00:00 2001 From: Tyler Wilding Date: Mon, 14 Mar 2022 00:30:57 -0400 Subject: [PATCH 02/12] runtime: add FS helper functions --- common/util/FileUtil.cpp | 19 ++++++++++++++++--- common/util/FileUtil.h | 1 + game/kernel/kmachine.cpp | 28 ++++++++++++++++++++++++++++ goal_src/kernel-defs.gc | 6 ++++++ 4 files changed, 51 insertions(+), 3 deletions(-) diff --git a/common/util/FileUtil.cpp b/common/util/FileUtil.cpp index 96c9b93306..73f3dcd5f1 100644 --- a/common/util/FileUtil.cpp +++ b/common/util/FileUtil.cpp @@ -43,6 +43,11 @@ std::filesystem::path get_user_home_dir() { #endif } +std::filesystem::path get_user_game_dir() { + // TODO - i anticipate UTF-8 problems on windows with our current FS api + return get_user_home_dir() / "OpenGOAL"; +} + std::string get_project_path() { #ifdef _WIN32 char buffer[FILENAME_MAX]; @@ -66,6 +71,14 @@ std::string get_project_path() { } std::string get_file_path(const std::vector& input) { + // TODO - clean this behaviour up, it causes unexpected behaviour when working with files + // the project path should be explicitly provided by whatever if needed + // TEMP HACK + // - if the provided path is absolute, don't add the project path + if (input.size() == 1 && std::filesystem::path(input.at(0)).is_absolute()) { + return input.at(0); + } + std::string currentPath = file_util::get_project_path(); char dirSeparator; @@ -85,10 +98,10 @@ std::string get_file_path(const std::vector& input) { bool create_dir_if_needed(const std::string& path) { if (!std::filesystem::is_directory(path)) { - std::filesystem::create_directories(path); - return true; + return std::filesystem::create_directories(std::filesystem::path(path).parent_path()); + } else { + return std::filesystem::create_directories(path); } - return false; } void write_binary_file(const std::string& name, const void* data, size_t size) { diff --git a/common/util/FileUtil.h b/common/util/FileUtil.h index b34b73ba5c..c8d8905bf6 100644 --- a/common/util/FileUtil.h +++ b/common/util/FileUtil.h @@ -14,6 +14,7 @@ namespace fs = std::filesystem; namespace file_util { std::filesystem::path get_user_home_dir(); +std::filesystem::path get_user_game_dir(); std::string get_project_path(); std::string get_file_path(const std::vector& input); bool create_dir_if_needed(const std::string& path); diff --git a/game/kernel/kmachine.cpp b/game/kernel/kmachine.cpp index b6f8309817..4ed46d79b2 100644 --- a/game/kernel/kmachine.cpp +++ b/game/kernel/kmachine.cpp @@ -28,6 +28,7 @@ #include "game/sce/libpad.h" #include "common/symbols.h" #include "common/log/log.h" +#include "common/util/FileUtil.h" #include "common/util/Timer.h" #include "game/graphics/sceGraphicsInterface.h" #include "game/graphics/gfx.h" @@ -816,6 +817,19 @@ void update_discord_rpc(u32 discord_info) { } } +u64 filepath_exists(u32 filepath) { + auto filepath_str = std::string(Ptr(filepath).c()->data()); + if (file_util::file_exists(filepath_str)) { + return intern_from_c("#t").offset; + } + return intern_from_c("#f").offset; +} + +void mkdir_path(u32 filepath) { + auto filepath_str = std::string(Ptr(filepath).c()->data()); + file_util::create_dir_if_needed(filepath_str); +} + void InitMachine_PCPort() { // PC Port added functions make_function_symbol_from_c("__read-ee-timer", (void*)read_ee_timer); @@ -844,6 +858,10 @@ void InitMachine_PCPort() { make_function_symbol_from_c("pc-set-fullscreen", (void*)Gfx::set_fullscreen); make_function_symbol_from_c("pc-renderer-tree-set-lod", (void*)Gfx::SetLod); + // file related functions + make_function_symbol_from_c("pc-filepath-exists?", (void*)filepath_exists); + make_function_symbol_from_c("pc-mkdir-path", (void*)mkdir_path); + // discord rich presence make_function_symbol_from_c("pc-discord-rpc-set", (void*)set_discord_rpc); make_function_symbol_from_c("pc-discord-rpc-update", (void*)update_discord_rpc); @@ -853,6 +871,16 @@ void InitMachine_PCPort() { make_function_symbol_from_c("vm-ptr", (void*)VM::get_vm_ptr); VM::vm_init(); } + + // setup string constants + auto user_dir_path = file_util::get_user_game_dir(); + intern_from_c("*pc-user-dir-base-path*")->value = + make_string_from_c(user_dir_path.string().c_str()); + // TODO - we will eventually need a better way to know what game we are playing + auto settings_path = std::filesystem::path(user_dir_path) / "jak1" / "settings"; + intern_from_c("*pc-settings-folder*")->value = + make_string_from_c(settings_path.string().c_str()); + } void vif_interrupt_callback() { diff --git a/goal_src/kernel-defs.gc b/goal_src/kernel-defs.gc index b37292c6d7..2e661ce55b 100644 --- a/goal_src/kernel-defs.gc +++ b/goal_src/kernel-defs.gc @@ -335,6 +335,12 @@ (define-extern pc-renderer-tree-set-lod (function pc-renderer-tree-type int none)) (define-extern pc-discord-rpc-update (function discord-info none)) (define-extern pc-discord-rpc-set (function int none)) +(define-extern pc-filepath-exists? (function string symbol)) +(define-extern pc-mkdir-path (function string none)) + +;; Constants generated within the C++ runtime +(define-extern *pc-user-dir-base-path* string) +(define-extern *pc-settings-folder* string) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; vm functions From df9b95f26b2709d5f2ba05c2123e3bcb5a27f108 Mon Sep 17 00:00:00 2001 From: Tyler Wilding Date: Mon, 14 Mar 2022 00:32:01 -0400 Subject: [PATCH 03/12] game: save/restore pc-settings | add original aspect option --- .../jak1_ntsc_black_label/new_strings.jsonc | 3 +- goal_src/engine/game/settings.gc | 5 - goal_src/game.gp | 2 +- .../pc/engine/ui/progress/progress-draw.gc | 26 ++-- .../pc/engine/ui/progress/progress-static.gc | 85 +++++------ goal_src/pc/engine/ui/progress/progress.gc | 142 +++++++++++------- goal_src/pc/engine/ui/text-h.gc | 56 +++---- goal_src/pc/pckernel-h.gc | 36 ++++- goal_src/pc/pckernel.gc | 120 ++++++++++----- 9 files changed, 284 insertions(+), 191 deletions(-) diff --git a/decompiler/config/jak1_ntsc_black_label/new_strings.jsonc b/decompiler/config/jak1_ntsc_black_label/new_strings.jsonc index 8cb290dd67..eed40d182b 100644 --- a/decompiler/config/jak1_ntsc_black_label/new_strings.jsonc +++ b/decompiler/config/jak1_ntsc_black_label/new_strings.jsonc @@ -51,6 +51,7 @@ "1018": ["AUTO"], "1019": ["BORDERLESS"], "1020": ["FULLSCREEN"], - "1021": ["WINDOWED"] + "1021": ["WINDOWED"], + "1049": ["USE ORIGINAL ASPECT"] } } diff --git a/goal_src/engine/game/settings.gc b/goal_src/engine/game/settings.gc index 5f9e45c5b7..f2a9629f09 100644 --- a/goal_src/engine/game/settings.gc +++ b/goal_src/engine/game/settings.gc @@ -449,11 +449,6 @@ (set! (-> gp-0 aspect-ratio) 'aspect4x3) ) ) - (#when PC_PORT - (when (nonzero? (-> *pc-settings* aspect-setting)) - (set! (-> gp-0 aspect-ratio) (-> *pc-settings* aspect-setting)) - ) - ) (if (zero? *boot-video-mode*) (set! (-> gp-0 video-mode) 'ntsc) (set! (-> gp-0 video-mode) 'pal) diff --git a/goal_src/game.gp b/goal_src/game.gp index e5380d6739..b9cd8f4824 100644 --- a/goal_src/game.gp +++ b/goal_src/game.gp @@ -1876,7 +1876,7 @@ ;; Custom or Modified Code (goal-src "pc/pckernel-h.gc" "dma-disasm") -(goal-src "pc/pckernel.gc" "gsound") +(goal-src "pc/pckernel.gc" "settings") (goal-src "pc/subtitle.gc" "text") (goal-src "pc/engine/ui/text-h.gc" "connect") diff --git a/goal_src/pc/engine/ui/progress/progress-draw.gc b/goal_src/pc/engine/ui/progress/progress-draw.gc index 27a40a20e0..44c76589f8 100644 --- a/goal_src/pc/engine/ui/progress/progress-draw.gc +++ b/goal_src/pc/engine/ui/progress/progress-draw.gc @@ -1744,7 +1744,7 @@ (set! sv-128 (+ (the int (* 2.5 (-> (the-as (pointer float) (-> s3-0 s0-0 value-to-modify))))) -100)) sv-128 ) - ((= v1-81 2) + ((or (= v1-81 2) (= v1-81 #x15)) (cond ((-> (the-as (pointer uint32) (-> s3-0 s0-0 value-to-modify))) (set! sv-320 format) @@ -1774,19 +1774,21 @@ ((= v1-81 1) (draw-options-list obj font-ctx s2-1 *language-name-remap*)) ((= v1-81 #x10) - (draw-options-list obj font-ctx s2-1 *pc-graphics-aspect-ratio-mode-remap*)) + (if (-> *pc-settings* use-original-aspect-ratio?) + (draw-options-list obj font-ctx s2-1 *pc-graphics-original-aspect-ratio-mode-remap*) + (draw-options-list obj font-ctx s2-1 *pc-graphics-aspect-ratio-mode-remap*))) ((= v1-81 #x11) (case (-> *pc-settings* aspect-ratio-mode) - (('pc-aspect-4x3) - (draw-options-list obj font-ctx s2-1 *pc-graphics-4x3-valid-resolutions-names*)) - (('pc-aspect-5x4) - (draw-options-list obj font-ctx s2-1 *pc-graphics-5x4-valid-resolutions-names*)) - (('pc-aspect-16x9) - (draw-options-list obj font-ctx s2-1 *pc-graphics-16x9-valid-resolutions-names*)) - (('pc-aspect-21x9) - (draw-options-list obj font-ctx s2-1 *pc-graphics-21x9-valid-resolutions-names*)) - (('pc-aspect-32x9) - (draw-options-list obj font-ctx s2-1 *pc-graphics-32x9-valid-resolutions-names*)))) + (('pc-aspect-4x3 'orig-aspect-4x3) + (draw-options-list obj font-ctx s2-1 *pc-graphics-4x3-valid-resolutions-names*)) + (('pc-aspect-5x4) + (draw-options-list obj font-ctx s2-1 *pc-graphics-5x4-valid-resolutions-names*)) + (('pc-aspect-16x9 'orig-aspect-16x9) + (draw-options-list obj font-ctx s2-1 *pc-graphics-16x9-valid-resolutions-names*)) + (('pc-aspect-21x9) + (draw-options-list obj font-ctx s2-1 *pc-graphics-21x9-valid-resolutions-names*)) + (('pc-aspect-32x9) + (draw-options-list obj font-ctx s2-1 *pc-graphics-32x9-valid-resolutions-names*)))) ((= v1-81 #x12) (draw-options-list obj font-ctx s2-1 *pc-graphics-display-mode-remap*)) ((= v1-81 #x13) diff --git a/goal_src/pc/engine/ui/progress/progress-static.gc b/goal_src/pc/engine/ui/progress/progress-static.gc index 6c50bd91cb..e08952ce54 100644 --- a/goal_src/pc/engine/ui/progress/progress-static.gc +++ b/goal_src/pc/engine/ui/progress/progress-static.gc @@ -73,6 +73,7 @@ ;; 12 - port window type ;; 13 - port subtitle language ;; 14 - port subtitle speaker +;; 15 - original aspect ratio (define *game-options* (new 'static 'boxed-array :type game-option :length 5 :allocated-length 5 @@ -114,7 +115,8 @@ )) (define *graphic-options* - (new 'static 'boxed-array :type game-option :length 5 :allocated-length 5 + (new 'static 'boxed-array :type game-option :length 6 + (new 'static 'game-option :option-type #x15 :name (game-text-id progress-use-original-aspect) :scale #t) (new 'static 'game-option :option-type #x12 :name (game-text-id progress-display-mode) :scale #t) (new 'static 'game-option :option-type #x10 :name (game-text-id aspect-ratio) :scale #t) (new 'static 'game-option :option-type #x11 :name (game-text-id progress-resolution) :scale #t) @@ -256,80 +258,61 @@ (game-text-id progress-subtitles-label-speaker-off) (game-text-id progress-subtitles-label-speaker-auto))) -(define *pc-subtitle-speaker-valid-options* - (new 'static 'boxed-array :type symbol :length 3 :allocated-length 3 #t #f 'auto)) - -(define *pc-graphics-display-mode-symbol-options* - (new 'static 'boxed-array :type symbol :length 3 :allocated-length 3 'borderless 'fullscreen 'windowed)) - (define *pc-graphics-display-mode-remap* (new 'static 'boxed-array :type game-text-id :length 3 :allocated-length 3 (game-text-id progress-display-mode-borderless) (game-text-id progress-display-mode-fullscreen) (game-text-id progress-display-mode-windowed))) -(define *pc-graphics-aspect-ratio-options* - (new 'static 'boxed-array :type symbol :length 5 :allocated-length 5 'pc-aspect-4x3 'pc-aspect-5x4 'pc-aspect-16x9 'pc-aspect-21x9 'pc-aspect-32x9)) +(define *pc-graphics-original-aspect-ratio-mode-remap* + (new 'static 'boxed-array :type game-text-id :length 2 :allocated-length 2 + (game-text-id progress-aspect-ratio-4x3) + (game-text-id progress-aspect-ratio-16x9))) (define *pc-graphics-aspect-ratio-mode-remap* (new 'static 'boxed-array :type game-text-id :length 5 :allocated-length 5 - (game-text-id process-aspect-ratio-4x3) - (game-text-id process-aspect-ratio-5x4) - (game-text-id process-aspect-ratio-16x9) - (game-text-id process-aspect-ratio-21x9) - (game-text-id process-aspect-ratio-32x9))) - -(define *pc-graphics-4x3-valid-resolutions* - (new 'static 'boxed-array :type symbol :length 5 :allocated-length 5 '640x480 '800x600 '1024x768 '1280x960 '1600x1200)) + (game-text-id progress-aspect-ratio-4x3) + (game-text-id progress-aspect-ratio-5x4) + (game-text-id progress-aspect-ratio-16x9) + (game-text-id progress-aspect-ratio-21x9) + (game-text-id progress-aspect-ratio-32x9))) (define *pc-graphics-4x3-valid-resolutions-names* (new 'static 'boxed-array :type game-text-id :length 5 :allocated-length 5 - (game-text-id process-res-4x3-640x480) - (game-text-id process-res-4x3-800x600) - (game-text-id process-res-4x3-1024x768) - (game-text-id process-res-4x3-1280x960) - (game-text-id process-res-4x3-1600x1200))) - -(define *pc-graphics-5x4-valid-resolutions* - (new 'static 'boxed-array :type symbol :length 3 :allocated-length 3 '960x768 '1280x1024 '1500x1200)) + (game-text-id progress-res-4x3-640x480) + (game-text-id progress-res-4x3-800x600) + (game-text-id progress-res-4x3-1024x768) + (game-text-id progress-res-4x3-1280x960) + (game-text-id progress-res-4x3-1600x1200))) (define *pc-graphics-5x4-valid-resolutions-names* (new 'static 'boxed-array :type game-text-id :length 3 :allocated-length 3 - (game-text-id process-res-5x4-960x768) - (game-text-id process-res-5x4-1280x1024) - (game-text-id process-res-5x4-1500x1200))) - -(define *pc-graphics-16x9-valid-resolutions* - (new 'static 'boxed-array :type symbol :length 7 :allocated-length 7 '854x480 '1280x720 '1920x1080 '2560x1440 '2880x1620 '3840x2160 '5120x2880)) + (game-text-id progress-res-5x4-960x768) + (game-text-id progress-res-5x4-1280x1024) + (game-text-id progress-res-5x4-1500x1200))) (define *pc-graphics-16x9-valid-resolutions-names* (new 'static 'boxed-array :type game-text-id :length 7 :allocated-length 7 - (game-text-id process-res-16x9-854x480) - (game-text-id process-res-16x9-1280x720) - (game-text-id process-res-16x9-1920x1080) - (game-text-id process-res-16x9-2560x1440) - (game-text-id process-res-16x9-2880x1620) - (game-text-id process-res-16x9-3840x2160) - (game-text-id process-res-16x9-5120x2880))) - -(define *pc-graphics-21x9-valid-resolutions* - (new 'static 'boxed-array :type symbol :length 6 :allocated-length 6 '2560x1080 '3120x1440 '3200x1440 '3440x1440 '3840x1600 '5120x2160)) + (game-text-id progress-res-16x9-854x480) + (game-text-id progress-res-16x9-1280x720) + (game-text-id progress-res-16x9-1920x1080) + (game-text-id progress-res-16x9-2560x1440) + (game-text-id progress-res-16x9-2880x1620) + (game-text-id progress-res-16x9-3840x2160) + (game-text-id progress-res-16x9-5120x2880))) (define *pc-graphics-21x9-valid-resolutions-names* (new 'static 'boxed-array :type game-text-id :length 6 :allocated-length 6 - (game-text-id process-res-21x9-2560x1080) - (game-text-id process-res-21x9-3120x1440) - (game-text-id process-res-21x9-3200x1440) - (game-text-id process-res-21x9-3440x1440) - (game-text-id process-res-21x9-3840x1600) - (game-text-id process-res-21x9-5120x2160))) - -(define *pc-graphics-32x9-valid-resolutions* - (new 'static 'boxed-array :type symbol :length 1 :allocated-length 1 '5120x1440)) + (game-text-id progress-res-21x9-2560x1080) + (game-text-id progress-res-21x9-3120x1440) + (game-text-id progress-res-21x9-3200x1440) + (game-text-id progress-res-21x9-3440x1440) + (game-text-id progress-res-21x9-3840x1600) + (game-text-id progress-res-21x9-5120x2160))) (define *pc-graphics-32x9-valid-resolutions-names* (new 'static 'boxed-array :type game-text-id :length 1 :allocated-length 1 - (game-text-id process-res-32x9-5120x1440))) + (game-text-id progress-res-32x9-5120x1440))) ;; all level tasks (define *level-task-data* diff --git a/goal_src/pc/engine/ui/progress/progress.gc b/goal_src/pc/engine/ui/progress/progress.gc index ccdbc7cd21..731d4f835f 100644 --- a/goal_src/pc/engine/ui/progress/progress.gc +++ b/goal_src/pc/engine/ui/progress/progress.gc @@ -153,7 +153,6 @@ (set! (-> *options-remap* 32) *ok-options*) (set! (-> *options-remap* 33) *ok-options*) (set! (-> *options-remap* 34) *yes-no-options*) - (set! (-> *progress-state* aspect-ratio-choice) (get-aspect-ratio)) (set! (-> *progress-state* video-mode-choice) (get-video-mode)) (set! (-> *progress-state* yes-no-choice) #f) (set! (-> *game-options* 0 value-to-modify) (&-> *setting-control* default vibration)) @@ -176,10 +175,11 @@ (set! (-> *language-options* 1 value-to-modify) (&-> *pc-settings* subtitles?)) (set! (-> *language-options* 2 value-to-modify) (&-> *pc-settings* subtitle-language)) (set! (-> *language-options* 3 value-to-modify) (&-> *pc-settings* subtitle-speaker?)) ;; TODO - refactor this like i did with display-mode - (set! (-> *graphic-options* 0 value-to-modify) (&-> *pc-settings* display-mode)) - (set! (-> *graphic-options* 1 value-to-modify) (&-> *pc-settings* aspect-ratio-mode)) - (set! (-> *graphic-options* 2 value-to-modify) (&-> *pc-settings* resolution)) - (set! (-> *graphic-options* 3 value-to-modify) (&-> *pc-settings* letterbox?)) + (set! (-> *graphic-options* 0 value-to-modify) (&-> *progress-state* aspect-ratio-choice)) + (set! (-> *graphic-options* 1 value-to-modify) (&-> *pc-settings* display-mode)) + (set! (-> *graphic-options* 2 value-to-modify) (&-> *pc-settings* aspect-ratio-mode)) + (set! (-> *graphic-options* 3 value-to-modify) (&-> *pc-settings* resolution)) + (set! (-> *graphic-options* 4 value-to-modify) (&-> *pc-settings* letterbox?)) (none) ) @@ -1344,6 +1344,9 @@ (set! play-sound? (= (-> (the-as (pointer symbol) (-> s5-0 (-> obj option-index) value-to-modify))) 'ntsc)) (set! (-> (the-as (pointer symbol) (-> s5-0 (-> obj option-index) value-to-modify))) 'pal) ) + ((#x15) + (set! play-sound? (= (-> (the-as (pointer symbol) (-> s5-0 (-> obj option-index) value-to-modify))) #f)) + (set! (-> (the-as (pointer symbol) (-> s5-0 (-> obj option-index) value-to-modify))) #t)) ;; arbitrary list options ((1 #x10 #x11 #x12 #x13 #x14) ;; every list moves the same way, common logic @@ -1373,22 +1376,35 @@ (dec (-> *progress-menu-list-tracker* selected-index)))))) ;; aspect ratio setting ((#x10) - ;; get the current selected item - (let ((curr-val (-> *pc-graphics-aspect-ratio-options* + (if (-> *pc-settings* use-original-aspect-ratio?) + (let ((curr-val (-> *pc-graphics-original-aspect-ratio-options* (-> *progress-menu-list-tracker* selected-index)))) - (if (= curr-val (first-arr *pc-graphics-aspect-ratio-options*)) - ;; if we've hit the beginning, wrap around to the end - (set! (-> *progress-menu-list-tracker* selected-index) - (last-idx-arr *pc-graphics-aspect-ratio-options*)) - ;; else just move left - (set! (-> *progress-menu-list-tracker* selected-index) - (dec (-> *progress-menu-list-tracker* selected-index)))))) + (if (= curr-val (first-arr *pc-graphics-original-aspect-ratio-options*)) + (set! (-> *progress-menu-list-tracker* selected-index) + (last-idx-arr *pc-graphics-original-aspect-ratio-options*)) + (set! (-> *progress-menu-list-tracker* selected-index) + (dec (-> *progress-menu-list-tracker* selected-index))))) + (let ((curr-val (-> *pc-graphics-aspect-ratio-options* + (-> *progress-menu-list-tracker* selected-index)))) + (if (= curr-val (first-arr *pc-graphics-aspect-ratio-options*)) + (set! (-> *progress-menu-list-tracker* selected-index) + (last-idx-arr *pc-graphics-aspect-ratio-options*)) + (set! (-> *progress-menu-list-tracker* selected-index) + (dec (-> *progress-menu-list-tracker* selected-index))))))) ;; resolution setting ;; this is a little more sophisticated -- only display the ones related to the aspect ratio ((#x11) (let ((curr-idx (-> *progress-menu-list-tracker* selected-index)) (new-idx (dec (-> *progress-menu-list-tracker* selected-index)))) (case (-> *pc-settings* aspect-ratio-mode) + (('orig-aspect-4x3) + (when (= (-> *pc-graphics-4x3-valid-resolutions* curr-idx) + (first-arr *pc-graphics-4x3-valid-resolutions*)) + (set! new-idx (last-idx-arr *pc-graphics-4x3-valid-resolutions*)))) + (('orig-aspect-16x9) + (when (= (-> *pc-graphics-16x9-valid-resolutions* curr-idx) + (first-arr *pc-graphics-16x9-valid-resolutions*)) + (set! new-idx (last-idx-arr *pc-graphics-16x9-valid-resolutions*)))) (('pc-aspect-4x3) (when (= (-> *pc-graphics-4x3-valid-resolutions* curr-idx) (first-arr *pc-graphics-4x3-valid-resolutions*)) @@ -1424,7 +1440,7 @@ (last-idx-arr *pc-subtitle-speaker-valid-options*)) (set! (-> *progress-menu-list-tracker* selected-index) (dec (-> *progress-menu-list-tracker* selected-index))))))) - (format #t "VAS: Moving Left. New Index: ~D" (-> *progress-menu-list-tracker* selected-index)))) + (format 0 "VAS: Moving Left. New Index: ~D" (-> *progress-menu-list-tracker* selected-index)))) (if play-sound? (sound-play-by-name (static-sound-name "cursor-l-r") (new-sound-id) 1024 0 0 1 #t))))) (else @@ -1496,6 +1512,9 @@ (set! play-sound? (= (-> (the-as (pointer symbol) (-> s5-0 (-> obj option-index) value-to-modify))) 'pal)) (set! (-> (the-as (pointer symbol) (-> s5-0 (-> obj option-index) value-to-modify))) 'ntsc) ) + ((#x15) + (set! play-sound? (= (-> (the-as (pointer symbol) (-> s5-0 (-> obj option-index) value-to-modify))) #t)) + (set! (-> (the-as (pointer symbol) (-> s5-0 (-> obj option-index) value-to-modify))) #f)) ;; arbitrary list options ((1 #x10 #x11 #x12 #x13 #x14) ;; every list moves the same way, common logic @@ -1524,21 +1543,33 @@ (inc (-> *progress-menu-list-tracker* selected-index)))))) ;; aspect ratio setting ((#x10) - ;; get the current selected item - (let ((curr-val (-> *pc-graphics-aspect-ratio-options* - (-> *progress-menu-list-tracker* selected-index)))) - (if (= curr-val (last-arr *pc-graphics-aspect-ratio-options*)) - ;; if we've hit the end, wrap around to the beginning - (set! (-> *progress-menu-list-tracker* selected-index) 0) - ;; else just move left - (set! (-> *progress-menu-list-tracker* selected-index) - (inc (-> *progress-menu-list-tracker* selected-index)))))) + (if (-> *pc-settings* use-original-aspect-ratio?) + (let ((curr-val (-> *pc-graphics-original-aspect-ratio-options* + (-> *progress-menu-list-tracker* selected-index)))) + (if (= curr-val (last-arr *pc-graphics-original-aspect-ratio-options*)) + (set! (-> *progress-menu-list-tracker* selected-index) 0) + (set! (-> *progress-menu-list-tracker* selected-index) + (inc (-> *progress-menu-list-tracker* selected-index))))) + (let ((curr-val (-> *pc-graphics-aspect-ratio-options* + (-> *progress-menu-list-tracker* selected-index)))) + (if (= curr-val (last-arr *pc-graphics-aspect-ratio-options*)) + (set! (-> *progress-menu-list-tracker* selected-index) 0) + (set! (-> *progress-menu-list-tracker* selected-index) + (inc (-> *progress-menu-list-tracker* selected-index))))))) ;; resolution setting ;; this is a little more sophisticated -- only display the ones related to the aspect ratio ((#x11) (let ((curr-idx (-> *progress-menu-list-tracker* selected-index)) (new-idx (inc (-> *progress-menu-list-tracker* selected-index)))) (case (-> *pc-settings* aspect-ratio-mode) + (('orig-aspect-4x3) + (when (= (-> *pc-graphics-4x3-valid-resolutions* curr-idx) + (last-arr *pc-graphics-4x3-valid-resolutions*)) + (set! new-idx 0))) + (('orig-aspect-16x9) + (when (= (-> *pc-graphics-16x9-valid-resolutions* curr-idx) + (last-arr *pc-graphics-16x9-valid-resolutions*)) + (set! new-idx 0))) (('pc-aspect-4x3) (when (= (-> *pc-graphics-4x3-valid-resolutions* curr-idx) (last-arr *pc-graphics-4x3-valid-resolutions*)) @@ -1573,7 +1604,7 @@ (set! (-> *progress-menu-list-tracker* selected-index) 0) (set! (-> *progress-menu-list-tracker* selected-index) (inc (-> *progress-menu-list-tracker* selected-index))))))) - (format #t "VAS: Moving Right. New Index: ~D" (-> *progress-menu-list-tracker* selected-index)))) + (format 0 "VAS: Moving Right. New Index: ~D" (-> *progress-menu-list-tracker* selected-index)))) (if play-sound? (sound-play-by-name (static-sound-name "cursor-l-r") (new-sound-id) 1024 0 0 1 #t))))) (else @@ -1739,13 +1770,8 @@ (set! (-> *progress-state* center-x-backup) (-> *setting-control* default screenx)) (set! (-> *progress-state* center-y-backup) (-> *setting-control* default screeny)) ) - ((or (= v1-427 4) (= v1-427 5)) - (set! (-> *progress-state* aspect-ratio-backup) - (the-as symbol (-> (the-as (pointer uint32) (-> s5-0 (-> obj option-index) value-to-modify)))) - ) - ) - ) - ) + ((= v1-427 #x15) + (set! (-> *progress-state* aspect-ratio-choice) (-> *pc-settings* use-original-aspect-ratio?))))) (sound-play-by-name (static-sound-name "select-option") (new-sound-id) 1024 0 0 1 #t) (logclear! (-> *cpad-list* cpads 0 button0-abs 0) (pad-buttons x)) (logclear! (-> *cpad-list* cpads 0 button0-rel 0) (pad-buttons x)) @@ -1759,7 +1785,7 @@ (= (-> s5-0 (-> obj option-index) option-type) #x12) (= (-> s5-0 (-> obj option-index) option-type) #x13) (= (-> s5-0 (-> obj option-index) option-type) #x14)) - (format #t "VAS: list option opened") + (format 0 "VAS: list option opened") ;; reset tracker to defaults ;; defaults to left? (set! (-> *progress-menu-list-tracker* direction) 'left) (set! (-> *progress-menu-list-tracker* transition?) #f) @@ -1771,10 +1797,19 @@ (set! (-> *progress-menu-list-tracker* selected-index) (the-as int (-> *setting-control* current language)))) ((#x10) - (set! (-> *progress-menu-list-tracker* selected-index) - (arr-idx-of *pc-graphics-aspect-ratio-options* (-> *pc-settings* aspect-ratio-mode) 0))) + (if (-> *pc-settings* use-original-aspect-ratio?) + (set! (-> *progress-menu-list-tracker* selected-index) + (arr-idx-of *pc-graphics-original-aspect-ratio-options* (-> *pc-settings* aspect-ratio-mode) 0)) + (set! (-> *progress-menu-list-tracker* selected-index) + (arr-idx-of *pc-graphics-aspect-ratio-options* (-> *pc-settings* aspect-ratio-mode) 0)))) ((#x11) (case (-> *pc-settings* aspect-ratio-mode) + (('orig-aspect-4x3) + (set! (-> *progress-menu-list-tracker* selected-index) + (arr-idx-of *pc-graphics-4x3-valid-resolutions* (-> *pc-settings* resolution) 0))) + (('orig-aspect-16x9) + (set! (-> *progress-menu-list-tracker* selected-index) + (arr-idx-of *pc-graphics-16x9-valid-resolutions* (-> *pc-settings* resolution) 0))) (('pc-aspect-4x3) (set! (-> *progress-menu-list-tracker* selected-index) (arr-idx-of *pc-graphics-4x3-valid-resolutions* (-> *pc-settings* resolution) 0))) @@ -1805,13 +1840,10 @@ (else (sound-play-by-name (static-sound-name "start-options") (new-sound-id) 1024 0 0 1 #t) (set! (-> obj selected-option) #f) - (format #t "VAS: list selection confirmed!") + (format 0 "VAS: list selection confirmed!") (case (-> s5-0 (-> obj option-index) option-type) - ((4) - (set! (-> *setting-control* default aspect-ratio) - (the-as symbol (-> (the-as (pointer uint32) (-> s5-0 (-> obj option-index) value-to-modify)))) - ) - ) + ((#x15) + (use-orig-aspect-ratio! *pc-settings* (-> *progress-state* aspect-ratio-choice))) ((5) (case (-> (the-as (pointer uint32) (-> s5-0 (-> obj option-index) value-to-modify))) (('pal) @@ -1829,23 +1861,19 @@ (when (not (-> *progress-menu-list-tracker* transition?)) (load-level-text-files (-> obj display-level-index)))) ((#x10) - (set-aspect-ratio-mode! *pc-settings* - (-> *pc-graphics-aspect-ratio-options* (-> *progress-menu-list-tracker* selected-index))) - ;; change to the lowest option for that resolution as well - (case (-> *pc-settings* aspect-ratio-mode) - (('pc-aspect-4x3) - (set-resolution! *pc-settings* (-> *pc-graphics-4x3-valid-resolutions* 0))) - (('pc-aspect-5x4) - (set-resolution! *pc-settings* (-> *pc-graphics-5x4-valid-resolutions* 0))) - (('pc-aspect-16x9) - (set-resolution! *pc-settings* (-> *pc-graphics-16x9-valid-resolutions* 0))) - (('pc-aspect-21x9) - (set-resolution! *pc-settings* (-> *pc-graphics-21x9-valid-resolutions* 0))) - (('pc-aspect-32x9) - (set-resolution! *pc-settings* (-> *pc-graphics-32x9-valid-resolutions* 0)))) - ) + (if (-> *pc-settings* use-original-aspect-ratio?) + (set-aspect-ratio-mode! *pc-settings* + (-> *pc-graphics-original-aspect-ratio-options* (-> *progress-menu-list-tracker* selected-index))) + (set-aspect-ratio-mode! *pc-settings* + (-> *pc-graphics-aspect-ratio-options* (-> *progress-menu-list-tracker* selected-index))))) ((#x11) (case (-> *pc-settings* aspect-ratio-mode) + (('orig-aspect-4x3) + (set-resolution! *pc-settings* + (-> *pc-graphics-4x3-valid-resolutions* (-> *progress-menu-list-tracker* selected-index)))) + (('orig-aspect-16x9) + (set-resolution! *pc-settings* + (-> *pc-graphics-16x9-valid-resolutions* (-> *progress-menu-list-tracker* selected-index)))) (('pc-aspect-4x3) (set-resolution! *pc-settings* (-> *pc-graphics-4x3-valid-resolutions* (-> *progress-menu-list-tracker* selected-index)))) @@ -1871,6 +1899,8 @@ (set! (-> *pc-settings* subtitle-speaker?) (-> *pc-subtitle-speaker-valid-options* (-> *progress-menu-list-tracker* selected-index)))) ) + ;; persist pc-settings + (commit-to-file *pc-settings*) ) ) ) diff --git a/goal_src/pc/engine/ui/text-h.gc b/goal_src/pc/engine/ui/text-h.gc index 1a64cd8d5b..753b58b036 100644 --- a/goal_src/pc/engine/ui/text-h.gc +++ b/goal_src/pc/engine/ui/text-h.gc @@ -483,38 +483,40 @@ (progress-display-mode-fullscreen #x1020) (progress-display-mode-windowed #x1021) ;; aspect ratios - (process-aspect-ratio-4x3 #x1022) - (process-aspect-ratio-5x4 #x1023) - (process-aspect-ratio-16x9 #x1024) - (process-aspect-ratio-21x9 #x1025) - (process-aspect-ratio-32x9 #x1026) + (progress-aspect-ratio-4x3 #x1022) + (progress-aspect-ratio-5x4 #x1023) + (progress-aspect-ratio-16x9 #x1024) + (progress-aspect-ratio-21x9 #x1025) + (progress-aspect-ratio-32x9 #x1026) ;; 4:3 resolutions - (process-res-4x3-640x480 #x1027) - (process-res-4x3-800x600 #x1028) - (process-res-4x3-1024x768 #x1029) - (process-res-4x3-1280x960 #x1030) - (process-res-4x3-1600x1200 #x1031) + (progress-res-4x3-640x480 #x1027) + (progress-res-4x3-800x600 #x1028) + (progress-res-4x3-1024x768 #x1029) + (progress-res-4x3-1280x960 #x1030) + (progress-res-4x3-1600x1200 #x1031) ;; 5:4 resolutions - (process-res-5x4-960x768 #x1032) - (process-res-5x4-1280x1024 #x1033) - (process-res-5x4-1500x1200 #x1034) + (progress-res-5x4-960x768 #x1032) + (progress-res-5x4-1280x1024 #x1033) + (progress-res-5x4-1500x1200 #x1034) ;; 16:9 resolutions - (process-res-16x9-854x480 #x1035) - (process-res-16x9-1280x720 #x1036) - (process-res-16x9-1920x1080 #x1037) - (process-res-16x9-2560x1440 #x1038) - (process-res-16x9-2880x1620 #x1039) - (process-res-16x9-3840x2160 #x1040) - (process-res-16x9-5120x2880 #x1041) + (progress-res-16x9-854x480 #x1035) + (progress-res-16x9-1280x720 #x1036) + (progress-res-16x9-1920x1080 #x1037) + (progress-res-16x9-2560x1440 #x1038) + (progress-res-16x9-2880x1620 #x1039) + (progress-res-16x9-3840x2160 #x1040) + (progress-res-16x9-5120x2880 #x1041) ;; 21:9 resolutions - (process-res-21x9-2560x1080 #x1042) - (process-res-21x9-3120x1440 #x1043) - (process-res-21x9-3200x1440 #x1044) - (process-res-21x9-3440x1440 #x1045) - (process-res-21x9-3840x1600 #x1046) - (process-res-21x9-5120x2160 #x1047) + (progress-res-21x9-2560x1080 #x1042) + (progress-res-21x9-3120x1440 #x1043) + (progress-res-21x9-3200x1440 #x1044) + (progress-res-21x9-3440x1440 #x1045) + (progress-res-21x9-3840x1600 #x1046) + (progress-res-21x9-5120x2160 #x1047) ;; 32:9 resolutions - (process-res-32x9-5120x1440 #x1048) + (progress-res-32x9-5120x1440 #x1048) + ;; original aspect ratio + (progress-use-original-aspect #x1049) ) ;; an individual string. diff --git a/goal_src/pc/pckernel-h.gc b/goal_src/pc/pckernel-h.gc index 16ae4af52c..7d322533be 100644 --- a/goal_src/pc/pckernel-h.gc +++ b/goal_src/pc/pckernel-h.gc @@ -55,7 +55,32 @@ (defconstant PC_SETTINGS_FILE_NAME "game_config/pc-settings.txt") +(define *pc-subtitle-speaker-valid-options* + (new 'static 'boxed-array :type symbol :length 3 :allocated-length 3 #t #f 'auto)) +(define *pc-graphics-display-mode-symbol-options* + (new 'static 'boxed-array :type symbol :length 3 :allocated-length 3 'borderless 'fullscreen 'windowed)) + +(define *pc-graphics-original-aspect-ratio-options* + (new 'static 'boxed-array :type symbol :length 2 :allocated-length 2 'orig-aspect-4x3 'orig-aspect-16x9)) + +(define *pc-graphics-aspect-ratio-options* + (new 'static 'boxed-array :type symbol :length 5 :allocated-length 5 'pc-aspect-4x3 'pc-aspect-5x4 'pc-aspect-16x9 'pc-aspect-21x9 'pc-aspect-32x9)) + +(define *pc-graphics-4x3-valid-resolutions* + (new 'static 'boxed-array :type symbol :length 5 :allocated-length 5 '640x480 '800x600 '1024x768 '1280x960 '1600x1200)) + +(define *pc-graphics-5x4-valid-resolutions* + (new 'static 'boxed-array :type symbol :length 3 :allocated-length 3 '960x768 '1280x1024 '1500x1200)) + +(define *pc-graphics-16x9-valid-resolutions* + (new 'static 'boxed-array :type symbol :length 7 :allocated-length 7 '854x480 '1280x720 '1920x1080 '2560x1440 '2880x1620 '3840x2160 '5120x2880)) + +(define *pc-graphics-21x9-valid-resolutions* + (new 'static 'boxed-array :type symbol :length 6 :allocated-length 6 '2560x1080 '3120x1440 '3200x1440 '3440x1440 '3840x1600 '5120x2160)) + +(define *pc-graphics-32x9-valid-resolutions* + (new 'static 'boxed-array :type symbol :length 1 :allocated-length 1 '5120x1440)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; types and enums @@ -202,7 +227,7 @@ (win-height int32) (dpi-x float) ;; DPI width scale (dpi-y float) ;; DPI height scale - (aspect-setting symbol) ;; aspect ratio setting, for the original game + (use-original-aspect-ratio? symbol) (aspect-ratio-auto? symbol) ;; if on, aspect ratio is calculated automatically. (aspect-ratio float) ;; the desired aspect ratio. set auto to off and then this to 4/3 to force 4x3 aspect. (aspect-ratio-scale float) ;; aspect ratio compared to 4x3 @@ -290,6 +315,8 @@ (discord-rpc? symbol) ;; enable discord rich presence integration (cheats pc-cheats) + + ;; TODO - save/restore original settings (language/sound/etc) ) (:methods @@ -306,6 +333,7 @@ (reset-fixes (_type_) none) (reset-extra (_type_) none) (draw (_type_ dma-buffer) none) + (use-orig-aspect-ratio! (_type_ symbol) none) (set-display-mode! (_type_ symbol) none) (set-aspect-ratio-mode! (_type_ symbol) none) (set-resolution! (_type_ symbol) none) @@ -316,6 +344,7 @@ (write-to-file (_type_ string) symbol) (actor-force-visible? (_type_) symbol) (update-cheats (_type_) int) + (commit-to-file (_type_) none) ) ) @@ -345,6 +374,8 @@ (define *pc-settings* (the-as pc-settings #f)) (format 0 "PC kernel version: ~D.~D~%" PC_KERNEL_VERSION_MAJOR PC_KERNEL_VERSION_MINOR) +(define *pc-temp-string-1* (new 'global 'string 2048 (the-as string #f))) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; resets ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -390,7 +421,8 @@ (set! (-> obj target-fps) 60) (set! (-> obj width) PC_BASE_WIDTH) (set! (-> obj height) PC_BASE_HEIGHT) - (set! (-> obj use-vis?) #t) + (set! (-> obj use-vis?) #f) + (set! (-> obj use-original-aspect-ratio?) #f) (set! (-> obj aspect-ratio-auto?) #f) (set! (-> obj vsync?) #t) (set! (-> obj letterbox?) #t) diff --git a/goal_src/pc/pckernel.gc b/goal_src/pc/pckernel.gc index b50a42dc0a..5776f806b9 100644 --- a/goal_src/pc/pckernel.gc +++ b/goal_src/pc/pckernel.gc @@ -52,7 +52,6 @@ (defmethod set-size! pc-settings ((obj pc-settings) (width int) (height int)) "sets the size of the display window" - (pc-set-window-size width height) (none)) @@ -66,6 +65,17 @@ ) (none)) +(defmethod use-orig-aspect-ratio! pc-settings ((obj pc-settings) (val symbol)) + "whether to use the pc port's aspect ratio, or the original games 4:3/16:9" + (if (= (-> obj use-original-aspect-ratio?) val) + (return 0)) + (set! (-> obj use-original-aspect-ratio?) val) + ;; default to the simplist resolution if we are changing + (if val + (set-aspect-ratio-mode! obj 'orig-aspect-4x3) + (set-aspect-ratio-mode! obj 'pc-aspect-4x3)) + (set! (-> *pc-settings* use-vis?) val) + (none)) (defmethod set-aspect-ratio! pc-settings ((obj pc-settings) (aspect float)) "set the aspect ratio used for rendering." @@ -83,29 +93,48 @@ ;; else change it and update it (set! (-> obj aspect-ratio-mode) mode) - (cond - ((= mode 'pc-aspect-5x4) - (set-aspect! obj 5 4)) - ((= mode 'pc-aspect-16x9) - (set-aspect! obj 16 9)) - ((= mode 'pc-aspect-21x9) - (set-aspect! obj 21 9)) - ((= mode 'pc-aspect-32x9) - (set-aspect! obj 32 9)) - (else ;; default to 4x3 - (set-aspect! obj 4 3))) + ;; also default to the lowest resolution option at the same time + (case mode + (('orig-aspect-4x3) + (set! (-> *setting-control* default aspect-ratio) 'aspect4x3) + (set-aspect-ratio (-> *setting-control* default aspect-ratio)) + (set-resolution! obj (-> *pc-graphics-4x3-valid-resolutions* 0))) + (('orig-aspect-16x9) + (set! (-> *setting-control* default aspect-ratio) 'aspect16x9) + (set-aspect-ratio (-> *setting-control* default aspect-ratio)) + (set-resolution! obj (-> *pc-graphics-16x9-valid-resolutions* 0))) + (('pc-aspect-4x3) + (set-aspect! obj 4 3) + (set-resolution! obj (-> *pc-graphics-4x3-valid-resolutions* 0))) + (('pc-aspect-5x4) + (set-aspect! obj 5 4) + (set-resolution! obj (-> *pc-graphics-5x4-valid-resolutions* 0))) + (('pc-aspect-16x9) + (set-aspect! obj 16 9) + (set-resolution! obj (-> *pc-graphics-16x9-valid-resolutions* 0))) + (('pc-aspect-21x9) + (set-aspect! obj 21 9) + (set-resolution! obj (-> *pc-graphics-21x9-valid-resolutions* 0))) + (('pc-aspect-32x9) + (set-aspect! obj 32 9) + (set-resolution! obj (-> *pc-graphics-32x9-valid-resolutions* 0)))) + + ; fix hud by picking either 4x3 or 16x9 on the game's aspect ratio + ; this probably just a temporary hack + ; (set-aspect-ratio (-> *setting-control* default aspect-ratio)) + (none)) (defmethod set-resolution! pc-settings ((obj pc-settings) (mode symbol)) "sets the game's resolution" + ;; TODO - implement a custom resolution mode which will enable resizing and use the values stored ;; changing to same mode, no-op (if (= (-> obj resolution) mode) (none)) ;; else change it and update it (set! (-> obj resolution) mode) - ;; give me string splitting! (case mode (('640x480) (set-size! obj 640 480)) (('800x600) (set-size! obj 800 600)) @@ -131,6 +160,15 @@ (('5120x1440) (set-size! obj 5120 1440))) (none)) +(defmethod commit-to-file pc-settings ((obj pc-settings)) + "commits the current settings to the file" + ;; auto load settings if available + (clear *pc-temp-string-1*) + (format *pc-temp-string-1* "~S/pc-settings.gc" *pc-settings-folder*) + (write-to-file obj *pc-temp-string-1*) + (clear *pc-temp-string-1*) + (none)) + (defmethod update-from-os pc-settings ((obj pc-settings)) "Update settings from the PC kernel to GOAL." @@ -200,6 +238,8 @@ (pc-renderer-tree-set-lod (pc-renderer-tree-type tie3) (-> obj lod-force-tie)) ) + ;; TODO - save changes + (none)) (define *pc-cheat-temp* (the-as (pointer int32) (malloc 'global 24))) @@ -217,7 +257,7 @@ (update-from-os obj) (update-to-os obj) - + (set! (-> obj movie?) (movie?)) (let ((info (new 'stack 'discord-info))) @@ -274,49 +314,49 @@ (defmethod update-cheats pc-settings ((obj pc-settings)) "run cheats." - + (when (and (cpad-hold? 0 l2) (cpad-hold? 0 l1) (cpad-hold? 0 r2) (cpad-hold? 0 r1)) (pc-check-cheat-code (-> *pc-cheat-temp* 0) 0 (s p i r i t) :extra (x) (logclear! (-> obj cheats) (pc-cheats eco-red eco-yellow eco-green)) (pc-cheat-toggle-and-tune obj eco-blue)) - + (pc-check-cheat-code (-> *pc-cheat-temp* 1) 0 (s p i r i t) :extra (circle) (logclear! (-> obj cheats) (pc-cheats eco-blue eco-yellow eco-green)) (pc-cheat-toggle-and-tune obj eco-red)) - + (pc-check-cheat-code (-> *pc-cheat-temp* 2) 0 (s p i r i t) :extra (triangle) (logclear! (-> obj cheats) (pc-cheats eco-red eco-yellow eco-blue)) (pc-cheat-toggle-and-tune obj eco-green)) - + (pc-check-cheat-code (-> *pc-cheat-temp* 3) 0 (s p i r i t) :extra (square) (logclear! (-> obj cheats) (pc-cheats eco-red eco-blue eco-green)) (pc-cheat-toggle-and-tune obj eco-yellow)) - + (pc-check-cheat-code (-> *pc-cheat-temp* 4) 0 (s t e e l) (logclear! (-> *target* state-flags) 16) (pc-cheat-toggle-and-tune obj invinc)) - + (pc-check-cheat-code (-> *pc-cheat-temp* 5) 0 (l e a d s) (pc-cheat-toggle-and-tune obj sidekick-blue)) ) - + (when *target* - + (when (and (pc-cheats? obj eco-blue) (or (= (-> *target* fact-info-target eco-type) (pickup-type eco-blue)) (<= (-> *target* fact-info-target eco-level) 0.0))) (send-event *target* 'get-pickup (pickup-type eco-blue) (-> *FACT-bank* eco-full-inc))) - + (when (and (pc-cheats? obj eco-yellow) (or (= (-> *target* fact-info-target eco-type) (pickup-type eco-yellow)) (<= (-> *target* fact-info-target eco-level) 0.0))) (send-event *target* 'get-pickup (pickup-type eco-yellow) (-> *FACT-bank* eco-full-inc))) - + (when (and (pc-cheats? obj eco-red) (or (= (-> *target* fact-info-target eco-type) (pickup-type eco-red)) (<= (-> *target* fact-info-target eco-level) 0.0))) (send-event *target* 'get-pickup (pickup-type eco-red) (-> *FACT-bank* eco-full-inc))) - + (when (and (pc-cheats? obj eco-green) (or (= (-> *target* fact-info-target eco-type) (pickup-type eco-green)) (<= (-> *target* fact-info-target eco-level) 0.0))) @@ -327,11 +367,11 @@ (logior! (-> *target* control root-prim prim-core action) #x200) (send-event *target* 'get-pickup (pickup-type eco-green) (-> *FACT-bank* eco-full-inc))) )) - + (when (pc-cheats? obj invinc) (logior! (-> *target* state-flags) 16) ) - + ) 0) @@ -507,7 +547,7 @@ (return #f)) (let ((file (new 'stack 'file-stream filename 'read))) - (if (not (file-stream-valid? file)) + (when (not (file-stream-valid? file)) (return #f)) (let ((version PC_KERNEL_VERSION)) @@ -525,12 +565,13 @@ (set-size! obj (-> obj width) (-> obj height)) (set-aspect! obj (-> obj width) (-> obj height)) ) + (("use-original-aspect-ratio?") + (set! (-> obj use-original-aspect-ratio?) (file-stream-read-symbol file))) (("aspect") (set! (-> obj aspect-custom-x) (file-stream-read-int file)) (set! (-> obj aspect-custom-y) (file-stream-read-int file)) ) (("aspect-auto") (set! (-> obj aspect-ratio-auto?) (file-stream-read-symbol file))) - (("aspect-game") (set! (-> obj aspect-setting) (file-stream-read-symbol file))) (("display-mode") (set-display-mode! obj (file-stream-read-symbol file))) (("aspect-ratio-mode") (set-aspect-ratio-mode! obj (file-stream-read-symbol file))) (("resolution") (set-resolution! obj (file-stream-read-symbol file))) @@ -657,14 +698,13 @@ (if (not (file-stream-valid? file)) (return #f)) - (format file "(settings #x~X~%" (-> obj version)) (format file " (fps ~D)~%" (-> obj target-fps)) (format file " (size ~D ~D)~%" (-> obj width) (-> obj height)) + (format file " (use-original-aspect-ratio? ~A)~%" (-> obj use-original-aspect-ratio?)) (format file " (aspect ~D ~D)~%" (-> obj aspect-custom-x) (-> obj aspect-custom-y)) (format file " (aspect-auto ~A)~%" (-> obj aspect-ratio-auto?)) - (format file " (aspect-game ~A)~%" (-> *setting-control* default aspect-ratio)) (format file " (display-mode ~A)~%" (-> obj display-mode)) (format file " (aspect-ratio-mode ~A)~%" (-> obj aspect-ratio-mode)) (format file " (resolution ~A)~%" (-> obj resolution)) @@ -760,11 +800,21 @@ (defmethod new pc-settings ((allocation symbol) (type-to-make type)) "make a new pc-settings" - (let ((obj (object-new allocation type-to-make (the-as int (-> type-to-make size))))) - (reset obj) - + ;; auto load settings if available + (clear *pc-temp-string-1*) + (format *pc-temp-string-1* "~S/pc-settings.gc" *pc-settings-folder*) + (if (pc-filepath-exists? *pc-temp-string-1*) + (begin + (format 0 "[PC] PC Settings found at '~S'...loading!~%" *pc-temp-string-1*) + (read-from-file obj *pc-temp-string-1*)) + ;; - otherwise, create the dir and initialize the file + (begin + (format 0 "[PC] PC Settings not found at '~S'...creating and initializing with defaults!~%" *pc-temp-string-1*) + (pc-mkdir-path *pc-temp-string-1*) + (commit-to-file obj))) + (clear *pc-temp-string-1*) obj ) ) @@ -777,8 +827,6 @@ (define *pc-settings* (new 'global 'pc-settings)) -(read-from-file *pc-settings* PC_SETTINGS_FILE_NAME) - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; From f2bc8726acaefd0960d6c0c0ab9d85020d2d9f9d Mon Sep 17 00:00:00 2001 From: Tyler Wilding Date: Mon, 14 Mar 2022 01:12:03 -0400 Subject: [PATCH 04/12] game: overwrite unloadable settings with defaults --- Taskfile.yml | 6 ++++ goal_src/pc/engine/ui/progress/progress.gc | 8 ++--- goal_src/pc/pckernel.gc | 37 ++++++++++++++-------- 3 files changed, 33 insertions(+), 18 deletions(-) diff --git a/Taskfile.yml b/Taskfile.yml index 140eaf953b..22e82f5a9b 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -23,6 +23,12 @@ tasks: msg: "Couldn't locate runtime executable -- Have you compiled in release mode?" cmds: - "{{.GK_BIN_RELEASE_DIR}}/gk -fakeiso -debug -v" + run-game-quiet: + preconditions: + - sh: test -f {{.DECOMP_BIN_RELEASE_DIR}}/gk{{.EXE_FILE_EXTENSION}} + msg: "Couldn't locate runtime executable -- Have you compiled in release mode?" + cmds: + - "{{.GK_BIN_RELEASE_DIR}}/gk -fakeiso" repl: env: OPENGOAL_DECOMP_DIR: "jak1/" diff --git a/goal_src/pc/engine/ui/progress/progress.gc b/goal_src/pc/engine/ui/progress/progress.gc index 731d4f835f..1fd0ac0f71 100644 --- a/goal_src/pc/engine/ui/progress/progress.gc +++ b/goal_src/pc/engine/ui/progress/progress.gc @@ -1440,7 +1440,7 @@ (last-idx-arr *pc-subtitle-speaker-valid-options*)) (set! (-> *progress-menu-list-tracker* selected-index) (dec (-> *progress-menu-list-tracker* selected-index))))))) - (format 0 "VAS: Moving Left. New Index: ~D" (-> *progress-menu-list-tracker* selected-index)))) + (format 0 "VAS: Moving Left. New Index: ~D~%" (-> *progress-menu-list-tracker* selected-index)))) (if play-sound? (sound-play-by-name (static-sound-name "cursor-l-r") (new-sound-id) 1024 0 0 1 #t))))) (else @@ -1604,7 +1604,7 @@ (set! (-> *progress-menu-list-tracker* selected-index) 0) (set! (-> *progress-menu-list-tracker* selected-index) (inc (-> *progress-menu-list-tracker* selected-index))))))) - (format 0 "VAS: Moving Right. New Index: ~D" (-> *progress-menu-list-tracker* selected-index)))) + (format 0 "VAS: Moving Right. New Index: ~D~%" (-> *progress-menu-list-tracker* selected-index)))) (if play-sound? (sound-play-by-name (static-sound-name "cursor-l-r") (new-sound-id) 1024 0 0 1 #t))))) (else @@ -1785,7 +1785,7 @@ (= (-> s5-0 (-> obj option-index) option-type) #x12) (= (-> s5-0 (-> obj option-index) option-type) #x13) (= (-> s5-0 (-> obj option-index) option-type) #x14)) - (format 0 "VAS: list option opened") + (format 0 "VAS: list option opened~%") ;; reset tracker to defaults ;; defaults to left? (set! (-> *progress-menu-list-tracker* direction) 'left) (set! (-> *progress-menu-list-tracker* transition?) #f) @@ -1840,7 +1840,7 @@ (else (sound-play-by-name (static-sound-name "start-options") (new-sound-id) 1024 0 0 1 #t) (set! (-> obj selected-option) #f) - (format 0 "VAS: list selection confirmed!") + (format 0 "VAS: list selection confirmed!~%") (case (-> s5-0 (-> obj option-index) option-type) ((#x15) (use-orig-aspect-ratio! *pc-settings* (-> *progress-state* aspect-ratio-choice))) diff --git a/goal_src/pc/pckernel.gc b/goal_src/pc/pckernel.gc index 5776f806b9..e8fc8b388e 100644 --- a/goal_src/pc/pckernel.gc +++ b/goal_src/pc/pckernel.gc @@ -105,24 +105,30 @@ (set-resolution! obj (-> *pc-graphics-16x9-valid-resolutions* 0))) (('pc-aspect-4x3) (set-aspect! obj 4 3) + (set! (-> *setting-control* default aspect-ratio) 'aspect4x3) + (set-aspect-ratio (-> *setting-control* default aspect-ratio)) + (set! (-> *setting-control* default aspect-ratio) 'aspect16x9) + (set-aspect-ratio (-> *setting-control* default aspect-ratio)) (set-resolution! obj (-> *pc-graphics-4x3-valid-resolutions* 0))) (('pc-aspect-5x4) (set-aspect! obj 5 4) (set-resolution! obj (-> *pc-graphics-5x4-valid-resolutions* 0))) (('pc-aspect-16x9) (set-aspect! obj 16 9) + (set! (-> *setting-control* default aspect-ratio) 'aspect16x9) + (set-aspect-ratio (-> *setting-control* default aspect-ratio)) (set-resolution! obj (-> *pc-graphics-16x9-valid-resolutions* 0))) (('pc-aspect-21x9) (set-aspect! obj 21 9) + (set! (-> *setting-control* default aspect-ratio) 'aspect16x9) + (set-aspect-ratio (-> *setting-control* default aspect-ratio)) (set-resolution! obj (-> *pc-graphics-21x9-valid-resolutions* 0))) (('pc-aspect-32x9) (set-aspect! obj 32 9) + (set! (-> *setting-control* default aspect-ratio) 'aspect16x9) + (set-aspect-ratio (-> *setting-control* default aspect-ratio)) (set-resolution! obj (-> *pc-graphics-32x9-valid-resolutions* 0)))) - ; fix hud by picking either 4x3 or 16x9 on the game's aspect ratio - ; this probably just a temporary hack - ; (set-aspect-ratio (-> *setting-control* default aspect-ratio)) - (none)) (defmethod set-resolution! pc-settings ((obj pc-settings) (mode symbol)) @@ -803,22 +809,25 @@ (let ((obj (object-new allocation type-to-make (the-as int (-> type-to-make size))))) (reset obj) ;; auto load settings if available + ;; if saved settings are corrupted, reset them (clear *pc-temp-string-1*) (format *pc-temp-string-1* "~S/pc-settings.gc" *pc-settings-folder*) + (if (pc-filepath-exists? *pc-temp-string-1*) (begin (format 0 "[PC] PC Settings found at '~S'...loading!~%" *pc-temp-string-1*) - (read-from-file obj *pc-temp-string-1*)) - ;; - otherwise, create the dir and initialize the file - (begin - (format 0 "[PC] PC Settings not found at '~S'...creating and initializing with defaults!~%" *pc-temp-string-1*) - (pc-mkdir-path *pc-temp-string-1*) - (commit-to-file obj))) + (if (read-from-file obj *pc-temp-string-1*) + (return obj) + (begin + (format 0 "[PC] PC Settings found at '~S' but could not be loaded, re-creating with defaults!~%" *pc-temp-string-1*) + (reset obj)))) + (format 0 "[PC] PC Settings not found at '~S'...creating and initializing with defaults!~%" *pc-temp-string-1*)) + + ;; persist reset / new settings if we made it this far + (pc-mkdir-path *pc-temp-string-1*) + (commit-to-file obj) (clear *pc-temp-string-1*) - obj - ) - ) - + obj)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; From 2178916d731ecc0cd2b2fdcac1da522a30a05a6b Mon Sep 17 00:00:00 2001 From: Tyler Wilding Date: Mon, 14 Mar 2022 02:02:53 -0400 Subject: [PATCH 05/12] temp: unable to set the games aspect-ratio in the boot else crash? --- goal_src/pc/pckernel.gc | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/goal_src/pc/pckernel.gc b/goal_src/pc/pckernel.gc index e8fc8b388e..b13babe7f8 100644 --- a/goal_src/pc/pckernel.gc +++ b/goal_src/pc/pckernel.gc @@ -91,44 +91,42 @@ (if (= (-> obj aspect-ratio-mode) mode) (return 0)) + ;; if i set the aspect ratio at boot time here....crashes + ;; if it does it at runtime though, its perfectly fine....what? + ;; else change it and update it (set! (-> obj aspect-ratio-mode) mode) ;; also default to the lowest resolution option at the same time (case mode (('orig-aspect-4x3) - (set! (-> *setting-control* default aspect-ratio) 'aspect4x3) - (set-aspect-ratio (-> *setting-control* default aspect-ratio)) + ; (set! (-> *setting-control* default aspect-ratio) 'aspect4x3) (set-resolution! obj (-> *pc-graphics-4x3-valid-resolutions* 0))) (('orig-aspect-16x9) - (set! (-> *setting-control* default aspect-ratio) 'aspect16x9) - (set-aspect-ratio (-> *setting-control* default aspect-ratio)) + ; (set! (-> *setting-control* default aspect-ratio) 'aspect16x9) (set-resolution! obj (-> *pc-graphics-16x9-valid-resolutions* 0))) (('pc-aspect-4x3) (set-aspect! obj 4 3) - (set! (-> *setting-control* default aspect-ratio) 'aspect4x3) - (set-aspect-ratio (-> *setting-control* default aspect-ratio)) - (set! (-> *setting-control* default aspect-ratio) 'aspect16x9) - (set-aspect-ratio (-> *setting-control* default aspect-ratio)) + ; (set! (-> *setting-control* default aspect-ratio) 'aspect4x3) (set-resolution! obj (-> *pc-graphics-4x3-valid-resolutions* 0))) (('pc-aspect-5x4) (set-aspect! obj 5 4) + ; (set! (-> *setting-control* default aspect-ratio) 'aspect4x3) (set-resolution! obj (-> *pc-graphics-5x4-valid-resolutions* 0))) (('pc-aspect-16x9) (set-aspect! obj 16 9) - (set! (-> *setting-control* default aspect-ratio) 'aspect16x9) - (set-aspect-ratio (-> *setting-control* default aspect-ratio)) + ; (set! (-> *setting-control* default aspect-ratio) 'aspect16x9) (set-resolution! obj (-> *pc-graphics-16x9-valid-resolutions* 0))) (('pc-aspect-21x9) (set-aspect! obj 21 9) - (set! (-> *setting-control* default aspect-ratio) 'aspect16x9) - (set-aspect-ratio (-> *setting-control* default aspect-ratio)) + ; (set! (-> *setting-control* default aspect-ratio) 'aspect16x9) (set-resolution! obj (-> *pc-graphics-21x9-valid-resolutions* 0))) (('pc-aspect-32x9) (set-aspect! obj 32 9) - (set! (-> *setting-control* default aspect-ratio) 'aspect16x9) - (set-aspect-ratio (-> *setting-control* default aspect-ratio)) + ; (set! (-> *setting-control* default aspect-ratio) 'aspect16x9) (set-resolution! obj (-> *pc-graphics-32x9-valid-resolutions* 0)))) + ; (set-aspect-ratio (-> *setting-control* default aspect-ratio)) + (none)) (defmethod set-resolution! pc-settings ((obj pc-settings) (mode symbol)) From d98cf1ff2c5fe465c93d7157be5c8e2e644269b1 Mon Sep 17 00:00:00 2001 From: Tyler Wilding Date: Mon, 14 Mar 2022 02:03:33 -0400 Subject: [PATCH 06/12] runtime: save memcard files to user directory as well --- .vs/launch.vs.json | 2 +- common/util/FileUtil.cpp | 8 ++++++++ common/util/FileUtil.h | 2 ++ game/kernel/kmachine.cpp | 2 +- game/kernel/kmemcard.cpp | 42 +++++++++++++++++++++------------------- 5 files changed, 34 insertions(+), 22 deletions(-) diff --git a/.vs/launch.vs.json b/.vs/launch.vs.json index b3adb4c2ef..3b6301e167 100644 --- a/.vs/launch.vs.json +++ b/.vs/launch.vs.json @@ -54,7 +54,7 @@ "project" : "CMakeLists.txt", "projectTarget" : "gk.exe (bin\\gk.exe)", "name" : "Run - Runtime (with kernel)", - "args" : [ "-fakeiso", "-debug", "-v", "-nodisplay" ] + "args" : [ "-fakeiso", "-debug", "-v" ] }, { "type" : "default", diff --git a/common/util/FileUtil.cpp b/common/util/FileUtil.cpp index 73f3dcd5f1..068e21baa0 100644 --- a/common/util/FileUtil.cpp +++ b/common/util/FileUtil.cpp @@ -48,6 +48,14 @@ std::filesystem::path get_user_game_dir() { return get_user_home_dir() / "OpenGOAL"; } +std::filesystem::path get_user_settings_dir() { + return get_user_game_dir() / "jak1" / "settings"; +} + +std::filesystem::path get_user_memcard_dir() { + return get_user_game_dir() / "jak1" / "saves"; +} + std::string get_project_path() { #ifdef _WIN32 char buffer[FILENAME_MAX]; diff --git a/common/util/FileUtil.h b/common/util/FileUtil.h index c8d8905bf6..51b808de0a 100644 --- a/common/util/FileUtil.h +++ b/common/util/FileUtil.h @@ -15,6 +15,8 @@ namespace fs = std::filesystem; namespace file_util { std::filesystem::path get_user_home_dir(); std::filesystem::path get_user_game_dir(); +std::filesystem::path get_user_settings_dir(); +std::filesystem::path get_user_memcard_dir(); std::string get_project_path(); std::string get_file_path(const std::vector& input); bool create_dir_if_needed(const std::string& path); diff --git a/game/kernel/kmachine.cpp b/game/kernel/kmachine.cpp index 4ed46d79b2..de855026a5 100644 --- a/game/kernel/kmachine.cpp +++ b/game/kernel/kmachine.cpp @@ -877,7 +877,7 @@ void InitMachine_PCPort() { intern_from_c("*pc-user-dir-base-path*")->value = make_string_from_c(user_dir_path.string().c_str()); // TODO - we will eventually need a better way to know what game we are playing - auto settings_path = std::filesystem::path(user_dir_path) / "jak1" / "settings"; + auto settings_path = file_util::get_user_settings_dir(); intern_from_c("*pc-settings-folder*")->value = make_string_from_c(settings_path.string().c_str()); diff --git a/game/kernel/kmemcard.cpp b/game/kernel/kmemcard.cpp index da1f1ed3a1..6d96190396 100644 --- a/game/kernel/kmemcard.cpp +++ b/game/kernel/kmemcard.cpp @@ -100,12 +100,12 @@ void mc_print(const std::string& str, Args&&... args) { } const char* filename[12] = { - "/BASCUS-97124AYBABTU!", "/BASCUS-97124AYBABTU!/icon.sys", - "/BASCUS-97124AYBABTU!/icon.ico", "/BASCUS-97124AYBABTU!/BASCUS-97124AYBABTU!", - "/BASCUS-97124AYBABTU!/bank0.bin", "/BASCUS-97124AYBABTU!/bank1.bin", - "/BASCUS-97124AYBABTU!/bank2.bin", "/BASCUS-97124AYBABTU!/bank3.bin", - "/BASCUS-97124AYBABTU!/bank4.bin", "/BASCUS-97124AYBABTU!/bank5.bin", - "/BASCUS-97124AYBABTU!/bank6.bin", "/BASCUS-97124AYBABTU!/bank7.bin"}; + "BASCUS-97124AYBABTU!", "BASCUS-97124AYBABTU!/icon.sys", + "BASCUS-97124AYBABTU!/icon.ico", "BASCUS-97124AYBABTU!/BASCUS-97124AYBABTU!", + "BASCUS-97124AYBABTU!/bank0.bin", "BASCUS-97124AYBABTU!/bank1.bin", + "BASCUS-97124AYBABTU!/bank2.bin", "BASCUS-97124AYBABTU!/bank3.bin", + "BASCUS-97124AYBABTU!/bank4.bin", "BASCUS-97124AYBABTU!/bank5.bin", + "BASCUS-97124AYBABTU!/bank6.bin", "BASCUS-97124AYBABTU!/bank7.bin"}; void kmemcard_init_globals() { // next = 0; @@ -180,7 +180,7 @@ u32 mc_checksum(Ptr data, s32 size) { * PC port function that returns whether a given bank ID's file exists or not. */ bool file_is_present(int id, int bank = 0) { - auto bankname = file_util::get_file_path({"user", "memcard", filename[4 + id * 2 + bank]}); + auto bankname = file_util::get_user_memcard_dir() / filename[4 + id * 2 + bank]; if (!std::filesystem::exists(bankname)) { // file doesn't exist... return false; @@ -210,14 +210,14 @@ void pc_update_card() { // int highest_save_count = 0; mc_last_file = -1; for (s32 file = 0; file < 4; file++) { - auto bankname = file_util::get_file_path({"user", "memcard", filename[4 + file * 2]}); + auto bankname = file_util::get_user_memcard_dir() / filename[4 + file * 2]; mc_files[file].present = file_is_present(file); if (mc_files[file].present) { - auto bankdata = file_util::read_binary_file(bankname); + auto bankdata = file_util::read_binary_file(bankname.string()); auto header1 = reinterpret_cast(bankdata.data()); if (file_is_present(file, 1)) { - auto bankname2 = file_util::get_file_path({"user", "memcard", filename[1 + 4 + file * 2]}); - auto bankdata2 = file_util::read_binary_file(bankname2); + auto bankname2 = file_util::get_user_memcard_dir() / filename[1 + 4 + file * 2]; + auto bankdata2 = file_util::read_binary_file(bankname2.string()); auto header2 = reinterpret_cast(bankdata.data()); if (header2->save_count > header1->save_count) { @@ -253,7 +253,8 @@ void pc_game_save_synch() { Timer mc_timer; mc_timer.start(); pc_update_card(); - file_util::create_dir_if_needed(file_util::get_file_path({"user", "memcard", filename[0]})); + auto path = file_util::get_user_memcard_dir() / filename[0]; + file_util::create_dir_if_needed(path.string()); // cd_reprobe_save // if (!file_is_present(op.param2)) { @@ -274,9 +275,9 @@ void pc_game_save_synch() { // file*2 + p4 is the bank (2 banks per file, p4 is 0 or 1 to select the bank) // 4 is the first bank file mc_print("open {} for saving", filename[op.param2 * 2 + 4 + p4]); - auto fd = - fopen(file_util::get_file_path({"user", "memcard", filename[op.param2 * 2 + 4 + p4]}).c_str(), - "wb"); + auto save_path = file_util::get_user_memcard_dir() / filename[op.param2 * 2 + 4 + p4]; + file_util::create_dir_if_needed(save_path.string()); + auto fd = fopen(save_path.string().c_str(), "wb"); fmt::print("[MC] synchronous save file open took {:.2f}ms\n", mc_timer.getMs()); if (fd) { // cb_openedsave // @@ -325,6 +326,7 @@ void pc_game_save_synch() { op.result = McStatusCode::INTERNAL_ERROR; } } else { + fmt::print("[MC] Error opening file, errno - {}", errno); op.operation = MemoryCardOperationKind::NO_OP; op.result = McStatusCode::INTERNAL_ERROR; } @@ -344,12 +346,11 @@ void pc_game_load_open_file(FILE* fd) { // cb_closedload // p2++; // added : check if aux bank exists - auto new_bankname = - file_util::get_file_path({"user", "memcard", filename[op.param2 * 2 + 4 + p2]}); + auto new_bankname = file_util::get_user_memcard_dir() / filename[op.param2 * 2 + 4 + p2]; bool aux_exists = std::filesystem::exists(new_bankname); if (p2 < 2 && aux_exists) { mc_print("reading next save bank {}", filename[op.param2 * 2 + 4 + p2]); - auto new_fd = fopen(new_bankname.c_str(), "rb"); + auto new_fd = fopen(new_bankname.string().c_str(), "rb"); pc_game_load_open_file(new_fd); } else { // let's verify the data. @@ -464,8 +465,9 @@ void pc_game_load_synch() { // cb_reprobe_load // p2 = 0; mc_print("opening save file {}", filename[op.param2 * 2 + 4]); - auto fd = fopen( - file_util::get_file_path({"user", "memcard", filename[op.param2 * 2 + 4]}).c_str(), "rb"); + + auto path = file_util::get_user_memcard_dir() / filename[op.param2 * 2 + 4]; + auto fd = fopen(path.string().c_str(), "rb"); pc_game_load_open_file(fd); fmt::print("[MC] synchronous load took {:.2f}ms\n", mc_timer.getMs()); From 14ed38cfd2af57ddb27963a910f9e91199a55d17 Mon Sep 17 00:00:00 2001 From: Tyler Wilding Date: Mon, 14 Mar 2022 19:54:02 -0400 Subject: [PATCH 07/12] runtime: fix `pckernel` load order which resolves setting the orig aspect ratio --- goal_src/build/game_dgos.gc | 2 +- goal_src/dgos/game.gd | 2 +- goal_src/engine/game/settings.gc | 3 --- goal_src/pc/pckernel.gc | 23 ++++++++++++----------- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/goal_src/build/game_dgos.gc b/goal_src/build/game_dgos.gc index 2d04ef7073..2052411fe6 100644 --- a/goal_src/build/game_dgos.gc +++ b/goal_src/build/game_dgos.gc @@ -355,7 +355,6 @@ ("load-dgo.o" "load-dgo") ("ramdisk.o" "ramdisk") ("gsound.o" "gsound") - ("pckernel.o" "pckernel") ;; added ("transformq.o" "transformq") ("collide-func.o" "collide-func") ("joint.o" "joint") @@ -405,6 +404,7 @@ ("game-info.o" "game-info") ("game-save.o" "game-save") ("settings.o" "settings") + ("pckernel.o" "pckernel") ;; added ("mood-tables.o" "mood-tables") ("mood.o" "mood") ("weather-part.o" "weather-part") diff --git a/goal_src/dgos/game.gd b/goal_src/dgos/game.gd index 85c62b276b..7b3573d782 100644 --- a/goal_src/dgos/game.gd +++ b/goal_src/dgos/game.gd @@ -142,7 +142,6 @@ ("load-dgo.o" "load-dgo") ("ramdisk.o" "ramdisk") ("gsound.o" "gsound") - ("pckernel.o" "pckernel") ;; added ("transformq.o" "transformq") ("collide-func.o" "collide-func") ("joint.o" "joint") @@ -192,6 +191,7 @@ ("game-info.o" "game-info") ("game-save.o" "game-save") ("settings.o" "settings") + ("pckernel.o" "pckernel") ;; added ("mood-tables.o" "mood-tables") ("mood.o" "mood") ("weather-part.o" "weather-part") diff --git a/goal_src/engine/game/settings.gc b/goal_src/engine/game/settings.gc index f2a9629f09..46d7ef6e9a 100644 --- a/goal_src/engine/game/settings.gc +++ b/goal_src/engine/game/settings.gc @@ -477,6 +477,3 @@ - - - diff --git a/goal_src/pc/pckernel.gc b/goal_src/pc/pckernel.gc index b13babe7f8..43f709f7e1 100644 --- a/goal_src/pc/pckernel.gc +++ b/goal_src/pc/pckernel.gc @@ -91,42 +91,43 @@ (if (= (-> obj aspect-ratio-mode) mode) (return 0)) - ;; if i set the aspect ratio at boot time here....crashes - ;; if it does it at runtime though, its perfectly fine....what? - ;; else change it and update it (set! (-> obj aspect-ratio-mode) mode) ;; also default to the lowest resolution option at the same time (case mode (('orig-aspect-4x3) - ; (set! (-> *setting-control* default aspect-ratio) 'aspect4x3) (set-resolution! obj (-> *pc-graphics-4x3-valid-resolutions* 0))) (('orig-aspect-16x9) - ; (set! (-> *setting-control* default aspect-ratio) 'aspect16x9) (set-resolution! obj (-> *pc-graphics-16x9-valid-resolutions* 0))) (('pc-aspect-4x3) (set-aspect! obj 4 3) - ; (set! (-> *setting-control* default aspect-ratio) 'aspect4x3) (set-resolution! obj (-> *pc-graphics-4x3-valid-resolutions* 0))) (('pc-aspect-5x4) (set-aspect! obj 5 4) - ; (set! (-> *setting-control* default aspect-ratio) 'aspect4x3) (set-resolution! obj (-> *pc-graphics-5x4-valid-resolutions* 0))) (('pc-aspect-16x9) (set-aspect! obj 16 9) - ; (set! (-> *setting-control* default aspect-ratio) 'aspect16x9) (set-resolution! obj (-> *pc-graphics-16x9-valid-resolutions* 0))) (('pc-aspect-21x9) (set-aspect! obj 21 9) - ; (set! (-> *setting-control* default aspect-ratio) 'aspect16x9) (set-resolution! obj (-> *pc-graphics-21x9-valid-resolutions* 0))) (('pc-aspect-32x9) (set-aspect! obj 32 9) - ; (set! (-> *setting-control* default aspect-ratio) 'aspect16x9) (set-resolution! obj (-> *pc-graphics-32x9-valid-resolutions* 0)))) - ; (set-aspect-ratio (-> *setting-control* default aspect-ratio)) + ;; NOTE - i believe this is a temporary workaround to get the hud looking decent on pc aspect ratios + ;; eventually i assume this will only be required for the original ones! + (case mode + (('orig-aspect-4x3 'pc-aspect-4x3) + (set! (-> *setting-control* default aspect-ratio) 'aspect4x3)) + (else + (set! (-> *setting-control* default aspect-ratio) 'aspect16x9))) + ;; NOTE - it should not be necessarily to call `set-aspect-ratio` as that is + ;; done on a per frame basis as long as it differs from the "current" setting-control value + ;; + ;; However, if I'm wrong, then that needs to be fixed at the build/load level again + ;; as that function is defined in `video` later in the order. (none)) (defmethod set-resolution! pc-settings ((obj pc-settings) (mode symbol)) From 8ebcb36f6ffe25f1c0d5c49e937303afca145d4a Mon Sep 17 00:00:00 2001 From: Tyler Wilding Date: Mon, 14 Mar 2022 19:57:52 -0400 Subject: [PATCH 08/12] lint: format --- .../stack_structures.jsonc | 28 ++------ .../jak1_ntsc_black_label/type_casts.jsonc | 70 ++++++------------- .../jak1_ntsc_black_label/var_names.jsonc | 4 +- game/kernel/kmachine.cpp | 4 +- 4 files changed, 30 insertions(+), 76 deletions(-) diff --git a/decompiler/config/jak1_ntsc_black_label/stack_structures.jsonc b/decompiler/config/jak1_ntsc_black_label/stack_structures.jsonc index 6bf38f1926..a18346a3eb 100644 --- a/decompiler/config/jak1_ntsc_black_label/stack_structures.jsonc +++ b/decompiler/config/jak1_ntsc_black_label/stack_structures.jsonc @@ -5472,33 +5472,19 @@ "ocean-near-add-matrices": [[16, "matrix"]], - "ocean-near-add-upload": [ - [16, "vector"] - ], + "ocean-near-add-upload": [[16, "vector"]], - "draw-ocean-mid": [ - [16, "vector"] - ], + "draw-ocean-mid": [[16, "vector"]], - "draw-ocean-mid-seams": [ - [16, "sphere"] - ], + "draw-ocean-mid-seams": [[16, "sphere"]], - "ocean-mid-add-upload-table": [ - [16, "vector"] - ], + "ocean-mid-add-upload-table": [[16, "vector"]], - "ocean-mid-add-upload": [ - [16, "vector"] - ], + "ocean-mid-add-upload": [[16, "vector"]], - "ocean-mid-check": [ - [16, "vector"] - ], + "ocean-mid-check": [[16, "vector"]], - "ocean-mid-add-matrices": [ - [16, "vector"] - ], + "ocean-mid-add-matrices": [[16, "vector"]], "placeholder-do-not-add-below!": [] } diff --git a/decompiler/config/jak1_ntsc_black_label/type_casts.jsonc b/decompiler/config/jak1_ntsc_black_label/type_casts.jsonc index d79316288c..a081f09630 100644 --- a/decompiler/config/jak1_ntsc_black_label/type_casts.jsonc +++ b/decompiler/config/jak1_ntsc_black_label/type_casts.jsonc @@ -4023,9 +4023,7 @@ [251, "a0", "process-drawable"] ], - "(anon-function 46 racer-states)": [ - [[4, 32], "v1", "target"] - ], + "(anon-function 46 racer-states)": [[[4, 32], "v1", "target"]], "(anon-function 45 racer-states)": [ [19, "a0", "target"], @@ -7263,7 +7261,7 @@ [8, "a0", "dma-packet"], [10, "a0", "dma-packet"] ], - + "ocean-near-add-matrices": [ [7, "a0", "dma-packet"], [12, "a0", "dma-packet"], @@ -7275,9 +7273,7 @@ [47, "v1", "matrix"] ], - "ocean-near-add-constants": [ - [3, "a0", "dma-packet"] - ], + "ocean-near-add-constants": [[3, "a0", "dma-packet"]], "draw-ocean-near": [ [2, "a0", "dma-packet"], @@ -7344,7 +7340,7 @@ [24, "a0", "dma-packet"] ], - "draw-bones-generic-merc":[ + "draw-bones-generic-merc": [ [11, "v1", "generic-merc-ctrl"], [198, "v1", "generic-merc-ctrl"], [274, "a0", "generic-merc-ctrl"], @@ -7358,7 +7354,7 @@ ], "generic-merc-execute-all": [ - [[165,170], "v1", "terrain-context"], + [[165, 170], "v1", "terrain-context"], [92, "a0", "terrain-context"], [96, "v1", "terrain-context"], [100, "v1", "terrain-context"], @@ -7376,7 +7372,7 @@ [32, "a0", "terrain-context"] ], - "generic-work-init":[ + "generic-work-init": [ [10, "a0", "terrain-context"], [13, "a0", "terrain-context"], [16, "a0", "terrain-context"], @@ -7384,13 +7380,9 @@ [[21, 42], "gp", "adgif-shader"] ], - "render-ocean-far": [ - [[23,588], "s5", "(inline-array ocean-vertex)"] - ], + "render-ocean-far": [[[23, 588], "s5", "(inline-array ocean-vertex)"]], - "draw-ocean-far": [ - [[65, 72], "gp", "dma-packet"] - ], + "draw-ocean-far": [[[65, 72], "gp", "dma-packet"]], "ocean-init-buffer": [ [[9, 14], "a2", "dma-packet"], @@ -7427,34 +7419,22 @@ [[114, 117], "v1", "dma-packet"] ], - "ocean-texture-add-constants": [ - [[8, 16], "a0", "dma-packet"] - ], + "ocean-texture-add-constants": [[[8, 16], "a0", "dma-packet"]], - "ocean-texture-add-envmap": [ - [[1, 8], "v1", "(pointer uint128)"] - ], + "ocean-texture-add-envmap": [[[1, 8], "v1", "(pointer uint128)"]], - "ocean-texture-add-verts": [ - [[6, 11], "a0", "dma-packet"] - ], + "ocean-texture-add-verts": [[[6, 11], "a0", "dma-packet"]], "ocean-texture-add-verts-last": [ [[6, 11], "a3", "dma-packet"], [[19, 24], "a0", "dma-packet"] ], - "ocean-texture-add-call-start": [ - [[3, 8], "a0", "dma-packet"] - ], + "ocean-texture-add-call-start": [[[3, 8], "a0", "dma-packet"]], - "ocean-texture-add-call-rest": [ - [[3, 8], "a0", "dma-packet"] - ], + "ocean-texture-add-call-rest": [[[3, 8], "a0", "dma-packet"]], - "ocean-texture-add-call-done": [ - [[3, 8], "a0", "dma-packet"] - ], + "ocean-texture-add-call-done": [[[3, 8], "a0", "dma-packet"]], "draw-ocean-texture": [ [[24, 29], "a0", "dma-packet"], @@ -7531,7 +7511,7 @@ [57, "v1", "(inline-array vector)"] ], - "ocean-near-add-upload":[ + "ocean-near-add-upload": [ [[40, 48], "a0", "dma-packet"], [64, "a2", "(pointer int16)"], [[81, 89], "a1", "vector4w"], @@ -7568,13 +7548,9 @@ [49, "v1", "(pointer uint8)"] ], - "ocean-mid-mask-ptrs-bit?": [ - [31, "a0", "(pointer uint8)"] - ], + "ocean-mid-mask-ptrs-bit?": [[31, "a0", "(pointer uint8)"]], - "ocean-mid-camera-masks-bit?": [ - [25, "a0", "(pointer uint8)"] - ], + "ocean-mid-camera-masks-bit?": [[25, "a0", "(pointer uint8)"]], "ocean-mid-add-upload": [ [[48, 62], "a2", "dma-packet"], @@ -7582,13 +7558,9 @@ [95, "v1", "(pointer uint64)"] ], - "ocean-mid-add-call-flush": [ - [[3, 11], "a0", "dma-packet"] - ], + "ocean-mid-add-call-flush": [[[3, 11], "a0", "dma-packet"]], - "ocean-mid-add-call": [ - [[3, 11], "a0", "dma-packet"] - ], + "ocean-mid-add-call": [[[3, 11], "a0", "dma-packet"]], "ocean-mid-add-matrices": [ [[12, 20], "a0", "dma-packet"], @@ -7596,9 +7568,7 @@ [[41, 46], "s3", "vector"] ], - "ocean-mid-add-constants": [ - [[8, 16], "a0", "dma-packet"] - ], + "ocean-mid-add-constants": [[[8, 16], "a0", "dma-packet"]], "placeholder-do-not-add-below": [] } diff --git a/decompiler/config/jak1_ntsc_black_label/var_names.jsonc b/decompiler/config/jak1_ntsc_black_label/var_names.jsonc index 9a8f088f0d..efd68a5e95 100644 --- a/decompiler/config/jak1_ntsc_black_label/var_names.jsonc +++ b/decompiler/config/jak1_ntsc_black_label/var_names.jsonc @@ -4028,9 +4028,9 @@ } }, - "render-ocean-far" : { + "render-ocean-far": { "vars": { - "s5-0" : ["vertices", "(inline-array ocean-vertex)"] + "s5-0": ["vertices", "(inline-array ocean-vertex)"] } }, diff --git a/game/kernel/kmachine.cpp b/game/kernel/kmachine.cpp index de855026a5..fbcfb96603 100644 --- a/game/kernel/kmachine.cpp +++ b/game/kernel/kmachine.cpp @@ -878,9 +878,7 @@ void InitMachine_PCPort() { make_string_from_c(user_dir_path.string().c_str()); // TODO - we will eventually need a better way to know what game we are playing auto settings_path = file_util::get_user_settings_dir(); - intern_from_c("*pc-settings-folder*")->value = - make_string_from_c(settings_path.string().c_str()); - + intern_from_c("*pc-settings-folder*")->value = make_string_from_c(settings_path.string().c_str()); } void vif_interrupt_callback() { From 2c244da92ed37b6bc3f6f5e0ab152627fd0cba01 Mon Sep 17 00:00:00 2001 From: Tyler Wilding Date: Mon, 14 Mar 2022 20:39:03 -0400 Subject: [PATCH 09/12] cmake: revert warning suppression, it's just causing problems it seems --- CMakeLists.txt | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fd4a2f149a..9e37f234bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -80,9 +80,6 @@ if(ASAN_BUILD) message(STATUS "Doing ASAN build") endif() -# preserve CXX Flags -set(SAVE_CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) - option(CODE_COVERAGE "Enable Code Coverage Compiler Flags" OFF) set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/third-party/cmake/modules/) @@ -110,8 +107,6 @@ add_subdirectory(common) add_subdirectory(decompiler) # build glfw library -string(REPLACE " -W3" " -W0" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") -string(REPLACE " -Wall" " -w" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") add_subdirectory(third-party/glfw) add_subdirectory(third-party/zstd) @@ -119,7 +114,6 @@ add_subdirectory(third-party/zstd) include_directories(third-party/glad/include) include_directories(third-party/glfw/include) add_subdirectory(third-party/imgui) -set(CMAKE_CXX_FLAGS "${SAVE_CMAKE_CXX_FLAGS}") # build the game code in C++ add_subdirectory(game) @@ -134,18 +128,13 @@ add_subdirectory(tools) if(WIN32) set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) endif() -string(REPLACE " -W3" " -W0" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") -string(REPLACE " -Wall" " -w" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") add_subdirectory(third-party/googletest EXCLUDE_FROM_ALL) include(GoogleTest) -set(CMAKE_CXX_FLAGS "${SAVE_CMAKE_CXX_FLAGS}") # build tests include(test/CMakeLists.txt) # build lzokay library -string(REPLACE " -W3" " -W0" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") -string(REPLACE " -Wall" " -w" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") add_subdirectory(third-party/lzokay EXCLUDE_FROM_ALL) # build format library @@ -166,4 +155,3 @@ if(WIN32) add_subdirectory(third-party/mman) endif() -set(CMAKE_CXX_FLAGS "${SAVE_CMAKE_CXX_FLAGS}") From 0cdb0b0ff3c132c2287e72c005508ff9f61e00ff Mon Sep 17 00:00:00 2001 From: Tyler Wilding Date: Mon, 14 Mar 2022 20:39:38 -0400 Subject: [PATCH 10/12] fix the order of the rest of `pckernel` and creation of obj file paths --- common/util/FileUtil.cpp | 10 ++++++++-- common/util/FileUtil.h | 5 +++++ goal_src/build/all_files.gc | 2 +- goal_src/build/game_dgos.gc | 2 +- goal_src/dgos/engine.gd | 2 +- goalc/compiler/compilation/CompilerControl.cpp | 6 +++--- test/goalc/test_goal_kernel.cpp | 2 +- 7 files changed, 20 insertions(+), 9 deletions(-) diff --git a/common/util/FileUtil.cpp b/common/util/FileUtil.cpp index 068e21baa0..e58ccbbe23 100644 --- a/common/util/FileUtil.cpp +++ b/common/util/FileUtil.cpp @@ -105,9 +105,15 @@ std::string get_file_path(const std::vector& input) { } bool create_dir_if_needed(const std::string& path) { - if (!std::filesystem::is_directory(path)) { - return std::filesystem::create_directories(std::filesystem::path(path).parent_path()); + if (std::filesystem::is_directory(path)) { + return std::filesystem::create_directories(path); } else { + // check if the "file" has an extension + auto temp = std::filesystem::path(path); + if (temp.has_extension()) { + return std::filesystem::create_directories(std::filesystem::path(path).parent_path()); + } + // otherwise, assume it's a directory with no trailing slash return std::filesystem::create_directories(path); } } diff --git a/common/util/FileUtil.h b/common/util/FileUtil.h index 51b808de0a..faba11563f 100644 --- a/common/util/FileUtil.h +++ b/common/util/FileUtil.h @@ -19,6 +19,11 @@ std::filesystem::path get_user_settings_dir(); std::filesystem::path get_user_memcard_dir(); std::string get_project_path(); std::string get_file_path(const std::vector& input); +/// +/// Like running a `mkdir -p [path]`. If a file with an extension is provided, the parent_path will be used instead +/// +/// +/// if the path was successfully created bool create_dir_if_needed(const std::string& path); void write_binary_file(const std::string& name, const void* data, size_t size); void write_rgba_png(const std::string& name, void* data, int w, int h); diff --git a/goal_src/build/all_files.gc b/goal_src/build/all_files.gc index a6651ea29c..1cfabb873c 100644 --- a/goal_src/build/all_files.gc +++ b/goal_src/build/all_files.gc @@ -154,7 +154,6 @@ "goal_src/engine/load/load-dgo.gc" "goal_src/engine/load/ramdisk.gc" "goal_src/engine/sound/gsound.gc" - "goal_src/pc/pckernel.gc" ;; added "goal_src/engine/math/transformq.gc" "goal_src/engine/collide/collide-func.gc" "goal_src/engine/anim/joint.gc" @@ -204,6 +203,7 @@ "goal_src/engine/game/game-info.gc" "goal_src/engine/game/game-save.gc" "goal_src/engine/game/settings.gc" + "goal_src/pc/pckernel.gc" ;; added "goal_src/engine/ambient/mood-tables.gc" "goal_src/engine/ambient/mood.gc" "goal_src/engine/ambient/weather-part.gc" diff --git a/goal_src/build/game_dgos.gc b/goal_src/build/game_dgos.gc index 2052411fe6..f0846b0af4 100644 --- a/goal_src/build/game_dgos.gc +++ b/goal_src/build/game_dgos.gc @@ -718,7 +718,6 @@ ("load-dgo.o" "load-dgo") ("ramdisk.o" "ramdisk") ("gsound.o" "gsound") - ("pckernel.o" "pckernel") ;; added ("transformq.o" "transformq") ("collide-func.o" "collide-func") ("joint.o" "joint") @@ -768,6 +767,7 @@ ("game-info.o" "game-info") ("game-save.o" "game-save") ("settings.o" "settings") + ("pckernel.o" "pckernel") ;; added ("mood-tables.o" "mood-tables") ("mood.o" "mood") ("weather-part.o" "weather-part") diff --git a/goal_src/dgos/engine.gd b/goal_src/dgos/engine.gd index a7bafb52f8..7abbc3cad0 100644 --- a/goal_src/dgos/engine.gd +++ b/goal_src/dgos/engine.gd @@ -146,7 +146,6 @@ ("load-dgo.o" "load-dgo") ("ramdisk.o" "ramdisk") ("gsound.o" "gsound") - ("pckernel.o" "pckernel") ;; added ("transformq.o" "transformq") ("collide-func.o" "collide-func") ("joint.o" "joint") @@ -196,6 +195,7 @@ ("game-info.o" "game-info") ("game-save.o" "game-save") ("settings.o" "settings") + ("pckernel.o" "pckernel") ;; added ("mood-tables.o" "mood-tables") ("mood.o" "mood") ("weather-part.o" "weather-part") diff --git a/goalc/compiler/compilation/CompilerControl.cpp b/goalc/compiler/compilation/CompilerControl.cpp index 73de469076..75095e5b9c 100644 --- a/goalc/compiler/compilation/CompilerControl.cpp +++ b/goalc/compiler/compilation/CompilerControl.cpp @@ -212,9 +212,9 @@ Val* Compiler::compile_asm_file(const goos::Object& form, const goos::Object& re // save file if (write) { - file_util::create_dir_if_needed(file_util::get_file_path({"out", "obj"})); - file_util::write_binary_file(file_util::get_file_path({"out", "obj", obj_file_name + ".o"}), - (void*)data.data(), data.size()); + auto path = file_util::get_file_path({"out", "obj", obj_file_name + ".o"}); + file_util::create_dir_if_needed(path); + file_util::write_binary_file(path, (void*)data.data(), data.size()); } } else { if (load) { diff --git a/test/goalc/test_goal_kernel.cpp b/test/goalc/test_goal_kernel.cpp index 2fc7194bfb..917b2146b9 100644 --- a/test/goalc/test_goal_kernel.cpp +++ b/test/goalc/test_goal_kernel.cpp @@ -145,4 +145,4 @@ TEST_F(KernelTest, ThrowXmm) { "now its 10.1000\n" "0\n"; EXPECT_EQ(expected, result); -} \ No newline at end of file +} From 44660c31cd5cef770923bc7b245764b9e48d4690 Mon Sep 17 00:00:00 2001 From: Tyler Wilding Date: Thu, 17 Mar 2022 00:22:13 -0400 Subject: [PATCH 11/12] lint: formatting --- common/util/FileUtil.h | 3 ++- decompiler/config/jak1_ntsc_black_label/type_casts.jsonc | 6 ++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/common/util/FileUtil.h b/common/util/FileUtil.h index faba11563f..34bda372bd 100644 --- a/common/util/FileUtil.h +++ b/common/util/FileUtil.h @@ -20,7 +20,8 @@ std::filesystem::path get_user_memcard_dir(); std::string get_project_path(); std::string get_file_path(const std::vector& input); /// -/// Like running a `mkdir -p [path]`. If a file with an extension is provided, the parent_path will be used instead +/// Like running a `mkdir -p [path]`. If a file with an extension is provided, the parent_path will +/// be used instead /// /// /// if the path was successfully created diff --git a/decompiler/config/jak1_ntsc_black_label/type_casts.jsonc b/decompiler/config/jak1_ntsc_black_label/type_casts.jsonc index 55f9c4ee8f..86569ccd54 100644 --- a/decompiler/config/jak1_ntsc_black_label/type_casts.jsonc +++ b/decompiler/config/jak1_ntsc_black_label/type_casts.jsonc @@ -7274,9 +7274,7 @@ [[40, 46], "s3", "vector"] ], - "ocean-near-add-constants": [ - [[8, 16], "a0", "dma-packet"] - ], + "ocean-near-add-constants": [[[8, 16], "a0", "dma-packet"]], "draw-ocean-near": [ [2, "a0", "dma-packet"], @@ -7573,7 +7571,7 @@ "ocean-mid-add-constants": [[[8, 16], "a0", "dma-packet"]], - "ocean-near-add-heights" : [ + "ocean-near-add-heights": [ [26, "a1", "int"], [[11, 19], "a3", "dma-packet"], [[30, 38], "a2", "dma-packet"] From 4190cf5da80099c5b236b5acde518be74ceab87f Mon Sep 17 00:00:00 2001 From: Tyler Wilding Date: Sat, 19 Mar 2022 20:36:50 -0400 Subject: [PATCH 12/12] game: don't save settings on startup even if they are corrupted --- common/util/FileUtil.cpp | 18 ++++++++---------- common/util/FileUtil.h | 9 +++------ game/kernel/kmachine.cpp | 8 ++++---- game/kernel/kmemcard.cpp | 4 ++-- goal_src/kernel-defs.gc | 2 +- goal_src/pc/pckernel.gc | 13 +++++-------- goalc/compiler/compilation/CompilerControl.cpp | 2 +- 7 files changed, 24 insertions(+), 32 deletions(-) diff --git a/common/util/FileUtil.cpp b/common/util/FileUtil.cpp index e58ccbbe23..2889e5a566 100644 --- a/common/util/FileUtil.cpp +++ b/common/util/FileUtil.cpp @@ -105,17 +105,15 @@ std::string get_file_path(const std::vector& input) { } bool create_dir_if_needed(const std::string& path) { - if (std::filesystem::is_directory(path)) { - return std::filesystem::create_directories(path); - } else { - // check if the "file" has an extension - auto temp = std::filesystem::path(path); - if (temp.has_extension()) { - return std::filesystem::create_directories(std::filesystem::path(path).parent_path()); - } - // otherwise, assume it's a directory with no trailing slash - return std::filesystem::create_directories(path); + if (!std::filesystem::is_directory(path)) { + std::filesystem::create_directories(path); + return true; } + return false; +} + +bool create_dir_if_needed_for_file(const std::string& path) { + return std::filesystem::create_directories(std::filesystem::path(path).parent_path()); } void write_binary_file(const std::string& name, const void* data, size_t size) { diff --git a/common/util/FileUtil.h b/common/util/FileUtil.h index 34bda372bd..35b2806ebd 100644 --- a/common/util/FileUtil.h +++ b/common/util/FileUtil.h @@ -19,13 +19,10 @@ std::filesystem::path get_user_settings_dir(); std::filesystem::path get_user_memcard_dir(); std::string get_project_path(); std::string get_file_path(const std::vector& input); -/// -/// Like running a `mkdir -p [path]`. If a file with an extension is provided, the parent_path will -/// be used instead -/// -/// -/// if the path was successfully created + bool create_dir_if_needed(const std::string& path); +bool create_dir_if_needed_for_file(const std::string& path); + void write_binary_file(const std::string& name, const void* data, size_t size); void write_rgba_png(const std::string& name, void* data, int w, int h); void write_text_file(const std::string& file_name, const std::string& text); diff --git a/game/kernel/kmachine.cpp b/game/kernel/kmachine.cpp index fbcfb96603..d2ddf4aff1 100644 --- a/game/kernel/kmachine.cpp +++ b/game/kernel/kmachine.cpp @@ -819,15 +819,15 @@ void update_discord_rpc(u32 discord_info) { u64 filepath_exists(u32 filepath) { auto filepath_str = std::string(Ptr(filepath).c()->data()); - if (file_util::file_exists(filepath_str)) { + if (std::filesystem::exists(filepath_str)) { return intern_from_c("#t").offset; } - return intern_from_c("#f").offset; + return s7.offset; } void mkdir_path(u32 filepath) { auto filepath_str = std::string(Ptr(filepath).c()->data()); - file_util::create_dir_if_needed(filepath_str); + file_util::create_dir_if_needed_for_file(filepath_str); } void InitMachine_PCPort() { @@ -860,7 +860,7 @@ void InitMachine_PCPort() { // file related functions make_function_symbol_from_c("pc-filepath-exists?", (void*)filepath_exists); - make_function_symbol_from_c("pc-mkdir-path", (void*)mkdir_path); + make_function_symbol_from_c("pc-mkdir-file-path", (void*)mkdir_path); // discord rich presence make_function_symbol_from_c("pc-discord-rpc-set", (void*)set_discord_rpc); diff --git a/game/kernel/kmemcard.cpp b/game/kernel/kmemcard.cpp index 6d96190396..26f7ca5bdc 100644 --- a/game/kernel/kmemcard.cpp +++ b/game/kernel/kmemcard.cpp @@ -254,7 +254,7 @@ void pc_game_save_synch() { mc_timer.start(); pc_update_card(); auto path = file_util::get_user_memcard_dir() / filename[0]; - file_util::create_dir_if_needed(path.string()); + file_util::create_dir_if_needed_for_file(path.string()); // cd_reprobe_save // if (!file_is_present(op.param2)) { @@ -276,7 +276,7 @@ void pc_game_save_synch() { // 4 is the first bank file mc_print("open {} for saving", filename[op.param2 * 2 + 4 + p4]); auto save_path = file_util::get_user_memcard_dir() / filename[op.param2 * 2 + 4 + p4]; - file_util::create_dir_if_needed(save_path.string()); + file_util::create_dir_if_needed_for_file(save_path.string()); auto fd = fopen(save_path.string().c_str(), "wb"); fmt::print("[MC] synchronous save file open took {:.2f}ms\n", mc_timer.getMs()); if (fd) { diff --git a/goal_src/kernel-defs.gc b/goal_src/kernel-defs.gc index 2e661ce55b..4ce936e1fd 100644 --- a/goal_src/kernel-defs.gc +++ b/goal_src/kernel-defs.gc @@ -336,7 +336,7 @@ (define-extern pc-discord-rpc-update (function discord-info none)) (define-extern pc-discord-rpc-set (function int none)) (define-extern pc-filepath-exists? (function string symbol)) -(define-extern pc-mkdir-path (function string none)) +(define-extern pc-mkdir-file-path (function string none)) ;; Constants generated within the C++ runtime (define-extern *pc-user-dir-base-path* string) diff --git a/goal_src/pc/pckernel.gc b/goal_src/pc/pckernel.gc index 43f709f7e1..3a9103adaf 100644 --- a/goal_src/pc/pckernel.gc +++ b/goal_src/pc/pckernel.gc @@ -170,6 +170,7 @@ ;; auto load settings if available (clear *pc-temp-string-1*) (format *pc-temp-string-1* "~S/pc-settings.gc" *pc-settings-folder*) + (pc-mkdir-file-path *pc-temp-string-1*) (write-to-file obj *pc-temp-string-1*) (clear *pc-temp-string-1*) (none)) @@ -808,23 +809,19 @@ (let ((obj (object-new allocation type-to-make (the-as int (-> type-to-make size))))) (reset obj) ;; auto load settings if available - ;; if saved settings are corrupted, reset them + ;; if saved settings are corrupted or not found, use defaults (clear *pc-temp-string-1*) (format *pc-temp-string-1* "~S/pc-settings.gc" *pc-settings-folder*) (if (pc-filepath-exists? *pc-temp-string-1*) (begin (format 0 "[PC] PC Settings found at '~S'...loading!~%" *pc-temp-string-1*) - (if (read-from-file obj *pc-temp-string-1*) - (return obj) + (unless (read-from-file obj *pc-temp-string-1*) (begin - (format 0 "[PC] PC Settings found at '~S' but could not be loaded, re-creating with defaults!~%" *pc-temp-string-1*) + (format 0 "[PC] PC Settings found at '~S' but could not be loaded, using defaults!~%" *pc-temp-string-1*) (reset obj)))) - (format 0 "[PC] PC Settings not found at '~S'...creating and initializing with defaults!~%" *pc-temp-string-1*)) + (format 0 "[PC] PC Settings not found at '~S'...initializing with defaults!~%" *pc-temp-string-1*)) - ;; persist reset / new settings if we made it this far - (pc-mkdir-path *pc-temp-string-1*) - (commit-to-file obj) (clear *pc-temp-string-1*) obj)) diff --git a/goalc/compiler/compilation/CompilerControl.cpp b/goalc/compiler/compilation/CompilerControl.cpp index 75095e5b9c..ab975f8006 100644 --- a/goalc/compiler/compilation/CompilerControl.cpp +++ b/goalc/compiler/compilation/CompilerControl.cpp @@ -213,7 +213,7 @@ Val* Compiler::compile_asm_file(const goos::Object& form, const goos::Object& re // save file if (write) { auto path = file_util::get_file_path({"out", "obj", obj_file_name + ".o"}); - file_util::create_dir_if_needed(path); + file_util::create_dir_if_needed_for_file(path); file_util::write_binary_file(path, (void*)data.data(), data.size()); } } else {