On Wed, Oct 24, 2012 at 3:21 AM, Thorbjørn Lindeijer <[email protected]>wrote:
> On Wed, Oct 24, 2012 at 10:13 AM, Stefan Lundmark <[email protected]> > wrote: > > Exposing the sleep amount time might be a good idea considering 200 ms > makes > > it totally useless for anything that needs to run in real-time, like > games. > 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(). Also, since the data is passed as a QByteArray signal parameter, this > necessitates creating a copy of the data. To avoid this > QByteArray::fromRawData could be used, but that's somewhat dangerous > for a library to do since this would make it illegal for the > QENetPacket (or its data) to be stored for later use unless an > explicit copy is made of its data while it is still allocated (since > it would be comparable to simply storing the char * and length > provided by enet). > 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. As for the automatic host service timer, maybe the library should just > expose a 'service' method (slot) so that the application using the > library can hook up a timer of its own at whatever desired frequency. > 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). > I do think ENet is rather simple to use directly so for me personally > such a library is not adding much. For my own purposes I wrote this > ENetClient class, which is meant to be subclassed in order to > implement different clients and has some protocol helpers used by the > Mana client and server built into it (MessageIn and MessageOut) as > well as using QHostInfo for non-blocking host lookup (I couldn't find > a way to have enet do this in a non-blocking way). > > https://github.com/mana/manamobile/blob/master/src/mana/enetclient.cpp Cool! I hadn't realized anyone else had done a Qt wrapper for ENet. - Nathan
_______________________________________________ ENet-discuss mailing list [email protected] http://lists.cubik.org/mailman/listinfo/enet-discuss
