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.40 by root, Thu Sep 14 00:07:15 2006 UTC vs.
Revision 1.46 by root, Thu Sep 14 21:16:11 2006 UTC

35 35
36int nrofallocobjects = 0; 36int nrofallocobjects = 0;
37static UUID uuid; 37static UUID uuid;
38const uint64 UUID_SKIP = 1<<19; 38const uint64 UUID_SKIP = 1<<19;
39 39
40object *objects; /* Pointer to the list of used objects */
41object *active_objects; /* List of active objects that need to be processed */ 40object *active_objects; /* List of active objects that need to be processed */
42 41
43short freearr_x[SIZEOFFREE] = { 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, 42short freearr_x[SIZEOFFREE] = { 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,
44 0, 1, 2, 3, 3, 3, 3, 3, 3, 3, 2, 1, 0, -1, -2, -3, -3, -3, -3, -3, -3, -3, -2, -1 43 0, 1, 2, 3, 3, 3, 3, 3, 3, 3, 2, 1, 0, -1, -2, -3, -3, -3, -3, -3, -3, -3, -2, -1
45}; 44};
447void 446void
448dump_all_objects (void) 447dump_all_objects (void)
449{ 448{
450 object *op; 449 object *op;
451 450
452 for (op = objects; op != NULL; op = op->next) 451 for (op = object::first; op != NULL; op = op->next)
453 { 452 {
454 dump_object (op); 453 dump_object (op);
455 fprintf (logfile, "Object %d\n:%s\n", op->count, errmsg); 454 fprintf (logfile, "Object %d\n:%s\n", op->count, errmsg);
456 } 455 }
457} 456}
483object * 482object *
484find_object (tag_t i) 483find_object (tag_t i)
485{ 484{
486 object *op; 485 object *op;
487 486
488 for (op = objects; op != NULL; op = op->next) 487 for (op = object::first; op != NULL; op = op->next)
489 if (op->count == i) 488 if (op->count == i)
490 break; 489 break;
491 return op; 490 return op;
492} 491}
493 492
501find_object_name (const char *str) 500find_object_name (const char *str)
502{ 501{
503 shstr_cmp str_ (str); 502 shstr_cmp str_ (str);
504 object *op; 503 object *op;
505 504
506 for (op = objects; op != NULL; op = op->next) 505 for (op = object::first; op != NULL; op = op->next)
507 if (op->name == str_) 506 if (op->name == str_)
508 break; 507 break;
509 508
510 return op; 509 return op;
511} 510}
512 511
513void 512void
514free_all_object_data () 513free_all_object_data ()
515{ 514{
516 LOG (llevDebug, "%d allocated objects\n", nrofallocobjects); 515 LOG (llevDebug, "%d allocated objects\n", nrofallocobjects);
517}
518
519/*
520 * Returns the object which this object marks as being the owner.
521 * A id-scheme is used to avoid pointing to objects which have been
522 * freed and are now reused. If this is detected, the owner is
523 * set to NULL, and NULL is returned.
524 * Changed 2004-02-12 - if the player is setting at the play again
525 * prompt, he is removed, and we don't want to treat him as an owner of
526 * anything, so check removed flag. I don't expect that this should break
527 * anything - once an object is removed, it is basically dead anyways.
528 */
529object *
530object::get_owner ()
531{
532 if (!owner
533 || QUERY_FLAG (owner, FLAG_FREED)
534 || QUERY_FLAG (owner, FLAG_REMOVED))
535 owner = 0;
536
537 return owner;
538} 516}
539 517
540/* 518/*
541 * Sets the owner and sets the skill and exp pointers to owner's current 519 * Sets the owner and sets the skill and exp pointers to owner's current
542 * skill and experience objects. 520 * skill and experience objects.
612 590
613 /* What is not cleared is next, prev, and count */ 591 /* What is not cleared is next, prev, and count */
614 592
615 expmul = 1.0; 593 expmul = 1.0;
616 face = blank_face; 594 face = blank_face;
617 attacked_by_count = -1;
618 595
619 if (settings.casting_time) 596 if (settings.casting_time)
620 casting_time = -1; 597 casting_time = -1;
621} 598}
622 599
917 894
918 if (op->more != NULL) 895 if (op->more != NULL)
919 update_object (op->more, action); 896 update_object (op->more, action);
920} 897}
921 898
922static unordered_vector<object *> mortals; 899object::vector object::mortals;
923static std::vector<object *, slice_allocator <object *> > freed; 900object::vector object::objects; // not yet used
901object *object::first;
924 902
925void object::free_mortals () 903void object::free_mortals ()
926{ 904{
927 for (unordered_vector<object *>::iterator i = mortals.begin (); i != mortals.end ();) 905 for (AUTODECL (i, mortals.begin ()); i != mortals.end ();)
928 if ((*i)->refcnt) 906 if ((*i)->refcnt)
929 ++i; // further delay freeing 907 ++i; // further delay freeing
930 else 908 else
931 { 909 {
932 //freed.push_back (*i);//D
933 delete *i; 910 delete *i;
934 mortals.erase (i); 911 mortals.erase (i);
935 } 912 }
936 913
937 if (mortals.size() && 0)//D 914 static int lastmortals = 0;//D
915
916 if (mortals.size() != lastmortals)//D
917 {
918 lastmortals = mortals.size ();//D
938 LOG (llevDebug, "%d objects in mortal queue\n", mortals.size());//D 919 LOG (llevDebug, "%d objects in mortal queue\n", lastmortals);//D
920 }
939} 921}
940 922
941object::object () 923object::object ()
942{ 924{
943 SET_FLAG (this, FLAG_REMOVED); 925 SET_FLAG (this, FLAG_REMOVED);
944 926
945 expmul = 1.0; 927 expmul = 1.0;
946 face = blank_face; 928 face = blank_face;
947 attacked_by_count = -1;
948} 929}
949 930
950object::~object () 931object::~object ()
951{ 932{
952 free_key_values (this); 933 free_key_values (this);
953} 934}
954 935
955void object::link () 936void object::link ()
956{ 937{
957 count = ++ob_count; 938 count = ++ob_count;
939 uuid = gen_uuid ();
958 940
959 prev = 0; 941 prev = 0;
960 next = objects; 942 next = object::first;
961 943
962 if (objects) 944 if (object::first)
963 objects->prev = this; 945 object::first->prev = this;
964 946
965 objects = this; 947 object::first = this;
966} 948}
967 949
968void object::unlink () 950void object::unlink ()
969{ 951{
970 count = 0; 952 //count = 0;//D
971 uuid = gen_uuid (); 953 if (!prev && !next) return;//D
972 954
973 if (this == objects) 955 if (this == object::first)
974 objects = next; 956 object::first = next;
975 957
976 /* Remove this object from the list of used objects */ 958 /* Remove this object from the list of used objects */
977 if (prev)
978 {
979 prev->next = next; 959 if (prev) prev->next = next;
960 if (next) next->prev = prev;
961
980 prev = 0; 962 prev = 0;
981 }
982
983 if (next)
984 {
985 next->prev = prev;
986 next = 0; 963 next = 0;
987 }
988} 964}
989 965
990object *object::create () 966object *object::create ()
991{ 967{
992 object *op;
993
994 if (freed.empty ())
995 op = new object; 968 object *op = new object;
996 else
997 {
998 // highly annoying, but the only way to get it stable right now
999 op = freed.back ();
1000 freed.pop_back ();
1001 op->~object ();
1002 new ((void *) op) object;
1003 }
1004
1005 op->link (); 969 op->link ();
1006 return op; 970 return op;
1007} 971}
1008 972
1009/* 973/*
1075 op = tmp; 1039 op = tmp;
1076 } 1040 }
1077 } 1041 }
1078 } 1042 }
1079 1043
1044 // clear those pointers that likely might have circular references to us
1080 owner = 0; 1045 owner = 0;
1046 enemy = 0;
1047 attacked_by = 0;
1081 1048
1082 /* Remove object from the active list */ 1049 /* Remove object from the active list */
1083 speed = 0; 1050 speed = 0;
1084 update_ob_speed (this); 1051 update_ob_speed (this);
1085 1052
1097sub_weight (object *op, signed long weight) 1064sub_weight (object *op, signed long weight)
1098{ 1065{
1099 while (op != NULL) 1066 while (op != NULL)
1100 { 1067 {
1101 if (op->type == CONTAINER) 1068 if (op->type == CONTAINER)
1102 {
1103 weight = (signed long) (weight * (100 - op->stats.Str) / 100); 1069 weight = (signed long) (weight * (100 - op->stats.Str) / 100);
1104 } 1070
1105 op->carrying -= weight; 1071 op->carrying -= weight;
1106 op = op->env; 1072 op = op->env;
1107 } 1073 }
1108} 1074}
1109 1075
1117 */ 1083 */
1118 1084
1119void 1085void
1120remove_ob (object *op) 1086remove_ob (object *op)
1121{ 1087{
1088 object *tmp, *last = 0;
1122 object * 1089 object *otmp;
1123 tmp, *
1124 last = NULL;
1125 object *
1126 otmp;
1127 1090
1128 tag_t 1091 tag_t tag;
1129 tag;
1130 int
1131 check_walk_off; 1092 int check_walk_off;
1132 mapstruct * 1093 mapstruct *m;
1133 m;
1134 1094
1135 sint16 1095 sint16 x, y;
1136 x,
1137 y;
1138 1096
1139 if (QUERY_FLAG (op, FLAG_REMOVED)) 1097 if (QUERY_FLAG (op, FLAG_REMOVED))
1140 return; 1098 return;
1141 1099
1142 SET_FLAG (op, FLAG_REMOVED); 1100 SET_FLAG (op, FLAG_REMOVED);
1330 free_object (op); 1288 free_object (op);
1331 return top; 1289 return top;
1332 } 1290 }
1333 } 1291 }
1334 1292
1335 return NULL; 1293 return 0;
1336} 1294}
1337 1295
1338/* 1296/*
1339 * same as insert_ob_in_map except it handle separate coordinates and do a clean 1297 * same as insert_ob_in_map except it handle separate coordinates and do a clean
1340 * job preparing multi-part monsters 1298 * job preparing multi-part monsters
1667 remove_ob (tmp); 1625 remove_ob (tmp);
1668 free_object (tmp); 1626 free_object (tmp);
1669 } 1627 }
1670 } 1628 }
1671 1629
1672 tmp1 = arch_to_object (find_archetype (arch_string)); 1630 tmp1 = arch_to_object (archetype::find (arch_string));
1673 1631
1674 tmp1->x = op->x; 1632 tmp1->x = op->x;
1675 tmp1->y = op->y; 1633 tmp1->y = op->y;
1676 insert_ob_in_map (tmp1, op->map, op, 0); 1634 insert_ob_in_map (tmp1, op->map, op, 0);
1677} 1635}
2735 2693
2736 if (tempfile == NULL) 2694 if (tempfile == NULL)
2737 { 2695 {
2738 LOG (llevError, "Error - Unable to access load object temp file\n"); 2696 LOG (llevError, "Error - Unable to access load object temp file\n");
2739 return NULL; 2697 return NULL;
2740 }; 2698 }
2699
2741 fprintf (tempfile, obstr); 2700 fprintf (tempfile, obstr);
2742 fclose (tempfile); 2701 fclose (tempfile);
2743 2702
2744 op = get_object (); 2703 op = get_object ();
2745 2704

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines