vg4->nw->update()
Retrieve input-events and receive from and send to network-server.
SYNTAX
FUNCTION PARAMETERS
dowait | For returning whether to wait in the game-loop: - VG_TRUE: yes, as no subsequent package is available - VG_FALSE: no, as subsequent packages are available |
zdata | For returning received additional-data |
RETURN VALUE
Returns boolean:
- VG_TRUE: OK
- VG_FALSE: Got exit-request (or network-error occurred)
DESCRIPTION
Retrieve input-events and receive from and send to network-server.
Receive also an update which clients are connected.
This function must be used instead of vg4->input->update() for network-games in the game-loop.
EXAMPLE
VG_BOOL dowait; struct VG_NwZdata nw_zdata; int clnr, clmax, icl; struct { int k_quit; int k_nw_fire; } kref; [...] /* set QUIT-key as local key */ if ((kref.k_quit = vg4->input->key_insert("Quit", VG_FALSE, VG_FALSE)) == 0) { VG_dest(); exit(1); } vg4->input->key_setkbd(kref.k_quit, VG_INPUT_KBDCODE_Q); /* set FIRE-key as network-key */ if ((kref.k_nw_fire = vg4->input->key_insert("Fire", VG_FALSE, VG_TRUE)) == 0) { VG_dest(); exit(1); } vg4->input->key_setkbd(kref.k_nw_fire, VG_INPUT_KBDCODE_SPACE); /* connect, get in clnr client-number of local client */ [...] clmax = vg4->nw->numberofclients(NULL); /* game loop */ for (;;) { if (!vg4->nw->update(&dowait, &nw_zdata)) { break; } /* check if local client is still connected */ if (!vg4->nw->is_connected(clnr)) { break; } /* check local QUIT-key */ if (vg4->input->key_newpressed(kref.k_quit)) { break; } vg4->window->clear(); /* for each player */ for (icl = 1; icl <= clmax; icl++) { /* still connected? */ if (!vg4->nw->is_connected(icl)) { continue; } /* check player's input-events */ if (vg4->nw->key_pressed(icl, kref.k_nw_fire)) { /* player icl has pressed FIRE-key */ } } vg4->window->flush(); if (dowait) { vg4->misc->wait_time(50); } }
SEE ALSO