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.1 by elmex, Sun Aug 13 17:16:00 2006 UTC vs.
Revision 1.7 by root, Tue Aug 29 05:03:54 2006 UTC

1/* 1/*
2 * static char *rcsid_object_c = 2 * static char *rcsid_object_c =
3 * "$Id: object.C,v 1.1 2006/08/13 17:16:00 elmex Exp $"; 3 * "$Id: object.C,v 1.7 2006/08/29 05:03:54 root Exp $";
4 */ 4 */
5 5
6/* 6/*
7 CrossFire, A Multiplayer game for X-windows 7 CrossFire, A Multiplayer game for X-windows
8 8
51#endif 51#endif
52 52
53object *objects; /* Pointer to the list of used objects */ 53object *objects; /* Pointer to the list of used objects */
54object *free_objects; /* Pointer to the list of unused objects */ 54object *free_objects; /* Pointer to the list of unused objects */
55object *active_objects; /* List of active objects that need to be processed */ 55object *active_objects; /* List of active objects that need to be processed */
56
57void (*object_free_callback)(object *ob);
58 56
59short freearr_x[SIZEOFFREE]= 57short freearr_x[SIZEOFFREE]=
60 {0,0,1,1,1,0,-1,-1,-1,0,1,2,2,2,2,2,1,0,-1,-2,-2,-2,-2,-2,-1, 58 {0,0,1,1,1,0,-1,-1,-1,0,1,2,2,2,2,2,1,0,-1,-2,-2,-2,-2,-2,-1,
61 0,1,2,3,3,3,3,3,3,3,2,1,0,-1,-2,-3,-3,-3,-3,-3,-3,-3,-2,-1}; 59 0,1,2,3,3,3,3,3,3,3,2,1,0,-1,-2,-3,-3,-3,-3,-3,-3,-3,-2,-1};
62short freearr_y[SIZEOFFREE]= 60short freearr_y[SIZEOFFREE]=
548 op->slaying = NULL; 546 op->slaying = NULL;
549 op->skill = NULL; 547 op->skill = NULL;
550 op->msg = NULL; 548 op->msg = NULL;
551 op->materialname = NULL; 549 op->materialname = NULL;
552 op->lore = NULL; 550 op->lore = NULL;
553 op->current_weapon_script = NULL;
554 clear_object(op); 551 clear_object(op);
555} 552}
556 553
557/* Zero the key_values on op, decrementing the shared-string 554/* Zero the key_values on op, decrementing the shared-string
558 * refcounts and freeing the links. 555 * refcounts and freeing the links.
581 * clear_object() frees everything allocated by an object, and also 578 * clear_object() frees everything allocated by an object, and also
582 * clears all variables and flags to default settings. 579 * clears all variables and flags to default settings.
583 */ 580 */
584 581
585void clear_object(object *op) { 582void clear_object(object *op) {
583 op->clear ();
586 584
587 event *evt; 585 event *evt;
588 event *evt2; 586 event *evt2;
589 587
590 /* redo this to be simpler/more efficient. Was also seeing 588 /* redo this to be simpler/more efficient. Was also seeing
661 659
662void copy_object(object *op2, object *op) { 660void copy_object(object *op2, object *op) {
663 int is_freed=QUERY_FLAG(op,FLAG_FREED),is_removed=QUERY_FLAG(op,FLAG_REMOVED); 661 int is_freed=QUERY_FLAG(op,FLAG_FREED),is_removed=QUERY_FLAG(op,FLAG_REMOVED);
664 event *evt, *evt2, *evt_new; 662 event *evt, *evt2, *evt_new;
665 663
664 op->clear ();
665
666 /* Decrement the refcounts, but don't bother zeroing the fields; 666 /* Decrement the refcounts, but don't bother zeroing the fields;
667 they'll be overwritten by memcpy. */ 667 they'll be overwritten by memcpy. */
668 if(op->name!=NULL) free_string(op->name); 668 if(op->name!=NULL) free_string(op->name);
669 if(op->name_pl!=NULL) free_string(op->name_pl); 669 if(op->name_pl!=NULL) free_string(op->name_pl);
670 if(op->title!=NULL) free_string(op->title); 670 if(op->title!=NULL) free_string(op->title);
689 op->events = NULL; 689 op->events = NULL;
690 690
691 free_key_values(op); 691 free_key_values(op);
692 692
693 *(object_special *)op = *(object_special *)op2; 693 *(object_special *)op = *(object_special *)op2;
694 op2->clone (op);
694 695
695 if(is_freed) SET_FLAG(op,FLAG_FREED); 696 if(is_freed) SET_FLAG(op,FLAG_FREED);
696 if(is_removed) SET_FLAG(op,FLAG_REMOVED); 697 if(is_removed) SET_FLAG(op,FLAG_REMOVED);
697 if(op->name!=NULL) add_refcount(op->name); 698 if(op->name!=NULL) add_refcount(op->name);
698 if(op->name_pl!=NULL) add_refcount(op->name_pl); 699 if(op->name_pl!=NULL) add_refcount(op->name_pl);
754 tail->next = new_link; 755 tail->next = new_link;
755 tail = new_link; 756 tail = new_link;
756 } 757 }
757 } 758 }
758 } 759 }
759 760
760 update_ob_speed(op); 761 update_ob_speed(op);
761} 762}
762 763
763/* 764/*
764 * expand_objects() allocates more objects for the list of unused objects. 765 * expand_objects() allocates more objects for the list of unused objects.
1063 free_object2(ob, 0); 1064 free_object2(ob, 0);
1064} 1065}
1065void free_object2(object *ob, int free_inventory) { 1066void free_object2(object *ob, int free_inventory) {
1066 object *tmp,*op; 1067 object *tmp,*op;
1067 1068
1068 if (object_free_callback) 1069 ob->clear ();
1069 object_free_callback (ob);
1070 1070
1071 if (!QUERY_FLAG(ob,FLAG_REMOVED)) { 1071 if (!QUERY_FLAG(ob,FLAG_REMOVED)) {
1072 LOG(llevDebug,"Free object called with non removed object\n"); 1072 LOG(llevDebug,"Free object called with non removed object\n");
1073 dump_object(ob); 1073 dump_object(ob);
1074#ifdef MANY_CORES 1074#ifdef MANY_CORES
2638 if (tempfile == NULL) 2638 if (tempfile == NULL)
2639 { 2639 {
2640 LOG(llevError,"Error - Unable to read object temp file\n"); 2640 LOG(llevError,"Error - Unable to read object temp file\n");
2641 return NULL; 2641 return NULL;
2642 }; 2642 };
2643 object_thawer thawer (tempfile);
2643 load_object(tempfile,op,LO_NEWFILE,0); 2644 load_object(thawer,op,LO_NEWFILE,0);
2644 LOG(llevDebug," load str completed, object=%s\n",op->name); 2645 LOG(llevDebug," load str completed, object=%s\n",op->name);
2645 CLEAR_FLAG(op,FLAG_REMOVED); 2646 CLEAR_FLAG(op,FLAG_REMOVED);
2646 fclose(tempfile); 2647 fclose(tempfile);
2647 return op; 2648 return op;
2648} 2649}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines