More string migration

FossilOrigin-Name: 4a87b39dfe44d37093be0ed635660eea488e329a402a3377c282966fc08d6be8
This commit is contained in:
Jonathan Schleifer 2025-03-08 03:40:26 +00:00
parent 3d8735818d
commit 4871985da9
2 changed files with 160 additions and 156 deletions

View file

@ -146,7 +146,7 @@ renderspheres(int time)
glDepthMask(GL_TRUE); glDepthMask(GL_TRUE);
} }
string closeent; static OFString *closeent;
OFString *entnames[] = { OFString *entnames[] = {
@"none?", @"none?",
@"light", @"light",
@ -176,7 +176,7 @@ OFString *entnames[] = {
void void
renderents() // show sparkly thingies for map entities in edit mode renderents() // show sparkly thingies for map entities in edit mode
{ {
closeent[0] = 0; closeent = @"";
if (!editmode) if (!editmode)
return; return;
loopv(ents) loopv(ents)
@ -190,14 +190,11 @@ renderents() // show sparkly thingies for map entities in edit mode
int e = closestent(); int e = closestent();
if (e >= 0) { if (e >= 0) {
entity &c = ents[e]; entity &c = ents[e];
@autoreleasepool { closeent = [[OFString alloc]
sprintf_s(closeent)( initWithFormat:@"closest entity = %@ (%d, %d, %d, %d), "
"closest entity = %s (%d, %d, %d, %d), " @"selection = (%d, %d)",
"selection = (%d, %d)", entnames[c.type], c.attr1, c.attr2, c.attr3, c.attr4,
entnames[c.type].UTF8String, c.attr1, c.attr2, getvar(@"selxs"), getvar(@"selys")];
c.attr3, c.attr4, getvar(@"selxs"),
getvar(@"selys"));
}
} }
} }
@ -371,8 +368,8 @@ gl_drawhud(int w, int h, int curfps, int nquads, int curvert, bool underwater)
if (command) if (command)
draw_textf(@"> %@_", 20, 1570, 2, command); draw_textf(@"> %@_", 20, 1570, 2, command);
else if (closeent[0]) else if (closeent.length > 0)
draw_text(@(closeent), 20, 1570, 2); draw_text(closeent, 20, 1570, 2);
else if (player != nil) else if (player != nil)
draw_text(player, 20, 1570, 2); draw_text(player, 20, 1570, 2);
} }

View file

@ -3,17 +3,19 @@
#include "cube.h" #include "cube.h"
void void
backup(char *name, char *backupname) backup(OFString *name, OFString *backupname)
{ {
remove(backupname); [OFFileManager.defaultManager removeItemAtPath:backupname];
rename(name, backupname); [OFFileManager.defaultManager moveItemAtPath:name toPath:backupname];
} }
string cgzname, bakname, pcfname, mcfname; static OFString *cgzname, *bakname, *pcfname, *mcfname;
static void static void
setnames(const char *name) setnames(OFString *name_)
{ {
@autoreleasepool {
const char *name = name_.UTF8String;
string pakname, mapname; string pakname, mapname;
const char *slash = strpbrk(name, "/\\"); const char *slash = strpbrk(name, "/\\");
if (slash) { if (slash) {
@ -23,11 +25,17 @@ setnames(const char *name)
strcpy_s(pakname, "base"); strcpy_s(pakname, "base");
strcpy_s(mapname, name); strcpy_s(mapname, name);
} }
sprintf_s(cgzname)("packages/%s/%s.cgz", pakname, mapname);
sprintf_s(bakname)( cgzname = [[OFString alloc]
"packages/%s/%s_%d.BAK", pakname, mapname, lastmillis); initWithFormat:@"packages/%s/%s.cgz", pakname, mapname];
sprintf_s(pcfname)("packages/%s/package.cfg", pakname); bakname =
sprintf_s(mcfname)("packages/%s/%s.cfg", pakname, mapname); [[OFString alloc] initWithFormat:@"packages/%s/%s_%d.BAK",
pakname, mapname, lastmillis];
pcfname = [[OFString alloc]
initWithFormat:@"packages/%s/package.cfg", pakname];
mcfname = [[OFString alloc]
initWithFormat:@"packages/%s/%s.cfg", pakname, mapname];
}
} }
// the optimize routines below are here to reduce the detrimental effects of // the optimize routines below are here to reduce the detrimental effects of
@ -122,12 +130,10 @@ toptimize() // FIXME: only does 2x2, make atleast for 4x4 also
void void
writemap(OFString *mname, int msize, uchar *mdata) writemap(OFString *mname, int msize, uchar *mdata)
{ {
@autoreleasepool { setnames(mname);
setnames(mname.UTF8String);
}
backup(cgzname, bakname); backup(cgzname, bakname);
FILE *f = fopen(cgzname, "wb"); FILE *f = fopen([cgzname cStringWithEncoding:OFLocale.encoding], "wb");
if (!f) { if (!f) {
conoutf(@"could not write map to %s", cgzname); conoutf(@"could not write map to %s", cgzname);
return; return;
@ -140,9 +146,7 @@ writemap(OFString *mname, int msize, uchar *mdata)
OFData * OFData *
readmap(OFString *mname) readmap(OFString *mname)
{ {
@autoreleasepool { setnames(mname);
setnames(mname.UTF8String);
}
return [OFData dataWithContentsOfFile:mname]; return [OFData dataWithContentsOfFile:mname];
} }
@ -161,9 +165,10 @@ save_world(OFString *mname)
toptimize(); toptimize();
if (mname.length == 0) if (mname.length == 0)
mname = getclientmap(); mname = getclientmap();
setnames(mname.UTF8String); setnames(mname);
backup(cgzname, bakname); backup(cgzname, bakname);
gzFile f = gzopen(cgzname, "wb9"); gzFile f = gzopen(
[cgzname cStringWithEncoding:OFLocale.encoding], "wb9");
if (!f) { if (!f) {
conoutf(@"could not write map to %s", cgzname); conoutf(@"could not write map to %s", cgzname);
return; return;
@ -247,13 +252,13 @@ void
load_world(OFString *mname) // still supports all map formats that have existed load_world(OFString *mname) // still supports all map formats that have existed
// since the earliest cube betas! // since the earliest cube betas!
{ {
@autoreleasepool {
stopifrecording(); stopifrecording();
cleardlights(); cleardlights();
pruneundos(); pruneundos();
@autoreleasepool { setnames(mname);
setnames(mname.UTF8String); gzFile f = gzopen(
} [cgzname cStringWithEncoding:OFLocale.encoding], "rb9");
gzFile f = gzopen(cgzname, "rb9");
if (!f) { if (!f) {
conoutf(@"could not read map %s", cgzname); conoutf(@"could not read map %s", cgzname);
return; return;
@ -281,7 +286,8 @@ load_world(OFString *mname) // still supports all map formats that have existed
e.spawned = false; e.spawned = false;
if (e.type == LIGHT) { if (e.type == LIGHT) {
if (!e.attr2) if (!e.attr2)
e.attr2 = 255; // needed for MAPVERSION<=2 e.attr2 =
255; // needed for MAPVERSION<=2
if (e.attr1 > 32) if (e.attr1 > 32)
e.attr1 = 32; // 12_03 and below e.attr1 = 32; // 12_03 and below
} }
@ -329,8 +335,10 @@ load_world(OFString *mname) // still supports all map formats that have existed
default: { default: {
if (type < 0 || type >= MAXTYPE) { if (type < 0 || type >= MAXTYPE) {
OFString *t = [OFString OFString *t = [OFString
stringWithFormat:@"%d @ %d", type, k]; stringWithFormat:@"%d @ %d", type,
fatal(@"while reading map: type out of range: ", k];
fatal(@"while reading map: type out of "
@"range: ",
t); t);
} }
s->type = type; s->type = type;
@ -346,7 +354,8 @@ load_world(OFString *mname) // still supports all map formats that have existed
gzgetc(f); gzgetc(f);
} }
s->vdelta = gzgetc(f); s->vdelta = gzgetc(f);
s->utex = (hdr.version >= 2) ? gzgetc(f) : s->wtex; s->utex =
(hdr.version >= 2) ? gzgetc(f) : s->wtex;
s->tag = (hdr.version >= 5) ? gzgetc(f) : 0; s->tag = (hdr.version >= 5) ? gzgetc(f) : 0;
s->type = type; s->type = type;
} }
@ -355,7 +364,8 @@ load_world(OFString *mname) // still supports all map formats that have existed
t = s; t = s;
texuse[s->wtex] = 1; texuse[s->wtex] = 1;
if (!SOLID(s)) if (!SOLID(s))
texuse[s->utex] = texuse[s->ftex] = texuse[s->ctex] = 1; texuse[s->utex] = texuse[s->ftex] =
texuse[s->ctex] = 1;
} }
gzclose(f); gzclose(f);
calclight(); calclight();
@ -368,17 +378,14 @@ load_world(OFString *mname) // still supports all map formats that have existed
startmap(mname); startmap(mname);
loopl(256) loopl(256)
{ {
@autoreleasepool {
// can this be done smarter? // can this be done smarter?
OFString *aliasname = OFString *aliasname =
[OFString stringWithFormat:@"level_trigger_%d", l]; [OFString stringWithFormat:@"level_trigger_%d", l];
if (identexists(aliasname)) if (identexists(aliasname))
alias(aliasname, @""); alias(aliasname, @"");
} }
}
execfile(@"data/default_map_settings.cfg"); execfile(@"data/default_map_settings.cfg");
@autoreleasepool { execfile(pcfname);
execfile(@(pcfname)); execfile(mcfname);
execfile(@(mcfname));
} }
} }