示例#1
0
        public void RecordData()
        {
            if (Player == null)
            {
                return;
            }

            Session session = (Engine.Scene as Level).Session;

            // A data frame is always a new frame, no matter if the previous one lacks data or not.
            LastFrameData = new GhostFrame {
                Data = new GhostChunkData {
                    IsValid = true,

                    InControl = Player.InControl,

                    Position = Player.Position,
                    Speed    = Player.Speed,
                    Rotation = Player.Sprite.Rotation,
                    Scale    = Player.Sprite.Scale,
                    Color    = Player.Sprite.Color,

                    Facing = Player.Facing,

                    CurrentAnimationID    = Player.Sprite.CurrentAnimationID,
                    CurrentAnimationFrame = Player.Sprite.CurrentAnimationFrame,

                    HairColor          = Player.Hair.Color,
                    HairSimulateMotion = Player.Hair.SimulateMotion,

                    DashColor = Player.StateMachine.State == Player.StDash ? Player.GetCurrentTrailColor() : (Color?)null,
                    DashDir   = Player.DashDir,
                    DashWasB  = Player.GetWasDashB(),

                    Time = session.Time
                }
            };

            if (Player.StateMachine.State == Player.StRedDash)
            {
                LastFrameData.Data.HairCount = 1;
            }
            else if (Player.StateMachine.State != Player.StStarFly)
            {
                LastFrameData.Data.HairCount = Player.Dashes > 1 ? 5 : 4;
            }
            else
            {
                LastFrameData.Data.HairCount = 7;
            }

            if (Data != null)
            {
                Data.Frames.Add(LastFrameData);
            }
        }
示例#2
0
        public void Write(BinaryWriter writer)
        {
            writer.Write((short)0x0ade);
            writer.Write(MagicChars);
            writer.Write(Version);

            writer.Write(0); // Uncompressed

            writer.WriteNullTerminatedString(SID);
            writer.Write((int)Mode);
            writer.WriteNullTerminatedString(Level);
            writer.Write((float)RespawnPoint.X);
            writer.Write((float)RespawnPoint.Y);
            writer.WriteNullTerminatedString(Target);

            writer.WriteNullTerminatedString(Name);
            writer.Write(Date.ToBinary());

            writer.Write(Dead);

            if (Opacity != null)
            {
                writer.Write(true);
                writer.Write(Opacity.Value);
            }
            else
            {
                writer.Write(false);
            }

            writer.Write(Run.ToByteArray());

            writer.Write(Frames.Count);
            writer.Write('\r');
            writer.Write('\n');
            for (int i = 0; i < Frames.Count; i++)
            {
                GhostFrame frame = Frames[i];
                frame.Write(writer);
            }
        }
示例#3
0
        public void RecordData()
        {
            if (Player == null)
            {
                return;
            }

            // A data frame is always a new frame, no matter if the previous one lacks data or not.
            LastFrameData = new GhostFrame {
                Data = new GhostChunkData {
                    IsValid = true,

                    InControl = Player.InControl,

                    Position = Player.Position,
                    Speed    = Player.Speed,
                    Rotation = Player.Sprite.Rotation,
                    Scale    = Player.Sprite.Scale,
                    Color    = Player.Sprite.Color,

                    Facing = Player.Facing,

                    CurrentAnimationID    = Player.Sprite.CurrentAnimationID,
                    CurrentAnimationFrame = Player.Sprite.CurrentAnimationFrame,

                    HairColor          = Player.Hair.Color,
                    HairSimulateMotion = Player.Hair.SimulateMotion,

                    DashColor = Player.StateMachine.State == Player.StDash ? Player.GetCurrentTrailColor() : (Color?)null,
                    DashDir   = Player.DashDir,
                    DashWasB  = Player.GetWasDashB()
                }
            };

            if (Data != null)
            {
                Data.Frames.Add(LastFrameData);
            }
        }
示例#4
0
        public GhostData Read(BinaryReader reader)
        {
            if (reader.ReadInt16() != 0x0ade)
            {
                return(null); // Endianness mismatch.
            }
            char[] magic = reader.ReadChars(MagicChars.Length);
            if (magic.Length != MagicChars.Length)
            {
                return(null); // Didn't read as much as we wanted to read.
            }
            for (int i = 0; i < MagicChars.Length; i++)
            {
                if (magic[i] != MagicChars[i])
                {
                    return(null); // Magic mismatch.
                }
            }

            int version = reader.ReadInt32();

            // Don't read data from the future, but try to read data from the past.
            if (version > Version)
            {
                return(null);
            }

            int compression = reader.ReadInt32();

            if (compression != 0)
            {
                return(null); // Compression not supported yet.
            }
            SID    = reader.ReadNullTerminatedString();
            Mode   = (AreaMode)reader.ReadInt32();
            Level  = reader.ReadNullTerminatedString();
            Target = reader.ReadNullTerminatedString();

            Name = reader.ReadNullTerminatedString();
            long dateBin = reader.ReadInt64();

            try {
                Date = DateTime.FromBinary(dateBin);
            } catch {
                // The date was invalid. Let's ignore it.
                Date = DateTime.UtcNow;
            }

            Dead = reader.ReadBoolean();

            Opacity = reader.ReadBoolean() ? (float?)reader.ReadSingle() : null;

            if (version >= 1)
            {
                Run = new Guid(reader.ReadBytes(16));
            }
            else
            {
                Run = Guid.Empty;
            }

            int count = reader.ReadInt32();

            reader.ReadChar(); // \r
            reader.ReadChar(); // \n
            Frames = new List <GhostFrame>(count);
            for (int i = 0; i < count; i++)
            {
                GhostFrame frame = new GhostFrame();
                frame.Read(reader);
                Frames.Add(frame);
            }

            return(this);
        }
示例#5
0
        public void RecordInput()
        {
            // Check if we've got a data-less input frame. If so, add input to it.
            // If the frame already has got input, add a new input frame.

            bool inputDisabled = MInput.Disabled;

            MInput.Disabled = false;

            GhostFrame frame;
            bool       isNew = false;

            if (Data == null || Data.Frames.Count == 0 || Data[Data.Frames.Count - 1].Input.IsValid)
            {
                frame = new GhostFrame();
                isNew = true;
            }
            else
            {
                frame = Data[Data.Frames.Count - 1];
            }

            frame.Input.IsValid = true;

            frame.Input.MoveX = Input.MoveX.Value;
            frame.Input.MoveY = Input.MoveY.Value;

            frame.Input.Aim         = Input.Aim.Value;
            frame.Input.MountainAim = Input.MountainAim.Value;

            frame.Input.ESC          = Input.ESC.Check;
            frame.Input.Pause        = Input.Pause.Check;
            frame.Input.MenuLeft     = Input.MenuLeft.Check;
            frame.Input.MenuRight    = Input.MenuRight.Check;
            frame.Input.MenuUp       = Input.MenuUp.Check;
            frame.Input.MenuDown     = Input.MenuDown.Check;
            frame.Input.MenuConfirm  = Input.MenuConfirm.Check;
            frame.Input.MenuCancel   = Input.MenuCancel.Check;
            frame.Input.MenuJournal  = Input.MenuJournal.Check;
            frame.Input.QuickRestart = Input.QuickRestart.Check;
            frame.Input.Jump         = Input.Jump.Check;
            frame.Input.Dash         = Input.Dash.Check;
            frame.Input.Grab         = Input.Grab.Check;
            frame.Input.Talk         = Input.Talk.Check;

            if (Data != null)
            {
                if (isNew)
                {
                    Data.Frames.Add(frame);
                }
                else
                {
                    Data.Frames[Data.Frames.Count - 1] = frame;
                }
            }

            LastFrameInput = frame;

            MInput.Disabled = inputDisabled;
        }