Esempio n. 1
0
        static List <DemoWriteInfo> GetWriteInfo(List <ParsedDemo> files)
        {
            List <DeltaPacket>   lastFile    = null;
            List <DeltaPacket>   currentFile = null;
            List <DemoWriteInfo> writeInfos  = new List <DemoWriteInfo>();

            for (int i = 0; i < files.Count; ++i)
            {
                var info = new DemoWriteInfo();
                lastFile    = currentFile;
                currentFile = files[i].Info.FindDeltaPacketInfo();

                if (i == 0)
                {
                    info.SetFirstDemo();
                }
                else
                {
                    int  lastIndex         = writeInfos.Count - 1;
                    bool adjacentTickFound = false;



                    // Check for adjacent ticks on consecutive demos on the same map
                    if (files[i - 1].Info.MapName == files[i].Info.MapName)
                    {
                        adjacentTickFound = TryExactDeltaMatch(lastFile, currentFile, writeInfos[lastIndex], info);
                        if (!adjacentTickFound)
                        {
                            adjacentTickFound = TryApproximateMatch(lastFile, currentFile, writeInfos[lastIndex], info);
                        }
                    }

                    if (!adjacentTickFound)
                    {
                        // Let the previous demo run until the end if no tick is found
                        writeInfos[lastIndex].SetLast(int.MaxValue, int.MaxValue);
                        if (currentFile.Count > 0)
                        {
                            info.SetStart(currentFile[0].Tick, currentFile[0].GlobalTick);
                        }
                        else
                        {
                            info.SetStart(int.MinValue, int.MinValue);
                        }
                    }
                }

                // If last demo, include all the ticks
                if (i == files.Count - 1)
                {
                    info.SetLast(int.MaxValue, int.MaxValue);
                }

                writeInfos.Add(info);
            }

            return(writeInfos);
        }
Esempio n. 2
0
        static bool TryApproximateMatch(List <DeltaPacket> lastFile, List <DeltaPacket> currentFile, DemoWriteInfo lastWriteInfo, DemoWriteInfo info)
        {
            for (int u = 0; u < currentFile.Count; ++u)
            {
                for (int v = lastFile.Count - 1; v >= 0; --v)
                {
                    if (lastFile[v].GlobalTick <= currentFile[u].DeltaFrom)
                    {
                        lastWriteInfo.SetLast(lastFile[v].Tick, lastFile[v].GlobalTick);
                        info.SetStart(currentFile[u].Tick, currentFile[u].GlobalTick);
                        return(true);
                    }
                }
            }

            return(false);
        }