More style fixes

FossilOrigin-Name: c634a689e76e7c60fb8b685ea40cb9993a86f23474d1ead7159eb331e98f1110
This commit is contained in:
Jonathan Schleifer 2025-03-29 17:13:40 +00:00
parent d3dc40de33
commit a838f496b1
39 changed files with 536 additions and 582 deletions

View file

@ -6,8 +6,8 @@ OF_ASSUME_NONNULL_BEGIN
OF_CONSTRUCTOR() \
{ \
enqueueInit(^ { \
Identifier.identifiers[@#name] = \
[Command commandWithName: @#name \
Identifier.identifiers[@#name] = [Command \
commandWithName: @#name \
argumentsTypes: nargs \
block: block_]; \
}); \

View file

@ -128,10 +128,8 @@ VARP(minmillis, 0, 5, 1000);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
if ((_window = SDL_CreateWindow("cube engine",
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
_width, _height,
SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL |
(!windowed ? SDL_WINDOW_FULLSCREEN : 0))) ==
NULL ||
_width, _height, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL |
(!windowed ? SDL_WINDOW_FULLSCREEN : 0))) == NULL ||
SDL_GL_CreateContext(_window) == NULL)
fatal(@"Unable to create OpenGL screen");
@ -244,8 +242,8 @@ VARP(minmillis, 0, 5, 1000);
if (_repeatsKeys ||
event.key.repeat == 0)
keypress(event.key.keysym.sym,
event.key.state ==
SDL_PRESSED);
(event.key.state ==
SDL_PRESSED));
break;
case SDL_TEXTINPUT:
input(@(event.text.text));
@ -314,10 +312,8 @@ VARP(minmillis, 0, 5, 1000);
for (int idx = 0; idx < _height; idx++) {
char *dest =
(char *)temp->pixels + 3 * _width * idx;
memcpy(dest,
(char *)image->pixels +
3 * _width * (_height - 1 - idx),
3 * _width);
memcpy(dest, (char *)image->pixels + 3 *
_width * (_height - 1 - idx), 3 * _width);
endianswap(dest, 3, _width);
}

View file

