public void Update(Object3D obj) { bool bResetNeeded = false; try { // only need to reset the quad for the object if it is no longer in one of the quads try { foreach (Quad q in obj.m_Quads) { try { if (!obj.InRect(q.m_Bounds)) { bResetNeeded = true; } } catch { Console.AddLine("invalid quad in object quad list"); } } } catch { Console.AddLine("fails in foreach"); } try { if (bResetNeeded) { m_BaseQuad.RemoveObject(obj); m_BaseQuad.AddObject(obj); } } catch { Console.AddLine("fails in reset needed"); } } catch (DirectXException d3de) { Console.AddLine("Unable to update a Quad " + Name); Console.AddLine(d3de.ErrorString); } catch (Exception e) { Console.AddLine("Unable to update a Quad " + Name); Console.AddLine(e.Message); } }
public void AddObject(Object3D obj) { try { if (obj != null) { if (obj.InRect(m_Bounds)) { int nIndex = m_Objects.IndexOfKey(obj.Name); try { if (nIndex < 0) // add object if we don't have it yet { m_Objects.Add(obj.Name, obj); obj.m_Quads.Add(this); // if ( !obj.Name.StartsWith("Quad") && !obj.Name.StartsWith("tree") && !obj.Name.StartsWith("red")&& !obj.Name.StartsWith("blue")) // { // Console.AddLine(obj.Name + " added to " + Name ); // } if (m_NorthEast != null && obj.InRect(m_NorthEast.Bounds)) { m_NorthEast.AddObject(obj); } if (m_NorthWest != null && obj.InRect(m_NorthWest.Bounds)) { m_NorthWest.AddObject(obj); } if (m_SouthWest != null && obj.InRect(m_SouthWest.Bounds)) { m_SouthWest.AddObject(obj); } if (m_SouthEast != null && obj.InRect(m_SouthEast.Bounds)) { m_SouthEast.AddObject(obj); } } else { // Console.AddLine("Attempt to add another " + obj.Name ); } } catch (DirectXException d3de) { Console.AddLine("Unable to add object"); Console.AddLine(d3de.ErrorString); } catch (Exception e) { Console.AddLine("Unable to add object"); Console.AddLine(e.Message); } } else { int nIndex = m_Objects.IndexOfKey(obj.Name); if (nIndex >= 0) // remove the object if we have it { RemoveObject(obj); if (m_Parent != null) { m_Parent.AddObject(obj); } } } } } catch { Console.AddLine("fails in Quad AddObject"); } }