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_CPP
AC_PROG_OBJCXX(clang++ g++)
AC_PROG_OBJCXXCPP
AC_PROG_CXX
AC_PROG_CXXCPP
AC_CHECK_TOOL(OBJFW_CONFIG, objfw-config)
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(RANLIB, ranlib)

View file

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

View file

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