static void ReceviceSameCmdMsg(SyncSession session, SameCommand msg)
    {
        //消息确认
        AffirmMsg amsg = new AffirmMsg();

        amsg.index = msg.frame;
        amsg.time  = msg.time;
        ProtocolAnalysisService.SendMsg(session, amsg);

        ConnectionComponent connectComp = session.m_connect;

        if (connectComp != null)
        {
            WorldBase world = connectComp.Entity.World;

            //取上一帧的数据
            T scmd = (T)connectComp.GetCommand(msg.frame - 1).DeepCopy();

            if (msg.frame > world.FrameCount)
            {
                scmd.frame = msg.frame;

                connectComp.AddCommand(scmd);
                BroadcastSameCommand(world, connectComp, msg, true);
            }
            else
            {
                scmd.frame = world.FrameCount;
                connectComp.AddCommand(scmd);
            }

            ControlSpeed(connectComp, world, msg.frame);
        }
    }
    public override void BeforeFixedUpdate(int deltaTime)
    {
        //Debug.Log("GetEntityList A");

        List <EntityBase> list = GetEntityList();

        //Debug.Log("list Res -> " + GetEntityList(new string[] { "CommandComponent", "ConnectionComponent" }).Count);

        //Debug.Log("GetEntityList B " + list.Count);

        for (int i = 0; i < list.Count; i++)
        {
            ConnectionComponent comp = list[i].GetComp <ConnectionComponent>();
            T cmd = (T)comp.GetCommand(m_world.FrameCount);
            cmd.id    = list[i].ID;
            cmd.frame = m_world.FrameCount;

            list[i].ChangeComp(cmd);

            //Debug.Log("USE cmd id "+ list[i].ID + " frame " + cmd.frame + " content " + Serializer.Serialize(cmd));

            //到了这一帧还没有发送命令的,给预测一个并广播给所有前端
            if (comp.LastInputFrame < m_world.FrameCount)
            {
                for (int j = 0; j < list.Count; j++)
                {
                    ConnectionComponent conn = list[j].GetComp <ConnectionComponent>();
                    ProtocolAnalysisService.SendMsg(conn.m_session, cmd);
                }
            }
        }
    }
예제 #3
0
    public override void BeforeFixedUpdate(int deltaTime)
    {
        List <EntityBase> list = GetEntityList();

        for (int i = 0; i < list.Count; i++)
        {
            ConnectionComponent comp = list[i].GetComp <ConnectionComponent>();
            comp.m_isInframe = true;

            T cmd = (T)comp.GetCommand(m_world.FrameCount);
            cmd.id    = list[i].ID;
            cmd.frame = m_world.FrameCount;

            list[i].ChangeComp(cmd);

            //Debug.Log("USE cmd id "+ list[i].ID + " frame " + cmd.frame + " content " + Serializer.Serialize(cmd));

            //到了这一帧还没有发送命令的,给预测一个并广播给所有前端
            //if (comp.LastInputFrame < m_world.FrameCount)
            {
                for (int j = 0; j < list.Count; j++)
                {
                    cmd.time = ServiceTime.GetServiceTime();

                    ConnectionComponent conn = list[j].GetComp <ConnectionComponent>();
                    ProtocolAnalysisService.SendMsg(conn.m_session, cmd);
                    //Debug.Log("预测并广播 " + cmd.frame);
                }
            }
        }
    }
    static void ReceviceQueryMsg(SyncSession session, QueryCommand msg)
    {
        ConnectionComponent connectComp = session.m_connect;

        if (connectComp != null)
        {
            WorldBase world = connectComp.Entity.World;

            EntityBase          entity = world.GetEntity(msg.id);
            ConnectionComponent cc     = entity.GetComp <ConnectionComponent>();

            T cmd = (T)cc.GetCommand(msg.frame);
            ProtocolAnalysisService.SendMsg(connectComp.m_session, cmd);
        }
    }
예제 #5
0
        public override void NoRecalcBeforeFixedUpdate(int deltaTime)
        {
            List <EntityBase> list = GetEntityList();

            for (int i = 0; i < list.Count; i++)
            {
                ConnectionComponent comp = list[i].GetComp <ConnectionComponent>();

                if (comp.m_commandList.Count > 0)
                {
                    T cmd = (T)comp.GetCommand(m_world.FrameCount);
                    cmd.id    = list[i].ID;
                    cmd.frame = m_world.FrameCount;

                    list[i].ChangeComp(cmd);
                }
            }
        }
    public override void NoRecalcBeforeFixedUpdate(int deltaTime)
    {
        List <EntityBase> list = GetEntityList();

        for (int i = 0; i < list.Count; i++)
        {
            ConnectionComponent comp = list[i].GetComp <ConnectionComponent>();
            CommandComponent    cmd  = (CommandComponent)comp.GetCommand(m_world.FrameCount);
            cmd.id    = list[i].ID;
            cmd.frame = m_world.FrameCount;

            list[i].ChangeComp(cmd);

            //Debug.Log("USE cmd id "+ list[i].ID + " frame " + cmd.frame + " content " + Serializer.Serialize(cmd));

            //到了这一帧还没有发送命令的,给预测一个并广播给所有前端
            if (comp.LastInputFrame < m_world.FrameCount)
            {
                for (int j = 0; j < list.Count; j++)
                {
                    ConnectionComponent conn = list[j].GetComp <ConnectionComponent>();

                    //lock(conn.m_unConfirmFrame)
                    {
                        ////补发未确认的帧
                        //foreach (var item in conn.m_unConfirmFrame)
                        //{
                        //    CommandMsg info = item.Value;
                        //    ProtocolAnalysisService.SendMsg(conn.m_session, info);
                        //}

                        //cmsg.index = conn.GetSendIndex();

                        //conn.m_unConfirmFrame.Add(cmsg.index, cmd);

                        ProtocolAnalysisService.SendMsg(conn.m_session, cmd);

                        //Debug.Log("消息落后或掉线 预测一个 输入并派发 comp.lastInputFrame " + comp.lastInputFrame  + " m_world.FrameCount " + m_world.FrameCount +" ID " + comp.Entity.ID);
                    }
                }
            }
        }
    }
예제 #7
0
    static void ReceviceSameCmdMsg(SyncSession session, SameCommand msg)
    {
        //消息确认
        AffirmMsg amsg = new AffirmMsg();

        amsg.index = msg.frame;
        amsg.time  = msg.time;
        ProtocolAnalysisService.SendMsg(session, amsg);

        ConnectionComponent connectComp = session.m_connect;

        if (connectComp != null)
        {
            WorldBase world = connectComp.Entity.World;

            if (world.FrameCount <= msg.frame + 4)
            {
                //取上一帧的数据
                T scmd = (T)connectComp.GetCommand(msg.frame - 1).DeepCopy();
                scmd.frame = world.FrameCount + 1;
                connectComp.AddCommand(scmd);
            }

            //    //取上一帧的数据
            //    T scmd = (T)connectComp.GetCommand(msg.frame - 1).DeepCopy();
            ////msg.frame = world.FrameCount + 1;
            //    scmd.frame = world.FrameCount + 1;
            //if (connectComp.AddCommand(scmd))
            //    {
            //        //BroadcastSameCommand(world, connectComp, msg, true);
            //    }
            //}
            //else
            //{
            //    //Debug.Log("Same frame " + world.FrameCount);
            //    //scmd.frame = world.FrameCount + 1;
            //    //connectComp.AddCommand(scmd);
            //}

            ControlSpeed(connectComp, world, msg.frame);
        }
    }
예제 #8
0
    public override void NoRecalcBeforeFixedUpdate(int deltaTime)
    {
        List <EntityBase> list = GetEntityList();

        for (int i = 0; i < list.Count; i++)
        {
            ConnectionComponent comp = list[i].GetComp <ConnectionComponent>();
            CommandComponent    cmd  = (CommandComponent)comp.GetCommand(m_world.FrameCount);
            cmd.id    = list[i].ID;
            cmd.frame = m_world.FrameCount;

            list[i].ChangeComp(cmd);

            //到了这一帧还没有发送命令的,给预测一个并广播给所有前端
            if (comp.lastInputFrame < m_world.FrameCount)
            {
                for (int j = 0; j < list.Count; j++)
                {
                    ConnectionComponent conn = list[j].GetComp <ConnectionComponent>();
                    ProtocolAnalysisService.SendMsg(comp.m_session, cmd);
                }
            }
        }
    }