Beispiel #1
0
 public UsLogPacket(UsCmd c)
 {
     SeqID = (ushort)c.ReadInt16();
     LogType = (UsLogType)c.ReadInt32();
     Content = c.ReadString();
     RealtimeSinceStartup = c.ReadFloat();
 }
Beispiel #2
0
 public void WriteMesh(int instID, UsCmd cmd)
 {
     MeshData data;
     if (_lut.TryGetValue(instID, out data)) {
         data.Write(cmd);
     }
 }
Beispiel #3
0
 public static void WriteIntList(UsCmd c, List<int> l)
 {
     c.WriteInt32 (l.Count);
     foreach (var item in l) {
         c.WriteInt32 (item);
     }
 }
Beispiel #4
0
        private void OnLogicallyConnected(object sender, EventArgs e)
        {
            this.Dispatcher.Invoke(new Action(() =>
            {
                cb_targetIP.IsEnabled = false;
                bt_connect.IsEnabled = false;
                bt_disconnect.IsEnabled = true;

                string remoteAddr = cb_targetIP.Text;
                UsLogging.Printf(LogWndOpt.Bold, "connected to [u]{0}[/u].", remoteAddr);

                if (AppSettingsUtil.AppendAsRecentlyConnected(remoteAddr))
                {
                    cb_targetIP.Items.Add(remoteAddr);
                    UsLogging.Printf("{0} is appended into the recent connection list.", remoteAddr);
                }

                // query switches and sliders
                {
                    UsCmd cmd = new UsCmd();
                    cmd.WriteNetCmd(eNetCmd.CL_QuerySwitches);
                    NetManager.Instance.Send(cmd);
                }
                {
                    UsCmd cmd = new UsCmd();
                    cmd.WriteNetCmd(eNetCmd.CL_QuerySliders);
                    NetManager.Instance.Send(cmd);
                }

            }));
        }
Beispiel #5
0
        public bool NetHandle_Editor_SelectionChanged(eNetCmd cmd, UsCmd c)
        {
            int count = c.ReadInt32();
            UsLogging.Printf("eNetCmd.SV_Editor_SelectionChanged received ({0}, inst count: {1}).", c.Buffer.Length, count);

            _instances.Clear();
            for (int i = 0; i < count; i++)
            {
                int instID = c.ReadInt32();
                _instances.Add(instID);
            }

            MeshGrid.Dispatcher.Invoke(new Action(() =>
            {
                ClearAllSelectionsAndHighlightedObjects();
                var meshes = HighlightMeshes(_instances, Colors.PaleTurquoise);
                foreach (var mesh in meshes)
                {
                    var matLst = HighlightMaterialByMesh(mesh, Colors.PaleTurquoise);
                    foreach (var mat in matLst)
                        HighlightTextureByMaterial(mat, Colors.PaleTurquoise);
                }
            }));

            return true;
        }
