Skip to main content
GameDev.net gamedev.net
🔒 Locked

Overloaded Callbacks

Started by Eralp Apr 16, 2009 at 1:02 PM 0 replies 750+ views
Original Post
Eralp
Eralp
Hi, I am not sure where this question belongs it contains networking system in my game.But I think it is mostly a question about how I should design this 'structure' so I wrote it here. I now have a networking class which can get packets.The first char of packets (as usually) decides what kind of function to be called. And next char's are parameters.btw their types and numbers differs from function to function. So here is my question; Where should I "solve" the packets to parameters.I mean should game engine has an function like this HandlePacket(Packet& newPacket)? Or should game engine have many functions like UpdatePlayer()NewPlayer()FireBullet() and pointers to these functions should be in a list of Networking class.Although I find the second way better, It is harder to do (overloaded functions with boost::bind).So is the first way proper or how should I handle this situation. Any help would be greatly appreciated =). I wrote this quickly, so I hope you can understand.
NotAYakk
NotAYakk
At some point you should have a function like HandlePacket(Packet& newPacket).

At some point, the data should be packaged up and passed to functions like UpdatePlayer( player_name, ... ).

Where exactly these functions reside is, to a certain extent, as important as what colour you paint a bikeshed.

I'd be tempted (just tempted) to write code where you pass in your function with its arguments and a function id, and have some generated code (via templates or just good old code generation) spit out code that encapsulates the reading of the data from the network stream.

But I'm weird that way. It could just be as easy (with a limited number of actions) to manually write the 'read from network stream' code for each possible message. I'd find writing that much boilerplate madenning, and enjoy writing the code generator -- so even if the code generator takes more time, I'd be tempted by it. :)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.