More style cleanup

FossilOrigin-Name: 753ff34122c906fdba43b8c382ac52cc9f0ac3ce585ec9f4db6b1dc1f21ef86a
This commit is contained in:
Jonathan Schleifer 2025-03-08 03:05:16 +00:00
parent dd08a1069e
commit a28209edcf
27 changed files with 525 additions and 539 deletions

View file

@ -21,6 +21,8 @@ AlwaysBreakAfterReturnType: AllDefinitions
AlignAfterOpenBracket: DontAlign AlignAfterOpenBracket: DontAlign
AlignEscapedNewlines: Left AlignEscapedNewlines: Left
AlignOperands: DontAlign AlignOperands: DontAlign
Cpp11BracedListStyle: false
SpaceBeforeCpp11BracedList: true
ObjCBlockIndentWidth: 8 ObjCBlockIndentWidth: 8
ObjCSpaceAfterProperty: true ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: true ObjCSpaceBeforeProtocolList: true
@ -34,6 +36,7 @@ ObjCPropertyAttributeOrder: [
] ]
SpaceBeforeInheritanceColon: false SpaceBeforeInheritanceColon: false
QualifierAlignment: Left QualifierAlignment: Left
MaxEmptyLinesToKeep: 1
#RemoveEmptyLinesInUnwrappedLines: true #RemoveEmptyLinesInUnwrappedLines: true
RemoveSemicolon: true RemoveSemicolon: true
CompactNamespaces: true CompactNamespaces: true

View file

@ -29,15 +29,18 @@ VARP(minmillis, 0, 5, 1000);
#define log(s) conoutf(@"init: %@", s) #define log(s) conoutf(@"init: %@", s)
log(@"sdl"); log(@"sdl");
const OFOptionsParserOption options[] = { const OFOptionsParserOption options[] = { { 'd', @"dedicated", 0,
{'d', @"dedicated", 0, &dedicated, NULL}, &dedicated, NULL },
{ 't', @"window", 0, &windowed, NULL }, { 't', @"window", 0, &windowed, NULL },
{'w', @"width", 1, NULL, NULL}, {'h', @"height", 1, NULL, NULL}, { 'w', @"width", 1, NULL, NULL },
{ 'h', @"height", 1, NULL, NULL },
{ 'u', @"upload-rate", 1, NULL, NULL }, { 'u', @"upload-rate", 1, NULL, NULL },
{'n', @"server-desc", 1, NULL, &sdesc}, {'i', @"ip", 1, NULL, &ip}, { 'n', @"server-desc", 1, NULL, &sdesc },
{ 'i', @"ip", 1, NULL, &ip },
{ 'm', @"master", 1, NULL, &master }, { 'm', @"master", 1, NULL, &master },
{ 'p', @"password", 1, NULL, &passwd }, { 'p', @"password", 1, NULL, &passwd },
{'c', @"max-clients", 1, NULL, NULL}, {'\0', nil, 0, NULL, NULL}}; { 'c', @"max-clients", 1, NULL, NULL },
{ '\0', nil, 0, NULL, NULL } };
OFOptionsParser *optionsParser = OFOptionsParser *optionsParser =
[OFOptionsParser parserWithOptions:options]; [OFOptionsParser parserWithOptions:options];
OFUnichar option; OFUnichar option;

View file

@ -120,14 +120,14 @@ disconnect(int onlyclean, int async)
enet_peer_disconnect(clienthost->peers); enet_peer_disconnect(clienthost->peers);
enet_host_flush(clienthost); enet_host_flush(clienthost);
disconnecting = lastmillis; disconnecting = lastmillis;
}; }
if (clienthost->peers->state != ENET_PEER_STATE_DISCONNECTED) { if (clienthost->peers->state != ENET_PEER_STATE_DISCONNECTED) {
if (async) if (async)
return; return;
enet_peer_reset(clienthost->peers); enet_peer_reset(clienthost->peers);
}; }
enet_host_destroy(clienthost); enet_host_destroy(clienthost);
}; }
if (clienthost && !connecting) if (clienthost && !connecting)
conoutf(@"disconnected"); conoutf(@"disconnected");
@ -385,8 +385,8 @@ gets2c() // get updates from the server
conoutf(@"could not connect to server"); conoutf(@"could not connect to server");
disconnect(); disconnect();
return; return;
}; }
}; }
while ( while (
clienthost != NULL && enet_host_service(clienthost, &event, 0) > 0) clienthost != NULL && enet_host_service(clienthost, &event, 0) > 0)
switch (event.type) { switch (event.type) {

View file

@ -8,9 +8,10 @@
// D D D D' D D D D' A A' P P' I I' // D D D D' D D D D' A A' P P' I I'
// R, R' E L J J' // R, R' E L J J'
int frame[] = {178, 184, 190, 137, 183, 189, 197, 164, 46, 51, 54, 32, 0, 0, 40, int frame[] = { 178, 184, 190, 137, 183, 189, 197, 164, 46, 51, 54, 32, 0, 0,
1, 162, 162, 67, 168}; 40, 1, 162, 162, 67, 168 };
int range[] = {6, 6, 8, 28, 1, 1, 1, 1, 8, 19, 4, 18, 40, 1, 6, 15, 1, 1, 1, 1}; int range[] = { 6, 6, 8, 28, 1, 1, 1, 1, 8, 19, 4, 18, 40, 1, 6, 15, 1, 1, 1,
1 };
void void
renderclient(dynent *d, bool team, OFString *mdlname, bool hellpig, float scale) renderclient(dynent *d, bool team, OFString *mdlname, bool hellpig, float scale)
@ -37,8 +38,8 @@ renderclient(dynent *d, bool team, OFString *mdlname, bool hellpig, float scale)
if (t > (r + 10) * 100) { if (t > (r + 10) * 100) {
t -= (r + 10) * 100; t -= (r + 10) * 100;
mz -= t * t / 10000000000.0f * t; mz -= t * t / 10000000000.0f * t;
}; }
}; }
if (mz < -1000) if (mz < -1000)
return; return;
// mdl = (((int)d>>6)&1)+1; // mdl = (((int)d>>6)&1)+1;

View file

@ -70,7 +70,7 @@ spawnstate(dynent *d) // reset player state not persistent accross spawns
if (gamemode == 12) { if (gamemode == 12) {
d->gunselect = GUN_FIST; d->gunselect = GUN_FIST;
return; return;
}; // eihrul's secret "instafist" mode } // eihrul's secret "instafist" mode
d->health = 256; d->health = 256;
if (m_tarena) { if (m_tarena) {
int gun1 = rnd(4) + 1; int gun1 = rnd(4) + 1;
@ -80,8 +80,8 @@ spawnstate(dynent *d) // reset player state not persistent accross spawns
if (gun1 != gun2) { if (gun1 != gun2) {
baseammo(gun2); baseammo(gun2);
break; break;
}; }
}; }
} else if (m_arena) // insta arena } else if (m_arena) // insta arena
{ {
d->ammo[GUN_RIFLE] = 100; d->ammo[GUN_RIFLE] = 100;
@ -89,12 +89,12 @@ spawnstate(dynent *d) // reset player state not persistent accross spawns
{ {
loopi(4) baseammo(i + 1); loopi(4) baseammo(i + 1);
d->gunselect = GUN_CG; d->gunselect = GUN_CG;
}; }
d->ammo[GUN_CG] /= 2; d->ammo[GUN_CG] /= 2;
}; }
} else { } else {
d->ammo[GUN_SG] = 5; d->ammo[GUN_SG] = 5;
}; }
} }
dynent * dynent *
@ -144,7 +144,7 @@ arenacount(dynent *d, int &alive, int &dead, char *&lastteam, bool &oneteam)
lastteam = d->team; lastteam = d->team;
} else { } else {
dead++; dead++;
}; }
} }
int arenarespawnwait = 0; int arenarespawnwait = 0;
@ -178,8 +178,8 @@ arenarespawn()
arenarespawnwait = lastmillis + 5000; arenarespawnwait = lastmillis + 5000;
arenadetectwait = lastmillis + 10000; arenadetectwait = lastmillis + 10000;
player1->roll = 0; player1->roll = 0;
}; }
}; }
} }
void void
@ -201,7 +201,7 @@ otherplayers()
if (lagtime > 1000 && players[i]->state == CS_ALIVE) { if (lagtime > 1000 && players[i]->state == CS_ALIVE) {
players[i]->state = CS_LAGGED; players[i]->state = CS_LAGGED;
continue; continue;
}; }
if (lagtime && players[i]->state != CS_DEAD && if (lagtime && players[i]->state != CS_DEAD &&
(!demoplayback || i != democlientnum)) (!demoplayback || i != democlientnum))
moveplayer( moveplayer(
@ -273,7 +273,7 @@ updateworld(int millis) // main game update loop
} else if (!intermission) { } else if (!intermission) {
moveplayer(player1, 20, true); moveplayer(player1, 20, true);
checkitems(); checkitems();
}; }
c2sinfo(player1); // do this last, to reduce the c2sinfo(player1); // do this last, to reduce the
// effective frame lag // effective frame lag
} }
@ -319,7 +319,7 @@ spawnplayer(dynent *d) // place at random spawn. also used by monsters!
} else { } else {
d->o.x = d->o.y = (float)ssize / 2; d->o.x = d->o.y = (float)ssize / 2;
d->o.z = 4; d->o.z = 4;
}; }
entinmap(d); entinmap(d);
spawnstate(d); spawnstate(d);
d->state = CS_ALIVE; d->state = CS_ALIVE;

View file

@ -46,12 +46,12 @@ updatepos(dynent *d)
d->o.y += dy < 0 ? r - fy : -(r - fy); // push aside d->o.y += dy < 0 ? r - fy : -(r - fy); // push aside
else else
d->o.x += dx < 0 ? r - fx : -(r - fx); d->o.x += dx < 0 ? r - fx : -(r - fx);
}; }
int lagtime = lastmillis - d->lastupdate; int lagtime = lastmillis - d->lastupdate;
if (lagtime) { if (lagtime) {
d->plag = (d->plag * 5 + lagtime) / 6; d->plag = (d->plag * 5 + lagtime) / 6;
d->lastupdate = lastmillis; d->lastupdate = lastmillis;
}; }
} }
void void

View file

