objwriter.cxx

changeset 37
c349dca807f9
parent 34
0a9a5902beaa
child 38
e4bbd540663b
equal deleted inserted replaced
36:a8838b5f1213 37:c349dca807f9
133 133
134 if (sizeof (unsigned char) != 1) 134 if (sizeof (unsigned char) != 1)
135 error ("size of unsigned char isn't 1, but %d!\n", sizeof (unsigned char)); 135 error ("size of unsigned char isn't 1, but %d!\n", sizeof (unsigned char));
136 136
137 for (unsigned int x = 0; x < MainBuffer->writesize; x++) { 137 for (unsigned int x = 0; x < MainBuffer->writesize; x++) {
138 unsigned char c = *(MainBuffer->buffer+x); 138 // Check if this position is a reference
139 fwrite (&c, 1, 1, fp); 139 for (unsigned int r = 0; r < MAX_MARKS; r++) {
140 numWrittenBytes++; 140 if (MainBuffer->refs[r] && MainBuffer->refs[r]->pos == x) {
141 word ref = static_cast<word> (MainBuffer->marks[MainBuffer->refs[r]->num]->pos);
142 WriteDataToFile<word> (ref);
143 }
144 }
145
146 WriteDataToFile<unsigned char> (*(MainBuffer->buffer+x));
141 } 147 }
142 148
143 printf ("-- %u byte%s written to %s\n", numWrittenBytes, PLURAL (numWrittenBytes), filepath.chars()); 149 printf ("-- %u byte%s written to %s\n", numWrittenBytes, PLURAL (numWrittenBytes), filepath.chars());
144 fclose (fp); 150 fclose (fp);
145 } 151 }
152
153 DataBuffer* ObjWriter::GetCurrentBuffer() {
154 return (g_CurMode == MODE_MAINLOOP) ? MainLoopBuffer :
155 (g_CurMode == MODE_ONENTER) ? OnEnterBuffer :
156 MainBuffer;
157 }
158
159 ScriptMark* g_ScriptMark = NULL;
160
161 // Adds a mark
162 unsigned int ObjWriter::AddMark (int type, str name) {
163 return GetCurrentBuffer()->AddMark (type, name);
164 }
165
166 // Adds a reference
167 unsigned int ObjWriter::AddReference (unsigned int mark) {
168 DataBuffer* b = GetCurrentBuffer();
169 return b->AddMarkReference (mark);
170 }
171
172 // Finds a mark
173 unsigned int ObjWriter::FindMark (int type, str name) {
174 DataBuffer* b = GetCurrentBuffer();
175 for (unsigned int u = 0; u < MAX_MARKS; u++) {
176 if (b->marks[u] && b->marks[u]->type == type && !b->marks[u]->name.icompare (name))
177 return u;
178 }
179 return MAX_MARKS;
180 }

mercurial