From 90a96eb8bb1a07a3f524a14aa4a43f544af155c5 Mon Sep 17 00:00:00 2001 From: kichikuou Date: Sat, 25 Feb 2023 21:05:53 +0900 Subject: [PATCH 1/3] Use UTF8-aware dirname/basename functions Command line paths containing non-ASCII characters now work on Windows. --- src/asset_manager.c | 1 - src/system4.c | 11 +++-------- subprojects/libsys4 | 2 +- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/asset_manager.c b/src/asset_manager.c index 3896cdd..f15dfb3 100644 --- a/src/asset_manager.c +++ b/src/asset_manager.c @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include diff --git a/src/system4.c b/src/system4.c index 8589dc9..0d1e174 100644 --- a/src/system4.c +++ b/src/system4.c @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include @@ -266,7 +265,7 @@ static bool config_init_with_ini(const char *ini_path) if (!config.ain_filename) ERROR("No AIN filename specified in %s", ini_path); char *tmp = strdup(ini_path); - config.game_dir = strdup(dirname(tmp)); + config.game_dir = strdup(path_dirname(tmp)); free(tmp); config_init(); return true; @@ -286,12 +285,8 @@ static bool config_init_with_dir(const char *dir) static void config_init_with_ain(const char *ain_path) { - char *basename_tmp = strdup(ain_path); - char *dirname_tmp = strdup(ain_path); - config.ain_filename = strdup(basename(basename_tmp)); - config.game_dir = strdup(dirname(dirname_tmp)); - free(basename_tmp); - free(dirname_tmp); + config.ain_filename = strdup(path_basename(ain_path)); + config.game_dir = strdup(path_dirname(ain_path)); config_init(); } diff --git a/subprojects/libsys4 b/subprojects/libsys4 index 481581b..187a463 160000 --- a/subprojects/libsys4 +++ b/subprojects/libsys4 @@ -1 +1 @@ -Subproject commit 481581b3b5833ec676d0578a044fa7c54b421089 +Subproject commit 187a463044a0b9b207f322796aa20c42322fed98 From e53dc6ad0e1204f5b87fa7f5440139953a05a106 Mon Sep 17 00:00:00 2001 From: kichikuou Date: Sat, 25 Feb 2023 21:57:34 +0900 Subject: [PATCH 2/3] Add vm_sleep() The nanosleep() function in mingw-w64 often sleeps for more than the specified time. This causes a problem in Rance 6 combat scene, where the damage popup is noticeably slow. This adds vm_sleep() that calls SDL_Delay() which uses high-resolution timer on Windows. --- include/vm.h | 1 + src/hll/InputDevice.c | 9 ++------- src/hll/Timer.c | 7 ++----- src/vm.c | 11 ++++++----- 4 files changed, 11 insertions(+), 17 deletions(-) diff --git a/include/vm.h b/include/vm.h index b1bca0c..5992fcf 100644 --- a/include/vm.h +++ b/include/vm.h @@ -106,6 +106,7 @@ union vm_value vm_copy(union vm_value v, enum ain_data_type type); int vm_execute_ain(struct ain *program); void vm_call(int fno, int struct_page); int vm_time(void); +void vm_sleep(int ms); void hll_call(int libno, int fno); bool library_exists(int libno); diff --git a/src/hll/InputDevice.c b/src/hll/InputDevice.c index d39733a..cf3e4e6 100644 --- a/src/hll/InputDevice.c +++ b/src/hll/InputDevice.c @@ -14,12 +14,11 @@ * along with this program; if not, see . */ -#include - #include "system4/string.h" #include "hll.h" #include "input.h" +#include "vm.h" static void handle_events_throttled(void) { @@ -28,11 +27,7 @@ static void handle_events_throttled(void) static int count; if (++count == 30) { count = 0; - struct timespec ts = { - .tv_sec = 0, - .tv_nsec = 10000000L - }; - nanosleep(&ts, NULL); + vm_sleep(10); } handle_events(); } diff --git a/src/hll/Timer.c b/src/hll/Timer.c index 92964d6..dfd2598 100644 --- a/src/hll/Timer.c +++ b/src/hll/Timer.c @@ -17,6 +17,7 @@ #include #include "hll.h" +#include "vm.h" HLL_WARN_UNIMPLEMENTED(1, int, Timer, Init, void *imainsystem); @@ -28,11 +29,7 @@ static int Timer_Get(void) static void Timer_Wait(int time) { - struct timespec ts = { - .tv_sec = time / 1000, - .tv_nsec = (time % 1000) * 1000000L - }; - nanosleep(&ts, NULL); + vm_sleep(time); } static void Timer_GetDayTime(int *year, int *month, int *day_of_week, int *day, diff --git a/src/vm.c b/src/vm.c index 78131ef..042a6e0 100644 --- a/src/vm.c +++ b/src/vm.c @@ -570,11 +570,7 @@ static void system_call(enum syscall_code code) } case SYS_SLEEP: {// system.Sleep(int nSleep) int ms = stack_pop().i; - struct timespec ts = { - .tv_sec = ms / 1000, - .tv_nsec = (ms % 1000) * 1000000L - }; - nanosleep(&ts, NULL); + vm_sleep(ms); break; } case SYS_RESUME_READ_COMMENT: {// system.ResumeReadComment(string szKeyName, string szFileName, ref array@string aszComment) @@ -2374,6 +2370,11 @@ int vm_time(void) return (ts.tv_sec * 1000) + (ts.tv_nsec / 1000000); } +void vm_sleep(int ms) +{ + SDL_Delay(ms); +} + _Noreturn void vm_exit(int code) { vm_free(); From d4f7ab06cf6a8bd626ce476e80d3d02acaddf527 Mon Sep 17 00:00:00 2001 From: kichikuou Date: Mon, 6 Mar 2023 20:01:43 +0900 Subject: [PATCH 3/3] Add stub for DrawDungeon14.SetRasterScroll This function is used for the underwater effect in GALZOO. It should be implemented as a post-processing effect, but in the meantime let's stub it out to avoid runtime error. --- src/hll/DrawDungeon.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/hll/DrawDungeon.c b/src/hll/DrawDungeon.c index 6ecdd6e..db6a27f 100644 --- a/src/hll/DrawDungeon.c +++ b/src/hll/DrawDungeon.c @@ -408,6 +408,7 @@ HLL_LIBRARY(DrawDungeon, DRAW_DUNGEON_EXPORTS ); +HLL_WARN_UNIMPLEMENTED( , void, DrawDungeon14, SetRasterScroll, int surface, int type); HLL_WARN_UNIMPLEMENTED( , void, DrawDungeon14, SetRasterAmp, int nSurface, float fAmp); HLL_WARN_UNIMPLEMENTED( , void, DrawDungeon14, SetLapFilter, int surface, int type, int r, int g, int b); @@ -431,7 +432,7 @@ HLL_LIBRARY(DrawDungeon14, HLL_EXPORT(Init, DrawDungeon14_Init), DRAW_DUNGEON_EXPORTS, HLL_EXPORT(GetWalked, dungeon_get_walked), - HLL_TODO_EXPORT(SetRasterScroll, DrawDungeon14_SetRasterScroll), + HLL_EXPORT(SetRasterScroll, DrawDungeon14_SetRasterScroll), HLL_EXPORT(SetRasterAmp, DrawDungeon14_SetRasterAmp), HLL_EXPORT(SetLapFilter, DrawDungeon14_SetLapFilter), HLL_EXPORT(GetDrawMapObjectFlag, DrawDungeon14_GetDrawMapObjectFlag),