… | |
… | |
918 | if (op->more != NULL) |
918 | if (op->more != NULL) |
919 | update_object (op->more, action); |
919 | update_object (op->more, action); |
920 | } |
920 | } |
921 | |
921 | |
922 | static unordered_vector<object *> mortals; |
922 | static unordered_vector<object *> mortals; |
923 | static std::vector<object *, slice_allocator <object *> > freed; |
|
|
924 | |
923 | |
925 | void object::free_mortals () |
924 | void object::free_mortals () |
926 | { |
925 | { |
927 | for (unordered_vector<object *>::iterator i = mortals.begin (); i != mortals.end ();) |
926 | for (unordered_vector<object *>::iterator i = mortals.begin (); i != mortals.end ();) |
928 | if ((*i)->refcnt) |
927 | if ((*i)->refcnt) |
929 | ++i; // further delay freeing |
928 | ++i; // further delay freeing |
930 | else |
929 | else |
931 | { |
930 | { |
932 | //printf ("free_mortal(%p,%ld,%ld)\n", *i, pticks, (*i)->count);//D |
|
|
933 | //freed.push_back (*i);//D |
|
|
934 | delete *i; |
931 | delete *i; |
935 | mortals.erase (i); |
932 | mortals.erase (i); |
936 | } |
933 | } |
937 | |
934 | |
938 | if (mortals.size() && 0)//D |
935 | static int lastmortals = 0;//D |
|
|
936 | |
|
|
937 | if (mortals.size() != lastmortals)//D |
|
|
938 | { |
|
|
939 | lastmortals = mortals.size ();//D |
939 | LOG (llevDebug, "%d objects in mortal queue\n", mortals.size());//D |
940 | LOG (llevDebug, "%d objects in mortal queue\n", lastmortals);//D |
|
|
941 | } |
940 | } |
942 | } |
941 | |
943 | |
942 | object::object () |
944 | object::object () |
943 | { |
945 | { |
944 | SET_FLAG (this, FLAG_REMOVED); |
946 | SET_FLAG (this, FLAG_REMOVED); |
… | |
… | |
983 | next = 0; |
985 | next = 0; |
984 | } |
986 | } |
985 | |
987 | |
986 | object *object::create () |
988 | object *object::create () |
987 | { |
989 | { |
988 | object *op; |
|
|
989 | |
|
|
990 | if (freed.empty ()) |
|
|
991 | op = new object; |
990 | 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 (); |
991 | op->link (); |
1002 | return op; |
992 | return op; |
1003 | } |
993 | } |
1004 | |
994 | |
1005 | /* |
995 | /* |
… | |
… | |
1022 | |
1012 | |
1023 | if (!QUERY_FLAG (this, FLAG_REMOVED)) |
1013 | if (!QUERY_FLAG (this, FLAG_REMOVED)) |
1024 | remove_ob (this); |
1014 | remove_ob (this); |
1025 | |
1015 | |
1026 | SET_FLAG (this, FLAG_FREED); |
1016 | SET_FLAG (this, FLAG_FREED); |
1027 | |
|
|
1028 | //printf ("free(%p,%ld,%ld)\n", this, pticks, count);//D |
|
|
1029 | |
1017 | |
1030 | if (more) |
1018 | if (more) |
1031 | { |
1019 | { |
1032 | more->free (free_inventory); |
1020 | more->free (free_inventory); |
1033 | more = 0; |
1021 | more = 0; |