1 | /* |
1 | /* |
2 | * static char *rcsid_object_c = |
2 | * static char *rcsid_object_c = |
3 | * "$Id: object.C,v 1.2 2006/08/25 17:11:52 root Exp $"; |
3 | * "$Id: object.C,v 1.3 2006/08/26 08:44:05 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) { |
586 | |
584 | op->clear (); |
587 | if (object_free_callback) |
|
|
588 | object_free_callback (op); |
|
|
589 | |
585 | |
590 | event *evt; |
586 | event *evt; |
591 | event *evt2; |
587 | event *evt2; |
592 | |
588 | |
593 | /* redo this to be simpler/more efficient. Was also seeing |
589 | /* redo this to be simpler/more efficient. Was also seeing |
… | |
… | |
664 | |
660 | |
665 | void copy_object(object *op2, object *op) { |
661 | void copy_object(object *op2, object *op) { |
666 | 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); |
667 | event *evt, *evt2, *evt_new; |
663 | event *evt, *evt2, *evt_new; |
668 | |
664 | |
669 | if (object_free_callback) |
665 | op->clear (); |
670 | object_free_callback (op); |
|
|
671 | |
|
|
672 | // callback registries and self are empty for copied objects |
|
|
673 | // this ought to change in the future |
|
|
674 | |
666 | |
675 | /* Decrement the refcounts, but don't bother zeroing the fields; |
667 | /* Decrement the refcounts, but don't bother zeroing the fields; |
676 | they'll be overwritten by memcpy. */ |
668 | they'll be overwritten by memcpy. */ |
677 | if(op->name!=NULL) free_string(op->name); |
669 | if(op->name!=NULL) free_string(op->name); |
678 | if(op->name_pl!=NULL) free_string(op->name_pl); |
670 | if(op->name_pl!=NULL) free_string(op->name_pl); |
… | |
… | |
698 | op->events = NULL; |
690 | op->events = NULL; |
699 | |
691 | |
700 | free_key_values(op); |
692 | free_key_values(op); |
701 | |
693 | |
702 | *(object_special *)op = *(object_special *)op2; |
694 | *(object_special *)op = *(object_special *)op2; |
|
|
695 | op->clone (op2); |
703 | |
696 | |
704 | if(is_freed) SET_FLAG(op,FLAG_FREED); |
697 | if(is_freed) SET_FLAG(op,FLAG_FREED); |
705 | if(is_removed) SET_FLAG(op,FLAG_REMOVED); |
698 | if(is_removed) SET_FLAG(op,FLAG_REMOVED); |
706 | if(op->name!=NULL) add_refcount(op->name); |
699 | if(op->name!=NULL) add_refcount(op->name); |
707 | if(op->name_pl!=NULL) add_refcount(op->name_pl); |
700 | if(op->name_pl!=NULL) add_refcount(op->name_pl); |
… | |
… | |
1072 | free_object2(ob, 0); |
1065 | free_object2(ob, 0); |
1073 | } |
1066 | } |
1074 | void free_object2(object *ob, int free_inventory) { |
1067 | void free_object2(object *ob, int free_inventory) { |
1075 | object *tmp,*op; |
1068 | object *tmp,*op; |
1076 | |
1069 | |
1077 | if (object_free_callback) |
1070 | ob->clear (); |
1078 | object_free_callback (ob); |
|
|
1079 | |
1071 | |
1080 | if (!QUERY_FLAG(ob,FLAG_REMOVED)) { |
1072 | if (!QUERY_FLAG(ob,FLAG_REMOVED)) { |
1081 | LOG(llevDebug,"Free object called with non removed object\n"); |
1073 | LOG(llevDebug,"Free object called with non removed object\n"); |
1082 | dump_object(ob); |
1074 | dump_object(ob); |
1083 | #ifdef MANY_CORES |
1075 | #ifdef MANY_CORES |