Migrate to a software rasterizer to dramatically improve performance

Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
2026-03-16 00:03:21 +01:00
parent 59fc530a1a
commit 752c143234
15 changed files with 553 additions and 522 deletions

View File

@@ -180,32 +180,33 @@ abstract class WLParser {
// --- Private Helpers ---
static Sprite _parseWallChunk(ByteData vswap, int offset) {
// Generate the 64x64 pixel grid in column-major order functionally
return List.generate(
64,
(x) => List.generate(64, (y) => vswap.getUint8(offset + (x * 64) + y)),
);
final pixels = Uint8List(64 * 64);
for (int x = 0; x < 64; x++) {
for (int y = 0; y < 64; y++) {
// Flat 1D index: x * 64 + y
pixels[x * 64 + y] = vswap.getUint8(offset + (x * 64) + y);
}
}
return Sprite(pixels);
}
static Sprite _parseSingleSprite(ByteData vswap, int offset) {
// Initialize the 64x64 grid with 255 (The Magenta Transparency Color!)
Sprite sprite = List.generate(64, (_) => List.filled(64, 255));
// Initialize the 1D array with 255 (Transparency)
final pixels = Uint8List(64 * 64)..fillRange(0, 4096, 255);
Sprite sprite = Sprite(pixels);
int leftPix = vswap.getUint16(offset, Endian.little);
int rightPix = vswap.getUint16(offset + 2, Endian.little);
// Parse vertical columns within the sprite bounds
for (int x = leftPix; x <= rightPix; x++) {
int colOffset = vswap.getUint16(
offset + 4 + ((x - leftPix) * 2),
Endian.little,
);
if (colOffset != 0) {
_parseSpriteColumn(vswap, sprite, x, offset, offset + colOffset);
}
}
return sprite;
}
@@ -216,23 +217,21 @@ abstract class WLParser {
int baseOffset,
int cmdOffset,
) {
// Execute the column drawing commands
while (true) {
int endY = vswap.getUint16(cmdOffset, Endian.little);
if (endY == 0) break; // 0 marks the end of the column
endY ~/= 2; // Wolf3D stores Y coordinates multiplied by 2
if (endY == 0) break;
endY ~/= 2;
int pixelOfs = vswap.getUint16(cmdOffset + 2, Endian.little);
int startY = vswap.getUint16(cmdOffset + 4, Endian.little);
startY ~/= 2;
for (int y = startY; y < endY; y++) {
// The Carmack 286 Hack: pixelOfs + y gives the exact byte address
sprite[x][y] = vswap.getUint8(baseOffset + pixelOfs + y);
// Write directly to the 1D array
sprite.pixels[x * 64 + y] = vswap.getUint8(baseOffset + pixelOfs + y);
}
cmdOffset += 6; // Move to the next 6-byte instruction
cmdOffset += 6;
}
}