Ejemplo n.º 1
0
        void SaveInput(SWBytes data, int start, int end)
        {
            SWConsole.Info($"SaveItems start={start}, end={end}");

            if (end > _lastEndIndex)
            {
                _lastEndIndex = end;
            }

            return;

            string partialName            = _game.replayFileName + start.ToString("D6") + end.ToString("D6");
            SaveReplayoperation operation = new SaveReplayoperation(data.Data(), partialName);

            operationQueue.AddOperation(operation);
        }
Ejemplo n.º 2
0
        void CombineSavedInputFiles()
        {
            return;

            string fileName = _game.replayFileName;

            string[] savedFiles = SWLocalStorage.GetFilesWithPartialName(FrameSyncConstant.DEFAULT_DIRECTORY, fileName);

            if (savedFiles.Length == 0)
            {
                return;
            }

            SortedList <int, string> orderedFiles = new SortedList <int, string>();
            List <int> sortedIndexes = new List <int>();

            foreach (string saveFile in savedFiles)
            {
                Debug.Log($"saveFile={saveFile}");
                string frameNumber = saveFile.Substring(saveFile.LastIndexOf(fileName) + fileName.Length);
                Debug.Log($"frameNumber={frameNumber}");
                long frameNumberLong = 0;
                bool good            = long.TryParse(frameNumber, out frameNumberLong);
                if (!good)
                {
                    continue;
                }
                int low  = (int)(frameNumberLong / 1000000);
                int high = (int)(frameNumberLong % 100000);
                int size = high - low;
                Debug.Log($"low={low} high={high} size={size}");

                orderedFiles[low] = saveFile;
                sortedIndexes.Add(low);
                sortedIndexes.Add(high);
            }

            sortedIndexes.Sort();

            int  count    = sortedIndexes.Count;
            bool verified = true;

            for (int i = 0; i < count; i++)
            {
                if (i == count - 1)
                {
                    break;
                }

                if (i % 2 == 1)
                {
                    bool match = sortedIndexes[i] == sortedIndexes[i + 1];
                    if (!match)
                    {
                        verified = false;
                        break;
                    }
                }
            }

            if (!verified)
            {
                Debug.Log("Corrupted files");
            }

            int startFrameNumber = sortedIndexes[0];
            int endFrameNumber   = sortedIndexes[sortedIndexes.Count - 1];

            Debug.Log($"start={startFrameNumber} end={endFrameNumber}");
            int estimatedSize = (endFrameNumber - startFrameNumber) * InputFrameDelta.DataSize + 100;

            byte[]  dataToSave               = new byte[estimatedSize];
            SWBytes combinedBuffer           = new SWBytes(dataToSave);
            PersistentArrayMetaData metaData = new PersistentArrayMetaData();

            metaData.itemCount = endFrameNumber - startFrameNumber;
            combinedBuffer.SetWriteIndex(PersistentArrayMetaData.DataSize);

            foreach (var orderedFile in orderedFiles)
            {
                byte[]  data;
                int     length     = SWLocalStorage.LoadFromFile(orderedFile.Value, out data);
                SWBytes dataBuffer = new SWBytes(data);
                //Debug.Log($"Combined add={dataBuffer.FullString()}");
                combinedBuffer.PushAll(dataBuffer);
                Debug.Log($"Remove {orderedFile.Value}");
                SWLocalStorage.RemoveFile(orderedFile.Value);
            }

            combinedBuffer.SetReadIndex(PersistentArrayMetaData.DataSize);
            metaData.checksum = combinedBuffer.Crc32();

            int end = combinedBuffer.GetWriteIndex();

            combinedBuffer.SetWriteIndex(0);
            //Debug.Log($"Combined before meta={combinedBuffer.FullString()}");
            metaData.Export(combinedBuffer);
            //Debug.Log($"Combined after meta={combinedBuffer.FullString()}");
            combinedBuffer.SetWriteIndex(end);
            combinedBuffer.SetReadIndex(0);


            //Debug.Log($"Combined combinedBuffer={combinedBuffer.FullString()}");

            SaveReplayoperation operation = new SaveReplayoperation(combinedBuffer.Data(), fileName + ".play");

            operationQueue.AddOperation(operation);
        }