/// <summary>
        /// Optionally Set to a different L-system, and reset the state and the current runtime parameters
        /// </summary>
        private void ResetState(
            LSystemState <float> newState,
            LSystemStepper newSystem)
        {
            if (lSystemPendingCompletable != null)
            {
                lSystemPendingCompletable.Cancel();
            }
            lastState?.currentSymbols.Dispose();
            lastState = null;
            currentState?.currentSymbols.Dispose();
            currentState = null;

            totalSteps        = 0;
            lastUpdateChanged = true;
            currentState      = newState;

            runtimeParameters = systemObject.GetRuntimeParameters();

            if (newSystem != null)
            {
                SetNewCompiledSystem(newSystem);
            }

            // clear out the next state handle. if an update is pending, just abort it.

            OnSystemStateUpdated?.Invoke();
        }
Ejemplo n.º 2
0
 private void LSystemStateWasUpdated()
 {
     OnSystemStateUpdated?.Invoke();
     SetLastUpdateTime();
 }
        /// <summary>
        /// Root implementation of Step system, all other step calls funnel here
        /// </summary>
        /// <param name="runtimeParameters"></param>
        /// <param name="repeatLast">True if this system should just repeat the last update. Useful if a runtime parameter changed, or </param>
        private void StepSystemAsync(
            ArrayParameterRepresenation <float> runtimeParameters,
            bool repeatLast = false)
        {
            ICompletable <LSystemState <float> > pendingStateHandle;

            try
            {
                if (compiledSystem == null || compiledSystem.isDisposed)
                {
                    Debug.LogError("No Compiled system available!");
                }
                if (repeatLast)
                {
                    globalResourceHandle.UpdateUniqueIdReservationSpace(lastState);
                    pendingStateHandle = compiledSystem.StepSystemJob(
                        lastState,
                        runtimeParameters.GetCurrentParameters());
                }
                else
                {
                    globalResourceHandle.UpdateUniqueIdReservationSpace(currentState);
                    var sunlightJob = globalResourceHandle.ApplyPrestepEnvironment(
                        currentState,
                        compiledSystem.customSymbols);

                    pendingStateHandle = compiledSystem.StepSystemJob(
                        currentState,
                        runtimeParameters.GetCurrentParameters(),
                        parameterWriteDependency: sunlightJob);
                }
                if (pendingStateHandle == null)
                {
                    lSystemPendingCompletable = null;
                    return;
                }
            }
            catch (System.Exception e)
            {
                lastUpdateChanged = false;
                Debug.LogException(e);
                lSystemPendingCompletable = null;
                return;
            }

            lSystemPendingCompletable = CompletableExecutor.Instance.RegisterCompletable(pendingStateHandle);

            lSystemPendingCompletable.OnCompleted += (nextState) =>
            {
                UnityEngine.Profiling.Profiler.BeginSample("updating stepping handle state");
                if (repeatLast)
                {
                    // dispose the current state, since it is about to be replaced
                    currentState?.currentSymbols.Dispose();
                }
                else
                {
                    // dispose the last state
                    lastState?.currentSymbols.Dispose();
                    lastState = currentState;
                    totalSteps++;
                }
                currentState = nextState;
                // if there are immature markers, use those instead. avoiding an equality check saves time.
                var hasImmatureMarkers = systemObject.linkedFiles.immaturitySymbolMarkers.Length > 0;
                lastUpdateChanged = hasImmatureMarkers || !(currentState?.currentSymbols.Data.Equals(lastState.currentSymbols.Data) ?? false);

                lSystemPendingCompletable = null;
                UnityEngine.Profiling.Profiler.EndSample();
                OnSystemStateUpdated?.Invoke();
            };
        }