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.5 2006/08/27 16:15:11 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 | |
53 | object *objects; /* Pointer to the list of used objects */ |
53 | object *objects; /* Pointer to the list of used objects */ |
54 | object *free_objects; /* Pointer to the list of unused objects */ |
54 | object *free_objects; /* Pointer to the list of unused objects */ |
55 | object *active_objects; /* List of active objects that need to be processed */ |
55 | object *active_objects; /* List of active objects that need to be processed */ |
56 | |
|
|
57 | void (*object_free_callback)(object *ob); |
|
|
58 | |
56 | |
59 | short freearr_x[SIZEOFFREE]= |
57 | short 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}; |
62 | short freearr_y[SIZEOFFREE]= |
60 | short freearr_y[SIZEOFFREE]= |
… | |
… | |
581 | * clear_object() frees everything allocated by an object, and also |
579 | * clear_object() frees everything allocated by an object, and also |
582 | * clears all variables and flags to default settings. |
580 | * clears all variables and flags to default settings. |
583 | */ |
581 | */ |
584 | |
582 | |
585 | void clear_object(object *op) { |
583 | void clear_object(object *op) { |
|
|
584 | op->clear (); |
586 | |
585 | |
587 | event *evt; |
586 | event *evt; |
588 | event *evt2; |
587 | event *evt2; |
589 | |
588 | |
590 | /* redo this to be simpler/more efficient. Was also seeing |
589 | /* redo this to be simpler/more efficient. Was also seeing |
… | |
… | |
661 | |
660 | |
662 | void copy_object(object *op2, object *op) { |
661 | void copy_object(object *op2, object *op) { |
663 | int is_freed=QUERY_FLAG(op,FLAG_FREED),is_removed=QUERY_FLAG(op,FLAG_REMOVED); |
662 | int is_freed=QUERY_FLAG(op,FLAG_FREED),is_removed=QUERY_FLAG(op,FLAG_REMOVED); |
664 | event *evt, *evt2, *evt_new; |
663 | event *evt, *evt2, *evt_new; |
665 | |
664 | |
|
|
665 | op->clear (); |
|
|
666 | |
666 | /* Decrement the refcounts, but don't bother zeroing the fields; |
667 | /* Decrement the refcounts, but don't bother zeroing the fields; |
667 | they'll be overwritten by memcpy. */ |
668 | they'll be overwritten by memcpy. */ |
668 | if(op->name!=NULL) free_string(op->name); |
669 | if(op->name!=NULL) free_string(op->name); |
669 | if(op->name_pl!=NULL) free_string(op->name_pl); |
670 | if(op->name_pl!=NULL) free_string(op->name_pl); |
670 | if(op->title!=NULL) free_string(op->title); |
671 | if(op->title!=NULL) free_string(op->title); |
… | |
… | |
689 | op->events = NULL; |
690 | op->events = NULL; |
690 | |
691 | |
691 | free_key_values(op); |
692 | free_key_values(op); |
692 | |
693 | |
693 | *(object_special *)op = *(object_special *)op2; |
694 | *(object_special *)op = *(object_special *)op2; |
|
|
695 | op2->clone (op); |
694 | |
696 | |
695 | if(is_freed) SET_FLAG(op,FLAG_FREED); |
697 | if(is_freed) SET_FLAG(op,FLAG_FREED); |
696 | if(is_removed) SET_FLAG(op,FLAG_REMOVED); |
698 | if(is_removed) SET_FLAG(op,FLAG_REMOVED); |
697 | if(op->name!=NULL) add_refcount(op->name); |
699 | if(op->name!=NULL) add_refcount(op->name); |
698 | if(op->name_pl!=NULL) add_refcount(op->name_pl); |
700 | if(op->name_pl!=NULL) add_refcount(op->name_pl); |
… | |
… | |
754 | tail->next = new_link; |
756 | tail->next = new_link; |
755 | tail = new_link; |
757 | tail = new_link; |
756 | } |
758 | } |
757 | } |
759 | } |
758 | } |
760 | } |
759 | |
761 | |
760 | update_ob_speed(op); |
762 | update_ob_speed(op); |
761 | } |
763 | } |
762 | |
764 | |
763 | /* |
765 | /* |
764 | * expand_objects() allocates more objects for the list of unused objects. |
766 | * expand_objects() allocates more objects for the list of unused objects. |
… | |
… | |
1063 | free_object2(ob, 0); |
1065 | free_object2(ob, 0); |
1064 | } |
1066 | } |
1065 | void free_object2(object *ob, int free_inventory) { |
1067 | void free_object2(object *ob, int free_inventory) { |
1066 | object *tmp,*op; |
1068 | object *tmp,*op; |
1067 | |
1069 | |
1068 | if (object_free_callback) |
1070 | ob->clear (); |
1069 | object_free_callback (ob); |
|
|
1070 | |
1071 | |
1071 | if (!QUERY_FLAG(ob,FLAG_REMOVED)) { |
1072 | if (!QUERY_FLAG(ob,FLAG_REMOVED)) { |
1072 | LOG(llevDebug,"Free object called with non removed object\n"); |
1073 | LOG(llevDebug,"Free object called with non removed object\n"); |
1073 | dump_object(ob); |
1074 | dump_object(ob); |
1074 | #ifdef MANY_CORES |
1075 | #ifdef MANY_CORES |
… | |
… | |
2638 | if (tempfile == NULL) |
2639 | if (tempfile == NULL) |
2639 | { |
2640 | { |
2640 | LOG(llevError,"Error - Unable to read object temp file\n"); |
2641 | LOG(llevError,"Error - Unable to read object temp file\n"); |
2641 | return NULL; |
2642 | return NULL; |
2642 | }; |
2643 | }; |
|
|
2644 | object_thawer thawer; |
2643 | load_object(tempfile,op,LO_NEWFILE,0); |
2645 | load_object(tempfile,thawer,op,LO_NEWFILE,0); |
2644 | LOG(llevDebug," load str completed, object=%s\n",op->name); |
2646 | LOG(llevDebug," load str completed, object=%s\n",op->name); |
2645 | CLEAR_FLAG(op,FLAG_REMOVED); |
2647 | CLEAR_FLAG(op,FLAG_REMOVED); |
2646 | fclose(tempfile); |
2648 | fclose(tempfile); |
2647 | return op; |
2649 | return op; |
2648 | } |
2650 | } |