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

View file

@ -29,15 +29,15 @@ OF_CONSTRUCTOR()
int selh = 0;
bool selset = false;
#define loopselxy(b) \
{ \
makeundo(); \
loop(x, sel->xs) loop(y, sel->ys) \
{ \
#define loopselxy(b) \
{ \
makeundo(); \
loop(x, sel->xs) loop(y, sel->ys) \
{ \
struct sqr *s = S(sel->x + x, sel->y + y); \
b; \
} \
remip(sel, 0); \
b; \
} \
remip(sel, 0); \
}
int cx, cy, ch;
@ -261,8 +261,8 @@ void
makeundo()
{
if (undos == nil)
undos =
[[OFMutableData alloc] initWithItemSize:sizeof(struct block *)];
undos = [[OFMutableData alloc]
initWithItemSize:sizeof(struct block *)];
struct block *copy = blockcopy(&sel);
[undos addItem:&copy];

View file

@ -30,8 +30,8 @@ initEntities()
}
static void
renderent(Entity *e, OFString *mdlname, float z, float yaw, int frame/* = 0*/,
int numf/* = 1*/, int basetime/* = 0*/, float speed/* = 10.0f*/)
renderent(Entity *e, OFString *mdlname, float z, float yaw, int frame /* = 0*/,
int numf /* = 1*/, int basetime /* = 0*/, float speed /* = 10.0f*/)
{
rendermodel(mdlname, frame, numf, 0, 1.1f,
OFMakeVector3D(e.x, z + S(e.x, e.y)->floor, e.y), yaw, 0, false,
@ -67,7 +67,7 @@ renderentities()
(float)(1 +
sin(lastmillis / 100.0 + e.x + e.y) /
20),
lastmillis / 10.0f, 0,1,0,10.0f);
lastmillis / 10.0f, 0, 1, 0, 10.0f);
} else {
switch (e.attr2) {
case 1:
@ -85,7 +85,7 @@ renderentities()
20),
lastmillis /
(e.attr2 ? 1.0f : 10.0f),
0, 1, 0, 10.0f);
0, 1, 0, 10.0f);
break;
case 4:

View file

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

View file

@ -11,36 +11,36 @@
#import "MapModelInfo.h"
// collide with player or monster
bool
static bool
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)
return true;
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 (d.o.z - d.eyeheight < o.o.z - o.eyeheight) {
if (o.o.z - o.eyeheight < hi)
hi = o.o.z - o.eyeheight - 1;
} else if (o.o.z + o.aboveeye > lo)
lo = o.o.z + o.aboveeye + 1;
if (o.o.z - o.eyeheight < *hi)
*hi = o.o.z - o.eyeheight - 1;
} else if (o.o.z + o.aboveeye > *lo)
*lo = o.o.z + o.aboveeye + 1;
if (fabs(o.o.z - d.o.z) < o.aboveeye + d.eyeheight)
return false;
if (d.monsterstate)
return false; // hack
headspace = d.o.z - o.o.z - o.aboveeye - d.eyeheight;
if (headspace < 0)
headspace = 10;
*headspace = d.o.z - o.o.z - o.aboveeye - d.eyeheight;
if (*headspace < 0)
*headspace = 10;
}
return true;
}
bool
cornertest(int mip, int x, int y, int dx, int dy, int &bx, int &by,
int &bs) // recursively collide with a mipmapped corner cube
// recursively collide with a mipmapped corner cube
static bool
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;
bool stest =
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;
y /= 2;
if (SWS(wmip[mip], x, y, ssize >> mip)->type == CORNER) {
bx = x << mip;
by = y << mip;
bs = 1 << mip;
*bx = x << mip;
*by = y << mip;
*bs = 1 << mip;
return cornertest(mip, x, y, dx, dy, bx, by, bs);
}
return stest;
}
void
mmcollide(DynamicEntity *d, float &hi, float &lo) // collide with a mapmodel
// collide with a mapmodel
static void
mmcollide(DynamicEntity *d, float *hi, float *lo)
{
for (Entity *e in ents) {
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);
if (d.o.z - d.eyeheight < mmz) {
if (mmz < hi)
hi = mmz;
} else if (mmz + mmi.h > lo)
lo = mmz + mmi.h;
if (mmz < *hi)
*hi = mmz;
} else if (mmz + mmi.h > *lo)
*lo = mmz + mmi.h;
}
}
}
@ -109,7 +110,7 @@ collide(DynamicEntity *d, bool spawn, float drop, float rise)
// collide with map
if (OUTBORD(x, y))
return false;
sqr *s = S(x, y);
struct sqr *s = S(x, y);
float ceil = s->ceil;
float floor = s->floor;
switch (s->type) {
@ -120,18 +121,19 @@ collide(DynamicEntity *d, bool spawn, float drop, float rise)
int bx = x, by = y, bs = 1;
if (x == x1 && y == y1 &&
cornertest(
0, x, y, -1, -1, bx, by, bs) &&
0, x, y, -1, -1, &bx, &by, &bs) &&
fx1 - bx + fy1 - by <= bs ||
x == x2 && y == y1 &&
cornertest(
0, x, y, 1, -1, bx, by, bs) &&
0, x, y, 1, -1, &bx, &by, &bs) &&
fx2 - bx >= fy1 - by ||
x == x1 && y == y2 &&
cornertest(
0, x, y, -1, 1, bx, by, bs) &&
0, x, y, -1, 1, &bx, &by, &bs) &&
fx1 - bx <= fy2 - by ||
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)
return false;
break;
@ -166,21 +168,21 @@ collide(DynamicEntity *d, bool spawn, float drop, float rise)
for (id player in players) {
if (player == [OFNull null] || player == d)
continue;
if (!plcollide(d, player, headspace, hi, lo))
if (!plcollide(d, player, &headspace, &hi, &lo))
return false;
}
if (d != player1)
if (!plcollide(d, player1, headspace, hi, lo))
if (!plcollide(d, player1, &headspace, &hi, &lo))
return false;
// this loop can be a performance bottleneck with many monster on a slow
// cpu, should replace with a blockmap but seems mostly fast enough
for (DynamicEntity *monster in getmonsters())
if (!vreject(d.o, monster.o, 7.0f) && d != monster &&
!plcollide(d, monster, headspace, hi, lo))
!plcollide(d, monster, &headspace, &hi, &lo))
return false;
headspace -= 0.01f;
mmcollide(d, hi, lo); // collide with map models
mmcollide(d, &hi, &lo); // collide with map models
if (spawn) {
// 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
// multiplayer prediction) local is false for multiplayer prediction
void
moveplayer(DynamicEntity *pl, int moveres, bool local, int curtime)
static void
moveplayer4(DynamicEntity *pl, int moveres, bool local, int curtime)
{
const bool water = hdr.waterlevel > pl.o.z - 0.5f;
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)
pl.outsidemap = true;
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.o.z < s->floor - (s->type == FHF ? 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
moveplayer(DynamicEntity *pl, int moveres, bool local)
{
loopi(physicsrepeat) moveplayer(pl, moveres, local,
loopi(physicsrepeat) moveplayer4(pl, moveres, local,
i ? curtime / physicsrepeat
: curtime - curtime / physicsrepeat * (physicsrepeat - 1));
}

View file

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

View file

@ -25,7 +25,7 @@ linestyle(float width, int r, int g, int b)
}
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);
glVertex3f((float)b->x, z1, (float)b->y);
@ -86,9 +86,9 @@ struct sphere {
OFVector3D o;
float size, max;
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;
void
@ -103,7 +103,7 @@ newsphere(const OFVector3D *o, float max, int type)
sinit = true;
}
if (sempty) {
sphere *p = sempty;
struct sphere *p = sempty;
sempty = p->next;
p->o = *o;
p->max = max;
@ -122,7 +122,7 @@ renderspheres(int time)
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glBindTexture(GL_TEXTURE_2D, 4);
for (sphere *p, **pp = &slist; p = *pp;) {
for (struct sphere *p, **pp = &slist; (p = *pp) != NULL;) {
glPushMatrix();
float size = p->size / p->max;
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 disconnect_client(int n, OFString *reason);
void
send(int n, ENetPacket *packet)
static void
send_(int n, ENetPacket *packet)
{
if (!packet)
return;
@ -77,7 +77,7 @@ send2(bool rel, int cn, int a, int b)
if (cn < 0)
process(packet, -1);
else
send(cn, packet);
send_(cn, packet);
if (packet->referenceCount == 0)
enet_packet_destroy(packet);
}
@ -115,9 +115,9 @@ resetitems()
notgotitems = true;
}
void
pickup(uint i, int sec, int sender) // server side item pickup, acknowledge
// first client that gets it
// server side item pickup, acknowledge first client that gets it
static void
pickup(uint i, int sec, int sender)
{
if (i >= (uint)sents.count)
return;
@ -265,7 +265,7 @@ process(ENetPacket *packet, int sender) // sender may be -1
}
case SV_RECVMAP:
send(sender, recvmap(sender));
send_(sender, recvmap(sender));
return;
// 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);
enet_packet_resize(packet, p - start);
send(n, packet);
send_(n, packet);
}
void
@ -329,7 +329,7 @@ multicast(ENetPacket *packet, int sender)
size_t count = clients.count;
for (size_t i = 0; i < count; i++)
if (i != sender)
send(i, packet);
send_(i, packet);
}
void

View file

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

View file

@ -37,7 +37,7 @@ VAR(soundbufferlen, 128, 1024, 4096);
void
initsound()
{
memset(soundlocs, 0, sizeof(soundloc) * MAXCHAN);
memset(soundlocs, 0, sizeof(struct soundloc) * MAXCHAN);
if (Mix_OpenAudio(SOUNDFREQ, MIX_DEFAULT_FORMAT, 2, soundbufferlen) <
0) {
conoutf(@"sound init failed (SDL_mixer): %s",
@ -125,7 +125,7 @@ updatechanvol(int chan, const OFVector3D *loc)
float yaw =
-atan2(v.x, v.y) - player1.yaw * (PI / 180.0f);
// 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;

View file

@ -1,7 +1,6 @@
// implementation of generic tools
#include "tools.h"
#include <new>
///////////////////////// 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,
int qdam)
{