public void updateStatus() { while (statusOrders.tryReadFifo(out UpdateStatus order) && initAskedForUpdate == 0) { for (int i = 0; i < order.ids.Count; ++i) { if (!theAgents.ContainsKey(order.ids[i])) { BeeAgent a = new BeeAgent(); a.id = order.ids[i]; a.pos = Vector3.zero; //a.pointID = idManager.getNextFreeIndex(); //a.pointID = frameManager.getPointIDForPos(a.pos); a.pointID = -2; //Code to notify this is an uncomplete agent theAgents.Add(a.id, a); } theAgents[order.ids[i]].age = order.ages[i]; theAgents[order.ids[i]].JH = order.jhAmounts[i]; theAgents[order.ids[i]].amountExchanged = order.phExchanged[i]; if (order.taskNames[i] == "QueenTask") { theAgents[order.ids[i]].isQueen = true; } } } }
/* * public void updateStatus() * { * while (statusOrders.tryReadFifo(out UpdateStatus order) && initAskedForUpdate == 0) * { * for (int i = 0; i < order.ids.Count; ++i) * { * if(theAgents.ContainsKey(order.ids[i])) * { * theAgents[order.ids[i]].age = order.ages[i]; * theAgents[order.ids[i]].JH = order.jhAmounts[i]; * * if (order.taskNames[i] == "QueenTask") * { * theAgents[order.ids[i]].isQueen = true; * } * } * } * } * } * * public void updateContacts() * { * while(contactOrders.tryReadFifo(out UpdateContactOrder order) && initAskedForUpdate == 0) * { * for(int i = 0; i < order.ids.Count; ++i) * { * if(theAgents.ContainsKey(order.ids[i])) * { * theAgents[order.ids[i]].amountExchanged = order.amounts[i]; * } // Ignoring NO MORE the agents that have still not been recieved via position * else * { * BeeAgent a = new BeeAgent(); * a.id = order.ids[i]; * a.pos = Vector3.zero; * * //a.pointID = idManager.getNextFreeIndex(); * //a.pointID = frameManager.getPointIDForPos(a.pos); * a.pointID = -2; * //Code to notify this is an uncomplete agent * * theAgents.Add(a.id, a); * } * } * } * } */ public void updateDeaths() { while (deadOrder.tryReadFifo(out List <int> deadIds) && initAskedForUpdate == 0) { foreach (int id in deadIds) { if (theAgents.ContainsKey(id)) { BeeAgent agent = theAgents[id]; //Delete the BeeAgents and free their ids in the different clouds frameManager.freeFrameIDForPos(agent.pos, agent.pointID); theAgents.Remove(id); } else { Debug.LogWarning("dead id not found in the system"); } } } }
public void updateAgents() { while (agentOrders.tryReadFifo(out UpdateOrder updateOrder) && initAskedForUpdate == 0) { int newAgents = 0; float loopUpdate = Time.realtimeSinceStartup; List <Vector3> targets = new List <Vector3>(); List <int> ids = new List <int>(); List <Color> colors = new List <Color>(); for (int i = 0; i < updateOrder.targetsIDs.Count; ++i) { BeeAgent a; if (!theAgents.ContainsKey(updateOrder.targetsIDs[i])) { a = new BeeAgent(); a.id = updateOrder.targetsIDs[i]; a.pos = updateOrder.newTargets[i]; //a.pointID = idManager.getNextFreeIndex(); a.pointID = frameManager.getPointIDForPos(a.pos); theAgents.Add(updateOrder.targetsIDs[i], a); newAgents++; } else { a = theAgents[updateOrder.targetsIDs[i]]; bool changed = false; if (a.pointID == -2)//Uncomplete agent code { a.pos = updateOrder.newTargets[i]; a.pointID = frameManager.getPointIDForPos(a.pos); changed = true; } else { if (a.pos.z != updateOrder.newTargets[i].z) { //Change of Frame frameManager.freeFrameIDForPos(a.pos, a.pointID); a.pointID = frameManager.getPointIDForPos(updateOrder.newTargets[i]); //do something to animate that change, not mandatory tho changed = true; } } a.pos = updateOrder.newTargets[i]; if (changed) { a.pos.x = -a.pos.x; //Encoding the change to be detected by the manager } } if (a.pos.z == -1) { targets.Add(a.pos); //Forager } else { //targets.Add(frameManager.getPosOnFrame(a.pos)); targets.Add(a.pos); } ids.Add(a.pointID); //colors.Add(a.JH > 0.5f ? Color.yellow : Color.red); colors.Add(a.getColor()); } //Debug.Log("AgentLoop" + updateOrder.targetsIDs.Count + "(" + newAgents + ") update took " + (Time.realtimeSinceStartup - loopUpdate) * 1000 + "ms."); //pointCloud.updatePoints(new UpdateOrder(targets, ids)); frameManager.updateBeePoints(new UpdateOrder(targets, ids, colors)); //if (newAgents != 0) Debug.Log("created " + newAgents + " newAgents / total: " + theAgents.Count); } //if (initCount != 0) Debug.Log("Agent update took " + (Time.realtimeSinceStartup - updateStartTime) * 1000 + "ms. From " + initCount + " to " + incOrders.Count); }