Moderate refactor.

Removes "Source" from in front of source engine structures.
Spells out full names of structures in class names.
Adds punctuation to all documentation comments and fixes some mistakes.
Adds some missing documentation comments.
This commit is contained in:
Will
2016-01-26 22:37:52 -07:00
parent ed5abdcc92
commit 9bf45765a5
43 changed files with 1167 additions and 1038 deletions

View File

@@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
namespace LibBSP {
/// <summary>
/// Class representing a group of <see cref="DisplacementVertex"/> objects. Contains helpful methods to handle Displacement Vertices in the <c>List</c>.
/// </summary>
public class DisplacementVertices : List<DisplacementVertex> {
/// <summary>
/// Parses the passed <c>byte</c> array into a <c>List</c> of <see cref="DisplacementVertex"/> objects.
/// </summary>
/// <param name="data">Array of <c>byte</c>s to parse.</param>
/// <param name="type">Format identifier.</param>
/// <exception cref="ArgumentNullException"><paramref name="data" /> was <c>null</c>.</exception>
public DisplacementVertices(byte[] data, MapType type) : base(data.Length / 20) {
if (data == null) {
throw new ArgumentNullException();
}
int structLength = 20;
byte[] bytes = new byte[structLength];
for (int i = 0; i < data.Length / structLength; ++i) {
Array.Copy(data, (i * structLength), bytes, 0, structLength);
Add(new DisplacementVertex(bytes, type));
}
}
/// <summary>
/// Gets enough vertices from the list for a displacement of power <paramref name="power"/>, starting at <paramref name="first"/>.
/// </summary>
/// <param name="first">The first vertex to get.</param>
/// <param name="power">The power of the displacement.</param>
/// <returns>Array of <see cref="DisplacementVertex"/> objects containing all the vertices in this displacement</returns>
public virtual DisplacementVertex[] GetVerticesInDisplacement(int first, int power) {
int numVerts = 0;
switch (power) {
case 2: {
numVerts = 25;
break;
}
case 3: {
numVerts = 81;
break;
}
case 4: {
numVerts = 289;
break;
}
}
DisplacementVertex[] ret = new DisplacementVertex[numVerts];
for (int i = 0; i < numVerts; ++i) {
ret[i] = this[first + i];
}
return ret;
}
}
}

View File

