--- deliantra/server/socket/image.C 2007/07/05 10:34:08 1.45 +++ deliantra/server/socket/image.C 2007/07/06 03:52:51 1.46 @@ -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 (i, ix); + ns->ixface.insert (pos, 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 }