Skip to content

Commit 80aa226

Browse files
committed
Use native type
1 parent acf99a5 commit 80aa226

File tree

11 files changed

+64
-114
lines changed

11 files changed

+64
-114
lines changed

Sources/GameMath/2D Types (New)/Rectn.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
* http://stregasgate.com
66
*/
77

8-
public typealias Rect2i = Rect2n<Int32>
9-
public typealias Rect2f = Rect2n<Float32>
8+
public typealias Rect2i = Rect2n<Int>
9+
public typealias Rect2f = Rect2n<Float>
1010

1111
public struct Rect2n<Scalar: Vector2n.ScalarType> {
1212
public var position: Position2n<Scalar>

Sources/GameMath/2D Types (New)/Vector2n.swift

Lines changed: 25 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ public protocol Vector2n<Scalar> {
1515
init(x: Scalar, y: Scalar)
1616
}
1717

18-
public typealias Position2i = Position2n<Int32>
19-
public typealias Position2f = Position2n<Float32>
18+
public typealias Position2i = Position2n<Int>
19+
public typealias Position2f = Position2n<Float>
2020
public struct Position2n<Scalar: Vector2n.ScalarType>: Vector2n {
2121
public typealias Vector2Counterpart = Position2
2222
public var x: Scalar
@@ -35,8 +35,8 @@ extension Position2n: Sendable where Scalar: Sendable { }
3535
extension Position2n: Codable where Scalar: Codable { }
3636
extension Position2n: BinaryCodable where Scalar: BinaryCodable { }
3737

38-
public typealias Size2i = Size2n<Int32>
39-
public typealias Size2f = Size2n<Float32>
38+
public typealias Size2i = Size2n<Int>
39+
public typealias Size2f = Size2n<Float>
4040
public struct Size2n<Scalar: Vector2n.ScalarType>: Vector2n {
4141
public typealias Vector2Counterpart = Size2
4242
public var x: Scalar
@@ -65,58 +65,6 @@ public extension Size2n {
6565
}
6666
}
6767

68-
public extension Vector2n where Scalar: BinaryInteger {
69-
@inlinable
70-
@_disfavoredOverload
71-
static func castInit<T1: BinaryInteger, T2: BinaryInteger>(width: T1, height: T2) -> Self {
72-
return .init(x: Scalar(width), y: Scalar(height))
73-
}
74-
75-
@inlinable
76-
@_disfavoredOverload
77-
static func castInit<T1: BinaryFloatingPoint, T2: BinaryFloatingPoint>(width: T1, height: T2) -> Self {
78-
return .init(x: Scalar(width), y: Scalar(height))
79-
}
80-
81-
@inlinable
82-
@_disfavoredOverload
83-
static func castInit<T1: BinaryInteger, T2: BinaryFloatingPoint>(width: T1, height: T2) -> Self {
84-
return .init(x: Scalar(width), y: Scalar(height))
85-
}
86-
87-
@inlinable
88-
@_disfavoredOverload
89-
static func castInit<T1: BinaryFloatingPoint, T2: BinaryInteger>(width: T1, height: T2) -> Self {
90-
return .init(x: Scalar(width), y: Scalar(height))
91-
}
92-
}
93-
94-
public extension Vector2n where Scalar: BinaryFloatingPoint {
95-
@inlinable
96-
@_disfavoredOverload
97-
static func castInit<T1: BinaryInteger, T2: BinaryInteger>(width: T1, height: T2) -> Self {
98-
return .init(x: Scalar(width), y: Scalar(height))
99-
}
100-
101-
@inlinable
102-
@_disfavoredOverload
103-
static func castInit<T1: BinaryFloatingPoint, T2: BinaryFloatingPoint>(width: T1, height: T2) -> Self {
104-
return .init(x: Scalar(width), y: Scalar(height))
105-
}
106-
107-
@inlinable
108-
@_disfavoredOverload
109-
static func castInit<T1: BinaryInteger, T2: BinaryFloatingPoint>(width: T1, height: T2) -> Self {
110-
return .init(x: Scalar(width), y: Scalar(height))
111-
}
112-
113-
@inlinable
114-
@_disfavoredOverload
115-
static func castInit<T1: BinaryFloatingPoint, T2: BinaryInteger>(width: T1, height: T2) -> Self {
116-
return .init(x: Scalar(width), y: Scalar(height))
117-
}
118-
}
119-
12068
extension Vector2n where Scalar: BinaryInteger {
12169
@inlinable
12270
public init(_ vector2n: some Vector2n<Scalar>) {
@@ -206,25 +154,6 @@ public extension Vector2n where Scalar: Numeric {
206154
}
207155
}
208156

209-
extension Vector2n where Scalar: Comparable {
210-
public static func < (lhs: Self, rhs: some Vector2n<Scalar>) -> Bool {
211-
return lhs.x < rhs.x && lhs.y < rhs.y
212-
}
213-
}
214-
215-
extension Vector2n where Scalar: Equatable {
216-
public static func == (lhs: Self, rhs: some Vector2n<Scalar>) -> Bool {
217-
return lhs.x == rhs.x && lhs.y == rhs.y
218-
}
219-
}
220-
221-
extension Vector2n where Scalar: Hashable {
222-
public func hash(into hasher: inout Hasher) {
223-
hasher.combine(x)
224-
hasher.combine(y)
225-
}
226-
}
227-
228157
public extension Vector2n where Scalar: FloatingPoint {
229158
@inlinable
230159
static func / (lhs: Self, rhs: some Vector2n<Scalar>) -> Self {
@@ -249,6 +178,27 @@ public extension Vector2n where Scalar: FixedWidthInteger {
249178
}
250179
}
251180

181+
public extension Vector2n where Scalar: Comparable {
182+
@inlinable
183+
static func < (lhs: Self, rhs: some Vector2n<Scalar>) -> Bool {
184+
return lhs.x < rhs.x && lhs.y < rhs.y
185+
}
186+
}
187+
188+
extension Vector2n where Scalar: Equatable {
189+
@inlinable
190+
public static func == (lhs: Self, rhs: some Vector2n<Scalar>) -> Bool {
191+
return lhs.x == rhs.x && lhs.y == rhs.y
192+
}
193+
}
194+
195+
extension Vector2n where Scalar: Hashable {
196+
public func hash(into hasher: inout Hasher) {
197+
hasher.combine(x)
198+
hasher.combine(y)
199+
}
200+
}
201+
252202
extension Vector2n where Scalar: BinaryCodable {
253203
public func encode(into data: inout ContiguousArray<UInt8>, version: BinaryCodableVersion) throws {
254204
try self.x.encode(into: &data, version: version)

Sources/GameMath/3D Types (New)/Vector3n.swift

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ public protocol Vector3n<Scalar> {
1616
init(x: Scalar, y: Scalar, z: Scalar)
1717
}
1818

19-
public typealias Position3i = Position3n<Int32>
20-
public typealias Position3f = Position3n<Float32>
19+
public typealias Position3i = Position3n<Int>
20+
public typealias Position3f = Position3n<Float>
2121
public struct Position3n<Scalar: Vector3n.ScalarType>: Vector3n {
2222
public typealias Vector3Counterpart = Position3
2323
public var x: Scalar
@@ -38,8 +38,8 @@ extension Position3n: Sendable where Scalar: Sendable { }
3838
extension Position3n: Codable where Scalar: Codable { }
3939
extension Position3n: BinaryCodable where Scalar: BinaryCodable { }
4040

41-
public typealias Size3i = Size3n<Int32>
42-
public typealias Size3f = Size3n<Float32>
41+
public typealias Size3i = Size3n<Int>
42+
public typealias Size3f = Size3n<Float>
4343
public struct Size3n<Scalar: Vector3n.ScalarType>: Vector3n {
4444
public typealias Vector3Counterpart = Size3
4545
public var x: Scalar
@@ -144,26 +144,6 @@ public extension Vector3n where Scalar: AdditiveArithmetic {
144144
static var zero: Self {Self(x: .zero, y: .zero, z: .zero)}
145145
}
146146

147-
extension Vector3n where Scalar: Comparable {
148-
public static func < (lhs: Self, rhs: Self) -> Bool {
149-
return lhs.x < rhs.x && lhs.y < rhs.y && lhs.z < rhs.z
150-
}
151-
}
152-
153-
extension Vector3n where Scalar: Equatable {
154-
public static func == (lhs: Self, rhs: Self) -> Bool {
155-
return lhs.x == rhs.x && lhs.y == rhs.y && lhs.z == rhs.z
156-
}
157-
}
158-
159-
extension Vector3n where Scalar: Hashable {
160-
public func hash(into hasher: inout Hasher) {
161-
hasher.combine(x)
162-
hasher.combine(y)
163-
hasher.combine(z)
164-
}
165-
}
166-
167147
public extension Vector3n where Scalar: FloatingPoint {
168148
@inlinable
169149
static func / (lhs: Self, rhs: Self) -> Self {
@@ -188,6 +168,26 @@ public extension Vector3n where Scalar: FixedWidthInteger {
188168
}
189169
}
190170

171+
public extension Vector3n where Scalar: Comparable {
172+
static func < (lhs: Self, rhs: Self) -> Bool {
173+
return lhs.x < rhs.x && lhs.y < rhs.y && lhs.z < rhs.z
174+
}
175+
}
176+
177+
extension Vector3n where Scalar: Equatable {
178+
public static func == (lhs: Self, rhs: Self) -> Bool {
179+
return lhs.x == rhs.x && lhs.y == rhs.y && lhs.z == rhs.z
180+
}
181+
}
182+
183+
extension Vector3n where Scalar: Hashable {
184+
public func hash(into hasher: inout Hasher) {
185+
hasher.combine(x)
186+
hasher.combine(y)
187+
hasher.combine(z)
188+
}
189+
}
190+
191191
extension Vector3n where Scalar: BinaryCodable {
192192
public func encode(into data: inout ContiguousArray<UInt8>, version: BinaryCodableVersion) throws {
193193
try self.x.encode(into: &data, version: version)

Sources/GateEngine/ECS/2D Specific/Sprite/SpriteComponent.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ public final class SpriteComponent: Component {
105105
let texture = spriteSheet?.texture,
106106
texture.state == .ready
107107
{
108-
let columns = Float(texture.size.width / Int32(spriteSize.width))
109-
let rows = Float(texture.size.height / Int32(spriteSize.height))
108+
let columns = Float(texture.size.width / Int(spriteSize.width))
109+
let rows = Float(texture.size.height / Int(spriteSize.height))
110110
let startFrame = (animation.spriteSheetStart.y * columns) + animation.spriteSheetStart.x
111111
let endFrame = {
112112
if let frameCount = animation.frameCount {

Sources/GateEngine/ECS/StandardRenderingSystem.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@ import GameMath
99

1010
@RenderingSystem(drawing: .afterGameView)
1111
public final class StandardRenderingSystem: RenderingSystem {
12-
internal var verticalResolution: Float? = nil
12+
internal var verticalResolution: UInt? = nil
1313
internal lazy var renderTarget: RenderTarget = RenderTarget()
1414

1515
public convenience init(verticalResolution: UInt) {
1616
self.init()
17-
self.verticalResolution = Float(verticalResolution)
17+
self.verticalResolution = verticalResolution
1818
}
1919

2020
public override func render(context: ECSContext, into view: GameView, withTimePassed deltaTime: Float) {
2121
if let verticalResolution = verticalResolution {
22-
var width = verticalResolution * view.frame.size.aspectRatio
22+
var width = Float(verticalResolution) * view.frame.size.aspectRatio
2323
width -= width.truncatingRemainder(dividingBy: 2)
24-
renderTarget.size = Size2i(width: Int32(width), height: Int32(verticalResolution))
24+
renderTarget.size = Size2i(width: Int(width), height: Int(verticalResolution))
2525
}
2626

2727
do { // 3D

Sources/GateEngine/Helpers/TextureAtlas.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public final class TextureAtlasBuilder {
212212
}
213213

214214
public func generateAtlas() -> TextureAtlas {
215-
let textureSize: Size2i = .castInit(width: self.searchGrid.width * blockSize, height: self.searchGrid.height * blockSize)
215+
let textureSize: Size2i = .init(width: self.searchGrid.width * blockSize, height: self.searchGrid.height * blockSize)
216216

217217
let dstWidth = Int(textureSize.width * 4)
218218

Sources/GateEngine/Resources/Import & Export/Coding/PNGCoder.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ enum LibSPNG {
277277
throw GateEngineError.failedToDecode(String(cString: spng_strerror(header_err)))
278278
}
279279

280-
return RawTexture(imageSize: .castInit(width: header.width, height: header.height), imageData: out)
280+
return RawTexture(imageSize: Size2i(width: Int(header.width), height: Int(header.height)), imageData: out)
281281
}
282282
}catch let error as GateEngineError {
283283
throw error // Typed throws not supported by closures as of Swift 6.2

Sources/GateEngine/Resources/Import & Export/Importers/ApplePlatformImageImporter.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public final class ApplePlatformImageImporter: TextureImporter {
4343
guard let image = CGImageSourceCreateImageAtIndex(imageSource, 0, nil) else {
4444
throw GateEngineError.failedToDecode("Failed to decode subimage zero.")
4545
}
46-
self.size = .castInit(width: image.width, height: image.height)
46+
self.size = Size2i(width: image.width, height: image.height)
4747
guard let data = image.dataProvider?.data as? Data else {
4848
throw GateEngineError.failedToDecode("Failed to decode data.")
4949
}

Sources/GateEngine/Resources/Import & Export/Importers/TiledTSJImporter.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,10 @@ public final class TiledTSJImporter: TileSetImporter {
115115
let texturePath = basePath + "/" + file.image
116116

117117
return await TileSetBackend(
118-
texture: Texture(path: texturePath, sizeHint: .castInit(width: file.imagewidth, height: file.imageheight)),
118+
texture: Texture(path: texturePath, sizeHint: .init(width: file.imagewidth, height: file.imageheight)),
119119
count: file.tilecount,
120120
columns: file.columns,
121-
tileSize: .castInit(width: file.tilewidth, height: file.tileheight),
121+
tileSize: .init(width: file.tilewidth, height: file.tileheight),
122122
tiles: tiles
123123
)
124124
}

Sources/GateEngine/Resources/Tiles/TileSet.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ import GameMath
7373
public func rectForTile(_ tile: TileMap.Tile) -> Rect {
7474
let row = tile.id / columns
7575
let column = tile.id % columns
76-
let position = Position2i(x: tileSize.width * Int32(column), y: tileSize.height * Int32(row))
76+
let position = Position2i(x: tileSize.width * column, y: tileSize.height * row)
7777
let size = Size2(Float(tileSize.width), Float(tileSize.height))
7878
return Rect(position: position.vector2, size: size)
7979
}

0 commit comments

Comments
 (0)