dima424658/darkengine: the lost runtime that made Thief’s world tick

A deep look at Looking Glass’s DIY COM layer, the Dark Loop scheduler, and the unusually modular engine architecture hidden inside a late-1990s immersive sim.

9 min read • View on GitHub • More from dima424658

A wide black-ink editorial scene of a clockwork city built from stacked engine layers. At the center, a circular loop mechanism pushes tokens through input, AI, sound, rendering, and mode switching, while separate modules plug into the ring like mechanical blocks. The image explains that the engine’s core identity is a scheduler and component bus, not a single monolithic game loop.
The Dark Engine behaves less like one program and more like a disciplined city of peers, all marching through the same loop.
Key Takeaways

The engine is a scheduler before it is a game

The surprise inside dima424658/darkengine is not a renderer or an AI system. It is the fact that the engine is organized around a message-driven runtime, where modes and frame phases matter more than any single subsystem.

That is why the Dark Engine feels coherent. Input, sound, AI, rendering, loading, and menus all move through the same control plane, in a fixed order, with explicit transitions instead of ad hoc branching.

The Dark Loop is a staged dispatcher. It keeps frame order stable while letting modes change underneath it.

That matters in an immersive sim because the world cannot feel like it is pausing to make exceptions for itself. A predictable loop lets the engine keep systems in step, which is exactly what you want when AI, physics, audio, and UI all have to coexist without breaking the fiction.

The Dark Engine is a 3D game engine developed and used by Looking Glass Studios for Thief: The Dark Project (1998), Thief II: The Metal Age (2000), and the Irrational Games joint projects System Shock 2 (1999) and Deep Cover (the project was cancelled). Source code is based on Thief 2 leak. Don't use it for commercial purposes.

dima424658, Maintainer · GitHub - dima424658/darkengine

Why immersion starts with control flow

The Dark Loop is not elegant for elegance’s sake. It exists because a simulation-heavy game needs one place to decide who runs now, who waits, and which sub-state is allowed to interrupt the rest.

That is also why the engine supports things like minor modes. A menu, a loading step, or a minigame can appear as a nested state instead of a separate program, which keeps the rest of the world alive in the background.

A close-up black-ink cross-section of a message pipeline divided into three horizontal bands for Begin Frame, Normal Frame, and End Frame. A side branch leads into Enter Mode and Exit Mode, with a smaller nested chamber representing a Minor Mode inside the main path. The image explains how the scheduler preserves order while allowing sub-states to branch without resetting the whole engine.
The trick is not just dispatch. It is keeping the main loop intact while nested modes borrow control for a while.

Looking Glass built its own COM clone

The other big idea in this repo is the component model. Looking Glass did not rely on a giant inheritance tree. It built a COM-like world of aggregates, interfaces, and runtime queries, so systems could be swapped and composed at runtime.

/* Simplified from the engine's aggregate pattern */
class IThing : public IUnknown {
public:
    virtual void Update() = 0;
};

class cAppAggregate {
public:
    HRESULT QueryInterface(REFIID iid, void** out);
    ULONG AddRef();
    ULONG Release();
};

// Subsystems are discovered at runtime, not hard-wired into one class graph.
IThing* input = nullptr;
appAggregate->QueryInterface(IID_IThing, (void**)&input);

That design is older than modern plugin talk, but it rhymes with it. The engine can swap implementations without rewriting the whole game around them, which is exactly what a large late-1990s studio needed.

The Windows wrapper is the thin skin on top

At the boundary, Windows still does Windows things. But the wrapper code folds Win32 message handling into the engine’s own rules, so the OS event loop becomes an input source instead of the final authority.

BOOL cWindowsApplication::DispatchOneMessage() {
    MSG msg;
    if (!GetMessage(&msg, nullptr, 0, 0))
        return FALSE;

    if (PreTranslateMessage(&msg))
        return TRUE;

    TranslateMessage(&msg);
    DispatchMessage(&msg);
    return TRUE;
}

That layering is the point. The outside world speaks Win32, but the inside world speaks loop messages, mode transitions, and frame phases.

Why this repo exists now

This repository is a reconstruction of leaked source, not a clean-room rewrite. That makes it historically valuable for engine archaeology, but it also makes its legal and practical status more complicated than a normal open-source game engine.

That tension explains its audience. Modders want source-level clues. Preservationists want the original logic. Engine readers want to see how a shipping studio solved modularity, scheduling, and platform glue under 1990s constraints.

ProjectWhat it isSource availabilityMain valueBest forTradeoff
darkengineSource-level reconstruction of the original Dark EnginePublic, but based on leaked codeHistorical fidelity and engine archaeologyResearch, modding clues, studying original logicNot the cleanest path to modern playability
NewDarkBinary update and compatibility patch for the original engineClosed sourceBest-in-class way to run the classic gamesPlaying original missions on modern systemsOpaque internals
The Dark ModStandalone open-source reimplementation inspired by ThiefOpen sourceModern, legal, actively maintained Thief-like playCreating new missions and using a modern toolchainNot the original engine code

That comparison is the cleanest way to place the repo. darkengine is not the most convenient option, and that is exactly why it is interesting.

The strange longevity of a 1990s engine

The same choices that made the engine flexible also made it heavy with era-specific assumptions. A custom loop, COM-like aggregation, legacy DirectX dependencies, and low-level compiler workarounds gave Looking Glass control, but they also tied the code to a very particular moment in Windows game development.

That is the lasting lesson of darkengine. The code is dated, but the architecture is not primitive. It is a serious attempt to turn a game into a coordinated runtime, and it still reads that way.