Convert to ObjC++

FossilOrigin-Name: 7c2704b3d77d6e63d960e315bfb601fddbf6fce538b7c5db6da664e04fbce4c2
This commit is contained in:
Jonathan Schleifer 2024-07-21 12:02:07 +00:00
parent 04fa50a332
commit 133382170f
34 changed files with 87 additions and 79 deletions

View file

@ -13,9 +13,16 @@ BUILDSYS_INIT
AC_PROG_CC AC_PROG_CC
AC_PROG_CPP AC_PROG_CPP
AC_PROG_OBJCXX(clang++ g++)
AC_PROG_OBJCXXCPP
AC_PROG_CXX AC_CHECK_TOOL(OBJFW_CONFIG, objfw-config)
AC_PROG_CXXCPP AS_IF([test x"$OBJFW_CONFIG" = x""], [
AC_MSG_ERROR(You need ObjFW and objfw-config installed!)
])
OBJCXXFLAGS="$OBJCXXFLAGS $($OBJFW_CONFIG --cppflags --objcflags)"
LDFLAGS="$($OBJFW_CONFIG --ldflags --rpath)"
LIBS="$($OBJFW_CONFIG --libs) $LIBS"
AC_PATH_TOOL(AR, ar) AC_PATH_TOOL(AR, ar)
AC_PATH_TOOL(RANLIB, ranlib) AC_PATH_TOOL(RANLIB, ranlib)

View file

@ -1,37 +1,37 @@
PROG = client PROG = client
SRCS = client.cxx \ SRCS = client.mm \
clientextras.cxx \ clientextras.mm \
clientgame.cxx \ clientgame.mm \
clients2c.cxx \ clients2c.mm \
command.cxx \ command.mm \
console.cxx \ console.mm \
editing.cxx \ editing.mm \
entities.cxx \ entities.mm \
main.cxx \ main.mm \
menus.cxx \ menus.mm \
monster.cxx \ monster.mm \
physics.cxx \ physics.mm \
rendercubes.cxx \ rendercubes.mm \
renderextras.cxx \ renderextras.mm \
rendergl.cxx \ rendergl.mm \
rendermd2.cxx \ rendermd2.mm \
renderparticles.cxx \ renderparticles.mm \
rendertext.cxx \ rendertext.mm \
rndmap.cxx \ rndmap.mm \
savegamedemo.cxx \ savegamedemo.mm \
server.cxx \ server.mm \
serverbrowser.cxx \ serverbrowser.mm \
serverms.cxx \ serverms.mm \
serverutil.cxx \ serverutil.mm \
sound.cxx \ sound.mm \
tools.cxx \ tools.mm \
weapon.cxx \ weapon.mm \
world.cxx \ world.mm \
worldio.cxx \ worldio.mm \
worldlight.cxx \ worldlight.mm \
worldocull.cxx \ worldocull.mm \
worldrender.cxx worldrender.mm
include ../buildsys.mk include ../buildsys.mk
include ../extra.mk include ../extra.mk
@ -47,5 +47,6 @@ LIBS += -L../enet -lenet \
${GL_LIBS} \ ${GL_LIBS} \
${GLU_LIBS} \ ${GLU_LIBS} \
${X11_LIBS} \ ${X11_LIBS} \
${ZLIB_LIBS} ${ZLIB_LIBS} \
LD = ${CXX} -lm
LD = ${OBJCXX}

View file

@ -155,15 +155,15 @@ parseword(char *&p) // parse single argument, including expressions
char * char *
lookup(char *n) // find value of ident referenced with $ in exp lookup(char *n) // find value of ident referenced with $ in exp
{ {
ident *id = idents->access(n + 1); ident *ID = idents->access(n + 1);
if (id) if (ID)
switch (id->type) { switch (ID->type) {
case ID_VAR: case ID_VAR:
string t; string t;
itoa(t, *(id->storage)); itoa(t, *(ID->storage));
return exchangestr(n, t); return exchangestr(n, t);
case ID_ALIAS: case ID_ALIAS:
return exchangestr(n, id->action); return exchangestr(n, ID->action);
}; };
conoutf("unknown alias lookup: %s", n + 1); conoutf("unknown alias lookup: %s", n + 1);
return n; return n;
@ -202,98 +202,98 @@ execute(char *p, bool isdown) // all evaluation happens here, recursively
if (!*c) if (!*c)
continue; // empty statement continue; // empty statement
ident *id = idents->access(c); ident *ID = idents->access(c);
if (!id) { if (!ID) {
val = ATOI(c); val = ATOI(c);
if (!val && *c != '0') if (!val && *c != '0')
conoutf("unknown command: %s", c); conoutf("unknown command: %s", c);
} else } else
switch (id->type) { switch (ID->type) {
case ID_COMMAND: // game defined commands case ID_COMMAND: // game defined commands
switch (id->narg) // use very ad-hoc function switch (ID->narg) // use very ad-hoc function
// signature, and just call it // signature, and just call it
{ {
case ARG_1INT: case ARG_1INT:
if (isdown) if (isdown)
((void(__cdecl *)(int))id->fun)( ((void(__cdecl *)(int))ID->fun)(
ATOI(w[1])); ATOI(w[1]));
break; break;
case ARG_2INT: case ARG_2INT:
if (isdown) if (isdown)
((void(__cdecl *)( ((void(__cdecl *)(
int, int))id->fun)( int, int))ID->fun)(
ATOI(w[1]), ATOI(w[2])); ATOI(w[1]), ATOI(w[2]));
break; break;
case ARG_3INT: case ARG_3INT:
if (isdown) if (isdown)
((void(__cdecl *)(int, int, ((void(__cdecl *)(int, int,
int))id->fun)(ATOI(w[1]), int))ID->fun)(ATOI(w[1]),
ATOI(w[2]), ATOI(w[3])); ATOI(w[2]), ATOI(w[3]));
break; break;
case ARG_4INT: case ARG_4INT:
if (isdown) if (isdown)
((void(__cdecl *)(int, int, int, ((void(__cdecl *)(int, int, int,
int))id->fun)(ATOI(w[1]), int))ID->fun)(ATOI(w[1]),
ATOI(w[2]), ATOI(w[3]), ATOI(w[2]), ATOI(w[3]),
ATOI(w[4])); ATOI(w[4]));
break; break;
case ARG_NONE: case ARG_NONE:
if (isdown) if (isdown)
((void(__cdecl *)())id->fun)(); ((void(__cdecl *)())ID->fun)();
break; break;
case ARG_1STR: case ARG_1STR:
if (isdown) if (isdown)
((void(__cdecl *)( ((void(__cdecl *)(
char *))id->fun)(w[1]); char *))ID->fun)(w[1]);
break; break;
case ARG_2STR: case ARG_2STR:
if (isdown) if (isdown)
((void(__cdecl *)( ((void(__cdecl *)(
char *, char *))id->fun)( char *, char *))ID->fun)(
w[1], w[2]); w[1], w[2]);
break; break;
case ARG_3STR: case ARG_3STR:
if (isdown) if (isdown)
((void(__cdecl *)(char *, ((void(__cdecl *)(char *,
char *, char *))id->fun)( char *, char *))ID->fun)(
w[1], w[2], w[3]); w[1], w[2], w[3]);
break; break;
case ARG_5STR: case ARG_5STR:
if (isdown) if (isdown)
((void(__cdecl *)(char *, ((void(__cdecl *)(char *,
char *, char *, char *, char *, char *, char *,
char *))id->fun)(w[1], w[2], char *))ID->fun)(w[1], w[2],
w[3], w[4], w[5]); w[3], w[4], w[5]);
break; break;
case ARG_DOWN: case ARG_DOWN:
((void(__cdecl *)(bool))id->fun)( ((void(__cdecl *)(bool))ID->fun)(
isdown); isdown);
break; break;
case ARG_DWN1: case ARG_DWN1:
((void(__cdecl *)(bool, ((void(__cdecl *)(bool,
char *))id->fun)(isdown, w[1]); char *))ID->fun)(isdown, w[1]);
break; break;
case ARG_1EXP: case ARG_1EXP:
if (isdown) if (isdown)
val = ((int(__cdecl *)( val = ((int(__cdecl *)(
int))id->fun)( int))ID->fun)(
execute(w[1])); execute(w[1]));
break; break;
case ARG_2EXP: case ARG_2EXP:
if (isdown) if (isdown)
val = ((int(__cdecl *)(int, val = ((int(__cdecl *)(int,
int))id->fun)(execute(w[1]), int))ID->fun)(execute(w[1]),
execute(w[2])); execute(w[2]));
break; break;
case ARG_1EST: case ARG_1EST:
if (isdown) if (isdown)
val = ((int(__cdecl *)( val = ((int(__cdecl *)(
char *))id->fun)(w[1]); char *))ID->fun)(w[1]);
break; break;
case ARG_2EST: case ARG_2EST:
if (isdown) if (isdown)
val = ((int(__cdecl *)( val = ((int(__cdecl *)(
char *, char *))id->fun)( char *, char *))ID->fun)(
w[1], w[2]); w[1], w[2]);
break; break;
case ARG_VARI: case ARG_VARI:
@ -312,7 +312,7 @@ execute(char *p, bool isdown) // all evaluation happens here, recursively
strcat_s(r, " "); strcat_s(r, " ");
}; };
((void(__cdecl *)( ((void(__cdecl *)(
char *))id->fun)(r); char *))ID->fun)(r);
break; break;
} }
}; };
@ -322,36 +322,36 @@ execute(char *p, bool isdown) // all evaluation happens here, recursively
if (isdown) { if (isdown) {
if (!w[1][0]) if (!w[1][0])
conoutf("%s = %d", c, conoutf("%s = %d", c,
*id->storage); // var with *ID->storage); // var with
// no value // no value
// just // just
// prints its // prints its
// current // current
// value // value
else { else {
if (id->min > id->max) { if (ID->min > ID->max) {
conoutf("variable is " conoutf("variable is "
"read-only"); "read-only");
} else { } else {
int i1 = ATOI(w[1]); int i1 = ATOI(w[1]);
if (i1 < id->min || if (i1 < ID->min ||
i1 > id->max) { i1 > ID->max) {
i1 = i1 =
i1 < id->min i1 < ID->min
? id->min ? ID->min
: id->max; // clamp to valid range : ID->max; // clamp to valid range
conoutf( conoutf(
"valid " "valid "
"range for " "range for "
"%s is " "%s is "
"%d..%d", "%d..%d",
c, id->min, c, ID->min,
id->max); ID->max);
} }
*id->storage = i1; *ID->storage = i1;
}; };
if (id->fun) if (ID->fun)
((void(__cdecl *)())id ((void(__cdecl *)())ID
->fun)(); // call ->fun)(); // call
// trigger // trigger
// function // function
@ -371,7 +371,7 @@ execute(char *p, bool isdown) // all evaluation happens here, recursively
alias(t, w[i]); alias(t, w[i]);
}; };
char *action = newstring( char *action = newstring(
id->action); // create new string here ID->action); // create new string here
// because alias could rebind // because alias could rebind
// itself // itself
val = execute(action, isdown); val = execute(action, isdown);
@ -454,16 +454,16 @@ writecfg()
writeclientinfo(f); writeclientinfo(f);
fprintf(f, "\n"); fprintf(f, "\n");
enumerate( enumerate(
idents, ident *, id, if (id->type == ID_VAR && id->persist) { idents, ident *, ID, if (ID->type == ID_VAR && ID->persist) {
fprintf(f, "%s %d\n", id->name, *id->storage); fprintf(f, "%s %d\n", ID->name, *ID->storage);
};); };);
fprintf(f, "\n"); fprintf(f, "\n");
writebinds(f); writebinds(f);
fprintf(f, "\n"); fprintf(f, "\n");
enumerate( enumerate(
idents, ident *, id, idents, ident *, ID,
if (id->type == ID_ALIAS && !strstr(id->name, "nextmap_")) { if (ID->type == ID_ALIAS && !strstr(ID->name, "nextmap_")) {
fprintf(f, "alias \"%s\" [%s]\n", id->name, id->action); fprintf(f, "alias \"%s\" [%s]\n", ID->name, ID->action);
};); };);
fclose(f); fclose(f);
}; };