--- deliantra/server/socket/image.C 2007/03/14 01:19:10 1.30 +++ deliantra/server/socket/image.C 2007/04/10 09:35:24 1.40 @@ -200,7 +200,7 @@ void SendFaceCmd (char *buf, int len, client *ns) { - ns->send_face (atoi (buf), 1); + ns->send_image (atoi (buf)); } // how lame @@ -210,10 +210,10 @@ sl.printf ("%02x", d.chksum [i]); } -// gcfclient uses the server-provided checksum for comparison, -// but always wrotes a broken checksum to its cache file, so we -// have to provide gcfclient with a useless checksum just to -// have to cache the image despite its bugs. +// gcfclient uses the server-provided checksum for comparison, but always +// writes a broken checksum to its cache file, so we have to provide +// gcfclient with the same broken (and useless) checksum just to have it +// cache the image despite its bugs. static uint32 gcfclient_checksum (const facedata *d) { uint32 csum = 0; @@ -238,7 +238,7 @@ * we look at the facecache, and if set, send the image name. */ void -client::send_face (faceidx facenum, bool forced) +client::send_face (faceidx facenum) { // never send face 0. ever. it does not exist. if (!facenum) @@ -252,17 +252,40 @@ return; } - packet sl; + if (faces_sent[facenum]) + return; + + faces_sent[facenum] = true; - if (facecache && !forced) + // if for some reason we let a client without face caching connect, + // we better support that decision here and implement it. + if (!facecache) + return send_image (facenum); + + if (fxix) { - if (faces_sent[facenum]) - return; + fxface.push_back (facenum); + return; + } - faces_sent[facenum] = true; + packet sl; + + if (force_face0) + sl << "face " << uint16 (facenum); + else if (image2) + sl << "face2 " << uint16 (facenum) << uint8 (0) << uint32 (force_bad_checksum ? gcfclient_checksum (d) : 0); + else + sl << "face1 " << uint16 (facenum) << uint32 (force_bad_checksum ? gcfclient_checksum (d) : 0); + + // how lame + print_facename (sl, *d); + send_packet (sl); + if (EMI_smooth) + { faceinfo *f = face_info (facenum); - if (f->smooth && EMI_smooth) + + if (f->smooth) { send_face (f->smooth); @@ -273,29 +296,81 @@ send_packet (sl); } + } +} + +void client::flush_fx () +{ + while (!fxface.empty ()) + { + packet fx ("fx"); + packet sx ("sx"); + + do + { + faceidx facenum = fxface.back (); fxface.pop_back (); + + const facedata *d = face_data (facenum, faceset); - if (force_face0) - sl << "face " << uint16 (facenum); - else if (image2) - sl << "face2 " << uint16 (facenum) << uint8 (0) << uint32 (force_bad_checksum ? gcfclient_checksum (d) : 0); - else - sl << "face1 " << uint16 (facenum) << uint32 (force_bad_checksum ? gcfclient_checksum (d) : 0); + if (d) + { + fx << ber32 (facenum) + << data8 (d->chksum, CHKSUM_SIZE); + + if (smoothing) + { + faceinfo *f = face_info (facenum); + + if (f->smooth) + { + send_face (f->smooth); + sx << ber32 (facenum) + << ber32 (f->smooth) + << ber32 (f->smoothlevel); + } + } + } + } + while (!fxface.empty () + && fx.room () > ber32::size + CHKSUM_SIZE + 1 + && sx.room () > ber32::size * 3); - // how lame - print_facename (sl, *d); + send_packet (fx); + if (sx.length () > 3) send_packet (sx); } - else - { - sl << (image2 ? "image2 " : "image ") - << uint32 (facenum); +} - if (image2) - sl << uint8 (0); +void +client::send_image (faceidx facenum) +{ + // never send face 0. ever. it does not exist. + if (!facenum) + return; + + const facedata *d = face_data (facenum, faceset); - sl << uint32 (d->data.size ()) - << data (d->data.data (), d->data.size ()); + if (!d) + { + LOG (llevError, "client::send_image (%d) out of bounds??\n", facenum); + return; } + faces_sent[facenum] = true; + + if (force_image_newmap) + force_newmap = true; + + packet sl; + + sl << (image2 ? "image2 " : "image ") + << uint32 (facenum); + + if (image2) + sl << uint8 (0); + + sl << uint32 (d->data.size ()) + << data (d->data.data (), d->data.size ()); + send_packet (sl); }