@ -296,9 +296,7 @@ enemylos(Monster *m, OFVector3D *v)
}
float enemyYaw = -(float)atan2(self.enemy.origin.x - self.origin.x,
self.enemy.origin.y - self.origin.y) /
PI * 180 +
180;
self.enemy.origin.y - self.origin.y) / PI * 180 + 180;
switch (self.monsterState) {
case M_PAIN:
@ -311,17 +309,16 @@ enemylos(Monster *m, OFVector3D *v)
r: 200];
break;
case M_SLEEP: // state classic sp monster start in, wait for visual
// contact
{
// state classic sp monster start in, wait for visual contact
case M_SLEEP: {
OFVector3D target;
if (editmode || !enemylos(self, &target))
return; // skip running physics
[self normalizeWithAngle: enemyYaw];
float angle = (float)fabs(enemyYaw - self.yaw);
if (disttoenemy < 8 // the better the angle to the player, the
// further the monster can see/hear
|| (disttoenemy < 16 && angle < 135) ||
// the better the angle to the player, the further the monster
// can see/hear
if (disttoenemy < 8 || (disttoenemy < 16 && angle < 135) ||
(disttoenemy < 32 && angle < 90) ||
(disttoenemy < 64 && angle < 45) || angle < 10) {
[self transitionWithState: M_HOME
@ -401,9 +398,8 @@ enemylos(Monster *m, OFVector3D *v)
if (self != m) {
// don't attack straight away, first get angry
self.anger++;
int anger =
(self.monsterType == m.monsterType ? self.anger / 2
: self.anger);
int anger = (self.monsterType == m.monsterType
? self.anger / 2 : self.anger);
if (anger >= monstertypes[self.monsterType].loyalty)
// monster infight if very angry
self.enemy = m;
@ -438,8 +434,8 @@ enemylos(Monster *m, OFVector3D *v)
+ (void)endSinglePlayerWithAllKilled: (bool)allKilled
{
conoutf(allKilled ? @"you have cleared the map!"
: @"you reached the exit!");
conoutf(allKilled
? @"you have cleared the map!" : @"you reached the exit!");
conoutf(@"score: %d kills in %d seconds", numkilled,
(lastmillis - mtimestart) / 1000);
monstertotal = 0;

View file

@ -8,8 +8,8 @@ OF_ASSUME_NONNULL_BEGIN
OF_CONSTRUCTOR() \
{ \
enqueueInit(^ { \
Variable *variable = \
[Variable variableWithName: @#name \
Variable *variable = [Variable \
variableWithName: @#name \
min: min_ \
max: max_ \
storage: &name \
@ -24,8 +24,8 @@ OF_ASSUME_NONNULL_BEGIN
OF_CONSTRUCTOR() \
{ \
enqueueInit(^ { \
Variable *variable = \
[Variable variableWithName: @#name \
Variable *variable = [Variable \
variableWithName: @#name \
min: min_ \
max: max_ \
storage: &name \
@ -41,8 +41,8 @@ OF_ASSUME_NONNULL_BEGIN
OF_CONSTRUCTOR() \
{ \
enqueueInit(^ { \
Variable *variable = \
[Variable variableWithName: @#name \
Variable *variable = [Variable \
variableWithName: @#name \
min: min_ \
max: max_ \
storage: &name \
@ -64,8 +64,8 @@ OF_ASSUME_NONNULL_BEGIN
OF_CONSTRUCTOR() \
{ \
enqueueInit(^ { \
Variable *variable = \
[Variable variableWithName: @#name \
Variable *variable = [Variable \
variableWithName: @#name \
min: min_ \
max: max_ \
storage: &name \

View file

@ -12,10 +12,13 @@
// D D D D' D D D D' A A' P P' I I'
// R, R' E L J J'
int frame[] = { 178, 184, 190, 137, 183, 189, 197, 164, 46, 51, 54, 32, 0, 0,
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 frame[] = {
178, 184, 190, 137, 183, 189, 197, 164, 46, 51, 54, 32, 0, 0, 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
};
void
renderclient(

View file

@ -313,13 +313,9 @@ selfdamage(int damage, int actor, DynamicEntity *act)
player1.armour -= ad;
damage -= ad;
float droll = damage / 0.5f;
player1.roll += player1.roll > 0
? droll
: (player1.roll < 0
? -droll
: (rnd(2) ? droll
: -droll)); // give player a kick depending
// on amount of damage
// give player a kick depending on amount of damage
player1.roll += player1.roll > 0 ? droll : (player1.roll < 0 ? -droll :
(rnd(2) ? droll : -droll));
if ((player1.health -= damage) <= 0) {
if (actor == -2) {
conoutf(@"you got killed by %@!", act.name);
@ -332,8 +328,7 @@ selfdamage(int damage, int actor, DynamicEntity *act)
if (a != nil) {
if (isteam(a.team, player1.team))
conoutf(@"you got fragged by a "
@"teammate (%@)",
a.name);
@"teammate (%@)", a.name);
else
conoutf(
@"you got fragged by %@", a.name);

View file

@ -49,12 +49,10 @@ updatepos(DynamicEntity *d)
if (fx < r && fy < r && fz < rz && d.state != CS_DEAD) {
if (fx < fy)
// push aside
d.origin = OFAddVectors3D(d.origin,
OFMakeVector3D(
d.origin = OFAddVectors3D(d.origin, OFMakeVector3D(
0, (dy < 0 ? r - fy : -(r - fy)), 0));
else
d.origin = OFAddVectors3D(d.origin,
OFMakeVector3D(
d.origin = OFAddVectors3D(d.origin, OFMakeVector3D(
(dx < 0 ? r - fx : -(r - fx)), 0, 0));
}
int lagtime = lastmillis - d.lastUpdate;
@ -265,8 +263,8 @@ localservertoclient(unsigned char *buf, int len)
if (a != nil) {
if (isteam(a.team, d.name))
conoutf(@"%@ fragged his "
@"teammate (%@)",
a.name, d.name);
@"teammate (%@)", a.name,
d.name);
else
conoutf(@"%@ fragged %@",
a.name, d.name);
@ -303,8 +301,9 @@ localservertoclient(unsigned char *buf, int len)
realpickup(getint(&p), Player.player1);
break;
case SV_EDITH: // coop editing messages, should be extended to
// include all possible editing ops
// coop editing messages, should be extended to include all
// possible editing ops
case SV_EDITH:
case SV_EDITT:
case SV_EDITS:
case SV_EDITD:
@ -367,8 +366,7 @@ localservertoclient(unsigned char *buf, int len)
case SV_PONG:
addmsg(0, 2, SV_CLIENTPING,
Player.player1.ping = (Player.player1.ping * 5 +
lastmillis - getint(&p)) /
6);
lastmillis - getint(&p)) / 6);
break;
case SV_CLIENTPING:
@ -401,9 +399,9 @@ localservertoclient(unsigned char *buf, int len)
conoutf(@"%s", text);
break;
case SV_EXT: // so we can messages without breaking previous
// so we can messages without breaking previous
// clients/servers, if necessary
{
case SV_EXT: {
for (int n = getint(&p); n; n--)
getint(&p);
break;

View file

@ -83,8 +83,8 @@ renderconsole()
size_t i = 0;
for (ConsoleLine *conline in conlines) {
if (conskip ? i >= conskip - 1 || i >= conlines.count - ndraw
: lastmillis - conline.outtime < 20000) {
if (conskip ? i >= conskip - 1 || i >= conlines.count - ndraw :
lastmillis - conline.outtime < 20000) {
refs[nd++] = conline.text;
if (nd == ndraw)
break;
@ -221,9 +221,8 @@ keypress(int code, bool isDown)
if (code == SDLK_RETURN) {
if (commandbuf.length > 0) {
if (vhistory == nil)
vhistory =
[[OFMutableArray alloc]
init];
vhistory = [[OFMutableArray
alloc] init];
if (vhistory.count == 0 ||
![vhistory.lastObject isEqual:

View file

@ -72,16 +72,19 @@ toggleedit()
{
Player *player1 = Player.player1;
if (player1.state == CS_DEAD)
return; // do not allow dead players to edit to avoid state
// confusion
// do not allow dead players to edit to avoid state
return;
if (!editmode && !allowedittoggle())
return; // not in most multiplayer modes
// not in most multiplayer modes
return;
if (!(editmode = !editmode)) {
settagareas(); // reset triggers to allow quick playtesting
entinmap(player1); // find spawn closest to current floating pos
// reset triggers to allow quick playtesting
settagareas();
// find spawn closest to current floating pos
entinmap(player1);
} else {
resettagareas(); // clear trigger areas to allow them to be
// edited
// clear trigger areas to allow them to be edited
resettagareas();
player1.health = 100;
if (m_classicsp)
// all monsters back at their spawns for editing
@ -342,9 +345,9 @@ COMMAND(paste, ARG_NONE, ^ {
blockpaste(copybuf);
})
// maintain most recently used of the texture lists when applying texture
void
tofronttex() // maintain most recently used of the texture lists when applying
// texture
tofronttex()
{
for (int i = 0; i < 3; i++) {
int c = curedittex[i];
@ -408,7 +411,8 @@ COMMAND(editheight, ARG_2INT, ^ (int flr, int amount) {
void
edittexxy(int type, int t, const struct block *sel)
{
loopselxy(switch (type) {
loopselxy(
switch (type) {
case 0:
s->ftex = t;
break;
@ -421,7 +425,8 @@ edittexxy(int type, int t, const struct block *sel)
case 3:
s->utex = t;
break;
});
}
);
}
COMMAND(edittex, ARG_2INT, ^ (int type, int dir) {
@ -486,9 +491,8 @@ edittype(int type)
{
EDITSEL;
if (type == CORNER &&
(sel.xs != sel.ys || sel.xs == 3 || (sel.xs > 4 && sel.xs != 8) ||
sel.x & ~-sel.xs || sel.y & ~-sel.ys)) {
if (type == CORNER && (sel.xs != sel.ys || sel.xs == 3 || (sel.xs > 4 &&
sel.xs != 8) || sel.x & ~-sel.xs || sel.y & ~-sel.ys)) {
conoutf(@"corner selection must be power of 2 aligned");
return;
}
@ -582,11 +586,10 @@ COMMAND(arch, ARG_2INT, ^ (int sidedelta, int _a) {
struct block *sel_ = &sel;
// Ugly hack to make the macro work.
struct block *sel = sel_;
loopselxy(s->vdelta = sel->xs > sel->ys
? (archverts[sel->xs - 1][x] +
(y == 0 || y == sel->ys - 1 ? sidedelta : 0))
: (archverts[sel->ys - 1][y] +
(x == 0 || x == sel->xs - 1 ? sidedelta : 0)));
loopselxy(s->vdelta = sel->xs > sel->ys ? (archverts[sel->xs - 1][x] +
(y == 0 || y == sel->ys - 1 ? sidedelta : 0)) :
(archverts[sel->ys - 1][y] + (x == 0 || x == sel->xs - 1 ?
sidedelta : 0)));
remipmore(sel, 0);
})

View file

@ -51,11 +51,10 @@ renderentities()
if (mmi == nil)
continue;
rendermodel(mmi.name, 0, 1, e.attr4, (float)mmi.rad,
OFMakeVector3D(e.x,
(float)S(e.x, e.y)->floor + mmi.zoff + e.attr3,
e.y),
(float)((e.attr1 + 7) - (e.attr1 + 7) % 15), 0,
false, 1.0f, 10.0f, mmi.snap, 0);
OFMakeVector3D(e.x, (float)S(e.x, e.y)->floor +
mmi.zoff + e.attr3, e.y), (float)((e.attr1 + 7) -
(e.attr1 + 7) % 15), 0, false, 1.0f, 10.0f,
mmi.snap, 0);
} else {
if (OUTBORD(e.x, e.y))
continue;
@ -65,10 +64,9 @@ renderentities()
if (e.type < I_SHELLS || e.type > TELEPORT)
continue;
renderent(e, entmdlnames[e.type - I_SHELLS],
(float)(1 +
sin(lastmillis / 100.0 + e.x + e.y) /
20),
lastmillis / 10.0f, 0, 1, 0, 10.0f);
(float)(1 + sin(lastmillis / 100.0 + e.x +
e.y) / 20), lastmillis / 10.0f, 0, 1, 0,
10.0f);
} else {
switch (e.attr2) {
case 1:
@ -79,32 +77,26 @@ renderentities()
case 0:
if (!e.spawned)
continue;
renderent(e, @"carrot",
(float)(1 +
renderent(e, @"carrot", (float)(1 +
sin(lastmillis / 100.0 + e.x +
e.y) /
20),
lastmillis /
(e.attr2 ? 1.0f : 10.0f),
0, 1, 0, 10.0f);
e.y) / 20), lastmillis / (e.attr2 ?
1.0f : 10.0f), 0, 1, 0, 10.0f);
break;
case 4:
renderent(e, @"switch2", 3,
(float)e.attr3 * 90,
(!e.spawned && !triggertime) ? 1
: 0,
(e.spawned || !triggertime) ? 1 : 2,
triggertime, 1050.0f);
(!e.spawned && !triggertime) ?
1 : 0, (e.spawned || !triggertime) ?
1 : 2, triggertime, 1050.0f);
break;
case 5:
renderent(e, @"switch1", -0.15f,
(float)e.attr3 * 90,
(!e.spawned && !triggertime) ? 30
: 0,
(e.spawned || !triggertime) ? 1
: 30,
triggertime, 35.0f);
(!e.spawned && !triggertime) ?
30 : 0, (e.spawned ||
!triggertime) ? 1 : 30, triggertime,
35.0f);
break;
}
}

View file

@ -15,8 +15,8 @@
// collide with player or monster
static bool
plcollide(
DynamicEntity *d, DynamicEntity *o, float *headspace, float *hi, float *lo)
plcollide(DynamicEntity *d, DynamicEntity *o, float *headspace, float *hi,
float *lo)
{
if (o.state != CS_ALIVE)
return true;
@ -125,22 +125,15 @@ collide(DynamicEntity *d, bool spawn, float drop, float rise)
return false;
case CORNER: {
int bx = x, by = y, bs = 1;
if ((x == x1 && y == y1 &&
cornertest(
0, x, y, -1, -1, &bx, &by, &bs) &&
fx1 - bx + fy1 - by <= bs) ||
(x == x2 && y == y1 &&
cornertest(
0, x, y, 1, -1, &bx, &by, &bs) &&
fx2 - bx >= fy1 - by) ||
(x == x1 && y == y2 &&
cornertest(
0, x, y, -1, 1, &bx, &by, &bs) &&
fx1 - bx <= fy2 - by) ||
(x == x2 && y == y2 &&
cornertest(
0, x, y, 1, 1, &bx, &by, &bs) &&
fx2 - bx + fy2 - by >= bs))
if ((x == x1 && y == y1 && cornertest(0, x, y,
-1, -1, &bx, &by, &bs) && fx1 - bx + fy1 -
by <= bs) || (x == x2 && y == y1 &&
cornertest(0, x, y, 1, -1, &bx, &by, &bs) &&
fx2 - bx >= fy1 - by) || (x == x1 && y ==
y2 && cornertest(0, x, y, -1, 1, &bx, &by,
&bs) && fx1 - bx <= fy2 - by) || (x == x2 &&
y == y2 && cornertest(0, x, y, 1, 1, &bx,
&by, &bs) && fx2 - bx + fy2 - by >= bs))
return false;
break;
}
@ -149,14 +142,12 @@ collide(DynamicEntity *d, bool spawn, float drop, float rise)
case FHF:
floor -= (s->vdelta + S(x + 1, y)->vdelta +
S(x, y + 1)->vdelta +
S(x + 1, y + 1)->vdelta) /
16.0f;
S(x + 1, y + 1)->vdelta) / 16.0f;
break;
case CHF:
ceil += (s->vdelta + S(x + 1, y)->vdelta +
S(x, y + 1)->vdelta +
S(x + 1, y + 1)->vdelta) /
16.0f;
S(x + 1, y + 1)->vdelta) / 16.0f;
}
if (ceil < hi)
@ -214,8 +205,7 @@ collide(DynamicEntity *d, bool spawn, float drop, float rise)
return false;
} else
// gravity
d.origin = OFSubtractVectors3D(d.origin,
OFMakeVector3D(
d.origin = OFSubtractVectors3D(d.origin, OFMakeVector3D(
0, 0, min(min(drop, space), headspace)));
const float space2 = hi - (d.origin.z + d.aboveEye);
@ -407,11 +397,10 @@ moveplayer4(DynamicEntity *pl, int moveres, bool local, int curtime)
pl.outsideMap = true;
else {
struct sqr *s = S((int)pl.origin.x, (int)pl.origin.y);
pl.outsideMap = SOLID(s) ||
pl.origin.z <
s->floor - (s->type == FHF ? s->vdelta / 4 : 0) ||
pl.origin.z >
s->ceil + (s->type == CHF ? s->vdelta / 4 : 0);
pl.outsideMap = (SOLID(s) || pl.origin.z < s->floor -
(s->type == FHF ? s->vdelta / 4 : 0) ||
pl.origin.z > s->ceil + (s->type == CHF
? s->vdelta / 4 : 0));
}
// automatically apply smooth roll when strafing
@ -443,8 +432,6 @@ void
moveplayer(DynamicEntity *pl, int moveres, bool local)
{
for (int i = 0; i < physicsrepeat; i++)
moveplayer4(pl, moveres, local,
i ? curtime / physicsrepeat
: curtime -
curtime / physicsrepeat * (physicsrepeat - 1));
moveplayer4(pl, moveres, local, i ? curtime / physicsrepeat
: curtime - curtime / physicsrepeat * (physicsrepeat - 1));
}

View file

@ -138,14 +138,13 @@ render_flat(int wtex, int x, int y, int size, int h, struct sqr *l1,
} else // continue strip
{
int lighterr = lighterror * 2;
// skip vertices if light values are close enough
if ((abs(ol3r - l3->r) < lighterr &&
abs(ol4r - l4->r) < lighterr // skip vertices if light
// values are close enough
&& abs(ol3g - l3->g) < lighterr &&
abs(ol4r - l4->r) < lighterr &&
abs(ol3g - l3->g) < lighterr &&
abs(ol4g - l4->g) < lighterr &&
abs(ol3b - l3->b) < lighterr &&
abs(ol4b - l4->b) < lighterr) ||
!wtex) {
abs(ol4b - l4->b) < lighterr) || !wtex) {
curvert -= 2;
nquads--;
} else {

View file

@ -206,8 +206,7 @@ renderents()
int e = closestent();
if (e >= 0) {
Entity *c = ents[e];
closeent =
[OFString stringWithFormat:
closeent = [OFString stringWithFormat:
@"closest entity = %@ (%d, %d, %d, %d), "
@"selection = (%d, %d)",
entnames[c.type], c.attr1, c.attr2, c.attr3, c.attr4,

View file

@ -104,8 +104,7 @@ installtex(int tnum, OFIRI *IRI, int *xs, int *ys, bool clamp)
SDL_ConvertSurface(s, format, 0);
if (converted == NULL) {
conoutf(@"texture cannot be converted "
@"to 24bpp: %@",
IRI.string);
@"to 24bpp: %@", IRI.string);
return false;
}
@ -334,8 +333,8 @@ VARFP(gamma, 30, 100, 300, {
SDL_CalculateGammaRamp(f, ramp);
if (SDL_SetWindowGammaRamp(
Cube.sharedInstance.window, ramp, ramp, ramp) == -1) {
if (SDL_SetWindowGammaRamp(Cube.sharedInstance.window,
ramp, ramp, ramp) == -1) {
conoutf(
@"Could not set gamma (card/driver doesn't support it?)");
conoutf(@"sdl: %s", SDL_GetError());
@ -355,8 +354,7 @@ transplayer()
glTranslated(-player1.origin.x,
(player1.state == CS_DEAD ? player1.eyeHeight - 0.2f : 0) -
player1.origin.z,
-player1.origin.y);
player1.origin.z, -player1.origin.y);
}
VARP(fov, 10, 105, 120);
@ -377,9 +375,9 @@ drawhudmodel(int start, int end, float speed, int base)
Player *player1 = Player.player1;
rendermodel(hudgunnames[player1.gunSelect], start, end, 0, 1.0f,
OFMakeVector3D(
player1.origin.x, player1.origin.z, player1.origin.y),
player1.yaw + 90, player1.pitch, false, 1.0f, speed, 0, base);
OFMakeVector3D(player1.origin.x, player1.origin.z,
player1.origin.y), player1.yaw + 90, player1.pitch, false, 1.0f,
speed, 0, base);
}
void

View file

@ -111,7 +111,7 @@ rendermodel(OFString *mdl, int frame, int range, int tex, float rad,
light = [OFColor colorWithRed: s->r / ll + of
green: s->g / ll + of
blue: s->b / ll + of
alpha: 1];
alpha: 1.0f];
}
if (teammate) {
@ -120,7 +120,7 @@ rendermodel(OFString *mdl, int frame, int range, int tex, float rad,
light = [OFColor colorWithRed: red * 0.6f
green: green * 0.7f
blue: blue * 1.2f
alpha: 1];
alpha: 1.0f];
}
[m renderWithLight: light

View file

@ -72,8 +72,7 @@ render_particles(int time)
} parttypes[] = {
{ 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.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.8f, 0.8f, 20, 6, 1.2f }, // yellow: fireball1
{ 0.5f, 0.5f, 0.5f, 20, 7, 0.6f }, // grey: big smoke

View file

@ -16,13 +16,10 @@ noise(int x, int y, int seed)
float
smoothednoise(int x, int y, int seed)
{
float corners =
(noise(x - 1, y - 1, seed) + noise(x + 1, y - 1, seed) +
noise(x - 1, y + 1, seed) + noise(x + 1, y + 1, seed)) /
16;
float corners = (noise(x - 1, y - 1, seed) + noise(x + 1, y - 1, seed) +
noise(x - 1, y + 1, seed) + noise(x + 1, y + 1, seed)) / 16;
float sides = (noise(x - 1, y, seed) + noise(x + 1, y, seed) +
noise(x, y - 1, seed) + noise(x, y + 1, seed)) /
8;
noise(x, y - 1, seed) + noise(x, y + 1, seed)) / 8;
float center = noise(x, y, seed) / 4;
return corners + sides + center;
}
@ -78,11 +75,9 @@ perlinarea(const struct block *b, int scale, int seed, int psize)
struct sqr *s = S(x, y);
if (!SOLID(s) && x != b->x + b->xs && y != b->y + b->ys)
s->type = FHF;
s->vdelta =
(int)(perlinnoise_2D(x / ((float)scale) + seed,
y / ((float)scale) + seed, 1000, 0.01f) *
50 +
25);
s->vdelta = (int)(perlinnoise_2D(
x / ((float)scale) + seed,
y / ((float)scale) + seed, 1000, 0.01f) * 50 + 25);
if (s->vdelta > 128)
s->vdelta = 0;
}

View file

@ -164,9 +164,9 @@ loadstate(OFIRI *IRI)
if (strncmp(buf, "CUBESAVE", 8))
goto out;
if (gzgetc(f) != islittleendian)
goto out; // not supporting save->load accross
// incompatible architectures simpifies things
// a LOT
// not supporting save->load accross incompatible architectures
// simpifies things a LOT
goto out;
if (gzgeti() != SAVEGAMEVERSION ||
gzgeti() != DynamicEntity.serializedSize)
goto out;
@ -453,8 +453,7 @@ demoplaybackstep()
}
// insert latest copy of player into history
if (extras &&
(playerhistory.count == 0 ||
if (extras && (playerhistory.count == 0 ||
playerhistory.lastObject.lastUpdate != playbacktime)) {
Player *d = [target copy];
d.lastUpdate = playbacktime;

View file

@ -399,10 +399,10 @@ resetserverifempty()
int nonlocalclients = 0;
int lastconnect = 0;
// main server update, called from cube main loop in sp, or dedicated server
// loop
void
serverslice(int seconds,
unsigned int timeout) // main server update, called from cube main loop in
// sp, or dedicated server loop
serverslice(int seconds, unsigned int timeout)
{
// spawn entities when timer reached
[sents enumerateObjectsUsingBlock:
@ -473,8 +473,7 @@ serverslice(int seconds,
char hn[1024];
c.hostname = (enet_address_get_host(
&c.peer->address, hn, sizeof(hn)) == 0
? @(hn)
: @"localhost");
? @(hn) : @"localhost");
[OFStdOut writeFormat: @"client connected (%@)\n",
c.hostname];
send_welcome(lastconnect = clients.count - 1);

View file

@ -161,8 +161,7 @@ remip(const struct block *b, int level)
// next to hfs
fh -=
o[i]->vdelta /
4 +
2;
4 + 2;
if (o[i]->type == CHF)
// FIXME: needs
// to somehow
@ -173,8 +172,7 @@ remip(const struct block *b, int level)
// higher mips
ch +=
o[i]->vdelta /
4 +
2;
4 + 2;
}
if (fh < floor)
// take lowest floor and
@ -229,24 +227,19 @@ remip(const struct block *b, int level)
if (r->type == CHF || r->type == FHF) {
if (o[0]->vdelta - o[1]->vdelta !=
o[1]->vdelta -
SWS(w, x + 2, y, ws)
->vdelta ||
SWS(w, x + 2, y, ws)->vdelta ||
o[0]->vdelta - o[2]->vdelta !=
o[2]->vdelta -
SWS(w, x + 2, y + 2, ws)
->vdelta ||
SWS(w, x + 2, y + 2, ws)->vdelta ||
o[0]->vdelta - o[3]->vdelta !=
o[3]->vdelta -
SWS(w, x, y + 2, ws)
->vdelta ||
SWS(w, x, y + 2, ws)->vdelta ||
o[3]->vdelta - o[2]->vdelta !=
o[2]->vdelta -
SWS(w, x + 2, y + 1, ws)
->vdelta ||
SWS(w, x + 2, y + 1, ws)->vdelta ||
o[1]->vdelta - o[2]->vdelta !=
o[2]->vdelta -
SWS(w, x + 1, y + 2, ws)
->vdelta)
SWS(w, x + 1, y + 2, ws)->vdelta)
goto c;
}
}

View file

@ -170,8 +170,8 @@ readmap(OFString *mname)
void
save_world(OFString *mname)
{
resettagareas(); // wouldn't be able to reproduce tagged areas
// otherwise
// wouldn't be able to reproduce tagged areas otherwise
resettagareas();
voptimize();
toptimize();
if (mname.length == 0)
@ -262,9 +262,10 @@ COMMAND(savemap, ARG_1STR, ^ (OFString *mname) {
save_world(mname);
})
// still supports all map formats that have existed since the earliest cube
// betas!
void
load_world(OFString *mname) // still supports all map formats that have existed
// since the earliest cube betas!
load_world(OFString *mname)
{
stopifrecording();
cleardlights();

View file

@ -42,11 +42,8 @@ lightray(float bx, float by, Entity *light)
// coloured light version, special case because most lights are
// white
if (light.attr3 || light.attr4) {
int dimness = rnd(
(255 -
(light.attr2 + light.attr3 + light.attr4) / 3) /
16 +
1);
int dimness = rnd((255 - (light.attr2 + light.attr3 +
light.attr4) / 3) / 16 + 1);
x += stepx * dimness;
y += stepy * dimness;
@ -148,19 +145,20 @@ void
postlightarea(const struct block *a)
{
// assumes area not on edge of world
for (int x = 0; x < a->xs; x++)
for (int x = 0; x < a->xs; x++) {
for (int y = 0; y < a->ys; y++) {
struct sqr *s = S(x + a->x, y + a->y);
// median is 4/2/1 instead
#define median(m) \
s->m = \
(s->m * 2 + SW(s, 1, 0)->m * 2 + SW(s, 0, 1)->m * 2 + \
s->m = (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, -1)->m + SW(s, -1, 1)->m + SW(s, -1, -1)->m) / \
14; // median is 4/2/1 instead
SW(s, 1, -1)->m + SW(s, -1, 1)->m + SW(s, -1, -1)->m) / 14;
median(r);
median(g);
median(b);
}
}
remip(a, 0);
}

View file

@ -43,6 +43,7 @@ computeraytable(float vx, float vy)
!OUTBORD(vx, vy) && !SOLID(S((int)vx, (int)vy))) {
float ray = i * 8 / (float)NUMRAYS;
float dx, dy;
if (ray > 1 && ray < 3) {
dx = -(ray - 2);
dy = 1;
@ -56,6 +57,7 @@ computeraytable(float vx, float vy)
dx = 1;
dy = ray > 4 ? ray - 8 : ray;
}
float sx = vx;
float sy = vy;
for (;;) {
@ -125,60 +127,64 @@ isoccluded(float vx, float vy, float cx, float cy,
// below
float h, l;
if (cx <= vx) // ABDFG
{
if (cx + csize < vx) // ADF
{
if (cy <= vy) // AD
{
if (cx <= vx) {
// ABDFG
if (cx + csize < vx) {
// ADF
if (cy <= vy) {
// AD
if (cy + csize < vy) {
// A
h = ca(-(cx - vx), -(cy + csize - vy)) +
4;
l = ca(-(cx + csize - vx), -(cy - vy)) +
4;
} // A
else {
h = ma(-(cx + csize - vx),
-(cy + csize - vy)) +
4;
l = ma(-(cx + csize - vx), -(cy - vy)) +
4;
} // D
} else {
// D
h = ma(-(cx + csize - vx),
-(cy + csize - vy)) + 4;
l = ma(-(cx + csize - vx),
-(cy - vy)) + 4;
}
} else {
// F
h = ca(cy + csize - vy, -(cx + csize - vx)) + 2;
l = ca(cy - vy, -(cx - vx)) + 2;
} // F
} else { // BG
}
} else {
// BG
if (cy <= vy) {
if (cy + csize < vy) {
// B
h = ma(-(cy + csize - vy), cx - vx) + 6;
l = ma(-(cy + csize - vy),
cx + csize - vx) +
6;
} // B
else
cx + csize - vx) + 6;
} else
return 0;
} else {
// G
h = ma(cy - vy, -(cx + csize - vx)) + 2;
l = ma(cy - vy, -(cx - vx)) + 2;
} // G
}
} else // CEH
{
if (cy <= vy) // CE
{
}
} else {
// CEH
if (cy <= vy) {
// CE
if (cy + csize < vy) {
// C
h = ca(-(cy - vy), cx - vx) + 6;
l = ca(-(cy + csize - vy), cx + csize - vx) + 6;
} // C
else {
} else {
// E
h = ma(cx - vx, cy - vy);
l = ma(cx - vx, cy + csize - vy);
} // E
}
} else {
// H
h = ca(cx + csize - vx, cy - vy);
l = ca(cx - vx, cy + csize - vy);
} // H
}
}
// get indexes into occlusion map from angles
int si = h * (NUMRAYS / 8) + NUMRAYS;
@ -186,12 +192,11 @@ isoccluded(float vx, float vy, float cx, float cy,
if (ei <= si)
ei += NUMRAYS;
for (int i = si; i <= ei; i++) {
for (int i = si; i <= ei; i++)
if (dist < rdist[i & (NUMRAYS - 1)])
// if any value in this segment of the occlusion map is
// further away then cube is not occluded
return 0;
}
return 1; // cube is entirely occluded
}

View file

@ -125,9 +125,9 @@ render_seg_new(
int sz = ssize >> mip;
int vxx = ((int)vx + (1 << mip) / 2) >> mip;
int vyy = ((int)vy + (1 << mip) / 2) >> mip;
int lx =
vxx - lodleft; // these mark the rect inside the current rest that
// we want to render using a lower mip level
// these mark the rect inside the current rest that we want to render
// using a lower mip level
int lx = vxx - lodleft;
int ly = vyy - lodtop;
int rx = vxx + lodright;
int ry = vyy + lodbot;