Exemplo n.º 1
0
        // Reflect Object Attributes
        public override void FdAmb_ObjectAttributesReflectedHandler(object sender, Racon.RtiLayer.HlaObjectEventArgs data)
        {
            // Call the base class handler
            base.FdAmb_ObjectAttributesReflectedHandler(sender, data);

            // User code
            foreach (CUser user in simManager.Users)
            {
                // Find the Object
                if (data.ObjectInstance.Handle == user.Handle)
                {
                    // Get parameter values
                    // 1st method
                    // First check wheather the attr is updated or not. Result returns 0/null if the updated attribute set does not contain the attr and its value
                    if (data.IsValueUpdated(Som.UserOC.NickName))
                    {
                        user.NickName = data.GetAttributeValue <string>(Som.UserOC.NickName);
                    }
                    if (data.IsValueUpdated(Som.UserOC.Status))
                    {
                        user.Status = (StatusTypes)data.GetAttributeValue <uint>(Som.UserOC.Status);
                    }

                    // 2nd method
                    //foreach (var item in data.ObjectInstance.Attributes)
                    //{
                    //  if (item.Handle == Som.UserOC.NickName.Handle) user.NickName = item.GetValue<string>();
                    //  else if (item.Handle == Som.UserOC.Status.Handle) user.Status = (StatusTypes)item.GetValue<uint>();
                    //}
                    ViewText = "NickName: " + user.NickName + ". Status: " + user.Status + ". Update reason: " + data.Tag.GetData <string>() + Environment.NewLine;
                }
            }
        }
Exemplo n.º 2
0
        // An Object is Discovered
        public override void FdAmb_ObjectDiscoveredHandler(object sender, Racon.RtiLayer.HlaObjectEventArgs data)
        {
            // Call the base class handler
            base.FdAmb_ObjectDiscoveredHandler(sender, data);

            // User code
            // Check the class type of the discovered object
            if (data.ClassHandle == Som.UserOC.Handle)
            {
                // Create and add a new user to the list
                CUser nUser = new CUser(data.ObjectInstance);
                nUser.Type = Som.UserOC;
                simManager.Users.Add(nUser);

                // Request Update Values
                RequestAttributeValueUpdate(nUser, string.Empty);// Request update values of all attributes for this specific object
                //RequestAttributeValueUpdate(Som.UserOC);// Request update for all attribute values of all objects related to this object class

                // Request Update Values for specific attributes only
                //List<HlaAttribute> attributes = new List<HlaAttribute>();
                //attributes.Add(Som.UserOC.NickName);
                //attributes.Add(Som.UserOC.Status);
                //RequestAttributeValueUpdate(nUser, attributes);
            }
        }
Exemplo n.º 3
0
        // An Object is Removed
        public override void FdAmb_ObjectRemovedHandler(object sender, Racon.RtiLayer.HlaObjectEventArgs data)
        {
            // Call the base class handler
            base.FdAmb_ObjectRemovedHandler(sender, data);

            // User code
            // Lock while taking a snapshot - to avoid foreach loop enumeration exception
            object[] snap;
            lock (thisLock)
            {
                snap = simManager.Users.ToArray();
            }
            foreach (CUser user in snap)
            {
                if (data.ObjectInstance.Handle == user.Handle)// Find the Object
                {
                    simManager.Users.Remove(user);
                    // for DateTime
                    ViewText  = "Object removed. Reason: " + data.Tag.GetData <string>() + ". ";
                    ViewText += "User: "******" left. Number of Users Left: " + simManager.Users.Count + Environment.NewLine;
                }
            }
        }
Exemplo n.º 4
0
 /// <summary>
 ///
 /// </summary>
 protected virtual void OnTurnUpdatesOffForObjectInstanceAdvised(HlaObjectEventArgs e)
 {
     TurnUpdatesOffForObjectInstanceAdvised?.Invoke(this, e);// Raise the event.
 }
Exemplo n.º 5
0
 /// <summary>
 ///
 /// </summary>
 protected virtual void OnObjectAttributesReflected(HlaObjectEventArgs e)
 {
     ObjectAttributesReflected?.Invoke(this, e);// Raise the event.
 }
Exemplo n.º 6
0
 /// <summary>
 ///
 /// </summary>
 protected virtual void OnObjectRemoved(HlaObjectEventArgs e)
 {
     ObjectRemoved?.Invoke(this, e);// Raise the event.
 }
Exemplo n.º 7
0
 /// <summary>
 ///
 /// </summary>
 protected virtual void OnAttributeValueUpdateRequested(HlaObjectEventArgs e)
 {
     AttributeValueUpdateRequested?.Invoke(this, e);// Raise the event.
 }
Exemplo n.º 8
0
        // Attribute Value Update is Requested
        public override void FdAmb_AttributeValueUpdateRequestedHandler(object sender, Racon.RtiLayer.HlaObjectEventArgs data)
        {
            // Call the base class handler
            base.FdAmb_AttributeValueUpdateRequestedHandler(sender, data);

            // User code
            // !!! If it is created only one object, then it is sufficient to check the handle of that object, otherwise we need to check all the collection
            // Find the object class for which the request is made
            //ViewText = "received handle: " + data.ObjectInstance.Handle + ", local handle: " + simManager.Users[0].Handle + Environment.NewLine;
            if (data.ObjectInstance.Handle == simManager.Users[0].Handle)
            {
                // We can further try to figure out the attributes for which update is requested.
                // First check the  update is requested for the attribute, if true provide an update for that specific attribute
                //foreach (var item in data.ObjectInstance.Attributes)
                //{
                //  if (item.Handle == Som.UserOC.NickName.Handle) UpdateName(simManager.Users[0]);
                //  else if (item.Handle == Som.UserOC.Status.Handle) UpdateStatus(simManager.Users[0]);
                //}

                // We can update all attributes if we dont want to check every attribute.
                UpdateName(simManager.Users[0]);
                UpdateStatus(simManager.Users[0]);
            }
        }