--- deliantra/server/socket/image.C 2007/03/12 23:45:37 1.27 +++ deliantra/server/socket/image.C 2007/03/14 00:07:26 1.29 @@ -200,10 +200,7 @@ void SendFaceCmd (char *buf, int len, client *ns) { - uint16 facenum = atoi (buf); - - if (facenum != 0) - esrv_send_face (ns, facenum, 1); + ns->send_face (atoi (buf), 1); } // how lame @@ -241,47 +238,148 @@ * we look at the facecache, and if set, send the image name. */ void -esrv_send_face (client *ns, short face_num, int nocache) +client::send_face (faceidx facenum, bool forced) { - if (face_num <= 0 || face_num >= faces.size ()) + // never send face 0. ever. it does not exist. + if (!facenum) + return; + + const facedata *d = face_data (facenum, faceset); + + if (!d) { - LOG (llevError, "esrv_send_face (%d) out of bounds??\n", face_num); + LOG (llevError, "client::send_face (%d) out of bounds??\n", facenum); return; } - const facedata *d = face_data (face_num, ns->faceset); - packet sl; - if (ns->facecache && !nocache) + if (facecache && !forced) { - if (ns->force_face0) - sl << "face " << uint16 (face_num); - else if (ns->image2) - sl << "face2 " << uint16 (face_num) << uint8 (0) << uint32 (ns->force_bad_checksum ? gcfclient_checksum (d) : 0); + if (faces_sent[facenum] & NS_FACESENT_FACE) + return; + + faces_sent[facenum] |= NS_FACESENT_FACE; + + 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 (face_num) << uint32 (ns->force_bad_checksum ? gcfclient_checksum (d) : 0); + sl << "face1 " << uint16 (facenum) << uint32 (force_bad_checksum ? gcfclient_checksum (d) : 0); // how lame print_facename (sl, *d); - - ns->send_packet (sl); } else { - sl << (ns->image2 ? "image2 " : "image ") - << uint32 (face_num); + sl << (image2 ? "image2 " : "image ") + << uint32 (facenum); - if (ns->image2) + if (image2) sl << uint8 (0); sl << uint32 (d->data.size ()) << data (d->data.data (), d->data.size ()); + } + + send_packet (sl); +} + +// send all faces of this object to the client +// this uses more bandwidth initially, but makes +// animations look much smoother, and every client +// is supposed to do client-side caching anyways. +void +client::send_faces (object *ob) +{ + send_face (ob->face); + + if (ob->animation_id) + { + animation &anim = animations [ob->animation_id]; + + for (int i = 0; i < anim.num_animations; i++) + send_face (anim.faces [i]); + } +} + +/** + * A lot like the old AskSmooth (in fact, now called by AskSmooth). + * Basically, it makes no sense to wait for the client to request a + * a piece of data from us that we know the client wants. So + * if we know the client wants it, might as well push it to the + * client. + */ +void +client::send_smooth (faceidx face) +{ + faceinfo *f = face_info (face); + + if (!f) + return; - ns->send_packet (sl); + if (faces_sent[face] & NS_FACESENT_SMOOTH) + return; + + faces_sent[face] |= NS_FACESENT_SMOOTH; + + /* If we can't find a face, return and set it so we won't try to send this + * again. + */ + if (!f->smooth) + { + LOG (llevError, "could not findsmooth for %d.\n", face); + return; + } + + send_face (f->smooth); + + packet sl ("smooth"); + + sl << uint16 (face) + << uint16 (f->smooth); + + send_packet (sl); +} + +/** + * Need to send an animation sequence to the client. + * We will send appropriate face commands to the client if we haven't + * sent them the face yet (this can become quite costly in terms of + * how much we are sending - on the other hand, this should only happen + * when the player logs in and picks stuff up. + */ +void +client::send_animation (short anim_num) +{ + /* Do some checking on the anim_num we got. Note that the animations + * are added in contigous order, so if the number is in the valid + * range, it must be a valid animation. + */ + if (anim_num < 0 || anim_num > num_animations) + { + LOG (llevError, "esrv_send_anim (%d) out of bounds??\n", anim_num); + return; + } + + packet sl ("anim"); + + sl << uint16 (anim_num) + << uint16 (0); /* flags - not used right now */ + + /* Build up the list of faces. Also, send any information (ie, the + * the face itself) down to the client. + */ + for (int i = 0; i < animations[anim_num].num_animations; i++) + { + send_face (animations[anim_num].faces[i]); + sl << uint16 (animations[anim_num].faces[i]); /* flags - not used right now */ } - ns->faces_sent[face_num] |= NS_FACESENT_FACE; + send_packet (sl); + + anims_sent[anim_num] = 1; } /** @@ -289,7 +387,6 @@ * and the image_info file information. See the doc/Developers/protocol * if you want further detail. */ - void send_image_info (client *ns, char *params) {