public virtual void UnloadResources() { // dispose of items foreach (GUILayerItem item in itemsList) { item.Dispose(); } itemsList.Clear(); itemsLayout.Clear(); }
public override bool Update(GameTime gameTime) { if (base.Update(gameTime)) { // Update the QuadTree qTree.Clear(); var colliders = GetAllColliders(); foreach (var wo in colliders) { qTree.Insert(wo); } EntityMgr.Update(gameTime); camera.CenterToPosition(EntityMgr.GetEntity(0).Position); //if (Input.KeyDown(Keys.Up)) //{ // camera.Position += new Vector2(0, -scrollSpeed) * (float)gameTime.ElapsedGameTime.TotalMilliseconds; //} //else if (Input.KeyDown(Keys.Down)) //{ // camera.Position += new Vector2(0, scrollSpeed) * (float)gameTime.ElapsedGameTime.TotalMilliseconds; //} //if (Input.KeyDown(Keys.Left)) //{ // camera.Position += new Vector2(-scrollSpeed, 0) * (float)gameTime.ElapsedGameTime.TotalMilliseconds; //} //else if (Input.KeyDown(Keys.Right)) //{ // camera.Position += new Vector2(scrollSpeed, 0) * (float)gameTime.ElapsedGameTime.TotalMilliseconds; //} if (Input.KeyDown(Keys.D1)) { WorldTimer.CurrentTimeOfDay = TimeOfDay.Morning; } else if (Input.KeyDown(Keys.D2)) { WorldTimer.CurrentTimeOfDay = TimeOfDay.Day; } else if (Input.KeyDown(Keys.D3)) { WorldTimer.CurrentTimeOfDay = TimeOfDay.Afternoon; } else if (Input.KeyDown(Keys.D4)) { WorldTimer.CurrentTimeOfDay = TimeOfDay.Night; } worldMap.Update(gameTime); camera.SetCustomMatrix(Game1.Monitor.GetTransformationMatrix()); camera.Update(gameTime); return(true); } return(false); }
public void GetKClosestObjectsTest() { QuadTree <TestObject> tree = new QuadTree <TestObject>(m_Bounds); SpacePartitionerTests.GetKClosestObjectsTest(tree); // Now execute tests that will hit all branches of // KNearestNeighbor search method tree.Clear(); tree.Add(new TestObject(490, 499)); tree.Add(new TestObject(501, 499)); tree.Add(new TestObject(499.5f, 501)); tree.Add(new TestObject(501, 501)); tree.Update(); // Uses different orders of child node iteration tree.GetKClosestObjects(new Vector2f(499, 499), 5); tree.GetKClosestObjects(new Vector2f(501, 499), 5); tree.GetKClosestObjects(new Vector2f(499, 501), 5); tree.GetKClosestObjects(new Vector2f(501, 501), 5); // Some objects not in range tree.GetKClosestObjects(new Vector2f(500, 499), 3, 1.001f); // Requires replacing elements in the PQ tree.GetKClosestObjects(new Vector2f(500, 499), 3, 10f); }
public void Clear() { entities.Clear(); enemies.Clear(); marioPositions.Clear(); levelAreas.Clear(); layers.Clear(); }
private void ReconstructTree() { //this is faster than _quadTree.Reconstruct(), since the quadtree method runs a recusive query to find all nodes. _quadTree.Clear(); foreach (Element <FixtureProxy> elem in _idRegister.Values) { _quadTree.AddNode(elem); } }
public void Clear() { _started = false; _quadTree.Clear(); LineDrawer.Instance.Clear(); _entityCount = 0; UIManager.Instance.SetSimulationStatus("Cleared"); UIManager.Instance.SetEntityCount(_entityCount); }
private void Update() { _csQuad.Step(); _quadTree.Clear(); foreach (var b in _quadTreeBodies) { _quadTree.AddBody(b); } }
public void Clear() { plantsLookup.Clear(); for (var i = 0; i < plants.Count; i++) { Object.Destroy(plants[i]); } plants.Clear(); }
public void RebuildTree() { movingTree.Clear(); foreach (Entity entity in movingEntities) { movingTree.Insert(entity); } rebuildAsked = false; }
////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////// #region Tree Helpers public void updateAgentTree() { // QuadTree.cs suggests clearing the tree every frame and rebuilding, // for cases like this where there are a lot of moving objects. Will // try that for now. agentTree.Clear(); for (int i = 0; i < agents.Count; i++) { agentTree.Insert(agents[i], agents[i].Location.x, agents[i].Location.y, 0, 0); } }
public void ResetQuadTree() { if (quadtree == null) { quadtree = new QuadTree(0, startingBounds, Color.red); } else { quadtree.Clear(); } }
public void GetClosestObjectTest() { QuadTree <TestObject> tree = new QuadTree <TestObject>(m_Bounds); SpacePartitionerTests.GetClosestObjectTest(tree); // Now execute tests that will hit all branches of // NearestNeighbor search method tree.Clear(); tree.Add(new TestObject(488, 499)); tree.Add(new TestObject(508, 499)); tree.Add(new TestObject(496, 501)); tree.Add(new TestObject(501, 501)); tree.Update(); tree.GetClosestObject(new Vector2f(499, 499), 5); tree.Clear(); tree.Add(new TestObject(492, 499)); tree.Add(new TestObject(512, 499)); tree.Add(new TestObject(499, 501)); tree.Add(new TestObject(504, 501)); tree.Update(); tree.GetClosestObject(new Vector2f(501, 499), 5); tree.Clear(); tree.Add(new TestObject(496, 499)); tree.Add(new TestObject(501, 499)); tree.Add(new TestObject(488, 501)); tree.Add(new TestObject(508, 501)); tree.Update(); tree.GetClosestObject(new Vector2f(499, 501), 5); tree.Clear(); tree.Add(new TestObject(499, 499)); tree.Add(new TestObject(504, 499)); tree.Add(new TestObject(492, 501)); tree.Add(new TestObject(512, 501)); tree.Update(); tree.GetClosestObject(new Vector2f(501, 501), 5); }
/// <summary> /// Sets the count to 0 this quadtree and all its sub-quadtrees /// </summary> public void Clear( ) { if (subdivided) { subdivided = false; northWest.Clear( ); northEast.Clear( ); southWest.Clear( ); southEast.Clear( ); } count = 0; }
void ReBuildTree() { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); m_quadTree.Clear(); m_quadTree.LeafSize = this.LeafSize; foreach (var go in m_points) { m_quadTree.Insert(new Vector2(go.transform.position.x, go.transform.position.z), go); } UnityEngine.Debug.Log(string.Format("frame:{0} BuildTree {1}ms {2}tick", Time.frameCount, stopwatch.ElapsedMilliseconds, stopwatch.ElapsedTicks)); }
void UpdateQuadTree() { long StopBytes = 0; // Get total memory before create your dictionnary long StartBytes = 0; if (_Particles.Count > 1) { // foreach (GameObject particleObj in _Particles) // { // RootQuadTree.Remove(particleObj); // } RootQuadTree.Clear(); //.Remove(_Particles[0]); //RootQuadTree.Remove(_Particles[1]); _QuadTreePartitioners.Clear(); // Perform a collection of all generations up to and including 2. //System.GC.Collect(2); //StartBytes = System.GC.GetTotalMemory(false); // Get total memory after create your dictionnary AreaOfFrustum = FrustumArea(); foreach (GameObject particleObj in _Particles) { particleObj.gameObject.GetComponent <SpriteRenderer>().color = Color.blue; RootQuadTree.Insert(particleObj); } //StopBytes = System.GC.GetTotalMemory(false); } //return ((long)(StopBytes - StartBytes)); }
public static void PoolQuadTree(QuadTree tree) { if (tree == null) { return; } tree.Clear(); if (_pool.Count > _maxPoolCount) { return; } _pool.Enqueue(tree); }
private void Update() { switch (CSType) { case CollisionSystemType.Brute: _csBrute.Step(); break; case CollisionSystemType.QuadTree: _csQuad.Step(); break; } _quadTree.Clear(); foreach (var b in _quadTreeBodies) { _quadTree.AddBody(b); } }
public void CalculateCollisionPairs() { #if DEBUG CollisionDebug.BroadphaseDetections = 0; #endif CollisionPairs.Clear(); quadTree.Clear(); for (int i = 0; i < proxies.Count; i++) { // TODO dirty hack Element <BroadphaseProxy> e = new Element <BroadphaseProxy>(proxies[i], proxies[i].AABB); quadTree.Insert(e); } foreach (var proxy in proxies) { var possible = new List <Element <BroadphaseProxy> >(); quadTree.QueryAABB(ref proxy.AABB, ref possible); foreach (var p in possible) { if (proxy.ShouldCollide(p.Value) && proxy.AABB.Intersects(ref p.Value.AABB)) { #if DEBUG CollisionDebug.BroadphaseDetections++; #endif CollisionPairs.Add(new CollisionPair(proxy, p.Value)); } } } /* CollisionPairs.Sort(); * * * for (int i = CollisionPairs.Count - 1; i >= 0; i--) * { * var primary = CollisionPairs[i]; * --i; * while (i >= 0 && CollisionPairs[i].ProxyA.ProxyID == primary.ProxyA.ProxyID && CollisionPairs[i].ProxyB.ProxyID == primary.ProxyB.ProxyID) * { * CollisionPairs.RemoveAt(i--); * } * }*/ }
public void Clear() { QuadTree <byte> tree = new QuadTree <byte>(3, 0, 0, 10, 10); //Fill it with random data for (byte i = 0; i < byte.MaxValue; i++) { tree.Add(GetRandomVec(-10, 10), (byte)Random.Range(0, 255)); } byte[] data = tree.GetAll(); Debug.Assert(data.Length == byte.MaxValue); tree.Clear(); data = tree.GetAll(); Debug.Assert(data.Length == 0); }
// All the items must be pushed together at once // The first to push in the tree during the current frame wins public QuadTree <T> pushIntoTree(List <T> item) { // If we haven't already pushed items this frame if (oldFrame < Time.frameCount) { // We clear the tree INSTANCE.Clear(); // Then refill it foreach (T tItem in item) { INSTANCE.Insert(tItem); } // Finally we indicate we have pushed this frame oldFrame = Time.frameCount; } // The tree is returned to make it simplier return(INSTANCE); }
public static void HandleCollisions(IList <EnvironmentObject> objects) { foreach (var obj in objects) { collidingObjects.Insert(obj); } foreach (var obj in objects) { var candidateCollisionItems = collidingObjects.GetItems(new List <ICollidable>(), obj.Bounds); foreach (var item in candidateCollisionItems) { if (Rectangle.Intersects(obj.Bounds, item.Bounds) && item != obj) { var collisionInfo = new CollisionInfo(item); obj.RespondToCollision(collisionInfo); } } } collidingObjects.Clear(); }
private void Update() { if (gameObject.CompareTag("Generator")) { switch (CSType) { case CollisionSystemType.Brute: _csBrute.Step(); break; case CollisionSystemType.QuadTree: _csQuad.Step(); break; } // refresh QuadTree each frame if bodies can move _quadTree.Clear(); foreach (var b in _quadTreeBodies) { _quadTree.AddBody(b); } } }
protected override void Update(GameTime gameTime) { // Allows the game to exit sWatch.Start(); if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) { this.Exit(); } if (removing) { if (toRemove < gos.Length) { qt.Remove(gos[toRemove]); toRemove++; } } MouseState mState = Mouse.GetState(); camera.SetPos(new Vector2(mState.X, mState.Y)); KeyboardState kState = Keyboard.GetState(); if (kState.GetPressedKeys().Length == 0) { keyDown = false; } if (!keyDown) { if (kState.IsKeyDown(Keys.G)) { drawQuads = !drawQuads; keyDown = true; } if (kState.IsKeyDown(Keys.Q)) { useQuadTree = !useQuadTree; keyDown = true; } if (kState.IsKeyDown(Keys.D)) { removing = !removing; keyDown = true; } if (kState.IsKeyDown(Keys.C)) { qt.Clear(); keyDown = true; } } if (kState.IsKeyDown(Keys.OemPlus)) { camera.AddSize(1); } if (kState.IsKeyDown(Keys.OemMinus)) { camera.AddSize(-1); } base.Update(gameTime); if (interval == 0) { debugStatements["Update time"] = sWatch.ElapsedMilliseconds.ToString(); } }
void Update() { quadTree.Clear(); ClickToAddPoint(); }
public void clearBoard() { actors.Clear(); onBoardChanged(); }
public void clear() { _items.Clear(); }
/// <summary> /// 重新构建四叉树 /// 使用情况: 列表中对向位置已变更时 /// </summary> public void RebuildQuadTree() { quadTree.Clear(); quadTree.Insert(list); }
public void ClearAll() { quadTree.Clear(); edges.Clear(); Invalidate(); }
public void ClearSimulation() { quadTree.Clear(); activeFire.Clear(); }