Skip to content
This repository has been archived by the owner on Sep 16, 2019. It is now read-only.

Better WAD2 implementation #224

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

ericwa
Copy link
Contributor

@ericwa ericwa commented Dec 6, 2015

  • Supports quake and hexen 2 (they both use WAD2, with the palette in gfx/palette.lmp, but the palette colors are different)
  • Handles different open documents using different palettes correctly
  • If you change the gamedir in the game configuration, the palette isn't reloaded until you close/reopen the document, or open a new document

I didn't add anything to disable this code if the game is GoldSrc; it always tries to load gfx/palette.lmp in the Document constructor, but this could be surrounded by a check for the game engine type.

WAD2 is the same as WAD3 except that the miptex entries don't have a
palette after the pixel data, the palette needs to be supplied externally.
@@ -136,8 +141,16 @@ private void SetEntryData(WadEntry e, BinaryReader br)
var num = (int)(width * height);
var skipMapData = (num / 4) + (num / 16) + (num / 64);
br.BaseStream.Position += 16 + num + skipMapData; // Skip mipmap offsets, texture data, mipmap texture data
paletteSize = br.ReadUInt16();
paletteDataOffset = br.BaseStream.Position;
if (e.Type == WadEntryType.QuakeTexture)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'd probably be cleaner to branch in the switch instead of here, maybe something like this?

case WadEntryType.Texture:
    textureDataOffset = MoveToTextureData(br, out width, out height);
    paletteSize = br.ReadUInt16();
    paletteDataOffset = br.BaseStream.Position;
    break;
case WadEntryType.QuakeTexture:
    textureDataOffset = MoveToTextureData(br, out width, out height);
    paletteSize = 256;
    paletteDataOffset = 0;
    break;

...

private long MoveToTextureData(BinaryReader br, out uint width, out uint height)
{
    br.BaseStream.Position += 16; // Skip name
    width = br.ReadUInt32();
    height = br.ReadUInt32();
    var textureDataOffset = br.BaseStream.Position + 16;
    var num = (int)(width * height);
    var skipMapData = (num / 4) + (num / 16) + (num / 64);
    br.BaseStream.Position += 16 + num + skipMapData; // Skip mipmap offsets, texture data, mipmap texture data
    return textureDataOffset;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, I refactored it like that.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants