Beispiel #1
0
 void Awake()
 {
     if (singleton == null)
     {
         singleton = this;
     }
     else
     {
         Debug.LogWarning("There can only be one Console per project");
         Destroy(this);
         return;
     }
     if (dontDestroyOnLoad)
     {
         DontDestroyOnLoad(gameObject);
     }
     consoleCommands = new List <Command>()
     {
         new Command("HELP", GeneralHelp, "Shows a list of all Commands available"),
         new Command("DC_INFO", ShowInfo, "Shows info about the DevConsole"),
         new Command("DC_CLEAR", Clear, "Clears the console"),
         new Command("DC_CHANGE_KEY", ChangeKey, ChangeKeyHelp),
         new Command("DC_SHOW_DEBUGLOG", ShowLog, "Establishes whether or not to show Unity Debug Log"),
         new Command("DC_SHOW_TIMESTAMP", ShowTimeStamp, "Establishes whether or not to show the time stamp for each command")
     };
     GMCommand.regeditGMCommand();
 }
Beispiel #2
0
    /// <summary>
    /// 发送关键帧
    /// </summary>
    private void SendFrame()
    {
        if (mSentFrame >= mCurrentFrame)
        {
            return;
        }

        GM_Frame sendData = SharedValue <GM_Frame> .sData;

        sendData.command.Clear();

        sendData.roleId    = PlayerManager.GetSingleton().mRoleId;
        sendData.frame     = mCurrentFrame;
        sendData.frametime = mFrameTime;
        lock (mCommandQueue)
        {
            while (mCommandQueue.Count > 0)
            {
                Command   frame = mCommandQueue.Dequeue();
                GMCommand cmd   = ProtoTransfer.Get(frame);

                sendData.command.Add(cmd);
            }
            mCommandQueue.Clear();
        }

        ClientService.GetSingleton().SendUdp(ClientID.Frame, MessageID.GM_FRAME_CS, sendData);


        mSentFrame++;
    }
Beispiel #3
0
    void OnAddCommand(Command cmd)
    {
        if (cmd == null)
        {
            return;
        }

        if (mBegin == false)
        {
            Debug.Log("Frame not Begin ");

            return;
        }

        Debug.Log("AddFrame " + (CommandID)cmd.type);

        cmd.SetFrame(mCurrentFrame, mFrameTime);

        if (GameApplication.GetSingleton().mode == Mode.LockStep)
        {
            lock (mCommandQueue)
            {
                mCommandQueue.Enqueue(cmd);
            }
        }
        else
        {
            //乐观模式马上发送命令

            GM_Frame sendData = SharedValue <GM_Frame> .sData;
            sendData.command.Clear();

            sendData.roleId    = PlayerManager.GetSingleton().mRoleId;
            sendData.frame     = mCurrentFrame;
            sendData.frametime = mFrameTime;

            GMCommand data = ProtoTransfer.Get(cmd);

            sendData.command.Add(data);


            //string s1 = JsonSerializerUtil.ToJson<GM_Frame>(sendData);
            //GM_Frame sendData2 = JsonSerializerUtil.FromJson<GM_Frame>(s1);

            //byte[] bytes = JsonSerializerUtil.ToJsonByte<GM_Frame>(sendData);
            //GM_Frame sendData1 = JsonSerializerUtil.FromJsonByte<GM_Frame>(bytes);

            if (Debuger.ENABLELOG)
            {
                Debug.Log("当前帧:" + mCurrentFrame + "发送关键帧 = " + cmd.id.ToString() + ",frame = " + cmd.frame + ",time = " + cmd.time);
            }

            ClientService.GetSingleton().SendTcp(ClientID.Frame, MessageID.GM_FRAME_CS, sendData);
        }
    }
        public static GMCommand Get(Command cmd)
        {
            GMCommand o = new GMCommand();

            o.id        = cmd.id;
            o.frame     = cmd.frame;
            o.type      = cmd.type;
            o.frametime = cmd.time;
            o.data      = cmd.data;
            return(o);
        }
Beispiel #5
0
    private void OnLockStepFrameBC(GM_Frame_BC recvData)
    {
        if (recvData == null)
        {
            return;
        }
        //不打印那么多信息
        if (recvData.command.Count > 0 || recvData.frame % 30 == 0)
        {
            Debug.Log("Receive frame:" + recvData.frame + " command:" + recvData.command.Count);
        }

        long frame = recvData.frame;

        mFrameTime = recvData.frametime;

        if (frame == mCurrentFrame)
        {
            recvData.command.Sort(SortCommand);

            for (int i = 0; i < recvData.command.Count; ++i)
            {
                GMCommand cmd  = recvData.command[i];
                Command   data = new Command(cmd.id, cmd.frame, cmd.type, cmd.data, cmd.frametime);

                if (mFrameDic.ContainsKey(frame) == false)
                {
                    mFrameDic.Add(frame, new List <Command>());
                }
                mFrameDic[frame].Add(data);

                DoCommand(data);
            }

            EventDispatch.Dispatch(EventID.Frame_Broadcast, mCurrentFrame);

            mCurrentFrame++;
        }
        else
        {
            Debug.LogError("frame = " + frame + ",current=" + mCurrentFrame);
        }
    }
