Use one autorelease pool per frame

This way, nowhere else autorelease pools need to be managed.

FossilOrigin-Name: 489124a92fd2a7e6d543b58ce50e454f2cb1647c81b4ba637d6c252404012ddd
This commit is contained in:
Jonathan Schleifer 2025-03-16 10:11:39 +00:00
parent a67b134eb2
commit 875c395ce1
22 changed files with 1262 additions and 1443 deletions

View file

@ -21,6 +21,7 @@ VARP(minmillis, 0, 5, 1000);
- (void)applicationDidFinishLaunching:(OFNotification *)notification
{
@autoreleasepool {
bool dedicated, windowed;
int par = 0, uprate = 0, maxcl = 4;
OFString *__autoreleasing sdesc, *__autoreleasing ip;
@ -31,8 +32,8 @@ VARP(minmillis, 0, 5, 1000);
#define log(s) conoutf(@"init: %@", s)
log(@"sdl");
const OFOptionsParserOption options[] = { { 'd', @"dedicated", 0,
&dedicated, NULL },
const OFOptionsParserOption options[] = {
{ 'd', @"dedicated", 0, &dedicated, NULL },
{ 't', @"window", 0, &windowed, NULL },
{ 'w', @"width", 1, NULL, NULL },
{ 'h', @"height", 1, NULL, NULL },
@ -42,7 +43,8 @@ VARP(minmillis, 0, 5, 1000);
{ 'm', @"master", 1, NULL, &master },
{ 'p', @"password", 1, NULL, &passwd },
{ 'c', @"max-clients", 1, NULL, NULL },
{ '\0', nil, 0, NULL, NULL } };
{ '\0', nil, 0, NULL, NULL }
};
OFOptionsParser *optionsParser =
[OFOptionsParser parserWithOptions:options];
OFUnichar option;
@ -75,16 +77,18 @@ VARP(minmillis, 0, 5, 1000);
if (passwd == nil)
passwd = @"";
_gameDataIRI = [OFFileManager.defaultManager currentDirectoryIRI];
_userDataIRI = [OFFileManager.defaultManager currentDirectoryIRI];
_gameDataIRI =
[OFFileManager.defaultManager currentDirectoryIRI];
_userDataIRI =
[OFFileManager.defaultManager currentDirectoryIRI];
[OFFileManager.defaultManager
createDirectoryAtIRI:[_userDataIRI
IRIByAppendingPathComponent:@"demos"]
createDirectoryAtIRI:
[_userDataIRI IRIByAppendingPathComponent:@"demos"]
createParents:true];
[OFFileManager.defaultManager
createDirectoryAtIRI:[_userDataIRI
IRIByAppendingPathComponent:@"savegames"]
createDirectoryAtIRI:
[_userDataIRI IRIByAppendingPathComponent:@"savegames"]
createParents:true];
if (SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO | par) < 0)
@ -121,10 +125,12 @@ VARP(minmillis, 0, 5, 1000);
log(@"video: mode");
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
if ((_window = SDL_CreateWindow("cube engine", SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED, _width, _height,
if ((_window = SDL_CreateWindow("cube engine",
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
_width, _height,
SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL |
(!windowed ? SDL_WINDOW_FULLSCREEN : 0))) == NULL ||
(!windowed ? SDL_WINDOW_FULLSCREEN : 0))) ==
NULL ||
SDL_GL_CreateContext(_window) == NULL)
fatal(@"Unable to create OpenGL screen");
@ -139,41 +145,43 @@ VARP(minmillis, 0, 5, 1000);
log(@"basetex");
int xs, ys;
if (!installtex(2,
[_gameDataIRI IRIByAppendingPathComponent:@"data/newchars.png"],
[_gameDataIRI
IRIByAppendingPathComponent:@"data/newchars.png"],
&xs, &ys, false) ||
!installtex(3,
[_gameDataIRI
IRIByAppendingPathComponent:@"data/martin/base.png"],
[_gameDataIRI IRIByAppendingPathComponent:
@"data/martin/base.png"],
&xs, &ys, false) ||
!installtex(6,
[_gameDataIRI
IRIByAppendingPathComponent:@"data/martin/ball1.png"],
[_gameDataIRI IRIByAppendingPathComponent:
@"data/martin/ball1.png"],
&xs, &ys, false) ||
!installtex(7,
[_gameDataIRI
IRIByAppendingPathComponent:@"data/martin/smoke.png"],
[_gameDataIRI IRIByAppendingPathComponent:
@"data/martin/smoke.png"],
&xs, &ys, false) ||
!installtex(8,
[_gameDataIRI
IRIByAppendingPathComponent:@"data/martin/ball2.png"],
[_gameDataIRI IRIByAppendingPathComponent:
@"data/martin/ball2.png"],
&xs, &ys, false) ||
!installtex(9,
[_gameDataIRI
IRIByAppendingPathComponent:@"data/martin/ball3.png"],
[_gameDataIRI IRIByAppendingPathComponent:
@"data/martin/ball3.png"],
&xs, &ys, false) ||
!installtex(4,
[_gameDataIRI
IRIByAppendingPathComponent:@"data/explosion.jpg"],
&xs, &ys, false) ||
!installtex(5,
[_gameDataIRI IRIByAppendingPathComponent:@"data/items.png"],
[_gameDataIRI
IRIByAppendingPathComponent:@"data/items.png"],
&xs, &ys, false) ||
!installtex(1,
[_gameDataIRI
IRIByAppendingPathComponent:@"data/crosshair.png"],
&xs, &ys, false))
fatal(@"could not find core textures (hint: run cube from the "
@"parent of the bin directory)");
fatal(@"could not find core textures (hint: run cube "
@"from the parent of the bin directory)");
log(@"sound");
initsound();
@ -186,7 +194,8 @@ VARP(minmillis, 0, 5, 1000);
exec(@"data/prefabs.cfg");
exec(@"data/sounds.cfg");
exec(@"servers.cfg");
if (!execfile([_userDataIRI IRIByAppendingPathComponent:@"config.cfg"]))
if (!execfile([_userDataIRI
IRIByAppendingPathComponent:@"config.cfg"]))
execfile([_gameDataIRI
IRIByAppendingPathComponent:@"data/defaults.cfg"]);
exec(@"autoexec.cfg");
@ -197,9 +206,12 @@ VARP(minmillis, 0, 5, 1000);
changemap(@"metl3");
log(@"mainloop");
int ignore = 5;
}
OFDate *past = [OFDate date];
int ignore = 5;
for (;;) {
@autoreleasepool {
[OFRunLoop.mainRunLoop runUntilDate:past];
int millis = SDL_GetTicks() * gamespeed / 100;
@ -225,8 +237,8 @@ VARP(minmillis, 0, 5, 1000);
extern void updatevol();
updatevol();
// cheap hack to get rid of initial sparklies, even when triple
// buffering etc.
// cheap hack to get rid of initial sparklies, even when
// triple buffering etc.
if (_framesInMap++ < 5) {
player1.yaw += 5;
gl_drawframe(_width, _height, fps);
@ -244,27 +256,29 @@ VARP(minmillis, 0, 5, 1000);
break;
case SDL_KEYDOWN:
case SDL_KEYUP:
if (_repeatsKeys || event.key.repeat == 0)
if (_repeatsKeys ||
event.key.repeat == 0)
keypress(event.key.keysym.sym,
event.key.state == SDL_PRESSED);
event.key.state ==
SDL_PRESSED);
break;
case SDL_TEXTINPUT:
@autoreleasepool {
input(@(event.text.text));
}
break;
case SDL_MOUSEMOTION:
if (ignore) {
ignore--;
break;
}
mousemove(event.motion.xrel, event.motion.yrel);
mousemove(event.motion.xrel,
event.motion.yrel);
break;
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:
if (lasttype == event.type &&
lastbut == event.button.button)
// why?? get event twice without it
// why?? get event twice without
// it
break;
keypress(-event.button.button,
@ -275,8 +289,7 @@ VARP(minmillis, 0, 5, 1000);
}
}
}
[self quit];
}
}
- (void)applicationWillTerminate:(OFNotification *)notification
@ -323,16 +336,12 @@ VARP(minmillis, 0, 5, 1000);
endianswap(dest, 3, _width);
}
@autoreleasepool {
OFString *path = [OFString
stringWithFormat:
@"screenshots/screenshot_%d.bmp",
stringWithFormat:@"screenshots/screenshot_%d.bmp",
lastmillis];
SDL_SaveBMP(temp,
[_userDataIRI
IRIByAppendingPathComponent:path]
[_userDataIRI IRIByAppendingPathComponent:path]
.fileSystemRepresentation.UTF8String);
}
SDL_FreeSurface(temp);
}

