Example #1
0
        public void Tick(float elapsedms)
        {
            for (int i = 0; i < LatentSendCount; i++)
            {
                LatentSend ls = LatentSends[i];
                ls.RemainingTime -= elapsedms;
                if (ls.RemainingTime <= 0)
                {
                    for (int o = 0; o < Targets.Length; o++)
                    {
                        if (Addresses[o].Address.Equals(ls.Target.Address) && Addresses[o].Port == ls.Target.Port)
                        {
                            Targets[o].Receive(ls.Buffer, ls.Length, FromPoint);
                            break;
                        }
                    }

                    // now remove
                    LatentSendCount--;
                    LatentSends[i] = LatentSends[LatentSendCount];
                    LatentSends[LatentSendCount] = ls;
                }
            }
        }
Example #2
0
        public void Send(byte[] msg, int len, IPEndPoint target)
        {
            if (SimulatedLatencyMin > 0 || SimulatedLatencyMax > 0)
            {
                while (LatentSends.Length <= LatentSendCount)
                {
                    // must expand
                    LatentSend[] nls = new LatentSend[LatentSends.Length * 2];
                    for (int i = 0; i < LatentSends.Length; i++)
                    {
                        nls[i] = LatentSends[i];
                    }
                    LatentSends = nls;
                }
                if (LatentSends[LatentSendCount] == null)
                {
                    LatentSends[LatentSendCount] = new LatentSend();
                }
                LatentSend ls = LatentSends[LatentSendCount];
                LatentSendCount++;
                Buffer.BlockCopy(msg, 0, ls.Buffer, 0, len);
                ls.Length        = len;
                ls.RemainingTime = SimulatedLatencyMin + Random.NextDouble() * (SimulatedLatencyMax - SimulatedLatencyMin);
                ls.Target        = target;
                return;
            }

            for (int i = 0; i < Targets.Length; i++)
            {
                if (Addresses[i].Address.Equals(target.Address) && Addresses[i].Port == target.Port)
                {
                    Targets[i].Receive(msg, len, FromPoint);
                    break;
                }
            }
        }