private void SendViewProAttributeForAllObjects(String viewAccordingToThisDm, List<String> sensingObjects) { Dictionary<string, AttributeCollectionValue> thisDMsView = new Dictionary<string, AttributeCollectionValue>(); AttributeCollectionValue ACVptr; foreach (string obj in sensingObjects) { if (!objectViews.ContainsKey(obj)) continue; foreach (string targetObj in objectViews[obj].GetObjectKeys()) { if (!thisDMsView.ContainsKey(targetObj)) { thisDMsView.Add(targetObj, new AttributeCollectionValue()); } ACVptr = thisDMsView[targetObj]; MergeTwoAttributeCollections(ref ACVptr, objectViews[obj].GetObjectsAttributeCollection(targetObj)); } } dmViews[viewAccordingToThisDm] = new ObjectsAttributeCollection(); foreach (string o in thisDMsView.Keys) { dmViews[viewAccordingToThisDm].UpdateObject(o, thisDMsView[o]); AttributeCollectionValue tempACV = ExtractDetectedValuesFromACV(thisDMsView[o]); SendViewProInitializeObject(viewAccordingToThisDm, tempACV); //add tag info to tempACV if (unitTags.ContainsKey(o)) { if (unitTags[o].ContainsKey(dmTeamsMap[viewAccordingToThisDm])) { tempACV.attributes.Add("InitialTag", DataValueFactory.BuildString(unitTags[o][dmTeamsMap[viewAccordingToThisDm]])); } } SendViewProAttributeUpdate(viewAccordingToThisDm, tempACV); } }
/// <summary> /// This event is sent from the client to server once a client is ready to participate /// in the simulation. Once this event is received, that DM is added to the activeDMs list. /// This list acts as a filter; only DMs on this list will have any view pro events sent to them. /// This is to limited the amount of traffic being sent out if only a few DMs are attached /// to the system. /// This is also used when currentTick is > 0 to send out that client's view. If currentTick /// is above 0 and this event is received, then this client will need to get ViewProInitializeObject /// events for each object it has in its view, and then it will need motion updates for those /// objects in its view that are also in the movement list. /// </summary> /// <param name="e">Incoming event</param> private void HandshakeInitializeGUIDone(SimulationEvent e) { string dm = ((StringValue)e["PlayerID"]).value; if (!activeDMs.Contains(dm)) { activeDMs.Add(dm); } foreach (KeyValuePair<string, List<string>> nets in networkRosters) { if (nets.Value.Contains(dm)) { activeSensorNetworks[nets.Key] = true; } } if (currentTick > 0) { if (initialReplaySpeed != null) { distClient.PutEvent(initialReplaySpeed); } else { SimulationEvent ev = SimulationEventFactory.BuildEvent(ref simModel, "GameSpeed"); ev["SpeedFactor"] = DataValueFactory.BuildDouble(1); //default speed of 1 ev["Time"] = DataValueFactory.BuildInteger(currentTick); distClient.PutEvent(ev); } } // send classifications enum to user SimulationEvent classifications = SimulationEventFactory.BuildEvent(ref simModel, "InitializeClassifications"); classifications["Classifications"] = DataValueFactory.BuildStringList(ClassificationsEnum); classifications["Time"] = DataValueFactory.BuildInteger(currentTick); distClient.PutEvent(classifications); //SimulationEvent initEvent = SimulationEventFactory.BuildEvent(ref simModel, "ViewProInitializeObject"); //initEvent["Time"] = DataValueFactory.BuildInteger(currentTick); List<string> visibleObjects = new List<string>(); if (currentTick > 0) //The simulation has already begun, need to setup DM its view { if (!dmOwnedObjects.ContainsKey(dm)) dmOwnedObjects.Add(dm, new List<string>()); //foreach (string id in dmOwnedObjects[dm]) //{ // if (objectViews.ContainsKey(id)) // { // objectViews[id] = new ObjectsAttributeCollection(); // } //} //If time > 0, call a method that takes each object in this DMs sensor networks, //and compiles their total view, and then send off the appropriate init/att updates. if (currentTick > 0) { List<string> sensingObjects = new List<string>(); foreach (string sn in networkRosters.Keys) { if (networkRosters[sn].Contains(dm)) { foreach (string objID in networkObjects[sn]) { if (!sensingObjects.Contains(objID)) { sensingObjects.Add(objID); } } } } Dictionary<string, AttributeCollectionValue> thisDMsView = new Dictionary<string, AttributeCollectionValue>(); AttributeCollectionValue ACVptr; foreach (string obj in sensingObjects) { if (!objectViews.ContainsKey(obj)) continue; foreach (string targetObj in objectViews[obj].GetObjectKeys()) { if (!thisDMsView.ContainsKey(targetObj)) { thisDMsView.Add(targetObj, new AttributeCollectionValue()); } ACVptr = thisDMsView[targetObj]; MergeTwoAttributeCollections(ref ACVptr, objectViews[obj].GetObjectsAttributeCollection(targetObj)); } } dmViews[dm] = new ObjectsAttributeCollection(); foreach (string o in thisDMsView.Keys) { dmViews[dm].UpdateObject(o, thisDMsView[o]); AttributeCollectionValue tempACV = ExtractDetectedValuesFromACV(thisDMsView[o]); SendViewProInitializeObject(dm, tempACV); //add tag info to tempACV if (unitTags.ContainsKey(o)) { if (unitTags[o].ContainsKey(dmTeamsMap[dm])) { tempACV.attributes.Add("InitialTag", DataValueFactory.BuildString(unitTags[o][dmTeamsMap[dm]])); } } SendViewProAttributeUpdate(dm, tempACV); } } } foreach (StateDB.ActiveRegion reg in StateDB.activeRegions.Values) { SendViewProActiveRegionUpdate(reg.id, reg.isVisible, reg.displayColor, reg.currentAbsolutePolygon); } }