Convert more files to pure Objective-C

FossilOrigin-Name: b250dfa8d49dc6cf7dd86d6c7836733467c87769e3cedaa4678b94d411b7be12
This commit is contained in:
Jonathan Schleifer 2025-03-20 21:18:29 +00:00
parent 565a845aaf
commit b4d52ea3ec
12 changed files with 75 additions and 76 deletions

View file

@ -9,7 +9,7 @@
int nextmode = 0; // nextmode becomes gamemode after next map load int nextmode = 0; // nextmode becomes gamemode after next map load
VAR(gamemode, 1, 0, 0); VAR(gamemode, 1, 0, 0);
void static void
mode(int n) mode(int n)
{ {
addmsg(1, 2, SV_GAMEMODE, nextmode = n); addmsg(1, 2, SV_GAMEMODE, nextmode = n);
@ -144,17 +144,17 @@ respawnself()
showscores(false); showscores(false);
} }
void static void
arenacount( arenacount(
DynamicEntity *d, int &alive, int &dead, OFString **lastteam, bool &oneteam) DynamicEntity *d, int *alive, int *dead, OFString **lastteam, bool *oneteam)
{ {
if (d.state != CS_DEAD) { if (d.state != CS_DEAD) {
alive++; (*alive)++;
if (![*lastteam isEqual:d.team]) if (![*lastteam isEqual:d.team])
oneteam = false; *oneteam = false;
*lastteam = d.team; *lastteam = d.team;
} else } else
dead++; (*dead)++;
} }
int arenarespawnwait = 0; int arenarespawnwait = 0;
@ -177,8 +177,8 @@ arenarespawn()
for (id player in players) for (id player in players)
if (player != [OFNull null]) if (player != [OFNull null])
arenacount( arenacount(
player, alive, dead, &lastteam, oneteam); player, &alive, &dead, &lastteam, &oneteam);
arenacount(player1, alive, dead, &lastteam, oneteam); arenacount(player1, &alive, &dead, &lastteam, &oneteam);
if (dead > 0 && (alive <= 1 || (m_teammode && oneteam))) { if (dead > 0 && (alive <= 1 || (m_teammode && oneteam))) {
conoutf( conoutf(
@"arena round is over! next round in 5 seconds..."); @"arena round is over! next round in 5 seconds...");
@ -332,7 +332,7 @@ spawnplayer(DynamicEntity *d)
// movement input code // movement input code
#define dir(name, v, d, s, os) \ #define dir(name, v, d, s, os) \
void name(bool isdown) \ static void name(bool isdown) \
{ \ { \
player1.s = isdown; \ player1.s = isdown; \
player1.v = isdown ? d : (player1.os ? -(d) : 0); \ player1.v = isdown ? d : (player1.os ? -(d) : 0); \

View file

@ -197,11 +197,9 @@ addmsg(int rel, int num, int type, ...)
{ {
if (demoplayback) if (demoplayback)
return; return;
if (num != msgsizelookup(type)) { if (num != msgsizelookup(type))
fatal([OFString fatal(@"inconsistant msg size for %d (%d != %d)", type, num,
stringWithFormat:@"inconsistant msg size for %d (%d != %d)", msgsizelookup(type));
type, num, msgsizelookup(type)]);
}
if (messages.count == 100) { if (messages.count == 100) {
conoutf(@"command flood protection (type %d)", type); conoutf(@"command flood protection (type %d)", type);
return; return;

View file

@ -308,7 +308,7 @@ localservertoclient(uchar *buf, int len)
int xs = getint(&p); int xs = getint(&p);
int ys = getint(&p); int ys = getint(&p);
int v = getint(&p); int v = getint(&p);
block b = { x, y, xs, ys }; struct block b = { x, y, xs, ys };
switch (type) { switch (type) {
case SV_EDITH: case SV_EDITH:
editheightxy(v != 0, getint(&p), &b); editheightxy(v != 0, getint(&p), &b);

View file

@ -12,12 +12,12 @@ bool editmode = false;
// invariant: all code assumes that these are kept inside MINBORD distance of // invariant: all code assumes that these are kept inside MINBORD distance of
// the edge of the map // the edge of the map
block sel; struct block sel;
OF_CONSTRUCTOR() OF_CONSTRUCTOR()
{ {
enqueueInit(^{ enqueueInit(^{
sel = (block) { sel = (struct block) {
variable(@"selx", 0, 0, 4096, &sel.x, NULL, false), variable(@"selx", 0, 0, 4096, &sel.x, NULL, false),
variable(@"sely", 0, 0, 4096, &sel.y, NULL, false), variable(@"sely", 0, 0, 4096, &sel.y, NULL, false),
variable(@"selxs", 0, 0, 4096, &sel.xs, NULL, false), variable(@"selxs", 0, 0, 4096, &sel.xs, NULL, false),
@ -34,7 +34,7 @@ bool selset = false;
makeundo(); \ makeundo(); \
loop(x, sel->xs) loop(y, sel->ys) \ loop(x, sel->xs) loop(y, sel->ys) \
{ \ { \
sqr *s = S(sel->x + x, sel->y + y); \ struct sqr *s = S(sel->x + x, sel->y + y); \
b; \ b; \
} \ } \
remip(sel, 0); \ remip(sel, 0); \
@ -48,7 +48,7 @@ bool dragging = false;
int lastx, lasty, lasth; int lastx, lasty, lasth;
int lasttype = 0, lasttex = 0; int lasttype = 0, lasttex = 0;
sqr rtex; static struct sqr rtex;
VAR(editing, 0, 0, 1); VAR(editing, 0, 0, 1);
@ -121,7 +121,7 @@ noselection()
void void
selectpos(int x, int y, int xs, int ys) selectpos(int x, int y, int xs, int ys)
{ {
block s = { x, y, xs, ys }; struct block s = { x, y, xs, ys };
sel = s; sel = s;
selh = 0; selh = 0;
correctsel(); correctsel();
@ -130,7 +130,7 @@ selectpos(int x, int y, int xs, int ys)
void void
makesel() makesel()
{ {
block s = { min(lastx, cx), min(lasty, cy), abs(lastx - cx) + 1, struct block s = { min(lastx, cx), min(lasty, cy), abs(lastx - cx) + 1,
abs(lasty - cy) + 1 }; abs(lasty - cy) + 1 };
sel = s; sel = s;
selh = max(lasth, ch); selh = max(lasth, ch);
@ -141,9 +141,9 @@ makesel()
VAR(flrceil, 0, 0, 2); VAR(flrceil, 0, 0, 2);
// finds out z height when cursor points at wall
float float
sheight( sheight(struct sqr *s, struct sqr *t, float z)
sqr *s, sqr *t, float z) // finds out z height when cursor points at wall
{ {
return !flrceil // z-s->floor<s->ceil-z return !flrceil // z-s->floor<s->ceil-z
? (s->type == FHF ? s->floor - t->vdelta / 4.0f : (float)s->floor) ? (s->type == FHF ? s->floor - t->vdelta / 4.0f : (float)s->floor)
@ -165,7 +165,7 @@ cursorupdate() // called every frame from hud
if (OUTBORD(cx, cy)) if (OUTBORD(cx, cy))
return; return;
sqr *s = S(cx, cy); struct sqr *s = S(cx, cy);
// selected wall // selected wall
if (fabs(sheight(s, s, z) - z) > 1) { if (fabs(sheight(s, s, z) - z) > 1) {
@ -194,7 +194,7 @@ cursorupdate() // called every frame from hud
for (int iy = cy - GRIDSIZE; iy <= cy + GRIDSIZE; iy++) { for (int iy = cy - GRIDSIZE; iy <= cy + GRIDSIZE; iy++) {
if (OUTBORD(ix, iy)) if (OUTBORD(ix, iy))
continue; continue;
sqr *s = S(ix, iy); struct sqr *s = S(ix, iy);
if (SOLID(s)) if (SOLID(s))
continue; continue;
float h1 = sheight(s, s, z); float h1 = sheight(s, s, z);
@ -207,7 +207,7 @@ cursorupdate() // called every frame from hud
linestyle(GRIDW, 0x80, 0xFF, 0x80); linestyle(GRIDW, 0x80, 0xFF, 0x80);
else else
linestyle(GRIDW, 0x80, 0x80, 0x80); linestyle(GRIDW, 0x80, 0x80, 0x80);
block b = { ix, iy, 1, 1 }; struct block b = { ix, iy, 1, 1 };
box(&b, h1, h2, h3, h4); box(&b, h1, h2, h3, h4);
linestyle(GRID8, 0x40, 0x40, 0xFF); linestyle(GRID8, 0x40, 0x40, 0xFF);
if (!(ix & GRIDM)) if (!(ix & GRIDM))
@ -224,7 +224,7 @@ cursorupdate() // called every frame from hud
if (!SOLID(s)) { if (!SOLID(s)) {
float ih = sheight(s, s, z); float ih = sheight(s, s, z);
linestyle(GRIDS, 0xFF, 0xFF, 0xFF); linestyle(GRIDS, 0xFF, 0xFF, 0xFF);
block b = { cx, cy, 1, 1 }; struct block b = { cx, cy, 1, 1 };
box(&b, ih, sheight(s, SWS(s, 1, 0, ssize), z), box(&b, ih, sheight(s, SWS(s, 1, 0, ssize), z),
sheight(s, SWS(s, 1, 1, ssize), z), sheight(s, SWS(s, 1, 1, ssize), z),
sheight(s, SWS(s, 0, 1, ssize), z)); sheight(s, SWS(s, 0, 1, ssize), z));
@ -247,9 +247,9 @@ pruneundos(int maxremain) // bound memory
{ {
int t = 0; int t = 0;
for (ssize_t i = (ssize_t)undos.count - 1; i >= 0; i--) { for (ssize_t i = (ssize_t)undos.count - 1; i >= 0; i--) {
block *undo = *(block **)[undos itemAtIndex:i]; struct block *undo = [undos mutableItemAtIndex:i];
t += undo->xs * undo->ys * sizeof(sqr); t += undo->xs * undo->ys * sizeof(struct sqr);
if (t > maxremain) { if (t > maxremain) {
OFFreeMemory(undo); OFFreeMemory(undo);
[undos removeItemAtIndex:i]; [undos removeItemAtIndex:i];
@ -262,9 +262,9 @@ makeundo()
{ {
if (undos == nil) if (undos == nil)
undos = undos =
[[OFMutableData alloc] initWithItemSize:sizeof(block *)]; [[OFMutableData alloc] initWithItemSize:sizeof(struct block *)];
block *copy = blockcopy(&sel); struct block *copy = blockcopy(&sel);
[undos addItem:&copy]; [undos addItem:&copy];
pruneundos(undomegs << 20); pruneundos(undomegs << 20);
} }
@ -277,13 +277,13 @@ editundo()
conoutf(@"nothing more to undo"); conoutf(@"nothing more to undo");
return; return;
} }
block *p = *(block **)undos.lastItem; struct block *p = undos.mutableLastItem;
[undos removeLastItem]; [undos removeLastItem];
blockpaste(p); blockpaste(p);
OFFreeMemory(p); OFFreeMemory(p);
} }
block *copybuf = NULL; static struct block *copybuf = NULL;
void void
copy() copy()
@ -351,7 +351,7 @@ editdrag(bool isDown)
// strictly triggered locally. They all have very similar structure. // strictly triggered locally. They all have very similar structure.
void void
editheightxy(bool isfloor, int amount, const block *sel) editheightxy(bool isfloor, int amount, const struct block *sel)
{ {
loopselxy( loopselxy(
if (isfloor) { if (isfloor) {
@ -376,7 +376,7 @@ editheight(int flr, int amount)
COMMAND(editheight, ARG_2INT) COMMAND(editheight, ARG_2INT)
void void
edittexxy(int type, int t, const block *sel) edittexxy(int type, int t, const struct block *sel)
{ {
loopselxy(switch (type) { loopselxy(switch (type) {
case 0: case 0:
@ -419,7 +419,7 @@ replace()
EDITSELMP; EDITSELMP;
loop(x, ssize) loop(y, ssize) loop(x, ssize) loop(y, ssize)
{ {
sqr *s = S(x, y); struct sqr *s = S(x, y);
switch (lasttype) { switch (lasttype) {
case 0: case 0:
if (s->ftex == rtex.ftex) if (s->ftex == rtex.ftex)
@ -439,12 +439,12 @@ replace()
break; break;
} }
} }
block b = { 0, 0, ssize, ssize }; struct block b = { 0, 0, ssize, ssize };
remip(&b, 0); remip(&b, 0);
} }
void void
edittypexy(int type, const block *sel) edittypexy(int type, const struct block *sel)
{ {
loopselxy(s->type = type); loopselxy(s->type = type);
} }
@ -485,7 +485,7 @@ corner()
COMMAND(corner, ARG_NONE) COMMAND(corner, ARG_NONE)
void void
editequalisexy(bool isfloor, const block *sel) editequalisexy(bool isfloor, const struct block *sel)
{ {
int low = 127, hi = -128; int low = 127, hi = -128;
loopselxy({ loopselxy({
@ -515,7 +515,7 @@ equalize(int flr)
COMMAND(equalize, ARG_1INT) COMMAND(equalize, ARG_1INT)
void void
setvdeltaxy(int delta, const block *sel) setvdeltaxy(int delta, const struct block *sel)
{ {
loopselxy(s->vdelta = max(s->vdelta + delta, 0)); loopselxy(s->vdelta = max(s->vdelta + delta, 0));
remipmore(sel, 0); remipmore(sel, 0);
@ -555,9 +555,9 @@ arch(int sidedelta, int _a)
sel.xs = MAXARCHVERT; sel.xs = MAXARCHVERT;
if (sel.ys > MAXARCHVERT) if (sel.ys > MAXARCHVERT)
sel.ys = MAXARCHVERT; sel.ys = MAXARCHVERT;
block *sel_ = &sel; struct block *sel_ = &sel;
// Ugly hack to make the macro work. // Ugly hack to make the macro work.
block *sel = sel_; struct block *sel = sel_;
loopselxy(s->vdelta = sel->xs > sel->ys loopselxy(s->vdelta = sel->xs > sel->ys
? (archverts[sel->xs - 1][x] + ? (archverts[sel->xs - 1][x] +
(y == 0 || y == sel->ys - 1 ? sidedelta : 0)) (y == 0 || y == sel->ys - 1 ? sidedelta : 0))
@ -577,9 +577,9 @@ slope(int xd, int yd)
off -= yd * sel.ys; off -= yd * sel.ys;
sel.xs++; sel.xs++;
sel.ys++; sel.ys++;
block *sel_ = &sel; struct block *sel_ = &sel;
// Ugly hack to make the macro work. // Ugly hack to make the macro work.
block *sel = sel_; struct block *sel = sel_;
loopselxy(s->vdelta = xd * x + yd * y + off); loopselxy(s->vdelta = xd * x + yd * y + off);
remipmore(sel, 0); remipmore(sel, 0);
} }
@ -612,9 +612,9 @@ void
edittag(int tag) edittag(int tag)
{ {
EDITSELMP; EDITSELMP;
block *sel_ = &sel; struct block *sel_ = &sel;
// Ugly hack to make the macro work. // Ugly hack to make the macro work.
block *sel = sel_; struct block *sel = sel_;
loopselxy(s->tag = tag); loopselxy(s->tag = tag);
} }

View file

@ -29,9 +29,9 @@ initEntities()
ents = [[OFMutableArray alloc] init]; ents = [[OFMutableArray alloc] init];
} }
void static void
renderent(Entity *e, OFString *mdlname, float z, float yaw, int frame = 0, renderent(Entity *e, OFString *mdlname, float z, float yaw, int frame/* = 0*/,
int numf = 1, int basetime = 0, float speed = 10.0f) int numf/* = 1*/, int basetime/* = 0*/, float speed/* = 10.0f*/)
{ {
rendermodel(mdlname, frame, numf, 0, 1.1f, rendermodel(mdlname, frame, numf, 0, 1.1f,
OFMakeVector3D(e.x, z + S(e.x, e.y)->floor, e.y), yaw, 0, false, OFMakeVector3D(e.x, z + S(e.x, e.y)->floor, e.y), yaw, 0, false,
@ -67,7 +67,7 @@ renderentities()
(float)(1 + (float)(1 +
sin(lastmillis / 100.0 + e.x + e.y) / sin(lastmillis / 100.0 + e.x + e.y) /
20), 20),
lastmillis / 10.0f); lastmillis / 10.0f, 0,1,0,10.0f);
} else { } else {
switch (e.attr2) { switch (e.attr2) {
case 1: case 1:
@ -84,7 +84,8 @@ renderentities()
e.y) / e.y) /
20), 20),
lastmillis / lastmillis /
(e.attr2 ? 1.0f : 10.0f)); (e.attr2 ? 1.0f : 10.0f),
0, 1, 0, 10.0f);
break; break;
case 4: case 4:
@ -136,12 +137,12 @@ baseammo(int gun)
static int static int
radditem(int i, int v) radditem(int i, int v)
{ {
itemstat &is = itemstats[ents[i].type - I_SHELLS]; struct itemstat *is = &itemstats[ents[i].type - I_SHELLS];
ents[i].spawned = false; ents[i].spawned = false;
v += is.add; v += is->add;
if (v > is.max) if (v > is->max)
v = is.max; v = is->max;
playsoundc(is.sound); playsoundc(is->sound);
return v; return v;
} }

View file

@ -21,17 +21,17 @@ executable('client',
'ServerEntity.m', 'ServerEntity.m',
'ServerInfo.m', 'ServerInfo.m',
'Variable.m', 'Variable.m',
'clients.mm', 'clients.m',
'clientextras.mm', 'clientextras.m',
'clientgame.mm', 'clientgame.m',
'clients2c.mm', 'clients2c.m',
'commands.mm', 'commands.mm',
'console.mm', 'console.m',
'editing.mm', 'editing.m',
'entities.mm', 'entities.m',
'init.mm', 'init.mm',
'menus.mm', 'menus.m',
'monster.mm', 'monster.m',
'physics.mm', 'physics.mm',
'rendercubes.mm', 'rendercubes.mm',
'renderextras.mm', 'renderextras.mm',

View file

@ -63,7 +63,7 @@ basicmonster(int type, int yaw, int state, int trigger, int move)
type = 0; type = 0;
} }
DynamicEntity *m = newdynent(); DynamicEntity *m = newdynent();
monstertype *t = &monstertypes[(m.mtype = type)]; struct monstertype *t = &monstertypes[(m.mtype = type)];
m.eyeheight = 2.0f; m.eyeheight = 2.0f;
m.aboveeye = 1.9f; m.aboveeye = 1.9f;
m.radius *= t->bscale / 10.0f; m.radius *= t->bscale / 10.0f;
@ -138,7 +138,7 @@ monsterclear()
// height-correct line of sight for monster shooting/seeing // height-correct line of sight for monster shooting/seeing
bool bool
los(float lx, float ly, float lz, float bx, float by, float bz, OFVector3D &v) los(float lx, float ly, float lz, float bx, float by, float bz, OFVector3D *v)
{ {
if (OUTBORD((int)lx, (int)ly) || OUTBORD((int)bx, (int)by)) if (OUTBORD((int)lx, (int)ly) || OUTBORD((int)bx, (int)by))
return false; return false;
@ -151,7 +151,7 @@ los(float lx, float ly, float lz, float bx, float by, float bz, OFVector3D &v)
float y = ly; float y = ly;
int i = 0; int i = 0;
for (;;) { for (;;) {
sqr *s = S(fast_f2nat(x), fast_f2nat(y)); struct sqr *s = S(fast_f2nat(x), fast_f2nat(y));
if (SOLID(s)) if (SOLID(s))
break; break;
float floor = s->floor; float floor = s->floor;
@ -163,9 +163,9 @@ los(float lx, float ly, float lz, float bx, float by, float bz, OFVector3D &v)
float rz = lz - ((lz - bz) * (i / (float)steps)); float rz = lz - ((lz - bz) * (i / (float)steps));
if (rz < floor || rz > ceil) if (rz < floor || rz > ceil)
break; break;
v.x = x; v->x = x;
v.y = y; v->y = y;
v.z = rz; v->z = rz;
x += dx / (float)steps; x += dx / (float)steps;
y += dy / (float)steps; y += dy / (float)steps;
i++; i++;
@ -174,9 +174,9 @@ los(float lx, float ly, float lz, float bx, float by, float bz, OFVector3D &v)
} }
bool bool
enemylos(DynamicEntity *m, OFVector3D &v) enemylos(DynamicEntity *m, OFVector3D *v)
{ {
v = m.o; *v = m.o;
return los( return los(
m.o.x, m.o.y, m.o.z, m.enemy.o.x, m.enemy.o.y, m.enemy.o.z, v); m.o.x, m.o.y, m.o.z, m.enemy.o.x, m.enemy.o.y, m.enemy.o.z, v);
} }
@ -261,7 +261,7 @@ monsteraction(DynamicEntity *m)
// contact // contact
{ {
OFVector3D target; OFVector3D target;
if (editmode || !enemylos(m, target)) if (editmode || !enemylos(m, &target))
return; // skip running physics return; // skip running physics
normalise(m, enemyyaw); normalise(m, enemyyaw);
float angle = (float)fabs(enemyyaw - m.yaw); float angle = (float)fabs(enemyyaw - m.yaw);
@ -295,7 +295,7 @@ monsteraction(DynamicEntity *m)
m.targetyaw = enemyyaw; m.targetyaw = enemyyaw;
if (m.trigger < lastmillis) { if (m.trigger < lastmillis) {
OFVector3D target; OFVector3D target;
if (!enemylos(m, target)) { if (!enemylos(m, &target)) {
// no visual contact anymore, let monster get // no visual contact anymore, let monster get
// as close as possible then search for player // as close as possible then search for player
transition(m, M_HOME, 1, 800, 500); transition(m, M_HOME, 1, 800, 500);

View file

@ -202,7 +202,7 @@ checkpings()
} }
} }
void extern "C" void
refreshservers() refreshservers()
{ {
checkresolver(); checkresolver();