Skip to content

Commit

Permalink
Merge pull request #130 from royqh1979/master
Browse files Browse the repository at this point in the history
确保ege_sleep精度
  • Loading branch information
wysaid authored Jan 3, 2023
2 parents 7ccd269 + f0fedc8 commit 6a4f951
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/egegapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,11 @@ void movewindow(int x, int y, bool redraw) {

void
api_sleep(long dwMilliseconds) {
if (dwMilliseconds >= 0)
if (dwMilliseconds >= 0) {
::timeBeginPeriod(1);
::Sleep(dwMilliseconds);
::timeEndPeriod(1);
}
}

void
Expand All @@ -332,6 +335,8 @@ ege_sleep(long ms) {
} else if (1) { //高精模式,占CPU更高
static HANDLE hTimer = ::CreateWaitableTimer(NULL, TRUE, NULL);
LARGE_INTEGER liDueTime;

::timeBeginPeriod(1);
liDueTime.QuadPart = ms * (LONGLONG)-10000;

if (hTimer) {
Expand All @@ -342,6 +347,7 @@ ege_sleep(long ms) {
} else {
::Sleep(ms);
}
::timeEndPeriod(1);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/graphicstest/maintest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ int main()
edit.create();
edit.size(100, 18);
edit.visible(true);
for ( ; kbhit() != -1; delay_fps(60)) {
for ( ; kbhit() != -1; delay_fps(120)) {
//f.zorderup();
{
char str[20];
Expand Down

0 comments on commit 6a4f951

Please sign in to comment.