void Update() { ChunkInfo info = null; lock (_needsMesh) { if (_needsMesh.Count == 0) { _isGenerating = false; return; } info = _needsMesh.Dequeue(); } GameObject obj = (GameObject)Instantiate(_prefab, info.getPos(), Quaternion.identity); //GameObject obj = (GameObject)PhotonNetwork.Instantiate("Chunk", info.getPos(), Quaternion.identity, 0); Chunk chunk = ((Chunk)obj.GetComponent <Chunk>()); chunk.setInfo(info); chunk.generateMesh(); Vector3 pos = info.getPos(); int x = Mathf.FloorToInt(pos.x / Constants.chunkWidth); int z = Mathf.FloorToInt(pos.z / Constants.chunkWidth); if (!_chunks.ContainsKey(x)) { _chunks.Add(x, new Dictionary <int, Chunk>()); } _chunks[x].Add(z, chunk); }
public void CanEnqueueBeginning() { sut.Enqueue(2); sut.Enqueue(4); sut.Enqueue(10); sut.Dequeue(); sut.EnqueueBeginning(2); Assert.AreEqual(2, sut.Peek()); }
public void Count_should_become_less_after_Dequeue() { int expectedCount = 0; queue = new PQueue <TileNode>(); queue.Enqueue(fixture.Create <TileNode>(), 1); queue.Dequeue(); int actualeCount = queue.Count; Assert.AreEqual(expectedCount, actualeCount); }
public void Dequeue_should_return_first_come_object_if_all_objects_has_same_priority() { TileNode expectedTile = fixture.Create <TileNode>(); queue = new PQueue <TileNode>(); queue.Enqueue(expectedTile, 0); queue.Enqueue(fixture.Create <TileNode>(), 0); queue.Enqueue(fixture.Create <TileNode>(), 0); TileNode actualeTile = queue.Dequeue(); Assert.AreEqual(expectedTile, actualeTile); }
public void Dequeue_should_return_first_object_with_lowest_priority() { TileNode expectedTile = fixture.Create <TileNode>(); queue = new PQueue <TileNode>(); queue.Enqueue(fixture.Create <TileNode>(), 1); queue.Enqueue(expectedTile, 0); queue.Enqueue(fixture.Create <TileNode>(), 0); TileNode actualeTile = queue.Dequeue(); Assert.AreEqual(expectedTile, actualeTile); }
public static ModellingLog Run(model m, double tmax = 100) { double currtime = 0; PQueue q = new PQueue(); //fill pqueue while (currtime < tmax && q.Count > 0) { var e = q.Dequeue(); //process event } return(null); }
static void Main() { PQueue erwait = new PQueue(); pqItem[] erPatient = new pqItem[4]; pqItem nextPatient; erPatient[0].name = "Joe Smith"; erPatient[0].priority = 1; erPatient[1].name = "Mary Brown"; erPatient[1].priority = 0; erPatient[2].name = "Sam Jones"; erPatient[2].priority = 3; for (int x = 0; x <= erPatient.GetUpperBound(0); x++) { erwait.Enqueue(erPatient[x]); } nextPatient = (pqItem)erwait.Dequeue(); Console.WriteLine(nextPatient.name); }
private void generateChunks() { while (_running) { ChunkInfo toGenerate; lock (_needsGenerated) { if (_needsGenerated.Count == 0) { _isGenerating = false; continue; } _isGenerating = true; toGenerate = _needsGenerated.Dequeue(); } toGenerate.generate(); lock (_needsMesh) { _needsMesh.Enqueue(toGenerate); } } }
public bool FindPath(ANode root, ANode dest) { PQueue queue = new PQueue(); if (!nodes.Contains(root)) { nodes.Add(root); foreach (APath x in root.GetPaths()) { paths.Add(x); } } if (!nodes.Contains(dest)) { nodes.Add(dest); foreach (APath x in dest.GetPaths()) { paths.Add(x); } } ANode currentNode = root; currentNode.Cost = 0; List <ANode> notVisited = new List <ANode>(nodes); while (notVisited.Count > 0) { foreach (APath x in currentNode.GetPaths()) { ANode neighbor = x.GetOtherSide(currentNode); if (neighbor.Visited) { continue; } neighbor.UpdateHeuristic(GetHeuristicOf(neighbor, dest)); if (neighbor.Cost > currentNode.Cost + x.Cost) { neighbor.UpdateNodeCost(currentNode.Cost + x.Cost, currentNode); } queue.Enqueue(neighbor); } currentNode.Visited = true; notVisited.Remove(currentNode); if (notVisited.Count == 0) { break; } currentNode = queue.Dequeue(); if (currentNode.Equals(dest)) { UpdatePath(root, dest); return(true); } } return(false); }