Esempio n. 1
0
        public bool NetHandle_FrameData_Material(eNetCmd cmd, UsCmd c)
        {
            UsLogging.Printf("eNetCmd.Handle_FrameData_Material received ({0}).", c.Buffer.Length);

            var materials = new ObservableCollection <MaterialObject>();
            int count     = c.ReadInt32();

            for (int i = 0; i < count; i++)
            {
                var m = new MaterialObject();
                m.InstID     = c.ReadInt32();
                m.Name       = c.ReadString();
                m.ShaderName = c.ReadString();
                m.RefCnt     = c.ReadInt32();

                m.RefList = new List <int>();
                for (int k = 0; k < m.RefCnt; k++)
                {
                    int owner = c.ReadInt32();
                    m.RefList.Add(owner);
                }

                materials.Add(m);
            }

            MaterialGrid.Dispatcher.Invoke(new Action(() =>
            {
                title_material.Text      = string.Format("Materials ({0})", materials.Count);
                MaterialGrid.DataContext = materials;
            }));
            return(true);
        }
Esempio n. 2
0
        public bool NetHandle_FrameData_Texture(eNetCmd cmd, UsCmd c)
        {
            UsLogging.Printf("eNetCmd.Handle_FrameData_Texture received ({0}).", c.Buffer.Length);

            var textures = new ObservableCollection <TextureObject>();
            int count    = c.ReadInt32();

            for (int i = 0; i < count; i++)
            {
                var m = new TextureObject();
                m.InstID    = c.ReadInt32();
                m.Name      = c.ReadString();
                m.PixelSize = c.ReadString();
                m.MemSize   = c.ReadString();
                m.RefCnt    = c.ReadInt32();
                m.RefList   = new List <int>();
                for (int k = 0; k < m.RefCnt; k++)
                {
                    int owner = c.ReadInt32();
                    m.RefList.Add(owner);
                }

                textures.Add(m);
            }

            TextureGrid.Dispatcher.Invoke(new Action(() =>
            {
                title_texture.Text      = string.Format("Textures ({0})", textures.Count);
                TextureGrid.DataContext = textures;
            }));
            return(true);
        }
Esempio n. 3
0
        private 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);
        }
Esempio n. 4
0
        public bool NetHandle_FrameDataV2_Names(eNetCmd cmd, UsCmd c)
        {
            MeshGrid.Dispatcher.Invoke(new Action(() =>
            {
                int count = c.ReadInt32();
                UsLogging.Printf("eNetCmd.NetHandle_FrameDataV2_Names [b]({0} got)[/b].", count);
                for (int i = 0; i < count; i++)
                {
                    int instID      = c.ReadInt32();
                    string instName = c.ReadString();
                    foreach (var item in MeshGrid.Items)
                    {
                        MeshObject mo = item as MeshObject;
                        if (mo != null && mo.InstID == instID)
                        {
                            mo.Name = instName;
                        }
                    }
                }

                MeshGrid.Items.Refresh();
            }));

            return(true);
        }
Esempio n. 5
0
        public Home()
        {
            if (NetManager.Instance == null)
            {
                throw new Exception();
            }

            InitializeComponent();

            // refresh recent target IP list
            cb_targetIP.Items.Add(Properties.Settings.Default.LocalAddr);
            if (Properties.Settings.Default.RecentAddrList != null)
            {
                foreach (var item in Properties.Settings.Default.RecentAddrList)
                {
                    cb_targetIP.Items.Add(item);
                }
            }
            cb_targetIP.SelectedItem = cb_targetIP.Items[0];

            bb_logging.BBCode = string.Empty;

            cb_logLevel.ItemsSource           = Enum.GetValues(typeof(UsNetLogging.eLogLevel)).Cast <UsNetLogging.eLogLevel>();
            cb_logLevel.SelectedItem          = UsNetLogging.s_logLevel;
            cb_logCallstackLevel.ItemsSource  = Enum.GetValues(typeof(UsNetLogging.eLogCallstackLevel)).Cast <UsNetLogging.eLogCallstackLevel>();
            cb_logCallstackLevel.SelectedItem = UsNetLogging.s_logCallstackLevel;

            UsLogging.Receivers += Impl_PrintLogToWnd;
            UsLogging.Printf("usmooth is initialized successfully.");

            RegisterNetHandlers();
        }
Esempio n. 6
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);
                }
            }));
        }
Esempio n. 7
0
        public Home()
        {
            if (AppNetManager.Instance == null)
            {
                throw new Exception();
            }

            InitializeComponent();

            // refresh recent target IP list
            cb_targetIP.Items.Add(Properties.Settings.Default.LocalAddr);
            if (Properties.Settings.Default.RecentAddrList != null)
            {
                foreach (var item in Properties.Settings.Default.RecentAddrList)
                {
                    cb_targetIP.Items.Add(item);
                }
            }
            cb_targetIP.SelectedItem = cb_targetIP.Items[0];

            bb_logging.BBCode = string.Empty;

            UsLogging.Receivers += Impl_PrintLogToWnd;
            UsLogging.Printf("usmooth is initialized successfully.");

            AppNetManager.Instance.LogicallyConnected    += OnLogicallyConnected;
            AppNetManager.Instance.LogicallyDisconnected += OnLogicallyDisconnected;
        }
Esempio n. 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);
        }
Esempio n. 9
0
        public void OnNavigatedTo(NavigationEventArgs e)
        {
            if (!NetManager.Instance.IsConnected)
            {
                if (ModernDialog.ShowMessage("usmooth is [b]offline[/b], connect to a running game first.", "offline", MessageBoxButton.OK) == MessageBoxResult.OK)
                {
                    UsLogging.Printf("trying to enter the '[b]realtime[/b]' page when usmooth is [b]offline[/b], back to the main page.");

                    DefaultLinkNavigator dln = new DefaultLinkNavigator();
                    dln.Navigate(new Uri("/Pages/Home.xaml", UriKind.Relative), this);
                    return;
                }
            }

            NetRequest_FrameData();
        }
Esempio n. 10
0
        private void OnLogicallyConnected(object sender, EventArgs e)
        {
            this.Dispatcher.Invoke(new Action(() =>
            {
                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);
                }
            }));
        }
Esempio n. 11
0
        private void bt_connect_Click(object sender, RoutedEventArgs e)
        {
            if (AppNetManager.Instance == null)
            {
                UsLogging.Printf(LogWndOpt.Bold, "NetManager not available, connecting failed.");
                return;
            }

            if (!AppNetManager.Instance.Connect(cb_targetIP.Text))
            {
                UsLogging.Printf(LogWndOpt.Bold, "connecting failed.");
                return;
            }

            // temporarily disable all connection buttons to prevent double submitting
            bt_connect.IsEnabled    = false;
            bt_disconnect.IsEnabled = false;
        }
Esempio n. 12
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);
        }
Esempio n. 13
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);
        }
Esempio n. 14
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();
        }
Esempio n. 15
0
        private bool NetHandle_FrameData_Mesh(eNetCmd cmd, UsCmd c)
        {
            short subCmd = c.ReadInt16();

            switch ((eSubCmd_TransmitStage)subCmd)
            {
            case eSubCmd_TransmitStage.DataBegin:
            {
                MeshGrid.Dispatcher.Invoke(new Action(() =>
                    {
                        if (_meshes == null)
                        {
                            _meshes = new ObservableCollection <MeshObject>();
                        }
                        else
                        {
                            _meshes.Clear();
                        }
                        _meshExpectedCount = c.ReadInt32();
                        UsLogging.Printf("eNetCmd.NetHandle_FrameData_Mesh [b](DataBegin)[/b] ({0}).", _meshExpectedCount);
                    }));
            }
            break;

            case eSubCmd_TransmitStage.DataSlice:
            {
                int count = c.ReadInt32();
                UsLogging.Printf("eNetCmd.NetHandle_FrameData_Mesh [b](DataSlice)[/b] ({0}).", count);
                if (count > 0)
                {
                    MeshGrid.Dispatcher.Invoke(new Action(() =>
                        {
                            for (int i = 0; i < count; i++)
                            {
                                var m     = new MeshObject();
                                m.InstID  = c.ReadInt32();
                                m.Name    = c.ReadString();
                                m.VertCnt = c.ReadInt32();
                                m.MatCnt  = c.ReadInt32();
                                m.Size    = (float)c.ReadFloat();
                                _meshes.Add(m);
                            }
                        }));
                }
            }
            break;

            case eSubCmd_TransmitStage.DataEnd:
            {
                UsLogging.Printf("eNetCmd.NetHandle_FrameData_Mesh [b](DataEnd)[/b] (expected: {0} actual: {1}).", _meshExpectedCount, _meshes.Count);
                if (_meshExpectedCount != _meshes.Count)
                {
                    UsLogging.Printf(LogWndOpt.Bold, "The actually received mesh count is mismatched with expected.");
                }

                MeshGrid.Dispatcher.Invoke(new Action(() =>
                    {
                        title_mesh.Text      = string.Format("Meshes ({0})", _meshes.Count);
                        MeshGrid.DataContext = _meshes;
                    }));
            }
            break;

            default:
                break;
            }
            return(true);
        }
Esempio n. 16
0
 private void bt_disconnect_Click(object sender, RoutedEventArgs e)
 {
     UsLogging.Printf(LogWndOpt.Error, "[b]disconnecting manually...[/b]");
     NetManager.Instance.Disconnect();
 }