Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jkolb authored and Justin Kolb committed Oct 11, 2015
1 parent b28ced9 commit f4b2c43
Show file tree
Hide file tree
Showing 24 changed files with 230 additions and 185 deletions.
42 changes: 33 additions & 9 deletions Asheron/Cell/LandBlock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import Lilliput
extension ByteBuffer {
public func getLandBlock() -> LandBlock {
let identifier = getUInt32()
let meshBlockFlag = getUInt32()
let topography = getUInt16(9 * 9)
let height = getUInt8(9 * 9)
let flags = getUInt32()
let topography = getUInt16(LandBlock.sizeSquared)
let height = getUInt8(LandBlock.sizeSquared)
let pad = getUInt8()

return LandBlock(
identifier: identifier,
meshBlockFlag: meshBlockFlag,
flags: flags,
topography: topography,
height: height,
pad: pad
Expand All @@ -27,10 +27,34 @@ extension ByteBuffer {
}

public struct LandBlock {
let identifier: UInt32
let meshBlockFlag: UInt32
let topography: Array<UInt16> // 9 * 9 * 2 = 162
let height: Array<UInt8> // 9 * 9 * 1 = 81
let pad: UInt8
public static let size: Int = 9
public static let sizeSquared = size * size
public let identifier: UInt32
public let flags: UInt32
public let topography: [UInt16] // 9 * 9 * 2 = 162
public let height: [UInt8] // 9 * 9 * 1 = 81
public let pad: UInt8
// 252

public init(
identifier: UInt32 = 0,
flags: UInt32 = 0,
topography: [UInt16] = [UInt16](count: LandBlock.sizeSquared, repeatedValue: 0),
height: [UInt8] = [UInt8](count: LandBlock.sizeSquared, repeatedValue: 0),
pad: UInt8 = 0
) {
self.identifier = identifier
self.flags = flags
self.topography = topography
self.height = height
self.pad = pad
}

public func height(x: Int, _ y: Int) -> UInt8 {
return height[y * LandBlock.size + x]
}

public func topography(x: Int, _ y: Int) -> UInt16 {
return topography[y * LandBlock.size + x]
}
}
12 changes: 6 additions & 6 deletions Asheron/IndexedFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ extension ByteBuffer {
return Int(getUInt8())
}

func getIntFrom8Bits(count: Int) -> Array<Int> {
func getIntFrom8Bits(count: Int) -> [Int] {
return getArray(count, defaultValue: 0) { self.getIntFrom8Bits() }
}

func getIntFrom16Bits() -> Int {
return Int(getUInt16())
}

func getIntFrom16Bits(count: Int) -> Array<Int> {
func getIntFrom16Bits(count: Int) -> [Int] {
return getArray(count, defaultValue: 0) { self.getIntFrom16Bits() }
}

func getIntFrom32Bits() -> Int {
return Int(getInt32())
}

func getIntFrom32Bits(count: Int) -> Array<Int> {
func getIntFrom32Bits(count: Int) -> [Int] {
return getArray(count, defaultValue: 0) { self.getIntFrom32Bits() }
}

Expand All @@ -55,7 +55,7 @@ extension ByteBuffer {
)
}

func getIndexedFileV1IndexKey(count: Int) -> Array<IndexedFileV1.Index.Key> {
func getIndexedFileV1IndexKey(count: Int) -> [IndexedFileV1.Index.Key] {
return getArray(count, defaultValue: IndexedFileV1.Index.Key()) { return self.getIndexedFileV1IndexKey() }
}

Expand Down Expand Up @@ -183,9 +183,9 @@ public class IndexedFileV1 {
public var description: String { return "\(value):\(offset):\(length)" }
}

public var offset: Array<Int> // 62
public var offset: [Int] // 62
public var count: Int
public var key: Array<Key> // 61
public var key: [Key] // 61

public var isLeaf: Bool { return offset[0] == 0 }
public var description: String { return "\(offset):\(count):\(key)" }
Expand Down
10 changes: 5 additions & 5 deletions Asheron/Portal/BSPNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ extension ByteBuffer {
return (getUInt16(), getUInt16())
}

public func getDoubleIndex(count: Int) -> Array<(UInt16, UInt16)> {
public func getDoubleIndex(count: Int) -> [(UInt16, UInt16)] {
return getArray(count, defaultValue: (0, 0)) { self.getDoubleIndex() }
}

Expand Down Expand Up @@ -197,7 +197,7 @@ public struct CollisionLeaf : BSPNode { // 010000C19
public let unknown1: UInt32
public let unknown2: Vector4F
public let count: Int
public let index: Array<UInt16>
public let index: [UInt16]
}

public struct RenderNode : BSPNode {
Expand All @@ -207,7 +207,7 @@ public struct RenderNode : BSPNode {
public let child2: BSPNode
public let unknown2: Vector4F
public let count: Int
public let index: Array<UInt16>
public let index: [UInt16]
}

public struct RenderLeaf : BSPNode {
Expand All @@ -223,6 +223,6 @@ public struct PortalNode : BSPNode { // 010000801 & 0100081C
public let unknown2: Vector4F
public let count: Int
public let count2: Int
public let index: Array<UInt16>
public let index2: Array<(UInt16, UInt16)>
public let index: [UInt16]
public let index2: [(UInt16, UInt16)]
}
10 changes: 5 additions & 5 deletions Asheron/Portal/Mesh.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ extension ByteBuffer {
let unknown1 = getUInt32()
let vertexCount = getIntFrom32Bits()
let vertex = getVertex(vertexCount)
var collisionPolygons = Array<Polygon>()
var collisionPolygons = [Polygon]()
var collisionNode: BSPNode = EmptyNode()

if meshType == 3 {
Expand Down Expand Up @@ -57,12 +57,12 @@ extension ByteBuffer {
public struct Mesh {
public let identifier: UInt32
public let meshType: UInt32
public let materialId: Array<UInt32>
public let materialId: [UInt32]
public let unknown1: UInt32
public let vertex: Array<Vertex>
public let collisionPolygons: Array<Polygon>
public let vertex: [Vertex]
public let collisionPolygons: [Polygon]
public let collisionNode: BSPNode
public let position: Vector3F
public let renderPolygons: Array<Polygon>
public let renderPolygons: [Polygon]
public let renderNode: BSPNode
}
4 changes: 2 additions & 2 deletions Asheron/Portal/Model.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ extension ByteBuffer {
public struct Model {
public let identifier: UInt32
public let modelType: UInt32
public let meshId: Array<UInt32>
// public let transform: Array<Transform>
public let meshId: [UInt32]
// public let transform: [Transform]
}
10 changes: 5 additions & 5 deletions Asheron/Portal/Palette.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ extension ByteBuffer {
return Color(r, g, b, a)
}

public func getColor(count: Int) -> Array<Color> {
public func getColor(count: Int) -> [Color] {
return getArray(count, defaultValue: Color()) { self.getColor() }
}
}
Expand Down Expand Up @@ -46,18 +46,18 @@ public struct Color : CustomStringConvertible {
self.a = Color.clamp(a)
}

public init (floatComponents: Array<Float>) {
public init (floatComponents: [Float]) {
r = Color.clamp(floatComponents[0])
g = Color.clamp(floatComponents[1])
b = Color.clamp(floatComponents[2])
a = Color.clamp(floatComponents[3])
}

public var components: Array<UInt8> {
public var components: [UInt8] {
return [r, g, b, a]
}

public var floatComponents: Array<Float> {
public var floatComponents: [Float] {
return [
Color.floatComponent(r),
Color.floatComponent(g),
Expand Down Expand Up @@ -90,5 +90,5 @@ extension ByteBuffer {
public struct Palette {
public let identifier: UInt32
public let size: Int
public let color: Array<Color>
public let color: [Color]
}
26 changes: 13 additions & 13 deletions Asheron/Portal/Polygon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,25 @@ extension ByteBuffer {
let frontMaterialIndex = getIntFrom16Bits()
let backMaterialIndex = getIntFrom16Bits()
let vertexIndex = getIntFrom16Bits(count)
var texcoordIndex1: Array<Int>
var texcoordIndex2: Array<Int>
var unknown2: Array<UInt8>
var texcoordIndex1: [Int]
var texcoordIndex2: [Int]
var unknown2: [UInt8]

if type == 0 || type == 1 || type == 3 {
texcoordIndex1 = getIntFrom8Bits(count)
} else {
texcoordIndex1 = Array<Int>()
texcoordIndex1 = [Int]()
}

if hasBackFace == 2 {
texcoordIndex2 = getIntFrom8Bits(count)
} else {
texcoordIndex2 = Array<Int>()
texcoordIndex2 = [Int]()
}

let vertexIndexByteCount = vertexIndex.count * sizeof(UInt16)
let texcoord1IndexByteCount = texcoordIndex1.count * sizeof(UInt8)
let texcoord2IndexByteCount = texcoordIndex2.count * sizeof(UInt8)
let vertexIndexByteCount = vertexIndex.count * strideof(UInt16)
let texcoord1IndexByteCount = texcoordIndex1.count * strideof(UInt8)
let texcoord2IndexByteCount = texcoordIndex2.count * strideof(UInt8)
let byteCount = vertexIndexByteCount + texcoord1IndexByteCount + texcoord2IndexByteCount
let padding = (4 - (byteCount % 4)) % 4
unknown2 = getUInt8(padding);
Expand All @@ -56,7 +56,7 @@ extension ByteBuffer {
)
}

public func getPolygon(count: Int) -> Array<Polygon> {
public func getPolygon(count: Int) -> [Polygon] {
return getArray(count) { self.getPolygon() }
}
}
Expand All @@ -74,10 +74,10 @@ public struct Polygon : CustomStringConvertible {
public let unknown1: UInt16
public let frontMaterialIndex: Int
public let backMaterialIndex: Int
public let vertexIndex: Array<Int>
public let texcoordIndex1: Array<Int>
public let texcoordIndex2: Array<Int>
public let unknown2: Array<UInt8>
public let vertexIndex: [Int]
public let texcoordIndex1: [Int]
public let texcoordIndex2: [Int]
public let unknown2: [UInt8]

public var description: String {
return "\(index)\n\tcount: \(count)\n\ttype: \(type)\n\thasBackFace: \(hasBackFace)\n\tunknown1: \(unknown1)"
Expand Down
2 changes: 1 addition & 1 deletion Asheron/Portal/Texture.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ public struct Texture {
public let type: UInt32
public let width: Int
public let height: Int
public let data: Array<UInt8>
public let data: [UInt8]
public let paletteID: UInt32
}
9 changes: 2 additions & 7 deletions Asheron/Portal/Transform.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ extension ByteBuffer {
return Transform(translation: getVector3F(), rotation: getVector4F())
}

public func getTransform(count: Int) -> Array<Transform> {
public func getTransform(count: Int) -> [Transform] {
return getArray(count, defaultValue: Transform()) { self.getTransform() }
}
}
Expand All @@ -22,12 +22,7 @@ public struct Transform {
public let translation: Vector3F
public let rotation: Vector4F

public init() {
self.translation = Vector3F()
self.rotation = Vector4F()
}

public init(translation: Vector3F, rotation: Vector4F) {
public init(translation: Vector3F = Vector3F(), rotation: Vector4F = Vector4F()) {
self.translation = translation
self.rotation = rotation
}
Expand Down
6 changes: 3 additions & 3 deletions Asheron/Portal/Vector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ extension ByteBuffer {
return Vector2F(getFloat32(), getFloat32())
}

public func getVector2F(count: Int) -> Array<Vector2F> {
public func getVector2F(count: Int) -> [Vector2F] {
return getArray(count, defaultValue: Vector2F()) { self.getVector2F() }
}
}
Expand All @@ -28,7 +28,7 @@ extension ByteBuffer {
return Vector3F(getFloat32(), getFloat32(), getFloat32())
}

public func getVector3F(count: Int) -> Array<Vector3F> {
public func getVector3F(count: Int) -> [Vector3F] {
return getArray(count, defaultValue: Vector3F()) { self.getVector3F() }
}
}
Expand All @@ -38,7 +38,7 @@ extension ByteBuffer {
return Vector4F(getFloat32(), getFloat32(), getFloat32(), getFloat32())
}

public func getVector4F(count: Int) -> Array<Vector4F> {
public func getVector4F(count: Int) -> [Vector4F] {
return getArray(count, defaultValue: Vector4F()) { self.getVector4F() }
}
}
4 changes: 2 additions & 2 deletions Asheron/Portal/Vertex.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ extension ByteBuffer {
)
}

public func getVertex(count: Int) -> Array<Vertex> {
public func getVertex(count: Int) -> [Vertex] {
return getArray(count) { self.getVertex() }
}
}
Expand All @@ -35,5 +35,5 @@ public struct Vertex {
public let count: Int
public let position: Vector3F
public let normal: Vector3F
public let texcoord: Array<Vector2F>
public let texcoord: [Vector2F]
}
2 changes: 1 addition & 1 deletion Cartfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github "jkolb/Lilliput" == 1.1.0
github "jkolb/Lilliput" == 1.1.2
2 changes: 1 addition & 1 deletion Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github "jkolb/Lilliput" "1.1.0"
github "jkolb/Lilliput" "1.1.2"
20 changes: 20 additions & 0 deletions Carthage/Build/Mac/Lilliput.framework.dSYM/Contents/Info.plist

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified Carthage/Build/Mac/Lilliput.framework/Versions/A/Lilliput
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit f4b2c43

Please sign in to comment.