Beispiel #6
0
    void OnAddCommand(Command cmd)
    {
        if (cmd == null)
        {
            return;
        }

        if (mBegin == false)
        {
            Debug.Log("Frame not Begin ");

            return;
        }

        Debug.Log("AddFrame " + (CommandID)cmd.type);

        cmd.SetFrame(mCurrentFrame, mFrameTime);

        if (GameApplication.GetSingleton().mode == Mode.LockStep)
        {
            lock (mCommandQueue)
            {
                mCommandQueue.Enqueue(cmd);
            }
        }
        else
        {
            //乐观模式马上发送命令

            GM_Frame sendData = SharedValue <GM_Frame> .sData;
            sendData.command.Clear();

            sendData.roleId    = PlayerManager.GetSingleton().mRoleId;
            sendData.frame     = mCurrentFrame;
            sendData.frametime = mFrameTime;

            GMCommand data = ProtoTransfer.Get(cmd);

            sendData.command.Add(data);
            ClientService.GetSingleton().SendUdp(ClientID.Frame, MessageID.GM_FRAME_CS, sendData);
        }
    }
        /// <summary>
        /// 按固定频率向客户端广播帧
        /// </summary>
        private void SendFrame()
        {
            long        frame     = mCurrentFrame++;
            int         userCount = 0; //当前帧有多少个客户端发了命令
            GM_Frame_BC sendData  = new GM_Frame_BC();

            sendData.frame     = frame;
            sendData.frametime = mFrameTime;

            if (mFrameDic.ContainsKey(frame))
            {
                var frames = mFrameDic[frame];

                userCount = frames.Count;

                var it = frames.GetEnumerator();
                while (it.MoveNext())
                {
                    for (int i = 0, count = it.Current.Value.Count; i < count; ++i)
                    {
                        GMCommand cmd = ProtoTransfer.Get(it.Current.Value[i]);
                        cmd.eventType = it.Current.Value[i].eventType;
                        sendData.command.Add(cmd);
                    }
                }
            }


            //不显示那么多log
            if (frame % 30 == 0 || sendData.command.Count > 0)
            {
                Debug.Log(string.Format("Send frame:{0} user count:{1} command count:{2}", frame, userCount, sendData.command.Count), ConsoleColor.Gray);
            }

            BroadCast(MessageID.GM_FRAME_BC, sendData, true);
        }
Beispiel #8
0
    /// <summary>
    /// 乐观模式处理
    /// </summary>
    /// <param name="recvData"></param>
    private void OnOptimisticFrameBC(GM_Frame_BC recvData)
    {
        if (recvData == null)
        {
            return;
        }

        mCurrentFrame = recvData.frame;


        //不打印那么多信息
        if (recvData.command.Count > 0 || recvData.frame % 30 == 0)
        {
            Debug.Log("Receive frame:" + recvData.frame + " command:" + recvData.command.Count);
            Debug.Log(recvData.frametime + "," + mFrameTime + "," + (mFrameTime - recvData.frametime));
        }

        mFrameTime = recvData.frametime;


        for (int i = 0; i < recvData.command.Count; ++i)
        {
            GMCommand cmd  = recvData.command[i];
            Command   data = new Command(cmd.id, cmd.frame, cmd.type, cmd.data, cmd.frametime);

            if (mFrameDic.ContainsKey(mCurrentFrame) == false)
            {
                mFrameDic.Add(mCurrentFrame, new List <Command>());
            }
            mFrameDic[mCurrentFrame].Add(data);

            DoCommand(data);
        }

        EventDispatch.Dispatch(EventID.Frame_Broadcast, mCurrentFrame);
    }
        private void OnLockStepFrame(Session client, GM_Frame recvData)
        {
            long frame  = recvData.frame;
            int  roleId = recvData.roleId;

            if (recvData.command.Count > 0 || frame % 30 == 0)
            {
                Debug.Log(string.Format("Receive {0} serverframe:{1} clientframe:{2} command:{3}", roleId, mCurrentFrame, frame, recvData.command.Count), ConsoleColor.DarkGray);
            }
            if (mFrameDic.ContainsKey(frame) == false)
            {
                mFrameDic.Add(frame, new Dictionary <int, List <Command> >());
            }

            var frames = mFrameDic[frame];

            //当前帧的服务器命令
            if (frames.ContainsKey(SERVER_ROLEID) == false)
            {
                frames.Add(SERVER_ROLEID, new List <Command>());
            }

            //该玩家是否发送了当前帧
            if (frames.ContainsKey(roleId) == false)
            {
                frames.Add(roleId, new List <Command>());
            }

            for (int i = 0; i < recvData.command.Count; ++i)
            {
                Command cmd = new Command(recvData.command[i].frame, recvData.command[i].type, recvData.command[i].data, recvData.command[i].frametime);

                frames[roleId].Add(cmd);
            }

            //当所有玩家都发送了该帧,就可以广播了
            //减去1是因为服务器命令也在当前帧中
            if (frames.Count - 1 >= mUserList.Count)
            {
                GM_Frame_BC sendData = new GM_Frame_BC();
                sendData.frame     = frame;
                sendData.frametime = mFrameTime;
                var it = frames.GetEnumerator();
                while (it.MoveNext())
                {
                    for (int i = 0, count = it.Current.Value.Count; i < count; ++i)
                    {
                        GMCommand cmd = ProtoTransfer.Get(it.Current.Value[i]);

                        sendData.command.Add(cmd);
                    }
                }


                BroadCast(MessageID.GM_FRAME_BC, sendData, true);

                mCurrentFrame = frame + 1;
            }
            else
            {
                Debug.Log(string.Format("Waiting {0} frame:{1} count:{2} current:{3} ", roleId, frame, mFrameDic[frame].Count, mUserList.Count), ConsoleColor.Red);
            }
        }
