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

+1 -1
View File
@@ -2980,7 +2980,7 @@ bool CWorldServer::ReloadMobSpawn( CPlayer* thisclient, int id )
fPoint position = RandInPoly( thisspawn->points, thisspawn->pcount );
map->AddMonster( thisspawn->montype, position, 0, thisspawn->id, 1 );
}
thisspawn->lastRespawnTime=clock();
thisspawn->lastRespawnTime=time(NULL);
return true;
}