Skip to content

Commit

Permalink
Update for Strict Concurrency
Browse files Browse the repository at this point in the history
  • Loading branch information
STREGA committed Mar 26, 2024
1 parent 50b0e4a commit 92cbf7e
Show file tree
Hide file tree
Showing 15 changed files with 26 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ public enum OpenGL {
}
}

public struct ClearMask: OptionSet {
public struct ClearMask: OptionSet, Sendable {
public typealias RawValue = UInt32
public var rawValue: RawValue

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public struct CollisionTriangle: Sendable {
public var plane: Plane3D
public var center: Position3

@MainActor
public static var attributeParser = {(u: Float, v: Float, section: UInt32) -> UInt32 in
let range: Float = 3
let uidx: Float = floor(u * range)
Expand Down Expand Up @@ -58,6 +59,7 @@ public struct CollisionTriangle: Sendable {
}

public extension CollisionTriangle {
@MainActor
init(positions: [Position3], colors: [Color], offset: Position3 = .zero, attributeUV: [Position2]) {
var attributes: UInt32 = 0
for index in 0 ..< attributeUV.count {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ extension Collision2DComponent {
case `static`
case dynamic
}
public struct Options: OptionSet {
public struct Options: OptionSet, Sendable {
public let rawValue: UInt32

public static let skipEntities = Options(rawValue: 1 << 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ extension Collision3DComponent {
case `static`
case dynamic(_ priority: Int)
}
public struct Options: OptionSet {
public struct Options: OptionSet, Sendable {
public let rawValue: UInt32

public static let skipEntities = Options(rawValue: 1 << 1)
Expand Down
2 changes: 1 addition & 1 deletion Sources/GateEngine/ECS/Base/Component.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ extension Component {
}
}

public struct ComponentID: Equatable, Hashable {
public struct ComponentID: Equatable, Hashable, Sendable {
static let idGenerator = IDGenerator<Int>(startValue: 0)
@usableFromInline
internal let value: Int
Expand Down
6 changes: 3 additions & 3 deletions Sources/GateEngine/ECS/Base/SortOrder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* http://stregasgate.com
*/

public struct SystemSortOrder: RawRepresentable, ExpressibleByIntegerLiteral {
public struct SystemSortOrder: RawRepresentable, ExpressibleByIntegerLiteral, Sendable {
public typealias RawValue = Int
public let rawValue: RawValue
public init(rawValue: RawValue) {
Expand Down Expand Up @@ -36,7 +36,7 @@ public struct SystemSortOrder: RawRepresentable, ExpressibleByIntegerLiteral {
}
}

public struct RenderingSystemSortOrder: RawRepresentable, ExpressibleByIntegerLiteral {
public struct RenderingSystemSortOrder: RawRepresentable, ExpressibleByIntegerLiteral, Sendable {
public typealias RawValue = Int
public let rawValue: RawValue
public init(rawValue: RawValue) {
Expand Down Expand Up @@ -102,7 +102,7 @@ extension PlatformSystemSortOrder {
public static let deferredSystem: Self = 100_000
}

public struct PlatformSystemSortOrder: RawRepresentable, ExpressibleByIntegerLiteral {
public struct PlatformSystemSortOrder: RawRepresentable, ExpressibleByIntegerLiteral, Sendable {
public typealias RawValue = Int
public let rawValue: RawValue
public init(rawValue: RawValue) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public final class ParentRelationshipComponent: Component {
public var relativeTransform: Transform3? = nil
public var options: Options = [.relativePosition, .relativeRotation, .relativeScale]

public struct Options: OptionSet {
public struct Options: OptionSet, Sendable {
public typealias RawValue = UInt
public let rawValue: RawValue

Expand Down
1 change: 1 addition & 0 deletions Sources/GateEngine/Game.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public final class Game {
@MainActor public private(set) var state: State! = nil
@MainActor internal private(set) var internalState: State! = nil

@MainActor
lazy private(set) var identifier: String = delegate.resolvedGameIdentifier()

nonisolated public let isHeadless: Bool
Expand Down
2 changes: 1 addition & 1 deletion Sources/GateEngine/Helpers/IDGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import class Foundation.NSLock
#endif

#if canImport(Atomics)
public final class IDGenerator<T: AtomicInteger> {
public final class IDGenerator<T: AtomicInteger & Sendable> {
var value: ManagedAtomic<T>

public init(startValue: T = 0) {
Expand Down
2 changes: 1 addition & 1 deletion Sources/GateEngine/Resources/Geometry/Geometry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ extension Geometry: Equatable, Hashable {
return lhs.cacheKey == rhs.cacheKey
}

public func hash(into hasher: inout Hasher) {
nonisolated public func hash(into hasher: inout Hasher) {
hasher.combine(cacheKey)
}
}
Expand Down
1 change: 1 addition & 0 deletions Sources/GateEngine/Scripting/Gravity/Gravity+Errors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import Gravity

@MainActor
internal func errorCallback(
vm: OpaquePointer?,
errorType: error_type_t,
Expand Down
4 changes: 4 additions & 0 deletions Sources/GateEngine/Scripting/Gravity/Gravity+Files.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import Foundation
import Gravity

@MainActor
internal func filenameCallback(
fileID: UInt32,
xData: UnsafeMutableRawPointer?
Expand All @@ -19,6 +20,7 @@ internal func filenameCallback(
}
}

@MainActor
internal func loadFileCallback(
file: UnsafePointer<CChar>!,
size: UnsafeMutablePointer<Int>!,
Expand Down Expand Up @@ -101,6 +103,7 @@ extension Gravity {
}
}

@MainActor
@inline(__always)
private func cacheIncludes(fromSource sourceCode: String) async throws {
let includes = self.fileIncludesFromSource(sourceCode).filter({
Expand All @@ -119,6 +122,7 @@ extension Gravity {
- parameter addDebug: `true` to add debug. nil to add debug only in DEBUG configurations.
- throws: Gravity compilation errors such as syntax problems and file loading problems.
*/
@MainActor
public func compile(file path: String, addDebug: Bool? = nil) async throws {
let url = URL(fileURLWithPath: path)
let baseURL = url.deletingLastPathComponent()
Expand Down
2 changes: 1 addition & 1 deletion Sources/GateEngine/Scripting/Gravity/Gravity+Testing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#if DEBUG
import Gravity

@MainActor
internal func unittestCallback(
vm: OpaquePointer!,
errorType: error_type_t,
Expand All @@ -25,7 +26,6 @@ internal func unittestCallback(
column: column,
value: value
)
return
}
extension Gravity {
struct Testing {
Expand Down
15 changes: 6 additions & 9 deletions Sources/GateEngine/System/HID/Keyboard/CharacterStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,13 @@ public final class CharacterStream {
string.removeAll(keepingCapacity: true)
cursor = string.startIndex
}
public func startCapture() async {
await Game.shared.hid.keyboard.insertStream(self)
@MainActor
public func startCapture() {
Game.shared.hid.keyboard.insertStream(self)
}
public func stopCapture() async {
await Game.shared.hid.keyboard.removeStream(self)
}
deinit {
Task { @MainActor in
await self.stopCapture()
}
@MainActor
public func stopCapture() {
Game.shared.hid.keyboard.removeStream(self)
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/GateEngine/System/Platforms/FileSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public enum FileSystemItemType {
case file
}

public struct FileSystemWriteOptions: OptionSet {
public struct FileSystemWriteOptions: OptionSet, Sendable {
public typealias RawValue = UInt
public var rawValue: RawValue
public init(rawValue: RawValue) {
Expand Down

0 comments on commit 92cbf7e

Please sign in to comment.