@ -164,8 +164,8 @@ cursorupdate() // called every frame from hud
return; return;
sqr *s = S(cx, cy); sqr *s = S(cx, cy);
if (fabs(sheight(s, s, z) - z) > 1) // selected wall // selected wall
{ if (fabs(sheight(s, s, z) - z) > 1) {
x += x > player1->o.x ? 0.5f : -0.5f; // find right wall cube x += x > player1->o.x ? 0.5f : -0.5f; // find right wall cube
y += y > player1->o.y ? 0.5f : -0.5f; y += y > player1->o.y ? 0.5f : -0.5f;
@ -174,7 +174,7 @@ cursorupdate() // called every frame from hud
if (OUTBORD(cx, cy)) if (OUTBORD(cx, cy))
return; return;
}; }
if (dragging) if (dragging)
makesel(); makesel();
@ -187,7 +187,7 @@ cursorupdate() // called every frame from hud
// render editing grid // render editing grid
for (int ix = cx - GRIDSIZE; ix <= cx + GRIDSIZE; ix++) for (int ix = cx - GRIDSIZE; ix <= cx + GRIDSIZE; ix++) {
for (int iy = cy - GRIDSIZE; iy <= cy + GRIDSIZE; iy++) { for (int iy = cy - GRIDSIZE; iy <= cy + GRIDSIZE; iy++) {
if (OUTBORD(ix, iy)) if (OUTBORD(ix, iy))
continue; continue;
@ -215,7 +215,8 @@ cursorupdate() // called every frame from hud
line(ix, iy, h1, ix + 1, iy, h2); line(ix, iy, h1, ix + 1, iy, h2);
if (!(iy + 1 & GRIDM)) if (!(iy + 1 & GRIDM))
line(ix, iy + 1, h4, ix + 1, iy + 1, h3); line(ix, iy + 1, h4, ix + 1, iy + 1, h3);
}; }
}
if (!SOLID(s)) { if (!SOLID(s)) {
float ih = sheight(s, s, z); float ih = sheight(s, s, z);
@ -227,12 +228,12 @@ cursorupdate() // called every frame from hud
linestyle(GRIDS, 0xFF, 0x00, 0x00); linestyle(GRIDS, 0xFF, 0x00, 0x00);
dot(cx, cy, ih); dot(cx, cy, ih);
ch = (int)ih; ch = (int)ih;
}; }
if (selset) { if (selset) {
linestyle(GRIDS, 0xFF, 0x40, 0x40); linestyle(GRIDS, 0xFF, 0x40, 0x40);
box(sel, (float)selh, (float)selh, (float)selh, (float)selh); box(sel, (float)selh, (float)selh, (float)selh, (float)selh);
}; }
} }
vector<block *> undos; // unlimited undo vector<block *> undos; // unlimited undo
@ -316,7 +317,7 @@ tofronttex() // maintain most recently used of the texture lists when applying
p[a + 1] = p[a]; p[a + 1] = p[a];
p[0] = t; p[0] = t;
curedittex[i] = -1; curedittex[i] = -1;
}; }
} }
} }
@ -329,7 +330,7 @@ editdrag(bool isdown)
lasth = ch; lasth = ch;
selset = false; selset = false;
tofronttex(); tofronttex();
}; }
makesel(); makesel();
} }
@ -390,7 +391,7 @@ edittex(int type, int dir)
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;
@ -424,7 +425,7 @@ replace()
if (s->utex == rtex.utex) if (s->utex == rtex.utex)
s->utex = lasttex; s->utex = lasttex;
break; break;
}; }
} }
block b = { 0, 0, ssize, ssize }; block b = { 0, 0, ssize, ssize };
remip(b); remip(b);
@ -526,7 +527,7 @@ 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; loop(s, MAXARCHVERT) loop(v, MAXARCHVERT) archverts[s][v] = 0;
}; }
if (span >= MAXARCHVERT || vert >= MAXARCHVERT || span < 0 || vert < 0) if (span >= MAXARCHVERT || vert >= MAXARCHVERT || span < 0 || vert < 0)
return; return;
archverts[span][vert] = delta; archverts[span][vert] = delta;
@ -587,7 +588,7 @@ VARF(
if (noteditmode()) if (noteditmode())
return; return;
loopi(mipsize) world[i].r = world[i].g = world[i].b = 176; loopi(mipsize) world[i].r = world[i].g = world[i].b = 176;
};); });
void void
edittag(int tag) edittag(int tag)

View file

@ -63,7 +63,7 @@ renderentities()
sin(lastmillis / 100.0 + e.x + e.y) / sin(lastmillis / 100.0 + e.x + e.y) /
20), 20),
lastmillis / 10.0f); lastmillis / 10.0f);
} else } else {
switch (e.attr2) { switch (e.attr2) {
case 1: case 1:
case 3: case 3:
@ -99,41 +99,24 @@ renderentities()
: 30, : 30,
triggertime, 35.0f); triggertime, 35.0f);
break; break;
}; }
}; }
}
} }
} }
struct itemstat { struct itemstat {
int add, max, sound; int add, max, sound;
} itemstats[] = { } itemstats[] = {
10, { 10, 50, S_ITEMAMMO },
50, { 20, 100, S_ITEMAMMO },
S_ITEMAMMO, { 5, 25, S_ITEMAMMO },
20, { 5, 25, S_ITEMAMMO },
100, { 25, 100, S_ITEMHEALTH },
S_ITEMAMMO, { 50, 200, S_ITEMHEALTH },
5, { 100, 100, S_ITEMARMOUR },
25, { 150, 150, S_ITEMARMOUR },
S_ITEMAMMO, { 20000, 30000, S_ITEMPUP },
5,
25,
S_ITEMAMMO,
25,
100,
S_ITEMHEALTH,
50,
200,
S_ITEMHEALTH,
100,
100,
S_ITEMARMOUR,
150,
150,
S_ITEMARMOUR,
20000,
30000,
S_ITEMPUP,
}; };
void void
@ -233,8 +216,8 @@ teleport(int n, dynent *d) // also used by monsters
entinmap(d); entinmap(d);
playsoundc(S_TELEPORT); playsoundc(S_TELEPORT);
break; break;
}; }
}; }
} }
void void
@ -294,7 +277,7 @@ pickup(int n, dynent *d)
lastteleport = lastmillis; lastteleport = lastmillis;
teleport(n, d); teleport(n, d);
break; break;
}; }
case JUMPPAD: { case JUMPPAD: {
static int lastjumppad = 0; static int lastjumppad = 0;

View file

@ -33,14 +33,14 @@ struct monstertype // see docs for how these values modify behaviour
monstertypes[NUMMONSTERTYPES] = { monstertypes[NUMMONSTERTYPES] = {
{ GUN_FIREBALL, 15, 100, 3, 0, 100, 800, 1, 10, 10, S_PAINO, S_DIE1, { GUN_FIREBALL, 15, 100, 3, 0, 100, 800, 1, 10, 10, S_PAINO, S_DIE1,
@"an ogre", @"monster/ogro" }, @"an ogre", @"monster/ogro" },
{GUN_CG, 18, 70, 2, 70, 10, 400, 2, 8, 9, S_PAINR, S_DEATHR, @"a rhino", { GUN_CG, 18, 70, 2, 70, 10, 400, 2, 8, 9, S_PAINR, S_DEATHR,
@"monster/rhino"}, @"a rhino", @"monster/rhino" },
{ GUN_SG, 14, 120, 1, 100, 300, 400, 4, 14, 14, S_PAINE, S_DEATHE, { GUN_SG, 14, 120, 1, 100, 300, 400, 4, 14, 14, S_PAINE, S_DEATHE,
@"ratamahatta", @"monster/rat" }, @"ratamahatta", @"monster/rat" },
{ GUN_RIFLE, 15, 200, 1, 80, 300, 300, 4, 18, 18, S_PAINS, S_DEATHS, { GUN_RIFLE, 15, 200, 1, 80, 300, 300, 4, 18, 18, S_PAINS, S_DEATHS,
@"a slith", @"monster/slith" }, @"a slith", @"monster/slith" },
{GUN_RL, 13, 500, 1, 0, 100, 200, 6, 24, 24, S_PAINB, S_DEATHB, @"bauul", { GUN_RL, 13, 500, 1, 0, 100, 200, 6, 24, 24, S_PAINB, S_DEATHB,
@"monster/bauul"}, @"bauul", @"monster/bauul" },
{ GUN_BITE, 22, 50, 3, 0, 100, 400, 1, 12, 15, S_PAINP, S_PIGGR2, { GUN_BITE, 22, 50, 3, 0, 100, 400, 1, 12, 15, S_PAINP, S_PIGGR2,
@"a hellpig", @"monster/hellpig" }, @"a hellpig", @"monster/hellpig" },
{ GUN_ICEBALL, 12, 250, 1, 0, 10, 400, 6, 18, 18, S_PAINH, S_DEATHH, { GUN_ICEBALL, 12, 250, 1, 0, 10, 400, 6, 18, 18, S_PAINH, S_DEATHH,
@ -90,11 +90,12 @@ void
spawnmonster() // spawn a random monster according to freq distribution in DMSP spawnmonster() // spawn a random monster according to freq distribution in DMSP
{ {
int n = rnd(TOTMFREQ), type; int n = rnd(TOTMFREQ), type;
for (int i = 0;; i++) for (int i = 0;; i++) {
if ((n -= monstertypes[i].freq) < 0) { if ((n -= monstertypes[i].freq) < 0) {
type = i; type = i;
break; break;
}; }
}
basicmonster(type, rnd(360), M_SEARCH, 1000, 1); basicmonster(type, rnd(360), M_SEARCH, 1000, 1);
} }
@ -122,7 +123,7 @@ monsterclear() // called after map start of when toggling edit mode to
entinmap(m); entinmap(m);
monstertotal++; monstertotal++;
} }
}; }
} }
bool bool
@ -158,7 +159,7 @@ los(float lx, float ly, float lz, float bx, float by, float bz,
x += dx / (float)steps; x += dx / (float)steps;
y += dy / (float)steps; y += dy / (float)steps;
i++; i++;
}; }
return i >= steps; return i >= steps;
} }
@ -203,7 +204,7 @@ monsteraction(
if (m->enemy->state == CS_DEAD) { if (m->enemy->state == CS_DEAD) {
m->enemy = player1; m->enemy = player1;
m->anger = 0; m->anger = 0;
}; }
normalise(m, m->targetyaw); normalise(m, m->targetyaw);
if (m->targetyaw > m->yaw) // slowly turn monster towards his target if (m->targetyaw > m->yaw) // slowly turn monster towards his target
{ {
@ -214,29 +215,25 @@ monsteraction(
m->yaw -= curtime * 0.5f; m->yaw -= curtime * 0.5f;
if (m->targetyaw > m->yaw) if (m->targetyaw > m->yaw)
m->yaw = m->targetyaw; m->yaw = m->targetyaw;
}; }
vdist(disttoenemy, vectoenemy, m->o, m->enemy->o); vdist(disttoenemy, vectoenemy, m->o, m->enemy->o);
m->pitch = atan2(m->enemy->o.z - m->o.z, disttoenemy) * 180 / PI; m->pitch = atan2(m->enemy->o.z - m->o.z, disttoenemy) * 180 / PI;
if (m->blocked) // special case: if we run into scenery // special case: if we run into scenery
{ if (m->blocked) {
m->blocked = false; m->blocked = false;
if (!rnd(20000 / // try to jump over obstackle (rare)
monstertypes[m->mtype] if (!rnd(20000 / monstertypes[m->mtype].speed))
.speed)) // try to jump over obstackle (rare)
{
m->jumpnext = true; m->jumpnext = true;
} else if (m->trigger < lastmillis && // search for a way around (common)
(m->monsterstate != M_HOME || else if (m->trigger < lastmillis &&
!rnd(5))) // search for a way around (common) (m->monsterstate != M_HOME || !rnd(5))) {
{ // patented "random walk" AI pathfinding (tm) ;)
m->targetyaw += m->targetyaw += 180 + rnd(180);
180 + rnd(180); // patented "random walk" AI
// pathfinding (tm) ;)
transition(m, M_SEARCH, 1, 400, 1000); transition(m, M_SEARCH, 1, 400, 1000);
}; }
}; }
float enemyyaw = float enemyyaw =
-(float)atan2(m->enemy->o.x - m->o.x, m->enemy->o.y - m->o.y) / PI * -(float)atan2(m->enemy->o.x - m->o.x, m->enemy->o.y - m->o.y) / PI *
@ -266,9 +263,9 @@ monsteraction(
(disttoenemy < 64 && angle < 45) || angle < 10) { (disttoenemy < 64 && angle < 45) || angle < 10) {
transition(m, M_HOME, 1, 500, 200); transition(m, M_HOME, 1, 500, 200);
playsound(S_GRUNT1 + rnd(2), &m->o); playsound(S_GRUNT1 + rnd(2), &m->o);
}; }
break; break;
}; }
case M_AIMING: // this state is the delay between wanting to shoot and case M_AIMING: // this state is the delay between wanting to shoot and
// actually firing // actually firing
@ -277,7 +274,7 @@ monsteraction(
m->attacking = true; m->attacking = true;
shoot(m, m->attacktarget); shoot(m, m->attacktarget);
transition(m, M_ATTACKING, 0, 600, 0); transition(m, M_ATTACKING, 0, 600, 0);
}; }
break; break;
case M_HOME: // monster has visual contact, heads straight for player case M_HOME: // monster has visual contact, heads straight for player
@ -305,11 +302,11 @@ monsteraction(
{ {
transition(m, M_HOME, 1, transition(m, M_HOME, 1,
monstertypes[m->mtype].rate, 0); monstertypes[m->mtype].rate, 0);
}; }
}; }
}; }
break; break;
}; }
moveplayer(m, 1, false); // use physics to move monster moveplayer(m, 1, false); // use physics to move monster
} }
@ -317,24 +314,25 @@ monsteraction(
void void
monsterpain(dynent *m, int damage, dynent *d) monsterpain(dynent *m, int damage, dynent *d)
{ {
if (d->monsterstate) // a monster hit us // a monster hit us
{ if (d->monsterstate) {
if (m != d) // guard for RL guys shooting themselves :) // guard for RL guys shooting themselves :)
{ if (m != d) {
m->anger++; // don't attack straight away, first get // don't attack straight away, first get angry
// angry m->anger++;
int anger = int anger =
m->mtype == d->mtype ? m->anger / 2 : m->anger; m->mtype == d->mtype ? m->anger / 2 : m->anger;
if (anger >= monstertypes[m->mtype].loyalty) if (anger >= monstertypes[m->mtype].loyalty)
m->enemy = d; // monster infight if very angry // monster infight if very angry
}; m->enemy = d;
} else // player hit us }
{ } else {
// player hit us
m->anger = 0; m->anger = 0;
m->enemy = d; m->enemy = d;
}; }
transition(m, M_PAIN, 0, monstertypes[m->mtype].pain, // in this state monster won't attack
200); // in this state monster won't attack transition(m, M_PAIN, 0, monstertypes[m->mtype].pain, 200);
if ((m->health -= damage) <= 0) { if ((m->health -= damage) <= 0) {
m->state = CS_DEAD; m->state = CS_DEAD;
m->lastaction = lastmillis; m->lastaction = lastmillis;
@ -344,10 +342,9 @@ monsterpain(dynent *m, int damage, dynent *d)
int remain = monstertotal - numkilled; int remain = monstertotal - numkilled;
if (remain > 0 && remain <= 5) if (remain > 0 && remain <= 5)
conoutf(@"only %d monster(s) remaining", remain); conoutf(@"only %d monster(s) remaining", remain);
} else { } else
playsound(monstertypes[m->mtype].painsound, &m->o); playsound(monstertypes[m->mtype].painsound, &m->o);
} }
}
void void
endsp(bool allkilled) endsp(bool allkilled)
@ -368,7 +365,7 @@ monsterthink()
conoutf(@"The invasion has begun!"); conoutf(@"The invasion has begun!");
nextmonster = lastmillis + 1000; nextmonster = lastmillis + 1000;
spawnmonster(); spawnmonster();
}; }
if (monstertotal && !spawnremain && numkilled == monstertotal) if (monstertotal && !spawnremain && numkilled == monstertotal)
endsp(true); endsp(true);
@ -383,20 +380,22 @@ monsterthink()
continue; continue;
OFVector3D v = OFVector3D v =
OFMakeVector3D(e.x, e.y, (float)S(e.x, e.y)->floor); OFMakeVector3D(e.x, e.y, (float)S(e.x, e.y)->floor);
loopv(monsters) if (monsters[i]->state == CS_DEAD) loopv(monsters)
{ {
if (lastmillis - monsters[i]->lastaction < 2000) { if (monsters[i]->state == CS_DEAD) {
if (lastmillis - monsters[i]->lastaction <
2000) {
monsters[i]->move = 0; monsters[i]->move = 0;
moveplayer(monsters[i], 1, false); moveplayer(monsters[i], 1, false);
};
} }
else } else {
{
v.z += monsters[i]->eyeheight; v.z += monsters[i]->eyeheight;
vdist(dist, t, monsters[i]->o, v); vdist(dist, t, monsters[i]->o, v);
v.z -= monsters[i]->eyeheight; v.z -= monsters[i]->eyeheight;
if (dist < 4) if (dist < 4)
teleport((int)(&e - &ents[0]), monsters[i]); teleport(
(int)(&e - &ents[0]), monsters[i]);
}
} }
} }

View file

@ -29,7 +29,7 @@ plcollide(dynent *d, dynent *o, float &headspace, float &hi,
headspace = d->o.z - o->o.z - o->aboveeye - d->eyeheight; headspace = d->o.z - o->o.z - o->aboveeye - d->eyeheight;
if (headspace < 0) if (headspace < 0)
headspace = 10; headspace = 10;
}; }
return true; return true;
} }
@ -49,7 +49,7 @@ cornertest(int mip, int x, int y, int dx, int dy, int &bx, int &by,
by = y << mip; by = y << mip;
bs = 1 << mip; bs = 1 << mip;
return cornertest(mip, x, y, dx, dy, bx, by, bs); return cornertest(mip, x, y, dx, dy, bx, by, bs);
}; }
return stest; return stest;
} }
@ -132,7 +132,7 @@ collide(dynent *d, bool spawn, float drop, float rise)
fx2 - bx + fy2 - by >= bs) fx2 - bx + fy2 - by >= bs)
return false; return false;
break; break;
}; }
case FHF: // FIXME: too simplistic collision with case FHF: // FIXME: too simplistic collision with
// slopes, makes it feels like tiny stairs // slopes, makes it feels like tiny stairs
@ -147,14 +147,14 @@ collide(dynent *d, bool spawn, float drop, float rise)
S(x, y + 1)->vdelta + S(x, y + 1)->vdelta +
S(x + 1, y + 1)->vdelta) / S(x + 1, y + 1)->vdelta) /
16.0f; 16.0f;
}; }
if (ceil < hi) if (ceil < hi)
hi = ceil; hi = ceil;
if (floor > lo) if (floor > lo)
lo = floor; lo = floor;
if (floor < minfloor) if (floor < minfloor)
return false; return false;
}; }
if (hi - lo < d->eyeheight + d->aboveeye) if (hi - lo < d->eyeheight + d->aboveeye)
return false; return false;
@ -194,7 +194,7 @@ collide(dynent *d, bool spawn, float drop, float rise)
return false; return false;
} else { } else {
d->o.z -= min(min(drop, space), headspace); // gravity d->o.z -= min(min(drop, space), headspace); // gravity
}; }
const float space2 = hi - (d->o.z + d->aboveeye); const float space2 = hi - (d->o.z + d->aboveeye);
if (space2 < 0) { if (space2 < 0) {
@ -202,10 +202,10 @@ collide(dynent *d, bool spawn, float drop, float rise)
return false; // hack alert! return false; // hack alert!
d->o.z = hi - d->aboveeye; // glue to ceiling d->o.z = hi - d->aboveeye; // glue to ceiling
d->vel.z = 0; // cancel out jumping velocity d->vel.z = 0; // cancel out jumping velocity
}; }
d->onfloor = d->o.z - d->eyeheight - lo < 0.001f; d->onfloor = d->o.z - d->eyeheight - lo < 0.001f;
}; }
return true; return true;
} }
@ -229,7 +229,7 @@ physicsframe() // optimally schedule physics frames inside the graphics frames
physicsfraction = faketime - physicsrepeat * MINFRAMETIME; physicsfraction = faketime - physicsrepeat * MINFRAMETIME;
} else { } else {
physicsrepeat = 1; physicsrepeat = 1;
}; }
} }
// main physics routine, moves a player/monster for a curtime step // main physics routine, moves a player/monster for a curtime step
@ -252,7 +252,7 @@ moveplayer(dynent *pl, int moveres, bool local, int curtime)
d.x *= (float)cos(rad(pl->pitch)); d.x *= (float)cos(rad(pl->pitch));
d.y *= (float)cos(rad(pl->pitch)); d.y *= (float)cos(rad(pl->pitch));
d.z = (float)(pl->move * sin(rad(pl->pitch))); d.z = (float)(pl->move * sin(rad(pl->pitch)));
}; }
d.x += (float)(pl->strafe * cos(rad(pl->yaw - 180))); d.x += (float)(pl->strafe * cos(rad(pl->yaw - 180)));
d.y += (float)(pl->strafe * sin(rad(pl->yaw - 180))); d.y += (float)(pl->strafe * sin(rad(pl->yaw - 180)));
@ -287,37 +287,38 @@ moveplayer(dynent *pl, int moveres, bool local, int curtime)
if (pl->jumpnext) { if (pl->jumpnext) {
pl->jumpnext = false; pl->jumpnext = false;
pl->vel.z = 1.7f; // physics impulse upwards pl->vel.z = 1.7f; // physics impulse upwards
// dampen velocity change even harder, gives
// correct water feel
if (water) { if (water) {
pl->vel.x /= 8; pl->vel.x /= 8;
pl->vel.y /= 8; pl->vel.y /= 8;
}; // dampen velocity change even harder, gives }
// correct water feel
if (local) if (local)
playsoundc(S_JUMP); playsoundc(S_JUMP);
else if (pl->monsterstate) else if (pl->monsterstate)
playsound(S_JUMP, &pl->o); playsound(S_JUMP, &pl->o);
} else if (pl->timeinair > } else if (pl->timeinair > 800) {
800) // if we land after long time must have // if we land after long time must have been a
// been a high jump, make thud sound // high jump, make thud sound
{
if (local) if (local)
playsoundc(S_LAND); playsoundc(S_LAND);
else if (pl->monsterstate) else if (pl->monsterstate)
playsound(S_LAND, &pl->o); playsound(S_LAND, &pl->o);
}; }
pl->timeinair = 0; pl->timeinair = 0;
} else { } else {
pl->timeinair += curtime; pl->timeinair += curtime;
}; }
const float gravity = 20; const float gravity = 20;
const float f = 1.0f / moveres; const float f = 1.0f / moveres;
float dropf = ((gravity - 1) + // incorrect, but works fine
pl->timeinair / 15.0f); // incorrect, but works fine float dropf = ((gravity - 1) + pl->timeinair / 15.0f);
// float slowly down in water
if (water) { if (water) {
dropf = 5; dropf = 5;
pl->timeinair = 0; pl->timeinair = 0;
}; // float slowly down in water }
const float drop = dropf * curtime / gravity / 100 / const float drop = dropf * curtime / gravity / 100 /
moveres; // at high fps, gravity kicks in too fast moveres; // at high fps, gravity kicks in too fast
const float rise = speed / moveres / const float rise = speed / moveres /
@ -337,14 +338,14 @@ moveplayer(dynent *pl, int moveres, bool local, int curtime)
if (collide(pl, false, drop, rise)) { if (collide(pl, false, drop, rise)) {
d.x = 0; d.x = 0;
continue; continue;
}; }
pl->o.x += f * d.x; pl->o.x += f * d.x;
// still stuck, try x axis // still stuck, try x axis
pl->o.y -= f * d.y; pl->o.y -= f * d.y;
if (collide(pl, false, drop, rise)) { if (collide(pl, false, drop, rise)) {
d.y = 0; d.y = 0;
continue; continue;
}; }
pl->o.y += f * d.y; pl->o.y += f * d.y;
// try just dropping down // try just dropping down
pl->moving = false; pl->moving = false;
@ -353,11 +354,11 @@ moveplayer(dynent *pl, int moveres, bool local, int curtime)
if (collide(pl, false, drop, rise)) { if (collide(pl, false, drop, rise)) {
d.y = d.x = 0; d.y = d.x = 0;
continue; continue;
}; }
pl->o.z -= f * d.z; pl->o.z -= f * d.z;
break; break;
} }
}; }
// detect wether player is outside map, used for skipping zbuffer clear // detect wether player is outside map, used for skipping zbuffer clear
// mostly // mostly
@ -369,7 +370,7 @@ moveplayer(dynent *pl, int moveres, bool local, int curtime)
pl->outsidemap = SOLID(s) || pl->outsidemap = SOLID(s) ||
pl->o.z < s->floor - (s->type == FHF ? s->vdelta / 4 : 0) || pl->o.z < s->floor - (s->type == FHF ? s->vdelta / 4 : 0) ||
pl->o.z > s->ceil + (s->type == CHF ? s->vdelta / 4 : 0); pl->o.z > s->ceil + (s->type == CHF ? s->vdelta / 4 : 0);
}; }
// automatically apply smooth roll when strafing // automatically apply smooth roll when strafing
@ -381,7 +382,7 @@ moveplayer(dynent *pl, int moveres, bool local, int curtime)
pl->roll = (float)maxroll; pl->roll = (float)maxroll;
if (pl->roll < -maxroll) if (pl->roll < -maxroll)
pl->roll = (float)-maxroll; pl->roll = (float)-maxroll;
}; }
// play sounds on water transitions // play sounds on water transitions