Beispiel #10
0
 /// <summary>
 /// 命令排序,确保每个客户端命令的执行顺序一致
 /// </summary>
 /// <param name="a"></param>
 /// <param name="b"></param>
 /// <returns></returns>
 int SortCommand(GMCommand a, GMCommand b)
 {
     //比较帧
     if (a.frame < b.frame)
     {
         return(-1);
     }
     else if (a.frame > b.frame)
     {
         return(1);
     }
     else
     {
         //比较时间
         if (a.frametime < b.frametime)
         {
             return(-1);
         }
         else if (a.frametime > b.frametime)
         {
             return(1);
         }
         else
         {
             //比较类型
             if (a.type < b.type)
             {
                 return(-1);
             }
             else if (a.type > b.type)
             {
                 return(1);
             }
             else
             {
                 //比较数值
                 if (a.data.Length < b.data.Length)
                 {
                     return(-1);
                 }
                 else if (a.data.Length > b.data.Length)
                 {
                     return(1);
                 }
                 else
                 {
                     int length = a.data.Length;
                     for (int i = 0; i < length; ++i)
                     {
                         if (a.data[i] < b.data[i])
                         {
                             return(-1);
                         }
                         else if (a.data[i] > b.data[i])
                         {
                             return(1);
                         }
                     }
                 }
             }
         }
     }
     return(0);
 }
Beispiel #11
0
    public void GMorder(string _gmmo)
    {
        GMCommand _gmmos = new GMCommand();

        try { _gmmos = (GMCommand)Enum.Parse(typeof(GMCommand), _gmmo); }
        catch (Exception e)
        {
            Debug.Log("不存在的GM命令" + ":" + e.ToString());
        }


        switch (_gmmos)
        {
        case GMCommand.modifylevel:     //主公满级
            if (Role.Instance.Level == LEVEL)
            {
                return;
            }
            Role.Instance.Level = LEVEL;
            ZEventSystem.Dispatch(EventConst.UpdateData);

            break;

        case GMCommand.modifycopper:     //增加铜钱
            Role.Instance.Cash += COPPER;
            if (Role.Instance.Cash > 99999999)
            {
                Role.Instance.Cash = 99999999;
            }

            break;

        case GMCommand.clearclear:
            ClearsClose();
            break;

        case GMCommand.modifyPower:     //增加体力

            if (Role.Instance.Power < POWER * 10)
            {
                Role.Instance.Power = POWER;
            }
            break;

        case GMCommand.modifyviplevel:
            if (Role.Instance.Vip < 15)
            {
                Role.Instance.Vip = Role.Instance.Vip + 1;
            }
            Debug.Log("VIP等级" + Role.Instance.Vip);

            break;

        case GMCommand.modifyglevel:
            Debug.Log("未实现");
            break;

        case GMCommand.modifygold:
            Role.Instance.Gold       += COPPER;
            Role.Instance.LockedGold += COPPER;
            ZEventSystem.Dispatch(EventConst.UpdateData);
            if (Role.Instance.Gold > 99999999)
            {
                Role.Instance.Gold       = 99999999;
                Role.Instance.LockedGold = 99999999;
            }

            break;

        case GMCommand.clearsection:
            Simulate();
            break;

        case GMCommand.modifydynamic:

            Debug.Log("未实现");
            break;

        case GMCommand.equip:

            Debug.Log("未实现");
            break;

        case GMCommand.modifyarena:

            Debug.Log("未实现");
            break;

        case GMCommand.modifyhonor:

            if (Role.Instance.Honor < HONOR * 10)
            {
                Role.Instance.Honor += HONOR;
                Debug.Log("荣誉" + Role.Instance.Honor);
            }
            break;

        case GMCommand.modifyskill:
            Debug.Log("未实现");
            break;

        case GMCommand.modifyggzj:
            Debug.Log("未实现");
            break;

        case GMCommand.intensify:
            Debug.Log("未实现");
            break;

        case GMCommand.modifyvigor:
            Debug.Log("未实现");
            break;

        case GMCommand.divination:
            Debug.Log("未实现");
            break;

        case GMCommand.sophistication:
            Debug.Log("未实现");
            break;
        }
        GMOrder_input.text = "";
    }