/// <summary> /// This method validates that all <see cref="IActuator"/>s have unique names and equivalent action space types /// if the `DEBUG` preprocessor macro is defined, and allocates the appropriate buffers to manage the actions for /// all of the <see cref="IActuator"/>s that may live on a particular object. /// </summary> /// <param name="actuators">The list of actuators to validate and allocate buffers for.</param> /// <param name="numContinuousActions">The total number of continuous actions for all of the actuators.</param> /// <param name="sumOfDiscreteBranches">The total sum of the discrete branches for all of the actuators in order /// to be able to allocate an <see cref="IDiscreteActionMask"/>.</param> /// <param name="numDiscreteBranches">The number of discrete branches for all of the actuators.</param> internal void ReadyActuatorsForExecution(IList <IActuator> actuators, int numContinuousActions, int sumOfDiscreteBranches, int numDiscreteBranches) { if (m_ReadyForExecution) { return; } #if DEBUG // Make sure the names are actually unique // Make sure all Actuators have the same SpaceType ValidateActuators(); #endif // Sort the Actuators by name to ensure determinism SortActuators(); StoredContinuousActions = numContinuousActions == 0 ? Array.Empty <float>() : new float[numContinuousActions]; StoredDiscreteActions = numDiscreteBranches == 0 ? Array.Empty <int>() : new int[numDiscreteBranches]; m_DiscreteActionMask = new ActuatorDiscreteActionMask(actuators, sumOfDiscreteBranches, numDiscreteBranches); m_ReadyForExecution = true; }
/// <summary> /// This method validates that all <see cref="IActuator"/>s have unique names /// if the `DEBUG` preprocessor macro is defined, and allocates the appropriate buffers to manage the actions for /// all of the <see cref="IActuator"/>s that may live on a particular object. /// </summary> /// <param name="actuators">The list of actuators to validate and allocate buffers for.</param> /// <param name="numContinuousActions">The total number of continuous actions for all of the actuators.</param> /// <param name="sumOfDiscreteBranches">The total sum of the discrete branches for all of the actuators in order /// to be able to allocate an <see cref="IDiscreteActionMask"/>.</param> /// <param name="numDiscreteBranches">The number of discrete branches for all of the actuators.</param> internal void ReadyActuatorsForExecution(IList <IActuator> actuators, int numContinuousActions, int sumOfDiscreteBranches, int numDiscreteBranches) { if (m_ReadyForExecution) { return; } #if DEBUG // Make sure the names are actually unique ValidateActuators(); #endif // Sort the Actuators by name to ensure determinism SortActuators(); var continuousActions = numContinuousActions == 0 ? ActionSegment <float> .Empty : new ActionSegment <float>(new float[numContinuousActions]); var discreteActions = numDiscreteBranches == 0 ? ActionSegment <int> .Empty : new ActionSegment <int>(new int[numDiscreteBranches]); StoredActions = new ActionBuffers(continuousActions, discreteActions); m_CombinedActionSpec = CombineActionSpecs(actuators); m_DiscreteActionMask = new ActuatorDiscreteActionMask(actuators, sumOfDiscreteBranches, numDiscreteBranches, m_CombinedActionSpec.BranchSizes); m_ReadyForExecution = true; }