I assume &quot;rest(1)&quot; is a sleep function? for one second?<br>If so you&#39;re only checking for a key press packet once per second (and only processing one packet, even if more are waiting).<br><br><br><div class="gmail_quote">
On Sun, Sep 26, 2010 at 6:30 PM, Nicholas J Ingrassellino <span dir="ltr">&lt;<a href="mailto:nick@lifebloodnetworks.com">nick@lifebloodnetworks.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">



  

<div bgcolor="#ffffff" text="#000000">
I am running a little experiment in C++ using ENet v1.3.0 with MSVC
2k8. What I am attempting to create is a pure dumb terminal-style
application where all video is done on a remote server and sent to the
client while the client only sends over key presses. Yes, yes, I know;
I am reinventing the wheel and half the people reading this do not
approve. It is just an experiment I am doing for kicks.<br>
<br>
My issue lies in ENet&#39;s CPU usage. I had noticed that during the
receiving/drawing step my client CPU usage went to 100% and was
reacting way too slow to do what I want to do. After a while I have
narrowed the problem down to ENet. I even went as far as taking ENet
out of the picture to be sure it was not something else using simulated
data as if it were received from the server (IE virtually not changing
my client main loop). Just so I have gone on the record as saying it
the client, once ENet is removed from the picture, can draw an image,
pixel by pixel, 60 times a second without breaking a sweat.<br>
<br>
My server is sending 7 bytes (payload, of course) for each pixel. At
800x600x24 I am aware this is a hell of a lot of data but it is still
eating a lot more CPU than I figured it would on the client. The server
gets all the
data off in a timely fashion but the receiving side can not get it
nearly as fast as it was sent so it ends up backing up really quickly.
The client code looks like this:<br>
<blockquote>while ( !main_loop_exit ) {
<br>
    acquire_screen();
<br>
    blit(buffer, screen, 0, 0, 0, 0, buffer-&gt;w, buffer-&gt;h);
<br>
    release_screen();
<br>
  <br>
    if ( keypressed() ) {
<br>
        unsigned char key_next = readkey() &amp; 0xff;
<br>
        ENetPacket *packet = enet_packet_create(&amp;key_next,
sizeof(unsigned char), ENET_PACKET_FLAG_RELIABLE);
<br>
        enet_peer_send(peer, 0, packet);
<br>
    }
<br>
 <br>
    if ( enet_host_service(client, &amp;event, 0) &gt; 0 ) {
<br>
        if ( event.type == ENET_EVENT_TYPE_RECEIVE ) {
<br>
            _putpixel24(buffer, ((PACKET_PAYLOAD
*)event.packet-&gt;data)-&gt;x, ((PACKET_PAYLOAD
*)event.packet-&gt;data)-&gt;y, makecol(((PACKET_PAYLOAD
*)event.packet-&gt;data)-&gt;r, ((PACKET_PAYLOAD
*)event.packet-&gt;data)-&gt;g, ((PACKET_PAYLOAD
*)event.packet-&gt;data)-&gt;b));
<br>
            enet_packet_destroy(event.packet);
<br>
        }
<br>
        else if ( event.type == ENET_EVENT_TYPE_DISCONNECT )
<br>
            main_loop_exit = true;
<br>
    }
<br>
    else
<br>
        rest(1);
<br>
}<br>
</blockquote><br>
</div></blockquote></div><br>