[ENet-discuss] simulate lag

Alan Witkowski witkowsk at cs.utah.edu
Mon Jun 9 15:58:06 PDT 2008


Cool. I was thinking about doing it this way and it seemed like the 
easiest. Thanks

Martin Sherburn wrote:
> I did it like this, hope this helps:
>
>    float m_FakeLag = 200.0;
>
>    while (m_pHost && enet_host_service(m_pHost, &event, 0) > 0)
>    {
>            switch (event.type)
>            {
>            case ENET_EVENT_TYPE_CONNECT:
>                OnConnect(event.peer);
>                break;
>
>            case ENET_EVENT_TYPE_RECEIVE:
>                if (m_FakeLag)
>                {
>                    STORED_EVENTS StoredEvent;
>                    StoredEvent.Event = event;
>                    StoredEvent.Time = GAME->GetGameTime();
>                    m_StoredEvents.push_back(StoredEvent);
>                }
>                else
>                {
>                    ProcessPacket(event.packet, event.peer);
>                    enet_packet_destroy(event.packet);
>                }
>                break;
>                          case ENET_EVENT_TYPE_DISCONNECT:
>                OnDisconnect(event.peer);
>                break;
>            }
>    }
>
>    Real Time = GAME->GetGameTime();
>    list<STORED_EVENTS>::iterator itEvent = m_StoredEvents.begin();
>    while (itEvent != m_StoredEvents.end() && itEvent->Time < 
> Time-m_FakeLag)
>    {
>        ProcessPacket(itEvent->Event.packet, itEvent->Event.peer);
>        enet_packet_destroy(itEvent->Event.packet);
>        itEvent = m_StoredEvents.erase(itEvent);
>    }
>
> Martin.
>
>
> Alan Witkowski wrote:
>> What's the easiest way to simulate/introduce lag with enet?  All i 
>> want to do is basically make it so packets don't get to the receiving 
>> side until say 100-200 ms after they get sent. Obviously this is for 
>> testing internet conditions locally. Any easy way of doing this?
>>
>> Thanks
>> _______________________________________________
>> ENet-discuss mailing list
>> ENet-discuss at cubik.org
>> http://lists.cubik.org/mailman/listinfo/enet-discuss
>
> _______________________________________________
> ENet-discuss mailing list
> ENet-discuss at cubik.org
> http://lists.cubik.org/mailman/listinfo/enet-discuss



More information about the ENet-discuss mailing list