View file

@ -47,7 +47,7 @@ reallocv()
v.g = ls->g; \ v.g = ls->g; \
v.b = ls->b; \ v.b = ls->b; \
v.a = 255; \ v.a = 255; \
}; }
#define vert(v1, v2, v3, ls, t1, t2) \ #define vert(v1, v2, v3, ls, t1, t2) \
{ \ { \
@ -81,8 +81,8 @@ mipstats(int a, int b, int c)
if (floorstrip || deltastrip) { \ if (floorstrip || deltastrip) { \
addstrip(ogltex, firstindex, curvert - firstindex); \ addstrip(ogltex, firstindex, curvert - firstindex); \
floorstrip = deltastrip = false; \ floorstrip = deltastrip = false; \
}; \ } \
}; }
void void
finishstrips() finishstrips()
{ {
@ -100,7 +100,7 @@ render_flat(int wtex, int x, int y, int size, int h, sqr *l1, sqr *l2, sqr *l3,
if (showm) { if (showm) {
l3 = l1 = &sbright; l3 = l1 = &sbright;
l4 = l2 = &sdark; l4 = l2 = &sdark;
}; }
int sx, sy; int sx, sy;
int gltex = lookuptexture(wtex, &sx, &sy); int gltex = lookuptexture(wtex, &sx, &sy);
@ -128,7 +128,7 @@ render_flat(int wtex, int x, int y, int size, int h, sqr *l1, sqr *l2, sqr *l3,
} else { } else {
vert(x, h, y, l1, xo, yo); vert(x, h, y, l1, xo, yo);
vert(x + size, h, y, l2, xo + xs, yo); vert(x + size, h, y, l2, xo + xs, yo);
}; }
ol3r = l1->r; ol3r = l1->r;
ol3g = l1->g; ol3g = l1->g;
ol3b = l1->b; ol3b = l1->b;
@ -157,8 +157,8 @@ render_flat(int wtex, int x, int y, int size, int h, sqr *l1, sqr *l2, sqr *l3,
ol4r = p4[0]; ol4r = p4[0];
ol4g = p4[1]; ol4g = p4[1];
ol4b = p4[2]; ol4b = p4[2];
}; }
}; }
if (isceil) { if (isceil) {
vert(x + size, h, y + size, l3, xo + xs, yo + ys); vert(x + size, h, y + size, l3, xo + xs, yo + ys);
@ -166,7 +166,7 @@ render_flat(int wtex, int x, int y, int size, int h, sqr *l1, sqr *l2, sqr *l3,
} else { } else {
vert(x, h, y + size, l4, xo, yo + ys); vert(x, h, y + size, l4, xo, yo + ys);
vert(x + size, h, y + size, l3, xo + xs, yo + ys); vert(x + size, h, y + size, l3, xo + xs, yo + ys);
}; }
oy = y; oy = y;
nquads++; nquads++;
@ -181,7 +181,7 @@ render_flatdelta(int wtex, int x, int y, int size, float h1, float h2, float h3,
if (showm) { if (showm) {
l3 = l1 = &sbright; l3 = l1 = &sbright;
l4 = l2 = &sdark; l4 = l2 = &sdark;
}; }
int sx, sy; int sx, sy;
int gltex = lookuptexture(wtex, &sx, &sy); int gltex = lookuptexture(wtex, &sx, &sy);
@ -207,14 +207,14 @@ render_flatdelta(int wtex, int x, int y, int size, float h1, float h2, float h3,
} else { } else {
vertf((float)x, h1, (float)y, l1, xo, yo); vertf((float)x, h1, (float)y, l1, xo, yo);
vertf((float)x + size, h2, (float)y, l2, xo + xs, yo); vertf((float)x + size, h2, (float)y, l2, xo + xs, yo);
}; }
ol3r = l1->r; ol3r = l1->r;
ol3g = l1->g; ol3g = l1->g;
ol3b = l1->b; ol3b = l1->b;
ol4r = l2->r; ol4r = l2->r;
ol4g = l2->g; ol4g = l2->g;
ol4b = l2->b; ol4b = l2->b;
}; }
if (isceil) { if (isceil) {
vertf( vertf(
@ -224,7 +224,7 @@ render_flatdelta(int wtex, int x, int y, int size, float h1, float h2, float h3,
vertf((float)x, h4, (float)y + size, l4, xo, yo + ys); vertf((float)x, h4, (float)y + size, l4, xo, yo + ys);
vertf( vertf(
(float)x + size, h3, (float)y + size, l3, xo + xs, yo + ys); (float)x + size, h3, (float)y + size, l3, xo + xs, yo + ys);
}; }
oy = y; oy = y;
nquads++; nquads++;
@ -276,7 +276,7 @@ render_tris(int x, int y, int size, bool topleft, sqr *h1, sqr *h2, sqr *s,
if (h2) if (h2)
render_2tris(h2, s, x + size, y, x + size, y + size, x, render_2tris(h2, s, x + size, y, x + size, y + size, x,
y + size, t, u, v); y + size, t, u, v);
}; }
} }
void void
@ -289,7 +289,7 @@ render_square(int wtex, float floor1, float floor2, float ceil1, float ceil2,
if (showm) { if (showm) {
l1 = &sbright; l1 = &sbright;
l2 = &sdark; l2 = &sdark;
}; }
int sx, sy; int sx, sy;
int gltex = lookuptexture(wtex, &sx, &sy); int gltex = lookuptexture(wtex, &sx, &sy);
@ -308,7 +308,7 @@ render_square(int wtex, float floor1, float floor2, float ceil1, float ceil2,
vertf((float)x2, ceil2, (float)y2, l2, xo + xs, -yf * ceil2); vertf((float)x2, ceil2, (float)y2, l2, xo + xs, -yf * ceil2);
vertf((float)x1, floor1, (float)y1, l1, xo, -floor1 * yf); vertf((float)x1, floor1, (float)y1, l1, xo, -floor1 * yf);
vertf((float)x2, floor2, (float)y2, l2, xo + xs, -floor2 * yf); vertf((float)x2, floor2, (float)y2, l2, xo + xs, -floor2 * yf);
}; }
nquads++; nquads++;
addstrip(gltex, curvert - 4, 4); addstrip(gltex, curvert - 4, 4);
@ -375,17 +375,17 @@ renderwater(float hf)
vertw(xx, hf, yy, &dl, dx(xo), dy(yo), t1); vertw(xx, hf, yy, &dl, dx(xo), dy(yo), t1);
vertw(xx + watersubdiv, hf, yy, &dl, vertw(xx + watersubdiv, hf, yy, &dl,
dx(xo + xs), dy(yo), t1); dx(xo + xs), dy(yo), t1);
}; }
vertw(xx, hf, yy + watersubdiv, &dl, dx(xo), vertw(xx, hf, yy + watersubdiv, &dl, dx(xo),
dy(yo + ys), t1); dy(yo + ys), t1);
vertw(xx + watersubdiv, hf, yy + watersubdiv, &dl, vertw(xx + watersubdiv, hf, yy + watersubdiv, &dl,
dx(xo + xs), dy(yo + ys), t1); dx(xo + xs), dy(yo + ys), t1);
}; }
int n = (wy2 - wy1 - 1) / watersubdiv; int n = (wy2 - wy1 - 1) / watersubdiv;
nquads += n; nquads += n;
n = (n + 2) * 2; n = (n + 2) * 2;
glDrawArrays(GL_TRIANGLE_STRIP, curvert -= n, n); glDrawArrays(GL_TRIANGLE_STRIP, curvert -= n, n);
}; }
glDisable(GL_BLEND); glDisable(GL_BLEND);
glDepthMask(GL_TRUE); glDepthMask(GL_TRUE);
@ -412,7 +412,7 @@ addwaterquad(int x, int y, int size) // update bounding rect that contains water
wx2 = x2; wx2 = x2;
if (y2 > wy2) if (y2 > wy2)
wy2 = y2; wy2 = y2;
}; }
} }
void void

