Use delay_ms instead of spinwait
This commit is contained in:
parent
e23b39abaa
commit
ff5f461e6d
|
@ -271,6 +271,8 @@ target_sources(${EXECUTABLE_NAME} PUBLIC
|
|||
"src/sfall_lists.h"
|
||||
"src/sfall_opcodes.cc"
|
||||
"src/sfall_opcodes.h"
|
||||
"src/delay.cc"
|
||||
"src/delay.h"
|
||||
)
|
||||
|
||||
if(IOS)
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
#include "window_manager.h"
|
||||
#include "word_wrap.h"
|
||||
#include "worldmap.h"
|
||||
#include "delay.h"
|
||||
|
||||
namespace fallout {
|
||||
|
||||
|
@ -1991,7 +1992,7 @@ static int _get_input_str(int win, int cancelKeyCode, char* text, int maxLength,
|
|||
|
||||
windowRefresh(win);
|
||||
|
||||
while (getTicksSince(_frame_time) < 1000 / 24) { }
|
||||
delay_ms(1000 / 24 - (getTicks() - _frame_time));
|
||||
|
||||
renderPresent();
|
||||
sharedFpsLimiter.throttle();
|
||||
|
@ -2281,8 +2282,7 @@ static void characterEditorDrawBigNumber(int x, int y, int flags, int value, int
|
|||
windowWidth);
|
||||
windowRefreshRect(windowHandle, &rect);
|
||||
renderPresent();
|
||||
while (getTicksSince(_frame_time) < BIG_NUM_ANIMATION_DELAY)
|
||||
;
|
||||
delay_ms(BIG_NUM_ANIMATION_DELAY - (getTicks() - _frame_time));
|
||||
}
|
||||
|
||||
blitBufferToBuffer(numbersGraphicBufferPtr + BIG_NUM_WIDTH * ones,
|
||||
|
@ -2304,8 +2304,7 @@ static void characterEditorDrawBigNumber(int x, int y, int flags, int value, int
|
|||
windowWidth);
|
||||
windowRefreshRect(windowHandle, &rect);
|
||||
renderPresent();
|
||||
while (getTicksSince(_frame_time) < BIG_NUM_ANIMATION_DELAY)
|
||||
;
|
||||
delay_ms(BIG_NUM_ANIMATION_DELAY - (getTicks() - _frame_time));
|
||||
}
|
||||
|
||||
blitBufferToBuffer(numbersGraphicBufferPtr + BIG_NUM_WIDTH * tens,
|
||||
|
@ -3530,11 +3529,9 @@ static int characterEditorEditAge()
|
|||
}
|
||||
|
||||
if (v33 > dbl_50170B) {
|
||||
while (getTicksSince(_frame_time) < 1000 / _repFtime)
|
||||
;
|
||||
delay_ms(1000 / _repFtime - (getTicks() - _frame_time));
|
||||
} else {
|
||||
while (getTicksSince(_frame_time) < 1000 / 24)
|
||||
;
|
||||
delay_ms(1000 / 24 - (getTicks() - _frame_time));
|
||||
}
|
||||
|
||||
keyCode = inputGetInput();
|
||||
|
@ -3548,8 +3545,7 @@ static int characterEditorEditAge()
|
|||
} else {
|
||||
windowRefresh(win);
|
||||
|
||||
while (getTicksSince(_frame_time) < 1000 / 24)
|
||||
;
|
||||
delay_ms(1000 / 24 - (getTicks() - _frame_time));
|
||||
}
|
||||
|
||||
renderPresent();
|
||||
|
@ -3699,8 +3695,7 @@ static void characterEditorEditGender()
|
|||
|
||||
windowRefresh(win);
|
||||
|
||||
while (getTicksSince(_frame_time) < 41)
|
||||
;
|
||||
delay_ms(41 - (getTicks() - _frame_time));
|
||||
|
||||
renderPresent();
|
||||
sharedFpsLimiter.throttle();
|
||||
|
@ -3778,12 +3773,9 @@ static void characterEditorAdjustPrimaryStat(int eventCode)
|
|||
}
|
||||
|
||||
if (v11 >= 19.2) {
|
||||
unsigned int delay = 1000 / _repFtime;
|
||||
while (getTicksSince(_frame_time) < delay) {
|
||||
}
|
||||
delay_ms(1000 / _repFtime - (getTicks() - _frame_time));
|
||||
} else {
|
||||
while (getTicksSince(_frame_time) < 1000 / 24) {
|
||||
}
|
||||
delay_ms(1000 / 24 - (getTicks() - _frame_time));
|
||||
}
|
||||
|
||||
renderPresent();
|
||||
|
@ -5279,11 +5271,9 @@ static void characterEditorHandleAdjustSkillButtonPressed(int keyCode)
|
|||
if (!isUsingKeyboard) {
|
||||
unspentSp = pcGetStat(PC_STAT_UNSPENT_SKILL_POINTS);
|
||||
if (repeatDelay >= dbl_5018F0) {
|
||||
while (getTicksSince(_frame_time) < 1000 / _repFtime) {
|
||||
}
|
||||
delay_ms(1000 / _repFtime - (getTicks() - _frame_time));
|
||||
} else {
|
||||
while (getTicksSince(_frame_time) < 1000 / 24) {
|
||||
}
|
||||
delay_ms(1000 / 24 - (getTicks() - _frame_time));
|
||||
}
|
||||
|
||||
int keyCode = inputGetInput();
|
||||
|
@ -6141,11 +6131,9 @@ static int perkDialogHandleInput(int count, void (*refreshProc)())
|
|||
}
|
||||
|
||||
if (v19 < dbl_5019BE) {
|
||||
while (getTicksSince(_frame_time) < 1000 / 24) {
|
||||
}
|
||||
delay_ms(1000 / 24 - (getTicks() - _frame_time));
|
||||
} else {
|
||||
while (getTicksSince(_frame_time) < 1000 / _repFtime) {
|
||||
}
|
||||
delay_ms(1000 / _repFtime - (getTicks() - _frame_time));
|
||||
}
|
||||
|
||||
renderPresent();
|
||||
|
@ -6188,11 +6176,9 @@ static int perkDialogHandleInput(int count, void (*refreshProc)())
|
|||
}
|
||||
|
||||
if (v19 < dbl_5019BE) {
|
||||
while (getTicksSince(_frame_time) < 1000 / 24) {
|
||||
}
|
||||
delay_ms(1000 / 24 - (getTicks() - _frame_time));
|
||||
} else {
|
||||
while (getTicksSince(_frame_time) < 1000 / _repFtime) {
|
||||
}
|
||||
delay_ms(1000 / _repFtime - (getTicks() - _frame_time));
|
||||
}
|
||||
|
||||
renderPresent();
|
||||
|
@ -6224,11 +6210,9 @@ static int perkDialogHandleInput(int count, void (*refreshProc)())
|
|||
}
|
||||
|
||||
if (v19 < dbl_5019BE) {
|
||||
while (getTicksSince(_frame_time) < 1000 / 24) {
|
||||
}
|
||||
delay_ms(1000 / 24 - (getTicks() - _frame_time));
|
||||
} else {
|
||||
while (getTicksSince(_frame_time) < 1000 / _repFtime) {
|
||||
}
|
||||
delay_ms(1000 / _repFtime - (getTicks() - _frame_time));
|
||||
}
|
||||
|
||||
renderPresent();
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "svga.h"
|
||||
#include "text_font.h"
|
||||
#include "window_manager.h"
|
||||
#include "delay.h"
|
||||
|
||||
namespace fallout {
|
||||
|
||||
|
@ -172,8 +173,7 @@ void creditsOpen(const char* filePath, int backgroundFid, bool useReversedStyle)
|
|||
windowBuffer,
|
||||
windowWidth);
|
||||
|
||||
while (getTicksSince(tick) < CREDITS_WINDOW_SCROLLING_DELAY) {
|
||||
}
|
||||
delay_ms(CREDITS_WINDOW_SCROLLING_DELAY - (getTicks() - tick));
|
||||
|
||||
tick = getTicks();
|
||||
|
||||
|
@ -215,8 +215,7 @@ void creditsOpen(const char* filePath, int backgroundFid, bool useReversedStyle)
|
|||
windowBuffer,
|
||||
windowWidth);
|
||||
|
||||
while (getTicksSince(tick) < CREDITS_WINDOW_SCROLLING_DELAY) {
|
||||
}
|
||||
delay_ms(CREDITS_WINDOW_SCROLLING_DELAY - (getTicks() - tick));
|
||||
|
||||
tick = getTicks();
|
||||
|
||||
|
|
18
src/dbox.cc
18
src/dbox.cc
|
@ -21,6 +21,7 @@
|
|||
#include "text_font.h"
|
||||
#include "window_manager.h"
|
||||
#include "word_wrap.h"
|
||||
#include "delay.h"
|
||||
|
||||
namespace fallout {
|
||||
|
||||
|
@ -885,8 +886,8 @@ int showLoadFileDialog(char* title, char** fileList, char* dest, int fileListLen
|
|||
}
|
||||
|
||||
unsigned int delay = (scrollCounter > 14.4) ? 1000 / scrollDelay : 1000 / 24;
|
||||
while (getTicksSince(scrollTick) < delay) {
|
||||
}
|
||||
|
||||
delay_ms(delay - (getTicks() - scrollTick));
|
||||
|
||||
if (_game_user_wants_to_quit != 0) {
|
||||
rc = 1;
|
||||
|
@ -908,9 +909,8 @@ int showLoadFileDialog(char* title, char** fileList, char* dest, int fileListLen
|
|||
doubleClickTimer = FILE_DIALOG_DOUBLE_CLICK_DELAY;
|
||||
doubleClickSelectedFileIndex = -2;
|
||||
}
|
||||
|
||||
while (getTicksSince(tick) < (1000 / 24)) {
|
||||
}
|
||||
|
||||
delay_ms(1000 / 24 - (getTicks() - tick));
|
||||
}
|
||||
|
||||
if (_game_user_wants_to_quit) {
|
||||
|
@ -1335,8 +1335,7 @@ int showSaveFileDialog(char* title, char** fileList, char* dest, int fileListLen
|
|||
// FIXME: Missing windowRefresh makes blinking useless.
|
||||
|
||||
unsigned int delay = (scrollCounter > 14.4) ? 1000 / scrollDelay : 1000 / 24;
|
||||
while (getTicksSince(scrollTick) < delay) {
|
||||
}
|
||||
delay_ms(delay - (getTicks() - scrollTick));
|
||||
|
||||
if (_game_user_wants_to_quit != 0) {
|
||||
rc = 1;
|
||||
|
@ -1368,9 +1367,8 @@ int showSaveFileDialog(char* title, char** fileList, char* dest, int fileListLen
|
|||
doubleClickTimer = FILE_DIALOG_DOUBLE_CLICK_DELAY;
|
||||
doubleClickSelectedFileIndex = -2;
|
||||
}
|
||||
|
||||
while (getTicksSince(tick) < (1000 / 24)) {
|
||||
}
|
||||
|
||||
delay_ms(1000 / 24 - (getTicks() - tick));
|
||||
}
|
||||
|
||||
if (_game_user_wants_to_quit != 0) {
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
#include "delay.h"
|
||||
#include <SDL.h>
|
||||
|
||||
void delay_ms(int ms) {
|
||||
if (ms <= 0){
|
||||
return;
|
||||
}
|
||||
SDL_Delay(ms);
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
#ifndef DELAY_H
|
||||
#define DELAY_H
|
||||
|
||||
void delay_ms(int ms);
|
||||
|
||||
#endif
|
|
@ -21,6 +21,7 @@
|
|||
#include "sfall_config.h"
|
||||
#include "svga.h"
|
||||
#include "window_manager.h"
|
||||
#include "delay.h"
|
||||
|
||||
namespace fallout {
|
||||
|
||||
|
@ -452,9 +453,8 @@ int elevatorSelectLevel(int elevator, int* mapPtr, int* elevationPtr, int* tileP
|
|||
_elevatorBackgroundFrmImage.getWidth());
|
||||
|
||||
windowRefresh(gElevatorWindow);
|
||||
|
||||
while (getTicksSince(tick) < delay) {
|
||||
}
|
||||
|
||||
delay_ms(delay - (getTicks() - tick));
|
||||
|
||||
renderPresent();
|
||||
sharedFpsLimiter.throttle();
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
#include "text_object.h"
|
||||
#include "tile.h"
|
||||
#include "window_manager.h"
|
||||
#include "delay.h"
|
||||
|
||||
namespace fallout {
|
||||
|
||||
|
@ -2970,10 +2971,8 @@ void _gdialog_scroll_subwin(int win, int a2, unsigned char* a3, unsigned char* a
|
|||
windowRefreshRect(win, &rect);
|
||||
v7 += 10;
|
||||
v9 -= 10 * (GAME_DIALOG_WINDOW_WIDTH);
|
||||
|
||||
tick = getTicks();
|
||||
while (getTicksSince(tick) < 33) {
|
||||
}
|
||||
|
||||
delay_ms(33);
|
||||
|
||||
renderPresent();
|
||||
sharedFpsLimiter.throttle();
|
||||
|
@ -3010,10 +3009,8 @@ void _gdialog_scroll_subwin(int win, int a2, unsigned char* a3, unsigned char* a
|
|||
windowRefreshRect(win, &rect);
|
||||
|
||||
rect.top += 10;
|
||||
|
||||
tick = getTicks();
|
||||
while (getTicksSince(tick) < 33) {
|
||||
}
|
||||
|
||||
delay_ms(33);
|
||||
|
||||
renderPresent();
|
||||
sharedFpsLimiter.throttle();
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "text_font.h"
|
||||
#include "vcr.h"
|
||||
#include "win32.h"
|
||||
#include "delay.h"
|
||||
|
||||
namespace fallout {
|
||||
|
||||
|
@ -633,12 +634,7 @@ void inputPauseForTocks(unsigned int delay)
|
|||
// 0x4C93B8
|
||||
void inputBlockForTocks(unsigned int ms)
|
||||
{
|
||||
unsigned int start = SDL_GetTicks();
|
||||
unsigned int diff;
|
||||
do {
|
||||
// NOTE: Uninline
|
||||
diff = getTicksSince(start);
|
||||
} while (diff < ms);
|
||||
delay_ms(ms);
|
||||
}
|
||||
|
||||
// 0x4C93E0
|
||||
|
|
|
@ -55,6 +55,7 @@
|
|||
#include "window_manager.h"
|
||||
#include "word_wrap.h"
|
||||
#include "worldmap.h"
|
||||
#include "delay.h"
|
||||
|
||||
namespace fallout {
|
||||
|
||||
|
@ -650,9 +651,9 @@ int lsgSaveGame(int mode)
|
|||
}
|
||||
|
||||
if (scrollCounter > 14.4) {
|
||||
while (getTicksSince(start) < 1000 / scrollVelocity) { }
|
||||
delay_ms(1000 / scrollVelocity - (getTicks() - start));
|
||||
} else {
|
||||
while (getTicksSince(start) < 1000 / 24) { }
|
||||
delay_ms(1000 / 24 - (getTicks() - start));
|
||||
}
|
||||
|
||||
keyCode = inputGetInput();
|
||||
|
@ -696,8 +697,7 @@ int lsgSaveGame(int mode)
|
|||
doubleClickSlot = -1;
|
||||
}
|
||||
|
||||
while (getTicksSince(tick) < 1000 / 24) {
|
||||
}
|
||||
delay_ms(1000 / 24 - (getTicks() - tick));
|
||||
}
|
||||
|
||||
if (rc == 1) {
|
||||
|
@ -1153,9 +1153,9 @@ int lsgLoadGame(int mode)
|
|||
}
|
||||
|
||||
if (scrollCounter > 14.4) {
|
||||
while (getTicksSince(start) < 1000 / scrollVelocity) { }
|
||||
delay_ms(1000 / scrollVelocity - (getTicks() - start));
|
||||
} else {
|
||||
while (getTicksSince(start) < 1000 / 24) { }
|
||||
delay_ms(1000 / 24 - (getTicks() - start));
|
||||
}
|
||||
|
||||
keyCode = inputGetInput();
|
||||
|
@ -1205,7 +1205,7 @@ int lsgLoadGame(int mode)
|
|||
doubleClickSlot = -1;
|
||||
}
|
||||
|
||||
while (getTicksSince(time) < 1000 / 24) { }
|
||||
delay_ms(1000 / 24 - (getTicks() - time));
|
||||
}
|
||||
|
||||
if (rc == 1) {
|
||||
|
@ -2277,8 +2277,7 @@ static int _get_input_str2(int win, int doneKeyCode, int cancelKeyCode, char* de
|
|||
windowRefresh(win);
|
||||
}
|
||||
|
||||
while (getTicksSince(tick) < 1000 / 24) {
|
||||
}
|
||||
delay_ms(1000 / 24 - (getTicks() - tick));
|
||||
|
||||
renderPresent();
|
||||
sharedFpsLimiter.throttle();
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
#include "audio_engine.h"
|
||||
#include "platform_compat.h"
|
||||
#include "delay.h"
|
||||
|
||||
namespace fallout {
|
||||
|
||||
|
@ -794,6 +795,8 @@ static int _syncWait()
|
|||
if (_sync_active) {
|
||||
if (((_sync_time + 1000 * compat_timeGetTime()) & 0x80000000) != 0) {
|
||||
result = 1;
|
||||
|
||||
delay_ms(-(_sync_time + 1000 * compat_timeGetTime())/1000 - 3);
|
||||
while (((_sync_time + 1000 * compat_timeGetTime()) & 0x80000000) != 0)
|
||||
;
|
||||
}
|
||||
|
@ -1148,6 +1151,7 @@ static int _MVE_sndConfigure(int a1, int a2, int a3, int a4, int a5, int a6)
|
|||
}
|
||||
|
||||
// 0x4F56C0
|
||||
// Looks like this function is not used
|
||||
static void _MVE_syncSync()
|
||||
{
|
||||
if (_sync_active) {
|
||||
|
@ -1294,6 +1298,10 @@ static void _MVE_sndSync()
|
|||
break;
|
||||
}
|
||||
v0 = true;
|
||||
|
||||
#ifdef EMSCRIPTEN
|
||||
delay_ms(1);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (dword_6B3660 != dword_6B3AE4) {
|
||||
|
@ -1316,7 +1324,11 @@ static int _syncWaitLevel(int a1)
|
|||
}
|
||||
|
||||
v2 = _sync_time + a1;
|
||||
do {
|
||||
do {
|
||||
result = v2 + 1000 * compat_timeGetTime();
|
||||
if (result < 0) {
|
||||
delay_ms(-result/1000 - 3);
|
||||
}
|
||||
result = v2 + 1000 * compat_timeGetTime();
|
||||
} while (result < 0);
|
||||
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
#include "window_manager.h"
|
||||
#include "word_wrap.h"
|
||||
#include "worldmap.h"
|
||||
#include "delay.h"
|
||||
|
||||
namespace fallout {
|
||||
|
||||
|
@ -2000,9 +2001,8 @@ static bool pipboyRest(int hours, int minutes, int duration)
|
|||
pipboyDrawNumber(gameTimeGetHour(), 4, PIPBOY_WINDOW_TIME_X, PIPBOY_WINDOW_TIME_Y);
|
||||
pipboyDrawDate();
|
||||
windowRefresh(gPipboyWindow);
|
||||
|
||||
while (getTicksSince(start) < 50) {
|
||||
}
|
||||
|
||||
delay_ms(50 - (getTicks() - start));
|
||||
}
|
||||
|
||||
renderPresent();
|
||||
|
@ -2072,8 +2072,7 @@ static bool pipboyRest(int hours, int minutes, int duration)
|
|||
pipboyDrawHitPoints();
|
||||
windowRefresh(gPipboyWindow);
|
||||
|
||||
while (getTicksSince(start) < 50) {
|
||||
}
|
||||
delay_ms(50 - (getTicks() - start));
|
||||
}
|
||||
|
||||
renderPresent();
|
||||
|
@ -2368,8 +2367,7 @@ static int pipboyRenderScreensaver()
|
|||
v31 -= 1;
|
||||
} else {
|
||||
windowRefreshRect(gPipboyWindow, &gPipboyWindowContentRect);
|
||||
while (getTicksSince(time) < 50) {
|
||||
}
|
||||
delay_ms(50 - (getTicks() - time));
|
||||
}
|
||||
|
||||
renderPresent();
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "text_font.h"
|
||||
#include "text_object.h"
|
||||
#include "window_manager.h"
|
||||
#include "delay.h"
|
||||
|
||||
namespace fallout {
|
||||
|
||||
|
@ -1569,9 +1570,8 @@ static void _DoThing(int eventCode)
|
|||
|
||||
blitBufferToBufferTrans(_preferencesFrmImages[PREFERENCES_WINDOW_FRM_KNOB_ON].getData(), 21, 12, 21, gPreferencesWindowBuffer + PREFERENCES_WINDOW_WIDTH * meta->knobY + v31, PREFERENCES_WINDOW_WIDTH);
|
||||
windowRefresh(gPreferencesWindow);
|
||||
|
||||
while (getTicksSince(tick) < 35)
|
||||
;
|
||||
|
||||
delay_ms(35 - (getTicks() - tick));
|
||||
|
||||
renderPresent();
|
||||
sharedFpsLimiter.throttle();
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "memory.h"
|
||||
#include "mouse.h"
|
||||
#include "svga.h"
|
||||
#include "delay.h"
|
||||
|
||||
namespace fallout {
|
||||
|
||||
|
@ -228,8 +229,7 @@ int vcrUpdate()
|
|||
* (vcrEntry->time - stru_6AD940.time)
|
||||
/ (vcrEntry->counter - stru_6AD940.counter);
|
||||
|
||||
while (getTicksSince(_vcr_start_time) < delay) {
|
||||
}
|
||||
delay_ms(delay - (getTicks() - _vcr_start_time));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue