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.30 by root, Wed Mar 14 01:19:10 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])
260 return;
261
262 faces_sent[facenum] = true;
263
264 faceinfo *f = face_info (facenum);
265 if (f->smooth && EMI_smooth)
266 {
267 send_face (f->smooth);
268
269 packet sl ("smooth");
270
271 sl << uint16 (facenum)
272 << uint16 (f->smooth);
273
274 send_packet (sl);
275 }
276
258 if (ns->force_face0) 277 if (force_face0)
259 sl << "face " << uint16 (face_num); 278 sl << "face " << uint16 (facenum);
260 else if (ns->image2) 279 else if (image2)
261 sl << "face2 " << uint16 (face_num) << uint8 (0) << uint32 (ns->force_bad_checksum ? gcfclient_checksum (d) : 0); 280 sl << "face2 " << uint16 (facenum) << uint8 (0) << uint32 (force_bad_checksum ? gcfclient_checksum (d) : 0);
262 else 281 else
263 sl << "face1 " << uint16 (face_num) << uint32 (ns->force_bad_checksum ? gcfclient_checksum (d) : 0); 282 sl << "face1 " << uint16 (facenum) << uint32 (force_bad_checksum ? gcfclient_checksum (d) : 0);
264 283
265 // how lame 284 // how lame
266 print_facename (sl, *d); 285 print_facename (sl, *d);
267
268 ns->send_packet (sl);
269 } 286 }
270 else 287 else
271 { 288 {
272 sl << (ns->image2 ? "image2 " : "image ") 289 sl << (image2 ? "image2 " : "image ")
273 << uint32 (face_num); 290 << uint32 (facenum);
274 291
275 if (ns->image2) 292 if (image2)
276 sl << uint8 (0); 293 sl << uint8 (0);
277 294
278 sl << uint32 (d->data.size ()) 295 sl << uint32 (d->data.size ())
279 << data (d->data.data (), d->data.size ()); 296 << data (d->data.data (), d->data.size ());
297 }
280 298
281 ns->send_packet (sl); 299 send_packet (sl);
300}
301
302// send all faces of this object to the client
303// this uses more bandwidth initially, but makes
304// animations look much smoother, and every client
305// is supposed to do client-side caching anyways.
306void
307client::send_faces (object *ob)
308{
309 send_face (ob->face);
310
311 if (ob->animation_id)
282 } 312 {
313 animation &anim = animations [ob->animation_id];
283 314
284 ns->faces_sent[face_num] |= NS_FACESENT_FACE; 315 for (int i = 0; i < anim.num_animations; i++)
316 send_face (anim.faces [i]);
317 }
318}
319
320/**
321 * Need to send an animation sequence to the client.
322 * We will send appropriate face commands to the client if we haven't
323 * sent them the face yet (this can become quite costly in terms of
324 * how much we are sending - on the other hand, this should only happen
325 * when the player logs in and picks stuff up.
326 */
327void
328client::send_animation (short anim_num)
329{
330 /* Do some checking on the anim_num we got. Note that the animations
331 * are added in contigous order, so if the number is in the valid
332 * range, it must be a valid animation.
333 */
334 if (anim_num < 0 || anim_num > num_animations)
335 {
336 LOG (llevError, "esrv_send_anim (%d) out of bounds??\n", anim_num);
337 return;
338 }
339
340 packet sl ("anim");
341
342 sl << uint16 (anim_num)
343 << uint16 (0); /* flags - not used right now */
344
345 /* Build up the list of faces. Also, send any information (ie, the
346 * the face itself) down to the client.
347 */
348 for (int i = 0; i < animations[anim_num].num_animations; i++)
349 {
350 send_face (animations[anim_num].faces[i]);
351 sl << uint16 (animations[anim_num].faces[i]); /* flags - not used right now */
352 }
353
354 send_packet (sl);
355
356 anims_sent[anim_num] = 1;
285} 357}
286 358
287/** 359/**
288 * Sends the number of images, checksum of the face file, 360 * Sends the number of images, checksum of the face file,
289 * and the image_info file information. See the doc/Developers/protocol 361 * and the image_info file information. See the doc/Developers/protocol
290 * if you want further detail. 362 * if you want further detail.
291 */ 363 */
292
293void 364void
294send_image_info (client *ns, char *params) 365send_image_info (client *ns, char *params)
295{ 366{
296 packet sl; 367 packet sl;
297 368
336 407
337 sl.printf ("replyinfo image_sums %d %d ", start, stop); 408 sl.printf ("replyinfo image_sums %d %d ", start, stop);
338 409
339 for (int i = start; i <= stop && i < faces.size (); i++) 410 for (int i = start; i <= stop && i < faces.size (); i++)
340 { 411 {
341 ns->faces_sent[i] |= NS_FACESENT_FACE; 412 ns->faces_sent[i] = true;
342 413
343 const facedata *d = face_data (i, ns->faceset); 414 const facedata *d = face_data (i, ns->faceset);
344 415
345 if (sl.room () < 2 + 4 + 1 + d->data.size () + 1) 416 if (sl.room () < 2 + 4 + 1 + d->data.size () + 1)
346 break; 417 break;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines