I think I have gotten rid of all the fluff at this point. Now I need to mess with fonts. I am a hair confused about fonts but, I wont be for long.
straight out of gfx.wad 0x40 type

if you wanted to see where I'm at....edit:my tabbing looks like it's all over the place but, it isn't in my editor.
straight out of gfx.wad 0x40 type

if you wanted to see where I'm at....edit:my tabbing looks like it's all over the place but, it isn't in my editor.
Code:
public class WAD
{
private static const MAX_PALETTE_COLORS:int = 256;
private static const MAX_NAME_LENGTH:int = 16;
private static const QCHAR_WIDTH:int = 16;
private static const QNUM_GLYPHS:int = 256;
public static function parse(data:ByteArray):Vector.<Object>
{
data.endian = Endian.LITTLE_ENDIAN;
data.position = 0;
//check magic
if (data.readMultiByte(4, "iso-8859-1") != "WAD3")
throw new Error("Invalid or unsupported WAD file");
var cnt:int = data.readInt();
var ofs:int = data.readInt();
//prime vectors
var directories:Vector.<Object> = new Vector.<Object>(cnt);
var images:Vector.<Object> = new Vector.<Object>(cnt);
//set pointer
data.position = ofs;
//get all directories
directories.forEach( function(val:Object, n:int, self:Vector.<Object>):void
{ self[n] = {
offset: data.readInt(),
csize: data.readInt(),
dsize: data.readInt(),
type: data.readByte(),
comp: data.readBoolean(),
dummy: data.readShort(),
name: data.readMultiByte(MAX_NAME_LENGTH, "iso-8859-1")
}
});
//reusable vars
var width:int, height:int, x:int, y:int;
var pixels:ByteArray = new ByteArray();
var indexes:ByteArray = new ByteArray();
var palette:Vector.<uint> = new Vector.<uint>(MAX_PALETTE_COLORS);
//parse all images
directories.forEach( function(val:Object, n:int, self:Vector.<Object>):void
{
data.position = self[n].offset; //set pointer
if(self[n].type == 0x40 || self[n].type == 0x43)
data.position += MAX_NAME_LENGTH; //skip name
//store dimaensions
width = data.readInt();
height = data.readInt();
//FIXME: fill out this conditional - QFont
if (self[n].type == 0x46)
{ width = 256;
}
if (self[n].type == 0x40 || self[n].type == 0x43)
data.position += 16; //skip this nonsense - completely useless
//segregate palette indexes for this image
if (indexes.length > 0) indexes.clear(); //reset
data.readBytes(indexes, 0, width * height);
indexes.position = 0; //prime pointer
//skip mips for now
if (self[n].type == 0x40 || self[n].type == 0x43)
{ for (var s:int = 1; s < 4; ++s)
data.position += ((width >> s) * (height >> s));
}
data.position += 2; //pad
//get appropriate palette - FIXME: transparency
palette.forEach(function(val:uint, i:int, pal:Vector.<uint>):void {
if (self[n].type == 0x40)
pal[i] = (0xFF << 24 | i << 16 | i << 8 | i);
else
pal[i] = (0xFF << 24 | data.readUnsignedByte() << 16 | data.readUnsignedByte() << 8 | data.readUnsignedByte());;
});
if (pixels.length > 0) pixels.clear(); //reset
for (y = 0; y < height; ++y) //pixels columns
for (x = 0; x < width; ++x) //pixels rows
pixels.writeUnsignedInt( palette[ indexes.readUnsignedByte() ] );
pixels.position = 0; //set pointer at beginning
images[n] = new Object();
images[n].name = self[n].name;
images[n].mip = new BitmapData(width, height, true);
images[n].mip.setPixels(images[n].mip.rect, pixels);
});
return images;
}
}




Comment