Ejemplo n.º 1
0
    public virtual void UpdatePlayerPosition(PharusTransmission.TrackRecord trackRecord)
    {
        foreach (ATrackingEntity aPlayer in _playerList)
        {
            if (aPlayer.TrackID == trackRecord.trackID)
            {
                aPlayer.AbsolutePosition             = new Vector2(trackRecord.currentPos.x, trackRecord.currentPos.y);
                aPlayer.NextExpectedAbsolutePosition = new Vector2(trackRecord.expectPos.x, trackRecord.expectPos.y);
                aPlayer.RelativePosition             = new Vector2(trackRecord.relPos.x, trackRecord.relPos.y);
                aPlayer.Orientation = new Vector2(trackRecord.orientation.x, trackRecord.orientation.y);
                aPlayer.Speed       = trackRecord.speed;
                // use AddToVector2List() instead of ToVector2List() as it is more performant
                aPlayer.Echoes.Clear();
                trackRecord.echoes.AddToVector2List(aPlayer.Echoes);
                aPlayer.SetPosition(UnityPharusManager.GetScreenPositionFromRelativePosition(trackRecord.relPos));
                aPlayer.SetPosition(TrackingAdapter.GetScreenPositionFromRelativePosition(trackRecord.relPos.x, trackRecord.relPos.y));
                return;
            }
        }

        if (_addUnknownPlayerOnUpdate)
        {
            AddPlayer(trackRecord);
        }
    }
Ejemplo n.º 2
0
    public void AddPlayer(PharusTransmission.TrackRecord trackRecord)
    {
        //		Vector2 position = UnityPharusManager.GetScreenPositionFromRelativePosition(trackRecord.relPos);
        Vector2         position = TrackingAdapter.GetScreenPositionFromRelativePosition(trackRecord.relPos.x, trackRecord.relPos.y);
        ATrackingEntity aPlayer  = (GameObject.Instantiate(_playerPrefabArray[idx], new Vector3(position.x, position.y, 0), Quaternion.identity) as GameObject).GetComponent <ATrackingEntity>();

        aPlayer.TrackID                      = trackRecord.trackID;
        aPlayer.AbsolutePosition             = new Vector2(trackRecord.currentPos.x, trackRecord.currentPos.y);
        aPlayer.NextExpectedAbsolutePosition = new Vector2(trackRecord.expectPos.x, trackRecord.expectPos.y);
        aPlayer.RelativePosition             = new Vector2(trackRecord.relPos.x, trackRecord.relPos.y);
        aPlayer.Orientation                  = new Vector2(trackRecord.orientation.x, trackRecord.orientation.y);
        aPlayer.Speed = trackRecord.speed;
        aPlayer.Echoes.Clear();
        trackRecord.echoes.AddToVector2List(aPlayer.Echoes);

        aPlayer.gameObject.name = string.Format("PharusPlayer_{0}", aPlayer.TrackID);

        _playerList.Add(aPlayer);

        _playerList.Add(aPlayer);

        if (idx < _playerPrefabArray.Length - 1)
        {
            idx++;
        }
        else
        {
            idx = 0;
        }
    }
Ejemplo n.º 3
0
 private void RemoveAllTrackRecords()
 {
     foreach (KeyValuePair <int, TrackRecord> entry in TrackRecords)
     {
         TrackRecord track = entry.Value;
         foreach (ITransmissionReceiver receiver in transmissionReceiverList)
         {
             track.state = ETrackState.TS_OFF;
             receiver.OnTrackLost(track);
         }
     }
 }
Ejemplo n.º 4
0
        private void Receive()
        {
            NetworkStream stream = tcpClient.GetStream();

            if (stream.CanRead && stream.DataAvailable)
            {
                byte[] recvBuf  = new byte[tcpClient.ReceiveBufferSize];
                int    recvSize = 0;
                recvSize = stream.Read(recvBuf, 0, recvBuf.Length);

                if (recvSize > 0)
                {
                    int i = 0;
                    while (i < recvSize)
                    {
                        if (Convert.ToChar(recvBuf[i++]) != 'T')
                        {
                            Console.WriteLine("TransmissionClient: Unexpected header byte, skipping packet.");
                            i = recvSize;
                            continue;
                        }

                        // get the tracks's id
                        int tid;
                        tid = UnpackInt(recvBuf, ref i);

                        lock (trackDict)
                        {
                            // is this track known? if so, update, else add:
                            bool unknownTrack = !trackDict.ContainsKey(tid);

                            TrackRecord track;
                            if (unknownTrack)
                            {
                                track         = new TrackRecord();
                                track.echoes  = new List <Vector2f>();
                                track.trackID = tid;
                                trackDict.Add(tid, track);
                            }
                            else
                            {
                                track = trackDict[tid];
                            }

                            track.state         = (ETrackState)UnpackInt(recvBuf, ref i);
                            track.currentPos.x  = UnpackFloat(recvBuf, ref i);
                            track.currentPos.y  = UnpackFloat(recvBuf, ref i);
                            track.expectPos.x   = UnpackFloat(recvBuf, ref i);
                            track.expectPos.y   = UnpackFloat(recvBuf, ref i);
                            track.orientation.x = UnpackFloat(recvBuf, ref i);
                            track.orientation.y = UnpackFloat(recvBuf, ref i);
                            track.speed         = UnpackFloat(recvBuf, ref i);
                            track.relPos.x      = UnpackFloat(recvBuf, ref i);
                            track.relPos.y      = UnpackFloat(recvBuf, ref i);
                            track.echoes.Clear();
                            while (Convert.ToChar(recvBuf[i]) == 'E') // peek if echo(es) available
                            {
                                ++i;                                  // yep, then skip 'E'
                                Vector2f echo;
                                echo.x = UnpackFloat(recvBuf, ref i);
                                echo.y = UnpackFloat(recvBuf, ref i);
                                track.echoes.Add(echo);
                                ++i;                                 // 'e'
                            }

                            if (Convert.ToChar(recvBuf[i++]) != 't')
                            {
                                Console.WriteLine("TransmissionClient: Unexpected tailing byte, skipping packet.");
                                i = recvSize;
                                continue;
                            }

                            lock (transmissionReceiverList)
                            {
                                //notify callbacks
                                foreach (ITransmissionReceiver receiver in transmissionReceiverList)
                                {
                                    // track is unknown yet AND is not about to die
                                    if (unknownTrack && track.state != ETrackState.TS_OFF)
                                    {
                                        receiver.OnTrackNew(track);
                                    }
                                    // standard track update
                                    else if (!unknownTrack && track.state != ETrackState.TS_OFF)
                                    {
                                        receiver.OnTrackUpdate(track);
                                    }
                                    // track is known and this is his funeral
                                    else if (!unknownTrack && track.state == ETrackState.TS_OFF)
                                    {
                                        receiver.OnTrackLost(track);
                                    }
                                }
                            }

                            // remove track from dictionary
                            if (track.state == ETrackState.TS_OFF)
                            {
                                trackDict.Remove(track.trackID);
                            }
                        }
                    }
                }
            }
        }