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