public void FromLegacy(LegacyReplayFrame currentFrame, IBeatmap beatmap, ReplayFrame lastFrame = null)
        {
            Position = currentFrame.Position;
            Jumping  = currentFrame.ButtonState == ReplayButtonState.Left1;
            Shooting = currentFrame.ButtonState == ReplayButtonState.Left2;

            if (Jumping)
            {
                Actions.Add(BosuAction.Jump);
            }

            if (Shooting)
            {
                Actions.Add(BosuAction.Shoot);
            }

            if (lastFrame is BosuReplayFrame lastBosuFrame)
            {
                if (Position.X > lastBosuFrame.Position.X)
                {
                    lastBosuFrame.Actions.Add(BosuAction.MoveRight);
                }
                else if (Position.X < lastBosuFrame.Position.X)
                {
                    lastBosuFrame.Actions.Add(BosuAction.MoveLeft);
                }
            }
        }
示例#2
0
        public void FromLegacy(LegacyReplayFrame currentFrame, IBeatmap beatmap, ReplayFrame lastFrame = null)
        {
            Position    = currentFrame.Position;
            Shooting[0] = currentFrame.ButtonState == ReplayButtonState.Left1;
            Shooting[1] = currentFrame.ButtonState == ReplayButtonState.Right1;

            if (Shooting[0])
            {
                Actions.Add(TouhouAction.Shoot1);
            }
            if (Shooting[1])
            {
                Actions.Add(TouhouAction.Shoot2);
            }

            if (lastFrame is TouhouReplayFrame lastTouhouFrame)
            {
                if (Position.X > lastTouhouFrame.Position.X)
                {
                    lastTouhouFrame.Actions.Add(TouhouAction.MoveRight);
                }
                else if (Position.X < lastTouhouFrame.Position.X)
                {
                    lastTouhouFrame.Actions.Add(TouhouAction.MoveLeft);
                }
                if (Position.Y > lastTouhouFrame.Position.Y)
                {
                    lastTouhouFrame.Actions.Add(TouhouAction.MoveDown);
                }
                else if (Position.Y < lastTouhouFrame.Position.Y)
                {
                    lastTouhouFrame.Actions.Add(TouhouAction.MoveUp);
                }
            }
        }
示例#3
0
        protected override void Update()
        {
            if (!GameSession.IsPlaying)
            {
                return;
            }

            curTime = MusicController.CurrentTime;

            // Allocate next frame data
            nextFrame = null;
            if (replayWriter != null)
            {
                nextFrame = replayWriter.NextWriteItem;
                nextFrame?.Reset();
            }

            // Process update for other game modules.
            inputter.UpdateInputs(curTime);
            HitObjectHolder.UpdateObjects(curTime);

            // Record replay frame
            if (nextFrame != null)
            {
                nextFrame.Time = curTime;
                replayWriter.WriteData(nextFrame);
            }
        }
示例#4
0
        private void ReadReplay(bool replayDecompress)
        {
            CompressedReplayData = ReadByteArray();

            if (replayDecompress)
            {
                ReplayFrames           = new List <ReplayFrame>();
                DecompressedReplayData = SevenZipHelper.Decompress(CompressedReplayData);

                string replayData = Encoding.ASCII.GetString(DecompressedReplayData);
                if (replayData.Length > 0)
                {
                    string[] replayLines = replayData.Split(',');

                    ReplayFrame lastFrame;
                    if (ReplayFrames.Count > 0)
                    {
                        lastFrame = ReplayFrames[ReplayFrames.Count - 1];
                    }
                    else
                    {
                        lastFrame = new ReplayFrame(0, 0, 0);
                    }

                    foreach (string replayLine in replayLines)
                    {
                        if (replayLine.Length == 0)
                        {
                            continue;
                        }

                        string[] data = replayLine.Split('|');
                        if (data.Length < 4)
                        {
                            continue;
                        }

                        if (data[0] == "-12345")
                        {
                            Seed = int.Parse(data[3]);
                            continue;
                        }

                        ReplayFrame nextFrame = new ReplayFrame(
                            int.Parse(data[0]) + lastFrame.Time,
                            float.Parse(data[1], _nfi),
                            float.Parse(data[2], _nfi)
                            );

                        ReplayFrames.Add(nextFrame);
                        lastFrame = nextFrame;
                    }
                }
            }

            if (Version >= 20140721)
            {
                OnlineId = _reader.ReadInt64();
            }
        }
示例#5
0
        public void FromLegacy(LegacyReplayFrame legacyFrame, IBeatmap beatmap, ReplayFrame lastFrame = null)
        {
            var maniaBeatmap = (ManiaBeatmap)beatmap;

            var normalAction  = ManiaAction.Key1;
            var specialAction = ManiaAction.Special1;

            int activeColumns = (int)(legacyFrame.MouseX ?? 0);
            int counter       = 0;

            while (activeColumns > 0)
            {
                bool isSpecial = isColumnAtIndexSpecial(maniaBeatmap, counter);

                if ((activeColumns & 1) > 0)
                {
                    Actions.Add(isSpecial ? specialAction : normalAction);
                }

                if (isSpecial)
                {
                    specialAction++;
                }
                else
                {
                    normalAction++;
                }

                counter++;
                activeColumns >>= 1;
            }
        }
            internal void Tick()
            {
                if (!Done)
                {
                    cells.AddRange(frameCells);
                    lines.AddRange(frameLines);

                    frameCells.Clear();
                    frameLines.Clear();


                    if (frame >= replay.frames.Count)
                    {
                        Done       = true;
                        finishTick = Find.TickManager.TicksGame;
                    }
                    else
                    {
                        for (int i = 0; i < framesPerTick && frame < replay.frames.Count; i++)
                        {
                            ReplayFrame nextFrame = replay.frames[frame];
                            frameCells.AddRange(nextFrame.cells);
                            frameLines.AddRange(nextFrame.lines);
                            frame++;
                        }
                    }

                    oldCellDrawer.SetDirty();
                    frameCellDrawer.SetDirty();
                }
            }
        /// <summary>
        /// Performs update replay playback.
        /// </summary>
        private void UpdateJudgements(ReplayFrame frame)
        {
            var views = HitObjectHolder.HitObjectViews;

            foreach (var pair in frame.DraggerHoldFlags)
            {
                var dragger = views[pair.Key] as DraggerView;
                if (dragger != null)
                {
                    dragger.StartCircle.SetHold(pair.Value, frame.Time);
                }
            }

            foreach (var judgement in frame.Judgements)
            {
                // Find the target hit object from path.
                var path = judgement.HitObjectIndexPath;
                BaseHitObjectView hitObjectView = views[path[0]];
                for (int i = 1; i < path.Count; i++)
                {
                    int node = path[i];
                    hitObjectView = hitObjectView.BaseNestedObjects[node];
                }

                AddJudgement(
                    hitObjectView.SetResult(judgement.HitResult, judgement.HitOffset)
                    );
            }
        }
示例#8
0
 private void TestReplayFrame(ReplayFrame replayFrame, float time, float x, float y, Keys keys)
 {
     Assert.AreEqual(time, replayFrame.time);
     Assert.AreEqual(x, replayFrame.x);
     Assert.AreEqual(y, replayFrame.y);
     Assert.AreEqual(keys, replayFrame.keys);
 }
        public List <HitFrame> findOverAimHits()
        {
            var result   = new List <HitFrame>();
            int keyIndex = 0;

            for (int i = 0; i < hits.Count; ++i)
            {
                CircleObject note = hits[i].note;
                //bool hover = false;

                //searches for init circle object hover
                for (int j = keyIndex; j < replay.ReplayFrames.Count; ++j)
                {
                    ReplayFrame frame = replay.ReplayFrames[j];
                    if (note.ContainsPoint(new BMAPI.Point2(frame.X, frame.Y)) && Math.Abs(frame.Time - note.StartTime) <= hitTimeWindow)
                    {
                        while (note.ContainsPoint(new BMAPI.Point2(frame.X, frame.Y)) && frame.Time < hits[i].frame.Time)
                        {
                            ++j;
                            frame = replay.ReplayFrames[j];
                        }
                        if (!note.ContainsPoint(new BMAPI.Point2(frame.X, frame.Y)))
                        {
                            result.Add(hits[i]);
                        }
                    }
                }
            }
            return(result);
        }
        private List <HitFrame> findOverAimHits()
        {
            var result   = new List <HitFrame>();
            int keyIndex = 0;

            foreach (var t in hits)
            {
                var note = t.note;

                //searches for init circle object hover
                for (int j = keyIndex; j < replay.ReplayFrames.Count; ++j)
                {
                    ReplayFrame frame = replay.ReplayFrames[j];
                    if (!note.ContainsPoint(new Point2(frame.X, frame.Y)) ||
                        !(Math.Abs(frame.Time - note.StartTime) <= hitTimeWindow))
                    {
                        continue;
                    }

                    while (note.ContainsPoint(new Point2(frame.X, frame.Y)) && frame.Time < t.frame.Time)
                    {
                        ++j;
                        frame = replay.ReplayFrames[j];
                    }

                    if (!note.ContainsPoint(new Point2(frame.X, frame.Y)))
                    {
                        result.Add(t);
                    }
                }
            }
            return(result);
        }
示例#11
0
 public override Judgement judge(ReplayFrame cf, bool keyDown, bool hit, TimingPoint currentTiming)
 {
     if (cf.Time >= obj.StartTime)
     {
         return(new Judgement.Good());
     }
     return(null);
 }
示例#12
0
 public void FromLegacy(LegacyReplayFrame currentFrame, IBeatmap beatmap, ReplayFrame lastFrame = null)
 {
     Position = currentFrame.Position;
     Time     = currentFrame.Time;
     if (currentFrame.MouseLeft)
     {
         Actions.Add(TestAction.Down);
     }
 }
        private bool isTeleport(ReplayFrame frame)
        {
            if (frame.travelledDistanceDiff >= 40 && double.IsInfinity(frame.speed))
            {
                return(true);
            }

            return(frame.travelledDistanceDiff >= 150 && frame.speed >= 6);
        }
示例#14
0
 public void FromLegacy(LegacyReplayFrame currentFrame, IBeatmap beatmap, ReplayFrame lastFrame = null)
 {
     Position = currentFrame.Position;
     if (currentFrame.MouseLeft)
     {
         Actions.Add(CytosuAction.Action1);
     }
     if (currentFrame.MouseRight)
     {
         Actions.Add(CytosuAction.Action2);
     }
 }
示例#15
0
        public void HandleFrame(ReplayFrame frame)
        {
            if (frame is IConvertibleReplayFrame convertible)
            {
                pendingFrames.Enqueue(convertible.ToLegacy(currentBeatmap));
            }

            if (pendingFrames.Count > max_pending_frames)
            {
                purgePendingFrames();
            }
        }
示例#16
0
        /// <summary>
        /// Serializes current frame to stream and creates a new replay frame.
        /// </summary>
        private void NextFrame()
        {
            if (!IsRecording)
            {
                throw new InvalidOperationException("Could not save frame: recording not started.");
            }

            //_replayTypeModel.SerializeWithLengthPrefix(_stream, _frame, typeof(ReplayFrame), PrefixStyle.Base128,
            //	_frame.FrameNumber);

            _frame = new ReplayFrame(_frame.FrameNumber + 1);
        }
 public void ConvertFrom(LegacyReplayFrame currentFrame, IBeatmap beatmap, ReplayFrame lastFrame = null)
 {
     Position = currentFrame.Position;
     if (currentFrame.MouseLeft)
     {
         Actions.Add(OsuAction.LeftButton);
     }
     if (currentFrame.MouseRight)
     {
         Actions.Add(OsuAction.RightButton);
     }
 }
示例#18
0
        public override void ReadReplay(string path)
        {
            Replay replay = Replay.Read(path);

            bool[] keyPressed   = new bool[10];
            int[]  holdDuration = new int[10];
            int[]  startTiming  = new int[10];
            ReplayFile = new List <HitObject>();
            List <ReplayFrame> frames = replay.ReplayFrames.Where(x => x.TimeAbs > 0).ToList();
            int keyCount = frames.Select(x => Convert.ToString((int)x.X, 2).Length).Max();

            for (int j = 0; j < frames.Count(); j++)
            {
                ReplayFrame item = frames[j];
                string      x    = String.Join("", Convert.ToString((int)item.X, 2).ToCharArray().Reverse().ToArray());
                x = x.PadRight(keyCount, '0');
                //Console.WriteLine(x);

                char[] key = x.ToCharArray();

                for (int i = 0; i < key.Count(); i++)
                {
                    if (key[i] == '1')
                    {
                        if (!keyPressed[i])
                        {
                            startTiming[i] = item.TimeAbs;
                        }
                        keyPressed[i] = true;
                        if (j < frames.Count() - 1)
                        {
                            holdDuration[i] += frames[j + 1].TimeDiff;
                        }
                    }
                    else
                    {
                        if (keyPressed[i])
                        {
                            ReplayFile.Add(new HitObject(startTiming[i], i, holdDuration[i]));
                            holdDuration[i] = 0;
                        }
                        keyPressed[i] = false;
                    }
                }
            }
            //Console.WriteLine(ReplayFile.Count());
            //foreach (var item in ReplayFile)
            //{
            //	Console.WriteLine(item.Timing + "\t" + item.Key);
            //}
        }
示例#19
0
        private void readLegacyReplay(Replay replay, StreamReader reader)
        {
            float       lastTime     = 0;
            ReplayFrame currentFrame = null;

            string[] frames = reader.ReadToEnd().Split(',');

            for (int i = 0; i < frames.Length; i++)
            {
                string[] split = frames[i].Split('|');

                if (split.Length < 4)
                {
                    continue;
                }

                if (split[0] == "-12345")
                {
                    // Todo: The seed is provided in split[3], which we'll need to use at some point
                    continue;
                }

                float diff   = Parsing.ParseFloat(split[0]);
                float mouseX = Parsing.ParseFloat(split[1], Parsing.MAX_COORDINATE_VALUE);
                float mouseY = Parsing.ParseFloat(split[2], Parsing.MAX_COORDINATE_VALUE);

                lastTime += diff;

                if (i < 2 && mouseX == 256 && mouseY == -500)
                {
                    // at the start of the replay, stable places two replay frames, at time 0 and SkipBoundary - 1, respectively.
                    // both frames use a position of (256, -500).
                    // ignore these frames as they serve no real purpose (and can even mislead ruleset-specific handlers - see mania)
                    continue;
                }

                // Todo: At some point we probably want to rewind and play back the negative-time frames
                // but for now we'll achieve equal playback to stable by skipping negative frames
                if (diff < 0)
                {
                    continue;
                }

                currentFrame = convertFrame(new LegacyReplayFrame(lastTime,
                                                                  mouseX,
                                                                  mouseY,
                                                                  (ReplayButtonState)Parsing.ParseInt(split[3])), currentFrame);

                replay.Frames.Add(currentFrame);
            }
        }
示例#20
0
        public virtual void ResetFromReplayFrame(Ruleset ruleset, ReplayFrame frame)
        {
            if (frame.Header == null)
            {
                return;
            }

            JudgedHits = 0;

            foreach ((_, int count) in frame.Header.Statistics)
            {
                JudgedHits += count;
            }
        }
示例#21
0
        private void ProcessFrame(ReplayFrame frame)
        {
            // Advance simulation time
            _simulationTime = frame.time;

            // Update object pools
            UpdateObjectPools();

            // Update active objects with action
            bool             clickUsed = false;
            HitResult        hitResult;
            List <HitObject> toRemove = new List <HitObject>();

            foreach (HitObject hitObject in _activeObjects)
            {
                hitResult = UpdateHitObject(hitObject, frame.x, frame.y, frame.action, _simulationTime, clickUsed);
                if (hitResult != HitResult.None)
                {
                    switch (hitResult)
                    {
                    case HitResult.Hit300:
                        Count300++;
                        break;

                    case HitResult.Hit100:
                        Count100++;
                        break;

                    case HitResult.Hit50:
                        Count50++;
                        break;

                    case HitResult.Miss:
                        CountMiss++;
                        break;

                    default:
                        break;
                    }

                    clickUsed = true;
                    toRemove.Add(hitObject);
                    _completedObjects.Add(hitObject);
                }
            }
            foreach (HitObject hitObject in toRemove)
            {
                _activeObjects.Remove(hitObject);
            }
        }
示例#22
0
        public void HandleFrame(ReplayFrame frame)
        {
            Debug.Assert(ThreadSafety.IsUpdateThread);

            if (frame is IConvertibleReplayFrame convertible)
            {
                pendingFrames.Enqueue(convertible.ToLegacy(currentBeatmap));
            }

            if (pendingFrames.Count > max_pending_frames)
            {
                purgePendingFrames();
            }
        }
示例#23
0
        public void FromLegacy(LegacyReplayFrame currentFrame, IBeatmap beatmap, ReplayFrame lastFrame = null)
        {
            Time = currentFrame.Time;

            Actions = new List <HitokoriAction>();
            if (currentFrame.MouseLeft1)
            {
                Actions.Add(HitokoriAction.Action1);
            }
            if (currentFrame.MouseRight1)
            {
                Actions.Add(HitokoriAction.Action2);
            }
        }
示例#24
0
        private LegacyReplayFrame getLegacyFrame(ReplayFrame replayFrame)
        {
            switch (replayFrame)
            {
            case LegacyReplayFrame legacyFrame:
                return(legacyFrame);

            case IConvertibleReplayFrame convertibleFrame:
                return(convertibleFrame.ToLegacy(beatmap));

            default:
                throw new ArgumentException(@"Frame could not be converted to legacy frames", nameof(replayFrame));
            }
        }
示例#25
0
        private ReplayFrame insertReplayFrame(int j, int time)
        {
            ReplayFrame r = (ReplayFrame)this.processedReplays[0].replay.ReplayFrames[j].Clone();

            this.processedReplays[0].replay.ReplayFrames.Insert(j, r);

            //r.Time = (this.processedReplays[0].replay.ReplayFrames[j - 1].Time + r.Time) / 2;
            r.Time = time;

            r.TimeDiff = r.Time - this.processedReplays[0].replay.ReplayFrames[j - 1].Time;

            this.processedReplays[0].replay.ReplayFrames[j + 1].TimeDiff = this.processedReplays[0].replay.ReplayFrames[j + 1].Time - r.Time;

            return(r);
        }
示例#26
0
        public void FromLegacy(LegacyReplayFrame currentFrame, IBeatmap beatmap, ReplayFrame lastFrame = null)
        {
            Position = currentFrame.Position;

            if (currentFrame.MouseLeft)
            {
                Actions.Add(SentakkiAction.Button1);
            }
            if (currentFrame.MouseRight)
            {
                Actions.Add(SentakkiAction.Button2);
            }

            UsingSensorMode = currentFrame.ButtonState.HasFlagFast(ReplayButtonState.Smoke);
        }