View file

@ -98,7 +98,7 @@ newsphere(OFVector3D &o, float max, int type)
sempty = &spheres[i]; sempty = &spheres[i];
} }
sinit = true; sinit = true;
}; }
if (sempty) { if (sempty) {
sphere *p = sempty; sphere *p = sempty;
sempty = p->next; sempty = p->next;
@ -108,7 +108,7 @@ newsphere(OFVector3D &o, float max, int type)
p->type = type; p->type = type;
p->next = slist; p->next = slist;
slist = p; slist = p;
}; }
} }
void void
@ -139,8 +139,8 @@ renderspheres(int time)
} else { } else {
p->size += time / 100.0f; p->size += time / 100.0f;
pp = &p->next; pp = &p->next;
}; }
}; }
glDisable(GL_BLEND); glDisable(GL_BLEND);
glDepthMask(GL_TRUE); glDepthMask(GL_TRUE);
@ -210,8 +210,8 @@ loadsky(OFString *basename)
if ([lastsky isEqual:basename]) if ([lastsky isEqual:basename])
return; return;
static const OFString *side[] = { static const OFString *side[] = { @"ft", @"bk", @"lf", @"rt",
@"ft", @"bk", @"lf", @"rt", @"dn", @"up"}; @"dn", @"up" };
int texnum = 14; int texnum = 14;
loopi(6) loopi(6)
{ {
@ -336,7 +336,7 @@ gl_drawhud(int w, int h, int curfps, int nquads, int curvert, bool underwater)
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
cursorupdate(); cursorupdate();
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
}; }
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
invertperspective(); invertperspective();
@ -442,7 +442,7 @@ gl_drawhud(int w, int h, int curfps, int nquads, int curvert, bool underwater)
if (g > 2) { if (g > 2) {
g -= 3; g -= 3;
r = 128; r = 128;
}; }
drawicon((float)(g * 64), (float)r, 1220, 1650); drawicon((float)(g * 64), (float)r, 1220, 1650);
glPopMatrix(); glPopMatrix();
} }

View file

@ -110,8 +110,13 @@ installtex(int tnum, OFIRI *IRI, int *xs, int *ys, bool clamp)
} }
} }
// loopi(s->w*s->h*3) { uchar *p = (uchar *)s->pixels+i; *p = #if 0
// 255-*p; }; loopi(s->w * s->h * 3)
{
uchar *p = (uchar *)s->pixels + i;
*p = 255 - *p;
}
#endif
glBindTexture(GL_TEXTURE_2D, tnum); glBindTexture(GL_TEXTURE_2D, tnum);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
@ -264,7 +269,7 @@ setupworld()
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE); glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE);
glTexEnvi( glTexEnvi(
GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_PRIMARY_COLOR_EXT); GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_PRIMARY_COLOR_EXT);
}; }
} }
int skyoglid; int skyoglid;
@ -350,8 +355,8 @@ VAR(fogcolour, 0, 0x8099B3, 0xFFFFFF);
VARP(hudgun, 0, 1, 1); VARP(hudgun, 0, 1, 1);
OFString *hudgunnames[] = {@"hudguns/fist", @"hudguns/shotg", @"hudguns/chaing", OFString *hudgunnames[] = { @"hudguns/fist", @"hudguns/shotg",
@"hudguns/rocket", @"hudguns/rifle"}; @"hudguns/chaing", @"hudguns/rocket", @"hudguns/rifle" };
void void
drawhudmodel(int start, int end, float speed, int base) drawhudmodel(int start, int end, float speed, int base)
@ -382,7 +387,7 @@ drawhudgun(float fovy, float aspect, int farplane)
drawhudmodel(7, 18, rtime / 18.0f, player1->lastaction); drawhudmodel(7, 18, rtime / 18.0f, player1->lastaction);
} else { } else {
drawhudmodel(6, 1, 100, 0); drawhudmodel(6, 1, 100, 0);
}; }
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glLoadIdentity(); glLoadIdentity();
@ -413,7 +418,7 @@ gl_drawframe(int w, int h, float curfps)
aspect += (float)sin(lastmillis / 1000.0 + PI) * 0.1f; aspect += (float)sin(lastmillis / 1000.0 + PI) * 0.1f;
glFogi(GL_FOG_START, 0); glFogi(GL_FOG_START, 0);
glFogi(GL_FOG_END, (fog + 96) / 8); glFogi(GL_FOG_END, (fog + 96) / 8);
}; }
glClear((player1->outsidemap ? GL_COLOR_BUFFER_BIT : 0) | glClear((player1->outsidemap ? GL_COLOR_BUFFER_BIT : 0) |
GL_DEPTH_BUFFER_BIT); GL_DEPTH_BUFFER_BIT);

View file

@ -25,7 +25,7 @@ newparticle(OFVector3D &o, OFVector3D &d, int fade, int type)
parempty = &particles[i]; parempty = &particles[i];
} }
parinit = true; parinit = true;
}; }
if (parempty) { if (parempty) {
particle *p = parempty; particle *p = parempty;
parempty = p->next; parempty = p->next;
@ -36,7 +36,7 @@ newparticle(OFVector3D &o, OFVector3D &d, int fade, int type)
p->millis = lastmillis; p->millis = lastmillis;
p->next = parlist; p->next = parlist;
parlist = p; parlist = p;
}; }
} }
VAR(demotracking, 0, 0, 1); VAR(demotracking, 0, 0, 1);
@ -71,7 +71,8 @@ render_particles(int time)
} parttypes[] = { } parttypes[] = {
{ 0.7f, 0.6f, 0.3f, 2, 3, 0.06f }, // yellow: sparks { 0.7f, 0.6f, 0.3f, 2, 3, 0.06f }, // yellow: sparks
{ 0.5f, 0.5f, 0.5f, 20, 7, 0.15f }, // grey: small smoke { 0.5f, 0.5f, 0.5f, 20, 7, 0.15f }, // grey: small smoke
{0.2f, 0.2f, 1.0f, 20, 3, 0.08f}, // blue: edit mode entities { 0.2f, 0.2f, 1.0f, 20, 3,
0.08f }, // blue: edit mode entities
{ 1.0f, 0.1f, 0.1f, 1, 7, 0.06f }, // red: blood spats { 1.0f, 0.1f, 0.1f, 1, 7, 0.06f }, // red: blood spats
{ 1.0f, 0.8f, 0.8f, 20, 6, 1.2f }, // yellow: fireball1 { 1.0f, 0.8f, 0.8f, 20, 6, 1.2f }, // yellow: fireball1
{ 0.5f, 0.5f, 0.5f, 20, 7, 0.6f }, // grey: big smoke { 0.5f, 0.5f, 0.5f, 20, 7, 0.6f }, // grey: big smoke

View file

@ -73,7 +73,7 @@ perlinarea(block &b, int scale, int seed, int psize)
seed = rnd(10000); seed = rnd(10000);
if (!scale) if (!scale)
scale = 10; scale = 10;
for (int x = b.x; x <= b.x + b.xs; x++) for (int x = b.x; x <= b.x + b.xs; x++) {
for (int y = b.y; y <= b.y + b.ys; y++) { for (int y = b.y; y <= b.y + b.ys; y++) {
sqr *s = S(x, y); sqr *s = S(x, y);
if (!SOLID(s) && x != b.x + b.xs && y != b.y + b.ys) if (!SOLID(s) && x != b.x + b.xs && y != b.y + b.ys)
@ -85,5 +85,6 @@ perlinarea(block &b, int scale, int seed, int psize)
25); 25);
if (s->vdelta > 128) if (s->vdelta > 128)
s->vdelta = 0; s->vdelta = 0;
}; }
}
} }

View file

@ -71,7 +71,7 @@ stop()
if (demorecording) if (demorecording)
gzputi(-1); gzputi(-1);
gzclose(f); gzclose(f);
}; }
f = NULL; f = NULL;
demorecording = false; demorecording = false;
demoplayback = false; demoplayback = false;

View file

