From eb7f06be9a7c4cf62d54e3cf1f287b084d51fcab Mon Sep 17 00:00:00 2001 From: Alexander Batalov Date: Thu, 17 Nov 2022 15:02:12 +0300 Subject: [PATCH] Cleanup input --- src/game/actions.c | 6 +- src/game/anim.c | 8 +- src/game/automap.c | 4 +- src/game/bmpdlog.c | 26 +-- src/game/combat.c | 18 +- src/game/combatai.c | 4 +- src/game/counter.c | 4 +- src/game/credits.c | 12 +- src/game/cycle.c | 16 +- src/game/display.c | 4 +- src/game/editor.c | 88 ++++---- src/game/elevator.c | 8 +- src/game/endgame.c | 40 ++-- src/game/game.c | 11 +- src/game/gdialog.c | 57 ++--- src/game/gmouse.c | 20 +- src/game/gmovie.c | 3 +- src/game/gsound.c | 8 +- src/game/intface.c | 24 +-- src/game/inventry.c | 38 ++-- src/game/lip_sync.c | 2 +- src/game/loadsave.c | 34 +-- src/game/main.c | 16 +- src/game/mainmenu.c | 7 +- src/game/map.c | 16 +- src/game/options.c | 20 +- src/game/palette.c | 4 +- src/game/pipboy.c | 46 ++--- src/game/scripts.c | 15 +- src/game/select.c | 2 +- src/game/selfrun.c | 6 +- src/game/skilldex.c | 4 +- src/game/textobj.c | 10 +- src/game/worldmap.c | 30 +-- src/int/dialog.c | 1 + src/int/intlib.c | 9 +- src/int/intrpret.c | 2 +- src/int/mousemgr.c | 3 +- src/int/movie.c | 4 +- src/int/sound.c | 1 + src/int/sound.h | 4 +- src/movie_lib.c | 2 + src/movie_lib.h | 4 + src/plib/gnw/button.c | 14 +- src/plib/gnw/dxinput.c | 2 + src/plib/gnw/dxinput.h | 2 +- src/plib/gnw/gnw.c | 7 +- src/plib/gnw/input.c | 445 ++++++++++++++++++++++------------------ src/plib/gnw/input.h | 136 ++++-------- src/plib/gnw/intrface.c | 18 +- src/plib/gnw/kb.c | 13 +- src/plib/gnw/mouse.c | 31 +-- src/plib/gnw/vcr.c | 14 +- src/plib/gnw/winmain.c | 4 +- src/plib/gnw/winmain.h | 2 - src/window.c | 3 +- 56 files changed, 675 insertions(+), 657 deletions(-) diff --git a/src/game/actions.c b/src/game/actions.c index aef88fa..db081bf 100644 --- a/src/game/actions.c +++ b/src/game/actions.c @@ -1511,14 +1511,14 @@ Object* pick_object(int objectType, bool a2) foundObject = NULL; do { - _get_input(); + get_input(); } while ((mouse_get_buttons() & MOUSE_EVENT_LEFT_BUTTON_REPEAT) != 0); gmouse_set_cursor(MOUSE_CURSOR_PLUS); gmouse_3d_off(); do { - if (_get_input() == -2) { + if (get_input() == -2) { mouseEvent = mouse_get_buttons(); if ((mouseEvent & MOUSE_EVENT_LEFT_BUTTON_UP) != 0) { keyCode = 0; @@ -1556,7 +1556,7 @@ int pick_hex() elevation = map_elevation; while (1) { - inputEvent = _get_input(); + inputEvent = get_input(); if (inputEvent == -2) { break; } diff --git a/src/game/anim.c b/src/game/anim.c index f41637c..4db6ab9 100644 --- a/src/game/anim.c +++ b/src/game/anim.c @@ -2841,8 +2841,8 @@ void object_animate() Object* object = sad_entry->obj; - unsigned int time = _get_time(); - if (getTicksBetween(time, sad_entry->animationTimestamp) < sad_entry->ticksPerFrame) { + unsigned int time = get_time(); + if (elapsed_tocks(time, sad_entry->animationTimestamp) < sad_entry->ticksPerFrame) { continue; } @@ -3140,8 +3140,8 @@ void dude_fidget() return; } - unsigned int v0 = _get_bk_time(); - if (getTicksBetween(v0, last_time) <= next_time) { + unsigned int v0 = get_bk_time(); + if (elapsed_tocks(v0, last_time) <= next_time) { return; } diff --git a/src/game/automap.c b/src/game/automap.c index da3233b..7173a80 100644 --- a/src/game/automap.c +++ b/src/game/automap.c @@ -380,7 +380,7 @@ void automap(bool isInGame, bool isUsingScanner) // FIXME: There is minor bug in the interface - pressing H/L to toggle // high/low details does not update switch state. - int keyCode = _get_input(); + int keyCode = get_input(); switch (keyCode) { case KEY_TAB: case KEY_ESCAPE: @@ -444,7 +444,7 @@ void automap(bool isInGame, bool isUsingScanner) game_quit_with_confirm(); break; case KEY_F12: - takeScreenshot(); + dump_screen(); break; } diff --git a/src/game/bmpdlog.c b/src/game/bmpdlog.c index 3eded86..a162a14 100644 --- a/src/game/bmpdlog.c +++ b/src/game/bmpdlog.c @@ -450,7 +450,7 @@ int dialog_out(const char* title, const char** body, int bodyLength, int x, int int rc = -1; while (rc == -1) { - int keyCode = _get_input(); + int keyCode = get_input(); if (keyCode == 500) { rc = 1; @@ -670,8 +670,8 @@ int file_dialog(char* title, char** fileList, char* dest, int fileListLength, in int rc = -1; while (rc == -1) { - unsigned int tick = _get_time(); - int keyCode = _get_input(); + unsigned int tick = get_time(); + int keyCode = get_input(); int scrollDirection = FILE_DIALOG_SCROLL_DIRECTION_NONE; int scrollCounter = 0; bool isScrolling = false; @@ -778,7 +778,7 @@ int file_dialog(char* title, char** fileList, char* dest, int fileListLength, in unsigned int scrollDelay = 4; doubleClickSelectedFileIndex = -2; while (1) { - unsigned int scrollTick = _get_time(); + unsigned int scrollTick = get_time(); scrollCounter += 1; if ((!isScrolling && scrollCounter == 1) || (isScrolling && scrollCounter > 14.4)) { isScrolling = true; @@ -822,7 +822,7 @@ int file_dialog(char* title, char** fileList, char* dest, int fileListLength, in } unsigned int delay = (scrollCounter > 14.4) ? 1000 / scrollDelay : 1000 / 24; - while (getTicksSince(scrollTick) < delay) { + while (elapsed_time(scrollTick) < delay) { } if (game_user_wants_to_quit != 0) { @@ -830,7 +830,7 @@ int file_dialog(char* title, char** fileList, char* dest, int fileListLength, in break; } - int keyCode = _get_input(); + int keyCode = get_input(); if (keyCode == 505 || keyCode == 503) { break; } @@ -844,7 +844,7 @@ int file_dialog(char* title, char** fileList, char* dest, int fileListLength, in doubleClickSelectedFileIndex = -2; } - while (getTicksSince(tick) < (1000 / 24)) { + while (elapsed_time(tick) < (1000 / 24)) { } } @@ -1075,8 +1075,8 @@ int save_file_dialog(char* title, char** fileList, char* dest, int fileListLengt int rc = -1; while (rc == -1) { - unsigned int tick = _get_time(); - int keyCode = _get_input(); + unsigned int tick = get_time(); + int keyCode = get_input(); int scrollDirection = FILE_DIALOG_SCROLL_DIRECTION_NONE; int scrollCounter = 0; bool isScrolling = false; @@ -1220,7 +1220,7 @@ int save_file_dialog(char* title, char** fileList, char* dest, int fileListLengt unsigned int scrollDelay = 4; doubleClickSelectedFileIndex = -2; while (1) { - unsigned int scrollTick = _get_time(); + unsigned int scrollTick = get_time(); scrollCounter += 1; if ((!isScrolling && scrollCounter == 1) || (isScrolling && scrollCounter > 14.4)) { isScrolling = true; @@ -1281,7 +1281,7 @@ int save_file_dialog(char* title, char** fileList, char* dest, int fileListLengt // FIXME: Missing windowRefresh makes blinking useless. unsigned int delay = (scrollCounter > 14.4) ? 1000 / scrollDelay : 1000 / 24; - while (getTicksSince(scrollTick) < delay) { + while (elapsed_time(scrollTick) < delay) { } if (game_user_wants_to_quit != 0) { @@ -1289,7 +1289,7 @@ int save_file_dialog(char* title, char** fileList, char* dest, int fileListLengt break; } - int key = _get_input(); + int key = get_input(); if (key == 505 || key == 503) { break; } @@ -1313,7 +1313,7 @@ int save_file_dialog(char* title, char** fileList, char* dest, int fileListLengt doubleClickSelectedFileIndex = -2; } - while (getTicksSince(tick) < (1000 / 24)) { + while (elapsed_time(tick) < (1000 / 24)) { } } diff --git a/src/game/combat.c b/src/game/combat.c index 9e6bd79..9843fe1 100644 --- a/src/game/combat.c +++ b/src/game/combat.c @@ -2483,7 +2483,7 @@ static void combat_begin(Object* a1) { combat_turn_running = 0; anim_stop(); - tickersRemove(dude_fidget); + remove_bk_process(dude_fidget); combat_elev = map_elevation; if (!isInCombat()) { @@ -2548,7 +2548,7 @@ static void combat_begin(Object* a1) register_end(); while (anim_busy(v1)) { - _process_bk(); + process_bk(); } } } @@ -2683,7 +2683,7 @@ static void combat_over() } } - tickersAdd(dude_fidget); + add_bk_process(dude_fidget); for (int index = 0; index < list_noncom + list_com; index++) { Object* critter = combat_list[index]; @@ -2713,7 +2713,7 @@ static void combat_over() register_end(); while (anim_busy(critter)) { - _process_bk(); + process_bk(); } } } @@ -3045,7 +3045,7 @@ void combat_end() void combat_turn_run() { while (combat_turn_running > 0) { - _process_bk(); + process_bk(); } } @@ -3069,10 +3069,10 @@ static int combat_input() break; } - int keyCode = _get_input(); + int keyCode = get_input(); if (action_explode_running()) { while (combat_turn_running > 0) { - _process_bk(); + process_bk(); } } @@ -3221,7 +3221,7 @@ static int combat_turn(Object* a1, bool a2) } while (combat_turn_running > 0) { - _process_bk(); + process_bk(); } if (a1 == obj_dude) { @@ -5467,7 +5467,7 @@ static int get_called_shot_location(Object* critter, int* hitLocation, int hitMo int eventCode; while (true) { - eventCode = _get_input(); + eventCode = get_input(); if (eventCode == KEY_ESCAPE) { break; diff --git a/src/game/combatai.c b/src/game/combatai.c index 6bf26a1..5ba9df3 100644 --- a/src/game/combatai.c +++ b/src/game/combatai.c @@ -2954,7 +2954,7 @@ void combat_ai(Object* a1, Object* a2) // 0x42B3FC bool combatai_want_to_join(Object* a1) { - _process_bk(); + process_bk(); if ((a1->flags & OBJECT_HIDDEN) != 0) { return false; @@ -3000,7 +3000,7 @@ bool combatai_want_to_join(Object* a1) // 0x42B4A8 bool combatai_want_to_stop(Object* a1) { - _process_bk(); + process_bk(); if ((a1->data.critter.combat.maneuver & CRITTER_MANEUVER_STOP_ATTACKING) != 0) { return true; diff --git a/src/game/counter.c b/src/game/counter.c index 180b2ce..fe72643 100644 --- a/src/game/counter.c +++ b/src/game/counter.c @@ -24,7 +24,7 @@ void counter_on(CounterOutputFunc* outputFunc) { if (!counter_is_on) { debug_printf("Turning on counter...\n"); - tickersAdd(counter); + add_bk_process(counter); counter_output_func = outputFunc; counter_is_on = 1; last_time = clock(); @@ -35,7 +35,7 @@ void counter_on(CounterOutputFunc* outputFunc) void counter_off() { if (counter_is_on) { - tickersRemove(counter); + remove_bk_process(counter); counter_is_on = 0; } } diff --git a/src/game/credits.c b/src/game/credits.c index e948f02..05a8e4e 100644 --- a/src/game/credits.c +++ b/src/game/credits.c @@ -148,7 +148,7 @@ void credits(const char* filePath, int backgroundFid, bool useReversedStyle) unsigned char* dest = intermediateBuffer + CREDITS_WINDOW_WIDTH * CREDITS_WINDOW_HEIGHT - CREDITS_WINDOW_WIDTH + (CREDITS_WINDOW_WIDTH - v19) / 2; unsigned char* src = stringBuffer; for (int index = 0; index < lineHeight; index++) { - if (_get_input() != -1) { + if (get_input() != -1) { stop = true; break; } @@ -170,10 +170,10 @@ void credits(const char* filePath, int backgroundFid, bool useReversedStyle) windowBuffer, CREDITS_WINDOW_WIDTH); - while (getTicksSince(tick) < CREDITS_WINDOW_SCROLLING_DELAY) { + while (elapsed_time(tick) < CREDITS_WINDOW_SCROLLING_DELAY) { } - tick = _get_time(); + tick = get_time(); win_draw(window); @@ -187,7 +187,7 @@ void credits(const char* filePath, int backgroundFid, bool useReversedStyle) if (!stop) { for (int index = 0; index < CREDITS_WINDOW_HEIGHT; index++) { - if (_get_input() != -1) { + if (get_input() != -1) { break; } @@ -208,10 +208,10 @@ void credits(const char* filePath, int backgroundFid, bool useReversedStyle) windowBuffer, CREDITS_WINDOW_WIDTH); - while (getTicksSince(tick) < CREDITS_WINDOW_SCROLLING_DELAY) { + while (elapsed_time(tick) < CREDITS_WINDOW_SCROLLING_DELAY) { } - tick = _get_time(); + tick = get_time(); win_draw(window); } diff --git a/src/game/cycle.c b/src/game/cycle.c index 32ae5d0..b339a95 100644 --- a/src/game/cycle.c +++ b/src/game/cycle.c @@ -129,7 +129,7 @@ void cycle_init() monitors[index] >>= 2; } - tickersAdd(cycle_colors); + add_bk_process(cycle_colors); cycle_initialized = true; cycle_enabled = true; @@ -150,7 +150,7 @@ void cycle_reset() last_cycle_medium = 0; last_cycle_fast = 0; last_cycle_very_fast = 0; - tickersAdd(cycle_colors); + add_bk_process(cycle_colors); cycle_enabled = true; } } @@ -159,7 +159,7 @@ void cycle_reset() void cycle_exit() { if (cycle_initialized) { - tickersRemove(cycle_colors); + remove_bk_process(cycle_colors); cycle_initialized = false; cycle_enabled = false; } @@ -214,9 +214,9 @@ static void cycle_colors() bool changed = false; unsigned char* palette = getSystemPalette(); - unsigned int time = _get_time(); + unsigned int time = get_time(); - if (getTicksBetween(time, last_cycle_slow) >= COLOR_CYCLE_PERIOD_SLOW * cycle_speed_factor) { + if (elapsed_tocks(time, last_cycle_slow) >= COLOR_CYCLE_PERIOD_SLOW * cycle_speed_factor) { changed = true; last_cycle_slow = time; @@ -266,7 +266,7 @@ static void cycle_colors() } } - if (getTicksBetween(time, last_cycle_medium) >= COLOR_CYCLE_PERIOD_MEDIUM * cycle_speed_factor) { + if (elapsed_tocks(time, last_cycle_medium) >= COLOR_CYCLE_PERIOD_MEDIUM * cycle_speed_factor) { changed = true; last_cycle_medium = time; @@ -286,7 +286,7 @@ static void cycle_colors() } } - if (getTicksBetween(time, last_cycle_fast) >= COLOR_CYCLE_PERIOD_FAST * cycle_speed_factor) { + if (elapsed_tocks(time, last_cycle_fast) >= COLOR_CYCLE_PERIOD_FAST * cycle_speed_factor) { changed = true; last_cycle_fast = time; @@ -307,7 +307,7 @@ static void cycle_colors() } } - if (getTicksBetween(time, last_cycle_very_fast) >= COLOR_CYCLE_PERIOD_VERY_FAST * cycle_speed_factor) { + if (elapsed_tocks(time, last_cycle_very_fast) >= COLOR_CYCLE_PERIOD_VERY_FAST * cycle_speed_factor) { changed = true; last_cycle_very_fast = time; diff --git a/src/game/display.c b/src/game/display.c index 80c4256..fb1ae56 100644 --- a/src/game/display.c +++ b/src/game/display.c @@ -206,8 +206,8 @@ void display_print(char* str) int knobWidth = text_width(knobString); if (!isInCombat()) { - unsigned int now = _get_bk_time(); - if (getTicksBetween(now, last_time) >= DISPLAY_MONITOR_BEEP_DELAY) { + unsigned int now = get_bk_time(); + if (elapsed_tocks(now, last_time) >= DISPLAY_MONITOR_BEEP_DELAY) { last_time = now; gsound_play_sfx_file("monitor"); } diff --git a/src/game/editor.c b/src/game/editor.c index 8be72f2..ab1517b 100644 --- a/src/game/editor.c +++ b/src/game/editor.c @@ -783,8 +783,8 @@ int editor_design(bool isCreationMode) int rc = -1; while (rc == -1) { - _frame_time = _get_time(); - int keyCode = _get_input(); + _frame_time = get_time(); + int keyCode = get_input(); bool done = false; if (keyCode == 500) { @@ -1123,7 +1123,7 @@ int editor_design(bool isCreationMode) win_draw(edit_win); } else { if (keyCode == 390) { - takeScreenshot(); + dump_screen(); } win_draw(edit_win); @@ -1855,9 +1855,9 @@ int get_input_str(int win, int cancelKeyCode, char* text, int maxLength, int x, int rc = 1; while (rc == 1) { - _frame_time = _get_time(); + _frame_time = get_time(); - int keyCode = _get_input(); + int keyCode = get_input(); if (keyCode == cancelKeyCode) { rc = 0; } else if (keyCode == KEY_RETURN) { @@ -1905,7 +1905,7 @@ int get_input_str(int win, int cancelKeyCode, char* text, int maxLength, int x, win_draw(win); - while (getTicksSince(_frame_time) < 1000 / 24) { } + while (elapsed_time(_frame_time) < 1000 / 24) { } } if (rc == 0 || nameLength > 0) { @@ -2181,7 +2181,7 @@ static void PrintBigNum(int x, int y, int flags, int value, int previousValue, i if (flags & ANIMATE) { if (previousValue % 10 != ones) { - _frame_time = _get_time(); + _frame_time = get_time(); buf_to_buf(numbersGraphicBufferPtr + BIG_NUM_WIDTH * 11, BIG_NUM_WIDTH, BIG_NUM_HEIGHT, @@ -2189,7 +2189,7 @@ static void PrintBigNum(int x, int y, int flags, int value, int previousValue, i onesBufferPtr, windowWidth); win_draw_rect(windowHandle, &rect); - while (getTicksSince(_frame_time) < BIG_NUM_ANIMATION_DELAY) + while (elapsed_time(_frame_time) < BIG_NUM_ANIMATION_DELAY) ; } @@ -2202,7 +2202,7 @@ static void PrintBigNum(int x, int y, int flags, int value, int previousValue, i win_draw_rect(windowHandle, &rect); if (previousValue / 10 != tens) { - _frame_time = _get_time(); + _frame_time = get_time(); buf_to_buf(numbersGraphicBufferPtr + BIG_NUM_WIDTH * 11, BIG_NUM_WIDTH, BIG_NUM_HEIGHT, @@ -2210,7 +2210,7 @@ static void PrintBigNum(int x, int y, int flags, int value, int previousValue, i tensBufferPtr, windowWidth); win_draw_rect(windowHandle, &rect); - while (getTicksSince(_frame_time) < BIG_NUM_ANIMATION_DELAY) + while (elapsed_time(_frame_time) < BIG_NUM_ANIMATION_DELAY) ; } @@ -3319,12 +3319,12 @@ static int AgeWindow() } while (true) { - _frame_time = _get_time(); + _frame_time = get_time(); change = 0; flags = 0; int v32 = 0; - keyCode = _get_input(); + keyCode = get_input(); if (keyCode == KEY_RETURN || keyCode == 500) { if (keyCode != 500) { @@ -3382,7 +3382,7 @@ static int AgeWindow() _repFtime = 4; while (true) { - _frame_time = _get_time(); + _frame_time = get_time(); v33++; @@ -3425,14 +3425,14 @@ static int AgeWindow() } if (v33 > 14.4) { - while (getTicksSince(_frame_time) < 1000 / _repFtime) + while (elapsed_time(_frame_time) < 1000 / _repFtime) ; } else { - while (getTicksSince(_frame_time) < 1000 / 24) + while (elapsed_time(_frame_time) < 1000 / 24) ; } - keyCode = _get_input(); + keyCode = get_input(); if (keyCode == 503 || keyCode == 504 || game_user_wants_to_quit != 0) { break; } @@ -3440,7 +3440,7 @@ static int AgeWindow() } else { win_draw(win); - while (getTicksSince(_frame_time) < 1000 / 24) + while (elapsed_time(_frame_time) < 1000 / 24) ; } } @@ -3547,9 +3547,9 @@ static void SexWindow() win_set_button_rest_state(btns[savedGender], 1, 0); while (true) { - _frame_time = _get_time(); + _frame_time = get_time(); - int eventCode = _get_input(); + int eventCode = get_input(); if (eventCode == KEY_RETURN || eventCode == 500) { if (eventCode == KEY_RETURN) { @@ -3586,7 +3586,7 @@ static void SexWindow() win_draw(win); - while (getTicksSince(_frame_time) < 41) + while (elapsed_time(_frame_time) < 41) ; } @@ -3612,7 +3612,7 @@ static void StatButton(int eventCode) bool cont = true; do { - _frame_time = _get_time(); + _frame_time = get_time(); if (v11 <= 19.2) { v11++; } @@ -3661,13 +3661,13 @@ static void StatButton(int eventCode) if (v11 >= 19.2) { unsigned int delay = 1000 / _repFtime; - while (getTicksSince(_frame_time) < delay) { + while (elapsed_time(_frame_time) < delay) { } } else { - while (getTicksSince(_frame_time) < 1000 / 24) { + while (elapsed_time(_frame_time) < 1000 / 24) { } } - } while (_get_input() != 518 && cont); + } while (get_input() != 518 && cont); DrawInfoWin(); } @@ -3770,7 +3770,7 @@ static int OptionWindow() int rc = 0; while (rc == 0) { - int keyCode = _get_input(); + int keyCode = get_input(); if (game_user_wants_to_quit != 0) { rc = 2; @@ -5039,7 +5039,7 @@ static void SliderBtn(int keyCode) int repeatDelay = 0; for (;;) { - _frame_time = _get_time(); + _frame_time = get_time(); if (repeatDelay <= 19.2) { repeatDelay++; } @@ -5115,14 +5115,14 @@ static void SliderBtn(int keyCode) if (!isUsingKeyboard) { unspentSp = stat_pc_get(PC_STAT_UNSPENT_SKILL_POINTS); if (repeatDelay >= 19.2) { - while (getTicksSince(_frame_time) < 1000 / _repFtime) { + while (elapsed_time(_frame_time) < 1000 / _repFtime) { } } else { - while (getTicksSince(_frame_time) < 1000 / 24) { + while (elapsed_time(_frame_time) < 1000 / 24) { } } - int keyCode = _get_input(); + int keyCode = get_input(); if (keyCode != 522 && keyCode != 524 && rc != -1) { continue; } @@ -5837,7 +5837,7 @@ static int InputPDLoop(int count, void (*refreshProc)()) int rc = 0; while (rc == 0) { - int keyCode = _get_input(); + int keyCode = get_input(); int v19 = 0; if (keyCode == 500) { @@ -5948,7 +5948,7 @@ static int InputPDLoop(int count, void (*refreshProc)()) oldsline = -2; do { - _frame_time = _get_time(); + _frame_time = get_time(); if (v19 <= 14.4) { v19++; } @@ -5974,13 +5974,13 @@ static int InputPDLoop(int count, void (*refreshProc)()) } if (v19 < 14.4) { - while (getTicksSince(_frame_time) < 1000 / 24) { + while (elapsed_time(_frame_time) < 1000 / 24) { } } else { - while (getTicksSince(_frame_time) < 1000 / _repFtime) { + while (elapsed_time(_frame_time) < 1000 / _repFtime) { } } - } while (_get_input() != 574); + } while (get_input() != 574); break; case 573: @@ -5989,7 +5989,7 @@ static int InputPDLoop(int count, void (*refreshProc)()) if (count > 11) { do { - _frame_time = _get_time(); + _frame_time = get_time(); if (v19 <= 14.4) { v19++; } @@ -6016,16 +6016,16 @@ static int InputPDLoop(int count, void (*refreshProc)()) } if (v19 < 14.4) { - while (getTicksSince(_frame_time) < 1000 / 24) { + while (elapsed_time(_frame_time) < 1000 / 24) { } } else { - while (getTicksSince(_frame_time) < 1000 / _repFtime) { + while (elapsed_time(_frame_time) < 1000 / _repFtime) { } } - } while (_get_input() != 575); + } while (get_input() != 575); } else { do { - _frame_time = _get_time(); + _frame_time = get_time(); if (v19 <= 14.4) { v19++; } @@ -6047,13 +6047,13 @@ static int InputPDLoop(int count, void (*refreshProc)()) } if (v19 < 14.4) { - while (getTicksSince(_frame_time) < 1000 / 24) { + while (elapsed_time(_frame_time) < 1000 / 24) { } } else { - while (getTicksSince(_frame_time) < 1000 / _repFtime) { + while (elapsed_time(_frame_time) < 1000 / _repFtime) { } } - } while (_get_input() != 575); + } while (get_input() != 575); } break; case KEY_HOME: @@ -6073,8 +6073,8 @@ static int InputPDLoop(int count, void (*refreshProc)()) refreshProc(); break; default: - if (getTicksSince(_frame_time) > 700) { - _frame_time = _get_time(); + if (elapsed_time(_frame_time) > 700) { + _frame_time = get_time(); oldsline = -2; } break; diff --git a/src/game/elevator.c b/src/game/elevator.c index 6e2dbc1..80e6b40 100644 --- a/src/game/elevator.c +++ b/src/game/elevator.c @@ -402,7 +402,7 @@ int elevator_select(int elevator, int* mapPtr, int* elevationPtr, int* tilePtr) bool done = false; int keyCode; while (!done) { - keyCode = _get_input(); + keyCode = get_input(); if (keyCode == KEY_ESCAPE) { done = true; } @@ -442,7 +442,7 @@ int elevator_select(int elevator, int* mapPtr, int* elevationPtr, int* tilePtr) float v41 = (float)keyCode * v42; float v44 = (float)(*elevationPtr) * v42; do { - unsigned int tick = _get_time(); + unsigned int tick = get_time(); v44 += v43; buf_to_buf( grphbmp[ELEVATOR_FRM_GAUGE] + v18 * (int)v44, @@ -454,11 +454,11 @@ int elevator_select(int elevator, int* mapPtr, int* elevationPtr, int* tilePtr) win_draw(elev_win); - while (getTicksSince(tick) < delay) { + while (elapsed_time(tick) < delay) { } } while ((v43 <= 0.0 || v44 < v41) && (v43 > 0.0 || v44 > v41)); - coreDelayProcessingEvents(200); + pause_for_tocks(200); } } diff --git a/src/game/endgame.c b/src/game/endgame.c index 4e65387..80fce22 100644 --- a/src/game/endgame.c +++ b/src/game/endgame.c @@ -235,10 +235,10 @@ void endgame_movie() map_disable_bk_processes(); palette_fade_to(black_palette); endgame_maybe_done = 0; - tickersAdd(endgame_movie_bk_process); + add_bk_process(endgame_movie_bk_process); gsound_background_callback_set(endgame_movie_callback); gsound_background_play("akiss", 12, 14, 15); - coreDelayProcessingEvents(3000); + pause_for_tocks(3000); // NOTE: Result is ignored. I guess there was some kind of switch for male // vs. female ending, but it was not implemented. @@ -247,7 +247,7 @@ void endgame_movie() credits("credits.txt", -1, false); gsound_background_stop(); gsound_background_callback_set(NULL); - tickersRemove(endgame_movie_bk_process); + remove_bk_process(endgame_movie_bk_process); gsound_background_stop(); loadColorTable("color.pal"); palette_fade_to(cmap); @@ -351,7 +351,7 @@ static void endgame_pan_desert(int direction, const char* narratorFileName) end = width - 640; } - tickersDisable(); + disable_bk(); bool subtitlesLoaded = false; @@ -360,7 +360,7 @@ static void endgame_pan_desert(int direction, const char* narratorFileName) int v12 = 640 - v32; // TODO: Complex math, setup scene in debugger. - if (getTicksSince(since) >= v9) { + if (elapsed_time(since) >= v9) { buf_to_buf(backgroundData + start, ENDGAME_ENDING_WINDOW_WIDTH, ENDGAME_ENDING_WINDOW_HEIGHT, width, endgame_window_buffer, ENDGAME_ENDING_WINDOW_WIDTH); if (subtitlesLoaded) { @@ -369,7 +369,7 @@ static void endgame_pan_desert(int direction, const char* narratorFileName) win_draw(endgame_window); - since = _get_time(); + since = get_time(); bool v14; double v31; @@ -409,14 +409,14 @@ static void endgame_pan_desert(int direction, const char* narratorFileName) soundContinueAll(); - if (_get_input() != -1) { + if (get_input() != -1) { // NOTE: Uninline. endgame_stop_voiceover(); break; } } - tickersEnable(); + enable_bk(); art_ptr_unlock(backgroundHandle); palette_fade_to(black_palette); @@ -425,7 +425,7 @@ static void endgame_pan_desert(int direction, const char* narratorFileName) } while (mouse_get_buttons() != 0) { - _get_input(); + get_input(); } } @@ -456,17 +456,17 @@ static void endgame_display_image(int fid, const char* narratorFileName) palette_fade_to(cmap); - coreDelayProcessingEvents(500); + pause_for_tocks(500); // NOTE: Uninline. endgame_play_voiceover(); - unsigned int referenceTime = _get_time(); - tickersDisable(); + unsigned int referenceTime = get_time(); + disable_bk(); int keyCode; while (true) { - keyCode = _get_input(); + keyCode = get_input(); if (keyCode != -1) { break; } @@ -479,7 +479,7 @@ static void endgame_display_image(int fid, const char* narratorFileName) break; } - if (getTicksSince(referenceTime) > delay) { + if (elapsed_time(referenceTime) > delay) { break; } @@ -489,7 +489,7 @@ static void endgame_display_image(int fid, const char* narratorFileName) soundContinueAll(); } - tickersEnable(); + enable_bk(); gsound_speech_stop(); endgame_clear_subtitles(); @@ -497,13 +497,13 @@ static void endgame_display_image(int fid, const char* narratorFileName) endgame_subtitle_loaded = false; if (keyCode == -1) { - coreDelayProcessingEvents(500); + pause_for_tocks(500); } palette_fade_to(black_palette); while (mouse_get_buttons() != 0) { - _get_input(); + get_input(); } } @@ -687,7 +687,7 @@ static void endgame_play_voiceover() } if (endgame_subtitle_loaded) { - endgame_subtitle_start_time = _get_time(); + endgame_subtitle_start_time = get_time(); } } @@ -782,7 +782,7 @@ static void endgame_show_subtitles() return; } - if (getTicksSince(endgame_subtitle_start_time) > endgame_subtitle_times[endgame_current_subtitle]) { + if (elapsed_time(endgame_subtitle_start_time) > endgame_subtitle_times[endgame_current_subtitle]) { endgame_current_subtitle++; return; } @@ -850,7 +850,7 @@ static void endgame_movie_bk_process() if (endgame_maybe_done) { gsound_background_play("10labone", 11, 14, 16); gsound_background_callback_set(NULL); - tickersRemove(endgame_movie_bk_process); + remove_bk_process(endgame_movie_bk_process); } } diff --git a/src/game/game.c b/src/game/game.c index a4e6205..e65358b 100644 --- a/src/game/game.c +++ b/src/game/game.c @@ -4,6 +4,7 @@ #include #include +#include "window.h" #include "game/actions.h" #include "game/anim.h" #include "game/automap.h" @@ -178,8 +179,8 @@ int game_init(const char* windowTitle, bool isMapper, int font, int a4, int argc text_add_manager(&alias_mgr); text_font(font); - screenshotHandlerConfigure(KEY_F12, game_screendump); - pauseHandlerConfigure(-1, NULL); + register_screendump(KEY_F12, game_screendump); + register_pause(-1, NULL); tile_disable_refresh(); @@ -1057,7 +1058,7 @@ static int game_screendump(int width, int height, unsigned char* buffer, unsigne { MessageListItem messageListItem; - if (screenshotHandlerDefaultImpl(width, height, buffer, palette) != 0) { + if (default_screendump(width, height, buffer, palette) != 0) { // Error saving screenshot. messageListItem.num = 8; if (message_search(&misc_message_file, &messageListItem)) { @@ -1116,11 +1117,11 @@ static void game_help() loadColorTable("art\\intrface\\helpscrn.pal"); palette_set_to(cmap); - while (_get_input() == -1 && game_user_wants_to_quit == 0) { + while (get_input() == -1 && game_user_wants_to_quit == 0) { } while (mouse_get_buttons() != 0) { - _get_input(); + get_input(); } palette_set_to(black_palette); diff --git a/src/game/gdialog.c b/src/game/gdialog.c index 702672b..f3b9689 100644 --- a/src/game/gdialog.c +++ b/src/game/gdialog.c @@ -4,6 +4,7 @@ #include #include +#include "window.h" #include "game/actions.h" #include "plib/color/color.h" #include "game/combat.h" @@ -866,14 +867,14 @@ void gdialogFreeSpeech() // 0x4450EC int gdialogEnableBK() { - tickersAdd(gdialog_bk); + add_bk_process(gdialog_bk); return 0; } // 0x4450FC int gdialogDisableBK() { - tickersRemove(gdialog_bk); + remove_bk_process(gdialog_bk); return 0; } @@ -916,7 +917,7 @@ int gdialogInitFromScript(int headFid, int reaction) talk_need_to_center = 1; gdCreateHeadWindow(); - tickersAdd(gdialog_bk); + add_bk_process(gdialog_bk); gdSetupFidget(headFid, reaction); gdialog_state = 1; gmouse_disable_scrolling(); @@ -946,7 +947,7 @@ int gdialogExitFromScript() gdialogFreeSpeech(); gdReviewFree(); - tickersRemove(gdialog_bk); + remove_bk_process(gdialog_bk); if (PID_TYPE(dialog_target->pid) != OBJ_TYPE_ITEM) { if (gdPlayerTile != obj_dude->tile) { @@ -1414,7 +1415,7 @@ static int gdReviewInit(int* win) win_draw(*win); - tickersRemove(gdialog_bk); + remove_bk_process(gdialog_bk); int backgroundFid = art_id(OBJ_TYPE_INTERFACE, 102, 0, 0, 0); reviewDispBuf = art_ptr_lock_data(backgroundFid, 0, 0, &reviewDispBackKey); @@ -1429,7 +1430,7 @@ static int gdReviewInit(int* win) // 0x445C18 static int gdReviewExit(int* win) { - tickersAdd(gdialog_bk); + add_bk_process(gdialog_bk); for (int index = 0; index < GAME_DIALOG_REVIEW_WINDOW_BUTTON_FRM_COUNT; index++) { if (reviewKeys[index] != INVALID_CACHE_ENTRY) { @@ -1471,7 +1472,7 @@ static int gdReview() gdReviewDisplay(win, v1); while (true) { - int keyCode = _get_input(); + int keyCode = get_input(); if (keyCode == 17 || keyCode == 24 || keyCode == 324) { game_quit_with_confirm(); } @@ -1885,13 +1886,13 @@ static int gdProcess() gdReplyTooBig = 1; } - unsigned int tick = _get_time(); + unsigned int tick = get_time(); int pageCount = 0; int pageIndex = 0; int pageOffsets[10]; pageOffsets[0] = 0; for (;;) { - int keyCode = _get_input(); + int keyCode = get_input(); if (keyCode == KEY_CTRL_Q || keyCode == KEY_CTRL_X || keyCode == KEY_F10) { game_quit_with_confirm(); @@ -1938,9 +1939,9 @@ static int gdProcess() } if (gdReplyTooBig) { - unsigned int v6 = _get_bk_time(); + unsigned int v6 = get_bk_time(); if (v18) { - if (getTicksBetween(v6, tick) >= 10000 || keyCode == KEY_SPACE) { + if (elapsed_tocks(v6, tick) >= 10000 || keyCode == KEY_SPACE) { pageCount++; pageIndex++; pageOffsets[pageCount] = dialogBlock.offset; @@ -1995,7 +1996,7 @@ static int gdProcess() break; } - tick = _get_time(); + tick = get_time(); if (dialogBlock.offset) { v18 = 1; @@ -2549,9 +2550,9 @@ static void gdWaitForFidget() debug_printf("Waiting for fidget to complete...\n"); while (art_frame_max_frame(fidgetFp) > fidgetFrameCounter) { - if (getTicksSince(fidgetLastTime) >= fidgetTocksPerFrame) { + if (elapsed_time(fidgetLastTime) >= fidgetTocksPerFrame) { gdDisplayFrame(fidgetFp, fidgetFrameCounter); - fidgetLastTime = _get_time(); + fidgetLastTime = get_time(); fidgetFrameCounter++; } } @@ -2595,9 +2596,9 @@ static void gdPlayTransition(int anim) int frame = 0; unsigned int time = 0; while (frame < art_frame_max_frame(headFrm)) { - if (getTicksSince(time) >= delay) { + if (elapsed_time(time) >= delay) { gdDisplayFrame(headFrm, frame); - time = _get_time(); + time = get_time(); frame++; } } @@ -2825,7 +2826,7 @@ static void gdialog_bk() } if (can_start_new_fidget) { - if (getTicksSince(fidgetLastTime) >= tocksWaiting) { + if (elapsed_time(fidgetLastTime) >= tocksWaiting) { can_start_new_fidget = false; dialogue_seconds_since_last_input += tocksWaiting / 1000; tocksWaiting = 1000 * (roll_random(0, 3) + 4); @@ -2834,13 +2835,13 @@ static void gdialog_bk() return; } - if (getTicksSince(fidgetLastTime) >= fidgetTocksPerFrame) { + if (elapsed_time(fidgetLastTime) >= fidgetTocksPerFrame) { if (art_frame_max_frame(fidgetFp) <= fidgetFrameCounter) { gdDisplayFrame(fidgetFp, 0); can_start_new_fidget = true; } else { gdDisplayFrame(fidgetFp, fidgetFrameCounter); - fidgetLastTime = _get_time(); + fidgetLastTime = get_time(); fidgetFrameCounter += 1; } } @@ -2940,8 +2941,8 @@ static void gdialog_scroll_subwin(int win, int a2, unsigned char* a3, unsigned c v7 += 10; v9 -= 10 * (GAME_DIALOG_WINDOW_WIDTH); - tick = _get_time(); - while (getTicksSince(tick) < 33) { + tick = get_time(); + while (elapsed_time(tick) < 33) { } } } else { @@ -2975,8 +2976,8 @@ static void gdialog_scroll_subwin(int win, int a2, unsigned char* a3, unsigned c rect.uly += 10; - tick = _get_time(); - while (getTicksSince(tick) < 33) { + tick = get_time(); + while (elapsed_time(tick) < 33) { } } } @@ -3677,7 +3678,7 @@ static void gdControl() bool done = false; while (!done) { - int keyCode = _get_input(); + int keyCode = get_input(); if (keyCode != -1) { if (keyCode == KEY_CTRL_Q || keyCode == KEY_CTRL_X || keyCode == KEY_F10) { game_quit_with_confirm(); @@ -3920,7 +3921,7 @@ static void gdCustom() { bool done = false; while (!done) { - unsigned int keyCode = _get_input(); + unsigned int keyCode = get_input(); if (keyCode != -1) { if (keyCode == KEY_CTRL_Q || keyCode == KEY_CTRL_X || keyCode == KEY_F10) { game_quit_with_confirm(); @@ -4126,7 +4127,7 @@ static int gdCustomSelect(int a1) bool done = false; unsigned int v53 = 0; while (!done) { - int keyCode = _get_input(); + int keyCode = get_input(); if (keyCode == -1) { continue; } @@ -4165,9 +4166,9 @@ static int gdCustomSelect(int a1) continue; } - unsigned int timestamp = _get_time(); + unsigned int timestamp = get_time(); if (newValue == value) { - if (getTicksBetween(timestamp, v53) < 250) { + if (elapsed_tocks(timestamp, v53) < 250) { custom_current_selected[a1] = newValue; gdCustomUpdateSetting(a1, newValue); done = true; diff --git a/src/game/gmouse.c b/src/game/gmouse.c index 5906db5..5775f23 100644 --- a/src/game/gmouse.c +++ b/src/game/gmouse.c @@ -657,9 +657,9 @@ void gmouse_bk_process() return; } - unsigned int v3 = _get_bk_time(); + unsigned int v3 = get_bk_time(); if (mouseX == gmouse_3d_last_mouse_x && mouseY == gmouse_3d_last_mouse_y) { - if (gmouse_3d_hover_test || getTicksBetween(v3, gmouse_3d_last_move_time) < 250) { + if (gmouse_3d_hover_test || elapsed_tocks(v3, gmouse_3d_last_move_time) < 250) { return; } @@ -1005,7 +1005,7 @@ void gmouse_handle_event(int mouseX, int mouseY, int mouseState) gmouse_3d_hover_test = true; gmouse_3d_last_mouse_y = mouseY; gmouse_3d_last_mouse_x = mouseX; - gmouse_3d_last_move_time = _get_time() - 250; + gmouse_3d_last_move_time = get_time() - 250; } return; } @@ -1127,7 +1127,7 @@ void gmouse_handle_event(int mouseX, int mouseY, int mouseState) int v33 = mouseY; int actionIndex = 0; while ((mouse_get_buttons() & MOUSE_EVENT_LEFT_BUTTON_UP) == 0) { - _get_input(); + get_input(); if (game_user_wants_to_quit != 0) { actionMenuItems[actionIndex] = 0; @@ -1156,7 +1156,7 @@ void gmouse_handle_event(int mouseX, int mouseY, int mouseState) gmouse_3d_hover_test = false; gmouse_3d_last_mouse_x = mouseX; gmouse_3d_last_mouse_y = mouseY; - gmouse_3d_last_move_time = _get_time(); + gmouse_3d_last_move_time = get_time(); mouse_set_position(mouseX, v33); @@ -1262,14 +1262,14 @@ int gmouse_set_cursor(int cursor) bool shouldUpdate = true; int frame = 0; if (cursor >= FIRST_GAME_MOUSE_ANIMATED_CURSOR) { - unsigned int tick = _get_time(); + unsigned int tick = get_time(); if ((obj_mouse_flat->flags & OBJECT_HIDDEN) == 0) { gmouse_3d_off(); } unsigned int delay = 1000 / art_frame_fps(mouseCursorFrm); - if (getTicksBetween(tick, gmouse_wait_cursor_time) < delay) { + if (elapsed_tocks(tick, gmouse_wait_cursor_time) < delay) { shouldUpdate = false; } else { if (art_frame_max_frame(mouseCursorFrm) <= gmouse_wait_cursor_frame) { @@ -1405,7 +1405,7 @@ void gmouse_3d_set_mode(int mode) gmouse_3d_current_mode = mode; gmouse_3d_hover_test = false; - gmouse_3d_last_move_time = _get_time(); + gmouse_3d_last_move_time = get_time(); tile_refresh_rect(&rect, map_elevation); @@ -1585,7 +1585,7 @@ void gmouse_3d_on() } gmouse_3d_hover_test = false; - gmouse_3d_last_move_time = _get_time() - 250; + gmouse_3d_last_move_time = get_time() - 250; } // 0x44CE34 @@ -2059,7 +2059,7 @@ static int gmouse_3d_reset() gmouse_3d_last_mouse_x = -1; gmouse_3d_last_mouse_y = -1; gmouse_3d_hover_test = false; - gmouse_3d_last_move_time = _get_time(); + gmouse_3d_last_move_time = get_time(); gmouse_3d_synch_item_highlight(); return 0; diff --git a/src/game/gmovie.c b/src/game/gmovie.c index 913c98d..a3dea8a 100644 --- a/src/game/gmovie.c +++ b/src/game/gmovie.c @@ -6,6 +6,7 @@ #define WIN32_LEAN_AND_MEAN #include +#include "window.h" #include "plib/color/color.h" #include "plib/gnw/input.h" #include "game/cycle.h" @@ -245,7 +246,7 @@ int gmovie_play(int movie, int flags) int v11 = 0; int buttons; do { - if (!moviePlaying() || game_user_wants_to_quit || _get_input() != -1) { + if (!moviePlaying() || game_user_wants_to_quit || get_input() != -1) { break; } diff --git a/src/game/gsound.c b/src/game/gsound.c index b3d53fd..d69b44f 100644 --- a/src/game/gsound.c +++ b/src/game/gsound.c @@ -247,7 +247,7 @@ int gsound_init() return -1; } - tickersAdd(gsound_bkg_proc); + add_bk_process(gsound_bkg_proc); gsound_initialized = true; // SOUNDS @@ -376,7 +376,7 @@ int gsound_exit() return -1; } - tickersRemove(gsound_bkg_proc); + remove_bk_process(gsound_bkg_proc); // NOTE: Uninline. gsound_speech_stop(); @@ -2237,8 +2237,8 @@ int gsound_sfx_q_process(Object* a1, void* data) if (ambientSoundEffectIndex != -1) { char* fileName; if (wmSfxIdxName(ambientSoundEffectIndex, &fileName) == 0) { - int v7 = _get_bk_time(); - if (getTicksBetween(v7, lastTime) >= 5000) { + int v7 = get_bk_time(); + if (elapsed_tocks(v7, lastTime) >= 5000) { if (gsound_play_sfx_file(fileName) == -1) { debug_printf("\nGsound: playing ambient map sfx: %s. FAILED", fileName); } else { diff --git a/src/game/intface.c b/src/game/intface.c index 526b40c..9b91cad 100644 --- a/src/game/intface.c +++ b/src/game/intface.c @@ -1657,14 +1657,14 @@ void intface_end_window_open(bool animated) int time = 0; int frame = 0; while (frame < frameCount) { - if (getTicksSince(time) >= delay) { + if (elapsed_time(time) >= delay) { unsigned char* src = art_frame_data(art, frame, 0); if (src != NULL) { buf_to_buf(src, 57, 58, 57, interfaceBuffer + 640 * 38 + 580, 640); win_draw_rect(interfaceWindow, &endWindowRect); } - time = _get_time(); + time = get_time(); frame++; } gmouse_bk_process(); @@ -1711,7 +1711,7 @@ void intface_end_window_close(bool animated) int frame = art_frame_max_frame(art); while (frame != 0) { - if (getTicksSince(time) >= delay) { + if (elapsed_time(time) >= delay) { unsigned char* src = art_frame_data(art, frame - 1, 0); unsigned char* dest = interfaceBuffer + 640 * 38 + 580; if (src != NULL) { @@ -1719,7 +1719,7 @@ void intface_end_window_close(bool animated) win_draw_rect(interfaceWindow, &endWindowRect); } - time = _get_time(); + time = get_time(); frame--; } gmouse_bk_process(); @@ -2122,7 +2122,7 @@ static void intface_change_fid_animate(int previousWeaponAnimationCode, int weap break; } - _get_input(); + get_input(); } gmouse_set_cursor(MOUSE_CURSOR_NONE); @@ -2381,7 +2381,7 @@ static void intface_rotate_numbers(int x, int y, int previousValue, int value, i buf_to_buf(upSrc, 9, 17, 360, onesDest, 640); mouse_info(); gmouse_bk_process(); - coreDelay(delay); + block_for_tocks(delay); win_draw_rect(interfaceWindow, &numbersRect); ones += v49; @@ -2390,7 +2390,7 @@ static void intface_rotate_numbers(int x, int y, int previousValue, int value, i buf_to_buf(upSrc, 9, 17, 360, tensDest, 640); mouse_info(); gmouse_bk_process(); - coreDelay(delay); + block_for_tocks(delay); win_draw_rect(interfaceWindow, &numbersRect); tens += v49; @@ -2399,7 +2399,7 @@ static void intface_rotate_numbers(int x, int y, int previousValue, int value, i buf_to_buf(upSrc, 9, 17, 360, hundredsDest, 640); mouse_info(); gmouse_bk_process(); - coreDelay(delay); + block_for_tocks(delay); win_draw_rect(interfaceWindow, &numbersRect); hundreds += v49; @@ -2411,19 +2411,19 @@ static void intface_rotate_numbers(int x, int y, int previousValue, int value, i buf_to_buf(downSrc, 9, 17, 360, hundredsDest, 640); mouse_info(); gmouse_bk_process(); - coreDelay(delay); + block_for_tocks(delay); win_draw_rect(interfaceWindow, &numbersRect); } buf_to_buf(downSrc, 9, 17, 360, tensDest, 640); - coreDelay(delay); + block_for_tocks(delay); win_draw_rect(interfaceWindow, &numbersRect); } buf_to_buf(downSrc, 9, 17, 360, onesDest, 640); mouse_info(); gmouse_bk_process(); - coreDelay(delay); + block_for_tocks(delay); win_draw_rect(interfaceWindow, &numbersRect); previousValue += change; @@ -2435,7 +2435,7 @@ static void intface_rotate_numbers(int x, int y, int previousValue, int value, i buf_to_buf(previousValue >= 0 ? plusSrc : minusSrc, 6, 17, 360, signDest, 640); mouse_info(); gmouse_bk_process(); - coreDelay(delay); + block_for_tocks(delay); win_draw_rect(interfaceWindow, &numbersRect); } } diff --git a/src/game/inventry.c b/src/game/inventry.c index 476bda0..aa17b51 100644 --- a/src/game/inventry.c +++ b/src/game/inventry.c @@ -448,7 +448,7 @@ void handle_inventory() inven_set_mouse(INVENTORY_WINDOW_CURSOR_HAND); for (;;) { - int keyCode = _get_input(); + int keyCode = get_input(); if (keyCode == KEY_ESCAPE) { break; @@ -1356,7 +1356,7 @@ void display_body(int fid, int inventoryWindowType) // 0x5190F8 static int curr_rot = 0; - if (getTicksSince(ticker) < INVENTORY_NORMAL_WINDOW_PC_ROTATION_DELAY) { + if (elapsed_time(ticker) < INVENTORY_NORMAL_WINDOW_PC_ROTATION_DELAY) { return; } @@ -1493,7 +1493,7 @@ void display_body(int fid, int inventoryWindowType) art_ptr_unlock(handle); } - ticker = _get_time(); + ticker = get_time(); } // 0x470A2C @@ -1755,7 +1755,7 @@ void inven_pickup(int keyCode, int a2) } do { - _get_input(); + get_input(); display_body(-1, INVENTORY_WINDOW_TYPE_NORMAL); } while ((mouse_get_buttons() & MOUSE_EVENT_LEFT_BUTTON_REPEAT) != 0); @@ -2026,7 +2026,7 @@ void use_inventory_on(Object* a1) display_body(-1, INVENTORY_WINDOW_TYPE_USE_ITEM_ON); - int keyCode = _get_input(); + int keyCode = get_input(); switch (keyCode) { case KEY_HOME: stack_offset[curr_stack] = 0; @@ -3052,7 +3052,7 @@ void inven_action_cursor(int keyCode, int inventoryWindowType) int mouseState; do { - _get_input(); + get_input(); if (inventoryWindowType == INVENTORY_WINDOW_TYPE_NORMAL) { display_body(-1, INVENTORY_WINDOW_TYPE_NORMAL); @@ -3163,7 +3163,7 @@ void inven_action_cursor(int keyCode, int inventoryWindowType) int menuItemIndex = 0; int previousMouseY = y; while ((mouse_get_buttons() & MOUSE_EVENT_LEFT_BUTTON_UP) == 0) { - _get_input(); + get_input(); if (inventoryWindowType == INVENTORY_WINDOW_TYPE_NORMAL) { display_body(-1, INVENTORY_WINDOW_TYPE_NORMAL); @@ -3550,7 +3550,7 @@ int loot_container(Object* a1, Object* a2) break; } - int keyCode = _get_input(); + int keyCode = get_input(); if (keyCode == KEY_CTRL_Q || keyCode == KEY_CTRL_X || keyCode == KEY_F10) { game_quit_with_confirm(); @@ -3849,7 +3849,7 @@ int move_inventory(Object* a1, int a2, Object* a3, bool a4) } do { - _get_input(); + get_input(); } while ((mouse_get_buttons() & MOUSE_EVENT_LEFT_BUTTON_REPEAT) != 0); if (inventoryFrm != NULL) { @@ -4065,7 +4065,7 @@ static void barter_move_inventory(Object* a1, int quantity, int a3, int a4, Obje } do { - _get_input(); + get_input(); } while ((mouse_get_buttons() & MOUSE_EVENT_LEFT_BUTTON_REPEAT) != 0); if (inventoryFrm != NULL) { @@ -4148,7 +4148,7 @@ static void barter_move_from_table_inventory(Object* a1, int quantity, int a3, O } do { - _get_input(); + get_input(); } while ((mouse_get_buttons() & MOUSE_EVENT_LEFT_BUTTON_REPEAT) != 0); if (inventoryFrm != NULL) { @@ -4360,7 +4360,7 @@ void barter_inventory(int win, Object* a2, Object* a3, Object* a4, int a5) break; } - keyCode = _get_input(); + keyCode = get_input(); if (keyCode == KEY_CTRL_Q || keyCode == KEY_CTRL_X || keyCode == KEY_F10) { game_quit_with_confirm(); } @@ -4781,7 +4781,7 @@ static int do_move_timer(int inventoryWindowType, Object* item, int max) bool v5 = false; for (;;) { - int keyCode = _get_input(); + int keyCode = get_input(); if (keyCode == KEY_ESCAPE) { exit_move_timer_win(inventoryWindowType); return -1; @@ -4805,7 +4805,7 @@ static int do_move_timer(int inventoryWindowType, Object* item, int max) if (value < max) { if (inventoryWindowType == INVENTORY_WINDOW_TYPE_MOVE_ITEMS) { if ((mouse_get_buttons() & MOUSE_EVENT_LEFT_BUTTON_REPEAT) != 0) { - _get_time(); + get_time(); unsigned int delay = 100; while ((mouse_get_buttons() & MOUSE_EVENT_LEFT_BUTTON_REPEAT) != 0) { @@ -4814,11 +4814,11 @@ static int do_move_timer(int inventoryWindowType, Object* item, int max) } draw_amount(value, inventoryWindowType); - _get_input(); + get_input(); if (delay > 1) { delay--; - coreDelayProcessingEvents(delay); + pause_for_tocks(delay); } } } else { @@ -4838,7 +4838,7 @@ static int do_move_timer(int inventoryWindowType, Object* item, int max) if (value > min) { if (inventoryWindowType == INVENTORY_WINDOW_TYPE_MOVE_ITEMS) { if ((mouse_get_buttons() & MOUSE_EVENT_LEFT_BUTTON_REPEAT) != 0) { - _get_time(); + get_time(); unsigned int delay = 100; while ((mouse_get_buttons() & MOUSE_EVENT_LEFT_BUTTON_REPEAT) != 0) { @@ -4847,11 +4847,11 @@ static int do_move_timer(int inventoryWindowType, Object* item, int max) } draw_amount(value, inventoryWindowType); - _get_input(); + get_input(); if (delay > 1) { delay--; - coreDelayProcessingEvents(delay); + pause_for_tocks(delay); } } } else { diff --git a/src/game/lip_sync.c b/src/game/lip_sync.c index 4bd0f82..e1e7291 100644 --- a/src/game/lip_sync.c +++ b/src/game/lip_sync.c @@ -167,7 +167,7 @@ int lips_play_speech() int speechVolume = gsound_speech_volume_get(); soundVolume(lip_info.sound, (int)(speechVolume * 0.69)); - speechStartTime = _get_time(); + speechStartTime = get_time(); if (soundPlay(lip_info.sound) != 0) { debug_printf("Failed play!\n"); diff --git a/src/game/loadsave.c b/src/game/loadsave.c index 1feb184..3fc2453 100644 --- a/src/game/loadsave.c +++ b/src/game/loadsave.c @@ -470,8 +470,8 @@ int SaveGame(int mode) int rc = -1; int doubleClickSlot = -1; while (rc == -1) { - unsigned int tick = _get_time(); - int keyCode = _get_input(); + unsigned int tick = get_time(); + int keyCode = get_input(); bool selectionChanged = false; int scrollDirection = LOAD_SAVE_SCROLL_DIRECTION_NONE; @@ -580,7 +580,7 @@ int SaveGame(int mode) bool isScrolling = false; int scrollCounter = 0; do { - unsigned int start = _get_time(); + unsigned int start = get_time(); scrollCounter += 1; if ((!isScrolling && scrollCounter == 1) || (isScrolling && scrollCounter > 14.4)) { @@ -634,12 +634,12 @@ int SaveGame(int mode) } if (scrollCounter > 14.4) { - while (getTicksSince(start) < 1000 / scrollVelocity) { } + while (elapsed_time(start) < 1000 / scrollVelocity) { } } else { - while (getTicksSince(start) < 1000 / 24) { } + while (elapsed_time(start) < 1000 / 24) { } } - keyCode = _get_input(); + keyCode = get_input(); } while (keyCode != 505 && keyCode != 503); } else { if (selectionChanged) { @@ -677,7 +677,7 @@ int SaveGame(int mode) doubleClickSlot = -1; } - while (getTicksSince(tick) < 1000 / 24) { + while (elapsed_time(tick) < 1000 / 24) { } } @@ -951,8 +951,8 @@ int LoadGame(int mode) int rc = -1; int doubleClickSlot = -1; while (rc == -1) { - unsigned int time = _get_time(); - int keyCode = _get_input(); + unsigned int time = get_time(); + int keyCode = get_input(); bool selectionChanged = false; int scrollDirection = 0; @@ -1052,7 +1052,7 @@ int LoadGame(int mode) bool isScrolling = false; int scrollCounter = 0; do { - unsigned int start = _get_time(); + unsigned int start = get_time(); scrollCounter += 1; if ((!isScrolling && scrollCounter == 1) || (isScrolling && scrollCounter > 14.4)) { @@ -1111,12 +1111,12 @@ int LoadGame(int mode) } if (scrollCounter > 14.4) { - while (getTicksSince(start) < 1000 / scrollVelocity) { } + while (elapsed_time(start) < 1000 / scrollVelocity) { } } else { - while (getTicksSince(start) < 1000 / 24) { } + while (elapsed_time(start) < 1000 / 24) { } } - keyCode = _get_input(); + keyCode = get_input(); } while (keyCode != 505 && keyCode != 503); } else { if (selectionChanged) { @@ -1160,7 +1160,7 @@ int LoadGame(int mode) doubleClickSlot = -1; } - while (getTicksSince(time) < 1000 / 24) { } + while (elapsed_time(time) < 1000 / 24) { } } if (rc == 1) { @@ -2158,9 +2158,9 @@ static int get_input_str2(int win, int doneKeyCode, int cancelKeyCode, char* des int rc = 1; while (rc == 1) { - int tick = _get_time(); + int tick = get_time(); - int keyCode = _get_input(); + int keyCode = get_input(); if ((keyCode & 0x80000000) == 0) { v1++; } @@ -2211,7 +2211,7 @@ static int get_input_str2(int win, int doneKeyCode, int cancelKeyCode, char* des win_draw(win); } - while (getTicksSince(tick) < 1000 / 24) { + while (elapsed_time(tick) < 1000 / 24) { } } diff --git a/src/game/main.c b/src/game/main.c index 9b80843..f5708f7 100644 --- a/src/game/main.c +++ b/src/game/main.c @@ -329,7 +329,7 @@ static void main_game_loop() scr_enable(); while (game_user_wants_to_quit == 0) { - int keyCode = _get_input(); + int keyCode = get_input(); game_handle_input(keyCode, false); scripts_check_state(); @@ -523,11 +523,11 @@ static void main_death_scene() } while (mouse_get_buttons() != 0) { - _get_input(); + get_input(); } kb_clear(); - inputEventQueueReset(); + flush_input_buffer(); buf_to_buf(background, 640, 480, 640, windowBuffer, 640); art_ptr_unlock(backgroundHandle); @@ -572,22 +572,22 @@ static void main_death_scene() gsound_speech_play_preloaded(); - unsigned int time = _get_time(); + unsigned int time = get_time(); int keyCode; do { - keyCode = _get_input(); - } while (keyCode == -1 && !main_death_voiceover_done && getTicksSince(time) < delay); + keyCode = get_input(); + } while (keyCode == -1 && !main_death_voiceover_done && elapsed_time(time) < delay); gsound_speech_callback_set(NULL); gsound_speech_stop(); while (mouse_get_buttons() != 0) { - _get_input(); + get_input(); } if (keyCode == -1) { - coreDelayProcessingEvents(500); + pause_for_tocks(500); } palette_fade_to(black_palette); diff --git a/src/game/mainmenu.c b/src/game/mainmenu.c index be48d28..ff6854e 100644 --- a/src/game/mainmenu.c +++ b/src/game/mainmenu.c @@ -13,6 +13,7 @@ #include "game/options.h" #include "game/palette.h" #include "plib/gnw/button.h" +#include "plib/gnw/gnw.h" #include "plib/gnw/text.h" #include "game/version.h" @@ -310,11 +311,11 @@ int main_menu_loop() mouse_show(); } - unsigned int tick = _get_time(); + unsigned int tick = get_time(); int rc = -1; while (rc == -1) { - int keyCode = _get_input(); + int keyCode = get_input(); for (int buttonIndex = 0; buttonIndex < MAIN_MENU_BUTTON_COUNT; buttonIndex++) { if (keyCode == button_values[buttonIndex] || keyCode == toupper(button_values[buttonIndex])) { @@ -360,7 +361,7 @@ int main_menu_loop() } else if (game_user_wants_to_quit == 2) { game_user_wants_to_quit = 0; } else { - if (getTicksSince(tick) >= main_menu_timeout) { + if (elapsed_time(tick) >= main_menu_timeout) { rc = MAIN_MENU_TIMEOUT; } } diff --git a/src/game/map.c b/src/game/map.c index 079eaca..235480b 100644 --- a/src/game/map.c +++ b/src/game/map.c @@ -287,7 +287,7 @@ void map_init() void map_reset() { map_new_map(); - tickersAdd(gmouse_bk_process); + add_bk_process(gmouse_bk_process); gmouse_disable(0); win_show(display_win); } @@ -297,7 +297,7 @@ void map_exit() { win_hide(display_win); gmouse_set_cursor(MOUSE_CURSOR_ARROW); - tickersRemove(gmouse_bk_process); + remove_bk_process(gmouse_bk_process); if (!message_exit(&map_msg_file)) { debug_printf("\nError exiting map_msg_file!"); } @@ -311,8 +311,8 @@ void map_enable_bk_processes() if (!game_ui_is_disabled()) { gmouse_enable(); } - tickersAdd(object_animate); - tickersAdd(dude_fidget); + add_bk_process(object_animate); + add_bk_process(dude_fidget); scr_enable_critters(); map_bk_enabled = true; } @@ -326,8 +326,8 @@ bool map_disable_bk_processes() } scr_disable_critters(); - tickersRemove(dude_fidget); - tickersRemove(object_animate); + remove_bk_process(dude_fidget); + remove_bk_process(object_animate); gmouse_disable(0); text_object_disable(); @@ -597,11 +597,11 @@ int map_get_index_number() // 0x4826C0 int map_scroll(int dx, int dy) { - if (getTicksSince(map_last_scroll_time) < 33) { + if (elapsed_time(map_last_scroll_time) < 33) { return -2; } - map_last_scroll_time = _get_time(); + map_last_scroll_time = get_time(); int screenDx = dx * 32; int screenDy = dy * 24; diff --git a/src/game/options.c b/src/game/options.c index f9bb7d3..7c63ef1 100644 --- a/src/game/options.c +++ b/src/game/options.c @@ -390,7 +390,7 @@ int do_optionsFunc(int initialKeyCode) int rc = -1; while (rc == -1) { - int keyCode = _get_input(); + int keyCode = get_input(); bool showPreferences = false; if (initialKeyCode != -1) { @@ -448,7 +448,7 @@ int do_optionsFunc(int initialKeyCode) } else { switch (keyCode) { case KEY_F12: - takeScreenshot(); + dump_screen(); break; case KEY_UPPERCASE_E: case KEY_LOWERCASE_E: @@ -752,7 +752,7 @@ int PauseWindow(bool a1) bool done = false; while (!done) { - int keyCode = _get_input(); + int keyCode = get_input(); switch (keyCode) { case KEY_PLUS: case KEY_EQUAL: @@ -834,7 +834,7 @@ static int do_prefscreen() int rc = -1; while (rc == -1) { - int eventCode = _get_input(); + int eventCode = get_input(); switch (eventCode) { case KEY_RETURN: @@ -859,7 +859,7 @@ static int do_prefscreen() DecGamma(); break; case KEY_F12: - takeScreenshot(); + dump_screen(); break; case 527: SetDefaults(true); @@ -1169,7 +1169,7 @@ static void DoThing(int eventCode) if (valueChanged) { gsound_play_sfx_file("ib3p1xx1"); - coreDelay(70); + block_for_tocks(70); gsound_play_sfx_file("ib3lu1x1"); UpdateThing(preferenceIndex); win_draw(prfwin); @@ -1203,7 +1203,7 @@ static void DoThing(int eventCode) if (valueChanged) { gsound_play_sfx_file("ib2p1xx1"); - coreDelay(70); + block_for_tocks(70); gsound_play_sfx_file("ib2lu1x1"); UpdateThing(preferenceIndex); win_draw(prfwin); @@ -1242,9 +1242,9 @@ static void DoThing(int eventCode) int sfxVolumeExample = 0; int speechVolumeExample = 0; while (true) { - _get_input(); + get_input(); - int tick = _get_time(); + int tick = get_time(); mouse_get_position(&x, &y); @@ -1379,7 +1379,7 @@ static void DoThing(int eventCode) trans_buf_to_buf(prfbmp[PREFERENCES_WINDOW_FRM_KNOB_ON], 21, 12, 21, prefbuf + PREFERENCES_WINDOW_WIDTH * meta->knobY + v31, PREFERENCES_WINDOW_WIDTH); win_draw(prfwin); - while (getTicksSince(tick) < 35) + while (elapsed_time(tick) < 35) ; } } else if (preferenceIndex == 19) { diff --git a/src/game/palette.c b/src/game/palette.c index d37e736..88cece6 100644 --- a/src/game/palette.c +++ b/src/game/palette.c @@ -27,7 +27,7 @@ void palette_init() memset(white_palette, 63, 256 * 3); memcpy(current_palette, cmap, 256 * 3); - unsigned int tick = _get_time(); + unsigned int tick = get_time(); if (gsound_background_is_enabled() || gsound_speech_is_enabled()) { colorSetFadeBkFunc(soundContinueAll); } @@ -36,7 +36,7 @@ void palette_init() colorSetFadeBkFunc(NULL); - unsigned int diff = getTicksSince(tick); + unsigned int diff = elapsed_time(tick); // NOTE: Modern CPUs are super fast, so it's possible that less than 10ms // (the resolution of underlying GetTicks) is needed to fade between two diff --git a/src/game/pipboy.c b/src/game/pipboy.c index 587af66..69615cc 100644 --- a/src/game/pipboy.c +++ b/src/game/pipboy.c @@ -404,10 +404,10 @@ int pipboy(int intent) } mouse_get_position(&old_mouse_x, &old_mouse_y); - wait_time = _get_time(); + wait_time = get_time(); while (true) { - int keyCode = _get_input(); + int keyCode = get_input(); if (intent == PIPBOY_OPEN_INTENT_REST) { keyCode = 504; @@ -417,14 +417,14 @@ int pipboy(int intent) mouse_get_position(&mouse_x, &mouse_y); if (keyCode != -1 || mouse_x != old_mouse_x || mouse_y != old_mouse_y) { - wait_time = _get_time(); + wait_time = get_time(); old_mouse_x = mouse_x; old_mouse_y = mouse_y; } else { - if (_get_time() - wait_time > PIPBOY_IDLE_TIMEOUT) { + if (get_time() - wait_time > PIPBOY_IDLE_TIMEOUT) { ScreenSaver(); - wait_time = _get_time(); + wait_time = get_time(); mouse_get_position(&old_mouse_x, &old_mouse_y); } } @@ -439,7 +439,7 @@ int pipboy(int intent) } if (keyCode == KEY_F12) { - takeScreenshot(); + dump_screen(); } else if (keyCode >= 500 && keyCode <= 504) { crnt_func = keyCode - 500; PipFnctn[crnt_func](1024); @@ -878,7 +878,7 @@ static void PipStatus(int a1) ListStatLines(a1); ListHoloDiskTitles(-1); win_draw_rect(pip_win, &pip_rect); - coreDelayProcessingEvents(200); + pause_for_tocks(200); stat_flag = 1; } else { if (holocount != 0 && holocount >= a1 && mouse_x > 429) { @@ -906,7 +906,7 @@ static void PipStatus(int a1) ListHoloDiskTitles(holodisk); ListStatLines(-1); win_draw_rect(pip_win, &pip_rect); - coreDelayProcessingEvents(200); + pause_for_tocks(200); NixHotLines(); ShowHoloDisk(); AddHotLines(0, 0, true); @@ -943,7 +943,7 @@ static void PipStatus(int a1) pip_print(text2, PIPBOY_TEXT_ALIGNMENT_RIGHT_COLUMN_CENTER, colorTable[992]); win_draw_rect(pip_win, &pip_rect); - coreDelayProcessingEvents(200); + pause_for_tocks(200); PipStatus(1024); } } else { @@ -967,7 +967,7 @@ static void PipStatus(int a1) pip_print(text2, PIPBOY_TEXT_ALIGNMENT_RIGHT_COLUMN_CENTER, colorTable[992]); win_draw_rect(pip_win, &pip_rect); - coreDelayProcessingEvents(200); + pause_for_tocks(200); view_page += 1; @@ -997,7 +997,7 @@ static void PipStatus(int a1) pip_print(text2, PIPBOY_TEXT_ALIGNMENT_RIGHT_COLUMN_CENTER, colorTable[992]); win_draw_rect(pip_win, &pip_rect); - coreDelayProcessingEvents(200); + pause_for_tocks(200); view_page -= 1; @@ -1030,7 +1030,7 @@ static void PipStatus(int a1) pip_print(text2, PIPBOY_TEXT_ALIGNMENT_RIGHT_COLUMN_CENTER, colorTable[992]); win_draw_rect(pip_win, &pip_rect); - coreDelayProcessingEvents(200); + pause_for_tocks(200); if (view_page <= 0) { PipStatus(1024); @@ -1048,7 +1048,7 @@ static void PipStatus(int a1) gsound_play_sfx_file("ib1p1xx1"); pip_back(colorTable[32747]); win_draw_rect(pip_win, &pip_rect); - coreDelayProcessingEvents(200); + pause_for_tocks(200); PipStatus(1024); } @@ -1647,7 +1647,7 @@ static void PipArchives(int a1) text_font(101); - wait_time = _get_time(); + wait_time = get_time(); ListArchive(-1); } } @@ -1933,7 +1933,7 @@ static bool TimedRest(int hours, int minutes, int duration) break; } - unsigned int start = _get_time(); + unsigned int start = get_time(); unsigned int v6 = (unsigned int)((double)v5 / v4 * ((double)minutes * 600.0) + (double)gameTime); unsigned int nextEventTime = queue_next_time(); @@ -1953,7 +1953,7 @@ static bool TimedRest(int hours, int minutes, int duration) if (!rc) { gameTimeSetTime(v6); - if (_get_input() == KEY_ESCAPE || game_user_wants_to_quit != 0) { + if (get_input() == KEY_ESCAPE || game_user_wants_to_quit != 0) { rc = true; } @@ -1961,7 +1961,7 @@ static bool TimedRest(int hours, int minutes, int duration) pip_date(); win_draw(pip_win); - while (getTicksSince(start) < 50) { + while (elapsed_time(start) < 50) { } } } @@ -1990,9 +1990,9 @@ static bool TimedRest(int hours, int minutes, int duration) break; } - unsigned int start = _get_time(); + unsigned int start = get_time(); - if (_get_input() == KEY_ESCAPE || game_user_wants_to_quit != 0) { + if (get_input() == KEY_ESCAPE || game_user_wants_to_quit != 0) { rc = true; } @@ -2027,7 +2027,7 @@ static bool TimedRest(int hours, int minutes, int duration) DrawAlrmHitPnts(); win_draw(pip_win); - while (getTicksSince(start) < 50) { + while (elapsed_time(start) < 50) { } } } @@ -2207,10 +2207,10 @@ static int ScreenSaver() int v31 = 50; while (true) { - unsigned int time = _get_time(); + unsigned int time = get_time(); mouse_get_position(&mouse_x, &mouse_y); - if (_get_input() != -1 || old_mouse_x != mouse_x || old_mouse_y != mouse_y) { + if (get_input() != -1 || old_mouse_x != mouse_x || old_mouse_y != mouse_y) { break; } @@ -2322,7 +2322,7 @@ static int ScreenSaver() v31 -= 1; } else { win_draw_rect(pip_win, &pip_rect); - while (getTicksSince(time) < 50) { + while (elapsed_time(time) < 50) { } } } diff --git a/src/game/scripts.c b/src/game/scripts.c index f5ca976..d7932ba 100644 --- a/src/game/scripts.c +++ b/src/game/scripts.c @@ -5,6 +5,7 @@ #include #include +#include "window.h" #include "game/actions.h" #include "game/automap.h" #include "game/combat.h" @@ -599,11 +600,11 @@ static void doBkProcesses() static int lasttime; if (!set) { - lasttime = _get_bk_time(); + lasttime = get_bk_time(); set = 1; } - int v0 = _get_bk_time(); + int v0 = get_bk_time(); if (script_engine_running) { lasttime = v0; @@ -679,7 +680,7 @@ static void script_chk_timed_events() // 0x51C7E4 static int last_light_time = 0; - int v0 = _get_bk_time(); + int v0 = get_bk_time(); int v1 = false; if (!isInCombat()) { @@ -687,7 +688,7 @@ static void script_chk_timed_events() } if (game_state() != GAME_STATE_4) { - if (getTicksBetween(v0, last_light_time) >= 30000) { + if (elapsed_tocks(v0, last_light_time) >= 30000) { last_light_time = v0; scrExecMapProcScripts(SCRIPT_PROC_MAP_UPDATE); } @@ -695,7 +696,7 @@ static void script_chk_timed_events() v1 = false; } - if (getTicksBetween(v0, last_time) >= 100) { + if (elapsed_tocks(v0, last_time) >= 100) { last_time = v0; if (!isInCombat()) { fallout_game_time += 1; @@ -1504,7 +1505,7 @@ int scr_game_init() script_engine_game_mode = 1; fallout_game_time = 1; gameTimeSetTime(302400); - tickersAdd(doBkProcesses); + add_bk_process(doBkProcesses); if (scr_set_dude_script() == -1) { return -1; @@ -1584,7 +1585,7 @@ int scr_game_exit() scr_message_free(); scr_remove_all(); clearPrograms(); - tickersRemove(doBkProcesses); + remove_bk_process(doBkProcesses); message_exit(&script_message_file); if (scr_clear_dude_script() == -1) { return -1; diff --git a/src/game/select.c b/src/game/select.c index 028b826..17b3524 100644 --- a/src/game/select.c +++ b/src/game/select.c @@ -211,7 +211,7 @@ int select_character() break; } - int keyCode = _get_input(); + int keyCode = get_input(); switch (keyCode) { case KEY_MINUS: diff --git a/src/game/selfrun.c b/src/game/selfrun.c index 2f0f801..f4cfd9c 100644 --- a/src/game/selfrun.c +++ b/src/game/selfrun.c @@ -95,14 +95,14 @@ void selfrun_playback_loop(SelfrunData* selfrunData) } while (selfrun_state == SELFRUN_STATE_PLAYING) { - int keyCode = _get_input(); + int keyCode = get_input(); if (keyCode != selfrunData->stopKeyCode) { game_handle_input(keyCode, false); } } while (mouse_get_buttons() != 0) { - _get_input(); + get_input(); } if (cursorWasHidden) { @@ -161,7 +161,7 @@ void selfrun_recording_loop(SelfrunData* selfrunData) bool done = false; while (!done) { - int keyCode = _get_input(); + int keyCode = get_input(); if (keyCode == selfrunData->stopKeyCode) { vcr_stop(); game_user_wants_to_quit = 2; diff --git a/src/game/skilldex.c b/src/game/skilldex.c index fa84403..a58bd8e 100644 --- a/src/game/skilldex.c +++ b/src/game/skilldex.c @@ -121,7 +121,7 @@ int skilldex_select() int rc = -1; while (rc == -1) { - int keyCode = _get_input(); + int keyCode = get_input(); if (keyCode == KEY_ESCAPE || keyCode == 500 || game_user_wants_to_quit != 0) { rc = 0; @@ -134,7 +134,7 @@ int skilldex_select() } if (rc != 0) { - coreDelay(1000 / 9); + block_for_tocks(1000 / 9); } skilldex_end(); diff --git a/src/game/textobj.c b/src/game/textobj.c index 86dc924..35afce2 100644 --- a/src/game/textobj.c +++ b/src/game/textobj.c @@ -79,7 +79,7 @@ int text_object_init(unsigned char* windowBuffer, int width, int height) display_height = height; text_object_index = 0; - tickersAdd(text_object_bk); + add_bk_process(text_object_bk); double textBaseDelay; if (!config_get_double(&game_config, GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_TEXT_BASE_DELAY_KEY, &textBaseDelay)) { @@ -113,7 +113,7 @@ int text_object_reset() } text_object_index = 0; - tickersAdd(text_object_bk); + add_bk_process(text_object_bk); return 0; } @@ -123,7 +123,7 @@ void text_object_exit() { if (text_object_initialized) { text_object_reset(); - tickersRemove(text_object_bk); + remove_bk_process(text_object_bk); text_object_initialized = false; } } @@ -311,7 +311,7 @@ int text_object_create(Object* object, char* string, int font, int color, int a5 text_object_remove(object); textObject->owner = object; - textObject->time = _get_bk_time(); + textObject->time = get_bk_time(); text_object_list[text_object_index] = textObject; text_object_index++; @@ -370,7 +370,7 @@ static void text_object_bk() TextObject* textObject = text_object_list[index]; unsigned int delay = text_object_line_delay * textObject->linesCount + text_object_base_delay; - if ((textObject->flags & TEXT_OBJECT_MARKED_FOR_REMOVAL) != 0 || (getTicksBetween(_get_bk_time(), textObject->time) > delay)) { + if ((textObject->flags & TEXT_OBJECT_MARKED_FOR_REMOVAL) != 0 || (elapsed_tocks(get_bk_time(), textObject->time) > delay)) { tile_coord(textObject->tile, &(textObject->x), &(textObject->y), map_elevation); textObject->x += textObject->sx; textObject->y += textObject->sy; diff --git a/src/game/worldmap.c b/src/game/worldmap.c index f31c35a..9cc15f1 100644 --- a/src/game/worldmap.c +++ b/src/game/worldmap.c @@ -3051,8 +3051,8 @@ static int wmWorldMapFunc(int a1) int rc = 0; for (;;) { - int keyCode = _get_input(); - unsigned int tick = _get_time(); + int keyCode = get_input(); + unsigned int tick = get_time(); int mouseX; int mouseY; @@ -3136,7 +3136,7 @@ static int wmWorldMapFunc(int a1) wmInterfaceRefresh(); - if (getTicksBetween(tick, v24) > 1000) { + if (elapsed_tocks(tick, v24) > 1000) { if (partyMemberRestingHeal(3)) { intface_update_hit_points(false); v24 = tick; @@ -3354,8 +3354,8 @@ static void wmCheckGameEvents() // 0x4C0634 static int wmRndEncounterOccurred() { - unsigned int v0 = _get_time(); - if (getTicksBetween(v0, wmLastRndTime) < 1500) { + unsigned int v0 = get_time(); + if (elapsed_tocks(v0, wmLastRndTime) < 1500) { return 0; } @@ -3457,7 +3457,7 @@ static int wmRndEncounterOccurred() return -1; } - coreDelay(200); + block_for_tocks(200); } if (wmGenData.isInCar) { @@ -4481,7 +4481,7 @@ static int wmInterfaceInit() Art* frm; CacheEntry* frmHandle; - wmLastRndTime = _get_time(); + wmLastRndTime = get_time(); wmGenData.oldFont = text_curr(); text_font(0); @@ -4835,7 +4835,7 @@ static int wmInterfaceInit() wmGenData.carImageFrmHeight = art_frame_length(wmGenData.carImageFrm, 0, 0); } - tickersAdd(wmMouseBkProc); + add_bk_process(wmMouseBkProc); if (wmMakeTabsLabelList(&wmLabelList, &wmLabelCount) == -1) { return -1; @@ -4860,7 +4860,7 @@ static int wmInterfaceExit() int i; TileInfo* tile; - tickersRemove(wmMouseBkProc); + remove_bk_process(wmMouseBkProc); if (wmBkArtBuf != NULL) { art_ptr_unlock(wmBkKey); @@ -5159,9 +5159,9 @@ static void wmMouseBkProc() } } - unsigned int tick = _get_bk_time(); - if (getTicksBetween(tick, lastTime) > 50) { - lastTime = _get_bk_time(); + unsigned int tick = get_bk_time(); + if (elapsed_tocks(tick, lastTime) > 50) { + lastTime = get_bk_time(); // NOTE: Uninline. wmInterfaceScroll(dx, dy, &couldScroll); } @@ -5967,7 +5967,7 @@ static int wmTownMapFunc(int* mapIdxPtr) CityInfo* city = &(wmAreaInfoList[wmGenData.currentAreaId]); for (;;) { - int keyCode = _get_input(); + int keyCode = get_input(); if (keyCode == KEY_CTRL_Q || keyCode == KEY_CTRL_X || keyCode == KEY_F10) { game_quit_with_confirm(); } @@ -6093,7 +6093,7 @@ static int wmTownMapInit() } } - tickersRemove(wmMouseBkProc); + remove_bk_process(wmMouseBkProc); if (wmTownMapRefresh() == -1) { return -1; @@ -6166,7 +6166,7 @@ static int wmTownMapExit() return -1; } - tickersAdd(wmMouseBkProc); + add_bk_process(wmMouseBkProc); return 0; } diff --git a/src/int/dialog.c b/src/int/dialog.c index 92ec7d7..624b2cb 100644 --- a/src/int/dialog.c +++ b/src/int/dialog.c @@ -2,6 +2,7 @@ #include +#include "window.h" #include "plib/gnw/input.h" #include "int/memdbg.h" #include "int/movie.h" diff --git a/src/int/intlib.c b/src/int/intlib.c index ad13959..4dca4a5 100644 --- a/src/int/intlib.c +++ b/src/int/intlib.c @@ -1,5 +1,8 @@ #include "int/intlib.h" +#include + +#include "window.h" #include "plib/color/color.h" #include "plib/gnw/input.h" #include "int/datafile.h" @@ -539,7 +542,7 @@ static void interpretFadePaletteBK(unsigned char* oldPalette, unsigned char* new int index; unsigned char palette[256 * 3]; - time = _get_time(); + time = get_time(); previousTime = time; steps = (int)duration; step = 0; @@ -559,10 +562,10 @@ static void interpretFadePaletteBK(unsigned char* oldPalette, unsigned char* new } if (shouldProcessBk) { - _process_bk(); + process_bk(); } - time = _get_time(); + time = get_time(); delta = time - previousTime; } } diff --git a/src/int/intrpret.c b/src/int/intrpret.c index a6a12d0..da3ef2f 100644 --- a/src/int/intrpret.c +++ b/src/int/intrpret.c @@ -163,7 +163,7 @@ static int suspendEvents; // 0x4670A0 static unsigned int defaultTimerFunc() { - return _get_time(); + return get_time(); } // NOTE: Unused. diff --git a/src/int/mousemgr.c b/src/int/mousemgr.c index 0a74679..8699c0d 100644 --- a/src/int/mousemgr.c +++ b/src/int/mousemgr.c @@ -1,5 +1,6 @@ #include "int/mousemgr.h" +#include #include #include "plib/gnw/input.h" @@ -106,7 +107,7 @@ static int defaultRateCallback() // 0x48525C static int defaultTimeCallback() { - return _get_time(); + return get_time(); } // NOTE: Inlined. diff --git a/src/int/movie.c b/src/int/movie.c index 5bf953a..5a326d8 100644 --- a/src/int/movie.c +++ b/src/int/movie.c @@ -2,6 +2,7 @@ #include +#include "window.h" #include "plib/color/color.h" #include "plib/gnw/input.h" #include "db.h" @@ -17,6 +18,7 @@ #include "plib/gnw/svga.h" #include "plib/gnw/winmain.h" + typedef void(MovieCallback)(); typedef int(MovieBlitFunc)(int win, unsigned char* data, int width, int height, int pitch); @@ -929,7 +931,7 @@ static bool localMovieCallback() movieCallback(); } - return _get_input() != -1; + return get_input() != -1; } // 0x487AC8 diff --git a/src/int/sound.c b/src/int/sound.c index dfa4fb7..409a84e 100644 --- a/src/int/sound.c +++ b/src/int/sound.c @@ -9,6 +9,7 @@ #include "plib/gnw/debug.h" #include "plib/gnw/memory.h" +#include "plib/gnw/winmain.h" typedef struct FadeSound { Sound* sound; diff --git a/src/int/sound.h b/src/int/sound.h index b86ca84..e214286 100644 --- a/src/int/sound.h +++ b/src/int/sound.h @@ -1,8 +1,10 @@ #ifndef FALLOUT_INT_SOUND_H_ #define FALLOUT_INT_SOUND_H_ +#include + #include "memory_defs.h" -#include "plib/gnw/winmain.h" +#include "plib/gnw/gnw95dx.h" #define SOUND_FLAG_SOUND_IS_DONE 0x01 #define SOUND_FLAG_SOUND_IS_PLAYING 0x02 diff --git a/src/movie_lib.c b/src/movie_lib.c index bd2bbaa..4795681 100644 --- a/src/movie_lib.c +++ b/src/movie_lib.c @@ -8,6 +8,8 @@ #include #include +#include + // 0x51EBD8 int dword_51EBD8 = 0; diff --git a/src/movie_lib.h b/src/movie_lib.h index ce6d398..415cd77 100644 --- a/src/movie_lib.h +++ b/src/movie_lib.h @@ -1,8 +1,12 @@ #ifndef MOVIE_LIB_H #define MOVIE_LIB_H +#define WIN32_LEAN_AND_MEAN +#include + #define DIRECTDRAW_VERSION 0x0300 #include +#include #define DIRECTSOUND_VERSION 0x0300 #include diff --git a/src/plib/gnw/button.c b/src/plib/gnw/button.c index 55d021f..4e6e643 100644 --- a/src/plib/gnw/button.c +++ b/src/plib/gnw/button.c @@ -866,7 +866,7 @@ void win_delete_button_win(int btn, int inputEvent) button = GNW_find_button(btn, &w); if (button != NULL) { win_delete(w->id); - enqueueInputEvent(inputEvent); + GNW_add_input_buffer(inputEvent); } } @@ -926,7 +926,7 @@ int win_disable_button(int btn) if (button == w->field_34) { if (w->field_34->mouseExitEventCode != -1) { - enqueueInputEvent(w->field_34->mouseExitEventCode); + GNW_add_input_buffer(w->field_34->mouseExitEventCode); w->field_34 = NULL; } } @@ -983,7 +983,7 @@ int win_set_button_rest_state(int btn, bool a2, int a3) if (keyCode != -1) { if ((a3 & 0x01) != 0) { - enqueueInputEvent(keyCode); + GNW_add_input_buffer(keyCode); } } } @@ -1221,11 +1221,11 @@ int win_button_press_and_release(int btn) button->leftMouseDownProc(btn, button->lefMouseDownEventCode); if ((button->flags & BUTTON_FLAG_0x40) != 0) { - enqueueInputEvent(button->lefMouseDownEventCode); + GNW_add_input_buffer(button->lefMouseDownEventCode); } } else { if (button->lefMouseDownEventCode != -1) { - enqueueInputEvent(button->lefMouseDownEventCode); + GNW_add_input_buffer(button->lefMouseDownEventCode); } } @@ -1235,11 +1235,11 @@ int win_button_press_and_release(int btn) button->leftMouseUpProc(btn, button->leftMouseUpEventCode); if ((button->flags & BUTTON_FLAG_0x40) != 0) { - enqueueInputEvent(button->leftMouseUpEventCode); + GNW_add_input_buffer(button->leftMouseUpEventCode); } } else { if (button->leftMouseUpEventCode != -1) { - enqueueInputEvent(button->leftMouseUpEventCode); + GNW_add_input_buffer(button->leftMouseUpEventCode); } } diff --git a/src/plib/gnw/dxinput.c b/src/plib/gnw/dxinput.c index f2232bc..cf76a2c 100644 --- a/src/plib/gnw/dxinput.c +++ b/src/plib/gnw/dxinput.c @@ -1,6 +1,8 @@ #include #include "plib/gnw/dxinput.h" +#include "plib/gnw/gnw95dx.h" +#include "plib/gnw/winmain.h" #define KEYBOARD_DEVICE_DATA_CAPACITY 32 diff --git a/src/plib/gnw/dxinput.h b/src/plib/gnw/dxinput.h index 76079f5..1ff2a9e 100644 --- a/src/plib/gnw/dxinput.h +++ b/src/plib/gnw/dxinput.h @@ -1,7 +1,7 @@ #ifndef FALLOUT_PLIB_GNW_DXINPUT_H_ #define FALLOUT_PLIB_GNW_DXINPUT_H_ -#include "plib/gnw/winmain.h" +#include typedef struct dxinput_mouse_state { int delta_x; diff --git a/src/plib/gnw/gnw.c b/src/plib/gnw/gnw.c index ac312d0..c3973f4 100644 --- a/src/plib/gnw/gnw.c +++ b/src/plib/gnw/gnw.c @@ -12,6 +12,7 @@ #include "plib/gnw/vcr.h" #include "plib/gnw/intrface.h" #include "plib/gnw/svga.h" +#include "plib/gnw/winmain.h" static void win_free(int win); static void win_clip(Window* window, RectPtr* rectListNodePtr, unsigned char* a3); @@ -167,7 +168,7 @@ int win_init(VideoSystemInitProc* videoSystemInitProc, VideoSystemExitProc* vide GNW_debug_init(); - if (coreInit(a3) == -1) { + if (GNW_input_init(a3) == -1) { return WINDOW_MANAGER_ERR_INITIALIZING_INPUT; } @@ -249,7 +250,7 @@ void win_exit(void) video_reset(); } - coreExit(); + GNW_input_exit(); GNW_rect_exit(); GNW_text_exit(); colorsClose(); @@ -1013,7 +1014,7 @@ void win_drag(int win) Rect rect; rectCopy(&rect, &(w->rect)); - tickersExecute(); + GNW_do_bk_process(); if (vcr_update() != 3) { mouse_info(); diff --git a/src/plib/gnw/input.c b/src/plib/gnw/input.c index d815b8f..be7eaaf 100644 --- a/src/plib/gnw/input.c +++ b/src/plib/gnw/input.c @@ -11,26 +11,55 @@ #include "plib/gnw/gnw.h" #include "plib/gnw/intrface.h" #include "plib/gnw/svga.h" +#include "plib/gnw/winmain.h" + +typedef struct GNW95RepeatStruct { + // Time when appropriate key was pressed down or -1 if it's up. + TOCKS time; + unsigned short count; +} GNW95RepeatStruct; + +typedef struct inputdata { + // This is either logical key or input event id, which can be either + // character code pressed or some other numbers used throughout the + // game interface. + int input; + int mx; + int my; +} inputdata; + +typedef struct funcdata { + unsigned int flags; + BackgroundProcess* f; + struct funcdata* next; +} funcdata; + +typedef funcdata* FuncPtr; + +static int get_input_buffer(); +static void pause_game(); +static int default_pause_window(); +static void buf_blit(unsigned char* src, int src_pitch, int a3, int x, int y, int width, int height, int dest_x, int dest_y); +static void GNW95_build_key_map(); +static int GNW95_hook_keyboard(int hook); +static void GNW95_process_key(dxinput_key_data* data); // NOT USED. -void (*_idle_func)() = NULL; +static IdleFunc* idle_func = NULL; // NOT USED. -void (*_focus_func)(int) = NULL; +static FocusFunc* focus_func = NULL; // 0x51E23C -int gKeyboardKeyRepeatRate = 80; +static int GNW95_repeat_rate = 80; // 0x51E240 -int gKeyboardKeyRepeatDelay = 500; - -// 0x51E244 -bool _keyboard_hooked = false; +static int GNW95_repeat_delay = 500; // A map of DIK_* constants normalized for QWERTY keyboard. // // 0x6ABC70 -unsigned char gNormalizedQwertyKeys[256]; +unsigned char GNW95_key_map[256]; // Ring buffer of input events. // @@ -38,58 +67,58 @@ unsigned char gNormalizedQwertyKeys[256]; // buffer is full it will not overwrite values until they are dequeued. // // 0x6ABD70 -InputEvent gInputEventQueue[40]; +static inputdata input_buffer[40]; // 0x6ABF50 -STRUCT_6ABF50 _GNW95_key_time_stamps[256]; +GNW95RepeatStruct GNW95_key_time_stamps[256]; // 0x6AC750 -int _input_mx; +static int input_mx; // 0x6AC754 -int _input_my; +static int input_my; // 0x6AC758 -HHOOK _GNW95_keyboardHandle; +static HHOOK GNW95_keyboardHandle; // 0x6AC75C -bool gPaused; +static bool game_paused; // 0x6AC760 -int gScreenshotKeyCode; +static int screendump_key; // 0x6AC764 -int _using_msec_timer; +static int using_msec_timer; // 0x6AC768 -int gPauseKeyCode; +static int pause_key; // 0x6AC76C -ScreenshotHandler* gScreenshotHandler; +static ScreenDumpFunc* screendump_func; // 0x6AC770 -int gInputEventQueueReadIndex; +static int input_get; // 0x6AC774 -unsigned char* gScreenshotBuffer; +static unsigned char* screendump_buf; // 0x6AC778 -PauseHandler* gPauseHandler; +static PauseWinFunc* pause_win_func; // 0x6AC77C -int gInputEventQueueWriteIndex; +static int input_put; // 0x6AC780 -bool gRunLoopDisabled; +static bool bk_disabled; // 0x6AC784 -TickerListNode* gTickerListHead; +static FuncPtr bk_list; // 0x6AC788 -unsigned int gTickerLastTimestamp; +static unsigned int bk_process_time; // 0x4C8A70 -int coreInit(int a1) +int GNW_input_init(int use_msec_timer) { if (!dxinput_init()) { return -1; @@ -103,63 +132,63 @@ int coreInit(int a1) return -1; } - if (_GNW95_input_init() == -1) { + if (GNW95_input_init() == -1) { return -1; } - _GNW95_hook_input(1); - buildNormalizedQwertyKeys(); - _GNW95_clear_time_stamps(); + GNW95_hook_input(1); + GNW95_build_key_map(); + GNW95_clear_time_stamps(); - _using_msec_timer = a1; - gInputEventQueueWriteIndex = 0; - gInputEventQueueReadIndex = -1; - _input_mx = -1; - _input_my = -1; - gRunLoopDisabled = 0; - gPaused = false; - gPauseKeyCode = KEY_ALT_P; - gPauseHandler = pauseHandlerDefaultImpl; - gScreenshotHandler = screenshotHandlerDefaultImpl; - gTickerListHead = NULL; - gScreenshotKeyCode = KEY_ALT_C; + using_msec_timer = use_msec_timer; + input_put = 0; + input_get = -1; + input_mx = -1; + input_my = -1; + bk_disabled = 0; + game_paused = false; + pause_key = KEY_ALT_P; + pause_win_func = default_pause_window; + screendump_func = default_screendump; + bk_list = NULL; + screendump_key = KEY_ALT_C; return 0; } // 0x4C8B40 -void coreExit() +void GNW_input_exit() { - _GNW95_hook_keyboard(0); - _GNW95_input_init(); + // NOTE: Uninline. + GNW95_input_exit(); GNW_mouse_exit(); GNW_kb_restore(); dxinput_exit(); - TickerListNode* curr = gTickerListHead; + FuncPtr curr = bk_list; while (curr != NULL) { - TickerListNode* next = curr->next; + FuncPtr next = curr->next; mem_free(curr); curr = next; } } // 0x4C8B78 -int _get_input() +int get_input() { int v3; - _GNW95_process_message(); + GNW95_process_message(); if (!GNW95_isActive) { - _GNW95_lost_focus(); + GNW95_lost_focus(); } - _process_bk(); + process_bk(); - v3 = dequeueInputEvent(); + v3 = get_input_buffer(); if (v3 == -1 && mouse_get_buttons() & 0x33) { - mouse_get_position(&_input_mx, &_input_my); + mouse_get_position(&input_mx, &input_my); return -2; } else { return GNW_check_menu_bars(v3); @@ -169,11 +198,11 @@ int _get_input() } // 0x4C8BDC -void _process_bk() +void process_bk() { int v1; - tickersExecute(); + GNW_do_bk_process(); if (vcr_update() != 3) { mouse_info(); @@ -181,113 +210,112 @@ void _process_bk() v1 = win_check_all_buttons(); if (v1 != -1) { - enqueueInputEvent(v1); + GNW_add_input_buffer(v1); return; } v1 = kb_getch(); if (v1 != -1) { - enqueueInputEvent(v1); + GNW_add_input_buffer(v1); return; } } // 0x4C8C04 -void enqueueInputEvent(int a1) +void GNW_add_input_buffer(int a1) { if (a1 == -1) { return; } - if (a1 == gPauseKeyCode) { - pauseGame(); + if (a1 == pause_key) { + pause_game(); return; } - if (a1 == gScreenshotKeyCode) { - takeScreenshot(); + if (a1 == screendump_key) { + dump_screen(); return; } - if (gInputEventQueueWriteIndex == gInputEventQueueReadIndex) { + if (input_put == input_get) { return; } - InputEvent* inputEvent = &(gInputEventQueue[gInputEventQueueWriteIndex]); - inputEvent->logicalKey = a1; + inputdata* inputEvent = &(input_buffer[input_put]); + inputEvent->input = a1; - mouse_get_position(&(inputEvent->mouseX), &(inputEvent->mouseY)); + mouse_get_position(&(inputEvent->mx), &(inputEvent->my)); - gInputEventQueueWriteIndex++; + input_put++; - if (gInputEventQueueWriteIndex == 40) { - gInputEventQueueWriteIndex = 0; + if (input_put == 40) { + input_put = 0; return; } - if (gInputEventQueueReadIndex == -1) { - gInputEventQueueReadIndex = 0; + if (input_get == -1) { + input_get = 0; } } // 0x4C8C9C -int dequeueInputEvent() +static int get_input_buffer() { - if (gInputEventQueueReadIndex == -1) { + if (input_get == -1) { return -1; } - InputEvent* inputEvent = &(gInputEventQueue[gInputEventQueueReadIndex]); - int eventCode = inputEvent->logicalKey; - _input_mx = inputEvent->mouseX; - _input_my = inputEvent->mouseY; + inputdata* inputEvent = &(input_buffer[input_get]); + int eventCode = inputEvent->input; + input_mx = inputEvent->mx; + input_my = inputEvent->my; - gInputEventQueueReadIndex++; + input_get++; - if (gInputEventQueueReadIndex == 40) { - gInputEventQueueReadIndex = 0; + if (input_get == 40) { + input_get = 0; } - if (gInputEventQueueReadIndex == gInputEventQueueWriteIndex) { - gInputEventQueueReadIndex = -1; - gInputEventQueueWriteIndex = 0; + if (input_get == input_put) { + input_get = -1; + input_put = 0; } return eventCode; } // 0x4C8D04 -void inputEventQueueReset() +void flush_input_buffer() { - gInputEventQueueReadIndex = -1; - gInputEventQueueWriteIndex = 0; + input_get = -1; + input_put = 0; } // 0x4C8D1C -void tickersExecute() +void GNW_do_bk_process() { - if (gPaused) { + if (game_paused) { return; } - if (gRunLoopDisabled) { + if (bk_disabled) { return; } -#pragma warning(suppress : 28159) - gTickerLastTimestamp = GetTickCount(); + bk_process_time = get_time(); - TickerListNode* curr = gTickerListHead; - TickerListNode** currPtr = &(gTickerListHead); + FuncPtr curr = bk_list; + FuncPtr* currPtr = &(bk_list); while (curr != NULL) { - TickerListNode* next = curr->next; + FuncPtr next = curr->next; if (curr->flags & 1) { *currPtr = next; mem_free(curr); } else { - curr->proc(); + curr->f(); currPtr = &(curr->next); } curr = next; @@ -295,69 +323,73 @@ void tickersExecute() } // 0x4C8D74 -void tickersAdd(TickerProc* proc) +void add_bk_process(BackgroundProcess* f) { - TickerListNode* curr = gTickerListHead; - while (curr != NULL) { - if (curr->proc == proc) { - if ((curr->flags & 0x01) != 0) { - curr->flags &= ~0x01; + FuncPtr fp; + + fp = bk_list; + while (fp != NULL) { + if (fp->f == f) { + if ((fp->flags & 0x01) != 0) { + fp->flags &= ~0x01; return; } } - curr = curr->next; + fp = fp->next; } - curr = (TickerListNode*)mem_malloc(sizeof(*curr)); - curr->flags = 0; - curr->proc = proc; - curr->next = gTickerListHead; - gTickerListHead = curr; + fp = (FuncPtr)mem_malloc(sizeof(*fp)); + fp->flags = 0; + fp->f = f; + fp->next = bk_list; + bk_list = fp; } // 0x4C8DC4 -void tickersRemove(TickerProc* proc) +void remove_bk_process(BackgroundProcess* f) { - TickerListNode* curr = gTickerListHead; - while (curr != NULL) { - if (curr->proc == proc) { - curr->flags |= 0x01; + FuncPtr fp; + + fp = bk_list; + while (fp != NULL) { + if (fp->f == f) { + fp->flags |= 0x01; return; } - curr = curr->next; + fp = fp->next; } } // 0x4C8DE4 -void tickersEnable() +void enable_bk() { - gRunLoopDisabled = false; + bk_disabled = false; } // 0x4C8DF0 -void tickersDisable() +void disable_bk() { - gRunLoopDisabled = true; + bk_disabled = true; } // 0x4C8DFC -void pauseGame() +static void pause_game() { - if (!gPaused) { - gPaused = true; + if (!game_paused) { + game_paused = true; - int win = gPauseHandler(); + int win = pause_win_func(); - while (_get_input() != KEY_ESCAPE) { + while (get_input() != KEY_ESCAPE) { } - gPaused = false; + game_paused = false; win_delete(win); } } // 0x4C8E38 -int pauseHandlerDefaultImpl() +static int default_pause_window() { int windowWidth = text_width("Paused") + 32; int windowHeight = 3 * text_height() + 16; @@ -397,32 +429,32 @@ int pauseHandlerDefaultImpl() } // 0x4C8F34 -void pauseHandlerConfigure(int keyCode, PauseHandler* handler) +void register_pause(int new_pause_key, PauseWinFunc* new_pause_win_func) { - gPauseKeyCode = keyCode; + pause_key = new_pause_key; - if (handler == NULL) { - handler = pauseHandlerDefaultImpl; + if (new_pause_win_func == NULL) { + new_pause_win_func = default_pause_window; } - gPauseHandler = handler; + pause_win_func = new_pause_win_func; } // 0x4C8F4C -void takeScreenshot() +void dump_screen() { int width = scr_size.lrx - scr_size.ulx + 1; int height = scr_size.lry - scr_size.uly + 1; - gScreenshotBuffer = (unsigned char*)mem_malloc(width * height); - if (gScreenshotBuffer == NULL) { + screendump_buf = (unsigned char*)mem_malloc(width * height); + if (screendump_buf == NULL) { return; } ScreenBlitFunc* v0 = scr_blit; - scr_blit = screenshotBlitter; + scr_blit = buf_blit; ScreenBlitFunc* v2 = mouse_blit; - mouse_blit = screenshotBlitter; + mouse_blit = buf_blit; ScreenTransBlitFunc* v1 = mouse_blit_trans; mouse_blit_trans = NULL; @@ -434,19 +466,19 @@ void takeScreenshot() scr_blit = v0; unsigned char* palette = getSystemPalette(); - gScreenshotHandler(width, height, gScreenshotBuffer, palette); - mem_free(gScreenshotBuffer); + screendump_func(width, height, screendump_buf, palette); + mem_free(screendump_buf); } // 0x4C8FF0 -void screenshotBlitter(unsigned char* src, int srcPitch, int a3, int srcX, int srcY, int width, int height, int destX, int destY) +static void buf_blit(unsigned char* src, int srcPitch, int a3, int srcX, int srcY, int width, int height, int destX, int destY) { int destWidth = scr_size.lrx - scr_size.ulx + 1; - buf_to_buf(src + srcPitch * srcY + srcX, width, height, srcPitch, gScreenshotBuffer + destWidth * destY + destX, destWidth); + buf_to_buf(src + srcPitch * srcY + srcX, width, height, srcPitch, screendump_buf + destWidth * destY + destX, destWidth); } // 0x4C9048 -int screenshotHandlerDefaultImpl(int width, int height, unsigned char* data, unsigned char* palette) +int default_screendump(int width, int height, unsigned char* data, unsigned char* palette) { char fileName[16]; FILE* stream; @@ -565,67 +597,67 @@ int screenshotHandlerDefaultImpl(int width, int height, unsigned char* data, uns } // 0x4C9358 -void screenshotHandlerConfigure(int keyCode, ScreenshotHandler* handler) +void register_screendump(int new_screendump_key, ScreenDumpFunc* new_screendump_func) { - gScreenshotKeyCode = keyCode; + screendump_key = new_screendump_key; - if (handler == NULL) { - handler = screenshotHandlerDefaultImpl; + if (new_screendump_func == NULL) { + new_screendump_func = default_screendump; } - gScreenshotHandler = handler; + screendump_func = new_screendump_func; } // 0x4C9370 -unsigned int _get_time() +TOCKS get_time() { #pragma warning(suppress : 28159) return GetTickCount(); } // 0x4C937C -void coreDelayProcessingEvents(unsigned int delay) +void pause_for_tocks(unsigned int delay) { // NOTE: Uninline. - unsigned int start = _get_time(); - unsigned int end = _get_time(); + unsigned int start = get_time(); + unsigned int end = get_time(); // NOTE: Uninline. - unsigned int diff = getTicksBetween(end, start); + unsigned int diff = elapsed_tocks(end, start); while (diff < delay) { - _process_bk(); + process_bk(); - end = _get_time(); + end = get_time(); // NOTE: Uninline. - diff = getTicksBetween(end, start); + diff = elapsed_tocks(end, start); } } // 0x4C93B8 -void coreDelay(unsigned int ms) +void block_for_tocks(unsigned int ms) { #pragma warning(suppress : 28159) unsigned int start = GetTickCount(); unsigned int diff; do { // NOTE: Uninline - diff = getTicksSince(start); + diff = elapsed_time(start); } while (diff < ms); } // 0x4C93E0 -unsigned int getTicksSince(unsigned int start) +unsigned int elapsed_time(unsigned int start) { #pragma warning(suppress : 28159) unsigned int end = GetTickCount(); // NOTE: Uninline. - return getTicksBetween(end, start); + return elapsed_tocks(end, start); } // 0x4C9400 -unsigned int getTicksBetween(unsigned int end, unsigned int start) +unsigned int elapsed_tocks(unsigned int end, unsigned int start) { if (start > end) { return INT_MAX; @@ -635,15 +667,15 @@ unsigned int getTicksBetween(unsigned int end, unsigned int start) } // 0x4C9410 -unsigned int _get_bk_time() +unsigned int get_bk_time() { - return gTickerLastTimestamp; + return bk_process_time; } // 0x4C9490 -void buildNormalizedQwertyKeys() +static void GNW95_build_key_map() { - unsigned char* keys = gNormalizedQwertyKeys; + unsigned char* keys = GNW95_key_map; int k; keys[DIK_ESCAPE] = DIK_ESCAPE; @@ -971,11 +1003,11 @@ void buildNormalizedQwertyKeys() } // 0x4C9BB4 -void _GNW95_hook_input(int a1) +void GNW95_hook_input(int hook) { - _GNW95_hook_keyboard(a1); + GNW95_hook_keyboard(hook); - if (a1) { + if (hook) { dxinput_acquire_mouse(); } else { dxinput_unacquire_mouse(); @@ -983,34 +1015,45 @@ void _GNW95_hook_input(int a1) } // 0x4C9C20 -int _GNW95_input_init() +int GNW95_input_init() { return 0; } +// NOTE: Inlined. +// +// 0x4C9C24 +void GNW95_input_exit() +{ + GNW95_hook_keyboard(0); +} + // 0x4C9C28 -int _GNW95_hook_keyboard(int a1) +static int GNW95_hook_keyboard(int hook) { - if (a1 == _keyboard_hooked) { + // 0x51E244 + static bool hooked = false; + + if (hook == hooked) { return 0; } - if (!a1) { + if (!hook) { dxinput_unacquire_keyboard(); - UnhookWindowsHookEx(_GNW95_keyboardHandle); + UnhookWindowsHookEx(GNW95_keyboardHandle); kb_clear(); - _keyboard_hooked = a1; + hooked = hook; return 0; } if (dxinput_acquire_keyboard()) { - _GNW95_keyboardHandle = SetWindowsHookExA(WH_KEYBOARD, _GNW95_keyboard_hook, 0, GetCurrentThreadId()); + GNW95_keyboardHandle = SetWindowsHookExA(WH_KEYBOARD, GNW95_keyboard_hook, 0, GetCurrentThreadId()); kb_clear(); - _keyboard_hooked = a1; + hooked = hook; return 0; } @@ -1019,7 +1062,7 @@ int _GNW95_hook_keyboard(int a1) } // 0x4C9C4C -LRESULT CALLBACK _GNW95_keyboard_hook(int nCode, WPARAM wParam, LPARAM lParam) +LRESULT CALLBACK GNW95_keyboard_hook(int nCode, WPARAM wParam, LPARAM lParam) { if (nCode >= 0) { if (wParam == VK_DELETE && lParam & 0x20000000 && GetAsyncKeyState(VK_CONTROL) & 0x80000000) @@ -1041,33 +1084,33 @@ LRESULT CALLBACK _GNW95_keyboard_hook(int nCode, WPARAM wParam, LPARAM lParam) next: - return CallNextHookEx(_GNW95_keyboardHandle, nCode, wParam, lParam); + return CallNextHookEx(GNW95_keyboardHandle, nCode, wParam, lParam); } // 0x4C9CF0 -void _GNW95_process_message() +void GNW95_process_message() { if (GNW95_isActive && !kb_is_disabled()) { dxinput_key_data data; while (dxinput_read_keyboard_buffer(&data)) { - _GNW95_process_key(&data); + GNW95_process_key(&data); } // NOTE: Uninline - int tick = _get_time(); + TOCKS now = get_time(); for (int key = 0; key < 256; key++) { - STRUCT_6ABF50* ptr = &(_GNW95_key_time_stamps[key]); - if (ptr->tick != -1) { - int elapsedTime = ptr->tick > tick ? INT_MAX : tick - ptr->tick; - int delay = ptr->repeatCount == 0 ? gKeyboardKeyRepeatDelay : gKeyboardKeyRepeatRate; + GNW95RepeatStruct* ptr = &(GNW95_key_time_stamps[key]); + if (ptr->time != -1) { + int elapsedTime = ptr->time > now ? INT_MAX : now - ptr->time; + int delay = ptr->count == 0 ? GNW95_repeat_delay : GNW95_repeat_rate; if (elapsedTime > delay) { data.code = key; data.state = 1; - _GNW95_process_key(&data); + GNW95_process_key(&data); - ptr->tick = tick; - ptr->repeatCount++; + ptr->time = now; + ptr->count++; } } } @@ -1083,16 +1126,16 @@ void _GNW95_process_message() } // 0x4C9DF0 -void _GNW95_clear_time_stamps() +void GNW95_clear_time_stamps() { for (int index = 0; index < 256; index++) { - _GNW95_key_time_stamps[index].tick = -1; - _GNW95_key_time_stamps[index].repeatCount = 0; + GNW95_key_time_stamps[index].time = -1; + GNW95_key_time_stamps[index].count = 0; } } // 0x4C9E14 -void _GNW95_process_key(dxinput_key_data* data) +static void GNW95_process_key(dxinput_key_data* data) { short key = data->code & 0xFF; @@ -1115,7 +1158,7 @@ void _GNW95_process_key(dxinput_key_data* data) break; } - int qwertyKey = gNormalizedQwertyKeys[data->code & 0xFF]; + int qwertyKey = GNW95_key_map[data->code & 0xFF]; if (vcr_state == VCR_STATE_PLAYING) { if ((vcr_terminate_flags & VCR_TERMINATE_ON_KEY_PRESS) != 0) { @@ -1128,13 +1171,13 @@ void _GNW95_process_key(dxinput_key_data* data) qwertyKey -= 0x80; } - STRUCT_6ABF50* ptr = &(_GNW95_key_time_stamps[data->code & 0xFF]); + GNW95RepeatStruct* ptr = &(GNW95_key_time_stamps[data->code & 0xFF]); if (data->state == 1) { - ptr->tick = _get_time(); - ptr->repeatCount = 0; + ptr->time = get_time(); + ptr->count = 0; } else { qwertyKey |= 0x80; - ptr->tick = -1; + ptr->time = -1; } kb_simulate_key(qwertyKey); @@ -1142,21 +1185,21 @@ void _GNW95_process_key(dxinput_key_data* data) } // 0x4C9EEC -void _GNW95_lost_focus() +void GNW95_lost_focus() { - if (_focus_func != NULL) { - _focus_func(0); + if (focus_func != NULL) { + focus_func(0); } while (!GNW95_isActive) { - _GNW95_process_message(); + GNW95_process_message(); - if (_idle_func != NULL) { - _idle_func(); + if (idle_func != NULL) { + idle_func(); } } - if (_focus_func != NULL) { - _focus_func(1); + if (focus_func != NULL) { + focus_func(1); } } diff --git a/src/plib/gnw/input.h b/src/plib/gnw/input.h index e748769..7b66ba8 100644 --- a/src/plib/gnw/input.h +++ b/src/plib/gnw/input.h @@ -1,99 +1,49 @@ -#ifndef CORE_H -#define CORE_H +#ifndef FALLOUT_PLIB_GNW_INPUT_H_ +#define FALLOUT_PLIB_GNW_INPUT_H_ #include -#include "db.h" -#include "plib/gnw/dxinput.h" -#include "plib/gnw/rect.h" +#define WIN32_LEAN_AND_MEAN +#include + #include "plib/gnw/kb.h" #include "plib/gnw/mouse.h" -#include "window.h" - -typedef struct STRUCT_6ABF50 { - // Time when appropriate key was pressed down or -1 if it's up. - int tick; - int repeatCount; -} STRUCT_6ABF50; - -typedef struct InputEvent { - // This is either logical key or input event id, which can be either - // character code pressed or some other numbers used throughout the - // game interface. - int logicalKey; - int mouseX; - int mouseY; -} InputEvent; - -typedef void TickerProc(); - -typedef struct TickerListNode { - int flags; - TickerProc* proc; - struct TickerListNode* next; -} TickerListNode; - -typedef int(PauseHandler)(); -typedef int(ScreenshotHandler)(int width, int height, unsigned char* buffer, unsigned char* palette); - -extern void (*_idle_func)(); -extern void (*_focus_func)(int); -extern int gKeyboardKeyRepeatRate; -extern int gKeyboardKeyRepeatDelay; -extern bool _keyboard_hooked; - -extern unsigned char gNormalizedQwertyKeys[256]; -extern InputEvent gInputEventQueue[40]; -extern STRUCT_6ABF50 _GNW95_key_time_stamps[256]; -extern int _input_mx; -extern int _input_my; -extern HHOOK _GNW95_keyboardHandle; -extern bool gPaused; -extern int gScreenshotKeyCode; -extern int _using_msec_timer; -extern int gPauseKeyCode; -extern ScreenshotHandler* gScreenshotHandler; -extern int gInputEventQueueReadIndex; -extern unsigned char* gScreenshotBuffer; -extern PauseHandler* gPauseHandler; -extern int gInputEventQueueWriteIndex; -extern bool gRunLoopDisabled; -extern TickerListNode* gTickerListHead; -extern unsigned int gTickerLastTimestamp; - -int coreInit(int a1); -void coreExit(); -int _get_input(); -void _process_bk(); -void enqueueInputEvent(int a1); -int dequeueInputEvent(); -void inputEventQueueReset(); -void tickersExecute(); -void tickersAdd(TickerProc* fn); -void tickersRemove(TickerProc* fn); -void tickersEnable(); -void tickersDisable(); -void pauseGame(); -int pauseHandlerDefaultImpl(); -void pauseHandlerConfigure(int keyCode, PauseHandler* fn); -void takeScreenshot(); -void screenshotBlitter(unsigned char* src, int src_pitch, int a3, int x, int y, int width, int height, int dest_x, int dest_y); -int screenshotHandlerDefaultImpl(int width, int height, unsigned char* data, unsigned char* palette); -void screenshotHandlerConfigure(int keyCode, ScreenshotHandler* handler); -unsigned int _get_time(); -void coreDelayProcessingEvents(unsigned int ms); -void coreDelay(unsigned int ms); -unsigned int getTicksSince(unsigned int a1); -unsigned int getTicksBetween(unsigned int a1, unsigned int a2); -unsigned int _get_bk_time(); -void buildNormalizedQwertyKeys(); -void _GNW95_hook_input(int a1); -int _GNW95_input_init(); -int _GNW95_hook_keyboard(int a1); -LRESULT CALLBACK _GNW95_keyboard_hook(int nCode, WPARAM wParam, LPARAM lParam); -void _GNW95_process_message(); -void _GNW95_clear_time_stamps(); -void _GNW95_process_key(dxinput_key_data* data); -void _GNW95_lost_focus(); -#endif /* CORE_H */ +typedef unsigned long TOCKS; + +typedef void(IdleFunc)(); +typedef void(FocusFunc)(int); +typedef void(BackgroundProcess)(); +typedef int(PauseWinFunc)(); +typedef int(ScreenDumpFunc)(int width, int height, unsigned char* buffer, unsigned char* palette); + +int GNW_input_init(int use_msec_timer); +void GNW_input_exit(); +int get_input(); +void process_bk(); +void GNW_add_input_buffer(int a1); +void flush_input_buffer(); +void GNW_do_bk_process(); +void add_bk_process(BackgroundProcess* f); +void remove_bk_process(BackgroundProcess* f); +void enable_bk(); +void disable_bk(); +void register_pause(int new_pause_key, PauseWinFunc* new_pause_win_func); +void dump_screen(); +int default_screendump(int width, int height, unsigned char* data, unsigned char* palette); +void register_screendump(int new_screendump_key, ScreenDumpFunc* new_screendump_func); +TOCKS get_time(); +void pause_for_tocks(unsigned int ms); +void block_for_tocks(unsigned int ms); +unsigned int elapsed_time(unsigned int a1); +unsigned int elapsed_tocks(unsigned int a1, unsigned int a2); +unsigned int get_bk_time(); +void GNW95_hook_input(int hook); +int GNW95_input_init(); +void GNW95_input_exit(); +LRESULT CALLBACK GNW95_keyboard_hook(int nCode, WPARAM wParam, LPARAM lParam); +void GNW95_process_message(); +void GNW95_clear_time_stamps(); +void GNW95_lost_focus(); + +#endif /* FALLOUT_PLIB_GNW_INPUT_H_ */ diff --git a/src/plib/gnw/intrface.c b/src/plib/gnw/intrface.c index 01a8da9..2f18596 100644 --- a/src/plib/gnw/intrface.c +++ b/src/plib/gnw/intrface.c @@ -315,7 +315,7 @@ int win_list_select_at(const char* title, char** items, int itemsLength, SelectF // Relative to `scrollOffset`. int previousSelectedItemIndex = -1; while (1) { - int keyCode = _get_input(); + int keyCode = get_input(); int mouseX; int mouseY; mouse_get_position(&mouseX, &mouseY); @@ -653,7 +653,7 @@ int win_msg(const char* string, int x, int y, int flags) win_draw(win); - while (_get_input() != KEY_ESCAPE) { + while (get_input() != KEY_ESCAPE) { } win_delete(win); @@ -1016,7 +1016,7 @@ int win_input_str(int win, char* dest, int maxLength, int x, int y, int textColo // decremented in the loop body when key is not handled. bool isFirstKey = true; for (; cursorPos <= maxLength; cursorPos++) { - int keyCode = _get_input(); + int keyCode = get_input(); if (keyCode != -1) { if (keyCode == KEY_ESCAPE) { dest[cursorPos] = '\0'; @@ -1139,8 +1139,8 @@ int GNW_process_menu(MenuBar* menuBar, int pulldownIndex) } while (keyCode < -1); if (keyCode != -1) { - inputEventQueueReset(); - enqueueInputEvent(keyCode); + flush_input_buffer(); + GNW_add_input_buffer(keyCode); keyCode = menuBar->pulldowns[pulldownIndex].keyCode; } @@ -1203,7 +1203,7 @@ void GNW_intr_init() // 0x4DD4A4 void GNW_intr_exit() { - tickersRemove(tm_watch_msgs); + remove_bk_process(tm_watch_msgs); while (tm_kill != -1) { tm_kill_msg(); } @@ -1218,7 +1218,7 @@ static void tm_watch_msgs() tm_watch_active = 1; while (tm_kill != -1) { - if (getTicksSince(tm_queue[tm_kill].created) < tm_persistence) { + if (elapsed_time(tm_queue[tm_kill].created) < tm_persistence) { break; } @@ -1244,7 +1244,7 @@ static void tm_kill_msg() if (v0 == tm_add) { tm_add = 0; tm_kill = -1; - tickersRemove(tm_watch_msgs); + remove_bk_process(tm_watch_msgs); v0 = tm_kill; } } @@ -1290,7 +1290,7 @@ static void tm_kill_out_of_order(int a1) if (tm_add == tm_kill) { tm_add = 0; tm_kill = -1; - tickersRemove(tm_watch_msgs); + remove_bk_process(tm_watch_msgs); } } diff --git a/src/plib/gnw/kb.c b/src/plib/gnw/kb.c index 170afbe..872a8a6 100644 --- a/src/plib/gnw/kb.c +++ b/src/plib/gnw/kb.c @@ -2,6 +2,7 @@ #include "plib/gnw/input.h" #include "plib/gnw/dxinput.h" +#include "plib/gnw/gnw95dx.h" #include "plib/gnw/vcr.h" typedef struct key_ansi_t { @@ -107,7 +108,7 @@ int GNW_kb_set() kb_init_lock_status(); kb_set_layout(KEYBOARD_LAYOUT_QWERTY); - kb_idle_start_time = _get_time(); + kb_idle_start_time = get_time(); return 0; } @@ -130,7 +131,7 @@ void kb_wait() kb_clear(); do { - _GNW95_process_message(); + GNW95_process_message(); } while (keynumpress == 0); // NOTE: Uninline. @@ -155,7 +156,7 @@ void kb_clear() } dxinput_flush_keyboard_buffer(); - _GNW95_clear_time_stamps(); + GNW95_clear_time_stamps(); } // 0x4CBDE8 @@ -300,7 +301,7 @@ int kb_ascii_to_scan(int ascii) // 0x4CBF50 unsigned int kb_elapsed_time() { - return getTicksSince(kb_idle_start_time); + return elapsed_time(kb_idle_start_time); } // NOTE: Unused. @@ -308,7 +309,7 @@ unsigned int kb_elapsed_time() // 0x4CBF5C void kb_reset_elapsed_time() { - kb_idle_start_time = _get_time(); + kb_idle_start_time = get_time(); } // TODO: Key type is likely short. @@ -328,7 +329,7 @@ void kb_simulate_key(int scan_code) } } - kb_idle_start_time = _get_bk_time(); + kb_idle_start_time = get_bk_time(); if (scan_code == 224) { extended_code = 0x80; diff --git a/src/plib/gnw/mouse.c b/src/plib/gnw/mouse.c index c2d375a..a7f0313 100644 --- a/src/plib/gnw/mouse.c +++ b/src/plib/gnw/mouse.c @@ -1,8 +1,9 @@ #include "plib/gnw/mouse.h" #include "plib/color/color.h" -#include "plib/gnw/input.h" #include "plib/gnw/dxinput.h" +#include "plib/gnw/gnw.h" +#include "plib/gnw/input.h" #include "plib/gnw/memory.h" #include "plib/gnw/svga.h" #include "plib/gnw/vcr.h" @@ -139,7 +140,7 @@ int GNW_mouse_init() mouse_y = scr_size.lry / 2; raw_x = scr_size.lrx / 2; raw_y = scr_size.lry / 2; - mouse_idle_start_time = _get_time(); + mouse_idle_start_time = get_time(); return 0; } @@ -155,7 +156,7 @@ void GNW_mouse_exit() } if (mouse_fptr != NULL) { - tickersRemove(mouse_anim); + remove_bk_process(mouse_anim); mouse_fptr = NULL; } } @@ -239,7 +240,7 @@ int mouse_set_shape(unsigned char* buf, int width, int length, int full, int hot mouse_trans = trans; if (mouse_fptr) { - tickersRemove(mouse_anim); + remove_bk_process(mouse_anim); mouse_fptr = NULL; } @@ -300,7 +301,7 @@ int mouse_set_anim_frames(unsigned char* frames, int num_frames, int start_frame mouse_curr_frame = start_frame; mouse_speed = speed; - tickersAdd(mouse_anim); + add_bk_process(mouse_anim); return 0; } @@ -311,8 +312,8 @@ static void mouse_anim() // 0x51E2A8 static unsigned int ticker = 0; - if (getTicksSince(ticker) >= mouse_speed) { - ticker = _get_time(); + if (elapsed_time(ticker) >= mouse_speed) { + ticker = get_time(); if (++mouse_curr_frame == mouse_num_frames) { mouse_curr_frame = 0; @@ -502,7 +503,7 @@ void mouse_simulate_input(int delta_x, int delta_y, int buttons) } else { if (last_buttons == 0) { if (!mouse_idling) { - mouse_idle_start_time = _get_time(); + mouse_idle_start_time = get_time(); mouse_idling = 1; } @@ -523,9 +524,9 @@ void mouse_simulate_input(int delta_x, int delta_y, int buttons) if ((buttons & 0x01) != 0) { mouse_buttons |= MOUSE_EVENT_LEFT_BUTTON_REPEAT; - if (getTicksSince(left_time) > BUTTON_REPEAT_TIME) { + if (elapsed_time(left_time) > BUTTON_REPEAT_TIME) { mouse_buttons |= MOUSE_EVENT_LEFT_BUTTON_DOWN; - left_time = _get_time(); + left_time = get_time(); } } else { mouse_buttons |= MOUSE_EVENT_LEFT_BUTTON_UP; @@ -533,16 +534,16 @@ void mouse_simulate_input(int delta_x, int delta_y, int buttons) } else { if ((buttons & 0x01) != 0) { mouse_buttons |= MOUSE_EVENT_LEFT_BUTTON_DOWN; - left_time = _get_time(); + left_time = get_time(); } } if ((old & MOUSE_EVENT_RIGHT_BUTTON_DOWN_REPEAT) != 0) { if ((buttons & 0x02) != 0) { mouse_buttons |= MOUSE_EVENT_RIGHT_BUTTON_REPEAT; - if (getTicksSince(right_time) > BUTTON_REPEAT_TIME) { + if (elapsed_time(right_time) > BUTTON_REPEAT_TIME) { mouse_buttons |= MOUSE_EVENT_RIGHT_BUTTON_DOWN; - right_time = _get_time(); + right_time = get_time(); } } else { mouse_buttons |= MOUSE_EVENT_RIGHT_BUTTON_UP; @@ -550,7 +551,7 @@ void mouse_simulate_input(int delta_x, int delta_y, int buttons) } else { if (buttons & 0x02) { mouse_buttons |= MOUSE_EVENT_RIGHT_BUTTON_DOWN; - right_time = _get_time(); + right_time = get_time(); } } @@ -770,7 +771,7 @@ unsigned int mouse_elapsed_time() { if (mouse_idling) { if (have_mouse && !mouse_is_hidden && !mouse_disabled) { - return getTicksSince(mouse_idle_start_time); + return elapsed_time(mouse_idle_start_time); } mouse_idling = false; } diff --git a/src/plib/gnw/vcr.c b/src/plib/gnw/vcr.c index a5ca0e5..2fda06d 100644 --- a/src/plib/gnw/vcr.c +++ b/src/plib/gnw/vcr.c @@ -1,6 +1,6 @@ #include "plib/gnw/vcr.h" -#include +#include #include "plib/gnw/input.h" #include "plib/gnw/memory.h" @@ -97,7 +97,7 @@ bool vcr_record(const char* fileName) vcr_counter = 1; vcr_buffer_index++; - vcr_start_time = _get_time(); + vcr_start_time = get_time(); kb_clear(); vcr_state = VCR_STATE_RECORDING; @@ -146,7 +146,7 @@ bool vcr_play(const char* fileName, unsigned int terminationFlags, VcrPlaybackCo vcr_terminate_flags = 0; vcr_counter = 0; vcr_time = 0; - vcr_start_time = _get_time(); + vcr_start_time = get_time(); vcr_state = VCR_STATE_PLAYING; vcr_last_play_event.time = 0; vcr_last_play_event.counter = 0; @@ -210,7 +210,7 @@ int vcr_update() switch (vcr_state) { case VCR_STATE_RECORDING: vcr_counter++; - vcr_time = getTicksSince(vcr_start_time); + vcr_time = elapsed_time(vcr_start_time); if (vcr_buffer_index == VCR_BUFFER_CAPACITY - 1) { vcr_dump_buffer(); } @@ -225,7 +225,7 @@ int vcr_update() * (vcrEntry->time - vcr_last_play_event.time) / (vcrEntry->counter - vcr_last_play_event.counter); - while (getTicksSince(vcr_start_time) < delay) { + while (elapsed_time(vcr_start_time) < delay) { } } } @@ -234,7 +234,7 @@ int vcr_update() int rc = 0; while (vcr_counter >= vcr_buffer[vcr_buffer_index].counter) { - vcr_time = getTicksSince(vcr_start_time); + vcr_time = elapsed_time(vcr_start_time); if (vcr_time > vcr_buffer[vcr_buffer_index].time + 5 || vcr_time < vcr_buffer[vcr_buffer_index].time - 5) { vcr_start_time += vcr_time - vcr_buffer[vcr_buffer_index].time; @@ -254,7 +254,7 @@ int vcr_update() mouse_show(); kb_clear(); vcr_terminate_flags = vcr_temp_terminate_flags; - vcr_start_time = _get_time(); + vcr_start_time = get_time(); vcr_counter = 0; break; case VCR_ENTRY_TYPE_KEYBOARD_EVENT: diff --git a/src/plib/gnw/winmain.c b/src/plib/gnw/winmain.c index 2b34e46..5703d02 100644 --- a/src/plib/gnw/winmain.c +++ b/src/plib/gnw/winmain.c @@ -227,10 +227,10 @@ LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) case WM_ACTIVATEAPP: GNW95_isActive = wParam; if (wParam) { - _GNW95_hook_input(1); + GNW95_hook_input(1); win_refresh_all(&scr_size); } else { - _GNW95_hook_input(0); + GNW95_hook_input(0); } return 0; diff --git a/src/plib/gnw/winmain.h b/src/plib/gnw/winmain.h index f16589e..443f6d1 100644 --- a/src/plib/gnw/winmain.h +++ b/src/plib/gnw/winmain.h @@ -6,8 +6,6 @@ #define WIN32_LEAN_AND_MEAN #include -#include "plib/gnw/gnw95dx.h" - extern HWND GNW95_hwnd; extern HINSTANCE GNW95_hInstance; extern LPSTR GNW95_lpszCmdLine; diff --git a/src/window.c b/src/window.c index 1fb75a3..6f559ce 100644 --- a/src/window.c +++ b/src/window.c @@ -4,6 +4,7 @@ #include #include +#include "db.h" #include "plib/color/color.h" #include "plib/gnw/input.h" #include "int/datafile.h" @@ -440,7 +441,7 @@ bool _windowActivateRegion(const char* regionName, int a2) // 0x4B6ED0 int _getInput() { - int keyCode = _get_input(); + int keyCode = get_input(); if (keyCode == KEY_CTRL_Q || keyCode == KEY_CTRL_X || keyCode == KEY_F10) { game_quit_with_confirm(); }