Remove loop[ijkl]
They confused clang-format a lot. FossilOrigin-Name: 6b85eefc857c74c00d7ef693e312cc15df53201a6712aee8ba8d57c643c1703b
This commit is contained in:
parent
2c5f2d0342
commit
006dba8370
22 changed files with 318 additions and 257 deletions
12
src/MD2.m
12
src/MD2.m
|
@ -127,8 +127,7 @@ snap(int sn, float f)
|
|||
struct md2_frame *cf =
|
||||
(struct md2_frame *)((char *)_frames + _frameSize * frame);
|
||||
float sc = 16.0f / scale;
|
||||
loop(vi, _numVerts)
|
||||
{
|
||||
for (int vi = 0; vi < _numVerts; vi++) {
|
||||
uchar *cv = (uchar *)&cf->vertices[vi].vertex;
|
||||
OFVector3D *v = &(_mverts[frame])[vi];
|
||||
v->x = (snap(sn, cv[0] * cf->scale[0]) + cf->translate[0]) / sc;
|
||||
|
@ -149,9 +148,9 @@ snap(int sn, float f)
|
|||
snap:(int)sn
|
||||
basetime:(int)basetime
|
||||
{
|
||||
loopi(range) if (!_mverts[frame + i])[self scaleWithFrame:frame + i
|
||||
scale:sc
|
||||
snap:sn];
|
||||
for (int i = 0; i < range; i++)
|
||||
if (!_mverts[frame + i])
|
||||
[self scaleWithFrame:frame + i scale:sc snap:sn];
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef(position.x, position.y, position.z);
|
||||
|
@ -192,8 +191,7 @@ snap(int sn, float f)
|
|||
numVertex = -numVertex;
|
||||
}
|
||||
|
||||
loopi(numVertex)
|
||||
{
|
||||
for (int i = 0; i < numVertex; i++) {
|
||||
float tu = *((float *)command++);
|
||||
float tv = *((float *)command++);
|
||||
glTexCoord2f(tu, tv);
|
||||
|
|
|
@ -198,8 +198,8 @@ updateworld(int millis) // main game update loop
|
|||
void
|
||||
entinmap(DynamicEntity *d)
|
||||
{
|
||||
loopi(100) // try max 100 times
|
||||
{
|
||||
// try max 100 times
|
||||
for (int i = 0; i < 100; i++) {
|
||||
float dx = (rnd(21) - 10) / 10.0f * i; // increasing distance
|
||||
float dy = (rnd(21) - 10) / 10.0f * i;
|
||||
OFVector3D old = d.origin;
|
||||
|
@ -221,7 +221,8 @@ void
|
|||
spawnplayer(DynamicEntity *d)
|
||||
{
|
||||
int r = fixspawn-- > 0 ? 4 : rnd(10) + 1;
|
||||
loopi(r) spawncycle = findentity(PLAYERSTART, spawncycle + 1);
|
||||
for (int i = 0; i < r; i++)
|
||||
spawncycle = findentity(PLAYERSTART, spawncycle + 1);
|
||||
if (spawncycle != -1) {
|
||||
d.origin = OFMakeVector3D(
|
||||
ents[spawncycle].x, ents[spawncycle].y, ents[spawncycle].z);
|
||||
|
|
|
@ -213,8 +213,7 @@ addmsg(int rel, int num, int type, ...)
|
|||
|
||||
va_list marker;
|
||||
va_start(marker, type);
|
||||
loopi(num - 1)
|
||||
{
|
||||
for (int i = 0; i < num - 1; i++) {
|
||||
int tmp = va_arg(marker, int);
|
||||
[msg addItem:&tmp];
|
||||
}
|
||||
|
@ -345,7 +344,7 @@ c2sinfo(DynamicEntity *d)
|
|||
// send messages collected during the previous frames
|
||||
if (*(int *)[msg itemAtIndex:1])
|
||||
packet->flags = ENET_PACKET_FLAG_RELIABLE;
|
||||
loopi(*(int *)[msg itemAtIndex:0])
|
||||
for (int i = 0; i < *(int *)[msg itemAtIndex:0]; i++)
|
||||
putint(&p, *(int *)[msg itemAtIndex:i + 2]);
|
||||
}
|
||||
[messages removeAllObjects];
|
||||
|
|
|
@ -240,8 +240,7 @@ execute(OFString *string, bool isDown)
|
|||
for (bool cont = true; cont;) {
|
||||
// for each ; seperated statement
|
||||
int numargs = MAXWORDS;
|
||||
loopi(MAXWORDS)
|
||||
{
|
||||
for (int i = 0; i < MAXWORDS; i++) {
|
||||
// collect all argument values
|
||||
w[i] = @"";
|
||||
if (i > numargs)
|
||||
|
@ -421,8 +420,7 @@ loopa(OFString *times, OFString *body)
|
|||
{
|
||||
int t = times.cube_intValue;
|
||||
|
||||
loopi(t)
|
||||
{
|
||||
for (int i = 0; i < t; i++) {
|
||||
intset(@"i", i);
|
||||
execute(body, true);
|
||||
}
|
||||
|
@ -477,8 +475,7 @@ at(OFString *s_, OFString *pos)
|
|||
char *copy __attribute__((__cleanup__(cleanup))) =
|
||||
strdup(s_.UTF8String);
|
||||
char *s = copy;
|
||||
loopi(n)
|
||||
{
|
||||
for (int i = 0; i < n; i++) {
|
||||
s += strcspn(s, " \0");
|
||||
s += strspn(s, " ");
|
||||
}
|
||||
|
|
|
@ -95,11 +95,9 @@ renderconsole()
|
|||
i++;
|
||||
}
|
||||
|
||||
loopj(nd)
|
||||
{
|
||||
for (int j = 0; j < nd; j++)
|
||||
draw_text(refs[j], FONTH / 3,
|
||||
(FONTH / 4 * 5) * (nd - j - 1) + FONTH / 3, 2);
|
||||
}
|
||||
}
|
||||
|
||||
// keymap is defined externally in keymap.cfg
|
||||
|
|
|
@ -33,11 +33,12 @@ bool selset = false;
|
|||
#define loopselxy(b) \
|
||||
{ \
|
||||
makeundo(); \
|
||||
loop(x, sel->xs) loop(y, sel->ys) \
|
||||
{ \
|
||||
for (int x = 0; x < sel->xs; x++) { \
|
||||
for (int y = 0; y < sel->ys; y++) { \
|
||||
struct sqr *s = S(sel->x + x, sel->y + y); \
|
||||
b; \
|
||||
} \
|
||||
} \
|
||||
remip(sel, 0); \
|
||||
}
|
||||
|
||||
|
@ -291,8 +292,10 @@ void
|
|||
copy()
|
||||
{
|
||||
EDITSELMP;
|
||||
|
||||
if (copybuf)
|
||||
OFFreeMemory(copybuf);
|
||||
|
||||
copybuf = blockcopy(&sel);
|
||||
}
|
||||
|
||||
|
@ -321,8 +324,7 @@ void
|
|||
tofronttex() // maintain most recently used of the texture lists when applying
|
||||
// texture
|
||||
{
|
||||
loopi(3)
|
||||
{
|
||||
for (int i = 0; i < 3; i++) {
|
||||
int c = curedittex[i];
|
||||
if (c >= 0) {
|
||||
uchar *p = hdr.texlists[i];
|
||||
|
@ -371,6 +373,7 @@ void
|
|||
editheight(int flr, int amount)
|
||||
{
|
||||
EDITSEL;
|
||||
|
||||
bool isfloor = flr == 0;
|
||||
editheightxy(isfloor, amount, &sel);
|
||||
addmsg(1, 7, SV_EDITH, sel.x, sel.y, sel.xs, sel.ys, isfloor, amount);
|
||||
|
@ -400,12 +403,15 @@ void
|
|||
edittex(int type, int dir)
|
||||
{
|
||||
EDITSEL;
|
||||
|
||||
if (type < 0 || type > 3)
|
||||
return;
|
||||
|
||||
if (type != lasttype) {
|
||||
tofronttex();
|
||||
lasttype = type;
|
||||
}
|
||||
|
||||
int atype = type == 3 ? 1 : type;
|
||||
int i = curedittex[atype];
|
||||
i = i < 0 ? 0 : i + dir;
|
||||
|
@ -419,8 +425,9 @@ void
|
|||
replace()
|
||||
{
|
||||
EDITSELMP;
|
||||
loop(x, ssize) loop(y, ssize)
|
||||
{
|
||||
|
||||
for (int x = 0; x < ssize; x++) {
|
||||
for (int y = 0; y < ssize; y++) {
|
||||
struct sqr *s = S(x, y);
|
||||
switch (lasttype) {
|
||||
case 0:
|
||||
|
@ -441,6 +448,8 @@ replace()
|
|||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct block b = { 0, 0, ssize, ssize };
|
||||
remip(&b, 0);
|
||||
}
|
||||
|
@ -455,12 +464,14 @@ void
|
|||
edittype(int type)
|
||||
{
|
||||
EDITSEL;
|
||||
|
||||
if (type == CORNER &&
|
||||
(sel.xs != sel.ys || sel.xs == 3 || (sel.xs > 4 && sel.xs != 8) ||
|
||||
sel.x & ~-sel.xs || sel.y & ~-sel.ys)) {
|
||||
conoutf(@"corner selection must be power of 2 aligned");
|
||||
return;
|
||||
}
|
||||
|
||||
edittypexy(type, &sel);
|
||||
addmsg(1, 6, SV_EDITS, sel.x, sel.y, sel.xs, sel.ys, type);
|
||||
}
|
||||
|
@ -509,8 +520,10 @@ editequalisexy(bool isfloor, const struct block *sel)
|
|||
void
|
||||
equalize(int flr)
|
||||
{
|
||||
bool isfloor = flr == 0;
|
||||
bool isfloor = (flr == 0);
|
||||
|
||||
EDITSEL;
|
||||
|
||||
editequalisexy(isfloor, &sel);
|
||||
addmsg(1, 6, SV_EDITE, sel.x, sel.y, sel.xs, sel.ys, isfloor);
|
||||
}
|
||||
|
@ -527,6 +540,7 @@ void
|
|||
setvdelta(int delta)
|
||||
{
|
||||
EDITSEL;
|
||||
|
||||
setvdeltaxy(delta, &sel);
|
||||
addmsg(1, 6, SV_EDITD, sel.x, sel.y, sel.xs, sel.ys, delta);
|
||||
}
|
||||
|
@ -540,7 +554,9 @@ archvertex(int span, int vert, int delta)
|
|||
{
|
||||
if (!archvinit) {
|
||||
archvinit = true;
|
||||
loop(s, MAXARCHVERT) loop(v, MAXARCHVERT) archverts[s][v] = 0;
|
||||
for (int s = 0; s < MAXARCHVERT; s++)
|
||||
for (int v = 0; v < MAXARCHVERT; v++)
|
||||
archverts[s][v] = 0;
|
||||
}
|
||||
if (span >= MAXARCHVERT || vert >= MAXARCHVERT || span < 0 || vert < 0)
|
||||
return;
|
||||
|
@ -551,12 +567,15 @@ void
|
|||
arch(int sidedelta, int _a)
|
||||
{
|
||||
EDITSELMP;
|
||||
|
||||
sel.xs++;
|
||||
sel.ys++;
|
||||
|
||||
if (sel.xs > MAXARCHVERT)
|
||||
sel.xs = MAXARCHVERT;
|
||||
if (sel.ys > MAXARCHVERT)
|
||||
sel.ys = MAXARCHVERT;
|
||||
|
||||
struct block *sel_ = &sel;
|
||||
// Ugly hack to make the macro work.
|
||||
struct block *sel = sel_;
|
||||
|
@ -572,13 +591,16 @@ void
|
|||
slope(int xd, int yd)
|
||||
{
|
||||
EDITSELMP;
|
||||
|
||||
int off = 0;
|
||||
if (xd < 0)
|
||||
off -= xd * sel.xs;
|
||||
if (yd < 0)
|
||||
off -= yd * sel.ys;
|
||||
|
||||
sel.xs++;
|
||||
sel.ys++;
|
||||
|
||||
struct block *sel_ = &sel;
|
||||
// Ugly hack to make the macro work.
|
||||
struct block *sel = sel_;
|
||||
|
@ -590,15 +612,22 @@ void
|
|||
perlin(int scale, int seed, int psize)
|
||||
{
|
||||
EDITSELMP;
|
||||
|
||||
sel.xs++;
|
||||
sel.ys++;
|
||||
|
||||
makeundo();
|
||||
|
||||
sel.xs--;
|
||||
sel.ys--;
|
||||
|
||||
perlinarea(&sel, scale, seed, psize);
|
||||
|
||||
sel.xs++;
|
||||
sel.ys++;
|
||||
|
||||
remipmore(&sel, 0);
|
||||
|
||||
sel.xs--;
|
||||
sel.ys--;
|
||||
}
|
||||
|
@ -607,13 +636,15 @@ VARF(
|
|||
fullbright, 0, 0, 1, if (fullbright) {
|
||||
if (noteditmode())
|
||||
return;
|
||||
loopi(mipsize) world[i].r = world[i].g = world[i].b = 176;
|
||||
for (int i = 0; i < mipsize; i++)
|
||||
world[i].r = world[i].g = world[i].b = 176;
|
||||
});
|
||||
|
||||
void
|
||||
edittag(int tag)
|
||||
{
|
||||
EDITSELMP;
|
||||
|
||||
struct block *sel_ = &sel;
|
||||
// Ugly hack to make the macro work.
|
||||
struct block *sel = sel_;
|
||||
|
@ -624,6 +655,7 @@ void
|
|||
newent(OFString *what, OFString *a1, OFString *a2, OFString *a3, OFString *a4)
|
||||
{
|
||||
EDITSEL;
|
||||
|
||||
newentity(sel.x, sel.y, (int)player1.origin.z, what,
|
||||
[a1 cube_intValueWithBase:0], [a2 cube_intValueWithBase:0],
|
||||
[a3 cube_intValueWithBase:0], [a4 cube_intValueWithBase:0]);
|
||||
|
|
|
@ -61,8 +61,7 @@ rendermenu()
|
|||
title = m.name;
|
||||
int mdisp = m.items.count;
|
||||
int w = 0;
|
||||
loopi(mdisp)
|
||||
{
|
||||
for (int i = 0; i < mdisp; i++) {
|
||||
int x = text_width(m.items[i].text);
|
||||
if (x > w)
|
||||
w = x;
|
||||
|
@ -83,8 +82,7 @@ rendermenu()
|
|||
blendbox(
|
||||
x - FONTH, bh - 10, x + w + FONTH, bh + FONTH + 10, false);
|
||||
}
|
||||
loopj(mdisp)
|
||||
{
|
||||
for (int j = 0; j < mdisp; j++) {
|
||||
draw_text(m.items[j].text, x, y, 2);
|
||||
y += step;
|
||||
}
|
||||
|
|
|
@ -358,8 +358,8 @@ moveplayer4(DynamicEntity *pl, int moveres, bool local, int curtime)
|
|||
// extra smoothness when lifting up stairs
|
||||
const float rise = speed / moveres / 1.2f;
|
||||
|
||||
loopi(moveres) // discrete steps collision detection & sliding
|
||||
{
|
||||
// discrete steps collision detection & sliding
|
||||
for (int i = 0; i < moveres; i++) {
|
||||
// try move forward
|
||||
pl.origin = OFAddVector3D(pl.origin,
|
||||
OFMakeVector3D(f * d.x, f * d.y, f * d.z));
|
||||
|
@ -441,7 +441,9 @@ moveplayer4(DynamicEntity *pl, int moveres, bool local, int curtime)
|
|||
void
|
||||
moveplayer(DynamicEntity *pl, int moveres, bool local)
|
||||
{
|
||||
loopi(physicsrepeat) moveplayer4(pl, moveres, local,
|
||||
for (int i = 0; i < physicsrepeat; i++)
|
||||
moveplayer4(pl, moveres, local,
|
||||
i ? curtime / physicsrepeat
|
||||
: curtime - curtime / physicsrepeat * (physicsrepeat - 1));
|
||||
: curtime -
|
||||
curtime / physicsrepeat * (physicsrepeat - 1));
|
||||
}
|
||||
|
|
|
@ -95,8 +95,7 @@ void
|
|||
newsphere(const OFVector3D *o, float max, int type)
|
||||
{
|
||||
if (!sinit) {
|
||||
loopi(MAXSPHERES)
|
||||
{
|
||||
for (int i = 0; i < MAXSPHERES; i++) {
|
||||
spheres[i].next = sempty;
|
||||
sempty = &spheres[i];
|
||||
}
|
||||
|
@ -218,8 +217,7 @@ loadsky(OFString *basename)
|
|||
static const OFString *side[] = { @"ft", @"bk", @"lf", @"rt", @"dn",
|
||||
@"up" };
|
||||
int texnum = 14;
|
||||
loopi(6)
|
||||
{
|
||||
for (int i = 0; i < 6; i++) {
|
||||
OFString *path = [OFString
|
||||
stringWithFormat:@"packages/%@_%@.jpg", basename, side[i]];
|
||||
|
||||
|
|
|
@ -112,8 +112,7 @@ installtex(int tnum, OFIRI *IRI, int *xs, int *ys, bool clamp)
|
|||
}
|
||||
|
||||
#if 0
|
||||
loopi(s->w * s->h * 3)
|
||||
{
|
||||
for (int i = 0; i < s->w * s->h * 3; i++) {
|
||||
uchar *p = (uchar *)s->pixels + i;
|
||||
*p = 255 - *p;
|
||||
}
|
||||
|
@ -179,7 +178,9 @@ static OFString *mapname[256][MAXFRAMES];
|
|||
void
|
||||
purgetextures()
|
||||
{
|
||||
loopi(256) loop(j, MAXFRAMES) mapping[i][j] = 0;
|
||||
for (int i = 0; i < 256; i++)
|
||||
for (int j = 0; j < MAXFRAMES; j++)
|
||||
mapping[i][j] = 0;
|
||||
}
|
||||
|
||||
int curtexnum = 0;
|
||||
|
@ -221,8 +222,8 @@ lookuptexture(int tex, int *xs, int *ys)
|
|||
if (tid == 0)
|
||||
return 1; // crosshair :)
|
||||
|
||||
loopi(curtex) // lazily happens once per "texture" command, basically
|
||||
{
|
||||
// lazily happens once per "texture" command, basically
|
||||
for (int i = 0; i < curtex; i++) {
|
||||
if ([mapname[tex][frame] isEqual:texname[i]]) {
|
||||
mapping[tex][frame] = tid = i + FIRSTTEX;
|
||||
*xs = texx[i];
|
||||
|
|
|
@ -21,8 +21,7 @@ static void
|
|||
newparticle(const OFVector3D *o, const OFVector3D *d, int fade, int type)
|
||||
{
|
||||
if (!parinit) {
|
||||
loopi(MAXPARTICLES)
|
||||
{
|
||||
for (int i = 0; i < MAXPARTICLES; i++) {
|
||||
particles[i].next = parempty;
|
||||
parempty = &particles[i];
|
||||
}
|
||||
|
@ -138,8 +137,7 @@ render_particles(int time)
|
|||
void
|
||||
particle_splash(int type, int num, int fade, const OFVector3D *p)
|
||||
{
|
||||
loopi(num)
|
||||
{
|
||||
for (int i = 0; i < num; i++) {
|
||||
const int radius = type == 5 ? 50 : 150;
|
||||
int x, y, z;
|
||||
do {
|
||||
|
@ -158,8 +156,7 @@ particle_trail(int type, int fade, const OFVector3D *s, const OFVector3D *e)
|
|||
vdist(d, v, *s, *e);
|
||||
vdiv(v, d * 2 + 0.1f);
|
||||
OFVector3D p = *s;
|
||||
loopi((int)d * 2)
|
||||
{
|
||||
for (int i = 0; i < ((int)d * 2); i++) {
|
||||
vadd(p, v);
|
||||
OFVector3D d =
|
||||
OFMakeVector3D(rnd(11) - 5, rnd(11) - 5, rnd(11) - 5);
|
||||
|
|
|
@ -245,13 +245,14 @@ loadgamerest()
|
|||
[Monster restoreAll];
|
||||
|
||||
int nplayers = gzgeti();
|
||||
loopi(nplayers) if (!gzget())
|
||||
{
|
||||
for (int i = 0; i < nplayers; i++) {
|
||||
if (!gzget()) {
|
||||
DynamicEntity *d = getclient(i);
|
||||
assert(d);
|
||||
gzread(f, data.mutableItems, data.count);
|
||||
[d setFromSerializedData:data];
|
||||
}
|
||||
}
|
||||
|
||||
conoutf(@"savegame restored");
|
||||
if (demoloading)
|
||||
|
@ -321,7 +322,8 @@ incomingdemodata(uchar *buf, int len, bool extras)
|
|||
gzputi(player1.health);
|
||||
gzputi(player1.armour);
|
||||
gzput(player1.armourType);
|
||||
loopi(NUMGUNS) gzput(player1.ammo[i]);
|
||||
for (int i = 0; i < NUMGUNS; i++)
|
||||
gzput(player1.ammo[i]);
|
||||
gzput(player1.state);
|
||||
gzputi(bdamage);
|
||||
bdamage = 0;
|
||||
|
@ -448,7 +450,8 @@ demoplaybackstep()
|
|||
target.health = gzgeti();
|
||||
target.armour = gzgeti();
|
||||
target.armourType = gzget();
|
||||
loopi(NUMGUNS) target.ammo[i] = gzget();
|
||||
for (int i = 0; i < NUMGUNS; i++)
|
||||
target.ammo[i] = gzget();
|
||||
target.state = gzget();
|
||||
target.lastMove = playbacktime;
|
||||
if ((bdamage = gzgeti()))
|
||||
|
|
|
@ -253,7 +253,8 @@ process(ENetPacket *packet, int sender) // sender may be -1
|
|||
}
|
||||
int size = msgsizelookup(type);
|
||||
assert(size != -1);
|
||||
loopi(size - 2) getint(&p);
|
||||
for (int i = 0; i < size - 2; i++)
|
||||
getint(&p);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -280,7 +281,8 @@ process(ENetPacket *packet, int sender) // sender may be -1
|
|||
disconnect_client(sender, @"tag type");
|
||||
return;
|
||||
}
|
||||
loopi(size - 1) getint(&p);
|
||||
for (int i = 0; i < size - 1; i++)
|
||||
getint(&p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -546,7 +548,8 @@ initserver(bool dedicated, int uprate, OFString *sdesc, OFString *ip,
|
|||
serverhost = enet_host_create(&address, MAXCLIENTS, 0, uprate);
|
||||
if (!serverhost)
|
||||
fatal(@"could not create server host\n");
|
||||
loopi(MAXCLIENTS) serverhost->peers[i].data = (void *)-1;
|
||||
for (int i = 0; i < MAXCLIENTS; i++)
|
||||
serverhost->peers[i].data = (void *)-1;
|
||||
}
|
||||
|
||||
resetserverifempty();
|
||||
|
|
|
@ -146,13 +146,15 @@ updatevol()
|
|||
{
|
||||
if (nosound)
|
||||
return;
|
||||
loopi(MAXCHAN) if (soundlocs[i].inuse)
|
||||
{
|
||||
|
||||
for (int i = 0; i < MAXCHAN; i++) {
|
||||
if (soundlocs[i].inuse) {
|
||||
if (Mix_Playing(i))
|
||||
updatechanvol(i, &soundlocs[i].loc);
|
||||
else
|
||||
soundlocs[i].inuse = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -32,13 +32,9 @@ typedef unsigned int uint;
|
|||
#define rndreset() (srand(1))
|
||||
#define rndtime() \
|
||||
{ \
|
||||
loopi(lastmillis & 0xF) rnd(i + 1); \
|
||||
for (int i = 0; i < (lastmillis & 0xF); i++) \
|
||||
rnd(i + 1); \
|
||||
}
|
||||
#define loop(v, m) for (int v = 0; v < (m); v++)
|
||||
#define loopi(m) loop(i, m)
|
||||
#define loopj(m) loop(j, m)
|
||||
#define loopk(m) loop(k, m)
|
||||
#define loopl(m) loop(l, m)
|
||||
|
||||
#ifndef OF_WINDOWS
|
||||
# define __cdecl
|
||||
|
|
|
@ -10,11 +10,13 @@ endianswap(
|
|||
{
|
||||
if (*((char *)&stride))
|
||||
return;
|
||||
loop(w, length) loop(i, stride / 2)
|
||||
{
|
||||
|
||||
for (int w = 0; w < length; w++) {
|
||||
for (int i = 0; i < stride / 2; i++) {
|
||||
uchar *p = (uchar *)memory + w * stride;
|
||||
uchar t = p[i];
|
||||
p[i] = p[stride - i - 1];
|
||||
p[stride - i - 1] = t;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
14
src/weapon.m
14
src/weapon.m
|
@ -77,8 +77,7 @@ createrays(const OFVector3D *from, const OFVector3D *to)
|
|||
{
|
||||
vdist(dist, dvec, *from, *to);
|
||||
float f = dist * SGSPREAD / 1000;
|
||||
loopi(SGRAYS)
|
||||
{
|
||||
for (int i = 0; i < SGRAYS; i++) {
|
||||
#define RNDD (rnd(101) - 50) * f
|
||||
OFVector3D r = OFMakeVector3D(RNDD, RNDD, RNDD);
|
||||
sg[i] = *to;
|
||||
|
@ -168,7 +167,7 @@ newprojectile(const OFVector3D *from, const OFVector3D *to, float speed,
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
hit(int target, int damage, __kindof DynamicEntity *d, DynamicEntity *at)
|
||||
{
|
||||
OFVector3D o = d.origin;
|
||||
|
@ -205,7 +204,7 @@ radialeffect(
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
splash(Projectile *p, const OFVector3D *v, const OFVector3D *vold,
|
||||
int notthisplayer, int notthismonster, int qdam)
|
||||
{
|
||||
|
@ -322,7 +321,8 @@ shootv(int gun, const OFVector3D *from, const OFVector3D *to, DynamicEntity *d,
|
|||
break;
|
||||
|
||||
case GUN_SG: {
|
||||
loopi(SGRAYS) particle_splash(0, 5, 200, &sg[i]);
|
||||
for (int i = 0; i < SGRAYS; i++)
|
||||
particle_splash(0, 5, 200, &sg[i]);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -371,7 +371,9 @@ raydamage(DynamicEntity *o, const OFVector3D *from, const OFVector3D *to,
|
|||
qdam /= MONSTERDAMAGEFACTOR;
|
||||
if (d.gunSelect == GUN_SG) {
|
||||
int damage = 0;
|
||||
loop(r, SGRAYS) if (intersect(o, from, &sg[r])) damage += qdam;
|
||||
for (int r = 0; r < SGRAYS; r++)
|
||||
if (intersect(o, from, &sg[r]))
|
||||
damage += qdam;
|
||||
if (damage)
|
||||
hitpush(i, damage, o, d, from, to);
|
||||
} else if (intersect(o, from, to))
|
||||
|
|
115
src/world.m
115
src/world.m
|
@ -19,18 +19,19 @@ void
|
|||
settag(int tag, int type)
|
||||
{
|
||||
int maxx = 0, maxy = 0, minx = ssize, miny = ssize;
|
||||
loop(x, ssize) loop(y, ssize)
|
||||
{
|
||||
for (int x = 0; x < ssize; x++) {
|
||||
for (int y = 0; y < ssize; y++) {
|
||||
struct sqr *s = S(x, y);
|
||||
|
||||
if (s->tag) {
|
||||
if (tag) {
|
||||
if (tag == s->tag)
|
||||
s->type = SPACE;
|
||||
else
|
||||
continue;
|
||||
} else {
|
||||
} else
|
||||
s->type = type ? SOLID : SPACE;
|
||||
}
|
||||
|
||||
if (x > maxx)
|
||||
maxx = x;
|
||||
if (y > maxy)
|
||||
|
@ -41,16 +42,24 @@ settag(int tag, int type)
|
|||
miny = y;
|
||||
}
|
||||
}
|
||||
struct block b = { minx, miny, maxx - minx + 1, maxy - miny + 1 };
|
||||
if (maxx)
|
||||
remip(&b, 0); // remip minimal area of changed geometry
|
||||
}
|
||||
|
||||
if (maxx) {
|
||||
// remip minimal area of changed geometry
|
||||
struct block b = { minx, miny, maxx - minx + 1,
|
||||
maxy - miny + 1 };
|
||||
remip(&b, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// reset for editing or map saving
|
||||
void
|
||||
resettagareas()
|
||||
{
|
||||
settag(0, 0);
|
||||
} // reset for editing or map saving
|
||||
}
|
||||
|
||||
// set for playing
|
||||
void
|
||||
settagareas()
|
||||
{
|
||||
|
@ -60,7 +69,7 @@ settagareas()
|
|||
if (ents[i].type == CARROT)
|
||||
setspawn(i, true);
|
||||
}];
|
||||
} // set for playing
|
||||
}
|
||||
|
||||
void
|
||||
trigger(int tag, int type, bool savegame)
|
||||
|
@ -123,43 +132,57 @@ remip(const struct block *b, int level)
|
|||
struct sqr *r = SWS(v, x / 2, y / 2, vs);
|
||||
*r = *o[0];
|
||||
uchar nums[MAXTYPE];
|
||||
loopi(MAXTYPE) nums[i] = 0;
|
||||
loopj(4) nums[o[j]->type]++;
|
||||
for (int i = 0; i < MAXTYPE; i++)
|
||||
nums[i] = 0;
|
||||
for (int j = 0; j < 4; j++)
|
||||
nums[o[j]->type]++;
|
||||
// cube contains both solid and space, treated
|
||||
// specially in the renderer
|
||||
r->type = SEMISOLID;
|
||||
loopk(MAXTYPE) if (nums[k] == 4) r->type = k;
|
||||
for (int k = 0; k < MAXTYPE; k++)
|
||||
if (nums[k] == 4)
|
||||
r->type = k;
|
||||
if (!SOLID(r)) {
|
||||
int floor = 127, ceil = -128;
|
||||
loopi(4) if (!SOLID(o[i]))
|
||||
{
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (!SOLID(o[i])) {
|
||||
int fh = o[i]->floor;
|
||||
int ch = o[i]->ceil;
|
||||
if (r->type == SEMISOLID) {
|
||||
if (o[i]->type == FHF)
|
||||
// crap hack, needed
|
||||
// for rendering large
|
||||
// mips next to hfs
|
||||
fh -= o[i]->vdelta / 4 +
|
||||
// crap hack,
|
||||
// needed for
|
||||
// rendering
|
||||
// large mips
|
||||
// next to hfs
|
||||
fh -=
|
||||
o[i]->vdelta /
|
||||
4 +
|
||||
2;
|
||||
if (o[i]->type == CHF)
|
||||
// FIXME: needs to
|
||||
// somehow take into
|
||||
// account middle
|
||||
// vertices on higher
|
||||
// mips
|
||||
ch += o[i]->vdelta / 4 +
|
||||
// FIXME: needs
|
||||
// to somehow
|
||||
// take into
|
||||
// account
|
||||
// middle
|
||||
// vertices on
|
||||
// higher mips
|
||||
ch +=
|
||||
o[i]->vdelta /
|
||||
4 +
|
||||
2;
|
||||
}
|
||||
if (fh < floor)
|
||||
// take lowest floor and
|
||||
// highest ceil, so we never
|
||||
// have to see missing
|
||||
// lower/upper from the side
|
||||
// highest ceil, so we
|
||||
// never have to see
|
||||
// missing lower/upper
|
||||
// from the side
|
||||
floor = fh;
|
||||
if (ch > ceil)
|
||||
ceil = ch;
|
||||
}
|
||||
}
|
||||
r->floor = floor;
|
||||
r->ceil = ceil;
|
||||
}
|
||||
|
@ -169,8 +192,7 @@ remip(const struct block *b, int level)
|
|||
goto mip;
|
||||
r->defer = 1;
|
||||
if (SOLID(r)) {
|
||||
loopi(3)
|
||||
{
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (o[i]->wtex != o[3]->wtex)
|
||||
// on an all solid cube, only
|
||||
// thing that needs to be equal
|
||||
|
@ -179,8 +201,7 @@ remip(const struct block *b, int level)
|
|||
goto c;
|
||||
}
|
||||
} else {
|
||||
loopi(3)
|
||||
{
|
||||
for (int i = 0; i < 3; i++) {
|
||||
// perfect mip even if light is not
|
||||
// exactly equal
|
||||
if (o[i]->type != o[3]->type ||
|
||||
|
@ -228,7 +249,9 @@ remip(const struct block *b, int level)
|
|||
{
|
||||
// if any of the constituents is not perfect,
|
||||
// then this one isn't either
|
||||
loopi(4) if (o[i]->defer) goto c;
|
||||
for (int i = 0; i < 4; i++)
|
||||
if (o[i]->defer)
|
||||
goto c;
|
||||
}
|
||||
mip:
|
||||
r->defer = 0;
|
||||
|
@ -322,7 +345,9 @@ delent()
|
|||
int
|
||||
findtype(OFString *what)
|
||||
{
|
||||
loopi(MAXENTTYPES) if ([what isEqual:entnames[i]]) return i;
|
||||
for (int i = 0; i < MAXENTTYPES; i++)
|
||||
if ([what isEqual:entnames[i]])
|
||||
return i;
|
||||
conoutf(@"unknown entity type \"%@\"", what);
|
||||
return NOTUSED;
|
||||
}
|
||||
|
@ -428,7 +453,9 @@ findentity(int type, int index)
|
|||
for (int i = index; i < ents.count; i++)
|
||||
if (ents[i].type == type)
|
||||
return i;
|
||||
loopj(index) if (ents[j].type == type) return j;
|
||||
for (int j = 0; j < index; j++)
|
||||
if (ents[j].type == type)
|
||||
return j;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -442,8 +469,7 @@ setupworld(int factor)
|
|||
mipsize = cubicsize * 134 / 100;
|
||||
struct sqr *w = world =
|
||||
OFAllocZeroedMemory(mipsize, sizeof(struct sqr));
|
||||
loopi(LARGEST_FACTOR * 2)
|
||||
{
|
||||
for (int i = 0; i < LARGEST_FACTOR * 2; i++) {
|
||||
wmip[i] = w;
|
||||
w += cubicsize >> (i * 2);
|
||||
}
|
||||
|
@ -470,8 +496,8 @@ empty_world(int factor, bool force)
|
|||
factor = LARGEST_FACTOR;
|
||||
setupworld(factor);
|
||||
|
||||
loop(x, ssize) loop(y, ssize)
|
||||
{
|
||||
for (int x = 0; x < ssize; x++) {
|
||||
for (int y = 0; y < ssize; y++) {
|
||||
struct sqr *s = S(x, y);
|
||||
s->r = s->g = s->b = 150;
|
||||
s->ftex = DEFAULT_FLOOR;
|
||||
|
@ -483,6 +509,7 @@ empty_world(int factor, bool force)
|
|||
s->vdelta = 0;
|
||||
s->defer = 0;
|
||||
}
|
||||
}
|
||||
|
||||
strncpy(hdr.head, "CUBE", 4);
|
||||
hdr.version = MAPVERSION;
|
||||
|
@ -490,11 +517,12 @@ empty_world(int factor, bool force)
|
|||
hdr.sfactor = sfactor;
|
||||
|
||||
if (copy) {
|
||||
loop(x, ssize / 2) loop(y, ssize / 2)
|
||||
{
|
||||
for (int x = 0; x < ssize / 2; x++) {
|
||||
for (int y = 0; y < ssize / 2; y++) {
|
||||
*S(x + ssize / 4, y + ssize / 4) =
|
||||
*SWS(oldworld, x, y, ssize / 2);
|
||||
}
|
||||
}
|
||||
|
||||
for (Entity *e in ents) {
|
||||
e.x += ssize / 4;
|
||||
|
@ -504,8 +532,11 @@ empty_world(int factor, bool force)
|
|||
char buffer[128] = "Untitled Map by Unknown";
|
||||
memcpy(hdr.maptitle, buffer, 128);
|
||||
hdr.waterlevel = -100000;
|
||||
loopi(15) hdr.reserved[i] = 0;
|
||||
loopk(3) loopi(256) hdr.texlists[k][i] = i;
|
||||
for (int i = 0; i < 15; i++)
|
||||
hdr.reserved[i] = 0;
|
||||
for (int k = 0; k < 3; k++)
|
||||
for (int i = 0; i < 256; i++)
|
||||
hdr.texlists[k][i] = i;
|
||||
[ents removeAllObjects];
|
||||
struct block b = { 8, 8, ssize - 16, ssize - 16 };
|
||||
edittypexy(SPACE, &b);
|
||||
|
|
|
@ -61,9 +61,10 @@ nhf(struct sqr *s)
|
|||
void
|
||||
voptimize() // reset vdeltas on non-hf cubes
|
||||
{
|
||||
loop(x, ssize) loop(y, ssize)
|
||||
{
|
||||
for (int x = 0; x < ssize; x++) {
|
||||
for (int y = 0; y < ssize; y++) {
|
||||
struct sqr *s = S(x, y);
|
||||
|
||||
if (x && y) {
|
||||
if (nhf(s) && nhf(S(x - 1, y)) &&
|
||||
nhf(S(x - 1, y - 1)) && nhf(S(x, y - 1)))
|
||||
|
@ -71,6 +72,7 @@ voptimize() // reset vdeltas on non-hf cubes
|
|||
} else
|
||||
s->vdelta = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -84,16 +86,17 @@ topt(struct sqr *s, bool *wf, bool *uf, int *wt, int *ut)
|
|||
*wf = true;
|
||||
*uf = true;
|
||||
if (SOLID(s)) {
|
||||
loopi(4) if (!SOLID(o[i]))
|
||||
{
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (!SOLID(o[i])) {
|
||||
*wf = false;
|
||||
*wt = s->wtex;
|
||||
*ut = s->utex;
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
loopi(4) if (!SOLID(o[i]))
|
||||
{
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (!SOLID(o[i])) {
|
||||
if (o[i]->floor < s->floor) {
|
||||
*wt = s->wtex;
|
||||
*wf = false;
|
||||
|
@ -104,6 +107,7 @@ topt(struct sqr *s, bool *wf, bool *uf, int *wt, int *ut)
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -122,8 +126,7 @@ toptimize() // FIXME: only does 2x2, make atleast for 4x4 also
|
|||
&ut);
|
||||
topt(s[3] = SWS(s[0], 1, 0, ssize), &wf[3], &uf[3], &wt,
|
||||
&ut);
|
||||
loopi(4)
|
||||
{
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (wf[i])
|
||||
s[i]->wtex = wt;
|
||||
if (uf[i])
|
||||
|
@ -210,8 +213,7 @@ save_world(OFString *mname)
|
|||
sc = 0; \
|
||||
} \
|
||||
}
|
||||
loopk(cubicsize)
|
||||
{
|
||||
for (int k = 0; k < cubicsize; k++) {
|
||||
struct sqr *s = &world[k];
|
||||
#define c(f) (s->f == t->f)
|
||||
// 4 types of blocks, to compress a bit:
|
||||
|
@ -285,8 +287,7 @@ load_world(OFString *mname) // still supports all map formats that have existed
|
|||
hdr.waterlevel = -100000;
|
||||
}
|
||||
[ents removeAllObjects];
|
||||
loopi(hdr.numents)
|
||||
{
|
||||
for (int i = 0; i < hdr.numents; i++) {
|
||||
struct persistent_entity tmp;
|
||||
gzread(f, &tmp, sizeof(struct persistent_entity));
|
||||
endianswap(&tmp, sizeof(short), 4);
|
||||
|
@ -312,10 +313,10 @@ load_world(OFString *mname) // still supports all map formats that have existed
|
|||
free(world);
|
||||
setupworld(hdr.sfactor);
|
||||
char texuse[256];
|
||||
loopi(256) texuse[i] = 0;
|
||||
for (int i = 0; i < 256; i++)
|
||||
texuse[i] = 0;
|
||||
struct sqr *t = NULL;
|
||||
loopk(cubicsize)
|
||||
{
|
||||
for (int k = 0; k < cubicsize; k++) {
|
||||
struct sqr *s = &world[k];
|
||||
int type = gzgetc(f);
|
||||
switch (type) {
|
||||
|
@ -382,13 +383,14 @@ load_world(OFString *mname) // still supports all map formats that have existed
|
|||
calclight();
|
||||
settagareas();
|
||||
int xs, ys;
|
||||
loopi(256) if (texuse[i]) lookuptexture(i, &xs, &ys);
|
||||
for (int i = 0; i < 256; i++)
|
||||
if (texuse[i])
|
||||
lookuptexture(i, &xs, &ys);
|
||||
conoutf(@"read map %@ (%d milliseconds)", cgzname,
|
||||
SDL_GetTicks() - lastmillis);
|
||||
conoutf(@"%s", hdr.maptitle);
|
||||
startmap(mname);
|
||||
loopl(256)
|
||||
{
|
||||
for (int l = 0; l < 256; l++) {
|
||||
// can this be done smarter?
|
||||
OFString *aliasname =
|
||||
[OFString stringWithFormat:@"level_trigger_%d", l];
|
||||
|
|
|
@ -61,8 +61,7 @@ lightray(float bx, float by, Entity *light)
|
|||
stepg /= lightscale;
|
||||
b /= lightscale;
|
||||
stepb /= lightscale;
|
||||
loopi(steps)
|
||||
{
|
||||
for (int i = 0; i < steps; i++) {
|
||||
struct sqr *s = S(x >> PRECBITS, y >> PRECBITS);
|
||||
int tl = (l >> PRECBITS) + s->r;
|
||||
s->r = tl > 255 ? 255 : tl;
|
||||
|
@ -90,8 +89,7 @@ lightray(float bx, float by, Entity *light)
|
|||
if (OUTBORD(x >> PRECBITS, y >> PRECBITS))
|
||||
return;
|
||||
|
||||
loopi(steps)
|
||||
{
|
||||
for (int i = 0; i < steps; i++) {
|
||||
struct sqr *s = S(x >> PRECBITS, y >> PRECBITS);
|
||||
int tl = (l >> PRECBITS) + s->r;
|
||||
s->r = s->g = s->b = tl > 255 ? 255 : tl;
|
||||
|
@ -106,8 +104,7 @@ lightray(float bx, float by, Entity *light)
|
|||
} else // the old (white) light code, here for the few people with old
|
||||
// video cards that don't support overbright
|
||||
{
|
||||
loopi(steps)
|
||||
{
|
||||
for (int i = 0; i < steps; i++) {
|
||||
struct sqr *s = S(x >> PRECBITS, y >> PRECBITS);
|
||||
int light = l >> PRECBITS;
|
||||
if (light > s->r)
|
||||
|
@ -150,8 +147,9 @@ calclightsource(Entity *l)
|
|||
void
|
||||
postlightarea(const struct block *a)
|
||||
{
|
||||
loop(x, a->xs) loop(y, a->ys) // assumes area not on edge of world
|
||||
{
|
||||
// assumes area not on edge of world
|
||||
for (int x = 0; x < a->xs; x++)
|
||||
for (int y = 0; y < a->ys; y++) {
|
||||
struct sqr *s = S(x + a->x, y + a->y);
|
||||
#define median(m) \
|
||||
s->m = \
|
||||
|
@ -170,11 +168,12 @@ postlightarea(const struct block *a)
|
|||
void
|
||||
calclight()
|
||||
{
|
||||
loop(x, ssize) loop(y, ssize)
|
||||
{
|
||||
for (int x = 0; x < ssize; x++) {
|
||||
for (int y = 0; y < ssize; y++) {
|
||||
struct sqr *s = S(x, y);
|
||||
s->r = s->g = s->b = 10;
|
||||
}
|
||||
}
|
||||
|
||||
for (Entity *e in ents)
|
||||
if (e.type == LIGHT)
|
||||
|
|
|
@ -33,8 +33,7 @@ computeraytable(float vx, float vy)
|
|||
float byaw = (player1.yaw - 90 + af) / 360 * PI2;
|
||||
float syaw = (player1.yaw - 90 - af) / 360 * PI2;
|
||||
|
||||
loopi(NUMRAYS)
|
||||
{
|
||||
for (int i = 0; i < NUMRAYS; i++) {
|
||||
float angle = i * PI2 / NUMRAYS;
|
||||
if ((apitch > 45 // must be bigger if fov>120
|
||||
|| (angle < byaw && angle > syaw) ||
|
||||
|
|
|
@ -318,7 +318,8 @@ void
|
|||
render_world(
|
||||
float vx, float vy, float vh, int yaw, int pitch, float fov, int w, int h)
|
||||
{
|
||||
loopi(LARGEST_FACTOR) stats[i] = 0;
|
||||
for (int i = 0; i < LARGEST_FACTOR; i++)
|
||||
stats[i] = 0;
|
||||
min_lod = MIN_LOD + abs(pitch) / 12;
|
||||
yaw = 360 - yaw;
|
||||
float widef = fov / 75.0f;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue