Skip to content

Commit

Permalink
swift6 updates reflected as of Xcode16-beta3
Browse files Browse the repository at this point in the history
  • Loading branch information
heckj committed Jul 8, 2024
1 parent 610c6f0 commit a727f71
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 43 deletions.
6 changes: 3 additions & 3 deletions Sources/Lindenmayer/Examples/Examples3D.swift
Original file line number Diff line number Diff line change
Expand Up @@ -422,14 +422,14 @@ public enum Examples3D: Sendable {
let upper: Float = 45.0
let lower: Float = 15.0

if await rng.p(0.5) {
return await [
if rng.p(0.5) {
return [
StaticStem2(length: 2),
Modules.PitchDown(angle: Angle(degrees: Double(rng.randomFloat(in: lower ... upper)))),
Stem2(length: stem.length),
]
} else {
return await [
return [
StaticStem2(length: 2),
Modules.PitchUp(angle: Angle(degrees: Double(rng.randomFloat(in: lower ... upper)))),
Stem2(length: stem.length),
Expand Down
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
7 changes: 4 additions & 3 deletions Sources/LindenmayerViews/LSystem3DModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by Joseph Heck on 1/8/22.
//

@preconcurrency import Combine
import Combine
import Foundation
import Lindenmayer
import SceneKit
Expand All @@ -17,7 +17,7 @@ import SwiftUI
/// The module manages the number of evolutions of an L-system, and provides updated 3D SceneKit scenes as you change the number of evolutions.
/// The model emits `ObservableObject` change notifications when the number of iterations is changed.
@MainActor
public class LSystem3DModel: ObservableObject {
public class LSystem3DModel: @preconcurrency ObservableObject {
@Published public var system: LindenmayerSystem
let renderer = SceneKitRenderer()
let _baseSystem = Examples3D.sympodialTree
Expand All @@ -36,7 +36,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

0 comments on commit a727f71

Please sign in to comment.