Files
DarkflameServer/dDashboardServer/routes/Workers.h
Aaron Kimbrell 17689cd663 feat: build a zone's 3D data on worker threads
Opening a zone the first time built its terrain, scene objects and manifests
and ran ImageMagick on the web thread, stalling the dashboard for seconds.

- Workers: the shared pool plus Workers::Reply (answer at once when built,
  else from a worker via Web::Defer).
- terrain_chunks/terrain_layers/scene/paths/scenery/flairs (world3d, property
  and showcase routes) and terrain textures go through it; results are built
  once in OnceCaches, the .raw is read once per zone for chunks, layers and
  flairs, deflated bodies are cached thread-safely.
- ImageMagick conversions are deduplicated and written under a temporary name.
- Workers don't query the CDClient, read settings or call mongoose: ZoneTable,
  render components, flairs, object names, LOT kinds and terrain texture names
  are read at startup; client_location is read once; base64 is plain C++.
- Logger writes one line at a time (mutex; localtime's buffer is shared).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-28 22:30:51 -05:00

33 lines
1.2 KiB
C++

#pragma once
#include <functional>
#include "WorkerPool.h"
struct HTTPReply;
struct HTTPContext;
/**
* The dashboard's worker threads (one WorkerPool, scenery_workers threads) for slow work routes would otherwise do
* on the web server's one thread: converting the client's models, building a zone's terrain and scene data the
* first time it is viewed, converting textures with ImageMagick. What they run must be thread safe: the zone data
* builders keep their results in OnceCaches and read the client's files through ClientAssets.
*/
namespace Workers {
// Start the threads (scenery_workers: 0 picks WorkerPool::DefaultThreads)
void Start();
// Stop them; queued work is dropped (answer deferred requests before Web::Shutdown)
void Stop();
WorkerPool& Pool();
/**
* Answer a request with what `fill` writes to the reply: right away when `ready` (what it needs is built, so it's
* quick), else from a worker thread (Web::Defer). `fill` runs on either thread, so it must be thread safe and must
* not keep a reference to the request.
*/
void Reply(HTTPReply& reply, const HTTPContext& context, bool ready, std::function<void(HTTPReply&)> fill,
WorkerPool::ePriority priority = WorkerPool::ePriority::NORMAL);
}