game: auto-save pc-settings to user's home directory as well as memcard files (#1233)

* cmake: reduce warning spam especially from libs

* runtime: add FS helper functions

* game: save/restore pc-settings | add original aspect option

* game: overwrite unloadable settings with defaults

* temp: unable to set the games aspect-ratio in the boot else crash?

* runtime: save memcard files to user directory as well

* runtime: fix `pckernel` load order which resolves setting the orig aspect ratio

* lint: format

* cmake: revert warning suppression, it's just causing problems it seems

* fix the order of the rest of `pckernel` and creation of obj file paths

* lint: formatting

* game: don't save settings on startup even if they are corrupted
This commit is contained in:
Tyler Wilding 2022-03-20 20:29:44 -04:00 committed by GitHub
parent 44459757b5
commit 014da6f59d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 424 additions and 322 deletions

View File

@ -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",

View File

@ -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,24 +80,6 @@ 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()
option(CODE_COVERAGE "Enable Code Coverage Compiler Flags" OFF)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/third-party/cmake/modules/)
@ -126,7 +108,6 @@ add_subdirectory(decompiler)
# build glfw library
add_subdirectory(third-party/glfw)
add_subdirectory(third-party/zstd)
# build imgui
@ -158,7 +139,6 @@ 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 +150,8 @@ 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()

View File

@ -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/"

View File

@ -43,6 +43,19 @@ 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::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];
@ -66,6 +79,14 @@ std::string get_project_path() {
}
std::string get_file_path(const std::vector<std::string>& 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;
@ -91,6 +112,10 @@ bool create_dir_if_needed(const std::string& path) {
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) {
FILE* fp = fopen(name.c_str(), "wb");
if (!fp) {

View File

@ -14,9 +14,15 @@ 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<std::string>& input);
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);

View File

@ -51,6 +51,7 @@
"1018": ["AUTO"],
"1019": ["BORDERLESS"],
"1020": ["FULLSCREEN"],
"1021": ["WINDOWED"]
"1021": ["WINDOWED"],
"1049": ["USE ORIGINAL ASPECT"]
}
}

View File

@ -5472,33 +5472,19 @@
"ocean-near-add-matrices": [[16, "vector"]],
"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!": []
}

View File

@ -4032,9 +4032,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"],
@ -7272,7 +7270,7 @@
[8, "a0", "dma-packet"],
[10, "a0", "dma-packet"]
],
"ocean-near-add-matrices": [
[7, "a0", "dma-packet"],
[12, "a0", "dma-packet"],
@ -7285,9 +7283,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"],
@ -7354,7 +7350,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"],
@ -7368,7 +7364,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"],
@ -7386,7 +7382,7 @@
[32, "a0", "terrain-context"]
],
"generic-work-init":[
"generic-work-init": [
[10, "a0", "terrain-context"],
[13, "a0", "terrain-context"],
[16, "a0", "terrain-context"],
@ -7394,13 +7390,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"],
@ -7437,34 +7429,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"],
@ -7541,7 +7521,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"],
@ -7578,13 +7558,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"],
@ -7592,13 +7568,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"],
@ -7606,11 +7578,9 @@
[[41, 46], "s3", "vector"]
],
"ocean-mid-add-constants": [
[[8, 16], "a0", "dma-packet"]
],
"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"]

View File

@ -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)"]
}
},

View File

@ -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<String>(filepath).c()->data());
if (std::filesystem::exists(filepath_str)) {
return intern_from_c("#t").offset;
}
return s7.offset;
}
void mkdir_path(u32 filepath) {
auto filepath_str = std::string(Ptr<String>(filepath).c()->data());
file_util::create_dir_if_needed_for_file(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-file-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,14 @@ 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 = file_util::get_user_settings_dir();
intern_from_c("*pc-settings-folder*")->value = make_string_from_c(settings_path.string().c_str());
}
void vif_interrupt_callback() {

View File

@ -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<u8> 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<McHeader*>(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<McHeader*>(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_for_file(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_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) {
// 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());

View File

@ -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"

View File

@ -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")
@ -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")

View File

@ -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")

View File

@ -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")

View File

@ -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)
@ -482,6 +477,3 @@

View File

@ -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")

View File

@ -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-file-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

View File

@ -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)

View File

@ -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*

View File

@ -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*)
)
)
)

View File

@ -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.

View File

@ -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)

View File

@ -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,53 @@
;; 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-resolution! obj (-> *pc-graphics-4x3-valid-resolutions* 0)))
(('orig-aspect-16x9)
(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))))
;; 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))
"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 +165,16 @@
(('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*)
(pc-mkdir-file-path *pc-temp-string-1*)
(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 +244,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 +263,7 @@
(update-from-os obj)
(update-to-os obj)
(set! (-> obj movie?) (movie?))
(let ((info (new 'stack 'discord-info)))
@ -274,49 +320,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 +373,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 +553,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 +571,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 +704,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,15 +806,24 @@
(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
;; 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*)
obj
)
)
(if (pc-filepath-exists? *pc-temp-string-1*)
(begin
(format 0 "[PC] PC Settings found at '~S'...loading!~%" *pc-temp-string-1*)
(unless (read-from-file obj *pc-temp-string-1*)
(begin
(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'...initializing with defaults!~%" *pc-temp-string-1*))
(clear *pc-temp-string-1*)
obj))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -777,8 +832,6 @@
(define *pc-settings* (new 'global 'pc-settings))
(read-from-file *pc-settings* PC_SETTINGS_FILE_NAME)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

View File

@ -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_for_file(path);
file_util::write_binary_file(path, (void*)data.data(), data.size());
}
} else {
if (load) {

View File

@ -145,4 +145,4 @@ TEST_F(KernelTest, ThrowXmm) {
"now its 10.1000\n"
"0\n";
EXPECT_EQ(expected, result);
}
}