This repository has been archived by the owner on Sep 16, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 84
Better WAD2 implementation #224
Open
ericwa
wants to merge
2
commits into
LogicAndTrick:master
Choose a base branch
from
ericwa:better-wad2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace Sledge.DataStructures.GameData | ||
{ | ||
public class Palette | ||
{ | ||
public byte[] ByteArray { get; private set; } | ||
|
||
public Palette(byte[] pal) | ||
{ | ||
ByteArray = pal; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
using System; | ||
using Sledge.DataStructures.GameData; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
|
@@ -11,23 +12,26 @@ namespace Sledge.Packages.Wad | |
// https://developer.valvesoftware.com/wiki/WAD | ||
public class WadPackage : IPackage | ||
{ | ||
private const string Signature = "WAD3"; | ||
private const string WAD2Signature = "WAD2"; | ||
private const string WAD3Signature = "WAD3"; | ||
|
||
public FileInfo PackageFile { get; private set; } | ||
internal uint NumTextures { get; private set; } | ||
internal uint LumpOffset { get; private set; } | ||
internal List<WadEntry> Entries { get; private set; } | ||
public Palette Palette { get; private set; } | ||
|
||
public WadPackage(FileInfo packageFile) | ||
public WadPackage(FileInfo packageFile, Palette pal) | ||
{ | ||
PackageFile = packageFile; | ||
Entries = new List<WadEntry>(); | ||
Palette = pal; | ||
|
||
// Read the data from the wad | ||
using (var br = new BinaryReader(OpenFile(packageFile))) | ||
{ | ||
var sig = br.ReadFixedLengthString(Encoding.ASCII, 4); | ||
if (sig != Signature) throw new PackageException("Unknown package signature: Expected '" + Signature + "', got '" + sig + "'."); | ||
if (sig != WAD2Signature && sig != WAD3Signature) throw new PackageException("Unknown package signature: Expected [WAD2,WAD3], got '" + sig + "'."); | ||
|
||
NumTextures = br.ReadUInt32(); | ||
LumpOffset = br.ReadUInt32(); | ||
|
@@ -129,15 +133,24 @@ private void SetEntryData(WadEntry e, BinaryReader br) | |
paletteDataOffset = br.BaseStream.Position; | ||
break; | ||
case WadEntryType.Texture: | ||
case WadEntryType.QuakeTexture: | ||
br.BaseStream.Position += 16; // Skip name | ||
width = br.ReadUInt32(); | ||
height = br.ReadUInt32(); | ||
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 | ||
paletteSize = br.ReadUInt16(); | ||
paletteDataOffset = br.BaseStream.Position; | ||
if (e.Type == WadEntryType.QuakeTexture) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, I refactored it like that. |
||
{ | ||
paletteSize = 256; | ||
paletteDataOffset = 0; | ||
} | ||
else | ||
{ | ||
paletteSize = br.ReadUInt16(); | ||
paletteDataOffset = br.BaseStream.Position; | ||
} | ||
break; | ||
/* | ||
case WadEntryType.Font: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a fan of the palette being passed into all the package loaders when only the WAD provider needs it. I think it'd probably be better to cache the palette data inside the package by searching from the root like this:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that passing the Palette everywhere is messy. The problem with just using
packageFile
is, AFAIK, it's not necessarily inside the game directory - you could add a WAD file from a random location on your hard drive, but the palette always resides in the game directory. To work around that, I think the IFile for the game root directory would also need to be passed to the WadPackage constructor like:public WadPackage(FileInfo packageFile, IFile gameRoot)
then I could do this:
However, the problem with that is I can't use IFile or TraversePath inside the WadPackage implementation because it creates a circular dependency between Sledge.Filesystem and Sledge.Packages.
Maybe that could be worked around by merging the FileSystem and Packages assemblies, but that seems like a heavy handed workaround.