86 lines
12 KiB
Markdown
86 lines
12 KiB
Markdown
|
|
# Pentagram Rendering Compared With The Windows Rebuild
|
||
|
|
|
||
|
|
## Scope
|
||
|
|
|
||
|
|
This note compares the checked-in Pentagram renderer with the current native renderer in `rebuild/remorse`. It describes source-level behavior, not a claim that Pentagram is a pixel-perfect Crusader reference or that its code can be dropped into the rebuild unchanged. The Pentagram tree was inspected read-only; no game data or generated scene data was copied between repositories.
|
||
|
|
|
||
|
|
## Summary
|
||
|
|
|
||
|
|
Pentagram renders the current world view from live map items on each paint. It activates map chunks around the camera, adds only those chunk items to a per-frame display list, rejects fully clipped sprites before sorting, resolves overlapping-item order, and draws each frame directly to a clipped software surface.
|
||
|
|
|
||
|
|
The rebuild instead constructs a player-centered bitmap, stores it as a scene backing image, and paints a crop of that image plus a separate player patch. A full-scene refresh reconstructs the item/node list and sort order, then replaces the backing image. The camera-prefetch change starts that refresh before the crop is exhausted, but it is still a whole-scene refresh rather than Pentagram-style active-area rendering.
|
||
|
|
|
||
|
|
The main transferable idea is therefore **spatially bounded live rendering**, not a different graphics API. Pentagram's order resolver and game-specific item rules still need Crusader verification before reuse.
|
||
|
|
|
||
|
|
## Pipeline Comparison
|
||
|
|
|
||
|
|
| Concern | Pentagram | Current Windows rebuild |
|
||
|
|
|---|---|---|
|
||
|
|
| World candidates | `CurrentMap` stores items in a 64 x 64 grid. `GameMapGump::PaintThis` visits active (`fast`) chunks only. | `collectSceneItems` stages fixed/live items and expands glob contents for the render. Full-scene options currently have no world rectangle, so the full item set participates in each scene render. |
|
||
|
|
| Camera/visibility | `CameraProcess::GetLerped` updates a screen-space fast area. `CurrentMap::updateFastArea` uses coarse chunk bounds plus a projected chunk-rectangle check and a margin around the viewport. | A 2560 x 1440 player-centered backing image is cropped for the 1280 x 760 client. Near the crop margin, the UI asks the worker to build a new backing image around the player. |
|
||
|
|
| Sprite culling | `ItemSorter::AddItem` gets frame bounds and calls `RenderSurface::CheckClipped` before adding a sprite to the dependency/sort list. The software painter also clips rows and pixels. | Scene nodes are prepared and sorted before `MapSceneRenderer::render` tests their rectangles against the output crop. The output loop avoids painting off-crop nodes, but most have already incurred node preparation and sort work. |
|
||
|
|
| Draw order | `ItemSorter` incrementally builds overlap dependencies from item bounding boxes, including occlusion tests, then recursively paints dependencies before their dependents. | `prepareRenderNodes` builds a complete vector of sort items and `resolveRenderOrder` computes a full order for the collected render set. |
|
||
|
|
| Allocation reuse | `ItemSorter` recycles `SortItem` objects and each item's dependency-list nodes between display lists. | Vectors are reserved per render, but scene items, render nodes, sort items, and order are rebuilt on every render. Decoded frames are cached by shape/frame in `MapSceneRenderer`; the parsed-frame table is local to a render call. |
|
||
|
|
| Shape representation | `ShapeArchive::cache` loads a `Shape` on demand and retains it in the archive. Each `Shape` retains `ShapeFrame` metadata; `ShapeFrame` keeps line offsets and compressed RLE bytes, which the software painter walks directly. | Shape frames are decoded into pixel buffers and palette colors for rendering. The decoded-frame cache persists on the renderer, while scene nodes and ordering do not. |
|
||
|
|
| Pixel destination | The normal `RenderSurface::SetVideoMode` path requests an SDL software surface. `SoftRenderSurface` paints shape RLE directly into it; `EndPainting` presents with `SDL_Flip`. | The renderer fills a 2560 x 1440 `RenderedMapImage`, converts it to BGR DIB pixels, and `paintWindow` copies the visible crop, overlays the player patch, then calls `StretchDIBits`. |
|
||
|
|
| Update cadence | `GUIApp::paint` paints the desktop/gump tree each frame. `GameMapGump` obtains an interpolated camera position and builds/paints the world display list for that view. | The UI paints the cached scene crop each window paint. A background worker handles player patches and full backing-image refreshes; ordinary movement does not rebuild the full image unless a recenter or world mutation requires it. |
|
||
|
|
|
||
|
|
## Pentagram Details
|
||
|
|
|
||
|
|
### Active Map Area
|
||
|
|
|
||
|
|
`CurrentMap` keeps a chunk grid and a separate fast-area bitset. For Crusader, the chunk size is 1024 world units; the same class uses 512 for Ultima VIII. `updateFastArea` expands the camera's from/to bounds by viewport and chunk margins, checks a coarse chunk range, then calls `ChunkOnScreen` to test projected chunk bounds. `setChunkFast` and `unsetChunkFast` notify items entering or leaving the active area.
|
||
|
|
|
||
|
|
`CameraProcess::GetLerped` updates this area using the camera's interpolated interval. This keeps world activation ahead of camera movement rather than waiting until a fixed offscreen bitmap is exhausted.
|
||
|
|
|
||
|
|
### Display List And Visibility
|
||
|
|
|
||
|
|
`GameMapGump::PaintThis` calls `BeginDisplayList` with the interpolated camera, loops the chunk grid, skips chunks that are not fast, and submits items from active chunks. It also applies runtime filters for roofs, editor objects, and the special invisible-avatar case.
|
||
|
|
|
||
|
|
`ItemSorter::AddItem` obtains the shape frame and its dimensions, computes world and projected bounding boxes, and rejects fully clipped sprite rectangles before doing overlap/dependency work. Visible candidates are compared with existing candidates; overlap and occlusion relationships become dependency links. `PaintDisplayList` walks those links so objects behind an occluder paint first and fully occluded nodes are skipped.
|
||
|
|
|
||
|
|
This is not a simple global depth sort. It models Crusader/U8 item overlap rules using footpad bounds and projected geometry. It is also not automatically faster for every workload: each accepted item compares against earlier list entries, so a crowded active area can make insertion expensive. Pentagram gets its benefit primarily from limiting the candidate set and clipping before dependency construction.
|
||
|
|
|
||
|
|
### Shape And Pixel Path
|
||
|
|
|
||
|
|
`ShapeArchive::getShape` calls `cache`; a loaded `Shape` is retained in the archive's indexed shape vector. `Shape` creates frame objects once. `ShapeFrame` stores dimensions, offsets, line offsets, and an RLE data pointer. `SoftRenderSurface.inl` walks those runs and maps palette indices directly to destination pixels, with per-line and per-pixel clipping. It does not first expand every frame into a full RGB bitmap.
|
||
|
|
|
||
|
|
The standard surface is software-backed in the checked-in implementation: `RenderSurface::SetVideoMode(..., use_opengl=true)` reports OpenGL disabled, and the normal path selects `SDL_SWSURFACE` plus `SoftRenderSurface`. There is conditional D3D code behind an experimental compile flag, but it is not the default path.
|
||
|
|
|
||
|
|
## Differences That Matter For The Rebuild
|
||
|
|
|
||
|
|
1. **Selection happens too late in the rebuild.** The current full render creates nodes and resolves order for the full map before the final output-crop intersection. Pentagram's fast chunks reduce the set before its display list is sorted, and its clip test rejects off-surface frames before dependency insertion.
|
||
|
|
2. **The rebuild has a backing-image boundary.** Crossing its prefetch threshold triggers a full scene render and replacement. Pentagram shifts the active world area with the camera and paints the current surface every frame; it does not need to rebuild a large player-centered bitmap to move the view.
|
||
|
|
3. **The rebuild repeats preparation work.** Decoded pixels are retained, but scene collection, render-node construction, and order resolution are repeated for each full refresh. Pentagram also rebuilds a display list each paint, but does so only for active chunks and reuses its node/dependency allocations.
|
||
|
|
4. **The pixel strategies differ.** Pentagram pays the RLE walk and palette conversion while drawing clipped pixels. The rebuild pays frame decode and buffer memory up front, then copies RGB pixels during rasterization and DIB presentation. Which wins depends on active-item count, sprite coverage, and movement; source inspection alone does not establish a universal timing winner.
|
||
|
|
5. **Their sorting contracts are related, not identical.** The rebuild already ports several `ItemSorter` concepts, but Pentagram's `SortItem` flags, overlap tests, transparency behavior, roof rules, and insertion/dependency order should be compared case-by-case before claiming parity.
|
||
|
|
|
||
|
|
One instrumented map-1 launch of the rebuild after widening the initial scene selection produced 16,542 render candidates, 16,540 decoded nodes, and 1,355 painted nodes. The initial scene published in about 0.76 seconds on that run. This is evidence that scene creation is currently sub-second on this machine, but it also shows that most prepared nodes did not touch the initial viewport. It does not measure repeated camera recentering or establish how long a crowded region takes.
|
||
|
|
|
||
|
|
## Practical Directions
|
||
|
|
|
||
|
|
1. Add a native spatial index over map chunks or projected bounds. Query only chunks intersecting the camera's visible area plus a measured overscan margin; update membership before the player reaches the edge. Preserve a conservative overlap margin for tall sprites and glob contents.
|
||
|
|
2. Use conservative sprite bounds from TYPEFLAG dimensions and frame metadata to reject offscreen candidates before full pixel decoding and order resolution. Keep the final per-pixel clip as the correctness boundary.
|
||
|
|
3. Reuse stable render-node and sorting storage, or cache static-map preparation separately from mutable/live items. Invalidate only when relevant map content changes; do not reuse a stale sorted list across changed flags, positions, frames, globs, or roofs.
|
||
|
|
4. Keep avatar animation work independent in priority from whole-scene refreshes. The current worker now publishes the player patch before a full scene render and coalesces camera-prefetch requests; measure whether that removes the observed animation stall before adding a second concurrent renderer.
|
||
|
|
5. Instrument per-frame counts and durations: chunks visited/active, items submitted, rejected by clip, decoded-frame cache hits/misses, sort comparisons, nodes painted, and time in collection/sort/raster/presentation. This will identify whether chunk activation, early culling, cache reuse, or incremental redraw has the best payoff.
|
||
|
|
|
||
|
|
Pentagram's 6 x 5 dirty-tile renderer documented in the original Crusader draw-list analysis is a separate original-executable mechanism; it should not be inferred from Pentagram's `CurrentMap` fast chunks. Fast chunks activate world objects, while Pentagram's checked-in `GameMapGump` still paints its display list to the current render surface each frame.
|
||
|
|
|
||
|
|
## Source References
|
||
|
|
|
||
|
|
### Pentagram
|
||
|
|
|
||
|
|
- [`GameMapGump::PaintThis`](../../../misc/pentagram/gumps/GameMapGump.cpp)
|
||
|
|
- [`ItemSorter::BeginDisplayList`, `AddItem`, and `PaintDisplayList`](../../../misc/pentagram/world/ItemSorter.cpp)
|
||
|
|
- [`CurrentMap::updateFastArea`, `ChunkOnScreen`, and fast-area transitions`](../../../misc/pentagram/world/CurrentMap.cpp)
|
||
|
|
- [`CameraProcess::GetLerped`](../../../misc/pentagram/world/CameraProcess.cpp)
|
||
|
|
- [`ShapeArchive::getShape` and `cache`](../../../misc/pentagram/graphics/ShapeArchive.cpp)
|
||
|
|
- [`Shape` frame loading](../../../misc/pentagram/graphics/Shape.cpp), [`ShapeFrame`](../../../misc/pentagram/graphics/ShapeFrame.cpp), and [`SoftRenderSurface` RLE painter](../../../misc/pentagram/graphics/SoftRenderSurface.inl)
|
||
|
|
- [`RenderSurface` backend selection](../../../misc/pentagram/graphics/RenderSurface.cpp), [`GUIApp::paint`](../../../misc/pentagram/kernel/GUIApp.cpp), and [`BaseSoftRenderSurface::EndPainting`](../../../misc/pentagram/graphics/BaseSoftRenderSurface.cpp)
|
||
|
|
|
||
|
|
### Native Rebuild
|
||
|
|
|
||
|
|
- [`MapSceneRenderer::render`, item collection, and node preparation](../rebuild/remorse/src/map_renderer.cpp)
|
||
|
|
- [`fullSceneOptions`, `startLiveRenderer`, `paintWindow`, and camera-prefetch requests](../rebuild/remorse/src/windowed_game_main.cpp)
|
||
|
|
- [Original draw-list/tile-visibility notes](raw-0007-rendering.md)
|