@@ -2,28 +2,28 @@ using System;
using System.Collections.Generic;
namespace LibBSP {
/// <summary>
/// Enum containing known game lumps.
/// </summary>
public enum GameLumpType : int {
hlpd = 1685089384,
tlpd = 1685089396,
prpd = 1685090928,
sprp = 1936749168,
}
/// <summary>
/// Class containing the identification and information for the various Game Lumps in Source
/// engine BSPs. The only one we're really concerned with is the Static Props.
/// </summary>
public class GameLump : Dictionary<GameLumpType, GameLump.GameLumpInfo> {
public struct GameLumpInfo {
public ushort flags;
public ushort version;
public int offset;
public int length;
}
public class GameLump : Dictionary<GameLumpType, LumpInfo> {
private byte[] _rawData;
private int _gameLumpOffset;
/// <summary>
/// Byte array representing the raw data read from the BSP for the game lump
/// Byte array representing the raw data read from the BSP for the game lump.
/// </summary>
public byte[] rawData {
get {
@@ -32,7 +32,7 @@ namespace LibBSP {
}
/// <summary>
/// The amount to subtract from all the <c>GameLumpInfo.offset</c> values to find the offset relative to the start of the Game Lump data. May be 0.
/// The amount to subtract from all the <see cref="LumpInfo.offset"/> values to find the offset relative to the start of the Game Lump data. May be 0.
/// </summary>
public int gameLumpOffset {
get {
@@ -41,13 +41,13 @@ namespace LibBSP {
}
/// <summary>
/// Creates a new <c>GameLump</c> object by parsing a <c>byte</c> array into a <c>Dictionary</c> of <c>GameLumpInfo</c> objects.
/// Creates a new <see cref="GameLump"/> object by parsing a <c>byte</c> array into a <c>Dictionary</c> of <see cref="LumpInfo"/> objects.
/// These objects contain offsets, lengths and versions of the GameLump lumps.
/// </summary>
/// <param name="data">The data to parse</param>
/// <param name="type">The map type</param>
/// <exception cref="ArgumentNullException"><paramref name="data" /> was null</exception>
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype</exception>
/// <param name="data">The data to parse.</param>
/// <param name="type">The map type.</param>
/// <exception cref="ArgumentNullException"><paramref name="data"/> was <c>null</c>.</exception>
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype.</exception>
public GameLump(byte[] data, MapType type) {
if (data == null) {
throw new ArgumentNullException();
@@ -84,13 +84,14 @@ namespace LibBSP {
int lowestLumpOffset = Int32.MaxValue;
for (int i = 0; i < numGameLumps; ++i) {
GameLumpInfo info = new GameLumpInfo {
LumpInfo info = new LumpInfo {
ident = BitConverter.ToInt32(data, (i * structLength) + 4),
flags = BitConverter.ToUInt16(data, (i * structLength) + 8),
version = BitConverter.ToUInt16(data, (i * structLength) + 10),
offset = BitConverter.ToInt32(data, (i * structLength) + 12),
length = BitConverter.ToInt32(data, (i * structLength) + 16),
};
this[(GameLumpType)BitConverter.ToInt32(data, (i * structLength) + 4)] = info;
this[(GameLumpType)info.ident] = info;
if (info.offset < lowestLumpOffset) {
lowestLumpOffset = info.offset;
@@ -103,11 +104,11 @@ namespace LibBSP {
}
/// <summary>
/// Passes a <c>byte</c> array into the constructor for <c>GameLump</c>.
/// Passes a <c>byte</c> array into the constructor for <see cref="GameLump"/>.
/// </summary>
/// <param name="data">The data to parse</param>
/// <param name="type">The map type</param>
/// <returns>A new <c>GameLump</c> object</returns>
/// <param name="data">The data to parse.</param>
/// <param name="type">The map type.</param>
/// <returns>A new <see cref="GameLump"/> object.</returns>
/// <remarks>This is only here for consistency with the other lump structures.</remarks>
public static GameLump LumpFactory(byte[] data, MapType type) {
return new GameLump(data, type);
@@ -116,8 +117,8 @@ namespace LibBSP {
/// <summary>
/// Gets the index for this lump in the BSP file for a specific map format.
/// </summary>
/// <param name="type">The map type</param>
/// <returns>Index for this lump, or -1 if the format doesn't have this lump</returns>
/// <param name="type">The map type.</param>
/// <returns>Index for this lump, or -1 if the format doesn't have this lump.</returns>
public static int GetIndexForLump(MapType type) {
switch (type) {
case MapType.Vindictus:

View File

@@ -1,58 +0,0 @@
using System;
using System.Collections.Generic;
namespace LibBSP {
/// <summary>
/// Class representing a group of <c>SourceDispVertex</c> objects. Contains helpful methods to handle Displacement Vertices in the <c>List</c>
/// </summary>
public class SourceDispVertices : List<SourceDispVertex> {
/// <summary>
/// Parses the passed <c>byte</c> array into a <c>List</c> of <c>SourceDispVertices</c>
/// </summary>
/// <param name="data">Array of <c>byte</c>s to parse</param>
/// <param name="type">Format identifier</param>
/// <exception cref="ArgumentNullException"><paramref name="data" /> was null</exception>
public SourceDispVertices(byte[] data, MapType type) : base(data.Length / 20) {
if (data == null) {
throw new ArgumentNullException();
}
int structLength = 20;
byte[] bytes = new byte[structLength];
for (int i = 0; i < data.Length / structLength; ++i) {
Array.Copy(data, (i * structLength), bytes, 0, structLength);
Add(new SourceDispVertex(bytes, type));
}
}
/// <summary>
/// Gets enough vertices from the list for a displacement of power <paramref name="power" />, starting at <paramref name="first" />.
/// </summary>
/// <param name="first">The first vertex to get</param>
/// <param name="power">The power of the displacement</param>
/// <returns>Array of <c>SourceDispVertex</c> objects containing all the vertices in this displacement</returns>
public virtual SourceDispVertex[] GetVerticesInDisplacement(int first, int power) {
int numVerts = 0;
switch (power) {
case 2: {
numVerts = 25;
break;
}
case 3: {
numVerts = 81;
break;
}
case 4: {
numVerts = 289;
break;
}
}
SourceDispVertex[] ret = new SourceDispVertex[numVerts];
for (int i = 0; i < numVerts; ++i) {
ret[i] = this[first + i];
}
return ret;
}
}
}

View File

@@ -3,20 +3,20 @@ using System.Collections.Generic;
namespace LibBSP {
/// <summary>
/// List of <c>SourceStaticProp</c> objects containing data relevant to Static Props, like the dictionary of actual model paths.
/// List of <see cref="StaticProp"/> objects containing data relevant to Static Props, like the dictionary of actual model paths.
/// </summary>
public class SourceStaticProps : List<SourceStaticProp> {
public class StaticProps : List<StaticProp> {
public string[] dictionary { get; private set; }
/// <summary>
/// Parses the passed <c>byte</c> array into a <c>List</c> of <c>SourceStaticProp</c> objects
/// Parses the passed <c>byte</c> array into a <c>List</c> of <see cref="StaticProp"/> objects.
/// </summary>
/// <param name="data">Array of <c>byte</c>s to parse</param>
/// <param name="type">Format identifier</param>
/// <param name="version">Version of static prop lump this is</param>
/// <exception cref="ArgumentNullException"><paramref name="data" /> was null</exception>
public SourceStaticProps(byte[] data, MapType type, int version) {
/// <param name="data">Array of <c>byte</c>s to parse.</param>
/// <param name="type">Format identifier.</param>
/// <param name="version">Version of static prop lump this is.</param>
/// <exception cref="ArgumentNullException"><paramref name="data" /> was <c>null</c>.</exception>
public StaticProps(byte[] data, MapType type, int version) {
if (data == null) {
throw new ArgumentNullException();
}
@@ -37,7 +37,7 @@ namespace LibBSP {
byte[] bytes = new byte[structLength];
for (int i = 0; i < numProps; ++i) {
Array.Copy(data, (dictionary.Length * 128) + (numLeafDefinitions * 2) + 12 + (i * structLength), bytes, 0, structLength);
Add(new SourceStaticProp(bytes, type, version));
Add(new StaticProp(bytes, type, version));
offset += structLength;
}
}

View File

@@ -3,18 +3,18 @@ using System.Collections.Generic;
namespace LibBSP {
/// <summary>
/// <c>List</c>&lt;<c>Texture</c>&gt; with some useful methods for manipulating <c>Texture</c> objects,
/// <c>List</c>&lt;<see cref="Texture"/>&gt; with some useful methods for manipulating <see cref="Texture"/> objects,
/// especially when handling them as a group.
/// </summary>
public class Textures : List<Texture> {
/// <summary>
/// Parses a <c>byte</c> array into this <c>List</c> of <c>Texture</c> objects
/// Parses a <c>byte</c> array into this <c>List</c> of <see cref="Texture"/> objects.
/// </summary>
/// <param name="data">The data to parse</param>
/// <param name="type">The map type</param>
/// <exception cref="ArgumentNullException"><paramref name="data" /> was null</exception>
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype</exception>
/// <param name="data">The data to parse.</param>
/// <param name="type">The map type.</param>
/// <exception cref="ArgumentNullException"><paramref name="data" /> was <c>null</c>.</exception>
/// <exception cref="ArgumentException">This structure is not implemented for the given maptype.</exception>
public Textures(byte[] data, MapType type) {
if (data == null) {
throw new ArgumentNullException();
@@ -101,8 +101,8 @@ namespace LibBSP {
/// <summary>
/// Gets the name of the texture at the specified offset.
/// </summary>
/// <param name="offset">Lump offset of the texture name to find</param>
/// <returns>The name of the texture at offset <paramref name="offset" />, or null if it doesn't exist</returns>
/// <param name="offset">Lump offset of the texture name to find.</param>
/// <returns>The name of the texture at offset <paramref name="offset" />, or null if it doesn't exist.</returns>
public string GetTextureAtOffset(uint offset) {
int current = 0;
for (int i = 0; i < Count; ++i) {
@@ -120,12 +120,12 @@ namespace LibBSP {
/// <summary>
/// Finds the offset of the specified texture name.
/// </summary>
/// <param name="inTexture">The texture name to find in the lump</param>
/// <returns>The offset of the specified texture, or -1 if it wasn't found</returns>
public int GetOffsetOf(string inTexture) {
/// <param name="name">The texture name to find in the lump.</param>
/// <returns>The offset of the specified texture, or -1 if it wasn't found.</returns>
public int GetOffsetOf(string name) {
int offset = 0;
for (int i = 0; i < Count; ++i) {
if (this[i].name.Equals(inTexture, StringComparison.CurrentCultureIgnoreCase)) {
if (this[i].name.Equals(name, StringComparison.CurrentCultureIgnoreCase)) {
return offset;
} else {
offset += this[i].name.Length + 1;