[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.2 The client base library: libggzmod

This is a short description of ggzmod. Please see the API documentation for details.

A launched game client gets a control channel on its way, which it connects to a callback to receive control messages. Then it requests a direct game connection, which results in the creation of a game channel, which gets connected to a callback too. This game channel is then used to communicate with the game server.

A basic ggzmod usage may look like this:

@verbatim static void handle_ggz(gpointer data, gint source, GdkInputCondition cond) { ggzmod_dispatch(ggzmod); }

static void handle_ggzmod_server(GGZMod * ggzmod, GGZModEvent e, void *data) { int fd = *(int*)data; ggzmod_set_state(ggzmod, GGZMOD_STATE_PLAYING); gdk_input_add(fd, GDK_INPUT_READ, game_handle_io, NULL); }

int main() { ... GGZMod *ggzmod;

ggzmod = ggzmod_new(GGZMOD_GAME); ggzmod_set_handler(ggzmod, GGZMOD_EVENT_SERVER, &handle_ggzmod_server); ... ggzmod_connect(ggzmod); gdk_input_add(ggzmod_get_fd(ggzmod), GDK_INPUT_READ, handle_ggz, NULL); ... ggzmod_disconnect(ggzmod) ggzmod_free(game.ggzmod); ... }

(Note that this is for a Gtk+ game client written in C. Things will differ for other toolkits like Qt, and other programming languages like C++. Also, return values should be checked and such.)



This document was generated by Abel Cheung on December, 2 2004 using texi2html