ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/socket/image.C
(Generate patch)

Comparing deliantra/server/socket/image.C (file contents):
Revision 1.28 by root, Wed Mar 14 00:04:59 2007 UTC vs.
Revision 1.41 by root, Thu Apr 12 14:18:06 2007 UTC

198 * caching images. 198 * caching images.
199 */ 199 */
200void 200void
201SendFaceCmd (char *buf, int len, client *ns) 201SendFaceCmd (char *buf, int len, client *ns)
202{ 202{
203 ns->send_face (atoi (buf), 1); 203 ns->send_image (atoi (buf));
204} 204}
205 205
206// how lame 206// how lame
207static void print_facename (packet &sl, const facedata &d) 207static void print_facename (packet &sl, const facedata &d)
208{ 208{
209 for (int i = 0; i < CHKSUM_SIZE; ++i) 209 for (int i = 0; i < CHKSUM_SIZE; ++i)
210 sl.printf ("%02x", d.chksum [i]); 210 sl.printf ("%02x", d.chksum [i]);
211} 211}
212 212
213// gcfclient uses the server-provided checksum for comparison, 213// gcfclient uses the server-provided checksum for comparison, but always
214// but always wrotes a broken checksum to its cache file, so we 214// writes a broken checksum to its cache file, so we have to provide
215// have to provide gcfclient with a useless checksum just to 215// gcfclient with the same broken (and useless) checksum just to have it
216// have to cache the image despite its bugs. 216// cache the image despite its bugs.
217static uint32 gcfclient_checksum (const facedata *d) 217static uint32 gcfclient_checksum (const facedata *d)
218{ 218{
219 uint32 csum = 0; 219 uint32 csum = 0;
220 220
221 for (std::string::const_iterator i = d->data.begin (); 221 for (std::string::const_iterator i = d->data.begin ();
236 * this is needed for the askface, in which we really do want to send the 236 * this is needed for the askface, in which we really do want to send the
237 * face (and askface is the only place that should be setting it). Otherwise, 237 * face (and askface is the only place that should be setting it). Otherwise,
238 * we look at the facecache, and if set, send the image name. 238 * we look at the facecache, and if set, send the image name.
239 */ 239 */
240void 240void
241client::send_face (faceidx facenum, bool forced) 241client::send_face (faceidx facenum)
242{ 242{
243 // never send face 0. ever. it does not exist. 243 // never send face 0. ever. it does not exist.
244 if (!facenum) 244 if (!facenum)
245 return; 245 return;
246 246
250 { 250 {
251 LOG (llevError, "client::send_face (%d) out of bounds??\n", facenum); 251 LOG (llevError, "client::send_face (%d) out of bounds??\n", facenum);
252 return; 252 return;
253 } 253 }
254 254
255 if (faces_sent[facenum])
256 return;
257
258 faces_sent[facenum] = true;
259
260 // if for some reason we let a client without face caching connect,
261 // we better support that decision here and implement it.
262 if (!facecache)
263 return send_image (facenum);
264
265 if (fxix)
266 {
267 fxface.push_back (facenum);
268 return;
269 }
270
255 packet sl; 271 packet sl;
256 272
257 if (facecache && !forced)
258 {
259 if (faces_sent[facenum] & NS_FACESENT_FACE)
260 return;
261
262 faces_sent[facenum] |= NS_FACESENT_FACE;
263
264 if (force_face0) 273 if (force_face0)
265 sl << "face " << uint16 (facenum); 274 sl << "face " << uint16 (facenum);
266 else if (image2) 275 else if (image2)
267 sl << "face2 " << uint16 (facenum) << uint8 (0) << uint32 (force_bad_checksum ? gcfclient_checksum (d) : 0); 276 sl << "face2 " << uint16 (facenum) << uint8 (0) << uint32 (force_bad_checksum ? gcfclient_checksum (d) : 0);
268 else
269 sl << "face1 " << uint16 (facenum) << uint32 (force_bad_checksum ? gcfclient_checksum (d) : 0);
270
271 // how lame
272 print_facename (sl, *d);
273 }
274 else 277 else
278 sl << "face1 " << uint16 (facenum) << uint32 (force_bad_checksum ? gcfclient_checksum (d) : 0);
279
280 // how lame
281 print_facename (sl, *d);
282 send_packet (sl);
283
284 if (EMI_smooth)
285 {
286 faceinfo *f = face_info (facenum);
287
288 if (f->smooth)
289 {
290 send_face (f->smooth);
291
292 packet sl ("smooth");
293
294 sl << uint16 (facenum)
295 << uint16 (f->smooth);
296
297 send_packet (sl);
298 }
275 { 299 }
276 fprintf (stderr, "image %d\n", facenum);//D 300}
301
302void client::flush_fx ()
303{
304 while (!fxface.empty ())
305 {
306 packet fx ("fx");
307 packet sx ("sx");
308
309 do
310 {
311 faceidx facenum = fxface.back (); fxface.pop_back ();
312
313 const facedata *d = face_data (facenum, faceset);
314
315 if (d)
316 {
317 fx << ber32 (facenum)
318 << data8 (d->chksum, CHKSUM_SIZE);
319
320 if (smoothing)
321 {
322 faceinfo *f = face_info (facenum);
323
324 if (f->smooth)
325 {
326 send_face (f->smooth);
327 sx << ber32 (facenum)
328 << ber32 (f->smooth)
329 << ber32 (f->smoothlevel);
330 }
331 }
332 }
333 }
334 while (!fxface.empty ()
335 && fx.room () > ber32::size + CHKSUM_SIZE + 1
336 && sx.room () > ber32::size * 3);
337
338 send_packet (fx);
339 if (sx.length () > 3) send_packet (sx);
340 }
341}
342
343void
344client::send_image (faceidx facenum)
345{
346 // never send face 0. ever. it does not exist.
347 if (!facenum)
348 return;
349
350 const facedata *d = face_data (facenum, faceset);
351
352 if (!d)
353 {
354 LOG (llevError, "client::send_image (%d) out of bounds??\n", facenum);
355 return;
356 }
357
358 faces_sent[facenum] = true;
359
360 if (force_image_newmap)
361 force_newmap = true;
362
363 packet sl;
364
277 sl << (image2 ? "image2 " : "image ") 365 sl << (image2 ? "image2 " : "image ")
278 << uint32 (facenum); 366 << uint32 (facenum);
279 367
280 if (image2) 368 if (image2)
281 sl << uint8 (0); 369 sl << uint8 (0);
282 370
283 sl << uint32 (d->data.size ()) 371 sl << uint32 (d->data.size ())
284 << data (d->data.data (), d->data.size ()); 372 << data (d->data.data (), d->data.size ());
285 }
286 373
287 send_packet (sl); 374 send_packet (sl);
288} 375}
289 376
290// send all faces of this object to the client 377// send all faces of this object to the client
301 animation &anim = animations [ob->animation_id]; 388 animation &anim = animations [ob->animation_id];
302 389
303 for (int i = 0; i < anim.num_animations; i++) 390 for (int i = 0; i < anim.num_animations; i++)
304 send_face (anim.faces [i]); 391 send_face (anim.faces [i]);
305 } 392 }
306}
307
308/**
309 * A lot like the old AskSmooth (in fact, now called by AskSmooth).
310 * Basically, it makes no sense to wait for the client to request a
311 * a piece of data from us that we know the client wants. So
312 * if we know the client wants it, might as well push it to the
313 * client.
314 */
315void
316client::send_smooth (faceidx face)
317{
318 faceinfo *f = face_info (face);
319
320 if (!f)
321 return;
322
323 if (faces_sent[face] & NS_FACESENT_SMOOTH)
324 return;
325
326 faces_sent[face] |= NS_FACESENT_SMOOTH;
327
328 /* If we can't find a face, return and set it so we won't try to send this
329 * again.
330 */
331 if (!f->smooth)
332 {
333 LOG (llevError, "could not findsmooth for %d.\n", face);
334 return;
335 }
336
337 send_face (f->smooth);
338
339 packet sl ("smooth");
340
341 sl << uint16 (face)
342 << uint16 (f->smooth);
343
344 send_packet (sl);
345} 393}
346 394
347/** 395/**
348 * Need to send an animation sequence to the client. 396 * Need to send an animation sequence to the client.
349 * We will send appropriate face commands to the client if we haven't 397 * We will send appropriate face commands to the client if we haven't
356{ 404{
357 /* Do some checking on the anim_num we got. Note that the animations 405 /* Do some checking on the anim_num we got. Note that the animations
358 * are added in contigous order, so if the number is in the valid 406 * are added in contigous order, so if the number is in the valid
359 * range, it must be a valid animation. 407 * range, it must be a valid animation.
360 */ 408 */
361 if (anim_num < 0 || anim_num > num_animations) 409 if (anim_num < 0 || anim_num >= animations.size ())
362 { 410 {
363 LOG (llevError, "esrv_send_anim (%d) out of bounds??\n", anim_num); 411 LOG (llevError, "esrv_send_anim (%d) out of bounds??\n", anim_num);
364 return; 412 return;
365 } 413 }
366 414
434 482
435 sl.printf ("replyinfo image_sums %d %d ", start, stop); 483 sl.printf ("replyinfo image_sums %d %d ", start, stop);
436 484
437 for (int i = start; i <= stop && i < faces.size (); i++) 485 for (int i = start; i <= stop && i < faces.size (); i++)
438 { 486 {
439 ns->faces_sent[i] |= NS_FACESENT_FACE; 487 ns->faces_sent[i] = true;
440 488
441 const facedata *d = face_data (i, ns->faceset); 489 const facedata *d = face_data (i, ns->faceset);
442 490
443 if (sl.room () < 2 + 4 + 1 + d->data.size () + 1) 491 if (sl.room () < 2 + 4 + 1 + d->data.size () + 1)
444 break; 492 break;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines