<div class="gmail_quote">On Wed, Oct 24, 2012 at 3:21 AM, Thorbjørn Lindeijer <span dir="ltr"><<a href="mailto:bjorn@lindeijer.nl" target="_blank">bjorn@lindeijer.nl</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On Wed, Oct 24, 2012 at 10:13 AM, Stefan Lundmark <<a href="mailto:stefanlun@hotmail.com">stefanlun@hotmail.com</a>> wrote:<br>
> Exposing the sleep amount time might be a good idea considering 200 ms makes<br>
> it totally useless for anything that needs to run in real-time, like games.<br></div></blockquote><div><br>Yes, I have become convinced that exposing the number is a good idea. Therefore I have added a new parameter to the end of QENetHost::create(). <br>
<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Also, since the data is passed as a QByteArray signal parameter, this<br>
necessitates creating a copy of the data. To avoid this<br>
QByteArray::fromRawData could be used, but that's somewhat dangerous<br>
for a library to do since this would make it illegal for the<br>
QENetPacket (or its data) to be stored for later use unless an<br>
explicit copy is made of its data while it is still allocated (since<br>
it would be comparable to simply storing the char * and length<br>
provided by enet).<br></blockquote><div><br>Right - I originally was just storing the ENetPacket * itself in QENetPacket and discovered (with the help of the debugger) that ENet automatically frees packets once they are sent. So instead I decided it would be easier to just copy the packet's contents immediately upon receipt and go from there. I'm pretty sure QByteArray uses copy-on-write and therefore passing a QByteArray around by value won't result in a bunch of data copying operations.<br>
<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
As for the automatic host service timer, maybe the library should just<br>
expose a 'service' method (slot) so that the application using the<br>
library can hook up a timer of its own at whatever desired frequency.<br></blockquote><div><br>I have no idea why I didn't think of this myself. Thank you! I have created a slot QENetHost::service() that can be called at any time to service the host or attached to another QTimer, etc. You can disable QENetHost's built-in timer by passing a value of 0 as the final parameter to create() - you will then need to make sure your code calls QENetHost::service() at regular intervals (such as in a game's main loop).<br>
</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I do think ENet is rather simple to use directly so for me personally<br>
such a library is not adding much. For my own purposes I wrote this<br>
ENetClient class, which is meant to be subclassed in order to<br>
implement different clients and has some protocol helpers used by the<br>
Mana client and server built into it (MessageIn and MessageOut) as<br>
well as using QHostInfo for non-blocking host lookup (I couldn't find<br>
a way to have enet do this in a non-blocking way).<br>
<br>
<a href="https://github.com/mana/manamobile/blob/master/src/mana/enetclient.cpp" target="_blank">https://github.com/mana/manamobile/blob/master/src/mana/enetclient.cpp</a></blockquote><div><br> Cool! I hadn't realized anyone else had done a Qt wrapper for ENet.<br>
<br>- Nathan<br></div></div><br>