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.41 by root, Thu Sep 14 01:12:28 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 //printf ("free_mortal(%p,%ld,%ld)\n", *i, pticks, (*i)->count);//D
933 //freed.push_back (*i);//D
934 delete *i; 910 delete *i;
935 mortals.erase (i); 911 mortals.erase (i);
936 } 912 }
937 913
938 if (mortals.size() && 0)//D 914 static int lastmortals = 0;//D
915
916 if (mortals.size() != lastmortals)//D
917 {
918 lastmortals = mortals.size ();//D
939 LOG (llevDebug, "%d objects in mortal queue\n", mortals.size());//D 919 LOG (llevDebug, "%d objects in mortal queue\n", lastmortals);//D
920 }
940} 921}
941 922
942object::object () 923object::object ()
943{ 924{
944 SET_FLAG (this, FLAG_REMOVED); 925 SET_FLAG (this, FLAG_REMOVED);
945 926
946 expmul = 1.0; 927 expmul = 1.0;
947 face = blank_face; 928 face = blank_face;
948 attacked_by_count = -1;
949} 929}
950 930
951object::~object () 931object::~object ()
952{ 932{
953 free_key_values (this); 933 free_key_values (this);
957{ 937{
958 count = ++ob_count; 938 count = ++ob_count;
959 uuid = gen_uuid (); 939 uuid = gen_uuid ();
960 940
961 prev = 0; 941 prev = 0;
962 next = objects; 942 next = object::first;
963 943
964 if (objects) 944 if (object::first)
965 objects->prev = this; 945 object::first->prev = this;
966 946
967 objects = this; 947 object::first = this;
968} 948}
969 949
970void object::unlink () 950void object::unlink ()
971{ 951{
972 //count = 0;//D 952 //count = 0;//D
973 if (!prev && !next) return;//D 953 if (!prev && !next) return;//D
974 954
975 if (this == objects) 955 if (this == object::first)
976 objects = next; 956 object::first = next;
977 957
978 /* Remove this object from the list of used objects */ 958 /* Remove this object from the list of used objects */
979 if (prev) prev->next = next; 959 if (prev) prev->next = next;
980 if (next) next->prev = prev; 960 if (next) next->prev = prev;
981 961
983 next = 0; 963 next = 0;
984} 964}
985 965
986object *object::create () 966object *object::create ()
987{ 967{
988 object *op;
989
990 if (freed.empty ())
991 op = new object; 968 object *op = new object;
992 else
993 {
994 // highly annoying, but the only way to get it stable right now
995 op = freed.back ();
996 freed.pop_back ();
997 op->~object ();
998 new ((void *) op) object;
999 }
1000
1001 op->link (); 969 op->link ();
1002 return op; 970 return op;
1003} 971}
1004 972
1005/* 973/*
1022 990
1023 if (!QUERY_FLAG (this, FLAG_REMOVED)) 991 if (!QUERY_FLAG (this, FLAG_REMOVED))
1024 remove_ob (this); 992 remove_ob (this);
1025 993
1026 SET_FLAG (this, FLAG_FREED); 994 SET_FLAG (this, FLAG_FREED);
1027
1028 //printf ("free(%p,%ld,%ld)\n", this, pticks, count);//D
1029 995
1030 if (more) 996 if (more)
1031 { 997 {
1032 more->free (free_inventory); 998 more->free (free_inventory);
1033 more = 0; 999 more = 0;
1073 op = tmp; 1039 op = tmp;
1074 } 1040 }
1075 } 1041 }
1076 } 1042 }
1077 1043
1044 // clear those pointers that likely might have circular references to us
1078 owner = 0; 1045 owner = 0;
1046 enemy = 0;
1047 attacked_by = 0;
1079 1048
1080 /* Remove object from the active list */ 1049 /* Remove object from the active list */
1081 speed = 0; 1050 speed = 0;
1082 update_ob_speed (this); 1051 update_ob_speed (this);
1083 1052
1095sub_weight (object *op, signed long weight) 1064sub_weight (object *op, signed long weight)
1096{ 1065{
1097 while (op != NULL) 1066 while (op != NULL)
1098 { 1067 {
1099 if (op->type == CONTAINER) 1068 if (op->type == CONTAINER)
1100 {
1101 weight = (signed long) (weight * (100 - op->stats.Str) / 100); 1069 weight = (signed long) (weight * (100 - op->stats.Str) / 100);
1102 } 1070
1103 op->carrying -= weight; 1071 op->carrying -= weight;
1104 op = op->env; 1072 op = op->env;
1105 } 1073 }
1106} 1074}
1107 1075
1115 */ 1083 */
1116 1084
1117void 1085void
1118remove_ob (object *op) 1086remove_ob (object *op)
1119{ 1087{
1088 object *tmp, *last = 0;
1120 object * 1089 object *otmp;
1121 tmp, *
1122 last = NULL;
1123 object *
1124 otmp;
1125 1090
1126 tag_t 1091 tag_t tag;
1127 tag;
1128 int
1129 check_walk_off; 1092 int check_walk_off;
1130 mapstruct * 1093 mapstruct *m;
1131 m;
1132 1094
1133 sint16 1095 sint16 x, y;
1134 x,
1135 y;
1136 1096
1137 if (QUERY_FLAG (op, FLAG_REMOVED)) 1097 if (QUERY_FLAG (op, FLAG_REMOVED))
1138 return; 1098 return;
1139 1099
1140 SET_FLAG (op, FLAG_REMOVED); 1100 SET_FLAG (op, FLAG_REMOVED);
1328 free_object (op); 1288 free_object (op);
1329 return top; 1289 return top;
1330 } 1290 }
1331 } 1291 }
1332 1292
1333 return NULL; 1293 return 0;
1334} 1294}
1335 1295
1336/* 1296/*
1337 * 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
1338 * job preparing multi-part monsters 1298 * job preparing multi-part monsters
1665 remove_ob (tmp); 1625 remove_ob (tmp);
1666 free_object (tmp); 1626 free_object (tmp);
1667 } 1627 }
1668 } 1628 }
1669 1629
1670 tmp1 = arch_to_object (find_archetype (arch_string)); 1630 tmp1 = arch_to_object (archetype::find (arch_string));
1671 1631
1672 tmp1->x = op->x; 1632 tmp1->x = op->x;
1673 tmp1->y = op->y; 1633 tmp1->y = op->y;
1674 insert_ob_in_map (tmp1, op->map, op, 0); 1634 insert_ob_in_map (tmp1, op->map, op, 0);
1675} 1635}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines