Exemplo n.º 1
0
        public int Write(WriteAdapter adapter)
        {
            var expectedObservations = m_Shape[0];

            if (m_Observations.Count > expectedObservations)
            {
                // Too many observations, truncate
                Debug.LogWarningFormat(
                    "More observations ({0}) made than vector observation size ({1}). The observations will be truncated.",
                    m_Observations.Count, expectedObservations
                    );
                m_Observations.RemoveRange(expectedObservations, m_Observations.Count - expectedObservations);
            }
            else if (m_Observations.Count < expectedObservations)
            {
                // Not enough observations; pad with zeros.
                Debug.LogWarningFormat(
                    "Fewer observations ({0}) made than vector observation size ({1}). The observations will be padded.",
                    m_Observations.Count, expectedObservations
                    );
                for (int i = m_Observations.Count; i < expectedObservations; i++)
                {
                    m_Observations.Add(0);
                }
            }
            adapter.AddRange(m_Observations);
            return(expectedObservations);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Default implementation of Write interface. This creates a temporary array, calls WriteObservation,
        /// and then writes the results to the WriteAdapter.
        /// </summary>
        /// <param name="adapter"></param>
        public virtual int Write(WriteAdapter adapter)
        {
            // TODO reuse buffer for similar agents, don't call GetObservationShape()
            var numFloats = this.ObservationSize();

            float[] buffer = new float[numFloats];
            WriteObservation(buffer);

            adapter.AddRange(buffer);

            return(numFloats);
        }
 public int Write(WriteAdapter adapter)
 {
     using (TimerStack.Instance.Scoped("RayPerceptionSensor.Perceive"))
     {
         PerceiveStatic(
             m_RayDistance, m_Angles, m_DetectableObjects, m_StartOffset, m_EndOffset,
             m_CastRadius, m_Transform, m_CastType, m_Observations, m_LayerMask,
             m_DebugDisplayInfo
             );
         adapter.AddRange(m_Observations);
     }
     return(m_Observations.Length);
 }
Exemplo n.º 4
0
        public int Write(WriteAdapter adapter)
        {
            using (TimerStack.Instance.Scoped("RayPerceptionSensor.Perceive"))
            {
                Array.Clear(m_Observations, 0, m_Observations.Length);

                var numRays           = m_RayPerceptionInput.angles.Count;
                var numDetectableTags = m_RayPerceptionInput.detectableTags.Count;

                if (m_DebugDisplayInfo != null)
                {
                    // Reset the age information, and resize the buffer if needed.
                    m_DebugDisplayInfo.Reset();
                    if (m_DebugDisplayInfo.rayInfos == null || m_DebugDisplayInfo.rayInfos.Length != numRays)
                    {
                        m_DebugDisplayInfo.rayInfos = new DebugDisplayInfo.RayInfo[numRays];
                    }
                }

                // For each ray, do the casting, and write the information to the observation buffer
                for (var rayIndex = 0; rayIndex < numRays; rayIndex++)
                {
                    DebugDisplayInfo.RayInfo debugRay;
                    var rayOutput = PerceiveSingleRay(m_RayPerceptionInput, rayIndex, out debugRay);

                    if (m_DebugDisplayInfo != null)
                    {
                        m_DebugDisplayInfo.rayInfos[rayIndex] = debugRay;
                    }

                    rayOutput.ToFloatArray(numDetectableTags, rayIndex, m_Observations);
                }
                // Finally, add the observations to the WriteAdapter
                adapter.AddRange(m_Observations);
            }
            return(m_Observations.Length);
        }