Fix wall texture loading and improve loading times
Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
@@ -196,13 +196,25 @@ abstract class WLParser {
|
|||||||
// --- Private Helpers ---
|
// --- Private Helpers ---
|
||||||
|
|
||||||
static Sprite _parseWallChunk(ByteData vswap, int offset) {
|
static Sprite _parseWallChunk(ByteData vswap, int offset) {
|
||||||
final pixels = Uint8List(64 * 64);
|
// --- SAFETY CHECK ---
|
||||||
for (int x = 0; x < 64; x++) {
|
// Prevent crashes from corrupted VSWAP offsets or dummy EOF chunks
|
||||||
for (int y = 0; y < 64; y++) {
|
if (offset + 4096 > vswap.lengthInBytes) {
|
||||||
// Flat 1D index: x * 64 + y
|
// Return a blank transparent sprite if the data is invalid
|
||||||
pixels[x * 64 + y] = vswap.getUint8(offset + (x * 64) + y);
|
return Sprite(Uint8List(4096)..fillRange(0, 4096, 255));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --- OPTIMIZATION ---
|
||||||
|
// Instead of looping 4,096 times, we slice the exact memory block instantly.
|
||||||
|
// Because Wolf3D walls are natively stored in column-major order on disk,
|
||||||
|
// they perfectly match our 1D Sprite array layout without any math!
|
||||||
|
final rawView = vswap.buffer.asUint8List(
|
||||||
|
vswap.offsetInBytes + offset,
|
||||||
|
4096,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Create a new Uint8List copy so we don't hold the entire file in memory
|
||||||
|
final pixels = Uint8List.fromList(rawView);
|
||||||
|
|
||||||
return Sprite(pixels);
|
return Sprite(pixels);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,7 +237,6 @@ abstract class WLParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (int x = leftPix; x <= rightPix; x++) {
|
for (int x = leftPix; x <= rightPix; x++) {
|
||||||
// REVERTED to your original, correct math!
|
|
||||||
int colOffset = vswap.getUint16(
|
int colOffset = vswap.getUint16(
|
||||||
offset + 4 + ((x - leftPix) * 2),
|
offset + 4 + ((x - leftPix) * 2),
|
||||||
Endian.little,
|
Endian.little,
|
||||||
@@ -249,7 +260,6 @@ abstract class WLParser {
|
|||||||
if (endY == 0) break;
|
if (endY == 0) break;
|
||||||
endY ~/= 2;
|
endY ~/= 2;
|
||||||
|
|
||||||
// THE FIX: This MUST be a signed integer (getInt16) to handle DOS wraparound
|
|
||||||
int pixelOfs = vswap.getInt16(cmdOffset + 2, Endian.little);
|
int pixelOfs = vswap.getInt16(cmdOffset + 2, Endian.little);
|
||||||
|
|
||||||
int startY = vswap.getUint16(cmdOffset + 4, Endian.little);
|
int startY = vswap.getUint16(cmdOffset + 4, Endian.little);
|
||||||
|
|||||||
Reference in New Issue
Block a user