CPixmap
Header: include/pixmap.hpp
Implementation: src/pixmap.cpp (~1,922 lines) +
src/pixtables.cpp (static lookup tables)
CPixmap is the DirectDraw surface manager.
It owns all image surfaces, manages the 15 render channels, handles sprite blitting,
and drives the final display flip from the back buffer to the screen.
All drawing in Free Eggbert goes through CPixmap.
Overview
CPixmap wraps DirectDraw (DirectX 3) surfaces and exposes a higher-level
API for loading sprite sheets, drawing sprites, and compositing the scene.
Via Free Direct, these DirectDraw calls are translated to SDL3.
| File | Role | Status |
|---|---|---|
src/pixmap.cpp |
DirectDraw surface allocation, blitting, sprite drawing, display flip | Done |
src/pixtables.cpp |
Static lookup tables for pixmap operations | Done |
The 15 Image Channels
CPixmap manages up to 15 simultaneous DirectDraw surfaces, each
identified by a channel enum defined in include/def.hpp.
Each channel holds the sprite sheet for one visual category.
| Enum | Value | Loaded from (IMAGE08/IMAGE16) |
|---|---|---|
CHBACK | 0 | decor000–031.blp (selected by region) |
CHOBJECT | 1 | object.blp |
CHBLUPI | 2 | blupi000.blp (default player) |
CHDECOR | 3 | Decorative overlay layer |
CHBUTTON | 4 | button.blp |
CHJAUGE | 5 | jauge.blp (always 8-bit) |
CHTEXT | 6 | text.blp |
CHLITTLE | 7 | littletxt.blp |
CHMAP | 8 | map.blp (always 8-bit) |
CHEXPLO | 9 | explo.blp |
CHELEMENT | 10 | element.blp |
CHBLUPI1 | 11 | blupi001.blp |
CHBLUPI2 | 12 | blupi002.blp |
CHBLUPI3 | 13 | blupi003.blp |
CHTEMP / CHMAX | 14 | Temporary scratch surface |
See Image Channels Reference for full details
and the note on CHJAUGE and CHMAP always being 8-bit.
Key Methods
Full signatures from include/pixmap.hpp:
// Initialization
BOOL Create(HWND hwnd, POINT dim, BOOL bFullScreen,
int mouseType, BOOL bTrueColor, BOOL bTrueColorDecor);
BOOL CacheAll(BOOL cache, HWND hWnd, BOOL bFullScreen,
BOOL bTrueColor, BOOL bTrueColorDecor,
int mouseType, const char* pFilename, int region);
BOOL Restore();
BOOL Flush();
// Loading channels
BOOL Cache(int channel, char* pFilename,
POINT totalDim, POINT iconDim, BOOL bUsePalette);
BOOL BackgroundCache(int channel, const char* pFilename,
POINT totalDim, POINT iconDim, BOOL bUsePalette);
void Flush(int channel);
// Drawing (chDst = destination channel/surface)
BOOL DrawIcon(int chDst, int channel, int rank,
POINT pos, int mode=0, BOOL bMask=FALSE);
BOOL DrawIconDemi(int chDst, int channel, int rank,
POINT pos, int mode=0, BOOL bMask=FALSE);
BOOL DrawIconPart(int chDst, int channel, int rank,
POINT pos, int startY, int endY,
int mode=0, BOOL bMask=FALSE);
BOOL DrawPart(int chDst, int channel,
POINT dest, RECT rect, int mode=0, BOOL bMask=FALSE);
BOOL DrawImage(int chDst, int channel, RECT rect, int mode=0);
BOOL DrawMap(int channel, RECT src, RECT dest);
void HudIcon(int channel, int rank, POINT pos);
void QuickIcon(int channel, int rank, POINT pos);
// Display
BOOL Display(); // flip back buffer to screen
void Fill(RECT rect, COLORREF color);
// Mouse cursor
void SetMousePosSprite(POINT pos, int sprite, BOOL bDemoPlay);
void MouseShow(BOOL bShow);
// Color depth
void SetTrueColorBack(BOOL bTrueColor);
void SetTrueColorDecor(BOOL bTrueColorDecor);
BOOL GetTrueColorBack();
BOOL GetTrueColorDecor();
Render Pipeline
Each frame, CDecor::Build() orchestrates rendering through CPixmap:
- Clear the back buffer (channel
CHBACKterrain drawn first) - Draw background decor tiles from the current region sheet
- Draw foreground objects from
CHOBJECT - Draw player character from
CHBLUPI(orCHBLUPI1–3in multiplayer) - Draw explosions from
CHEXPLO - Draw UI elements (buttons, gauges) from
CHBUTTON/CHJAUGE - Draw text overlays from
CHTEXT/CHLITTLE - Call
Display()to present the final frame
Color Depth Modes
CPixmap supports 8-bit (palette) and 16-bit (true color) surfaces.
The mode is set via config.def keys TrueColorBack and
TrueColorDecor. IMAGE16 is the default for character/decor sprites;
IMAGE08 is used when configured to 8-bit mode.
jauge.blp and map.blp do not have IMAGE16 counterparts —
they are always loaded from IMAGE08 regardless of the color depth setting.
Known Decompilation Issues
CPixmap::Create() twice: once
directly in DoInit() and again inside CacheAll().
Under real DirectDraw 3 this could produce
DDERR_PRIMARYSURFACEALREADYEXISTS or DDERR_EXCLUSIVEMODEALREADYSET.
Free Direct currently tolerates this; the root cause is under investigation.
pixmap.hpp and the definition in
pixmap.cpp have the bTrueColor and
bTrueColorDecor parameters in the opposite order, causing
the wrong value to be used for each setting.
See Decompilation Notes.
CacheAll(FALSE, ...) contains a delete this pattern
copied directly from the decompiled binary. This is inherently unsafe in C++
and is guarded by the _LEGACY compile flag.