View file

@ -54,11 +54,11 @@ snap(int sn, float f)
- (bool)loadWithIRI:(OFIRI *)IRI
{
@autoreleasepool {
OFSeekableStream *stream;
@try {
stream = (OFSeekableStream *)[[OFIRIHandler
handlerForIRI:IRI] openItemAtIRI:IRI mode:@"r"];
stream = (OFSeekableStream *)[[OFIRIHandler handlerForIRI:IRI]
openItemAtIRI:IRI
mode:@"r"];
} @catch (id e) {
return false;
}
@ -68,8 +68,7 @@ snap(int sn, float f)
md2_header header;
[stream readIntoBuffer:&header exactLength:sizeof(md2_header)];
endianswap(
&header, sizeof(int), sizeof(md2_header) / sizeof(int));
endianswap(&header, sizeof(int), sizeof(md2_header) / sizeof(int));
if (header.magic != 844121161 || header.version != 8)
return false;
@ -83,8 +82,7 @@ snap(int sn, float f)
exactLength:header.frameSize * header.numFrames];
for (int i = 0; i < header.numFrames; ++i)
endianswap(
_frames + i * header.frameSize, sizeof(float), 6);
endianswap(_frames + i * header.frameSize, sizeof(float), 6);
_glCommands = new int[header.numGlCommands];
if (_glCommands == NULL)
@ -107,7 +105,6 @@ snap(int sn, float f)
loopj(_numFrames) _mverts[j] = NULL;
return true;
}
}
- (void)scaleWithFrame:(int)frame scale:(float)scale snap:(int)sn

View file

@ -63,28 +63,24 @@ throttle()
void
newname(OFString *name)
{
@autoreleasepool {
c2sinit = false;
if (name.length > 16)
name = [name substringToIndex:16];
player1.name = name;
}
}
COMMANDN(name, newname, ARG_1STR)
void
newteam(OFString *name)
{
@autoreleasepool {
c2sinit = false;
if (name.length > 5)
name = [name substringToIndex:5];
player1.team = name;
}
}
COMMANDN(team, newteam, ARG_1STR)
@ -103,13 +99,10 @@ connects(OFString *servername)
conoutf(@"attempting to connect to %@", servername);
ENetAddress address = { ENET_HOST_ANY, CUBE_SERVER_PORT };
@autoreleasepool {
if (enet_address_set_host(&address, servername.UTF8String) <
0) {
if (enet_address_set_host(&address, servername.UTF8String) < 0) {
conoutf(@"could not resolve server %@", servername);
return;
}
}
clienthost = enet_host_create(NULL, 1, rate, rate);
@ -287,18 +280,17 @@ sendpackettoserv(void *packet)
void
c2sinfo(DynamicEntity *d)
{
@autoreleasepool {
if (clientnum < 0)
return; // we haven't had a welcome message from the
// server yet
return; // we haven't had a welcome message from the server yet
if (lastmillis - lastupdate < 40)
return; // don't update faster than 25fps
ENetPacket *packet = enet_packet_create(NULL, MAXTRANS, 0);
uchar *start = packet->data;
uchar *p = start + 2;
bool serveriteminitdone = false;
if (toservermap.length > 0) // suggest server to change map
{ // do this exclusively as map change may invalidate rest of
// suggest server to change map
if (toservermap.length > 0) {
// do this exclusively as map change may invalidate rest of
// update
packet->flags = ENET_PACKET_FLAG_RELIABLE;
putint(p, SV_MAPCHANGE);
@ -308,8 +300,8 @@ c2sinfo(DynamicEntity *d)
} else {
putint(p, SV_POS);
putint(p, clientnum);
// quantize coordinates to 1/16th of a cube, between 1
// and 3 bytes
// quantize coordinates to 1/16th of a cube, between 1 and 3
// bytes
putint(p, (int)(d.o.x * DMF));
putint(p, (int)(d.o.y * DMF));
putint(p, (int)(d.o.z * DMF));
@ -320,8 +312,7 @@ c2sinfo(DynamicEntity *d)
putint(p, (int)(d.vel.x * DVF));
putint(p, (int)(d.vel.y * DVF));
putint(p, (int)(d.vel.z * DVF));
// pack rest in 1 byte: strafe:2, move:2, onfloor:1,
// state:3
// pack rest in 1 byte: strafe:2, move:2, onfloor:1, state:3
putint(p,
(d.strafe & 3) | ((d.move & 3) << 2) |
(((int)d.onfloor) << 4) |
@ -353,11 +344,9 @@ c2sinfo(DynamicEntity *d)
putint(p, player1.lifesequence);
}
for (OFData *msg in messages) {
// send messages collected during the previous
// frames
// send messages collected during the previous frames
if (*(int *)[msg itemAtIndex:1])
packet->flags =
ENET_PACKET_FLAG_RELIABLE;
packet->flags = ENET_PACKET_FLAG_RELIABLE;
loopi(*(int *)[msg itemAtIndex:0])
putint(p, *(int *)[msg itemAtIndex:i + 2]);
}
@ -379,7 +368,6 @@ c2sinfo(DynamicEntity *d)
lastupdate = lastmillis;
if (serveriteminitdone)
loadgamerest(); // hack
}
}
void

View file

@ -107,13 +107,12 @@ static OFMutableArray<OFString *> *scoreLines;
void
renderscore(DynamicEntity *d)
{
@autoreleasepool {
OFString *lag = [OFString stringWithFormat:@"%d", d.plag];
OFString *name = [OFString stringWithFormat:@"(%@)", d.name];
OFString *line =
[OFString stringWithFormat:@"%d\t%@\t%d\t%@\t%@", d.frags,
(d.state == CS_LAGGED ? @"LAG" : lag), d.ping,
d.team, (d.state == CS_DEAD ? name : d.name)];
(d.state == CS_LAGGED ? @"LAG" : lag), d.ping, d.team,
(d.state == CS_DEAD ? name : d.name)];
if (scoreLines == nil)
scoreLines = [[OFMutableArray alloc] init];
@ -121,7 +120,6 @@ renderscore(DynamicEntity *d)
[scoreLines addObject:line];
menumanual(0, scoreLines.count - 1, line);
}
}
static const int maxTeams = 4;
@ -132,7 +130,6 @@ static size_t teamsUsed;
void
addteamscore(DynamicEntity *d)
{
@autoreleasepool {
for (size_t i = 0; i < teamsUsed; i++) {
if ([teamName[i] isEqual:d.team]) {
teamScore[i] += d.frags;
@ -145,7 +142,6 @@ addteamscore(DynamicEntity *d)
teamName[teamsUsed] = d.team;
teamScore[teamsUsed++] = d.frags;
}
}
void
@ -172,10 +168,8 @@ renderscores()
[teamScores appendFormat:@"[ %@: %d ]", teamName[j],
teamScore[j]];
menumanual(0, scoreLines.count, @"");
@autoreleasepool {
menumanual(0, scoreLines.count + 1, teamScores);
}
}
}
// sendmap/getmap commands, should be replaced by more intuitive map downloading
@ -183,7 +177,6 @@ renderscores()
void
sendmap(OFString *mapname)
{
@autoreleasepool {
if (mapname.length > 0)
save_world(mapname);
changemap(mapname);
@ -214,7 +207,6 @@ sendmap(OFString *mapname)
@"\"getmap\" to receive it]",
mapname];
toserver(msg);
}
}
void

View file

@ -95,16 +95,13 @@ localservertoclient(uchar *buf, int len)
// map
toservermap = getclientmap();
sgetstr();
@autoreleasepool {
if (text[0] &&
strcmp(text, clientpassword.UTF8String)) {
conoutf(@"you need to set the correct "
@"password "
conoutf(@"you need to set the correct password "
@"to join this server!");
disconnect();
return;
}
}
if (getint(p) == 1)
conoutf(@"server is FULL, disconnecting..");
break;
@ -150,9 +147,7 @@ localservertoclient(uchar *buf, int len)
case SV_MAPCHANGE:
sgetstr();
@autoreleasepool {
changemapserv(@(text), getint(p));
}
mapchanged = true;
break;
@ -378,12 +373,10 @@ localservertoclient(uchar *buf, int len)
conoutf(@"received map \"%s\" from server, reloading..",
text);
int mapsize = getint(p);
@autoreleasepool {
OFString *string = @(text);
writemap(string, mapsize, p);
p += mapsize;
changemapserv(string, gamemode);
}
break;
}

View file

@ -123,17 +123,14 @@ parseexp(char *&p, int right)
}
char *s = strndup(word, p - word - 1);
if (left == '(') {
@autoreleasepool {
OFString *t;
@try {
t = [OFString
stringWithFormat:@"%d", execute(@(s))];
t = [OFString stringWithFormat:@"%d", execute(@(s))];
} @finally {
free(s);
}
s = strdup(t.UTF8String);
}
}
return s;
}
@ -164,19 +161,16 @@ parseword(char *&p)
return strndup(word, p - word);
}
// find value of ident referenced with $ in exp
OFString *
lookup(OFString *n) // find value of ident referenced with $ in exp
lookup(OFString *n)
{
@autoreleasepool {
__kindof Identifier *identifier =
identifiers[[n substringFromIndex:1]];
__kindof Identifier *identifier = identifiers[[n substringFromIndex:1]];
if ([identifier isKindOfClass:Variable.class]) {
return [OFString
stringWithFormat:@"%d", *[identifier storage]];
return [OFString stringWithFormat:@"%d", *[identifier storage]];
} else if ([identifier isKindOfClass:Alias.class])
return [identifier action];
}
conoutf(@"unknown alias lookup: %@", [n substringFromIndex:1]);
return n;
@ -234,7 +228,6 @@ executeIdentifier(__kindof Identifier *identifier,
int
execute(OFString *string, bool isDown)
{
@autoreleasepool {
std::unique_ptr<char> copy(strdup(string.UTF8String));
char *p = copy.get();
const int MAXWORDS = 25; // limit, remove
@ -284,7 +277,6 @@ execute(OFString *string, bool isDown)
}
return val;
}
}
// tab-completion of all identifiers
@ -300,7 +292,6 @@ resetcomplete()
void
complete(OFMutableString *s)
{
@autoreleasepool {
if (![s hasPrefix:@"/"])
[s insertString:@"/" atIndex:0];
@ -315,11 +306,10 @@ complete(OFMutableString *s)
__block int idx = 0;
[identifiers enumerateKeysAndObjectsUsingBlock:^(
OFString *name, Identifier *identifier, bool *stop) {
if (strncmp(identifier.name.UTF8String,
s.UTF8String + 1, completesize) == 0 &&
if (strncmp(identifier.name.UTF8String, s.UTF8String + 1,
completesize) == 0 &&
idx++ == completeidx)
[s replaceCharactersInRange:OFMakeRange(
1, s.length - 1)
[s replaceCharactersInRange:OFMakeRange(1, s.length - 1)
withString:identifier.name];
}];
@ -327,13 +317,11 @@ complete(OFMutableString *s)
if (completeidx >= idx)
completeidx = 0;
}
}
bool
execfile(OFIRI *cfgfile)
{
@autoreleasepool {
OFString *command;
@try {
command = [OFString stringWithContentsOfIRI:cfgfile];
@ -345,19 +333,16 @@ execfile(OFIRI *cfgfile)
execute(command);
return true;
}
}
void
exec(OFString *cfgfile)
{
@autoreleasepool {
if (!execfile([Cube.sharedInstance.userDataIRI
IRIByAppendingPathComponent:cfgfile]) &&
!execfile([Cube.sharedInstance.gameDataIRI
IRIByAppendingPathComponent:cfgfile]))
conoutf(@"could not read \"%@\"", cfgfile);
}
}
void
@ -418,9 +403,7 @@ COMMAND(writecfg, ARG_NONE)
void
intset(OFString *name, int v)
{
@autoreleasepool {
alias(name, [OFString stringWithFormat:@"%d", v]);
}
}
void
@ -432,7 +415,6 @@ ifthen(OFString *cond, OFString *thenp, OFString *elsep)
void
loopa(OFString *times, OFString *body)
{
@autoreleasepool {
int t = times.cube_intValue;
loopi(t)
@ -440,7 +422,6 @@ loopa(OFString *times, OFString *body)
intset(@"i", i);
execute(body);
}
}
}
void
@ -472,7 +453,6 @@ concatword(OFString *s)
int
listlen(OFString *a_)
{
@autoreleasepool {
const char *a = a_.UTF8String;
if (!*a)
@ -484,20 +464,17 @@ listlen(OFString *a_)
n++;
return n + 1;
}
}
void
at(OFString *s_, OFString *pos)
{
@autoreleasepool {
int n = pos.cube_intValue;
std::unique_ptr<char> copy(strdup(s_.UTF8String));
char *s = copy.get();
loopi(n) s += strspn(s += strcspn(s, " \0"), " ");
s[strcspn(s, " \0")] = 0;
concat(@(s));
}
}
COMMANDN(loop, loopa, ARG_2STR)

View file

@ -83,7 +83,6 @@ conline(OFString *sf, bool highlight) // add a line to the console buffer
void
conoutf(OFConstantString *format, ...)
{
@autoreleasepool {
va_list arguments;
va_start(arguments, format);
@ -98,7 +97,6 @@ conoutf(OFConstantString *format, ...)
string = [string substringFromIndex:WORDWRAP];
}
conline(string, n != 0);
}
}
// render buffer taking into account time & scrolling
@ -181,19 +179,15 @@ COMMAND(saycommand, ARG_VARI)
void
mapmsg(OFString *s)
{
@autoreleasepool {
memset(hdr.maptitle, '\0', sizeof(hdr.maptitle));
strncpy(hdr.maptitle, s.UTF8String, 127);
}
}
COMMAND(mapmsg, ARG_1STR)
void
pasteconsole()
{
@autoreleasepool {
[commandbuf appendString:@(SDL_GetClipboardText())];
}
}
static OFMutableArray<OFString *> *vhistory;
@ -262,22 +256,18 @@ keypress(int code, bool isDown)
} else {
if (code == SDLK_RETURN) {
if (commandbuf.length > 0) {
@autoreleasepool {
if (vhistory == nil)
vhistory =
[[OFMutableArray
alloc] init];
[[OFMutableArray alloc]
init];
if (vhistory.count == 0 ||
![vhistory.lastObject
isEqual:commandbuf]) {
// cap this?
[vhistory
addObject:
[commandbuf
[vhistory addObject:[commandbuf
copy]];
}
}
histpos = vhistory.count;
if ([commandbuf hasPrefix:@"/"])
execute(commandbuf, true);

View file

@ -604,11 +604,9 @@ void
newent(OFString *what, OFString *a1, OFString *a2, OFString *a3, OFString *a4)
{
EDITSEL;
@autoreleasepool {
newentity(sel.x, sel.y, (int)player1.o.z, what,
[a1 cube_intValueWithBase:0], [a2 cube_intValueWithBase:0],
[a3 cube_intValueWithBase:0], [a4 cube_intValueWithBase:0]);
}
}
COMMANDN(select, selectpos, ARG_4INT)

View file

@ -42,15 +42,10 @@ renderentities()
MapModelInfo *mmi = getmminfo(e.attr2);
if (mmi == nil)
continue;
@autoreleasepool {
rendermodel(mmi.name, 0, 1, e.attr4,
(float)mmi.rad, e.x,
(float)S(e.x, e.y)->floor + mmi.zoff +
e.attr3,
e.y,
(float)((e.attr1 + 7) - (e.attr1 + 7) % 15),
0, false, 1.0f, 10.0f, mmi.snap);
}
rendermodel(mmi.name, 0, 1, e.attr4, (float)mmi.rad,
e.x, (float)S(e.x, e.y)->floor + mmi.zoff + e.attr3,
e.y, (float)((e.attr1 + 7) - (e.attr1 + 7) % 15), 0,
false, 1.0f, 10.0f, mmi.snap);
} else {
if (OUTBORD(e.x, e.y))
continue;

View file

@ -43,7 +43,6 @@ void refreshservers();
bool
rendermenu()
{
@autoreleasepool {
if (vmenu < 0) {
[menuStack removeAllObjects];
return false;
@ -55,8 +54,7 @@ rendermenu()
Menu *m = menus[vmenu];
OFString *title;
if (vmenu > 1)
title =
[OFString stringWithFormat:@"[ %@ menu ]", m.name];
title = [OFString stringWithFormat:@"[ %@ menu ]", m.name];
else
title = m.name;
int mdisp = m.items.count;
@ -80,8 +78,8 @@ rendermenu()
y += FONTH * 2;
if (vmenu) {
int bh = y + m.menusel * step;
blendbox(x - FONTH, bh - 10, x + w + FONTH,
bh + FONTH + 10, false);
blendbox(
x - FONTH, bh - 10, x + w + FONTH, bh + FONTH + 10, false);
}
loopj(mdisp)
{
@ -89,7 +87,6 @@ rendermenu()
y += step;
}
return true;
}
}
void
@ -154,11 +151,8 @@ menukey(int code, bool isdown)
} else {
if (code == SDLK_RETURN || code == -2) {
OFString *action = menus[vmenu].items[menusel].action;
if (vmenu == 1) {
@autoreleasepool {
if (vmenu == 1)
connects(getservername(menusel));
}
}
if (menuStack == nil)
menuStack = [[OFMutableArray alloc] init];

View file

@ -203,7 +203,6 @@ renderents() // show sparkly thingies for map entities in edit mode
void
loadsky(OFString *basename)
{
@autoreleasepool {
static OFString *lastsky = @"";
basename = [basename stringByReplacingOccurrencesOfString:@"\\"
@ -212,14 +211,13 @@ loadsky(OFString *basename)
if ([lastsky isEqual:basename])
return;
static const OFString *side[] = { @"ft", @"bk", @"lf", @"rt",
@"dn", @"up" };
static const OFString *side[] = { @"ft", @"bk", @"lf", @"rt", @"dn",
@"up" };
int texnum = 14;
loopi(6)
{
OFString *path =
[OFString stringWithFormat:@"packages/%@_%@.jpg",
basename, side[i]];
OFString *path = [OFString
stringWithFormat:@"packages/%@_%@.jpg", basename, side[i]];
int xs, ys;
if (!installtex(texnum + i,
@ -230,7 +228,6 @@ loadsky(OFString *basename)
}
lastsky = basename;
}
}
COMMAND(loadsky, ARG_1STR)
@ -367,7 +364,6 @@ gl_drawhud(int w, int h, int curfps, int nquads, int curvert, bool underwater)
glEnable(GL_TEXTURE_2D);
@autoreleasepool {
OFString *command = getcurcommand();
OFString *player = playerincrosshair();
@ -377,7 +373,6 @@ gl_drawhud(int w, int h, int curfps, int nquads, int curvert, bool underwater)
draw_text(closeent, 20, 1570, 2);
else if (player != nil)
draw_text(player, 20, 1570, 2);
}
renderscores();
if (!rendermenu()) {

View file

@ -78,9 +78,7 @@ cleangl()
bool
installtex(int tnum, OFIRI *IRI, int *xs, int *ys, bool clamp)
{
@autoreleasepool {
SDL_Surface *s =
IMG_Load(IRI.fileSystemRepresentation.UTF8String);
SDL_Surface *s = IMG_Load(IRI.fileSystemRepresentation.UTF8String);
if (s == NULL) {
conoutf(@"couldn't load texture %@", IRI.string);
return false;
@ -90,8 +88,7 @@ installtex(int tnum, OFIRI *IRI, int *xs, int *ys, bool clamp)
SDL_PixelFormat *format =
SDL_AllocFormat(SDL_PIXELFORMAT_RGB24);
if (format == NULL) {
conoutf(
@"texture cannot be converted to 24bpp: %@",
conoutf(@"texture cannot be converted to 24bpp: %@",
IRI.string);
return false;
}
@ -126,8 +123,7 @@ installtex(int tnum, OFIRI *IRI, int *xs, int *ys, bool clamp)
clamp ? GL_CLAMP_TO_EDGE : GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
clamp ? GL_CLAMP_TO_EDGE : GL_REPEAT);
glTexParameteri(
GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_LINEAR_MIPMAP_LINEAR); // NEAREST);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
@ -145,8 +141,8 @@ installtex(int tnum, OFIRI *IRI, int *xs, int *ys, bool clamp)
conoutf(@"warning: quality loss: scaling %@",
IRI.string); // for voodoo cards under linux
scaledimg = OFAllocMemory(1, *xs * *ys * 3);
gluScaleImage(GL_RGB, s->w, s->h, GL_UNSIGNED_BYTE,
s->pixels, *xs, *ys, GL_UNSIGNED_BYTE, scaledimg);
gluScaleImage(GL_RGB, s->w, s->h, GL_UNSIGNED_BYTE, s->pixels,
*xs, *ys, GL_UNSIGNED_BYTE, scaledimg);
}
if (gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, *xs, *ys, GL_RGB,
@ -159,7 +155,6 @@ installtex(int tnum, OFIRI *IRI, int *xs, int *ys, bool clamp)
SDL_FreeSurface(s);
return true;
}
}
// management of texture slots
@ -197,17 +192,14 @@ COMMAND(texturereset, ARG_NONE)
void
texture(OFString *aframe, OFString *name)
{
@autoreleasepool {
int num = curtexnum++, frame = aframe.cube_intValue;
if (num < 0 || num >= 256 || frame < 0 || frame >= MAXFRAMES)
return;
mapping[num][frame] = 1;
mapname[num][frame] =
[name stringByReplacingOccurrencesOfString:@"\\"
mapname[num][frame] = [name stringByReplacingOccurrencesOfString:@"\\"
withString:@"/"];
}
}
COMMAND(texture, ARG_2STR)
@ -243,7 +235,6 @@ lookuptexture(int tex, int *xs, int *ys)
int tnum = curtex + FIRSTTEX;
texname[curtex] = mapname[tex][frame];
@autoreleasepool {
OFString *path =
[OFString stringWithFormat:@"packages/%@", texname[curtex]];
@ -259,7 +250,6 @@ lookuptexture(int tex, int *xs, int *ys)
} else {
return mapping[tex][frame] = FIRSTTEX; // temp fix
}
}
}
void

View file

@ -16,30 +16,25 @@ void
delayedload(MD2 *m)
{
if (!m.loaded) {
@autoreleasepool {
OFString *path = [OFString
stringWithFormat:@"packages/models/%@", m.loadname];
OFIRI *baseIRI = [Cube.sharedInstance.gameDataIRI
IRIByAppendingPathComponent:path];
OFIRI *IRI1 =
[baseIRI IRIByAppendingPathComponent:@"tris.md2"];
OFIRI *IRI1 = [baseIRI IRIByAppendingPathComponent:@"tris.md2"];
if (![m loadWithIRI:IRI1])
fatal(@"loadmodel: ", IRI1.string);
OFIRI *IRI2 =
[baseIRI IRIByAppendingPathComponent:@"skin.jpg"];
OFIRI *IRI2 = [baseIRI IRIByAppendingPathComponent:@"skin.jpg"];
int xs, ys;
installtex(FIRSTMDL + m.mdlnum, IRI2, &xs, &ys, false);
m.loaded = true;
}
}
}
MD2 *
loadmodel(OFString *name)
{
@autoreleasepool {
static int modelnum = 0;
MD2 *m = mdllookup[name];
@ -48,11 +43,7 @@ loadmodel(OFString *name)
m = [[MD2 alloc] init];
m.mdlnum = modelnum++;
m.mmi = [[MapModelInfo alloc] initWithRad:2
h:2
zoff:0
snap:0
name:@""];
m.mmi = [[MapModelInfo alloc] initWithRad:2 h:2 zoff:0 snap:0 name:@""];
m.loadname = name;
if (mdllookup == nil)
@ -61,7 +52,6 @@ loadmodel(OFString *name)
mdllookup[name] = m;
return m;
}
}
void

View file

@ -102,7 +102,6 @@ short char_coords[96][4] = {
int
text_width(OFString *string)
{
@autoreleasepool {
const char *str = string.UTF8String;
size_t len = string.UTF8StringLength;
@ -131,26 +130,22 @@ text_width(OFString *string)
}
return x;
}
}
void
draw_textf(OFConstantString *format, int left, int top, int gl_num, ...)
{
@autoreleasepool {
va_list arguments;
va_start(arguments, gl_num);
OFString *str = [[OFString alloc] initWithFormat:format
arguments:arguments];
va_end(arguments);
draw_text(str, left, top, gl_num);
}
}
void
draw_text(OFString *string, int left, int top, int gl_num)
{
@autoreleasepool {
glBlendFunc(GL_ONE, GL_ONE);
glBindTexture(GL_TEXTURE_2D, gl_num);
glColor3ub(255, 255, 255);
@ -168,9 +163,7 @@ draw_text(OFString *string, int left, int top, int gl_num)
int c = str[i];
if (c == '\t') {
x = (x - left + PIXELTAB) / PIXELTAB *
PIXELTAB +
left;
x = (x - left + PIXELTAB) / PIXELTAB * PIXELTAB + left;
continue;
}
@ -210,7 +203,6 @@ draw_text(OFString *string, int left, int top, int gl_num)
xtraverts += 4;
x += in_width + 1;
}
}
}
// also Don's code, so goes in here too :)

View file

@ -91,7 +91,6 @@ stopifrecording()
void
savestate(OFIRI *IRI)
{
@autoreleasepool {
stop();
f = gzopen([IRI.fileSystemRepresentation
cStringWithEncoding:OFLocale.encoding],
@ -125,7 +124,6 @@ savestate(OFIRI *IRI)
data = [player dataBySerializing];
gzwrite(f, data.items, data.count);
}
}
}
void
@ -136,22 +134,18 @@ savegame(OFString *name)
return;
}
@autoreleasepool {
OFString *path =
[OFString stringWithFormat:@"savegames/%@.csgz", name];
OFIRI *IRI = [Cube.sharedInstance.userDataIRI
IRIByAppendingPathComponent:path];
OFString *path = [OFString stringWithFormat:@"savegames/%@.csgz", name];
OFIRI *IRI =
[Cube.sharedInstance.userDataIRI IRIByAppendingPathComponent:path];
savestate(IRI);
stop();
conoutf(@"wrote %@", IRI.string);
}
}
COMMAND(savegame, ARG_1STR)
void
loadstate(OFIRI *IRI)
{
@autoreleasepool {
stop();
if (multiplayer())
return;
@ -177,29 +171,23 @@ loadstate(OFIRI *IRI)
goto out;
gzread(f, mapname, _MAXDEFSTR);
nextmode = gzgeti();
@autoreleasepool {
// continue below once map has been loaded and client &
// server have updated
// continue below once map has been loaded and client & server
// have updated
changemap(@(mapname));
}
return;
out:
out:
conoutf(@"aborting: savegame/demo from a different version of "
@"cube or cpu architecture");
stop();
}
}
void
loadgame(OFString *name)
{
@autoreleasepool {
OFString *path =
[OFString stringWithFormat:@"savegames/%@.csgz", name];
OFIRI *IRI = [Cube.sharedInstance.userDataIRI
IRIByAppendingPathComponent:path];
OFString *path = [OFString stringWithFormat:@"savegames/%@.csgz", name];
OFIRI *IRI =
[Cube.sharedInstance.userDataIRI IRIByAppendingPathComponent:path];
loadstate(IRI);
}
}
COMMAND(loadgame, ARG_1STR)
@ -286,18 +274,15 @@ record(OFString *name)
if (cn < 0)
return;
@autoreleasepool {
OFString *path =
[OFString stringWithFormat:@"demos/%@.cdgz", name];
OFIRI *IRI = [Cube.sharedInstance.userDataIRI
IRIByAppendingPathComponent:path];
OFString *path = [OFString stringWithFormat:@"demos/%@.cdgz", name];
OFIRI *IRI =
[Cube.sharedInstance.userDataIRI IRIByAppendingPathComponent:path];
savestate(IRI);
gzputi(cn);
conoutf(@"started recording demo to %@", IRI.string);
demorecording = true;
starttime = lastmillis;
ddamage = bdamage = 0;
}
}
COMMAND(record, ARG_1STR)
@ -348,14 +333,11 @@ incomingdemodata(uchar *buf, int len, bool extras)
void
demo(OFString *name)
{
@autoreleasepool {
OFString *path =
[OFString stringWithFormat:@"demos/%@.cdgz", name];
OFIRI *IRI = [Cube.sharedInstance.userDataIRI
IRIByAppendingPathComponent:path];
OFString *path = [OFString stringWithFormat:@"demos/%@.cdgz", name];
OFIRI *IRI =
[Cube.sharedInstance.userDataIRI IRIByAppendingPathComponent:path];
loadstate(IRI);
demoloading = true;
}
}
COMMAND(demo, ARG_1STR)

View file

@ -173,13 +173,10 @@ vote(OFString *map, int reqmode, int sender)
if (yes == 1 && no == 0)
return true; // single player
@autoreleasepool {
OFString *msg =
[OFString stringWithFormat:
@"%@ suggests %@ on map %@ (set map to vote)",
OFString *msg = [OFString
stringWithFormat:@"%@ suggests %@ on map %@ (set map to vote)",
clients[sender].name, modestr(reqmode), map];
sendservmsg(msg);
}
if (yes / (float)(yes + no) <= 0.5f)
return false;
@ -215,9 +212,7 @@ process(ENetPacket *packet, int sender) // sender may be -1
case SV_INITC2S:
sgetstr();
@autoreleasepool {
clients[cn].name = @(text);
}
sgetstr();
getint(p);
break;
@ -227,19 +222,15 @@ process(ENetPacket *packet, int sender) // sender may be -1
int reqmode = getint(p);
if (reqmode < 0)
reqmode = 0;
@autoreleasepool {
if (smapname.length > 0 && !mapreload &&
!vote(@(text), reqmode, sender))
return;
}
mapreload = false;
mode = reqmode;
minremain = mode & 1 ? 15 : 10;
mapend = lastsec + minremain * 60;
interm = 0;
@autoreleasepool {
smapname = @(text);
}
resetitems();
sender = -1;
break;
@ -284,9 +275,7 @@ process(ENetPacket *packet, int sender) // sender may be -1
case SV_SENDMAP: {
sgetstr();
int mapsize = getint(p);
@autoreleasepool {
sendmaps(sender, @(text), mapsize, p);
}
return;
}
@ -329,9 +318,7 @@ send_welcome(int n)
putint(p, SV_INITS2C);
putint(p, n);
putint(p, PROTOCOL_VERSION);
@autoreleasepool {
putint(p, *smapname.UTF8String);
}
sendstring(serverpassword, p);
putint(p, clients.count > maxclients);
if (smapname.length > 0) {
@ -493,13 +480,10 @@ serverslice(int seconds,
c.peer = event.peer;
c.peer->data = (void *)(clients.count - 1);
char hn[1024];
@autoreleasepool {
c.hostname =
(enet_address_get_host(
c.hostname = (enet_address_get_host(
&c.peer->address, hn, sizeof(hn)) == 0
? @(hn)
: @"localhost");
}
[OFStdOut
writeFormat:@"client connected (%@)\n", c.hostname];
send_welcome(lastconnect = clients.count - 1);
@ -566,11 +550,9 @@ initserver(bool dedicated, int uprate, OFString *sdesc, OFString *ip,
if ((isdedicated = dedicated)) {
ENetAddress address = { ENET_HOST_ANY, CUBE_SERVER_PORT };
@autoreleasepool {
if (ip.length > 0 &&
enet_address_set_host(&address, ip.UTF8String) < 0)
printf("WARNING: server ip not resolved");
}
serverhost = enet_host_create(&address, MAXCLIENTS, 0, uprate);
if (!serverhost)
fatal(@"could not create server host\n");
@ -589,6 +571,9 @@ initserver(bool dedicated, int uprate, OFString *sdesc, OFString *ip,
atexit(cleanupserver);
atexit(enet_deinitialize);
for (;;)
serverslice(/*enet_time_get_sec()*/ time(NULL), 5);
@autoreleasepool {
serverslice(
/*enet_time_get_sec()*/ time(NULL), 5);
}
}
}

View file

@ -180,7 +180,6 @@ getservername(int n)
void
addserver(OFString *servername)
{
@autoreleasepool {
for (ServerInfo *si in servers)
if ([si.name isEqual:servername])
return;
@ -188,9 +187,7 @@ addserver(OFString *servername)
if (servers == nil)
servers = [[OFMutableArray alloc] init];
[servers
addObject:[[ServerInfo alloc] initWithName:servername]];
}
[servers addObject:[[ServerInfo alloc] initWithName:servername]];
}
void
@ -260,13 +257,9 @@ checkpings()
si.numplayers = getint(p);
si.minremain = getint(p);
sgetstr();
@autoreleasepool {
si.map = @(text);
}
sgetstr();
@autoreleasepool {
si.sdesc = @(text);
}
break;
}
}
@ -306,10 +299,8 @@ refreshservers()
si.name];
// cut off too long server descriptions
@autoreleasepool {
if (si.full.length > 50)
si.full = [si.full substringToIndex:50];
}
menumanual(1, i, si.full);
@ -348,10 +339,8 @@ updatefrommaster()
conoutf(@"master server not replying");
else {
[servers removeAllObjects];
@autoreleasepool {
execute(@((char *)reply));
}
}
servermenu();
}
@ -366,9 +355,7 @@ writeservercfg()
if (!f)
return;
fprintf(f, "// servers connected to are added here automatically\n\n");
@autoreleasepool {
for (ServerInfo *si in servers.reversedArray)
fprintf(f, "addserver %s\n", si.name.UTF8String);
}
fclose(f);
}

View file

@ -10,9 +10,7 @@ httpgetsend(ENetAddress &ad, OFString *hostname, OFString *req, OFString *ref,
{
if (ad.host == ENET_HOST_ANY) {
[OFStdOut writeFormat:@"looking up %@...\n", hostname];
@autoreleasepool {
enet_address_set_host(&ad, hostname.UTF8String);
}
if (ad.host == ENET_HOST_ANY)
return;
}
@ -79,13 +77,10 @@ updatemasterserver(int seconds)
{
// send alive signal to masterserver every hour of uptime
if (seconds > updmaster) {
@autoreleasepool {
OFString *path = [OFString
stringWithFormat:@"%@register.do?action=add",
masterpath];
httpgetsend(masterserver, masterbase, path,
@"cubeserver", @"Cube Server");
}
stringWithFormat:@"%@register.do?action=add", masterpath];
httpgetsend(masterserver, masterbase, path, @"cubeserver",
@"Cube Server");
masterrep[0] = 0;
masterb.data = masterrep;
masterb.dataLength = MAXTRANS - 1;
@ -105,12 +100,10 @@ checkmasterreply()
uchar *
retrieveservers(uchar *buf, int buflen)
{
@autoreleasepool {
OFString *path = [OFString
stringWithFormat:@"%@retrieve.do?item=list", masterpath];
httpgetsend(masterserver, masterbase, path, @"cubeserver",
@"Cube Server");
}
OFString *path =
[OFString stringWithFormat:@"%@retrieve.do?item=list", masterpath];
httpgetsend(
masterserver, masterbase, path, @"cubeserver", @"Cube Server");
ENetBuffer eb;
buf[0] = 0;
eb.data = buf;
@ -160,7 +153,6 @@ serverms(int mode, int numplayers, int minremain, OFString *smapname,
void
servermsinit(OFString *master_, OFString *sdesc, bool listen)
{
@autoreleasepool {
const char *master = master_.UTF8String;
const char *mid = strstr(master, "/");
if (!mid)
@ -171,12 +163,10 @@ servermsinit(OFString *master_, OFString *sdesc, bool listen)
serverdesc = sdesc;
if (listen) {
ENetAddress address = { ENET_HOST_ANY,
CUBE_SERVINFO_PORT };
pongsock = enet_socket_create(
ENET_SOCKET_TYPE_DATAGRAM, &address);
ENetAddress address = { ENET_HOST_ANY, CUBE_SERVINFO_PORT };
pongsock =
enet_socket_create(ENET_SOCKET_TYPE_DATAGRAM, &address);
if (pongsock == ENET_SOCKET_NULL)
fatal(@"could not create server info socket\n");
}
}
}

View file

@ -45,14 +45,12 @@ getint(uchar *&p)
void
sendstring(OFString *t_, uchar *&p)
{
@autoreleasepool {
const char *t = t_.UTF8String;
for (size_t i = 0; i < _MAXDEFSTR && *t != '\0'; i++)
putint(p, *t++);
putint(p, 0);
}
}
static const OFString *modenames[] = {

View file

@ -87,7 +87,6 @@ music(OFString *name)
return;
stopsound();
if (soundvol && musicvol) {
@autoreleasepool {
name = [name stringByReplacingOccurrencesOfString:@"\\"
withString:@"/"];
OFString *path =
@ -97,34 +96,29 @@ music(OFString *name)
#ifdef USE_MIXER
if ((mod = Mix_LoadMUS(
IRI.fileSystemRepresentation.UTF8String)) !=
NULL) {
IRI.fileSystemRepresentation.UTF8String)) != NULL) {
Mix_PlayMusic(mod, -1);
Mix_VolumeMusic((musicvol * MAXVOL) / 255);
}
#else
if ((mod = FMUSIC_LoadSong(
IRI.fileSystemRepresentation.UTF8String)) !=
NULL) {
IRI.fileSystemRepresentation.UTF8String)) != NULL) {
FMUSIC_PlaySong(mod);
FMUSIC_SetMasterVolume(mod, musicvol);
} else if (stream = FSOUND_Stream_Open(
IRI.fileSystemRepresentation.UTF8String,
FSOUND_LOOP_NORMAL, 0, 0)) {
int chan =
FSOUND_Stream_Play(FSOUND_FREE, stream);
int chan = FSOUND_Stream_Play(FSOUND_FREE, stream);
if (chan >= 0) {
FSOUND_SetVolume(
chan, (musicvol * MAXVOL) / 255);
FSOUND_SetPaused(chan, false);
}
} else {
conoutf(
@"could not play music: %@", IRI.string);
conoutf(@"could not play music: %@", IRI.string);
}
#endif
}
}
}
COMMAND(music, ARG_1STR)

View file

@ -67,13 +67,11 @@ trigger(int tag, int type, bool savegame)
if (!savegame && type != 3)
playsound(S_RUMBLE);
@autoreleasepool {
OFString *aliasname =
[OFString stringWithFormat:@"level_trigger_%d", tag];
if (identexists(aliasname))
execute(aliasname);
}
if (type == 2)
endsp(false);
@ -306,9 +304,7 @@ delent()
return;
}
int t = ents[e].type;
@autoreleasepool {
conoutf(@"%@ entity deleted", entnames[t]);
}
ents[e].type = NOTUSED;
addmsg(1, 10, SV_EDITENT, e, NOTUSED, 0, 0, 0, 0, 0, 0, 0);
if (t == LIGHT)
@ -318,11 +314,9 @@ delent()
int
findtype(OFString *what)
{
@autoreleasepool {
loopi(MAXENTTYPES) if ([what isEqual:entnames[i]]) return i;
conoutf(@"unknown entity type \"%@\"", what);
return NOTUSED;
}
}
entity *

View file

@ -14,7 +14,6 @@ static OFString *cgzname, *bakname, *pcfname, *mcfname;
static void
setnames(OFString *name)
{
@autoreleasepool {
OFCharacterSet *cs =
[OFCharacterSet characterSetWithCharactersInString:@"/\\"];
OFRange range = [name rangeOfCharacterFromSet:cs];
@ -30,14 +29,12 @@ setnames(OFString *name)
cgzname = [[OFString alloc]
initWithFormat:@"packages/%@/%@.cgz", pakname, mapname];
bakname =
[[OFString alloc] initWithFormat:@"packages/%@/%@_%d.BAK",
bakname = [[OFString alloc] initWithFormat:@"packages/%@/%@_%d.BAK",
pakname, mapname, lastmillis];
pcfname = [[OFString alloc]
initWithFormat:@"packages/%@/package.cfg", pakname];
mcfname = [[OFString alloc]
initWithFormat:@"packages/%@/%@.cfg", pakname, mapname];
}
}
// the optimize routines below are here to reduce the detrimental effects of
@ -160,7 +157,6 @@ readmap(OFString *mname)
void
save_world(OFString *mname)
{
@autoreleasepool {
resettagareas(); // wouldn't be able to reproduce tagged areas
// otherwise
voptimize();
@ -169,8 +165,8 @@ save_world(OFString *mname)
mname = getclientmap();
setnames(mname);
backup(cgzname, bakname);
gzFile f = gzopen(
[cgzname cStringWithEncoding:OFLocale.encoding], "wb9");
gzFile f =
gzopen([cgzname cStringWithEncoding:OFLocale.encoding], "wb9");
if (!f) {
conoutf(@"could not write map to %@", cgzname);
return;
@ -223,9 +219,9 @@ save_world(OFString *mname)
gzputc(f, s->vdelta);
}
} else {
if (t && c(type) && c(floor) && c(ceil) &&
c(ctex) && c(ftex) && c(utex) && c(wtex) &&
c(vdelta) && c(tag)) {
if (t && c(type) && c(floor) && c(ceil) && c(ctex) &&
c(ftex) && c(utex) && c(wtex) && c(vdelta) &&
c(tag)) {
sc++;
} else {
spurge;
@ -246,7 +242,6 @@ save_world(OFString *mname)
gzclose(f);
conoutf(@"wrote map file %@", cgzname);
settagareas();
}
}
COMMANDN(savemap, save_world, ARG_1STR)
@ -254,13 +249,12 @@ void
load_world(OFString *mname) // still supports all map formats that have existed
// since the earliest cube betas!
{
@autoreleasepool {
stopifrecording();
cleardlights();
pruneundos();
setnames(mname);
gzFile f = gzopen(
[cgzname cStringWithEncoding:OFLocale.encoding], "rb9");
gzFile f =
gzopen([cgzname cStringWithEncoding:OFLocale.encoding], "rb9");
if (!f) {
conoutf(@"could not read map %@", cgzname);
return;
@ -288,8 +282,7 @@ load_world(OFString *mname) // still supports all map formats that have existed
e.spawned = false;
if (e.type == LIGHT) {
if (!e.attr2)
e.attr2 =
255; // needed for MAPVERSION<=2
e.attr2 = 255; // needed for MAPVERSION<=2
if (e.attr1 > 32)
e.attr1 = 32; // 12_03 and below
}
@ -337,8 +330,7 @@ load_world(OFString *mname) // still supports all map formats that have existed
default: {
if (type < 0 || type >= MAXTYPE) {
OFString *t = [OFString
stringWithFormat:@"%d @ %d", type,
k];
stringWithFormat:@"%d @ %d", type, k];
fatal(@"while reading map: type out of "
@"range: ",
t);
@ -356,8 +348,7 @@ load_world(OFString *mname) // still supports all map formats that have existed
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->type = type;
}
@ -366,8 +357,7 @@ load_world(OFString *mname) // still supports all map formats that have existed
t = s;
texuse[s->wtex] = 1;
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);
calclight();
@ -387,9 +377,8 @@ load_world(OFString *mname) // still supports all map formats that have existed
alias(aliasname, @"");
}
OFIRI *gameDataIRI = Cube.sharedInstance.gameDataIRI;
execfile([gameDataIRI IRIByAppendingPathComponent:
@"data/default_map_settings.cfg"]);
execfile([gameDataIRI
IRIByAppendingPathComponent:@"data/default_map_settings.cfg"]);
execfile([gameDataIRI IRIByAppendingPathComponent:pcfname]);
execfile([gameDataIRI IRIByAppendingPathComponent:mcfname]);
}
}