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.37 by root, Tue Sep 12 20:55:40 2006 UTC vs.
Revision 1.41 by root, Thu Sep 14 01:12:28 2006 UTC

32#include <object.h> 32#include <object.h>
33#include <funcpoint.h> 33#include <funcpoint.h>
34#include <loader.h> 34#include <loader.h>
35 35
36int nrofallocobjects = 0; 36int nrofallocobjects = 0;
37static UUID uuid;
38const uint64 UUID_SKIP = 1<<19;
37 39
38object *objects; /* Pointer to the list of used objects */ 40object *objects; /* Pointer to the list of used objects */
39object *active_objects; /* List of active objects that need to be processed */ 41object *active_objects; /* List of active objects that need to be processed */
40 42
41short 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, 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,
49}; 51};
50int freedir[SIZEOFFREE] = { 52int freedir[SIZEOFFREE] = {
51 0, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 2, 2, 3, 4, 4, 4, 5, 6, 6, 6, 7, 8, 8, 8, 53 0, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 2, 2, 3, 4, 4, 4, 5, 6, 6, 6, 7, 8, 8, 8,
52 1, 2, 2, 2, 2, 2, 3, 4, 4, 4, 4, 4, 5, 6, 6, 6, 6, 6, 7, 8, 8, 8, 8, 8 54 1, 2, 2, 2, 2, 2, 3, 4, 4, 4, 4, 4, 5, 6, 6, 6, 6, 6, 7, 8, 8, 8, 8, 8
53}; 55};
56
57static void
58write_uuid (void)
59{
60 char filename1[MAX_BUF], filename2[MAX_BUF];
61
62 sprintf (filename1, "%s/uuid", settings.localdir);
63 sprintf (filename2, "%s/uuid~", settings.localdir);
64
65 FILE *fp;
66
67 if (!(fp = fopen (filename2, "w")))
68 {
69 LOG (llevError, "ERROR: cannot open %s for writing, unable to write UUID!\n", filename2);
70 return;
71 }
72
73 fprintf (fp, "<1,%llx>\n", (unsigned long long)uuid.seq + UUID_SKIP * 2);
74 fclose (fp);
75 rename (filename2, filename1);
76}
77
78static void
79read_uuid (void)
80{
81 char filename[MAX_BUF];
82
83 sprintf (filename, "%s/uuid", settings.localdir);
84
85 FILE *fp;
86
87 if (!(fp = fopen (filename, "r")))
88 {
89 if (errno == ENOENT)
90 {
91 LOG (llevInfo, "RESET uid to 1\n");
92 uuid.seq = 0;
93 write_uuid ();
94 return;
95 }
96
97 LOG (llevError, "FATAL: cannot open %s for reading!\n", filename);
98 _exit (1);
99 }
100
101 int version;
102 unsigned long long uid;
103 if (2 != fscanf (fp, "<%d,%llx>\n", &version, &uid) || version != 1)
104 {
105 LOG (llevError, "FATAL: error reading uid from %s!\n", filename);
106 _exit (1);
107 }
108
109 uuid.seq = uid;
110 write_uuid ();
111 LOG (llevDebug, "read UID: %lld\n", uid);
112 fclose (fp);
113}
114
115UUID
116gen_uuid ()
117{
118 UUID uid;
119
120 uid.seq = ++uuid.seq;
121
122 if (!(uuid.seq & (UUID_SKIP - 1)))
123 write_uuid ();
124
125 return uid;
126}
127
128void
129init_uuid ()
130{
131 read_uuid ();
132}
54 133
55/* Returns TRUE if every key_values in wants has a partner with the same value in has. */ 134/* Returns TRUE if every key_values in wants has a partner with the same value in has. */
56static int 135static int
57compare_ob_value_lists_one (const object *wants, const object *has) 136compare_ob_value_lists_one (const object *wants, const object *has)
58{ 137{
848 for (unordered_vector<object *>::iterator i = mortals.begin (); i != mortals.end ();) 927 for (unordered_vector<object *>::iterator i = mortals.begin (); i != mortals.end ();)
849 if ((*i)->refcnt) 928 if ((*i)->refcnt)
850 ++i; // further delay freeing 929 ++i; // further delay freeing
851 else 930 else
852 { 931 {
932 //printf ("free_mortal(%p,%ld,%ld)\n", *i, pticks, (*i)->count);//D
853 freed.push_back (*i);//D 933 //freed.push_back (*i);//D
854 //delete *i; 934 delete *i;
855 mortals.erase (i); 935 mortals.erase (i);
856 } 936 }
857 937
858 if (mortals.size() && 0)//D 938 if (mortals.size() && 0)//D
859 LOG (llevDebug, "%d objects in mortal queue\n", mortals.size());//D 939 LOG (llevDebug, "%d objects in mortal queue\n", mortals.size());//D
874} 954}
875 955
876void object::link () 956void object::link ()
877{ 957{
878 count = ++ob_count; 958 count = ++ob_count;
959 uuid = gen_uuid ();
879 960
880 prev = 0; 961 prev = 0;
881 next = objects; 962 next = objects;
882 963
883 if (objects) 964 if (objects)
886 objects = this; 967 objects = this;
887} 968}
888 969
889void object::unlink () 970void object::unlink ()
890{ 971{
891 count = 0; 972 //count = 0;//D
892 973 if (!prev && !next) return;//D
893 /* Remove this object from the list of used objects */
894 if (prev)
895 {
896 prev->next = next;
897 prev = 0;
898 }
899
900 if (next)
901 {
902 next->prev = prev;
903 next = 0;
904 }
905 974
906 if (this == objects) 975 if (this == objects)
907 objects = next; 976 objects = next;
977
978 /* Remove this object from the list of used objects */
979 if (prev) prev->next = next;
980 if (next) next->prev = prev;
981
982 prev = 0;
983 next = 0;
908} 984}
909 985
910object *object::create () 986object *object::create ()
911{ 987{
912 object *op; 988 object *op;
946 1022
947 if (!QUERY_FLAG (this, FLAG_REMOVED)) 1023 if (!QUERY_FLAG (this, FLAG_REMOVED))
948 remove_ob (this); 1024 remove_ob (this);
949 1025
950 SET_FLAG (this, FLAG_FREED); 1026 SET_FLAG (this, FLAG_FREED);
1027
1028 //printf ("free(%p,%ld,%ld)\n", this, pticks, count);//D
951 1029
952 if (more) 1030 if (more)
953 { 1031 {
954 more->free (free_inventory); 1032 more->free (free_inventory);
955 more = 0; 1033 more = 0;
2655 2733
2656 if (tempfile == NULL) 2734 if (tempfile == NULL)
2657 { 2735 {
2658 LOG (llevError, "Error - Unable to access load object temp file\n"); 2736 LOG (llevError, "Error - Unable to access load object temp file\n");
2659 return NULL; 2737 return NULL;
2660 }; 2738 }
2739
2661 fprintf (tempfile, obstr); 2740 fprintf (tempfile, obstr);
2662 fclose (tempfile); 2741 fclose (tempfile);
2663 2742
2664 op = get_object (); 2743 op = get_object ();
2665 2744

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines