ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/object.C
(Generate patch)

Comparing deliantra/server/common/object.C (file contents):
Revision 1.136 by root, Thu Mar 15 14:23:02 2007 UTC vs.
Revision 1.137 by root, Mon Apr 16 06:23:40 2007 UTC

454 * refcounts and freeing the links. 454 * refcounts and freeing the links.
455 */ 455 */
456static void 456static void
457free_key_values (object *op) 457free_key_values (object *op)
458{ 458{
459 for (key_value *i = op->key_values; i != 0;) 459 for (key_value *i = op->key_values; i; )
460 { 460 {
461 key_value *next = i->next; 461 key_value *next = i->next;
462 delete i; 462 delete i;
463 463
464 i = next; 464 i = next;
465 } 465 }
466 466
467 op->key_values = 0; 467 op->key_values = 0;
468} 468}
469 469
470/* 470object &
471 * copy_to first frees everything allocated by the dst object, 471object::operator =(const object &src)
472 * and then copies the contents of itself into the second
473 * object, allocating what needs to be allocated. Basically, any
474 * data that is malloc'd needs to be re-malloc/copied. Otherwise,
475 * if the first object is freed, the pointers in the new object
476 * will point at garbage.
477 */
478void
479object::copy_to (object *dst)
480{ 472{
481 bool is_freed = QUERY_FLAG (dst, FLAG_FREED); 473 bool is_freed = flag [FLAG_FREED];
482 bool is_removed = QUERY_FLAG (dst, FLAG_REMOVED); 474 bool is_removed = flag [FLAG_REMOVED];
483 475
484 *(object_copy *)dst = *this; 476 *(object_copy *)this = src;
485 477
486 if (is_freed) 478 flag [FLAG_FREED] = is_freed;
487 SET_FLAG (dst, FLAG_FREED); 479 flag [FLAG_REMOVED] = is_removed;
488
489 if (is_removed)
490 SET_FLAG (dst, FLAG_REMOVED);
491
492 if (speed < 0)
493 dst->speed_left = speed_left - rndm ();
494 480
495 /* Copy over key_values, if any. */ 481 /* Copy over key_values, if any. */
496 if (key_values) 482 if (src.key_values)
497 { 483 {
498 key_value *tail = 0; 484 key_value *tail = 0;
499 key_value *i;
500
501 dst->key_values = 0; 485 key_values = 0;
502 486
503 for (i = key_values; i; i = i->next) 487 for (key_value *i = src.key_values; i; i = i->next)
504 { 488 {
505 key_value *new_link = new key_value; 489 key_value *new_link = new key_value;
506 490
507 new_link->next = 0; 491 new_link->next = 0;
508 new_link->key = i->key; 492 new_link->key = i->key;
509 new_link->value = i->value; 493 new_link->value = i->value;
510 494
511 /* Try and be clever here, too. */ 495 /* Try and be clever here, too. */
512 if (!dst->key_values) 496 if (!key_values)
513 { 497 {
514 dst->key_values = new_link; 498 key_values = new_link;
515 tail = new_link; 499 tail = new_link;
516 } 500 }
517 else 501 else
518 { 502 {
519 tail->next = new_link; 503 tail->next = new_link;
520 tail = new_link; 504 tail = new_link;
521 } 505 }
522 } 506 }
523 } 507 }
508}
509
510/*
511 * copy_to first frees everything allocated by the dst object,
512 * and then copies the contents of itself into the second
513 * object, allocating what needs to be allocated. Basically, any
514 * data that is malloc'd needs to be re-malloc/copied. Otherwise,
515 * if the first object is freed, the pointers in the new object
516 * will point at garbage.
517 */
518void
519object::copy_to (object *dst)
520{
521 *dst = *this;
522
523 if (speed < 0)
524 dst->speed_left = speed_left - rndm ();
524 525
525 dst->set_speed (dst->speed); 526 dst->set_speed (dst->speed);
526} 527}
527 528
528void 529void

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines