Differences From Artifact [1dbc40dfe7]:
- File
src/worldio.mm
— part of check-in
[489124a92f]
at
2025-03-16 10:11:39
on branch trunk
— Use one autorelease pool per frame
This way, nowhere else autorelease pools need to be managed. (user: js, size: 9284) [annotate] [blame] [check-ins using]
To Artifact [823b65f982]:
- File src/worldio.mm — part of check-in [4b002822f9] at 2025-03-20 16:04:35 on branch trunk — Convert entity to a class (user: js, size: 9761) [annotate] [blame] [check-ins using]
1 2 3 4 5 6 7 8 9 10 | // worldio.cpp: loading & saving of maps and savegames #include "cube.h" void backup(OFString *name, OFString *backupname) { [OFFileManager.defaultManager removeItemAtPath:backupname]; [OFFileManager.defaultManager moveItemAtPath:name toPath:backupname]; } | > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | // worldio.cpp: loading & saving of maps and savegames #include "cube.h" #import "Entity.h" struct persistent_entity { short x, y, z; // cube aligned position short attr1; uchar type; // type is one of the above uchar attr2, attr3, attr4; }; void backup(OFString *name, OFString *backupname) { [OFFileManager.defaultManager removeItemAtPath:backupname]; [OFFileManager.defaultManager moveItemAtPath:name toPath:backupname]; } |
︙ | ︙ | |||
169 170 171 172 173 174 175 | gzopen([cgzname cStringWithEncoding:OFLocale.encoding], "wb9"); if (!f) { conoutf(@"could not write map to %@", cgzname); return; } hdr.version = MAPVERSION; hdr.numents = 0; | > | > | < | | > | 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | gzopen([cgzname cStringWithEncoding:OFLocale.encoding], "wb9"); if (!f) { conoutf(@"could not write map to %@", cgzname); return; } hdr.version = MAPVERSION; hdr.numents = 0; for (Entity *e in ents) if (e.type != NOTUSED) hdr.numents++; header tmp = hdr; endianswap(&tmp.version, sizeof(int), 4); endianswap(&tmp.waterlevel, sizeof(int), 16); gzwrite(f, &tmp, sizeof(header)); for (Entity *e in ents) { if (e.type != NOTUSED) { struct persistent_entity tmp = { e.x, e.y, e.z, e.attr1, e.type, e.attr2, e.attr3, e.attr4 }; endianswap(&tmp, sizeof(short), 4); gzwrite(f, &tmp, sizeof(persistent_entity)); } } sqr *t = NULL; int sc = 0; #define spurge \ |
︙ | ︙ | |||
269 270 271 272 273 274 275 | fatal(@"illegal map size"); if (hdr.version >= 4) { gzread(f, &hdr.waterlevel, sizeof(int) * 16); endianswap(&hdr.waterlevel, sizeof(int), 16); } else { hdr.waterlevel = -100000; } | | | | | | > > > > > > > > > > > | 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 | fatal(@"illegal map size"); if (hdr.version >= 4) { gzread(f, &hdr.waterlevel, sizeof(int) * 16); endianswap(&hdr.waterlevel, sizeof(int), 16); } else { hdr.waterlevel = -100000; } [ents removeAllObjects]; loopi(hdr.numents) { struct persistent_entity tmp; gzread(f, &tmp, sizeof(persistent_entity)); endianswap(&tmp, sizeof(short), 4); Entity *e = [Entity entity]; e.x = tmp.x; e.y = tmp.y; e.z = tmp.z; e.attr1 = tmp.attr1; e.type = tmp.type; e.attr2 = tmp.attr2; e.attr3 = tmp.attr3; e.attr4 = tmp.attr4; [ents addObject:e]; if (e.type == LIGHT) { if (!e.attr2) e.attr2 = 255; // needed for MAPVERSION<=2 if (e.attr1 > 32) e.attr1 = 32; // 12_03 and below } } |
︙ | ︙ |