Beispiel #6
0
        public UsCmdExecResult Execute(UsCmd c)
        {
            try
            {
                eNetCmd cmd = c.ReadNetCmd();
                UsCmdHandler handler;
                if (!m_handlers.TryGetValue(cmd, out handler))
                {
                    return UsCmdExecResult.HandlerNotFound;
                }

                if (handler(cmd, c))
                {
                    return UsCmdExecResult.Succ;
                }
                else
                {
                    return UsCmdExecResult.Failed;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("[cmd] Execution failed. ({0})", ex.Message);
                return UsCmdExecResult.Failed;
            }
        }
Beispiel #7
0
 public static List<int> ReadIntList(UsCmd c)
 {
     List<int> ret = new List<int>();
     int count = c.ReadInt32 ();
     for (int i = 0; i < count; i++) {
         ret.Add(c.ReadInt32());
     }
     return ret;
 }
Beispiel #8
0
 bool NetHandle_StartAnalysePixels(eNetCmd cmd, UsCmd c)
 {
     int count = c.ReadInt32();
     for (int i = 0; i < count; ++i )
     {
         string msg = c.ReadString();
         UsLogging.Printf(msg);
     }
     return true;
 }
    private bool NetHandle_ExecCommand(eNetCmd cmd, UsCmd c)
    {
        string read = c.ReadString();
        bool ret = UsvConsole.Instance.ExecuteCommand(read);

        UsCmd reply = new UsCmd();
        reply.WriteNetCmd(eNetCmd.SV_ExecCommandResponse);
        reply.WriteInt32 (ret ? 1 : 0);
        UsNet.Instance.SendCommand(reply);
        return true;
    }
Beispiel #10
0
 public UsCmd CreatePacket()
 {
     UsCmd cmd = new UsCmd();
     cmd.WriteNetCmd(eNetCmd.SV_FrameDataV2);
     cmd.WriteInt32(_frameCount);
     cmd.WriteFloat(_frameDeltaTime);
     cmd.WriteFloat(_frameRealTime);
     cmd.WriteFloat(_frameStartTime);
     UsCmdUtil.WriteIntList(cmd, _frameMeshes);
     UsCmdUtil.WriteIntList(cmd, _frameMaterials);
     UsCmdUtil.WriteIntList(cmd, _frameTextures);
     return cmd;
 }
Beispiel #11
0
        private void requestStackDataInfo()
        {
            var selectNat = _selectedThing as NativeUnityEngineObject;

            if (selectNat == null)
            {
                return;
            }
            UsCmd cmd = new UsCmd();

            cmd.WriteInt16((short)eNetCmd.CL_RequestStackData);
            cmd.WriteInt32(selectNat.instanceID);
            cmd.WriteString(getRemoveDiffTypeStr(selectNat));
            NetManager.Instance.Send(cmd);
        }
    private bool NetHandle_QuerySwitches(eNetCmd cmd, UsCmd c)
    {
        UsCmd cmd1 = new UsCmd();

        cmd1.WriteNetCmd(eNetCmd.SV_QuerySwitchesResponse);
        cmd1.WriteInt32(GameInterface.ObjectNames.Count);
        foreach (KeyValuePair <string, string> objectName in GameInterface.ObjectNames)
        {
            cmd1.WriteString(objectName.Key);
            cmd1.WriteString(objectName.Value);
            cmd1.WriteInt16((short)1);
        }
        UsNet.Instance.SendCommand(cmd1);
        return(true);
    }
    private bool NetHandle_QuerySliders(eNetCmd cmd, UsCmd c)
    {
        UsCmd cmd1 = new UsCmd();

        cmd1.WriteNetCmd(eNetCmd.SV_QuerySlidersResponse);
        cmd1.WriteInt32(GameInterface.VisiblePercentages.Count);
        foreach (KeyValuePair <string, double> visiblePercentage in GameInterface.VisiblePercentages)
        {
            cmd1.WriteString(visiblePercentage.Key);
            cmd1.WriteFloat(0.0f);
            cmd1.WriteFloat(100f);
            cmd1.WriteFloat((float)visiblePercentage.Value);
        }
        UsNet.Instance.SendCommand(cmd1);
        return(true);
    }
Beispiel #14
0
        bool NetHandle_StressTestNames(eNetCmd cmd, UsCmd c)
        {
            var effects = new ObservableCollection<EffectObject>();
            int count = c.ReadInt32();
            for (int i = 0; i < count; i++)
            {
                var e = new EffectObject();
                e.Name = c.ReadString();
                effects.Add(e);
            }

            EffectGrid.Dispatcher.Invoke(new Action(() =>
            {
                EffectGrid.DataContext = effects;
            }));
            return true;
        }
Beispiel #15
0
        bool NetHandle_QuerySwitchesResponse(eNetCmd cmd, UsCmd c)
        {
            int count = c.ReadInt32();
            for (int i = 0; i < count; i++)
            {
                string name = c.ReadString();
                string path = c.ReadString();
                short initVal = c.ReadInt16();

                _switchersPanel.Dispatcher.Invoke(new Action(() =>
                {
                    AddSwitcher(name, path, initVal != 0);
                }));
            }

            return true;
        }
    private bool NetHandle_RequestFrameData(eNetCmd cmd, UsCmd c)
    {
        if (DataCollector.Instance == null)
        {
            return(true);
        }
        FrameData frameData = DataCollector.Instance.CollectFrameData();

        UsNet.Instance.SendCommand(frameData.CreatePacket());
        UsNet.Instance.SendCommand(DataCollector.Instance.CreateMaterialCmd());
        UsNet.Instance.SendCommand(DataCollector.Instance.CreateTextureCmd());
        UsCmd cmd1 = new UsCmd();

        cmd1.WriteNetCmd(eNetCmd.SV_FrameDataEnd);
        UsNet.Instance.SendCommand(cmd1);
        return(true);
    }
Beispiel #17
0
    private bool NetHandle_RequestFrameData(eNetCmd cmd, UsCmd c)
    {
        if (DataCollector.Instance == null)
        {
            return(true);
        }

        FrameData data = DataCollector.Instance.CollectFrameData();

        UsNet.Instance.SendCommand(data.CreatePacket());
        UsNet.Instance.SendCommand(DataCollector.Instance.CreateMaterialCmd());
        UsNet.Instance.SendCommand(DataCollector.Instance.CreateTextureCmd());

        //Debug.Log(string.Format("creating frame packet: id {0} mesh count {1}", eNetCmd.SV_FrameDataV2, data._frameMeshes.Count));

        return(true);
    }
Beispiel #18
0
        bool NetHandle_QuerySlidersResponse(eNetCmd cmd, UsCmd c)
        {
            int count = c.ReadInt32();
            for (int i = 0; i < count; i++)
            {
                string name = c.ReadString();
                float minVal = c.ReadFloat();
                float maxVal = c.ReadFloat();
                float initVal = c.ReadFloat();

                _slidersPanel.Dispatcher.Invoke(new Action(() =>
                {
                    AddSlider(name, minVal, maxVal, initVal);
                }));
            }

            return true;
        }
 private bool NetHandle_FrameV2_RequestNames(eNetCmd cmd, UsCmd c)
 {
     if (DataCollector.Instance != null)
     {
         foreach (List <int> intList in UsGeneric.Slice <int>(UsCmdUtil.ReadIntList(c), this.SLICE_COUNT))
         {
             UsCmd cmd1 = new UsCmd();
             cmd1.WriteNetCmd(eNetCmd.SV_FrameDataV2_Names);
             cmd1.WriteInt32(intList.Count);
             foreach (int instID in intList)
             {
                 DataCollector.Instance.WriteName(instID, cmd1);
             }
             UsNet.Instance.SendCommand(cmd1);
         }
     }
     return(true);
 }
Beispiel #20
0
        bool NetHandle_QuerySwitchesResponse(eNetCmd cmd, UsCmd c)
        {
            int count = c.ReadInt32();

            for (int i = 0; i < count; i++)
            {
                string name    = c.ReadString();
                string path    = c.ReadString();
                short  initVal = c.ReadInt16();

                _switchersPanel.Dispatcher.Invoke(new Action(() =>
                {
                    AddSwitcher(name, path, initVal != 0);
                }));
            }

            return(true);
        }
Beispiel #21
0
 public UsCmdExecResult ExecuteClient(string clientID, UsCmd c)
 {
     try
     {
         eNetCmd            eNetCmd = c.ReadNetCmd();
         UsClientCmdHandler clientCmdHandler;
         if (!this.m_clientHandlers.TryGetValue(eNetCmd, out clientCmdHandler))
         {
             return(UsCmdExecResult.HandlerNotFound);
         }
         return(clientCmdHandler(clientID, eNetCmd, c) ? UsCmdExecResult.Succ : UsCmdExecResult.Failed);
     }
     catch (Exception ex)
     {
         Console.WriteLine("[cmd] Execution failed. ({0})", (object)ex.Message);
         return(UsCmdExecResult.Failed);
     }
 }
    private bool NetHandle_QuerySwitches(eNetCmd cmd, UsCmd c)
    {
        UsCmd pkt = new UsCmd();

        pkt.WriteNetCmd(eNetCmd.SV_QuerySwitchesResponse);

        pkt.WriteInt32(GameInterface.ObjectNames.Count);
        foreach (var name in GameInterface.ObjectNames)
        {
            //Log.Info("{0} {1} switch added.", name.Key, name.Value);
            pkt.WriteString(name.Key);
            pkt.WriteString(name.Value);
            pkt.WriteInt16(1);
        }
        UsNet.Instance.SendCommand(pkt);

        return(true);
    }
Beispiel #23
0
        bool NetHandle_StressTestNames(eNetCmd cmd, UsCmd c)
        {
            var effects = new ObservableCollection <EffectObject>();
            int count   = c.ReadInt32();

            for (int i = 0; i < count; i++)
            {
                var e = new EffectObject();
                e.Name = c.ReadString();
                effects.Add(e);
            }

            EffectGrid.Dispatcher.Invoke(new Action(() =>
            {
                EffectGrid.DataContext = effects;
            }));
            return(true);
        }
 public void ExecuteCmd(string cmdText)
 {
     if (!this.IsConnected)
     {
         NetUtil.Log("not connected to server, command ignored.", (object[])Array.Empty <object>());
     }
     else if (cmdText.Length == 0)
     {
         NetUtil.Log("the command bar is empty, try 'help' to list all supported commands.", (object[])Array.Empty <object>());
     }
     else
     {
         UsCmd cmd = new UsCmd();
         cmd.WriteNetCmd(eNetCmd.CL_ExecCommand);
         cmd.WriteString(cmdText);
         this.Send(cmd);
         NetUtil.Log("command executed: [b]{0}[/b]", (object)cmdText);
     }
 }
    private bool NetHandle_QuerySliders(eNetCmd cmd, UsCmd c)
    {
        UsCmd pkt = new UsCmd();

        pkt.WriteNetCmd(eNetCmd.SV_QuerySlidersResponse);

        pkt.WriteInt32(GameInterface.VisiblePercentages.Count);
        foreach (var p in GameInterface.VisiblePercentages)
        {
            //Log.Info("{0} slider added.", p.Key);
            pkt.WriteString(p.Key);
            pkt.WriteFloat(0.0f);
            pkt.WriteFloat(100.0f);
            pkt.WriteFloat((float)p.Value);
        }
        UsNet.Instance.SendCommand(pkt);

        return(true);
    }
Beispiel #26
0
        bool NetHandle_QuerySlidersResponse(eNetCmd cmd, UsCmd c)
        {
            int count = c.ReadInt32();

            for (int i = 0; i < count; i++)
            {
                string name    = c.ReadString();
                float  minVal  = c.ReadFloat();
                float  maxVal  = c.ReadFloat();
                float  initVal = c.ReadFloat();

                _slidersPanel.Dispatcher.Invoke(new Action(() =>
                {
                    AddSlider(name, minVal, maxVal, initVal);
                }));
            }

            return(true);
        }
Beispiel #27
0
    public void OnSelectionChange()
    {
        _selectedIDs = Selection.instanceIDs;

        if (UsNet.Instance != null)
        {
            UsCmd cmd = new UsCmd();
            cmd.WriteNetCmd(eNetCmd.SV_Editor_SelectionChanged);
            cmd.WriteInt32(_selectedIDs.Length);
            //Debug.Log(string.Format("selection count: {0}", _selectedIDs.Length));
            foreach (int item in _selectedIDs)
            {
                cmd.WriteInt32(item);
            }
            UsNet.Instance.SendCommand(cmd);
        }

        Repaint();
    }
Beispiel #28
0
        public bool NetHandle_FrameDataV2(eNetCmd cmd, UsCmd c)
        {
            int   var = c.ReadInt32();
            float f1  = c.ReadFloat();

            f1 = c.ReadFloat();
            f1 = c.ReadFloat();
            var meshList     = UsCmdUtil.ReadIntList(c);
            var materialList = UsCmdUtil.ReadIntList(c);
            var textureList  = UsCmdUtil.ReadIntList(c);

            MeshGrid.Dispatcher.Invoke(new Action(() =>
            {
                if (MeshGrid.DataContext == null)
                {
                    MeshGrid.DataContext = new ObservableCollection <MeshObject>();
                }
                else
                {
                    ((ObservableCollection <MeshObject>)(MeshGrid.DataContext)).Clear();
                }
                title_mesh.Text = string.Format("Meshes ({0})", meshList.Count);
            }));

            {
                UsCmd req = new UsCmd();
                req.WriteNetCmd(eNetCmd.CL_FrameV2_RequestMeshes);
                UsCmdUtil.WriteIntList(req, meshList);
                NetManager.Instance.Send(req);
                UsLogging.Printf("eNetCmd.NetHandle_FrameDataV2 [b]({0} meshes expected)[/b].", meshList.Count);
            }

            {
                UsCmd req = new UsCmd();
                req.WriteNetCmd(eNetCmd.CL_FrameV2_RequestNames);
                UsCmdUtil.WriteIntList(req, meshList);
                NetManager.Instance.Send(req);
                UsLogging.Printf("eNetCmd.NetHandle_FrameDataV2 [b]({0} names expected)[/b].", meshList.Count);
            }

            return(true);
        }
    private bool NetHandle_FrameV2_RequestNames(eNetCmd cmd, UsCmd c)
    {
        if (usmooth.DataCollector.Instance != null)
        {
            List <int> instIDs = UsCmdUtil.ReadIntList(c);
            foreach (var slice in UsGeneric.Slice(instIDs, SLICE_COUNT))
            {
                UsCmd fragment = new UsCmd();
                fragment.WriteNetCmd(eNetCmd.SV_FrameDataV2_Names);
                fragment.WriteInt32(slice.Count);
                foreach (int instID in slice)
                {
                    usmooth.DataCollector.Instance.WriteName(instID, fragment);
                }
                UsNet.Instance.SendCommand(fragment);
            }
        }

        return(true);
    }
Beispiel #30
0
        private bool NetHandle_FrameDataV2_Meshes(eNetCmd cmd, UsCmd c)
        {
            MeshGrid.Dispatcher.Invoke(new Action(() =>
            {
                int count = c.ReadInt32();
                UsLogging.Printf("eNetCmd.NetHandle_FrameDataV2_Meshes [b]({0} got)[/b].", count);
                for (int i = 0; i < count; i++)
                {
                    var m     = new MeshObject();
                    m.InstID  = c.ReadInt32();
                    m.VertCnt = c.ReadInt32();
                    m.TriCnt  = c.ReadInt32();
                    m.MatCnt  = c.ReadInt32();
                    m.Size    = c.ReadFloat();
                    ((ObservableCollection <MeshObject>)(MeshGrid.DataContext)).Add(m);
                }
            }));

            return(true);
        }
    private bool NetHandle_FrameV2_RequestMeshes(eNetCmd cmd, UsCmd c)
    {
        if (usmooth.DataCollector.Instance != null)
        {
            List <int> meshIDs = UsCmdUtil.ReadIntList(c);
            //Debug.Log(string.Format("requesting meshes - count ({0})", meshIDs.Count));
            foreach (var slice in UsGeneric.Slice(meshIDs, SLICE_COUNT))
            {
                UsCmd fragment = new UsCmd();
                fragment.WriteNetCmd(eNetCmd.SV_FrameDataV2_Meshes);
                fragment.WriteInt32(slice.Count);
                foreach (int meshID in slice)
                {
                    usmooth.DataCollector.Instance.MeshTable.WriteMesh(meshID, fragment);
                }
                UsNet.Instance.SendCommand(fragment);
            }
        }

        return(true);
    }
Beispiel #32
0
    public bool NetHandle_RequestStackData(eNetCmd cmd, UsCmd c)
    {
        int    instID = c.ReadInt32();
        string str    = c.ReadString();

        Debug.Log((object)string.Format("NetHandle_RequestStackData instanceID={0} className={1}", (object)instID, (object)str));
        ResourceRequestInfo allocInfo = ResourceTracker.Instance.GetAllocInfo(instID);
        UsCmd cmd1 = new UsCmd();

        cmd1.WriteNetCmd(eNetCmd.SV_QueryStacksResponse);
        if (allocInfo == null)
        {
            cmd1.WriteString("<no_callstack_available>");
        }
        else
        {
            cmd1.WriteString(ResourceTracker.Instance.GetStackTrace(allocInfo));
        }
        UsNet.Instance.SendCommand(cmd1);
        return(true);
    }
Beispiel #33
0
        public bool NetHandle_FrameDataV2(eNetCmd cmd, UsCmd c)
        {
            int var = c.ReadInt32();
            float f1 = c.ReadFloat();
            f1 = c.ReadFloat();
            f1 = c.ReadFloat();
            var meshList = UsCmdUtil.ReadIntList(c);
            var materialList = UsCmdUtil.ReadIntList(c);
            var textureList = UsCmdUtil.ReadIntList(c);

            MeshGrid.Dispatcher.Invoke(new Action(() =>
            {
                if (MeshGrid.DataContext == null)
                {
                    MeshGrid.DataContext = new ObservableCollection<MeshObject>();
                }
                else
                {
                    ((ObservableCollection<MeshObject>)(MeshGrid.DataContext)).Clear();
                }
            }));

            {
                UsCmd req = new UsCmd();
                req.WriteNetCmd(eNetCmd.CL_FrameV2_RequestMeshes);
                UsCmdUtil.WriteIntList(req, meshList);
                NetManager.Instance.Send(req);
                UsLogging.Printf("eNetCmd.NetHandle_FrameDataV2 [b]({0} meshes expected)[/b].", meshList.Count);
            }

            {
                UsCmd req = new UsCmd();
                req.WriteNetCmd(eNetCmd.CL_FrameV2_RequestNames);
                UsCmdUtil.WriteIntList(req, meshList);
                NetManager.Instance.Send(req);
                UsLogging.Printf("eNetCmd.NetHandle_FrameDataV2 [b]({0} names expected)[/b].", meshList.Count);
            }

            return true;
        }
Beispiel #34
0
    public void Tick_ReceivingData()
    {
        try
        {
            while (_tcpClient.Available > 0)
            {
                byte[] cmdLenBuf  = new byte[2];
                int    cmdLenRead = _tcpClient.GetStream().Read(cmdLenBuf, 0, cmdLenBuf.Length);
                ushort cmdLen     = BitConverter.ToUInt16(cmdLenBuf, 0);
                if (cmdLenRead > 0 && cmdLen > 0)
                {
                    byte[] buffer = new byte[cmdLen];
                    int    len    = _tcpClient.GetStream().Read(buffer, 0, buffer.Length);

                    UsCmd           cmd    = new UsCmd(buffer);
                    UsCmdExecResult result = _cmdParser.Execute(cmd);
                    switch (result)
                    {
                    case UsCmdExecResult.Succ:
                        break;

                    case UsCmdExecResult.Failed:
                        NetUtil.Log("net cmd execution failed: {0}.", new UsCmd(buffer).ReadNetCmd());
                        break;

                    case UsCmdExecResult.HandlerNotFound:
                        NetUtil.Log("net unknown cmd: {0}.", new UsCmd(buffer).ReadNetCmd());
                        break;
                    }

                    len++; // warning CS0219: The variable `len' is assigned but its value is never used
                }
            }
        }
        catch (Exception ex)
        {
            DisconnectOnError("error detected while receiving data.", ex);
        }
    }
Beispiel #35
0
    public static void OnMessage(string data)
    {
        Debug.Assert(Instance != null);
        if (Instance == null)
        {
            return;
        }

        Debug.Assert(!string.IsNullOrEmpty(data));
        if (string.IsNullOrEmpty(data))
        {
            return;
        }

        if (Instance._networkAvailable)
        {
            UsCmd cmd = new UsCmd();
            cmd.WriteInt16((short)eNetCmd.SV_SendLuaProfilerMsg);
            cmd.WriteString(data);
            UsNet.Instance.SendCommand(cmd);
        }
    }
Beispiel #36
0
        public void ExecuteCmd(string cmdText)
        {
            if (!IsConnected)
            {
                UsLogging.Printf(LogWndOpt.Bold, "not connected to server, command ignored.");
                return;
            }

            if (cmdText.Length == 0)
            {
                UsLogging.Printf(LogWndOpt.Bold, "the command bar is empty, try 'help' to list all supported commands.");
                return;
            }

            UsCmd cmd = new UsCmd();

            cmd.WriteNetCmd(eNetCmd.CL_ExecCommand);
            cmd.WriteString(cmdText);
            Send(cmd);

            UsLogging.Printf(string.Format("command executed: [b]{0}[/b]", cmdText));
        }
Beispiel #37
0
        public UsCmd CreateMaterialCmd()
        {
            UsCmd cmd = new UsCmd();

            cmd.WriteNetCmd(eNetCmd.SV_FrameData_Material);
            cmd.WriteInt32(VisibleMaterials.Count);

            foreach (KeyValuePair <Material, HashSet <GameObject> > kv in VisibleMaterials)
            {
                //Debug.Log (string.Format("current_material: {0} - {1} - {2}", kv.Key.GetInstanceID(), kv.Key.name.Length, kv.Key.name));
                cmd.WriteInt32(kv.Key.GetInstanceID());
                cmd.WriteStringStripped(kv.Key.name);
                cmd.WriteStringStripped(kv.Key.shader.name);

                cmd.WriteInt32(kv.Value.Count);
                foreach (var item in kv.Value)
                {
                    cmd.WriteInt32(item.GetInstanceID());
                }
            }
            return(cmd);
        }
Beispiel #38
0
    public void ExecuteCmd(string cmdText)
    {
        if (!IsConnected)
        {
            NetUtil.Log("not connected to server, command ignored.");
            return;
        }

        if (cmdText.Length == 0)
        {
            NetUtil.Log("the command bar is empty, try 'help' to list all supported commands.");
            return;
        }

        UsCmd cmd = new UsCmd();

        cmd.WriteNetCmd(eNetCmd.CL_ExecCommand);
        cmd.WriteString(cmdText);
        Send(cmd);

        NetUtil.Log("command executed: [b]{0}[/b]", cmdText);
    }
Beispiel #39
0
        private void ExecInputCmd()
        {
            if (!AppNetManager.Instance.IsConnected)
            {
                UsLogging.Printf(LogWndOpt.Bold, "not connected to server, command ignored.");
                return;
            }

            if (tb_cmdbox.Text.Length == 0)
            {
                UsLogging.Printf(LogWndOpt.Bold, "the command bar is empty, try 'help' to list all supported commands.");
                return;
            }

            UsCmd cmd = new UsCmd();

            cmd.WriteNetCmd(eNetCmd.CL_ExecCommand);
            cmd.WriteString(tb_cmdbox.Text);
            AppNetManager.Instance.Send(cmd);

            UsLogging.Printf(string.Format("command executed: [b]{0}[/b]", tb_cmdbox.Text));
            tb_cmdbox.Clear();
        }
    public bool NetHandle_RequestStackData(eNetCmd cmd, UsCmd c)
    {
        int    instanceID = c.ReadInt32();
        string className  = c.ReadString();

        UnityEngine.Debug.Log(string.Format("NetHandle_RequestStackData instanceID={0} className={1}", instanceID, className));

        ResourceRequestInfo requestInfo = ResourceTracker.Instance.GetAllocInfo(instanceID);

        UsCmd pkt = new UsCmd();

        pkt.WriteNetCmd(eNetCmd.SV_QueryStacksResponse);
        if (requestInfo == null)
        {
            pkt.WriteString("<no_callstack_available>");
        }
        else
        {
            pkt.WriteString(ResourceTracker.Instance.GetStackTrace(requestInfo));
        }
        UsNet.Instance.SendCommand(pkt);
        return(true);
    }
Beispiel #41
0
        public UsCmd CreateTextureCmd()
        {
            UsCmd cmd = new UsCmd();

            cmd.WriteNetCmd(eNetCmd.SV_FrameData_Texture);
            cmd.WriteInt32(VisibleTextures.Count);

            foreach (KeyValuePair <Texture, HashSet <Material> > kv in VisibleTextures)
            {
                cmd.WriteInt32(kv.Key.GetInstanceID());
                cmd.WriteStringStripped(kv.Key.name);
                cmd.WriteString(string.Format("{0}x{1}", kv.Key.width, kv.Key.height));
                cmd.WriteString(UsTextureUtil.FormatSizeString(_textureSizeLut[kv.Key] / 1024));

                cmd.WriteInt32(kv.Value.Count);
                foreach (var item in kv.Value)
                {
                    cmd.WriteInt32(item.GetInstanceID());
                }
            }

            return(cmd);
        }
Beispiel #42
0
        bool NetHandle_StressTestResult(eNetCmd cmd, UsCmd c)
        {
            string name     = c.ReadString();
            int    avgMS    = c.ReadInt32();
            int    maxMS    = c.ReadInt32();
            int    drawcall = c.ReadInt32();
            int    parCount = c.ReadInt32();

            EffectGrid.Dispatcher.Invoke(new Action(() =>
            {
                foreach (var item in EffectGrid.Items)
                {
                    EffectObject mo = item as EffectObject;
                    if (mo != null && mo.Name == name)
                    {
                        if (_highlighted != null)
                        {
                            DataGridUtil.ClearHighlighted(EffectGrid, _highlighted);
                        }

                        mo.MSAvg          = avgMS;
                        mo.MSMax          = maxMS;
                        mo.DrawCallCount  = drawcall;
                        mo.TotalParticles = parCount;

                        DataGridUtil.MarkAsHighlighted(EffectGrid, item, Colors.Chartreuse);
                        _highlighted = mo;

                        break;
                    }
                }
            }));

            RunNextEffectStressTest();

            return(true);
        }
Beispiel #43
0
        private void Tick()
        {
            _currentTimeInMilliseconds = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;

            if (_currentTimeInMilliseconds - _lastKeepAlive > INTERVAL_KeepAlive)
            {
                UsCmd cmd = new UsCmd();
                cmd.WriteNetCmd(eNetCmd.CL_KeepAlive);
                _client.SendPacket(cmd);
                _lastKeepAlive = _currentTimeInMilliseconds;
            }

            if (_currentTimeInMilliseconds - _lastCheckingConnectionStatus > INTERVAL_CheckingConnectionStatus)
            {
                _client.Tick_CheckConnectionStatus();
                _lastCheckingConnectionStatus = _currentTimeInMilliseconds;
            }

            if (_currentTimeInMilliseconds - _lastReceivingData > INTERVAL_ReceivingData)
            {
                _client.Tick_ReceivingData();
                _lastReceivingData = _currentTimeInMilliseconds;
            }
        }
 public void Send(UsCmd cmd)
 {
     this._client.SendPacket(cmd);
 }
Beispiel #45
0
    public UsCmd CreateMaterialCmd()
    {
        UsCmd cmd = new UsCmd();
        cmd.WriteNetCmd(eNetCmd.SV_FrameData_Material);
        cmd.WriteInt32 (VisibleMaterials.Count);

        foreach (KeyValuePair<Material, HashSet<GameObject>> kv in VisibleMaterials) {
            //Debug.Log (string.Format("current_material: {0} - {1} - {2}", kv.Key.GetInstanceID(), kv.Key.name.Length, kv.Key.name));
            cmd.WriteInt32 (kv.Key.GetInstanceID());
            cmd.WriteStringStripped (kv.Key.name);
            cmd.WriteStringStripped (kv.Key.shader.name);

            cmd.WriteInt32 (kv.Value.Count);
            foreach (var item in kv.Value) {
                cmd.WriteInt32 (item.GetInstanceID());
            }
        }
        return cmd;
    }
Beispiel #46
0
        bool NetHandle_StressTestResult(eNetCmd cmd, UsCmd c)
        {
            string name = c.ReadString();
            int avgMS = c.ReadInt32();
            int maxMS = c.ReadInt32();
            int drawcall = c.ReadInt32();
            int parCount = c.ReadInt32();

            EffectGrid.Dispatcher.Invoke(new Action(() =>
            {
                foreach (var item in EffectGrid.Items)
                {
                    EffectObject mo = item as EffectObject;
                    if (mo != null && mo.Name == name)
                    {
                        if (_highlighted != null)
                        {
                            DataGridUtil.ClearHighlighted(EffectGrid, _highlighted);
                        }

                        mo.MSAvg = avgMS;
                        mo.MSMax = maxMS;
                        mo.DrawCallCount = drawcall;
                        mo.TotalParticles = parCount;

                        DataGridUtil.MarkAsHighlighted(EffectGrid, item, Colors.Chartreuse);
                        _highlighted = mo;

                        break;
                    }
                }
            }));

            RunNextEffectStressTest();

            return true;
        }
Beispiel #47
0
    public UsCmd CreateTextureCmd()
    {
        UsCmd cmd = new UsCmd();
        cmd.WriteNetCmd(eNetCmd.SV_FrameData_Texture);
        cmd.WriteInt32 (VisibleTextures.Count);

        foreach (KeyValuePair<Texture, HashSet<Material>> kv in VisibleTextures) {
            cmd.WriteInt32 (kv.Key.GetInstanceID());
            cmd.WriteStringStripped (kv.Key.name);
            cmd.WriteString (string.Format("{0}x{1}", kv.Key.width, kv.Key.height));
            cmd.WriteString (UsTextureUtil.FormatSizeString(_textureSizeLut[kv.Key] / 1024));

            cmd.WriteInt32 (kv.Value.Count);
            foreach (var item in kv.Value) {
                cmd.WriteInt32 (item.GetInstanceID());
            }
        }

        return cmd;
    }
Beispiel #48
0
        public void ExecuteCmd(string cmdText)
        {
            if (!IsConnected)
            {
                UsLogging.Printf(LogWndOpt.Bold, "not connected to server, command ignored.");
                return;
            }

            if (cmdText.Length == 0)
            {
                UsLogging.Printf(LogWndOpt.Bold, "the command bar is empty, try 'help' to list all supported commands.");
                return;
            }

            UsCmd cmd = new UsCmd();
            cmd.WriteNetCmd(eNetCmd.CL_ExecCommand);
            cmd.WriteString(cmdText);
            Send(cmd);

            UsLogging.Printf(string.Format("command executed: [b]{0}[/b]", cmdText));
        }
Beispiel #49
0
    public void OnSelectionChange()
    {
        _selectedIDs = Selection.instanceIDs;

        if (UsNet.Instance != null) {
            UsCmd cmd = new UsCmd();
            cmd.WriteNetCmd(eNetCmd.SV_Editor_SelectionChanged);
            cmd.WriteInt32 (_selectedIDs.Length);
            //Debug.Log(string.Format("selection count: {0}", _selectedIDs.Length));
            foreach (int item in _selectedIDs) {
                cmd.WriteInt32 (item);
            }
            UsNet.Instance.SendCommand(cmd);
        }

        Repaint ();
    }
Beispiel #50
0
        private bool Handle_ExecCommandResponse(eNetCmd cmd, UsCmd c)
        {
            int code = c.ReadInt32();
            UsLogging.Printf(string.Format("command executing result: [b]{0}[/b]", code));

            return true;
        }
Beispiel #51
0
 private bool Handle_ServerLogging(eNetCmd cmd, UsCmd c)
 {
     UsLogPacket pkt = new UsLogPacket(c);
     UsNetLogging.Print(pkt);
     return true;
 }
Beispiel #52
0
        private void Tick()
        {
            if (!_client.IsConnected)
                return;

            _currentTimeInMilliseconds = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;

            if (_currentTimeInMilliseconds - _lastKeepAlive > INTERVAL_KeepAlive)
            {
                UsCmd cmd = new UsCmd();
                cmd.WriteNetCmd(eNetCmd.CL_KeepAlive);
                _client.SendPacket(cmd);
                _lastKeepAlive = _currentTimeInMilliseconds;
            }

            if (_currentTimeInMilliseconds - _lastCheckingConnectionStatus > INTERVAL_CheckingConnectionStatus)
            {
                _client.Tick_CheckConnectionStatus();
                _lastCheckingConnectionStatus = _currentTimeInMilliseconds;
            }

            if (_currentTimeInMilliseconds - _lastReceivingData > INTERVAL_ReceivingData)
            {
                _client.Tick_ReceivingData();
                _lastReceivingData = _currentTimeInMilliseconds;
            }
        }
Beispiel #53
0
 private bool Handle_KeepAliveResponse(eNetCmd cmd, UsCmd c)
 {
     //UsLogging.Printf("'KeepAlive' received.");
     return true;
 }
Beispiel #54
0
 public void WriteName(int instID, UsCmd cmd)
 {
     string data;
     if (_nameLut.TryGetValue(instID, out data)) {
         cmd.WriteInt32 (instID);
         cmd.WriteStringStripped (data);
     }
 }
Beispiel #55
0
 public void SendPacket(UsCmd cmd)
 {
     try
     {
         byte[] cmdLenBytes = BitConverter.GetBytes((ushort)cmd.WrittenLen);
         _tcpClient.GetStream().Write(cmdLenBytes, 0, cmdLenBytes.Length);
         _tcpClient.GetStream().Write(cmd.Buffer, 0, cmd.WrittenLen);
     }
     catch (Exception ex)
     {
         DisconnectOnError("error detected while sending data.", ex);
     }
 }
Beispiel #56
0
 public void Write(UsCmd cmd)
 {
     cmd.WriteInt32(_instID);
     cmd.WriteInt32(_vertCount);
     cmd.WriteInt32(_triCount);
     cmd.WriteInt32(_materialCount);
     cmd.WriteFloat(_boundSize);
 }
Beispiel #57
0
        private void OnConnected(object sender, EventArgs e)
        {
            UsCmd cmd = new UsCmd();
            cmd.WriteInt16((short)eNetCmd.CL_Handshake);
            cmd.WriteInt16(Properties.Settings.Default.VersionMajor);
            cmd.WriteInt16(Properties.Settings.Default.VersionMinor);
            cmd.WriteInt16(Properties.Settings.Default.VersionPatch);
            _client.SendPacket(cmd);

            _tickTimer.Start();
            _guardTimer.Activate();
        }
Beispiel #58
0
 public void Send(UsCmd cmd)
 {
     _client.SendPacket(cmd);
 }
Beispiel #59
0
        private bool Handle_HandshakeResponse(eNetCmd cmd, UsCmd c)
        {
            UsLogging.Printf("eNetCmd.SV_HandshakeResponse received, connection validated.");

            SysPost.InvokeMulticast(this, LogicallyConnected);

            _guardTimer.Deactivate();
            return true;
        }
Beispiel #60
0
        public void Tick_ReceivingData()
        {
            try
            {
                while (_tcpClient.Available > 0)
                {
                    byte[] cmdLenBuf = new byte[2];
                    int cmdLenRead = _tcpClient.GetStream().Read(cmdLenBuf, 0, cmdLenBuf.Length);
                    ushort cmdLen = BitConverter.ToUInt16(cmdLenBuf, 0);
                    if (cmdLenRead > 0 && cmdLen > 0)
                    {
                        byte[] buffer = new byte[cmdLen];
                        int len = _tcpClient.GetStream().Read(buffer, 0, buffer.Length);

                        UsCmd cmd = new UsCmd(buffer);
                        UsCmdExecResult result = _cmdParser.Execute(cmd);
                        switch (result)
                        {
                            case UsCmdExecResult.Succ:
                                break;
                            case UsCmdExecResult.Failed:
                                UsLogging.Printf("net cmd execution failed: {0}.", new UsCmd(buffer).ReadNetCmd());
                                break;
                            case UsCmdExecResult.HandlerNotFound:
                                UsLogging.Printf("net unknown cmd: {0}.", new UsCmd(buffer).ReadNetCmd());
                                break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                DisconnectOnError("error detected while receiving data.", ex);
            }
        }