public SavedData(LSystemSteppingHandle source)
            {
                this.totalSteps        = source.totalSteps;
                this.lastUpdateChanged = source.lastUpdateChanged;
                this.useSharedSystem   = source.useSharedSystem;

                this.currentState = source.currentState;
                this.lastState    = source.lastState;
                this.oldHandle    = source.globalResourceHandle;

                this.systemObjectId = source.systemObject.myId;

                this.runtimeParameters = source.runtimeParameters;
                this.compiledGlobalCompiletimeReplacements = source.compiledGlobalCompiletimeReplacements;
            }
예제 #2
0
 public ArrayParameterRepresenation <float> GetRuntimeParameters()
 {
     return(ArrayParameterRepresenation <float> .GenerateFromList(linkedFiles.allGlobalRuntimeParams, p => p.name, p => p.defaultValue));
 }
        /// <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();
            };
        }