@ -20,8 +20,8 @@ vector<client> clients;
int maxclients = 8; int maxclients = 8;
static OFString *smapname; static OFString *smapname;
struct server_entity // server side version of "entity" type // server side version of "entity" type
{ struct server_entity {
bool spawned; bool spawned;
int spawnsecs; int spawnsecs;
}; };
@ -68,12 +68,12 @@ send(int n, ENetPacket *packet)
enet_peer_send(clients[n].peer, 0, packet); enet_peer_send(clients[n].peer, 0, packet);
bsend += packet->dataLength; bsend += packet->dataLength;
break; break;
}; }
case ST_LOCAL: case ST_LOCAL:
localservertoclient(packet->data, packet->dataLength); localservertoclient(packet->data, packet->dataLength);
break; break;
}; }
} }
void void
@ -137,7 +137,7 @@ pickup(uint i, int sec, int sender) // server side item pickup, acknowledge
sents[i].spawned = false; sents[i].spawned = false;
sents[i].spawnsecs = sec; sents[i].spawnsecs = sec;
send2(true, sender, SV_ITEMACC, i); send2(true, sender, SV_ITEMACC, i);
}; }
} }
void void
@ -190,7 +190,7 @@ process(ENetPacket *packet, int sender) // sender may be -1
packet->dataLength) { packet->dataLength) {
disconnect_client(sender, "packet length"); disconnect_client(sender, "packet length");
return; return;
}; }
uchar *end = packet->data + packet->dataLength; uchar *end = packet->data + packet->dataLength;
uchar *p = packet->data + 2; uchar *p = packet->data + 2;
@ -239,7 +239,7 @@ process(ENetPacket *packet, int sender) // sender may be -1
while (sents.length() <= n) while (sents.length() <= n)
sents.add(se); sents.add(se);
sents[n].spawned = true; sents[n].spawned = true;
}; }
notgotitems = false; notgotitems = false;
break; break;
} }
@ -260,7 +260,7 @@ process(ENetPacket *packet, int sender) // sender may be -1
clients[cn].type == ST_EMPTY) { clients[cn].type == ST_EMPTY) {
disconnect_client(sender, "client num"); disconnect_client(sender, "client num");
return; return;
}; }
int size = msgsizelookup(type); int size = msgsizelookup(type);
assert(size != -1); assert(size != -1);
loopi(size - 2) getint(p); loopi(size - 2) getint(p);
@ -286,22 +286,22 @@ process(ENetPacket *packet, int sender) // sender may be -1
for (int n = getint(p); n; n--) for (int n = getint(p); n; n--)
getint(p); getint(p);
break; break;
}; }
default: { default: {
int size = msgsizelookup(type); int size = msgsizelookup(type);
if (size == -1) { if (size == -1) {
disconnect_client(sender, "tag type"); disconnect_client(sender, "tag type");
return; return;
}; }
loopi(size - 1) getint(p); loopi(size - 1) getint(p);
}; }
}; }
if (p > end) { if (p > end) {
disconnect_client(sender, "end of packet"); disconnect_client(sender, "end of packet");
return; return;
}; }
multicast(packet, sender); multicast(packet, sender);
} }
@ -365,7 +365,7 @@ checkintermission()
if (!minremain) { if (!minremain) {
interm = lastsec + 10; interm = lastsec + 10;
mapend = lastsec + 1000; mapend = lastsec + 1000;
}; }
send2(true, -1, SV_TIMEUP, minremain--); send2(true, -1, SV_TIMEUP, minremain--);
} }
@ -406,7 +406,7 @@ serverslice(int seconds,
sents[i].spawnsecs = 0; sents[i].spawnsecs = 0;
sents[i].spawned = true; sents[i].spawned = true;
send2(true, -1, SV_ITEMSPAWN, i); send2(true, -1, SV_ITEMSPAWN, i);
}; }
} }
lastsec = seconds; lastsec = seconds;
@ -423,7 +423,7 @@ serverslice(int seconds,
mapreload = true; mapreload = true;
break; break;
} }
}; }
resetserverifempty(); resetserverifempty();
@ -448,7 +448,7 @@ serverslice(int seconds,
nonlocalclients, bsend / 60.0f / 1024, nonlocalclients, bsend / 60.0f / 1024,
brec / 60.0f / 1024); brec / 60.0f / 1024);
bsend = brec = 0; bsend = brec = 0;
}; }
ENetEvent event; ENetEvent event;
if (enet_host_service(serverhost, &event, timeout) > 0) { if (enet_host_service(serverhost, &event, timeout) > 0) {
@ -484,12 +484,11 @@ serverslice(int seconds,
send2(true, -1, SV_CDIS, (intptr_t)event.peer->data); send2(true, -1, SV_CDIS, (intptr_t)event.peer->data);
event.peer->data = (void *)-1; event.peer->data = (void *)-1;
break; break;
}; }
if (numplayers > maxclients) { if (numplayers > maxclients)
disconnect_client(lastconnect, "maxclients reached"); disconnect_client(lastconnect, "maxclients reached");
}; }
};
#ifndef _WIN32 #ifndef _WIN32
fflush(stdout); fflush(stdout);
#endif #endif
@ -542,8 +541,8 @@ initserver(bool dedicated, int uprate, OFString *sdesc, OFString *ip,
resetserverifempty(); resetserverifempty();
if (isdedicated) // do not return, this becomes main loop // do not return, this becomes main loop
{ if (isdedicated) {
#ifdef _WIN32 #ifdef _WIN32
SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);
#endif #endif
@ -553,5 +552,5 @@ initserver(bool dedicated, int uprate, OFString *sdesc, OFString *ip,
atexit(enet_deinitialize); atexit(enet_deinitialize);
for (;;) for (;;)
serverslice(/*enet_time_get_sec()*/ time(NULL), 5); serverslice(/*enet_time_get_sec()*/ time(NULL), 5);
}; }
} }

View file

@ -45,7 +45,7 @@ resolverloop(void *data)
rt->query = NULL; rt->query = NULL;
rt->starttime = 0; rt->starttime = 0;
SDL_UnlockMutex(resolvermutex); SDL_UnlockMutex(resolvermutex);
}; }
return 0; return 0;
} }
@ -125,8 +125,8 @@ resolvercheck(char **name, ENetAddress *address)
*name = rt.query; *name = rt.query;
SDL_UnlockMutex(resolvermutex); SDL_UnlockMutex(resolvermutex);
return true; return true;
}; }
}; }
} }
SDL_UnlockMutex(resolvermutex); SDL_UnlockMutex(resolvermutex);
return false; return false;
@ -305,7 +305,7 @@ servermenu()
if (pingsock == ENET_SOCKET_NULL) { if (pingsock == ENET_SOCKET_NULL) {
pingsock = enet_socket_create(ENET_SOCKET_TYPE_DATAGRAM, NULL); pingsock = enet_socket_create(ENET_SOCKET_TYPE_DATAGRAM, NULL);
resolverinit(1, 1000); resolverinit(1, 1000);
}; }
resolverclear(); resolverclear();
loopv(servers) resolverquery(servers[i].name); loopv(servers) resolverquery(servers[i].name);
refreshservers(); refreshservers();

View file

@ -46,11 +46,11 @@ httpgetrecieve(ENetBuffer &buf)
enet_socket_destroy(mssock); enet_socket_destroy(mssock);
mssock = ENET_SOCKET_NULL; mssock = ENET_SOCKET_NULL;
return; return;
}; }
buf.data = ((char *)buf.data) + len; buf.data = ((char *)buf.data) + len;
((char *)buf.data)[0] = 0; ((char *)buf.data)[0] = 0;
buf.dataLength -= len; buf.dataLength -= len;
}; }
} }
uchar * uchar *
@ -72,9 +72,8 @@ ENetBuffer masterb;
void void
updatemasterserver(int seconds) updatemasterserver(int seconds)
{ {
if (seconds > // send alive signal to masterserver every hour of uptime
updmaster) // send alive signal to masterserver every hour of uptime if (seconds > updmaster) {
{
sprintf_sd(path)("%sregister.do?action=add", masterpath); sprintf_sd(path)("%sregister.do?action=add", masterpath);
httpgetsend(masterserver, masterbase, path, "cubeserver", httpgetsend(masterserver, masterbase, path, "cubeserver",
"Cube Server"); "Cube Server");
@ -82,7 +81,7 @@ updatemasterserver(int seconds)
masterb.data = masterrep; masterb.data = masterrep;
masterb.dataLength = MAXTRANS - 1; masterb.dataLength = MAXTRANS - 1;
updmaster = seconds + 60 * 60; updmaster = seconds + 60 * 60;
}; }
} }
void void
@ -159,8 +158,8 @@ servermsinit(OFString *master_, OFString *sdesc, bool listen)
serverdesc = sdesc; serverdesc = sdesc;
if (listen) { if (listen) {
ENetAddress address = { ENetAddress address = { ENET_HOST_ANY,
ENET_HOST_ANY, CUBE_SERVINFO_PORT}; CUBE_SERVINFO_PORT };
pongsock = enet_socket_create( pongsock = enet_socket_create(
ENET_SOCKET_TYPE_DATAGRAM, &address); ENET_SOCKET_TYPE_DATAGRAM, &address);
if (pongsock == ENET_SOCKET_NULL) if (pongsock == ENET_SOCKET_NULL)

View file

@ -20,7 +20,7 @@ putint(uchar *&p, int n)
*p++ = n >> 8; *p++ = n >> 8;
*p++ = n >> 16; *p++ = n >> 16;
*p++ = n >> 24; *p++ = n >> 24;
}; }
} }
int int
@ -75,16 +75,15 @@ modestr(int n)
{ {
return (n >= -2 && n < 12) ? modenames[n + 2] : @"unknown"; return (n >= -2 && n < 12) ? modenames[n + 2] : @"unknown";
} }
// size inclusive message token, 0 for variable or not-checked sizes
char msgsizesl[] = // size inclusive message token, 0 for variable or char msgsizesl[] = { SV_INITS2C, 4, SV_INITC2S, 0, SV_POS, 12, SV_TEXT, 0,
// not-checked sizes SV_SOUND, 2, SV_CDIS, 2, SV_EDITH, 7, SV_EDITT, 7, SV_EDITS, 6,
{SV_INITS2C, 4, SV_INITC2S, 0, SV_POS, 12, SV_TEXT, 0, SV_SOUND, 2, SV_CDIS, SV_EDITD, 6, SV_EDITE, 6, SV_DIED, 2, SV_DAMAGE, 4, SV_SHOT, 8,
2, SV_EDITH, 7, SV_EDITT, 7, SV_EDITS, 6, SV_EDITD, 6, SV_EDITE, 6, SV_FRAGS, 2, SV_MAPCHANGE, 0, SV_ITEMSPAWN, 2, SV_ITEMPICKUP, 3,
SV_DIED, 2, SV_DAMAGE, 4, SV_SHOT, 8, SV_FRAGS, 2, SV_MAPCHANGE, 0, SV_DENIED, 2, SV_PING, 2, SV_PONG, 2, SV_CLIENTPING, 2, SV_GAMEMODE, 2,
SV_ITEMSPAWN, 2, SV_ITEMPICKUP, 3, SV_DENIED, 2, SV_PING, 2, SV_PONG, 2, SV_TIMEUP, 2, SV_EDITENT, 10, SV_MAPRELOAD, 2, SV_ITEMACC, 2,
SV_CLIENTPING, 2, SV_GAMEMODE, 2, SV_TIMEUP, 2, SV_EDITENT, 10, SV_SENDMAP, 0, SV_RECVMAP, 1, SV_SERVMSG, 0, SV_ITEMLIST, 0, SV_EXT, 0,
SV_MAPRELOAD, 2, SV_ITEMACC, 2, SV_SENDMAP, 0, SV_RECVMAP, 1, -1 };
SV_SERVMSG, 0, SV_ITEMLIST, 0, SV_EXT, 0, -1};
char char
msgsizelookup(int msg) msgsizelookup(int msg)
@ -187,8 +186,8 @@ main(int argc, char *argv[])
break; break;
default: default:
printf("WARNING: unknown commandline option\n"); printf("WARNING: unknown commandline option\n");
}; }
}; }
if (enet_initialize() < 0) if (enet_initialize() < 0)
fatal(@"Unable to initialise network module"); fatal(@"Unable to initialise network module");

View file

@ -45,13 +45,13 @@ stopsound()
FMUSIC_FreeSong(mod); FMUSIC_FreeSong(mod);
#endif #endif
mod = NULL; mod = NULL;
}; }
if (stream) { if (stream) {
#ifndef USE_MIXER #ifndef USE_MIXER
FSOUND_Stream_Close(stream); FSOUND_Stream_Close(stream);
#endif #endif
stream = NULL; stream = NULL;
}; }
} }
VAR(soundbufferlen, 128, 1024, 4096); VAR(soundbufferlen, 128, 1024, 4096);
@ -66,7 +66,7 @@ initsound()
conoutf(@"sound init failed (SDL_mixer): %s", conoutf(@"sound init failed (SDL_mixer): %s",
(size_t)Mix_GetError()); (size_t)Mix_GetError());
nosound = true; nosound = true;
}; }
Mix_AllocateChannels(MAXCHAN); Mix_AllocateChannels(MAXCHAN);
#else #else
if (FSOUND_GetVersion() < FMOD_VERSION) if (FSOUND_GetVersion() < FMOD_VERSION)
@ -182,8 +182,8 @@ updatechanvol(int chan, OFVector3D *loc)
pan = int(255.9f * pan = int(255.9f *
(0.5 * sin(yaw) + 0.5f)); // range is from 0 (left) (0.5 * sin(yaw) + 0.5f)); // range is from 0 (left)
// to 255 (right) // to 255 (right)
}; }
}; }
vol = (vol * MAXVOL) / 255; vol = (vol * MAXVOL) / 255;
#ifdef USE_MIXER #ifdef USE_MIXER
Mix_Volume(chan, vol); Mix_Volume(chan, vol);

