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

+3 -3
View File
@@ -331,7 +331,7 @@ bool CWorldServer::LoadMobGroups()
thisgroup->tacticalpoints = atoi(row[7]);
char* mobList = row[8];
thisgroup->lastRespawnTime = clock();
thisgroup->lastRespawnTime = time(NULL);
thisgroup->active = 0;
thisgroup->basicKills = 0;
thisgroup->curTac = 0;
@@ -439,7 +439,7 @@ bool CWorldServer::LoadMonsterSpawn( )
if (thisspawn->respawntime == 0)
thisspawn->respawntime=5;
thisspawn->amon = 0;
thisspawn->lastRespawnTime = clock();
thisspawn->lastRespawnTime = time(NULL);
thisspawn->type = atoi(row[9]);
thisspawn->triggertype = atoi(row[10]);
thisspawn->triggeramount = atoi(row[11]);
@@ -1244,7 +1244,7 @@ bool CWorldServer::LoadZoneData( )
//TD stuff
newzone->TDNextMon = 0;
newzone->TDNextSpawn = 0;
newzone->lastTDSpawnTime = clock();
newzone->lastTDSpawnTime = time(NULL);
newzone->LastUpdate = clock( );
newzone->CurrentTime = 0;
newzone->TDMobDelay = 1500;