public static Replay Save(string name)
        {
            byte[] saveBytes = CommandManager.RecordedBytes.ToArray ();
            CurrentReplay = new Replay ();
            CurrentReplay.Content = saveBytes;
            CurrentReplay.Name = name;
            CurrentReplay.Date = DateTime.UtcNow;
            CurrentReplay.FrameCount = LockstepManager.FrameCount;
            CurrentReplay.LastCommandedFrameCount = CommandManager.LastCommandedFrameCount;
            FileManager.SaveReplay (DemoName, CurrentReplay);

            return CurrentReplay;
        }
Beispiel #2
0
 private static void StartStreaming(Replay replay)
 {
     StopStreaming();
     streamer = UnityInstance.Instance.StartCoroutine(StreamPlayback(replay));
 }
        public static IEnumerator StreamPlayback(Replay playbackReplay)
        {
            int lastFrameByteCount = 0;
            int playbackPosition = 0;
            byte[] playbackBytes = playbackReplay.Content;

            bool getNextStream = true;
            int frameCount = 0;
            int nextFrame = -1;

            yield return null;
            FrameManager.EndFrame = playbackReplay.LastCommandedFrameCount;

            while (playbackPosition < playbackBytes.Length || frameCount <= nextFrame)
            {
                if (getNextStream == true)
                {
                    bufferBytes.FastClear ();
                    lastFrameByteCount = (int)BitConverter.ToUInt16 (playbackBytes, playbackPosition);
                    playbackPosition += 2;
                    nextFrame = BitConverter.ToInt32 (playbackBytes, playbackPosition);
                    bufferBytes.AddRange (playbackBytes, playbackPosition, lastFrameByteCount);
                    playbackPosition += lastFrameByteCount;
                    getNextStream = false;
                }

                if (nextFrame == frameCount)
                {
                    getNextStream = true;
                    CommandManager.ProcessPacket (bufferBytes);
                }
                else {
                    CommandManager.ProcessPacket (BitConverter.GetBytes (frameCount));
                }
                frameCount++;
            }
            yield break;
        }
 public static void Play(Replay replay)
 {
     CommandManager.sendType = SendState.None;
     IsPlayingBack = true;
     StartStreaming (replay);
 }
 public static void Play()
 {
     CurrentReplay = FileManager.RetrieveReplay (DemoName);
     Play (CurrentReplay);
 }
 private static void StartStreaming(Replay replay)
 {
     StopStreaming ();
     streamer = LockstepManager.UnityInstance.StartCoroutine (StreamPlayback (replay));
 }
Beispiel #7
0
 private static void StartStreaming(Replay replay)
 {
     StopStreaming();
     streamer = CoroutineManager.StartUnityCoroutine(StreamPlayback(replay));
 }
 public static void SaveReplay(string fileName, Replay replay)
 {
     File.WriteAllBytes(ReplayPath(fileName), replay.ToByteArray().Compressed());
 }