diff --git a/Sources/Lindenmayer/LSystemTypes/ParameterizedRandomContextualLSystem.swift b/Sources/Lindenmayer/LSystemTypes/ParameterizedRandomContextualLSystem.swift index 87f82a52..17ecdb1a 100644 --- a/Sources/Lindenmayer/LSystemTypes/ParameterizedRandomContextualLSystem.swift +++ b/Sources/Lindenmayer/LSystemTypes/ParameterizedRandomContextualLSystem.swift @@ -72,7 +72,6 @@ import Foundation /// /// ### Updating the L-system /// -/// - ``ParameterizedRandomContextualLSystem/setSeed(seed:)`` /// - ``ParameterizedRandomContextualLSystem/setParameters(params:)`` /// - ``ParameterizedRandomContextualLSystem/set(seed:params:)`` /// @@ -154,18 +153,18 @@ public struct ParameterizedRandomContextualLSystem: LindenmayerSyst } public func reset() async -> Self { - await prng.resetRNG(seed: prng.seed) + await prng.resetRNG() return ParameterizedRandomContextualLSystem(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. @@ -174,17 +173,6 @@ public struct ParameterizedRandomContextualLSystem: 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 diff --git a/Sources/Lindenmayer/LSystemTypes/RandomContextualLSystem.swift b/Sources/Lindenmayer/LSystemTypes/RandomContextualLSystem.swift index 5fee025e..d72ebab5 100644 --- a/Sources/Lindenmayer/LSystemTypes/RandomContextualLSystem.swift +++ b/Sources/Lindenmayer/LSystemTypes/RandomContextualLSystem.swift @@ -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()`` @@ -129,18 +125,9 @@ public struct RandomContextualLSystem: 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 diff --git a/Sources/Lindenmayer/PRNG/RNGWrapper.swift b/Sources/Lindenmayer/PRNG/RNGWrapper.swift index a86a80eb..3032147d 100644 --- a/Sources/Lindenmayer/PRNG/RNGWrapper.swift +++ b/Sources/Lindenmayer/PRNG/RNGWrapper.swift @@ -39,8 +39,9 @@ public actor RNGWrapper: 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 diff --git a/Sources/LindenmayerViews/LSystem3DModel.swift b/Sources/LindenmayerViews/LSystem3DModel.swift index bff50790..415bdaed 100644 --- a/Sources/LindenmayerViews/LSystem3DModel.swift +++ b/Sources/LindenmayerViews/LSystem3DModel.swift @@ -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. @@ -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 @@ -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() diff --git a/Tests/LindenmayerTests/PRNGWrapperTests.swift b/Tests/LindenmayerTests/PRNGWrapperTests.swift index 14859ab4..22b39733 100644 --- a/Tests/LindenmayerTests/PRNGWrapperTests.swift +++ b/Tests/LindenmayerTests/PRNGWrapperTests.swift @@ -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) } @@ -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