示例#27
0
    public List <ReplayFrame> interpolateReplay()
    {
        if (replayFrames == null)
        {
            return(null);
        }
        Console.WriteLine("Interpolating replay...");
        List <ReplayFrame> list = new List <ReplayFrame>();

        for (int i = 0; i < replayFrames.Count - 1; i++)
        {
            ReplayFrame replayFrame = new ReplayFrame();
            replayFrame.X        = (replayFrames[i].X + replayFrames[i + 1].X) / 2f;
            replayFrame.Y        = (replayFrames[i].Y + replayFrames[i + 1].Y) / 2f;
            replayFrame.TimeDiff = replayFrames[i].TimeDiff;
            switch (replayFrames[i].StandardKeys)
            {
            case StandardKeys.K1:
                replayFrame.StandardKeys = StandardKeys.K1;
                break;

            case StandardKeys.K2:
                replayFrame.StandardKeys = StandardKeys.K2;
                break;

            case StandardKeys.BOTH:
                replayFrame.StandardKeys = StandardKeys.BOTH;
                break;

            case StandardKeys.Smoke:
                replayFrame.StandardKeys = StandardKeys.Smoke;
                break;

            default:
                replayFrame.StandardKeys = StandardKeys.None;
                break;
            }
            ReplayFrame replayFrame2 = replayFrames[i];
            replayFrame2.TimeDiff /= 2;
            replayFrame.TimeDiff  -= replayFrame2.TimeDiff;
            list.Add(replayFrame2);
            list.Add(replayFrame);
        }
        Console.WriteLine("Interpolated replay");
        Console.WriteLine("Original frame count: " + replayFrames.Count);
        Console.WriteLine("Interpolated frame count: " + (list.Count - replayFrames.Count));
        return(list);
    }
示例#28
0
        private void readLegacyReplay(Replay replay, StreamReader reader)
        {
            float       lastTime     = 0;
            ReplayFrame currentFrame = null;

            var frames = reader.ReadToEnd().Split(',');

            for (var i = 0; i < frames.Length; i++)
            {
                var split = frames[i].Split('|');

                if (split.Length < 4)
                {
                    continue;
                }

                if (split[0] == "-12345")
                {
                    // Todo: The seed is provided in split[3], which we'll need to use at some point
                    continue;
                }

                var diff = Parsing.ParseFloat(split[0]);

                lastTime += diff;

                if (i == 0 && diff == 0)
                {
                    // osu-stable adds a zero-time frame before potentially valid negative user frames.
                    // we need to ignore this.
                    continue;
                }

                // Todo: At some point we probably want to rewind and play back the negative-time frames
                // but for now we'll achieve equal playback to stable by skipping negative frames
                if (diff < 0)
                {
                    continue;
                }

                currentFrame = convertFrame(new LegacyReplayFrame(lastTime,
                                                                  Parsing.ParseFloat(split[1], Parsing.MAX_COORDINATE_VALUE),
                                                                  Parsing.ParseFloat(split[2], Parsing.MAX_COORDINATE_VALUE),
                                                                  (ReplayButtonState)Parsing.ParseInt(split[3])), currentFrame);

                replay.Frames.Add(currentFrame);
            }
        }
示例#29
0
        void DoWalk(ReplayFrame frame)
        {
            SetAnimParam("walkspeed_scale", 2.0f / 260.0f);
            SetAnimParam("runspeed_scale", 2.0f / 260.0f);
            SetAnimParam("duckspeed_scale", 2.0f / 80.0f);

            var rot        = Rotation.From(frame.Angles);
            var moveDir    = frame.Velocity.Normal * 100.0f;
            var forward    = rot.Forward.Dot(moveDir);
            var sideward   = rot.Left.Dot(moveDir);
            var speedScale = WorldScale;

            SetAnimParam("forward", forward);
            SetAnimParam("sideward", sideward);
            SetAnimParam("wishspeed", speedScale > 0.0f ? frame.Velocity.Length / speedScale : 0.0f);
        }
示例#30
0
        private ReplayFrame convertFrame(LegacyReplayFrame currentFrame, ReplayFrame lastFrame)
        {
            var convertible = currentRuleset.CreateConvertibleReplayFrame();

            if (convertible == null)
            {
                throw new InvalidOperationException($"Legacy replay cannot be converted for the ruleset: {currentRuleset.Description}");
            }

            convertible.FromLegacy(currentFrame, currentBeatmap, lastFrame);

            var frame = (ReplayFrame)convertible;

            frame.Time = currentFrame.Time;

            return(frame);
        }