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.29 by root, Wed Mar 14 00:07: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_face (atoi (buf), 1);
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{
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, bool forced)
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);
253
254 packet sl; 255 packet sl;
255 256
256 if (ns->facecache && !nocache) 257 if (facecache && !forced)
257 { 258 {
259 if (faces_sent[facenum] & NS_FACESENT_FACE)
260 return;
261
262 faces_sent[facenum] |= NS_FACESENT_FACE;
263
258 if (ns->force_face0) 264 if (force_face0)
259 sl << "face " << uint16 (face_num); 265 sl << "face " << uint16 (facenum);
260 else if (ns->image2) 266 else if (image2)
261 sl << "face2 " << uint16 (face_num) << uint8 (0) << uint32 (ns->force_bad_checksum ? gcfclient_checksum (d) : 0); 267 sl << "face2 " << uint16 (facenum) << uint8 (0) << uint32 (force_bad_checksum ? gcfclient_checksum (d) : 0);
262 else 268 else
263 sl << "face1 " << uint16 (face_num) << uint32 (ns->force_bad_checksum ? gcfclient_checksum (d) : 0); 269 sl << "face1 " << uint16 (facenum) << uint32 (force_bad_checksum ? gcfclient_checksum (d) : 0);
264 270
265 // how lame 271 // how lame
266 print_facename (sl, *d); 272 print_facename (sl, *d);
267
268 ns->send_packet (sl);
269 } 273 }
270 else 274 else
271 { 275 {
272 fprintf (stderr, "image %s %d\n", &faces [face_num].name, nocache);//D
273 sl << (ns->image2 ? "image2 " : "image ") 276 sl << (image2 ? "image2 " : "image ")
274 << uint32 (face_num); 277 << uint32 (facenum);
275 278
276 if (ns->image2) 279 if (image2)
277 sl << uint8 (0); 280 sl << uint8 (0);
278 281
279 sl << uint32 (d->data.size ()) 282 sl << uint32 (d->data.size ())
280 << data (d->data.data (), d->data.size ()); 283 << data (d->data.data (), d->data.size ());
284 }
281 285
282 ns->send_packet (sl); 286 send_packet (sl);
287}
288
289// send all faces of this object to the client
290// this uses more bandwidth initially, but makes
291// animations look much smoother, and every client
292// is supposed to do client-side caching anyways.
293void
294client::send_faces (object *ob)
295{
296 send_face (ob->face);
297
298 if (ob->animation_id)
283 } 299 {
300 animation &anim = animations [ob->animation_id];
284 301
302 for (int i = 0; i < anim.num_animations; i++)
303 send_face (anim.faces [i]);
304 }
305}
306
307/**
308 * A lot like the old AskSmooth (in fact, now called by AskSmooth).
309 * Basically, it makes no sense to wait for the client to request a
310 * a piece of data from us that we know the client wants. So
311 * if we know the client wants it, might as well push it to the
312 * client.
313 */
314void
315client::send_smooth (faceidx face)
316{
317 faceinfo *f = face_info (face);
318
319 if (!f)
320 return;
321
322 if (faces_sent[face] & NS_FACESENT_SMOOTH)
323 return;
324
285 ns->faces_sent[face_num] |= NS_FACESENT_FACE; 325 faces_sent[face] |= NS_FACESENT_SMOOTH;
326
327 /* If we can't find a face, return and set it so we won't try to send this
328 * again.
329 */
330 if (!f->smooth)
331 {
332 LOG (llevError, "could not findsmooth for %d.\n", face);
333 return;
334 }
335
336 send_face (f->smooth);
337
338 packet sl ("smooth");
339
340 sl << uint16 (face)
341 << uint16 (f->smooth);
342
343 send_packet (sl);
344}
345
346/**
347 * Need to send an animation sequence to the client.
348 * We will send appropriate face commands to the client if we haven't
349 * sent them the face yet (this can become quite costly in terms of
350 * how much we are sending - on the other hand, this should only happen
351 * when the player logs in and picks stuff up.
352 */
353void
354client::send_animation (short anim_num)
355{
356 /* Do some checking on the anim_num we got. Note that the animations
357 * are added in contigous order, so if the number is in the valid
358 * range, it must be a valid animation.
359 */
360 if (anim_num < 0 || anim_num > num_animations)
361 {
362 LOG (llevError, "esrv_send_anim (%d) out of bounds??\n", anim_num);
363 return;
364 }
365
366 packet sl ("anim");
367
368 sl << uint16 (anim_num)
369 << uint16 (0); /* flags - not used right now */
370
371 /* Build up the list of faces. Also, send any information (ie, the
372 * the face itself) down to the client.
373 */
374 for (int i = 0; i < animations[anim_num].num_animations; i++)
375 {
376 send_face (animations[anim_num].faces[i]);
377 sl << uint16 (animations[anim_num].faces[i]); /* flags - not used right now */
378 }
379
380 send_packet (sl);
381
382 anims_sent[anim_num] = 1;
286} 383}
287 384
288/** 385/**
289 * Sends the number of images, checksum of the face file, 386 * Sends the number of images, checksum of the face file,
290 * and the image_info file information. See the doc/Developers/protocol 387 * and the image_info file information. See the doc/Developers/protocol
291 * if you want further detail. 388 * if you want further detail.
292 */ 389 */
293
294void 390void
295send_image_info (client *ns, char *params) 391send_image_info (client *ns, char *params)
296{ 392{
297 packet sl; 393 packet sl;
298 394

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines