--- deliantra/server/socket/loop.C 2007/01/20 13:47:17 1.39 +++ deliantra/server/socket/loop.C 2007/03/15 03:30:37 1.42 @@ -32,6 +32,7 @@ * maintanance (checking for lost connections and if data has arrived.) */ +#define BG_SCRUB_RATE 4 // how often to send a face in the background #include #include @@ -138,35 +139,62 @@ #endif //TODO: should not be done here, either - for (int i = 0; i < clients.size (); ++i) + for (unsigned i = 0; i < clients.size (); ++i) { - client *s = clients [i]; - player *pl = s->pl; + client *ns = clients [i]; - if (pl && pl->ns && !pl->ns->destroyed ()) - { - client *ns = pl->ns; + ns->tick (); + ns->refcnt_chk (); + } +} - /* Update the players stats once per tick. More efficient than - * sending them whenever they change, and probably just as useful - */ - esrv_update_stats (pl); +void +client::tick () +{ + if (!pl || destroyed ()) + return; - if (ns->last_weight != -1 && ns->last_weight != WEIGHT (pl->ob)) - { - esrv_update_item (UPD_WEIGHT, pl->ob, pl->ob); - if (ns->last_weight != WEIGHT (pl->ob)) - LOG (llevError, "esrv_update_item(UPD_WEIGHT) did not set player weight: is %lu, should be %lu\n", - (unsigned long) ns->last_weight, WEIGHT (pl->ob)); - } + /* Update the players stats once per tick. More efficient than + * sending them whenever they change, and probably just as useful + */ + esrv_update_stats (pl); - draw_client_map (pl->ob); + if (last_weight != -1 && last_weight != WEIGHT (pl->ob)) + { + esrv_update_item (UPD_WEIGHT, pl->ob, pl->ob); + if (last_weight != WEIGHT (pl->ob)) + LOG (llevError, "esrv_update_item(UPD_WEIGHT) did not set player weight: is %lu, should be %lu\n", + (unsigned long) last_weight, WEIGHT (pl->ob)); + } - if (s->update_look) - esrv_draw_look (pl->ob); - } + draw_client_map (pl->ob); - s->refcnt_chk (); + if (update_look) + esrv_draw_look (pl->ob); + + if (askface.empty ()) + { + if (bg_scrub && !--bg_scrub) + while (scrub_idx < faces.size () - 1) + { + ++scrub_idx; + if (!faces_sent [scrub_idx]) + { + send_face (scrub_idx); + bg_scrub = 1; // send up to one face per tick, unless an image was requested + break; + } + } } -} + else + while (!askface.empty () && outputbuffer_len () < max_rate) + { + // use a lifo to send most recently requested images + faceidx face = askface.back (); + askface.pop_back (); + send_image (face); + + bg_scrub = BG_SCRUB_RATE; + } +}