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.27 by root, Mon Mar 12 23:45:37 2007 UTC vs.
Revision 1.28 by root, Wed Mar 14 00:04:59 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 {
276 fprintf (stderr, "image %d\n", facenum);//D
272 sl << (ns->image2 ? "image2 " : "image ") 277 sl << (image2 ? "image2 " : "image ")
273 << uint32 (face_num); 278 << uint32 (facenum);
274 279
275 if (ns->image2) 280 if (image2)
276 sl << uint8 (0); 281 sl << uint8 (0);
277 282
278 sl << uint32 (d->data.size ()) 283 sl << uint32 (d->data.size ())
279 << data (d->data.data (), d->data.size ()); 284 << data (d->data.data (), d->data.size ());
285 }
280 286
281 ns->send_packet (sl); 287 send_packet (sl);
288}
289
290// send all faces of this object to the client
291// this uses more bandwidth initially, but makes
292// animations look much smoother, and every client
293// is supposed to do client-side caching anyways.
294void
295client::send_faces (object *ob)
296{
297 send_face (ob->face);
298
299 if (ob->animation_id)
282 } 300 {
301 animation &anim = animations [ob->animation_id];
283 302
303 for (int i = 0; i < anim.num_animations; i++)
304 send_face (anim.faces [i]);
305 }
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
284 ns->faces_sent[face_num] |= NS_FACESENT_FACE; 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}
346
347/**
348 * Need to send an animation sequence to the client.
349 * We will send appropriate face commands to the client if we haven't
350 * sent them the face yet (this can become quite costly in terms of
351 * how much we are sending - on the other hand, this should only happen
352 * when the player logs in and picks stuff up.
353 */
354void
355client::send_animation (short anim_num)
356{
357 /* 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
359 * range, it must be a valid animation.
360 */
361 if (anim_num < 0 || anim_num > num_animations)
362 {
363 LOG (llevError, "esrv_send_anim (%d) out of bounds??\n", anim_num);
364 return;
365 }
366
367 packet sl ("anim");
368
369 sl << uint16 (anim_num)
370 << uint16 (0); /* flags - not used right now */
371
372 /* Build up the list of faces. Also, send any information (ie, the
373 * the face itself) down to the client.
374 */
375 for (int i = 0; i < animations[anim_num].num_animations; i++)
376 {
377 send_face (animations[anim_num].faces[i]);
378 sl << uint16 (animations[anim_num].faces[i]); /* flags - not used right now */
379 }
380
381 send_packet (sl);
382
383 anims_sent[anim_num] = 1;
285} 384}
286 385
287/** 386/**
288 * Sends the number of images, checksum of the face file, 387 * Sends the number of images, checksum of the face file,
289 * and the image_info file information. See the doc/Developers/protocol 388 * and the image_info file information. See the doc/Developers/protocol
290 * if you want further detail. 389 * if you want further detail.
291 */ 390 */
292
293void 391void
294send_image_info (client *ns, char *params) 392send_image_info (client *ns, char *params)
295{ 393{
296 packet sl; 394 packet sl;
297 395

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines