Convert more files to pure Objective-C

FossilOrigin-Name: 46c577957085f072871cb93b46340fd8349c1e20503a448cc8e6d33ddaea1552
This commit is contained in:
Jonathan Schleifer 2025-03-20 21:52:26 +00:00
parent b4d52ea3ec
commit 61bf59bbfc
14 changed files with 176 additions and 162 deletions

View file

@ -3,8 +3,6 @@
#include "cube.h" #include "cube.h"
#include <memory>
#import "Alias.h" #import "Alias.h"
#import "Command.h" #import "Command.h"
#import "Identifier.h" #import "Identifier.h"
@ -14,6 +12,12 @@
// contains ALL vars/commands/aliases // contains ALL vars/commands/aliases
static OFMutableDictionary<OFString *, __kindof Identifier *> *identifiers; static OFMutableDictionary<OFString *, __kindof Identifier *> *identifiers;
static void
cleanup(char **string)
{
free(*string);
}
void void
alias(OFString *name, OFString *action) alias(OFString *name, OFString *action)
{ {
@ -100,26 +104,26 @@ addcommand(OFString *name, void (*function)(), int argumentsTypes)
} }
// parse any nested set of () or [] // parse any nested set of () or []
char * static char *
parseexp(char *&p, int right) parseexp(char **p, int right)
{ {
int left = *p++; int left = *(*p)++;
char *word = p; char *word = *p;
for (int brak = 1; brak;) { for (int brak = 1; brak;) {
int c = *p++; int c = *(*p)++;
if (c == '\r') if (c == '\r')
*(p - 1) = ' '; // hack *(*p - 1) = ' '; // hack
if (c == left) if (c == left)
brak++; brak++;
else if (c == right) else if (c == right)
brak--; brak--;
else if (!c) { else if (!c) {
p--; (*p)--;
conoutf(@"missing \"%c\"", right); conoutf(@"missing \"%c\"", right);
return NULL; return NULL;
} }
} }
char *s = strndup(word, p - word - 1); char *s = strndup(word, *p - word - 1);
if (left == '(') { if (left == '(') {
OFString *t; OFString *t;
@try { @try {
@ -134,30 +138,30 @@ parseexp(char *&p, int right)
} }
// parse single argument, including expressions // parse single argument, including expressions
char * static char *
parseword(char *&p) parseword(char **p)
{ {
p += strspn(p, " \t\r"); (*p) += strspn(*p, " \t\r");
if (p[0] == '/' && p[1] == '/') if ((*p)[0] == '/' && (*p)[1] == '/')
p += strcspn(p, "\n\0"); *p += strcspn(*p, "\n\0");
if (*p == '\"') { if (**p == '\"') {
p++; (*p)++;
char *word = p; char *word = *p;
p += strcspn(p, "\"\r\n\0"); *p += strcspn(*p, "\"\r\n\0");
char *s = strndup(word, p - word); char *s = strndup(word, *p - word);
if (*p == '\"') if (**p == '\"')
p++; (*p)++;
return s; return s;
} }
if (*p == '(') if (**p == '(')
return parseexp(p, ')'); return parseexp(p, ')');
if (*p == '[') if (**p == '[')
return parseexp(p, ']'); return parseexp(p, ']');
char *word = p; char *word = *p;
p += strcspn(p, "; \t\r\n\0"); *p += strcspn(*p, "; \t\r\n\0");
if (p - word == 0) if (*p - word == 0)
return NULL; return NULL;
return strndup(word, p - word); return strndup(word, *p - word);
} }
// find value of ident referenced with $ in exp // find value of ident referenced with $ in exp
@ -227,8 +231,9 @@ executeIdentifier(__kindof Identifier *identifier,
int int
execute(OFString *string, bool isDown) execute(OFString *string, bool isDown)
{ {
std::unique_ptr<char> copy(strdup(string.UTF8String)); char *copy __attribute__((__cleanup__(cleanup))) =
char *p = copy.get(); strdup(string.UTF8String);
char *p = copy;
const int MAXWORDS = 25; // limit, remove const int MAXWORDS = 25; // limit, remove
OFString *w[MAXWORDS]; OFString *w[MAXWORDS];
int val = 0; int val = 0;
@ -242,7 +247,7 @@ execute(OFString *string, bool isDown)
if (i > numargs) if (i > numargs)
continue; continue;
// parse and evaluate exps // parse and evaluate exps
char *s = parseword(p); char *s = parseword(&p);
if (!s) { if (!s) {
numargs = i; numargs = i;
s = strdup(""); s = strdup("");
@ -469,9 +474,14 @@ void
at(OFString *s_, OFString *pos) at(OFString *s_, OFString *pos)
{ {
int n = pos.cube_intValue; int n = pos.cube_intValue;
std::unique_ptr<char> copy(strdup(s_.UTF8String)); char *copy __attribute__((__cleanup__(cleanup))) =
char *s = copy.get(); strdup(s_.UTF8String);
loopi(n) s += strspn(s += strcspn(s, " \0"), " "); char *s = copy;
loopi(n)
{
s += strcspn(s, " \0");
s += strspn(s, " ");
}
s[strcspn(s, " \0")] = 0; s[strcspn(s, " \0")] = 0;
concat(@(s)); concat(@(s));
} }

View file

@ -261,8 +261,8 @@ void
makeundo() makeundo()
{ {
if (undos == nil) if (undos == nil)
undos = undos = [[OFMutableData alloc]
[[OFMutableData alloc] initWithItemSize:sizeof(struct block *)]; initWithItemSize:sizeof(struct block *)];
struct block *copy = blockcopy(&sel); struct block *copy = blockcopy(&sel);
[undos addItem:&copy]; [undos addItem:&copy];

View file

@ -30,8 +30,8 @@ initEntities()
} }
static 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, 0,1,0,10.0f); lastmillis / 10.0f, 0, 1, 0, 10.0f);
} else { } else {
switch (e.attr2) { switch (e.attr2) {
case 1: case 1:

View file

@ -4,7 +4,7 @@ executable('client',
'Client.m', 'Client.m',
'Command.m', 'Command.m',
'ConsoleLine.m', 'ConsoleLine.m',
'Cube.mm', 'Cube.m',
'DynamicEntity.m', 'DynamicEntity.m',
'Entity.m', 'Entity.m',
'Identifier.m', 'Identifier.m',
@ -25,29 +25,29 @@ executable('client',
'clientextras.m', 'clientextras.m',
'clientgame.m', 'clientgame.m',
'clients2c.m', 'clients2c.m',
'commands.mm', 'commands.m',
'console.m', 'console.m',
'editing.m', 'editing.m',
'entities.m', 'entities.m',
'init.mm', 'init.mm',
'menus.m', 'menus.m',
'monster.m', 'monster.m',
'physics.mm', 'physics.m',
'rendercubes.mm', 'rendercubes.m',
'renderextras.mm', 'renderextras.m',
'rendergl.mm', 'rendergl.mm',
'rendermd2.mm', 'rendermd2.mm',
'renderparticles.mm', 'renderparticles.mm',
'rendertext.mm', 'rendertext.mm',
'rndmap.mm', 'rndmap.mm',
'savegamedemo.mm', 'savegamedemo.mm',
'server.mm', 'server.m',
'serverbrowser.mm', 'serverbrowser.mm',
'serverms.mm', 'serverms.m',
'serverutil.mm', 'serverutil.m',
'sound.mm', 'sound.m',
'tools.mm', 'tools.m',
'weapon.mm', 'weapon.m',
'world.mm', 'world.mm',
'worldio.mm', 'worldio.mm',
'worldlight.mm', 'worldlight.mm',
@ -71,12 +71,12 @@ executable('server',
[ [
'Client.m', 'Client.m',
'ServerEntity.m', 'ServerEntity.m',
'server.mm', 'server.m',
'serverms.mm', 'serverms.m',
'serverutil.mm', 'serverutil.m',
'tools.mm', 'tools.m',
], ],
objcpp_args: ['-DSTANDALONE'], objc_args: ['-DSTANDALONE'],
dependencies: [ dependencies: [
objfw_dep, objfw_dep,
sdl_dep sdl_dep

View file

@ -11,36 +11,36 @@
#import "MapModelInfo.h" #import "MapModelInfo.h"
// collide with player or monster // collide with player or monster
bool static bool
plcollide( plcollide(
DynamicEntity *d, DynamicEntity *o, float &headspace, float &hi, float &lo) DynamicEntity *d, DynamicEntity *o, float *headspace, float *hi, float *lo)
{ {
if (o.state != CS_ALIVE) if (o.state != CS_ALIVE)
return true; return true;
const float r = o.radius + d.radius; const float r = o.radius + d.radius;
if (fabs(o.o.x - d.o.x) < r && fabs(o.o.y - d.o.y) < r) { if (fabs(o.o.x - d.o.x) < r && fabs(o.o.y - d.o.y) < r) {
if (d.o.z - d.eyeheight < o.o.z - o.eyeheight) { if (d.o.z - d.eyeheight < o.o.z - o.eyeheight) {
if (o.o.z - o.eyeheight < hi) if (o.o.z - o.eyeheight < *hi)
hi = o.o.z - o.eyeheight - 1; *hi = o.o.z - o.eyeheight - 1;
} else if (o.o.z + o.aboveeye > lo) } else if (o.o.z + o.aboveeye > *lo)
lo = o.o.z + o.aboveeye + 1; *lo = o.o.z + o.aboveeye + 1;
if (fabs(o.o.z - d.o.z) < o.aboveeye + d.eyeheight) if (fabs(o.o.z - d.o.z) < o.aboveeye + d.eyeheight)
return false; return false;
if (d.monsterstate) if (d.monsterstate)
return false; // hack return false; // hack
headspace = d.o.z - o.o.z - o.aboveeye - d.eyeheight; *headspace = d.o.z - o.o.z - o.aboveeye - d.eyeheight;
if (headspace < 0) if (*headspace < 0)
headspace = 10; *headspace = 10;
} }
return true; return true;
} }
bool // recursively collide with a mipmapped corner cube
cornertest(int mip, int x, int y, int dx, int dy, int &bx, int &by, static bool
int &bs) // recursively collide with a mipmapped corner cube cornertest(int mip, int x, int y, int dx, int dy, int *bx, int *by, int *bs)
{ {
sqr *w = wmip[mip]; struct sqr *w = wmip[mip];
int sz = ssize >> mip; int sz = ssize >> mip;
bool stest = bool stest =
SOLID(SWS(w, x + dx, y, sz)) && SOLID(SWS(w, x, y + dy, sz)); SOLID(SWS(w, x + dx, y, sz)) && SOLID(SWS(w, x, y + dy, sz));
@ -48,16 +48,17 @@ cornertest(int mip, int x, int y, int dx, int dy, int &bx, int &by,
x /= 2; x /= 2;
y /= 2; y /= 2;
if (SWS(wmip[mip], x, y, ssize >> mip)->type == CORNER) { if (SWS(wmip[mip], x, y, ssize >> mip)->type == CORNER) {
bx = x << mip; *bx = x << mip;
by = y << mip; *by = y << mip;
bs = 1 << mip; *bs = 1 << mip;
return cornertest(mip, x, y, dx, dy, bx, by, bs); return cornertest(mip, x, y, dx, dy, bx, by, bs);
} }
return stest; return stest;
} }
void // collide with a mapmodel
mmcollide(DynamicEntity *d, float &hi, float &lo) // collide with a mapmodel static void
mmcollide(DynamicEntity *d, float *hi, float *lo)
{ {
for (Entity *e in ents) { for (Entity *e in ents) {
if (e.type != MAPMODEL) if (e.type != MAPMODEL)
@ -73,10 +74,10 @@ mmcollide(DynamicEntity *d, float &hi, float &lo) // collide with a mapmodel
(float)(S(e.x, e.y)->floor + mmi.zoff + e.attr3); (float)(S(e.x, e.y)->floor + mmi.zoff + e.attr3);
if (d.o.z - d.eyeheight < mmz) { if (d.o.z - d.eyeheight < mmz) {
if (mmz < hi) if (mmz < *hi)
hi = mmz; *hi = mmz;
} else if (mmz + mmi.h > lo) } else if (mmz + mmi.h > *lo)
lo = mmz + mmi.h; *lo = mmz + mmi.h;
} }
} }
} }
@ -109,7 +110,7 @@ collide(DynamicEntity *d, bool spawn, float drop, float rise)
// collide with map // collide with map
if (OUTBORD(x, y)) if (OUTBORD(x, y))
return false; return false;
sqr *s = S(x, y); struct sqr *s = S(x, y);
float ceil = s->ceil; float ceil = s->ceil;
float floor = s->floor; float floor = s->floor;
switch (s->type) { switch (s->type) {
@ -120,18 +121,19 @@ collide(DynamicEntity *d, bool spawn, float drop, float rise)
int bx = x, by = y, bs = 1; int bx = x, by = y, bs = 1;
if (x == x1 && y == y1 && if (x == x1 && y == y1 &&
cornertest( cornertest(
0, x, y, -1, -1, bx, by, bs) && 0, x, y, -1, -1, &bx, &by, &bs) &&
fx1 - bx + fy1 - by <= bs || fx1 - bx + fy1 - by <= bs ||
x == x2 && y == y1 && x == x2 && y == y1 &&
cornertest( cornertest(
0, x, y, 1, -1, bx, by, bs) && 0, x, y, 1, -1, &bx, &by, &bs) &&
fx2 - bx >= fy1 - by || fx2 - bx >= fy1 - by ||
x == x1 && y == y2 && x == x1 && y == y2 &&
cornertest( cornertest(
0, x, y, -1, 1, bx, by, bs) && 0, x, y, -1, 1, &bx, &by, &bs) &&
fx1 - bx <= fy2 - by || fx1 - bx <= fy2 - by ||
x == x2 && y == y2 && x == x2 && y == y2 &&
cornertest(0, x, y, 1, 1, bx, by, bs) && cornertest(
0, x, y, 1, 1, &bx, &by, &bs) &&
fx2 - bx + fy2 - by >= bs) fx2 - bx + fy2 - by >= bs)
return false; return false;
break; break;
@ -166,21 +168,21 @@ collide(DynamicEntity *d, bool spawn, float drop, float rise)
for (id player in players) { for (id player in players) {
if (player == [OFNull null] || player == d) if (player == [OFNull null] || player == d)
continue; continue;
if (!plcollide(d, player, headspace, hi, lo)) if (!plcollide(d, player, &headspace, &hi, &lo))
return false; return false;
} }
if (d != player1) if (d != player1)
if (!plcollide(d, player1, headspace, hi, lo)) if (!plcollide(d, player1, &headspace, &hi, &lo))
return false; return false;
// this loop can be a performance bottleneck with many monster on a slow // this loop can be a performance bottleneck with many monster on a slow
// cpu, should replace with a blockmap but seems mostly fast enough // cpu, should replace with a blockmap but seems mostly fast enough
for (DynamicEntity *monster in getmonsters()) for (DynamicEntity *monster in getmonsters())
if (!vreject(d.o, monster.o, 7.0f) && d != monster && if (!vreject(d.o, monster.o, 7.0f) && d != monster &&
!plcollide(d, monster, headspace, hi, lo)) !plcollide(d, monster, &headspace, &hi, &lo))
return false; return false;
headspace -= 0.01f; headspace -= 0.01f;
mmcollide(d, hi, lo); // collide with map models mmcollide(d, &hi, &lo); // collide with map models
if (spawn) { if (spawn) {
// just drop to floor (sideeffect) // just drop to floor (sideeffect)
@ -246,8 +248,8 @@ physicsframe() // optimally schedule physics frames inside the graphics frames
// moveres indicated the physics precision (which is lower for monsters and // moveres indicated the physics precision (which is lower for monsters and
// multiplayer prediction) local is false for multiplayer prediction // multiplayer prediction) local is false for multiplayer prediction
void static void
moveplayer(DynamicEntity *pl, int moveres, bool local, int curtime) moveplayer4(DynamicEntity *pl, int moveres, bool local, int curtime)
{ {
const bool water = hdr.waterlevel > pl.o.z - 0.5f; const bool water = hdr.waterlevel > pl.o.z - 0.5f;
const bool floating = (editmode && local) || pl.state == CS_EDITING; const bool floating = (editmode && local) || pl.state == CS_EDITING;
@ -377,7 +379,7 @@ moveplayer(DynamicEntity *pl, int moveres, bool local, int curtime)
if (pl.o.x < 0 || pl.o.x >= ssize || pl.o.y < 0 || pl.o.y > ssize) if (pl.o.x < 0 || pl.o.x >= ssize || pl.o.y < 0 || pl.o.y > ssize)
pl.outsidemap = true; pl.outsidemap = true;
else { else {
sqr *s = S((int)pl.o.x, (int)pl.o.y); struct sqr *s = S((int)pl.o.x, (int)pl.o.y);
pl.outsidemap = SOLID(s) || pl.outsidemap = SOLID(s) ||
pl.o.z < s->floor - (s->type == FHF ? s->vdelta / 4 : 0) || pl.o.z < s->floor - (s->type == FHF ? s->vdelta / 4 : 0) ||
pl.o.z > s->ceil + (s->type == CHF ? s->vdelta / 4 : 0); pl.o.z > s->ceil + (s->type == CHF ? s->vdelta / 4 : 0);
@ -411,7 +413,7 @@ moveplayer(DynamicEntity *pl, int moveres, bool local, int curtime)
void void
moveplayer(DynamicEntity *pl, int moveres, bool local) moveplayer(DynamicEntity *pl, int moveres, bool local)
{ {
loopi(physicsrepeat) moveplayer(pl, moveres, local, loopi(physicsrepeat) moveplayer4(pl, moveres, local,
i ? curtime / physicsrepeat i ? curtime / physicsrepeat
: curtime - curtime / physicsrepeat * (physicsrepeat - 1)); : curtime - curtime / physicsrepeat * (physicsrepeat - 1));
} }

View file

@ -3,23 +3,23 @@
#include "cube.h" #include "cube.h"
vertex *verts = NULL; static struct vertex *verts = NULL;
int curvert; int curvert;
int curmaxverts = 10000; static int curmaxverts = 10000;
void void
setarraypointers() setarraypointers()
{ {
glVertexPointer(3, GL_FLOAT, sizeof(vertex), &verts[0].x); glVertexPointer(3, GL_FLOAT, sizeof(struct vertex), &verts[0].x);
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(vertex), &verts[0].r); glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(struct vertex), &verts[0].r);
glTexCoordPointer(2, GL_FLOAT, sizeof(vertex), &verts[0].u); glTexCoordPointer(2, GL_FLOAT, sizeof(struct vertex), &verts[0].u);
} }
void void
reallocv() reallocv()
{ {
verts = verts =
(vertex *)OFResizeMemory(verts, (curmaxverts *= 2), sizeof(vertex)); OFResizeMemory(verts, (curmaxverts *= 2), sizeof(struct vertex));
curmaxverts -= 10; curmaxverts -= 10;
setarraypointers(); setarraypointers();
} }
@ -36,16 +36,16 @@ reallocv()
#define vertf(v1, v2, v3, ls, t1, t2) \ #define vertf(v1, v2, v3, ls, t1, t2) \
{ \ { \
vertex &v = verts[curvert++]; \ struct vertex *v = &verts[curvert++]; \
v.u = t1; \ v->u = t1; \
v.v = t2; \ v->v = t2; \
v.x = v1; \ v->x = v1; \
v.y = v2; \ v->y = v2; \
v.z = v3; \ v->z = v3; \
v.r = ls->r; \ v->r = ls->r; \
v.g = ls->g; \ v->g = ls->g; \
v.b = ls->b; \ v->b = ls->b; \
v.a = 255; \ v->a = 255; \
} }
#define vert(v1, v2, v3, ls, t1, t2) \ #define vert(v1, v2, v3, ls, t1, t2) \
@ -88,12 +88,13 @@ finishstrips()
stripend(); stripend();
} }
sqr sbright, sdark; static struct sqr sbright, sdark;
VAR(lighterror, 1, 8, 100); VAR(lighterror, 1, 8, 100);
// floor/ceil quads
void void
render_flat(int wtex, int x, int y, int size, int h, sqr *l1, sqr *l2, sqr *l3, render_flat(int wtex, int x, int y, int size, int h, struct sqr *l1,
sqr *l4, bool isceil) // floor/ceil quads struct sqr *l2, struct sqr *l3, struct sqr *l4, bool isceil)
{ {
vertcheck(); vertcheck();
if (showm) { if (showm) {
@ -171,10 +172,11 @@ render_flat(int wtex, int x, int y, int size, int h, sqr *l1, sqr *l2, sqr *l3,
nquads++; nquads++;
} }
// floor/ceil quads on a slope
void void
render_flatdelta(int wtex, int x, int y, int size, float h1, float h2, float h3, render_flatdelta(int wtex, int x, int y, int size, float h1, float h2, float h3,
float h4, sqr *l1, sqr *l2, sqr *l3, sqr *l4, float h4, struct sqr *l1, struct sqr *l2, struct sqr *l3, struct sqr *l4,
bool isceil) // floor/ceil quads on a slope bool isceil)
{ {
vertcheck(); vertcheck();
if (showm) { if (showm) {
@ -229,9 +231,10 @@ render_flatdelta(int wtex, int x, int y, int size, float h1, float h2, float h3,
nquads++; nquads++;
} }
// floor/ceil tris on a corner cube
void void
render_2tris(sqr *h, sqr *s, int x1, int y1, int x2, int y2, int x3, int y3, render_2tris(struct sqr *h, struct sqr *s, int x1, int y1, int x2, int y2,
sqr *l1, sqr *l2, sqr *l3) // floor/ceil tris on a corner cube int x3, int y3, struct sqr *l1, struct sqr *l2, struct sqr *l3)
{ {
stripend(); stripend();
vertcheck(); vertcheck();
@ -258,8 +261,8 @@ render_2tris(sqr *h, sqr *s, int x1, int y1, int x2, int y2, int x3, int y3,
} }
void void
render_tris(int x, int y, int size, bool topleft, sqr *h1, sqr *h2, sqr *s, render_tris(int x, int y, int size, bool topleft, struct sqr *h1,
sqr *t, sqr *u, sqr *v) struct sqr *h2, struct sqr *s, struct sqr *t, struct sqr *u, struct sqr *v)
{ {
if (topleft) { if (topleft) {
if (h1) if (h1)
@ -280,7 +283,7 @@ render_tris(int x, int y, int size, bool topleft, sqr *h1, sqr *h2, sqr *s,
void void
render_square(int wtex, float floor1, float floor2, float ceil1, float ceil2, render_square(int wtex, float floor1, float floor2, float ceil1, float ceil2,
int x1, int y1, int x2, int y2, int size, sqr *l1, sqr *l2, int x1, int y1, int x2, int y2, int size, struct sqr *l1, struct sqr *l2,
bool flip) // wall quads bool flip) // wall quads
{ {
stripend(); stripend();
@ -319,8 +322,8 @@ VAR(watersubdiv, 1, 4, 64);
VARF(waterlevel, -128, -128, 127, VARF(waterlevel, -128, -128, 127,
if (!noteditmode()) hdr.waterlevel = waterlevel); if (!noteditmode()) hdr.waterlevel = waterlevel);
inline void static inline void
vertw(int v1, float v2, int v3, sqr *c, float t1, float t2, float t) vertw(int v1, float v2, int v3, struct sqr *c, float t1, float t2, float t)
{ {
vertcheck(); vertcheck();
vertf((float)v1, v2 - (float)sin(v1 * v3 * 0.1 + t) * 0.2f, (float)v3, vertf((float)v1, v2 - (float)sin(v1 * v3 * 0.1 + t) * 0.2f, (float)v3,
@ -363,7 +366,7 @@ renderwater(float hf)
float t1 = lastmillis / 300.0f; float t1 = lastmillis / 300.0f;
float t2 = lastmillis / 4000.0f; float t2 = lastmillis / 4000.0f;
sqr dl; struct sqr dl;
dl.r = dl.g = dl.b = 255; dl.r = dl.g = dl.b = 255;
for (int xx = wx1; xx < wx2; xx += watersubdiv) { for (int xx = wx1; xx < wx2; xx += watersubdiv) {

View file

@ -25,7 +25,7 @@ linestyle(float width, int r, int g, int b)
} }
void void
box(const block *b, float z1, float z2, float z3, float z4) box(const struct block *b, float z1, float z2, float z3, float z4)
{ {
glBegin(GL_POLYGON); glBegin(GL_POLYGON);
glVertex3f((float)b->x, z1, (float)b->y); glVertex3f((float)b->x, z1, (float)b->y);
@ -86,9 +86,9 @@ struct sphere {
OFVector3D o; OFVector3D o;
float size, max; float size, max;
int type; int type;
sphere *next; struct sphere *next;
}; };
sphere spheres[MAXSPHERES], *slist = NULL, *sempty = NULL; static struct sphere spheres[MAXSPHERES], *slist = NULL, *sempty = NULL;
bool sinit = false; bool sinit = false;
void void
@ -103,7 +103,7 @@ newsphere(const OFVector3D *o, float max, int type)
sinit = true; sinit = true;
} }
if (sempty) { if (sempty) {
sphere *p = sempty; struct sphere *p = sempty;
sempty = p->next; sempty = p->next;
p->o = *o; p->o = *o;
p->max = max; p->max = max;
@ -122,7 +122,7 @@ renderspheres(int time)
glBlendFunc(GL_SRC_ALPHA, GL_ONE); glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glBindTexture(GL_TEXTURE_2D, 4); glBindTexture(GL_TEXTURE_2D, 4);
for (sphere *p, **pp = &slist; p = *pp;) { for (struct sphere *p, **pp = &slist; (p = *pp) != NULL;) {
glPushMatrix(); glPushMatrix();
float size = p->size / p->max; float size = p->size / p->max;
glColor4f(1.0f, 1.0f, 1.0f, 1.0f - size); glColor4f(1.0f, 1.0f, 1.0f, 1.0f - size);

View file

@ -46,8 +46,8 @@ void process(ENetPacket *packet, int sender);
void multicast(ENetPacket *packet, int sender); void multicast(ENetPacket *packet, int sender);
void disconnect_client(int n, OFString *reason); void disconnect_client(int n, OFString *reason);
void static void
send(int n, ENetPacket *packet) send_(int n, ENetPacket *packet)
{ {
if (!packet) if (!packet)
return; return;
@ -77,7 +77,7 @@ send2(bool rel, int cn, int a, int b)
if (cn < 0) if (cn < 0)
process(packet, -1); process(packet, -1);
else else
send(cn, packet); send_(cn, packet);
if (packet->referenceCount == 0) if (packet->referenceCount == 0)
enet_packet_destroy(packet); enet_packet_destroy(packet);
} }
@ -115,9 +115,9 @@ resetitems()
notgotitems = true; notgotitems = true;
} }
void // server side item pickup, acknowledge first client that gets it
pickup(uint i, int sec, int sender) // server side item pickup, acknowledge static void
// first client that gets it pickup(uint i, int sec, int sender)
{ {
if (i >= (uint)sents.count) if (i >= (uint)sents.count)
return; return;
@ -265,7 +265,7 @@ process(ENetPacket *packet, int sender) // sender may be -1
} }
case SV_RECVMAP: case SV_RECVMAP:
send(sender, recvmap(sender)); send_(sender, recvmap(sender));
return; return;
// allows for new features that require no server updates // allows for new features that require no server updates
@ -320,7 +320,7 @@ send_welcome(int n)
} }
*(ushort *)start = ENET_HOST_TO_NET_16(p - start); *(ushort *)start = ENET_HOST_TO_NET_16(p - start);
enet_packet_resize(packet, p - start); enet_packet_resize(packet, p - start);
send(n, packet); send_(n, packet);
} }
void void
@ -329,7 +329,7 @@ multicast(ENetPacket *packet, int sender)
size_t count = clients.count; size_t count = clients.count;
for (size_t i = 0; i < count; i++) for (size_t i = 0; i < count; i++)
if (i != sender) if (i != sender)
send(i, packet); send_(i, packet);
} }
void void

View file

@ -5,13 +5,13 @@
static ENetSocket mssock = ENET_SOCKET_NULL; static ENetSocket mssock = ENET_SOCKET_NULL;
static void static void
httpgetsend(ENetAddress &ad, OFString *hostname, OFString *req, OFString *ref, httpgetsend(ENetAddress *ad, OFString *hostname, OFString *req, OFString *ref,
OFString *agent) OFString *agent)
{ {
if (ad.host == ENET_HOST_ANY) { if (ad->host == ENET_HOST_ANY) {
[OFStdOut writeFormat:@"looking up %@...\n", hostname]; [OFStdOut writeFormat:@"looking up %@...\n", hostname];
enet_address_set_host(&ad, hostname.UTF8String); enet_address_set_host(ad, hostname.UTF8String);
if (ad.host == ENET_HOST_ANY) if (ad->host == ENET_HOST_ANY)
return; return;
} }
if (mssock != ENET_SOCKET_NULL) if (mssock != ENET_SOCKET_NULL)
@ -21,7 +21,7 @@ httpgetsend(ENetAddress &ad, OFString *hostname, OFString *req, OFString *ref,
printf("could not open socket\n"); printf("could not open socket\n");
return; return;
} }
if (enet_socket_connect(mssock, &ad) < 0) { if (enet_socket_connect(mssock, ad) < 0) {
printf("could not connect\n"); printf("could not connect\n");
return; return;
} }
@ -38,21 +38,21 @@ httpgetsend(ENetAddress &ad, OFString *hostname, OFString *req, OFString *ref,
} }
static void static void
httpgetrecieve(ENetBuffer &buf) httpgetrecieve(ENetBuffer *buf)
{ {
if (mssock == ENET_SOCKET_NULL) if (mssock == ENET_SOCKET_NULL)
return; return;
enet_uint32 events = ENET_SOCKET_WAIT_RECEIVE; enet_uint32 events = ENET_SOCKET_WAIT_RECEIVE;
if (enet_socket_wait(mssock, &events, 0) >= 0 && events) { if (enet_socket_wait(mssock, &events, 0) >= 0 && events) {
int len = enet_socket_receive(mssock, NULL, &buf, 1); int len = enet_socket_receive(mssock, NULL, buf, 1);
if (len <= 0) { if (len <= 0) {
enet_socket_destroy(mssock); enet_socket_destroy(mssock);
mssock = ENET_SOCKET_NULL; mssock = ENET_SOCKET_NULL;
return; return;
} }
buf.data = ((char *)buf.data) + len; buf->data = ((char *)buf->data) + len;
((char *)buf.data)[0] = 0; ((char *)buf->data)[0] = 0;
buf.dataLength -= len; buf->dataLength -= len;
} }
} }
@ -79,7 +79,7 @@ updatemasterserver(int seconds)
if (seconds > updmaster) { if (seconds > updmaster) {
OFString *path = [OFString OFString *path = [OFString
stringWithFormat:@"%@register.do?action=add", masterpath]; stringWithFormat:@"%@register.do?action=add", masterpath];
httpgetsend(masterserver, masterbase, path, @"cubeserver", httpgetsend(&masterserver, masterbase, path, @"cubeserver",
@"Cube Server"); @"Cube Server");
masterrep[0] = 0; masterrep[0] = 0;
masterb.data = masterrep; masterb.data = masterrep;
@ -92,7 +92,7 @@ static void
checkmasterreply() checkmasterreply()
{ {
bool busy = mssock != ENET_SOCKET_NULL; bool busy = mssock != ENET_SOCKET_NULL;
httpgetrecieve(masterb); httpgetrecieve(&masterb);
if (busy && mssock == ENET_SOCKET_NULL) if (busy && mssock == ENET_SOCKET_NULL)
printf("masterserver reply: %s\n", stripheader(masterrep)); printf("masterserver reply: %s\n", stripheader(masterrep));
} }
@ -103,13 +103,13 @@ retrieveservers(uchar *buf, int buflen)
OFString *path = OFString *path =
[OFString stringWithFormat:@"%@retrieve.do?item=list", masterpath]; [OFString stringWithFormat:@"%@retrieve.do?item=list", masterpath];
httpgetsend( httpgetsend(
masterserver, masterbase, path, @"cubeserver", @"Cube Server"); &masterserver, masterbase, path, @"cubeserver", @"Cube Server");
ENetBuffer eb; ENetBuffer eb;
buf[0] = 0; buf[0] = 0;
eb.data = buf; eb.data = buf;
eb.dataLength = buflen - 1; eb.dataLength = buflen - 1;
while (mssock != ENET_SOCKET_NULL) while (mssock != ENET_SOCKET_NULL)
httpgetrecieve(eb); httpgetrecieve(&eb);
return stripheader(buf); return stripheader(buf);
} }

View file

@ -37,7 +37,7 @@ VAR(soundbufferlen, 128, 1024, 4096);
void void
initsound() initsound()
{ {
memset(soundlocs, 0, sizeof(soundloc) * MAXCHAN); memset(soundlocs, 0, sizeof(struct soundloc) * MAXCHAN);
if (Mix_OpenAudio(SOUNDFREQ, MIX_DEFAULT_FORMAT, 2, soundbufferlen) < if (Mix_OpenAudio(SOUNDFREQ, MIX_DEFAULT_FORMAT, 2, soundbufferlen) <
0) { 0) {
conoutf(@"sound init failed (SDL_mixer): %s", conoutf(@"sound init failed (SDL_mixer): %s",
@ -125,7 +125,7 @@ updatechanvol(int chan, const OFVector3D *loc)
float yaw = float yaw =
-atan2(v.x, v.y) - player1.yaw * (PI / 180.0f); -atan2(v.x, v.y) - player1.yaw * (PI / 180.0f);
// range is from 0 (left) to 255 (right) // range is from 0 (left) to 255 (right)
pan = int(255.9f * (0.5 * sin(yaw) + 0.5f)); pan = (int)(255.9f * (0.5 * sin(yaw) + 0.5f));
} }
} }
vol = (vol * MAXVOL) / 255; vol = (vol * MAXVOL) / 255;

View file

@ -1,7 +1,6 @@
// implementation of generic tools // implementation of generic tools
#include "tools.h" #include "tools.h"
#include <new>
///////////////////////// misc tools /////////////////////// ///////////////////////// misc tools ///////////////////////

View file

@ -242,7 +242,7 @@ splash(Projectile *p, const OFVector3D *v, const OFVector3D *vold,
} }
} }
inline void static inline void
projdamage(DynamicEntity *o, Projectile *p, const OFVector3D *v, int i, int im, projdamage(DynamicEntity *o, Projectile *p, const OFVector3D *v, int i, int im,
int qdam) int qdam)
{ {