Fix respawn/spawn timers racing ahead under multi-threading

POSIX clock() sums CPU time across every thread in the process, unlike
Windows' clock() which tracks wall-clock milliseconds. With several
worker threads running, respawn/spawn/AI timers based on clock() raced
far ahead of real elapsed time. Switch spawn-timer bookkeeping to
time(NULL)/time_t (seconds) throughout the world server, and add a
portable clock() shim in sockets.h (backed by CLOCK_MONOTONIC,
millisecond resolution) for remaining call sites so CLOCKS_PER_SEC==1000
still holds like it did on Windows.

Also: fix MapDelay/VisualDelay/WorldDelay being passed to usleep() (us)
without converting from their configured milliseconds; fix the shutdown
timer likewise; stop leaking the temporary actor used to run an NPC's
AIP script; fix CleanDrops() skipping the element that shifts into
position after an erase.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
ThomasandClaude Sonnet 5 committed 2026-07-09 06:35:05 +02:00
1 parent 1f626c6b93
commit 725620e23c
8 files changed
+66 -37

No files matched your search

+2 -2
View File
@@ -271,7 +271,7 @@ bool CMap::DeleteMonster( CMonster* monster, bool clearobject, UINT i )
if(thisspawn != NULL)
{
if(thisspawn->amon >= thisspawn->max)// reset spawn timer if the spawn is full
thisspawn->lastRespawnTime = clock();
thisspawn->lastRespawnTime = time(NULL);
thisspawn->amon--;
UpdateSpawnCounter( thisspawn->montype, thisspawn->id, 2);
}
@@ -282,7 +282,7 @@ bool CMap::DeleteMonster( CMonster* monster, bool clearobject, UINT i )
if(thisgroup!=NULL)
{
if(thisgroup->active >= thisgroup->limit)// reset spawn timer if the spawn is full
thisgroup->lastRespawnTime = clock();
thisgroup->lastRespawnTime = time(NULL);
thisgroup->active--;
thisgroup->basicKills++;
}