SamplingTime GetOutputPlayTime(DebugMemory debugMemory, SamplingTime samplingTime, SamplingTime closestMatch, DebugIdentifier outputTimeIdentifier)
        {
            if (!closestMatch.IsValid)
            {
                return(samplingTime);
            }

            int playAtTimeTypeCode = BurstRuntime.GetHashCode32 <PlayAtTimeDebug>();

            for (DebugReference reference = debugMemory.FirstOrDefault; reference.IsValid; reference = debugMemory.Next(reference))
            {
                if (reference.identifier.typeHashCode != playAtTimeTypeCode)
                {
                    continue;
                }

                PlayAtTimeDebug playAtTime = debugMemory.ReadObject <PlayAtTimeDebug>(reference);
                if (playAtTime.playTime.Equals(outputTimeIdentifier))
                {
                    return(closestMatch);
                }
            }

            return(samplingTime);
        }
        Nullable <TrajectoryHeuristicDebug> FindTrajectoryHeuristic(DebugMemory debugMemory)
        {
            if (!trajectory.IsValid)
            {
                return(null);
            }

            int heuristicTypeCode = BurstRuntime.GetHashCode32 <TrajectoryHeuristicDebug>();

            for (DebugReference reference = debugMemory.FirstOrDefault; reference.IsValid; reference = debugMemory.Next(reference))
            {
                if (reference.identifier.typeHashCode != heuristicTypeCode)
                {
                    continue;
                }

                TrajectoryHeuristicDebug heuristicDebug = debugMemory.ReadObject <TrajectoryHeuristicDebug>(reference);
                if (heuristicDebug.closestMatch.Equals(closestMatch))
                {
                    return(heuristicDebug);
                }
            }

            return(null);
        }
        public DebugReference Next(DebugReference current)
        {
            Header header = ReadHeader(current.address);

            if (header.nextAddress >= size)
            {
                return(DebugReference.Invalid);
            }

            return(GetObjectReference(header.nextAddress));
        }
        public T ReadObjectFromIdentifier <T>(DebugIdentifier identifier) where T : struct, IDebugObject
        {
            DebugReference reference = FindObjectReference(identifier);

            if (!reference.IsValid)
            {
                throw new ArgumentException("Identifier not bound to valid reference in debug memory", "identifier");
            }

            return(ReadObject <T>(reference));
        }
        public DebugReference FindObjectReference(DebugIdentifier identifier)
        {
            for (DebugReference debugRef = FirstOrDefault; debugRef.IsValid; debugRef = Next(debugRef))
            {
                if (debugRef.identifier.Equals(identifier))
                {
                    return(debugRef);
                }
            }

            return(DebugReference.Invalid);
        }
        bool IsObjectAlreadyWritten <T>(ref T obj) where T : struct, IDebugObject
        {
            if (!obj.debugIdentifier.IsValid)
            {
                obj.debugIdentifier = CreateIdentifier <T>();
                return(false);
            }
            else
            {
                for (DebugReference reference = FirstOrDefault; reference.IsValid; reference = Next(reference))
                {
                    if (reference.identifier.EqualsIndexAndVersion(obj.debugIdentifier))
                    {
                        // already written
                        return(true);
                    }
                }
            }

            return(false);
        }
        DebugIdentifier CreateIdentifier <T>() where T : struct
        {
            int    typeHashCode = BurstRuntime.GetHashCode32 <T>();
            ushort currentIndex = 0;

            for (DebugReference debugRef = FirstOrDefault; debugRef.IsValid; debugRef = Next(debugRef))
            {
                if (debugRef.identifier.typeHashCode == typeHashCode)
                {
                    currentIndex = debugRef.identifier.index;
                    ++currentIndex;
                }
            }

            return(new DebugIdentifier()
            {
                index = currentIndex,
                version = version,
                typeHashCode = typeHashCode
            });
        }
        public T ReadObject <T>(DebugReference reference) where T : struct, IDebugObject
        {
            T obj = new T();

            int    previousCursor = buffer.SetCursor(reference.address);
            Header header         = buffer.ReadBlittable <Header>();

            if (obj is Serializable serializable)
            {
                serializable.ReadFromStream(buffer);
                obj = (T)serializable;
            }
            else
            {
                obj = buffer.ReadBlittable <T>();
            }

            obj.debugIdentifier = reference.identifier;

            buffer.SetCursor(previousCursor);

            return(obj);
        }
 public T DebugReadObject <T>(DebugReference reference) where T : struct, IDebugObject
 {
     return(readDebugMemory.ReadObject <T>(reference));
 }