//Separate thread private void Objects_OnNewPrim(object sender, PrimEventArgs e) { //if (!this.IsHandleCreated) return; if (e.Simulator.Handle != client.Network.CurrentSim.Handle || e.Prim.Position == Vector3.Zero || e.Prim is Avatar) return; try { if (e.Prim.ParentID != 0) { lock (childItems) { ObjectsListItem citem = new ObjectsListItem(e.Prim, client, lbxChildren); if (!childItems.ContainsKey(e.Prim.LocalID)) { try { childItems.Add(e.Prim.LocalID, citem); } catch { ; } } } } else { BeginInvoke(new MethodInvoker(delegate() { lock (listItems) { ObjectsListItem item = new ObjectsListItem(e.Prim, client, lbxPrims); Vector3 location = new Vector3(Vector3.Zero); location = instance.SIMsittingPos(); Vector3 pos = new Vector3(Vector3.Zero); pos = item.Prim.Position; float dist = Vector3.Distance(location, pos); if (dist < range) { try { if (!listItems.ContainsKey(e.Prim.LocalID)) { listItems.Add(e.Prim.LocalID, item); item.PropertiesReceived += new EventHandler(iitem_PropertiesReceived); item.RequestProperties(); } //else //{ // listItems.Remove(e.Prim.LocalID); // listItems.Add(e.Prim.LocalID, item); // lock (lbxPrims.Items) // { // lbxPrims.BeginUpdate(); // if (lbxPrims.Items.Contains(item)) // { // lbxPrims.Items.Remove(item); // } // lbxPrims.Items.Add(item); // lbxPrims.EndUpdate(); // } // lbxPrims.SortList(); //} } catch { ; } //BeginInvoke(new MethodInvoker(delegate() //{ // pB1.Maximum += 1; //})); } } })); } } catch { ; } }
//private void DisplayObjects() //{ // if (eventsremoved) AddObjectEvents(); // lbxPrims.Items.Clear(); // try // { // Vector3 location = instance.SIMsittingPos(); // pBar3.Visible = true; // pB1.Visible = true; // pB1.Value = 0; // pB1.Maximum = ItemsProps.Count; // lock (ItemsProps) // { // //Vector3 location = instance.SIMsittingPos(); // foreach (KeyValuePair<uint, ObjectsListItem> entry in ItemsProps) // { // ObjectsListItem item = entry.Value; // if (item.Prim.ParentID == 0) //root prims only // { // Vector3 pos = item.Prim.Position; // if (Vector3.Distance(location,pos) < range) // { // lock (lbxPrims.Items) // { // lbxPrims.BeginUpdate(); // lbxPrims.Items.Add(item); // lbxPrims.EndUpdate(); // } // } // } // if (pB1.Value < ItemsProps.Count) pB1.Value += 1; // } // } // pB1.Visible = false; // pBar3.Visible = false; // //lblStatus.Visible = true; // //lbxPrims.SortList(); // //lblStatus.Visible = false; // //lbxPrims.Visible = true; // //lbxChildren.Visible = true; // txtSearch.Enabled = true; // //tlbStatus.Text = listItems.Count.ToString() + " objects"; // tlbDisplay.Text = lbxPrims.Items.Count.ToString(CultureInfo.CurrentCulture) + " objects"; // } // catch (Exception ex) // { // //string exp = exc.Message; // reporter.Show(ex); // } //} private void SearchFor(string text) { RemoveObjectEvents(); lbxPrims.Items.Clear(); pB1.Visible = true; string query = text.ToLower(CultureInfo.CurrentCulture); //bool inmem = false; List<Primitive> results = client.Network.CurrentSim.ObjectsPrimitives.FindAll( new Predicate<Primitive>(delegate(Primitive prim) { try { //evil comparison of death! return (prim.ParentID == 0 && prim.Properties != null) && (prim.Properties.Name.ToLower(CultureInfo.CurrentCulture).Contains(query) || prim.Properties.Description.ToLower(CultureInfo.CurrentCulture).Contains(query) || prim.Properties.OwnerID.ToString().ToLower(CultureInfo.CurrentCulture).Contains(query) || prim.Text.ToLower(CultureInfo.CurrentCulture).Contains(query) || prim.ID.ToString().ToLower(CultureInfo.CurrentCulture).Contains(query) || prim.Properties.CreatorID.ToString().ToLower(CultureInfo.CurrentCulture).Contains(query)); } catch { return false; } })); pB1.Maximum = results.Count; lock (listItems) { foreach (Primitive prim in results) { try { ObjectsListItem item = new ObjectsListItem(prim, client, lbxPrims); if (!listItems.ContainsKey(prim.LocalID)) { listItems.Add(prim.LocalID, item); item.PropertiesReceived += new EventHandler(item_PropertiesReceived); item.RequestProperties(); //inmem = true; } else { if (pB1.Value < results.Count) pB1.Value += 1; lock (lbxPrims.Items) { lbxPrims.BeginUpdate(); lbxPrims.Items.Remove(item); lbxPrims.Items.Add(item); lbxPrims.EndUpdate(); } } } catch { ; } } } //if (!inmem) //{ pB1.Value = 0; pB1.Visible = false; lbxPrims.SortList(); //} //tlbStatus.Text = listItems.Count.ToString() + " objects"; tlbDisplay.Text = lbxPrims.Items.Count.ToString(CultureInfo.CurrentCulture) + " objects"; }
private void AddAllObjects() { if (InvokeRequired) { BeginInvoke(new MethodInvoker(delegate() { AddAllObjects(); })); } //pB1.Maximum = 0; if (eventsremoved) AddObjectEvents(); Cursor.Current = Cursors.WaitCursor; pB1.Visible = true; //bool inmem = false; lbxPrims.location = instance.SIMsittingPos(); lbxPrims.SortByName = false; //pBar3.Visible = true; //lbxPrims.SortList(); //pBar3.Visible = false; //int ocnt = 1; try { lock (listItems) { Vector3 location = new Vector3(Vector3.Zero); location = instance.SIMsittingPos(); client.Network.CurrentSim.ObjectsPrimitives.ForEach( new Action<Primitive>( delegate(Primitive prim) { Vector3 pos = new Vector3(Vector3.Zero); pos = prim.Position; float dist = Vector3.Distance(location, pos); //// Work around for the Magnum problem //if (ocnt < 4) //{ // //instance.State.SetPointing(true, prim.ID); // //instance.State.SetPointing(false, prim.ID); // Vector3 target = new Vector3(Vector3.Zero); // target = prim.Position; // the object to look at // client.Self.Movement.TurnToward(target); // ocnt += 1; //} if (((int)dist < (int)range) && (prim.Position != Vector3.Zero)) { ObjectsListItem item = new ObjectsListItem(prim, client, lbxPrims); if (prim.ParentID == 0) //root prims only { if (!listItems.ContainsKey(prim.LocalID)) { lock (listItems) { listItems.Add(prim.LocalID, item); item.PropertiesReceived += new EventHandler(iitem_PropertiesReceived); item.RequestProperties(); //inmem = true; } //pB1.Maximum += 1; } else { lock (listItems) { listItems.Remove(prim.LocalID); listItems.Add(prim.LocalID, item); lock (lbxPrims.Items) { lbxPrims.BeginUpdate(); lbxPrims.Items.Remove(item); lbxPrims.Items.Add(item); lbxPrims.EndUpdate(); } } } } else { ObjectsListItem citem = new ObjectsListItem(prim, client, lbxChildren); if (!childItems.ContainsKey(prim.LocalID)) { lock (childItems) { childItems.Add(prim.LocalID, citem); } } else { lock (childItems) { childItems.Remove(prim.LocalID); childItems.Add(prim.LocalID, citem); } } } } })); } //if (!inmem) //{ //pB1.Value = 0; //pB1.Visible = false; groupBox2.Enabled = true; groupBox3.Enabled = true; //lbxPrims.SortList(); //} lblStatus.Visible = false; lbxPrims.Visible = true; lbxChildren.Visible = true; txtSearch.Enabled = true; //lbxPrims.SortList(); pB1.Visible = false; //tlbStatus.Text = listItems.Count.ToString() + " objects"; tlbDisplay.Text = lbxPrims.Items.Count.ToString(CultureInfo.CurrentCulture) + " objects"; } catch (Exception ex) { //string exp = exc.Message; reporter.Show(ex); } Cursor.Current = Cursors.Default; }