diff --git a/Source/dthread.cpp b/Source/dthread.cpp index 1e96a605e..e052f1276 100644 --- a/Source/dthread.cpp +++ b/Source/dthread.cpp @@ -15,6 +15,44 @@ HANDLE sghWorkToDoEvent; /* rdata */ static HANDLE sghThread = INVALID_HANDLE_VALUE; +static unsigned int __stdcall dthread_handler(void *data) +{ + const char *error_buf; + TMegaPkt *pkt; + DWORD dwMilliseconds; + + while (dthread_running) { + if (!sgpInfoHead && WaitForSingleObject(sghWorkToDoEvent, INFINITE) == WAIT_FAILED) { + error_buf = TraceLastError(); + app_fatal("dthread4:\n%s", error_buf); + } + + sgMemCrit.Enter(); + pkt = sgpInfoHead; + if (sgpInfoHead) + sgpInfoHead = sgpInfoHead->pNext; + else + ResetEvent(sghWorkToDoEvent); + sgMemCrit.Leave(); + + if (pkt) { + if (pkt->dwSpaceLeft != MAX_PLRS) + multi_send_zero_packet(pkt->dwSpaceLeft, pkt->data[0], &pkt->data[8], *(DWORD *)&pkt->data[4]); + + dwMilliseconds = 1000 * *(DWORD *)&pkt->data[4] / gdwDeltaBytesSec; + if (dwMilliseconds >= 1) + dwMilliseconds = 1; + + mem_free_dbg(pkt); + + if (dwMilliseconds) + Sleep(dwMilliseconds); + } + } + + return 0; +} + void dthread_remove_player(int pnum) { TMegaPkt *pkt; @@ -76,44 +114,6 @@ void dthread_start() } } -unsigned int __stdcall dthread_handler(void *data) -{ - const char *error_buf; - TMegaPkt *pkt; - DWORD dwMilliseconds; - - while (dthread_running) { - if (!sgpInfoHead && WaitForSingleObject(sghWorkToDoEvent, INFINITE) == WAIT_FAILED) { - error_buf = TraceLastError(); - app_fatal("dthread4:\n%s", error_buf); - } - - sgMemCrit.Enter(); - pkt = sgpInfoHead; - if (sgpInfoHead) - sgpInfoHead = sgpInfoHead->pNext; - else - ResetEvent(sghWorkToDoEvent); - sgMemCrit.Leave(); - - if (pkt) { - if (pkt->dwSpaceLeft != MAX_PLRS) - multi_send_zero_packet(pkt->dwSpaceLeft, pkt->data[0], &pkt->data[8], *(DWORD *)&pkt->data[4]); - - dwMilliseconds = 1000 * *(DWORD *)&pkt->data[4] / gdwDeltaBytesSec; - if (dwMilliseconds >= 1) - dwMilliseconds = 1; - - mem_free_dbg(pkt); - - if (dwMilliseconds) - Sleep(dwMilliseconds); - } - } - - return 0; -} - void dthread_cleanup() { const char *error_buf; diff --git a/Source/dthread.h b/Source/dthread.h index f4dc99c6f..481410464 100644 --- a/Source/dthread.h +++ b/Source/dthread.h @@ -6,13 +6,9 @@ #ifndef __DTHREAD_H__ #define __DTHREAD_H__ -extern unsigned int glpDThreadId; -extern BOOLEAN dthread_running; - void dthread_remove_player(int pnum); void dthread_send_delta(int pnum, char cmd, void *pbSrc, int dwLen); void dthread_start(); -unsigned int __stdcall dthread_handler(void *data); void dthread_cleanup(); /* data */