View file

@ -173,7 +173,7 @@ hit(int target, int damage, dynent *d, dynent *at)
else { else {
addmsg(1, 4, SV_DAMAGE, target, damage, d->lifesequence); addmsg(1, 4, SV_DAMAGE, target, damage, d->lifesequence);
playsound(S_PAIN1 + rnd(5), &d->o); playsound(S_PAIN1 + rnd(5), &d->o);
}; }
particle_splash(3, damage, 1000, d->o); particle_splash(3, damage, 1000, d->o);
demodamage(damage, d->o); demodamage(damage, d->o);
} }

View file

@ -25,7 +25,7 @@ settag(int tag, int type) // set all cubes with "tag" to space, if tag is 0 then
continue; continue;
} else { } else {
s->type = type ? SOLID : SPACE; s->type = type ? SOLID : SPACE;
}; }
if (x > maxx) if (x > maxx)
maxx = x; maxx = x;
if (y > maxy) if (y > maxy)
@ -34,7 +34,7 @@ settag(int tag, int type) // set all cubes with "tag" to space, if tag is 0 then
minx = x; minx = x;
if (y < miny) if (y < miny)
miny = y; miny = y;
}; }
} }
block b = { minx, miny, maxx - minx + 1, maxy - miny + 1 }; block b = { minx, miny, maxx - minx + 1, maxy - miny + 1 };
if (maxx) if (maxx)
@ -97,11 +97,11 @@ remip(block &b, int level)
if (s.x & 1) { if (s.x & 1) {
s.x--; s.x--;
s.xs++; s.xs++;
}; }
if (s.y & 1) { if (s.y & 1) {
s.y--; s.y--;
s.ys++; s.ys++;
}; }
s.xs = (s.xs + 1) & ~1; s.xs = (s.xs + 1) & ~1;
s.ys = (s.ys + 1) & ~1; s.ys = (s.ys + 1) & ~1;
for (int x = s.x; x < s.x + s.xs; x += 2) for (int x = s.x; x < s.x + s.xs; x += 2)
@ -144,7 +144,7 @@ remip(block &b, int level)
// account middle // account middle
// vertices on // vertices on
// higher mips // higher mips
}; }
if (fh < floor) if (fh < floor)
floor = floor =
fh; // take lowest floor and fh; // take lowest floor and
@ -157,7 +157,7 @@ remip(block &b, int level)
} }
r->floor = floor; r->floor = floor;
r->ceil = ceil; r->ceil = ceil;
}; }
if (r->type == CORNER) if (r->type == CORNER)
goto mip; // special case: don't ever split even goto mip; // special case: don't ever split even
// if textures etc are different // if textures etc are different
@ -218,16 +218,16 @@ remip(block &b, int level)
SWS(w, x + 1, y + 2, ws) SWS(w, x + 1, y + 2, ws)
->vdelta) ->vdelta)
goto c; goto c;
}; }
}; }
{ {
loopi(4) if (o[i]->defer) goto c; loopi(4) if (o[i]->defer) goto c;
}; // if any of the constituents is not perfect, then } // if any of the constituents is not perfect, then
// this one isn't either // this one isn't either
mip: mip:
r->defer = 0; r->defer = 0;
c:; c:;
}; }
s.x /= 2; s.x /= 2;
s.y /= 2; s.y /= 2;
s.xs /= 2; s.xs /= 2;
@ -267,7 +267,7 @@ closestent() // used for delent and edit mode ent display
if (dist < bdist) { if (dist < bdist) {
best = i; best = i;
bdist = dist; bdist = dist;
}; }
} }
return bdist == 99999 ? -1 : best; return bdist == 99999 ? -1 : best;
} }
@ -291,7 +291,7 @@ entproperty(int prop, int amount)
case 3: case 3:
ents[e].attr4 += amount; ents[e].attr4 += amount;
break; break;
}; }
} }
void void
@ -347,7 +347,7 @@ newentity(int x, int y, int z, OFString *what, int v1, int v2, int v3, int v4)
case PLAYERSTART: case PLAYERSTART:
e.attr1 = (int)player1->yaw; e.attr1 = (int)player1->yaw;
break; break;
}; }
addmsg(1, 10, SV_EDITENT, ents.length(), type, e.x, e.y, e.z, e.attr1, addmsg(1, 10, SV_EDITENT, ents.length(), type, e.x, e.y, e.z, e.attr1,
e.attr2, e.attr3, e.attr4); e.attr2, e.attr3, e.attr4);
ents.add(*((entity *)&e)); // unsafe! ents.add(*((entity *)&e)); // unsafe!
@ -399,7 +399,7 @@ scalelights(int f, int intens)
scalecomp(e.attr2, intens); scalecomp(e.attr2, intens);
scalecomp(e.attr3, intens); scalecomp(e.attr3, intens);
scalecomp(e.attr4, intens); scalecomp(e.attr4, intens);
}; }
} }
calclight(); calclight();
} }
@ -445,7 +445,7 @@ empty_world(
if (oldworld && factor < 0) { if (oldworld && factor < 0) {
factor = sfactor + 1; factor = sfactor + 1;
copy = true; copy = true;
}; }
if (factor < SMALLEST_FACTOR) if (factor < SMALLEST_FACTOR)
factor = SMALLEST_FACTOR; factor = SMALLEST_FACTOR;
if (factor > LARGEST_FACTOR) if (factor > LARGEST_FACTOR)

View file

@ -99,7 +99,7 @@ lightray(float bx, float by,
l -= stepl; l -= stepl;
stepl -= 25; stepl -= 25;
} }
}; }
} 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
{ {
@ -115,7 +115,7 @@ lightray(float bx, float by,
y += stepy; y += stepy;
l -= stepl; l -= stepl;
} }
}; }
} }
void void
@ -134,11 +134,11 @@ calclightsource(persistent_entity &l)
for (float sx2 = (float)sx; sx2 <= ex; sx2 += s * 2) { for (float sx2 = (float)sx; sx2 <= ex; sx2 += s * 2) {
lightray(sx2, (float)sy, l); lightray(sx2, (float)sy, l);
lightray(sx2, (float)ey, l); lightray(sx2, (float)ey, l);
}; }
for (float sy2 = sy + s; sy2 <= ey - s; sy2 += s * 2) { for (float sy2 = sy + s; sy2 <= ey - s; sy2 += s * 2) {
lightray((float)sx, sy2, l); lightray((float)sx, sy2, l);
lightray((float)ex, sy2, l); lightray((float)ex, sy2, l);
}; }
rndtime(); rndtime();
} }
@ -227,8 +227,8 @@ dodynlight(
dlights.add(blockcopy(b)); // backup area before rendering in dynlight dlights.add(blockcopy(b)); // backup area before rendering in dynlight
persistent_entity l = {(short)v.x, (short)v.y, (short)v.z, (short)reach, persistent_entity l = { (short)v.x, (short)v.y, (short)v.z,
LIGHT, (uchar)strength, 0, 0}; (short)reach, LIGHT, (uchar)strength, 0, 0 };
calclightsource(l); calclightsource(l);
postlightarea(b); postlightarea(b);
} }

View file

