Skip to content

Commit

Permalink
swift6 updates reflected as of Xcode16-beta3 (#44)
Browse files Browse the repository at this point in the history
* swift6 updates reflected as of Xcode16-beta3
  • Loading branch information
heckj authored Jul 8, 2024
1 parent 610c6f0 commit 0f0248b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ import Foundation
///
/// ### Updating the L-system
///
/// - ``ParameterizedRandomContextualLSystem/setSeed(seed:)``
/// - ``ParameterizedRandomContextualLSystem/setParameters(params:)``
/// - ``ParameterizedRandomContextualLSystem/set(seed:params:)``
///
Expand Down Expand Up @@ -154,18 +153,18 @@ public struct ParameterizedRandomContextualLSystem<PType, PRNG>: LindenmayerSyst
}

public func reset() async -> Self {
await prng.resetRNG(seed: prng.seed)
await prng.resetRNG()
return ParameterizedRandomContextualLSystem<PType, PRNG>(axiom: axiom, state: nil, newStateIndicators: nil, parameters: parameters, prng: prng, rules: rules)
}

/// Sets the seed for the pseudo-random number generator to the value you provide.
/// - Parameter seed: The seed value to set within the pseudo-random generator.
/// - Returns: The L-system with the seed value updated.
@discardableResult
public func setSeed(seed: UInt64) async -> Self {
await prng.resetRNG(seed: seed)
return self
}
// /// Sets the seed for the pseudo-random number generator to the value you provide.
// /// - Parameter seed: The seed value to set within the pseudo-random generator.
// /// - Returns: The L-system with the seed value updated.
// @discardableResult
// public func setSeed(seed: UInt64) async -> Self {
// await prng.resetRNG(seed: seed)
// return self
// }

/// Sets the parameters for the L-system to the value you provide.
/// - Parameter params: The updated value for the parameter type of the L-system.
Expand All @@ -174,17 +173,6 @@ public struct ParameterizedRandomContextualLSystem<PType, PRNG>: LindenmayerSyst
public func setParameters(params: PType) -> Self {
Self(axiom: axiom, state: state, newStateIndicators: newStateIndicators, parameters: params, prng: prng, rules: rules)
}

/// Sets the seed for the pseudo-random number generator and the parameters for the L-system to the value you provide.
/// - Parameters:
/// - seed: The seed value to set within the pseudo-random generator.
/// - params: The updated value for the parameter type of the L-system.
/// - Returns: The L-system with the seed value and parameters value updated.
@discardableResult
public func set(seed: UInt64) async -> Self {
await prng.resetRNG(seed: seed)
return self
}
}

// - MARK: Rewrite rules including RNG and Parameters from the LSystem
Expand Down
15 changes: 1 addition & 14 deletions Sources/Lindenmayer/LSystemTypes/RandomContextualLSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ import Foundation
/// - ``RandomContextualLSystem/rewriteWithRNG(directContext:rightContext:where:produces:)``
/// - ``RandomContextualLSystem/rewriteWithRNG(leftContext:directContext:rightContext:where:produces:)``
///
/// ### Updating the L-system
///
/// - ``RandomContextualLSystem/setSeed(seed:)``
///
/// ### Evolving the L-system
///
/// - ``RandomContextualLSystem/evolve()``
Expand Down Expand Up @@ -129,18 +125,9 @@ public struct RandomContextualLSystem<PRNG>: LindenmayerSystem where PRNG: Seede
/// Resets the L-system to it's initial state, wiping out an existing state while keeping the rules.
/// - Returns: A new L-system with it's state reset to the initial state you set when you created the L-system.
public func reset() async -> Self {
await prng.resetRNG(seed: prng.seed)
await prng.resetRNG()
return RandomContextualLSystem(axiom: axiom, state: nil, newStateIndicators: nil, prng: prng, rules: rules)
}

/// Sets the seed for the pseudo-random number generator to the value you provide.
/// - Parameter seed: The seed value to set within the pseudo-random generator.
/// - Returns: The L-system with the seed value updated.
@discardableResult
public func setSeed(seed: UInt64) async -> Self {
await prng.resetRNG(seed: seed)
return self
}
}

// - MARK: Rewrite rules including PRNG from the LSystem
Expand Down
5 changes: 3 additions & 2 deletions Sources/Lindenmayer/PRNG/RNGWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ public actor RNGWrapper<PRNG>: Sendable where PRNG: SeededRandomNumberGenerator
_prng.position
}

public func resetRNG(seed: UInt64) {
_prng = PRNG(seed: seed)
public func resetRNG() {
let originalSeed = _prng.seed
_prng = PRNG(seed: originalSeed)
#if DEBUG
_invokeCount = 0
#endif
Expand Down
6 changes: 3 additions & 3 deletions Sources/LindenmayerViews/LSystem3DModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import Lindenmayer
import SceneKit
import SceneKitDebugTools
import SwiftUI

/// A class that provides an observable model around a base L-system.
///
/// The module manages the number of evolutions of an L-system, and provides updated 3D SceneKit scenes as you change the number of evolutions.
Expand All @@ -25,7 +24,7 @@ public class LSystem3DModel: ObservableObject {
var _scene: SCNScene
var _transformSequence: [matrix_float4x4]

public let objectWillChange: ObservableObjectPublisher
nonisolated public let objectWillChange: ObservableObjectPublisher

public var scene: SCNScene {
_scene
Expand All @@ -36,7 +35,8 @@ public class LSystem3DModel: ObservableObject {
}

func evolveBy(iterations: Int) async {
system = await _baseSystem.evolved(iterations: _iterations)
system = await _baseSystem.evolved(iterations: iterations)
_iterations = iterations
objectWillChange.send()
(_scene, _transformSequence) = renderer.generateScene(lsystem: system)
let headingIndicator = DebugNodes.headingIndicator()
Expand Down
4 changes: 2 additions & 2 deletions Tests/LindenmayerTests/PRNGWrapperTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ final class PRNGWrapperTests: XCTestCase {
// continues to move forward as new evolutions are invoked.
_invokeCount = await twoEv.prng._invokeCount
XCTAssertEqual(_invokeCount, 4)
await start.prng.resetRNG(seed: start.prng.seed)
await start.prng.resetRNG()
_invokeCount = await start.prng._invokeCount
XCTAssertEqual(_invokeCount, 0)
}
Expand All @@ -105,7 +105,7 @@ final class PRNGWrapperTests: XCTestCase {
XCTAssertEqual(seed, 42)
XCTAssertEqual(_invokeCount, 2)

await start.prng.resetRNG(seed: start.prng.seed)
await start.prng.resetRNG()
let position = await oneEv.prng.position
seed = await oneEv.prng.seed
_invokeCount = await oneEv.prng._invokeCount
Expand Down

0 comments on commit 0f0248b

Please sign in to comment.