/////////////////////////////////////////////////////////////////////////////// // Methods for doing main class job // /////////////////////////////////////////////////////////////////////////////// #region PRIVATEMETHODS /// <summary> /// Parse the gaze data packet into a <see cref="SmartEyeGazeData"/> gazeData object. /// </summary> /// <param name="packet">The network packet.</param> /// <param name="gazeData">The gaze data.</param> /// <returns>True if parsing was successful.</returns> private bool ParseGazeData(NetworkDataPacket packet, out SmartEyeGazeData gazeData) { gazeData = new SmartEyeGazeData(); NetworkData data; if (packet.TryGetValue(TrackerDataId.GazeDirectionQ, out data)) { gazeData.GazeQuality = data.GetValue <double>(); } if (packet.TryGetValue(TrackerDataId.HeadPositionQ, out data)) { gazeData.HeadQuality = data.GetValue <double>(); } if (packet.TryGetValue(TrackerDataId.RealTimeClock, out data)) { gazeData.RealTime = (long)data.GetValue <ulong>(); gazeData.Time = (long)(gazeData.RealTime / 10000); } if (packet.TryGetValue(TrackerDataId.ClosestWorldIntersection, out data)) { var intersection = data.GetValue <WorldIntersection>(); gazeData.GazePosX = (float)intersection.ObjectPoint.X / Document.ActiveDocument.PresentationSize.Width; gazeData.GazePosY = (float)intersection.ObjectPoint.Y / Document.ActiveDocument.PresentationSize.Height; } if (packet.TryGetValue(TrackerDataId.LeftPupilDiameter, out data)) { gazeData.PupilDiaX = (float)data.GetValue <double>(); } if (packet.TryGetValue(TrackerDataId.RightPupilDiameter, out data)) { gazeData.PupilDiaY = (float)data.GetValue <double>(); } return(true); }
/////////////////////////////////////////////////////////////////////////////// // Methods for doing main class job // /////////////////////////////////////////////////////////////////////////////// #region PRIVATEMETHODS /// <summary> /// Parse the gaze data packet into a <see cref="SmartEyeGazeData"/> gazeData object. /// </summary> /// <param name="packet">The network packet.</param> /// <param name="gazeData">The gaze data.</param> /// <returns>True if parsing was successful.</returns> private bool ParseGazeData(NetworkDataPacket packet, out SmartEyeGazeData gazeData) { gazeData = new SmartEyeGazeData(); NetworkData data; if (packet.TryGetValue(TrackerDataId.GazeDirectionQ, out data)) { gazeData.GazeQuality = data.GetValue<double>(); } if (packet.TryGetValue(TrackerDataId.HeadPositionQ, out data)) { gazeData.HeadQuality = data.GetValue<double>(); } if (packet.TryGetValue(TrackerDataId.RealTimeClock, out data)) { gazeData.RealTime = (long)data.GetValue<ulong>(); gazeData.Time = (long)(gazeData.RealTime / 10000); } if (packet.TryGetValue(TrackerDataId.ClosestWorldIntersection, out data)) { var intersection = data.GetValue<WorldIntersection>(); gazeData.GazePosX = (float)intersection.ObjectPoint.X / Document.ActiveDocument.PresentationSize.Width; gazeData.GazePosY = (float)intersection.ObjectPoint.Y / Document.ActiveDocument.PresentationSize.Height; } if (packet.TryGetValue(TrackerDataId.LeftPupilDiameter, out data)) { gazeData.PupilDiaX = (float)data.GetValue<double>(); } if (packet.TryGetValue(TrackerDataId.RightPupilDiameter, out data)) { gazeData.PupilDiaY = (float)data.GetValue<double>(); } return true; }
//---------------------------------------------------------------------------------- // The IsNetworkMessage being optional could make this open to abuse as it allows the consumer to send it. // maybe the flags should be made private? /// <summary> /// Send entity message. The message will get pushed across the network to all slaves if there any available. /// </summary> /// <param name="szMessageName">Name of message.</param> /// <param name="entity">The entity we are sending this message to.</param> /// <param name="msgData">Data to sent with the message. (optional)</param> /// <param name="IsNetworkMessage">Is this being sent as a network message. (optional)</param> /// <returns></returns> //---------------------------------------------------------------------------------- public EntityMsgRslt SendMessage(String szMessageName, Entity entity, object msgData = null, bool IsNetworkMessage = false) { Rslt rslt = new Rslt(); //set flags rslt |= DynamicStores.Enums.NonAuthoritative; rslt |= DynamicStores.Enums.Invalid_Sender; rslt |= DynamicStores.Enums.Invalid_Receiver; //check entity is valid and authoritative. if (IsValid && entity.IsValid && entity.IsAuthoritative()) { //use reflection to get method call. MethodInfo methodInfo = null; Type type = entity.GetType(); methodInfo = type.GetMethod(szMessageName); if (methodInfo == null) { //If this method doesn't exist. Console.WriteLine("Message '" + szMessageName + "' does not exist for entity type " + type.ToString()); rslt.ClearRslt(); rslt |= DynamicStores.Enums.Fail; } else { //pack data into and message header in an object array. Object[] aMsgData = msgData != null ? new Object[2] : new Object[1]; aMsgData[0] = this; //This is the sending entity. if (msgData != null) { aMsgData[1] = msgData; //any data sent with it...this can be a struct etc. } methodInfo.Invoke(entity, aMsgData); if (!IsNetworkMessage) { NetworkEngine network = EngineServices.GetSystem <IGameSystems>().Network; //send this through the network. if (network.IsNetworkActive) { //create network packet. NetworkDataPacket packet = new NetworkDataPacket(); //set up packet. packet.EntityIDs.SendingEntityID = this.EntityID; packet.EntityIDs.ReceiveEntityID = entity.EntityID; packet.MessageType = MessageType.EntityMessage; packet.SendMethod = NetworkSendMethod.InOrder; packet.UserData = msgData; //push message. network.SendMessage(packet); } } rslt.ClearRslt(); rslt |= DynamicStores.Enums.Success; } } return(new EntityMsgRslt(this, entity, rslt)); }