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.25 by root, Sun Mar 11 20:25:37 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]);
211}
212
213// gcfclient uses the server-provided checksum for comparison, but always
214// writes a broken checksum to its cache file, so we have to provide
215// gcfclient with the same broken (and useless) checksum just to have it
216// cache the image despite its bugs.
217static uint32 gcfclient_checksum (const facedata *d)
218{
219 uint32 csum = 0;
220
221 for (std::string::const_iterator i = d->data.begin ();
222 i != d->data.end ();
223 ++i)
224 {
225 csum = rotate_right (csum);
226 csum += *(uint8 *)&*i;
227 }
228
229 return csum;
214} 230}
215 231
216/** 232/**
217 * Sends a face to a client if they are in pixmap mode 233 * Sends a face to a client if they are in pixmap mode
218 * nothing gets sent in bitmap mode. 234 * nothing gets sent in bitmap mode.
220 * 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
221 * 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,
222 * 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.
223 */ 239 */
224void 240void
225esrv_send_face (client *ns, short face_num, int nocache) 241client::send_face (faceidx facenum)
226{ 242{
227 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)
228 { 250 {
229 LOG (llevError, "esrv_send_face (%d) out of bounds??\n", face_num); 251 LOG (llevError, "client::send_face (%d) out of bounds??\n", facenum);
230 return; 252 return;
231 } 253 }
232 254
233 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 }
234 268
235 packet sl; 269 packet sl;
236 270
237 if (ns->facecache && !nocache) 271 if (force_face0)
238 { 272 sl << "face " << uint16 (facenum);
239 sl << (ns->image2 ? "face2 " : "face1 ") 273 else if (image2)
240 << uint16 (face_num); 274 sl << "face2 " << uint16 (facenum) << uint8 (0) << uint32 (force_bad_checksum ? gcfclient_checksum (d) : 0);
241
242 if (ns->image2)
243 sl << uint8 (0);
244
245 sl << uint32 (0);
246
247 // how lame
248 print_facename (sl, *d);
249
250 ns->send_packet (sl);
251 }
252 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);
253 { 293 }
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
254 sl << (ns->image2 ? "image2 " : "image ") 313 sl << (image2 ? "image2 " : "image ")
255 << uint32 (face_num); 314 << uint32 (facenum);
256 315
257 if (ns->image2) 316 if (image2)
258 sl << uint8 (0); 317 sl << uint8 (0);
259 318
260 sl << uint32 (d->data.size ()) 319 sl << uint32 (d->data.size ())
261 << data (d->data.data (), d->data.size ()); 320 << data (d->data.data (), d->data.size ());
262 321
263 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)
264 } 335 {
336 animation &anim = animations [ob->animation_id];
265 337
266 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;
267} 380}
268 381
269/** 382/**
270 * Sends the number of images, checksum of the face file, 383 * Sends the number of images, checksum of the face file,
271 * and the image_info file information. See the doc/Developers/protocol 384 * and the image_info file information. See the doc/Developers/protocol
272 * if you want further detail. 385 * if you want further detail.
273 */ 386 */
274
275void 387void
276send_image_info (client *ns, char *params) 388send_image_info (client *ns, char *params)
277{ 389{
278 packet sl; 390 packet sl;
279 391
318 430
319 sl.printf ("replyinfo image_sums %d %d ", start, stop); 431 sl.printf ("replyinfo image_sums %d %d ", start, stop);
320 432
321 for (int i = start; i <= stop && i < faces.size (); i++) 433 for (int i = start; i <= stop && i < faces.size (); i++)
322 { 434 {
323 ns->faces_sent[i] |= NS_FACESENT_FACE; 435 ns->faces_sent[i] = true;
324 436
325 const facedata *d = face_data (i, ns->faceset); 437 const facedata *d = face_data (i, ns->faceset);
326 438
327 if (sl.room () < 2 + 4 + 1 + d->data.size () + 1) 439 if (sl.room () < 2 + 4 + 1 + d->data.size () + 1)
328 break; 440 break;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines