--- deliantra/server/socket/image.C 2007/07/05 10:34:08 1.45 +++ deliantra/server/socket/image.C 2007/07/12 08:40:14 1.47 @@ -213,19 +213,38 @@ ix.idx = idx; ix.ofs = d->data.size (); - // this is (hopefully) a temporary fix around older cfplus versions not - // supporting interleaved transfers - ns->ixface.insert (ns->ixface.begin (), ix); + auto (pos, ns->ixface.end ()); -#if 0 - // the by far most common case will be to insert - // right at the end, so no looping. - auto (i, ns->ixface.end ()); - for (; i != ns->ixface.begin (); ) - if (pri >= (--i)->pri) - break; + if (ns->fxix < 2) + { + // gcfclient does not support prioritising, older cfplus versions + // do not support interleaved transfers. + if (!ns->ixface.empty ()) + pos = ns->ixface.end () - 1; + } + else + { + // the by far most common case will be to insert + // near the end, so little looping. + while (pos != ns->ixface.begin ()) + { + --pos; + + // sort within 2k bins, to slightly prefer smaller images + if (pri > pos->pri || (pri == pos->pri && (ix.ofs >> 11) <= (pos->ofs >> 11))) + { + ++pos; + break; + } + } + } + + ns->ixface.insert (pos, ix); - ns->ixface.insert (i, ix); +#if 0 + for (auto (i, ns->ixface.begin ()); i != ns->ixface.end (); ++i) + fprintf (stderr, "<%d,%d> ", i->pri, i->ofs); + fprintf (stderr, "\n"); #endif } @@ -289,11 +308,9 @@ return; } - if (faces_sent[facenum]) + if (!must_send_face (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)