@ -57,25 +57,22 @@ computeraytable(float vx, float vy)
} else { } else {
dx = 1; dx = 1;
dy = ray > 4 ? ray - 8 : ray; dy = ray > 4 ? ray - 8 : ray;
}; }
float sx = vx; float sx = vx;
float sy = vy; float sy = vy;
for (;;) { for (;;) {
sx += dx; sx += dx;
sy += dy; sy += dy;
if (SOLID(S(fast_f2nat(sx), // 90% of time spend in this function is on this
fast_f2nat( // line
sy)))) // 90% of time spend in this if (SOLID(S(fast_f2nat(sx), fast_f2nat(sy)))) {
// function is on this line
{
rdist[i] = (float)(fabs(sx - vx) + rdist[i] = (float)(fabs(sx - vx) +
fabs(sy - vy)); fabs(sy - vy));
break; break;
}; }
}; }
} else { } else
rdist[i] = 2; rdist[i] = 2;
};
} }
} }
@ -152,9 +149,8 @@ isoccluded(float vx, float vy, float cx, float cy,
} else { } else {
h = ca(cy + csize - vy, -(cx + csize - vx)) + 2; h = ca(cy + csize - vy, -(cx + csize - vx)) + 2;
l = ca(cy - vy, -(cx - vx)) + 2; l = ca(cy - vy, -(cx - vx)) + 2;
}; // F } // F
} else // BG } else { // BG
{
if (cy <= vy) { if (cy <= vy) {
if (cy + csize < vy) { if (cy + csize < vy) {
h = ma(-(cy + csize - vy), cx - vx) + 6; h = ma(-(cy + csize - vy), cx - vx) + 6;
@ -167,8 +163,8 @@ isoccluded(float vx, float vy, float cx, float cy,
} else { } else {
h = ma(cy - vy, -(cx + csize - vx)) + 2; h = ma(cy - vy, -(cx + csize - vx)) + 2;
l = ma(cy - vy, -(cx - vx)) + 2; l = ma(cy - vy, -(cx - vx)) + 2;
}; // G } // G
}; }
} else // CEH } else // CEH
{ {
if (cy <= vy) // CE if (cy <= vy) // CE
@ -180,12 +176,12 @@ isoccluded(float vx, float vy, float cx, float cy,
else { else {
h = ma(cx - vx, cy - vy); h = ma(cx - vx, cy - vy);
l = ma(cx - vx, cy + csize - vy); l = ma(cx - vx, cy + csize - vy);
}; // E } // E
} else { } else {
h = ca(cx + csize - vx, cy - vy); h = ca(cx + csize - vx, cy - vy);
l = ca(cx - vx, cy + csize - vy); l = ca(cx - vx, cy + csize - vy);
}; // H } // H
}; }
int si = fast_f2nat(h * (NUMRAYS / 8)) + int si = fast_f2nat(h * (NUMRAYS / 8)) +
NUMRAYS; // get indexes into occlusion map from angles NUMRAYS; // get indexes into occlusion map from angles
int ei = fast_f2nat(l * (NUMRAYS / 8)) + NUMRAYS + 1; int ei = fast_f2nat(l * (NUMRAYS / 8)) + NUMRAYS + 1;
@ -194,10 +190,10 @@ isoccluded(float vx, float vy, float cx, float cy,
for (int i = si; i <= ei; i++) { for (int i = si; i <= ei; i++) {
if (dist < rdist[i & (NUMRAYS - 1)]) if (dist < rdist[i & (NUMRAYS - 1)])
return 0; // if any value in this segment of the // if any value in this segment of the occlusion map is
// occlusion map is further away then cube is // further away then cube is not occluded
// not occluded return 0;
}; }
return 1; // cube is entirely occluded return 1; // cube is entirely occluded
} }

View file

@ -14,18 +14,18 @@ render_wall(sqr *o, sqr *s, int x1, int y1, int x2, int y2, int mip, sqr *d1,
if (s->type == FHF) { if (s->type == FHF) {
c1 -= d1->vdelta / 4.0f; c1 -= d1->vdelta / 4.0f;
c2 -= d2->vdelta / 4.0f; c2 -= d2->vdelta / 4.0f;
}; }
float f1 = s->ceil; float f1 = s->ceil;
float f2 = s->ceil; float f2 = s->ceil;
if (s->type == CHF) { if (s->type == CHF) {
f1 += d1->vdelta / 4.0f; f1 += d1->vdelta / 4.0f;
f2 += d2->vdelta / 4.0f; f2 += d2->vdelta / 4.0f;
}; }
// if(f1-c1<=0 && f2-c2<=0) return; // if(f1-c1<=0 && f2-c2<=0) return;
render_square(o->wtex, c1, c2, f1, f2, x1 << mip, y1 << mip, render_square(o->wtex, c1, c2, f1, f2, x1 << mip, y1 << mip,
x2 << mip, y2 << mip, 1 << mip, d1, d2, topleft); x2 << mip, y2 << mip, 1 << mip, d1, d2, topleft);
return; return;
}; }
{ {
float f1 = s->floor; float f1 = s->floor;
float f2 = s->floor; float f2 = s->floor;
@ -43,7 +43,7 @@ render_wall(sqr *o, sqr *s, int x1, int y1, int x2, int y2, int mip, sqr *d1,
goto skip; goto skip;
render_square(o->wtex, f1, f2, c1, c2, x1 << mip, y1 << mip, render_square(o->wtex, f1, f2, c1, c2, x1 << mip, y1 << mip,
x2 << mip, y2 << mip, 1 << mip, d1, d2, topleft); x2 << mip, y2 << mip, 1 << mip, d1, d2, topleft);
}; }
skip: { skip: {
float f1 = o->ceil; float f1 = o->ceil;
float f2 = o->ceil; float f2 = o->ceil;
@ -60,7 +60,7 @@ skip: {
return; return;
render_square(o->utex, f1, f2, c1, c2, x1 << mip, y1 << mip, x2 << mip, render_square(o->utex, f1, f2, c1, c2, x1 << mip, y1 << mip, x2 << mip,
y2 << mip, 1 << mip, d1, d2, topleft); y2 << mip, 1 << mip, d1, d2, topleft);
}; }
} }
const int MAX_MIP = 5; // 32x32 unit blocks const int MAX_MIP = 5; // 32x32 unit blocks
@ -94,7 +94,7 @@ issemi(int mip, int x, int y, int x1, int y1, int x2, int y2)
break; break;
default: default:
return true; return true;
}; }
switch (SWS(w, x + x2, y + y2, msize)->type) { switch (SWS(w, x + x2, y + y2, msize)->type) {
case SEMISOLID: case SEMISOLID:
if (issemi(mip, x + x2, y + y2, x1, y1, x2, y2)) if (issemi(mip, x + x2, y + y2, x1, y1, x2, y2))
@ -104,7 +104,7 @@ issemi(int mip, int x, int y, int x1, int y1, int x2, int y2)
break; break;
default: default:
return true; return true;
}; }
return false; return false;
} }
@ -131,14 +131,14 @@ render_seg_new(
int ry = vyy + lodbot; int ry = vyy + lodbot;
float fsize = (float)(1 << mip); float fsize = (float)(1 << mip);
for (int ox = x; ox < xs; ox++) for (int ox = x; ox < xs; ox++) {
for (int oy = y; oy < ys; // first collect occlusion information for this block
oy++) // first collect occlusion information for this block for (int oy = y; oy < ys; oy++) {
{
SWS(w, ox, oy, sz)->occluded = SWS(w, ox, oy, sz)->occluded =
isoccluded(player1->o.x, player1->o.y, isoccluded(player1->o.x, player1->o.y,
(float)(ox << mip), (float)(oy << mip), fsize); (float)(ox << mip), (float)(oy << mip), fsize);
}; }
}
int pvx = (int)vx >> mip; int pvx = (int)vx >> mip;
int pvy = (int)vy >> mip; int pvy = (int)vy >> mip;
@ -146,7 +146,7 @@ render_seg_new(
// SWS(w,vxx,vyy,sz)->occluded = 0; // SWS(w,vxx,vyy,sz)->occluded = 0;
SWS(w, pvx, pvy, sz)->occluded = SWS(w, pvx, pvy, sz)->occluded =
0; // player cell never occluded 0; // player cell never occluded
}; }
#define df(x) s->floor - (x->vdelta / 4.0f) #define df(x) s->floor - (x->vdelta / 4.0f)
#define dc(x) s->ceil + (x->vdelta / 4.0f) #define dc(x) s->ceil + (x->vdelta / 4.0f)
@ -195,7 +195,6 @@ render_seg_new(
dc(t), dc(u), dc(v), s, t, u, v, true); dc(t), dc(u), dc(v), s, t, u, v, true);
} }
} }
;
LOOPH continue; // floors LOOPH continue; // floors
LOOPD LOOPD
@ -204,16 +203,15 @@ if ((s->type == SPACE || s->type == CHF) && s->floor <= vh && render_floor) {
v, false); v, false);
if (s->floor < hdr.waterlevel && !SOLID(s)) if (s->floor < hdr.waterlevel && !SOLID(s))
addwaterquad(xx << mip, yy << mip, 1 << mip); addwaterquad(xx << mip, yy << mip, 1 << mip);
}; }
if (s->type == FHF) { if (s->type == FHF) {
render_flatdelta(s->ftex, xx << mip, yy << mip, 1 << mip, df(s), df(t), render_flatdelta(s->ftex, xx << mip, yy << mip, 1 << mip, df(s), df(t),
df(u), df(v), s, t, u, v, false); df(u), df(v), s, t, u, v, false);
if (s->floor - s->vdelta / 4.0f < hdr.waterlevel && !SOLID(s)) if (s->floor - s->vdelta / 4.0f < hdr.waterlevel && !SOLID(s))
addwaterquad(xx << mip, yy << mip, 1 << mip); addwaterquad(xx << mip, yy << mip, 1 << mip);
};
} }
} }
; }
LOOPH continue; // walls LOOPH continue; // walls
LOOPD LOOPD
@ -238,7 +236,7 @@ if (s->type == CORNER) {
} else if (SOLID(v)) { } else if (SOLID(v)) {
render_wall(v, h2 = s, xx, yy, xx + 1, yy + 1, mip, s, render_wall(v, h2 = s, xx, yy, xx + 1, yy + 1, mip, s,
u, false); u, false);
}; }
} else if (SOLID(t)) { } else if (SOLID(t)) {
if (SOLID(w)) { if (SOLID(w)) {
render_wall(w, h1 = s, xx + 1, yy + 1, xx, yy, mip, u, render_wall(w, h1 = s, xx + 1, yy + 1, xx, yy, mip, u,
@ -247,7 +245,7 @@ if (s->type == CORNER) {
render_wall(v, h1 = s, xx, yy + 1, xx + 1, yy, mip, v, render_wall(v, h1 = s, xx, yy + 1, xx + 1, yy, mip, v,
t, false); t, false);
topleft = false; topleft = false;
}; }
} else { } else {
normalwall = false; normalwall = false;
bool wv = w->ceil - w->floor < v->ceil - v->floor; bool wv = w->ceil - w->floor < v->ceil - v->floor;
@ -259,7 +257,7 @@ if (s->type == CORNER) {
} else { } else {
render_wall(h1 = s, h2 = w, xx, yy, xx + 1, render_wall(h1 = s, h2 = w, xx, yy, xx + 1,
yy + 1, mip, s, u, false); yy + 1, mip, s, u, false);
}; }
} else { } else {
if (wv) { if (wv) {
render_wall(h2 = s, h1 = v, xx + 1, yy + 1, xx, render_wall(h2 = s, h1 = v, xx + 1, yy + 1, xx,
@ -268,9 +266,9 @@ if (s->type == CORNER) {
render_wall(h2 = s, h1 = w, xx, yy + 1, xx + 1, render_wall(h2 = s, h1 = w, xx, yy + 1, xx + 1,
yy, mip, v, t, false); yy, mip, v, t, false);
topleft = false; topleft = false;
}; }
}; }
}; }
render_tris( render_tris(
xx << mip, yy << mip, 1 << mip, topleft, h1, h2, s, t, u, v); xx << mip, yy << mip, 1 << mip, topleft, h1, h2, s, t, u, v);
} }
@ -294,12 +292,10 @@ if (normalwall) {
(!SOLID(s) || v->type != CORNER) && (!SOLID(s) || v->type != CORNER) &&
(v->type != SEMISOLID || issemi(mip, xx, yy + 1, 0, 0, 1, 0))) (v->type != SEMISOLID || issemi(mip, xx, yy + 1, 0, 0, 1, 0)))
render_wall(s, v, xx, yy + 1, xx + 1, yy + 1, mip, v, u, true); render_wall(s, v, xx, yy + 1, xx + 1, yy + 1, mip, v, u, true);
};
} }
} }
;
} }
; }
void void
distlod(int &low, int &high, int angle, float widef) distlod(int &low, int &high, int angle, float widef)
@ -325,14 +321,13 @@ render_world(
yaw = 360 - yaw; yaw = 360 - yaw;
float widef = fov / 75.0f; float widef = fov / 75.0f;
int cdist = abs(yaw % 90 - 45); int cdist = abs(yaw % 90 - 45);
if (cdist < 7) // hack to avoid popup at high fovs at 45 yaw // hack to avoid popup at high fovs at 45 yaw
{ if (cdist < 7) {
min_lod = max(min_lod, // less if lod worked better
(int)(MIN_LOD + min_lod =
(10 - cdist) / 1.0f * max(min_lod, (int)(MIN_LOD + (10 - cdist) / 1.0f * widef));
widef)); // less if lod worked better
widef = 1.0f; widef = 1.0f;
}; }
lod = MAX_LOD; lod = MAX_LOD;
lodtop = lodbot = lodleft = lodright = min_lod; lodtop = lodbot = lodleft = lodright = min_lod;
if (yaw > 45 && yaw <= 135) { if (yaw > 45 && yaw <= 135) {
@ -348,7 +343,7 @@ render_world(
lodtop = lod; lodtop = lod;
distlod( distlod(
lodright, lodleft, yaw <= 45 ? yaw + 45 : yaw - 315, widef); lodright, lodleft, yaw <= 45 ? yaw + 45 : yaw - 315, widef);
}; }
float hyfov = fov * h / w / 2; float hyfov = fov * h / w / 2;
render_floor = pitch < hyfov; render_floor = pitch < hyfov;
render_ceil = -pitch < hyfov; render_ceil = -pitch < hyfov;