--- deliantra/server/socket/image.C 2007/07/12 18:48:54 1.49 +++ deliantra/server/socket/image.C 2007/07/24 04:55:34 1.50 @@ -37,139 +37,6 @@ #include "crc.h" -#define MAX_FACE_SETS 20 /**< Maximum number of image sets the program will handle */ - -/** Information about one image */ -typedef struct FaceInfo -{ - uint8 *data; /**< image data */ - uint16 datalen; /**< length of the xpm data */ - uint32 checksum; /**< Checksum of face data */ -} FaceInfo; - -/** Information about one face set */ -typedef struct -{ - char *prefix; /**< */ - char *fullname; - - uint8 fallback; /**< faceset to use when an image is not found in this faceset */ - char *size; - char *extension; - char *comment; - - FaceInfo *faces; /**< images in this faceset */ -} FaceSets; - -static FaceSets facesets[MAX_FACE_SETS]; /**< All facesets */ - -/** - * Checks specified faceset is valid - * \param fsn faceset number - */ -int -is_valid_faceset (int fsn) -{ - if (fsn >= 0 && fsn < MAX_FACE_SETS && facesets[fsn].prefix) - return TRUE; - return FALSE; -} - -/** - * Frees all faceset information - */ -void -free_socket_images (void) -{ - int num, q; - - for (num = 0; num < MAX_FACE_SETS; num++) - { - if (facesets[num].prefix) - { - for (q = 0; q < faces.size (); q++) - if (facesets[num].faces[q].data) - free (facesets[num].faces[q].data); - - free (facesets[num].prefix); - free (facesets[num].fullname); - free (facesets[num].size); - free (facesets[num].extension); - free (facesets[num].comment); - free (facesets[num].faces); - } - } -} - -/** - * This returns the set we will actually use when sending - * a face. This is used because the image files may be sparse. - * This function is recursive. imageno is the face number we are - * trying to send - * - * If face is not found in specified faceset, tries with 'fallback' faceset. - * - * \param faceset faceset to check - * \param imageno image number - * - */ -static int -get_face_fallback (int faceset, int imageno) -{ - /* faceset 0 is supposed to have every image, so just return. Doing - * so also prevents infinite loops in the case if it not having - * the face, but in that case, we are likely to crash when we try - * to access the data, but that is probably preferable to an infinite - * loop. - */ - if (faceset == 0) - return 0; - - if (!facesets[faceset].prefix) - { - LOG (llevError, "get_face_fallback called with unused set (%d)?\n", faceset); - return 0; /* use default set */ - } - - if (facesets[faceset].faces[imageno].data) - return faceset; - - return get_face_fallback (facesets[faceset].fallback, imageno); -} - -/** - * Checks fallback are correctly defined. - * This is a simple recursive function that makes sure the fallbacks - * are all proper (eg, the fall back to defined sets, and also - * eventually fall back to 0). At the top level, togo is set to MAX_FACE_SETS, - * if togo gets to zero, it means we have a loop. - * This is only run when we first load the facesets. - */ -static void -check_faceset_fallback (int faceset, int togo) -{ - int fallback = facesets[faceset].fallback; - - /* proper case - falls back to base set */ - if (fallback == 0) - return; - - if (!facesets[fallback].prefix) - { - LOG (llevError, "Face set %d falls to non set faceset %d\n", faceset, fallback); - abort (); - } - - togo--; - if (togo == 0) - { - LOG (llevError, "Infinite loop found in facesets. aborting.\n"); - abort (); - } - - check_faceset_fallback (fallback, togo); -} - #define MAX_IMAGE_SIZE 10000 /** @@ -255,7 +122,7 @@ void AskSmooth (char *buf, int len, client *ns) { - ns->send_face (atoi (buf)); + ns->send_face (atoi (buf), -100); ns->flush_fx (); } @@ -294,29 +161,29 @@ * we look at the facecache, and if set, send the image name. */ void -client::send_face (faceidx facenum) +client::send_face (faceidx facenum, int pri) { // never send face 0. ever. it does not exist. if (!facenum) return; - const facedata *d = face_data (facenum, faceset); + faceinfo *f = face_info (facenum); - if (!d) + if (!f) { LOG (llevError, "client::send_face (%d) out of bounds??\n", facenum); return; } - faceinfo *f = face_info (facenum); - - // refuse tos end non-image faces - if (f->type) + // refuse to send non-image faces + if (!fx_want [f->type]) return; - if (!must_send_face (facenum)) + if (faces_sent [facenum]) return; + faces_sent[facenum] = true; + // if for some reason we let a client without face caching connect, // we better support that decision here and implement it. if (!facecache) @@ -328,6 +195,8 @@ return; } + const facedata *d = f->data (faceset); + packet sl; if (force_face0) @@ -363,15 +232,24 @@ { packet fx ("fx"); packet sx ("sx"); + int type = 0; do { faceidx facenum = fxface.back (); fxface.pop_back (); - const facedata *d = face_data (facenum, faceset); - - if (d) + if (const faceinfo *f = face_info (facenum)) { + if (f->type != type) + { + type = f->type; + + fx << ber32 (0) + << uint8 (1) << uint8 (type); + } + + const facedata *d = f->data (faceset); + fx << ber32 (facenum) << data8 (d->chksum, CHKSUM_SIZE); @@ -381,7 +259,8 @@ if (f->smooth) { - send_face (f->smooth); + send_face (f->smooth, -110); + sx << ber32 (facenum) << ber32 (f->smooth) << ber32 (f->smoothlevel); @@ -390,7 +269,7 @@ } } while (!fxface.empty () - && fx.room () > ber32::size + CHKSUM_SIZE + 1 + && fx.room () > ber32::size + CHKSUM_SIZE + 1 + 3 /* type switch */ && sx.room () > ber32::size * 3); send_packet (fx); @@ -441,14 +320,14 @@ void client::send_faces (object *ob) { - send_face (ob->face); + send_face (ob->face, 10); if (ob->animation_id) { animation &anim = animations [ob->animation_id]; for (int i = 0; i < anim.num_animations; i++) - send_face (anim.faces [i]); + send_face (anim.faces [i], -10); } } @@ -482,7 +361,7 @@ */ for (int i = 0; i < animations[anim_num].num_animations; i++) { - send_face (animations[anim_num].faces[i]); + send_face (animations[anim_num].faces[i], -20); sl << uint16 (animations[anim_num].faces[i]); /* flags - not used right now */ }