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.26 by root, Mon Mar 12 23:45:10 2007 UTC vs.
Revision 1.33 by root, Wed Mar 14 16:23:26 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 uint16 facenum = atoi (buf); 203 ns->send_image (atoi (buf));
204
205 if (facenum != 0)
206 esrv_send_face (ns, facenum, 1);
207} 204}
208 205
209// how lame 206// how lame
210static void print_facename (packet &sl, const facedata &d) 207static void print_facename (packet &sl, const facedata &d)
211{ 208{
212 for (int i = 0; i < CHKSUM_SIZE; ++i) 209 for (int i = 0; i < CHKSUM_SIZE; ++i)
213 sl.printf ("%02x", d.chksum [i]); 210 sl.printf ("%02x", d.chksum [i]);
214} 211}
215 212
216// gcfclient uses the server-provided checksum for comparison, 213// gcfclient uses the server-provided checksum for comparison, but always
217// 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
218// have to provide gcfclient with a useless checksum just to 215// gcfclient with the same broken (and useless) checksum just to have it
219// have to cache the image despite its bugs. 216// cache the image despite its bugs.
220static uint32 gcfclient_checksum (const facedata *d) 217static uint32 gcfclient_checksum (const facedata *d)
221{ 218{
222 uint32 csum = 0; 219 uint32 csum = 0;
223 220
224 for (std::string::const_iterator i = d->data.begin (); 221 for (std::string::const_iterator i = d->data.begin ();
239 * 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
240 * 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,
241 * 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.
242 */ 239 */
243void 240void
244esrv_send_face (client *ns, short face_num, int nocache) 241client::send_face (faceidx facenum)
245{ 242{
246 if (face_num <= 0 || face_num >= faces.size ()) 243 // never send face 0. ever. it does not exist.
244 if (!facenum)
245 return;
246
247 const facedata *d = face_data (facenum, faceset);
248
249 if (!d)
247 { 250 {
248 LOG (llevError, "esrv_send_face (%d) out of bounds??\n", face_num); 251 LOG (llevError, "client::send_face (%d) out of bounds??\n", facenum);
249 return; 252 return;
250 } 253 }
251 254
252 const facedata *d = face_data (face_num, ns->faceset); 255 if (faces_sent[facenum])
256 return;
257
258 faces_sent[facenum] = true;
259
260 if (!facecache)
261 {
262 send_drawinfo (
263 "*** Please enable image/face caching in preferences or use a client that supports it.\n",
264 NDI_RED
265 );
266 return send_image (facenum);
267 }
253 268
254 packet sl; 269 packet sl;
255 270
256 if (ns->facecache && !nocache)
257 {
258 if (ns->force_face0) 271 if (force_face0)
259 sl << "face " << uint16 (face_num); 272 sl << "face " << uint16 (facenum);
260 else if (ns->image2) 273 else if (image2)
261 sl << "face2 " << uint16 (face_num) << uint8 (0) << uint32 (ns->force_bad_checksum ? gcfclient_checksum (d) : 0); 274 sl << "face2 " << uint16 (facenum) << uint8 (0) << uint32 (force_bad_checksum ? gcfclient_checksum (d) : 0);
262 else
263 sl << "face1 " << uint16 (face_num) << uint32 (ns->force_bad_checksum ? gcfclient_checksum (d) : 0);
264
265 // how lame
266 print_facename (sl, *d);
267
268 ns->send_packet (sl);
269 }
270 else 275 else
276 sl << "face1 " << uint16 (facenum) << uint32 (force_bad_checksum ? gcfclient_checksum (d) : 0);
277
278 // how lame
279 print_facename (sl, *d);
280 send_packet (sl);
281
282 faceinfo *f = face_info (facenum);
283 if (f->smooth && EMI_smooth)
284 {
285 send_face (f->smooth);
286
287 packet sl ("smooth");
288
289 sl << uint16 (facenum)
290 << uint16 (f->smooth);
291
292 send_packet (sl);
271 { 293 }
272 fprintf (stderr, "image %s %d\n", &faces [face_num].name, nocache);//D 294}
295
296void
297client::send_image (faceidx facenum)
298{
299 // never send face 0. ever. it does not exist.
300 if (!facenum)
301 return;
302
303 const facedata *d = face_data (facenum, faceset);
304
305 if (!d)
306 {
307 LOG (llevError, "client::send_image (%d) out of bounds??\n", facenum);
308 return;
309 }
310
311 packet sl;
312
273 sl << (ns->image2 ? "image2 " : "image ") 313 sl << (image2 ? "image2 " : "image ")
274 << uint32 (face_num); 314 << uint32 (facenum);
275 315
276 if (ns->image2) 316 if (image2)
277 sl << uint8 (0); 317 sl << uint8 (0);
278 318
279 sl << uint32 (d->data.size ()) 319 sl << uint32 (d->data.size ())
280 << data (d->data.data (), d->data.size ()); 320 << data (d->data.data (), d->data.size ());
281 321
282 ns->send_packet (sl); 322 send_packet (sl);
323}
324
325// send all faces of this object to the client
326// this uses more bandwidth initially, but makes
327// animations look much smoother, and every client
328// is supposed to do client-side caching anyways.
329void
330client::send_faces (object *ob)
331{
332 send_face (ob->face);
333
334 if (ob->animation_id)
283 } 335 {
336 animation &anim = animations [ob->animation_id];
284 337
285 ns->faces_sent[face_num] |= NS_FACESENT_FACE; 338 for (int i = 0; i < anim.num_animations; i++)
339 send_face (anim.faces [i]);
340 }
341}
342
343/**
344 * Need to send an animation sequence to the client.
345 * We will send appropriate face commands to the client if we haven't
346 * sent them the face yet (this can become quite costly in terms of
347 * how much we are sending - on the other hand, this should only happen
348 * when the player logs in and picks stuff up.
349 */
350void
351client::send_animation (short anim_num)
352{
353 /* Do some checking on the anim_num we got. Note that the animations
354 * are added in contigous order, so if the number is in the valid
355 * range, it must be a valid animation.
356 */
357 if (anim_num < 0 || anim_num > num_animations)
358 {
359 LOG (llevError, "esrv_send_anim (%d) out of bounds??\n", anim_num);
360 return;
361 }
362
363 packet sl ("anim");
364
365 sl << uint16 (anim_num)
366 << uint16 (0); /* flags - not used right now */
367
368 /* Build up the list of faces. Also, send any information (ie, the
369 * the face itself) down to the client.
370 */
371 for (int i = 0; i < animations[anim_num].num_animations; i++)
372 {
373 send_face (animations[anim_num].faces[i]);
374 sl << uint16 (animations[anim_num].faces[i]); /* flags - not used right now */
375 }
376
377 send_packet (sl);
378
379 anims_sent[anim_num] = 1;
286} 380}
287 381
288/** 382/**
289 * Sends the number of images, checksum of the face file, 383 * Sends the number of images, checksum of the face file,
290 * and the image_info file information. See the doc/Developers/protocol 384 * and the image_info file information. See the doc/Developers/protocol
291 * if you want further detail. 385 * if you want further detail.
292 */ 386 */
293
294void 387void
295send_image_info (client *ns, char *params) 388send_image_info (client *ns, char *params)
296{ 389{
297 packet sl; 390 packet sl;
298 391
337 430
338 sl.printf ("replyinfo image_sums %d %d ", start, stop); 431 sl.printf ("replyinfo image_sums %d %d ", start, stop);
339 432
340 for (int i = start; i <= stop && i < faces.size (); i++) 433 for (int i = start; i <= stop && i < faces.size (); i++)
341 { 434 {
342 ns->faces_sent[i] |= NS_FACESENT_FACE; 435 ns->faces_sent[i] = true;
343 436
344 const facedata *d = face_data (i, ns->faceset); 437 const facedata *d = face_data (i, ns->faceset);
345 438
346 if (sl.room () < 2 + 4 + 1 + d->data.size () + 1) 439 if (sl.room () < 2 + 4 + 1 + d->data.size () + 1)
347 break; 440 break;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines