Index: src/.clang-format ================================================================== --- src/.clang-format +++ src/.clang-format @@ -1,11 +1,28 @@ IndentWidth: 8 TabWidth: 8 UseTab: ForIndentation -BreakBeforeBraces: Linux +ColumnLimit: 80 +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Custom +BreakBeforeTernaryOperators: true +BraceWrapping: + AfterClass: false + AfterControlStatement: false + AfterEnum: false + AfterFunction: true + AfterNamespace: false + AfterObjCDeclaration: true + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false AlwaysBreakAfterReturnType: AllDefinitions AlignAfterOpenBracket: DontAlign +AlignEscapedNewlines: Left +AlignOperands: DontAlign ObjCBlockIndentWidth: 8 ObjCSpaceAfterProperty: true ObjCSpaceBeforeProtocolList: true ObjCPropertyAttributeOrder: [ class, direct, @@ -13,7 +30,13 @@ nullable, nonnull, null_resettable, null_unspecified, assign, retain, strong, copy, weak, unsafe_unretained, atomic, nonatomic, getter, setter ] +SpaceBeforeInheritanceColon: false +QualifierAlignment: Left +#RemoveEmptyLinesInUnwrappedLines: true +RemoveSemicolon: true +CompactNamespaces: true +SortIncludes: CaseSensitive IndentPPDirectives: AfterHash PPIndentWidth: 1 Index: src/Alias.h ================================================================== --- src/Alias.h +++ src/Alias.h @@ -1,10 +1,10 @@ #import "Identifier.h" OF_ASSUME_NONNULL_BEGIN -@interface Alias : Identifier +@interface Alias: Identifier @property (copy, nonatomic) OFString *action; @property (readonly, nonatomic) bool persisted; - (instancetype)initWithName:(OFString *)name OF_UNAVAILABLE; - (instancetype)initWithName:(OFString *)name Index: src/Command.h ================================================================== --- src/Command.h +++ src/Command.h @@ -1,10 +1,10 @@ #import "Identifier.h" OF_ASSUME_NONNULL_BEGIN -@interface Command : Identifier +@interface Command: Identifier @property (readonly, nonatomic) void (*function)(); @property (readonly, nonatomic) int argumentsTypes; - (instancetype)initWithName:(OFString *)name OF_UNAVAILABLE; - (instancetype)initWithName:(OFString *)name Index: src/Cube.mm ================================================================== --- src/Cube.mm +++ src/Cube.mm @@ -5,11 +5,12 @@ OF_APPLICATION_DELEGATE(Cube) VARF(gamespeed, 10, 100, 1000, if (multiplayer()) gamespeed = 100); VARP(minmillis, 0, 5, 1000); -@implementation Cube { +@implementation Cube +{ int _width, _height; } + (Cube *)sharedInstance { Index: src/Identifier.h ================================================================== --- src/Identifier.h +++ src/Identifier.h @@ -1,10 +1,10 @@ #import OF_ASSUME_NONNULL_BEGIN -@interface Identifier : OFObject +@interface Identifier: OFObject @property (readonly, copy, nonatomic) OFString *name; - (instancetype)init OF_UNAVAILABLE; - (instancetype)initWithName:(OFString *)name; @end Index: src/KeyMapping.h ================================================================== --- src/KeyMapping.h +++ src/KeyMapping.h @@ -1,10 +1,10 @@ #import OF_ASSUME_NONNULL_BEGIN -@interface KeyMapping : OFObject +@interface KeyMapping: OFObject @property (readonly) int code; @property (readonly, nonatomic) OFString *name; @property (copy, nonatomic) OFString *action; - (instancetype)initWithCode:(int)code name:(OFString *)name; Index: src/MD2.h ================================================================== --- src/MD2.h +++ src/MD2.h @@ -2,11 +2,11 @@ OF_ASSUME_NONNULL_BEGIN @class MapModelInfo; -@interface MD2 : OFObject +@interface MD2: OFObject @property (nonatomic) MapModelInfo *mmi; @property (copy, nonatomic) OFString *loadname; @property (nonatomic) int mdlnum; @property (nonatomic) bool loaded; Index: src/MD2.mm ================================================================== --- src/MD2.mm +++ src/MD2.mm @@ -28,11 +28,12 @@ snap(int sn, float f) { return sn ? (float)(((int)(f + sn * 0.5f)) & (~(sn - 1))) : f; } -@implementation MD2 { +@implementation MD2 +{ int _numGlCommands; int *_glCommands; int _numTriangles; int _frameSize; int _numFrames; Index: src/MapModelInfo.h ================================================================== --- src/MapModelInfo.h +++ src/MapModelInfo.h @@ -1,10 +1,10 @@ #import OF_ASSUME_NONNULL_BEGIN -@interface MapModelInfo : OFObject +@interface MapModelInfo: OFObject @property (nonatomic) int rad, h, zoff, snap; @property (copy, nonatomic) OFString *name; - (instancetype)initWithRad:(int)rad h:(int)h Index: src/Menu.h ================================================================== --- src/Menu.h +++ src/Menu.h @@ -2,11 +2,11 @@ OF_ASSUME_NONNULL_BEGIN @class MenuItem; -@interface Menu : OFObject +@interface Menu: OFObject @property (readonly, nonatomic) OFString *name; @property (readonly) OFMutableArray *items; @property (nonatomic) int mwidth; @property (nonatomic) int menusel; Index: src/MenuItem.h ================================================================== --- src/MenuItem.h +++ src/MenuItem.h @@ -1,7 +1,7 @@ #import -@interface MenuItem : OFObject +@interface MenuItem: OFObject @property (readonly, nonatomic) OFString *text, *action; - (instancetype)initWithText:(OFString *)text action:(OFString *)action; @end Index: src/Variable.h ================================================================== --- src/Variable.h +++ src/Variable.h @@ -1,10 +1,10 @@ #import "Identifier.h" OF_ASSUME_NONNULL_BEGIN -@interface Variable : Identifier +@interface Variable: Identifier @property (readonly, nonatomic) int min, max; @property (readonly, nonatomic) int *storage; @property (readonly, nonatomic) void (*__cdecl function)(); @property (readonly, nonatomic) bool persisted; Index: src/client.mm ================================================================== --- src/client.mm +++ src/client.mm @@ -293,14 +293,14 @@ toservermap = @""; putint(p, nextmode); } else { putint(p, SV_POS); putint(p, clientnum); - putint( - p, (int)(d->o.x * - DMF)); // quantize coordinates to 1/16th - // of a cube, between 1 and 3 bytes + putint(p, + (int)(d->o.x * + DMF)); // quantize coordinates to 1/16th + // of a cube, between 1 and 3 bytes putint(p, (int)(d->o.y * DMF)); putint(p, (int)(d->o.z * DMF)); putint(p, (int)(d->yaw * DAF)); putint(p, (int)(d->pitch * DAF)); putint(p, (int)(d->roll * DAF)); @@ -309,14 +309,14 @@ // almost always 1 byte putint(p, (int)(d->vel.y * DVF)); putint(p, (int)(d->vel.z * DVF)); // pack rest in 1 byte: strafe:2, move:2, onfloor:1, // state:3 - putint( - p, (d->strafe & 3) | ((d->move & 3) << 2) | - (((int)d->onfloor) << 4) | - ((editmode ? CS_EDITING : d->state) << 5)); + putint(p, + (d->strafe & 3) | ((d->move & 3) << 2) | + (((int)d->onfloor) << 4) | + ((editmode ? CS_EDITING : d->state) << 5)); if (senditemstoserver) { packet->flags = ENET_PACKET_FLAG_RELIABLE; putint(p, SV_ITEMLIST); if (!m_noitems) @@ -410,6 +410,6 @@ disconnect(); else server_err(); return; } -}; +} Index: src/clientextras.mm ================================================================== --- src/clientextras.mm +++ src/clientextras.mm @@ -76,13 +76,12 @@ void renderclients() { dynent *d; loopv(players) if ((d = players[i]) && - (!demoplayback || i != democlientnum)) - renderclient(d, isteam(player1->team, d->team), @"monster/ogro", - false, 1.0f); + (!demoplayback || i != democlientnum)) renderclient(d, + isteam(player1->team, d->team), @"monster/ogro", false, 1.0f); } // creation of scoreboard pseudo-menu bool scoreson = false; Index: src/clientgame.mm ================================================================== --- src/clientgame.mm +++ src/clientgame.mm @@ -39,11 +39,11 @@ d->k_up = false; d->k_down = false; d->jumpnext = false; d->strafe = 0; d->move = 0; -}; +} void spawnstate(dynent *d) // reset player state not persistent accross spawns { resetmovement(d); @@ -93,11 +93,11 @@ d->ammo[GUN_CG] /= 2; }; } else { d->ammo[GUN_SG] = 5; }; -}; +} dynent * newdynent() // create a new blank player or monster { dynent *d = (dynent *)malloc(sizeof(dynent)); @@ -123,18 +123,18 @@ d->blocked = false; d->lifesequence = 0; d->state = CS_ALIVE; spawnstate(d); return d; -}; +} void respawnself() { spawnplayer(player1); showscores(false); -}; +} void arenacount(dynent *d, int &alive, int &dead, char *&lastteam, bool &oneteam) { if (d->state != CS_DEAD) { @@ -143,11 +143,11 @@ oneteam = false; lastteam = d->team; } else { dead++; }; -}; +} int arenarespawnwait = 0; int arenadetectwait = 0; void @@ -178,19 +178,19 @@ arenarespawnwait = lastmillis + 5000; arenadetectwait = lastmillis + 10000; player1->roll = 0; }; }; -}; +} void zapdynent(dynent *&d) { if (d) free(d); d = NULL; -}; +} extern int democlientnum; void otherplayers() @@ -205,12 +205,12 @@ if (lagtime && players[i]->state != CS_DEAD && (!demoplayback || i != democlientnum)) moveplayer( players[i], 2, false); // use physics to extrapolate // player position - }; -}; + } +} void respawn() { if (player1->state == CS_DEAD) { @@ -266,12 +266,11 @@ if (player1->state == CS_DEAD) { if (lastmillis - player1->lastaction < 2000) { player1->move = player1->strafe = 0; moveplayer(player1, 10, false); } else if (!m_arena && !m_sp && - lastmillis - player1->lastaction > - 10000) + lastmillis - player1->lastaction > 10000) respawn(); } else if (!intermission) { moveplayer(player1, 20, true); checkitems(); }; @@ -298,11 +297,11 @@ d->o.y -= dy; } conoutf(@"can't find entity spawn spot! (%d, %d)", (int)d->o.x, (int)d->o.y); // leave ent at original pos, possibly stuck -}; +} int spawncycle = -1; int fixspawn = 2; void @@ -322,21 +321,21 @@ d->o.z = 4; }; entinmap(d); spawnstate(d); d->state = CS_ALIVE; -}; +} // movement input code -#define dir(name, v, d, s, os) \ - void name(bool isdown) \ - { \ - player1->s = isdown; \ - player1->v = isdown ? d : (player1->os ? -(d) : 0); \ - player1->lastmove = lastmillis; \ - }; +#define dir(name, v, d, s, os) \ + void name(bool isdown) \ + { \ + player1->s = isdown; \ + player1->v = isdown ? d : (player1->os ? -(d) : 0); \ + player1->lastmove = lastmillis; \ + } dir(backward, move, -1, k_down, k_up); dir(forward, move, 1, k_up, k_down); dir(left, strafe, 1, k_left, k_right); dir(right, strafe, -1, k_right, k_left); @@ -348,18 +347,18 @@ return; if (editmode) editdrag(on); else if (player1->attacking = on) respawn(); -}; +} void jumpn(bool on) { if (!intermission && (player1->jumpnext = on)) respawn(); -}; +} COMMAND(backward, ARG_DOWN) COMMAND(forward, ARG_DOWN) COMMAND(left, ARG_DOWN) COMMAND(right, ARG_DOWN) @@ -377,24 +376,23 @@ player1->pitch = -MAXPITCH; while (player1->yaw < 0.0f) player1->yaw += 360.0f; while (player1->yaw >= 360.0f) player1->yaw -= 360.0f; -}; +} void mousemove(int dx, int dy) { if (player1->state == CS_DEAD || intermission) return; const float SENSF = 33.0f; // try match quake sens player1->yaw += (dx / SENSF) * (sensitivity / (float)sensitivityscale); player1->pitch -= (dy / SENSF) * - (sensitivity / (float)sensitivityscale) * - (invmouse ? -1 : 1); + (sensitivity / (float)sensitivityscale) * (invmouse ? -1 : 1); fixplayer1range(); -}; +} // damage arriving from the network, monsters, yourself, all ends up here. void selfdamage(int damage, int actor, dynent *act) @@ -402,24 +400,23 @@ if (player1->state != CS_ALIVE || editmode || intermission) return; damageblend(damage); demoblend(damage); int ad = damage * (player1->armourtype + 1) * 20 / - 100; // let armour absorb when possible + 100; // let armour absorb when possible if (ad > player1->armour) ad = player1->armour; 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 + player1->roll += player1->roll > 0 + ? droll + : (player1->roll < 0 + ? -droll + : (rnd(2) ? droll + : -droll)); // give player a kick depending + // on amount of damage if ((player1->health -= damage) <= 0) { if (actor == -2) { conoutf(@"you got killed by %s!", act->name); } else if (actor == -1) { actor = getclientnum(); Index: src/clients2c.mm ================================================================== --- src/clients2c.mm +++ src/clients2c.mm @@ -50,11 +50,11 @@ int lagtime = lastmillis - d->lastupdate; if (lagtime) { d->plag = (d->plag * 5 + lagtime) / 6; d->lastupdate = lastmillis; }; -}; +} void localservertoclient( uchar *buf, int len) // processes any updates from the server { Index: src/console.mm ================================================================== --- src/console.mm +++ src/console.mm @@ -76,17 +76,18 @@ void renderconsole() // render buffer taking into account time & scrolling { int nd = 0; char *refs[ndraw]; - loopv(conlines) if (conskip ? i >= conskip - 1 || - i >= conlines.length() - ndraw - : lastmillis - conlines[i].outtime < 20000) + loopv(conlines) { - refs[nd++] = conlines[i].cref; - if (nd == ndraw) - break; + if (conskip ? i >= conskip - 1 || i >= conlines.length() - ndraw + : lastmillis - conlines[i].outtime < 20000) { + refs[nd++] = conlines[i].cref; + if (nd == ndraw) + break; + } } @autoreleasepool { loopj(nd) { draw_text(@(refs[j]), FONTH / 3, Index: src/cube.h ================================================================== --- src/cube.h +++ src/cube.h @@ -6,11 +6,11 @@ #include #undef gamma #include "tools.h" -@interface Cube : OFObject +@interface Cube: OFObject @property (class, readonly, nonatomic) Cube *sharedInstance; @property (readonly, nonatomic) SDL_Window *window; @property (readonly, nonatomic) OFIRI *gameDataIRI, *userDataIRI; @property (nonatomic) bool repeatsKeys; @property (nonatomic) int framesInMap; @@ -78,11 +78,11 @@ short attr1; uchar type; // type is one of the above uchar attr2, attr3, attr4; }; -struct entity : public persistent_entity { +struct entity: public persistent_entity { bool spawned; // the only dynamic state of a map entity }; #define MAPVERSION 5 // bump if map format changes, see worldio.cpp @@ -105,12 +105,12 @@ #define SMALLEST_FACTOR 6 // determines number of mips there can be #define DEFAULT_FACTOR 8 #define LARGEST_FACTOR 11 // 10 is already insane #define SOLID(x) ((x)->type == SOLID) #define MINBORD 2 // 2 cubes from the edge of the world are always solid -#define OUTBORD(x, y) \ - ((x) < MINBORD || (y) < MINBORD || (x) >= ssize - MINBORD || \ +#define OUTBORD(x, y) \ + ((x) < MINBORD || (y) < MINBORD || (x) >= ssize - MINBORD || \ (y) >= ssize - MINBORD) struct block { int x, y, xs, ys; }; @@ -159,11 +159,11 @@ OFVector3D attacktarget; // delayed attacks int anger; // how many times already hit by fellow monster string name, team; }; -#define SAVEGAMEVERSION \ +#define SAVEGAMEVERSION \ 4 // bump if dynent/netprotocol changes or any other savegame/demo data enum { A_BLUE, A_GREEN, A_YELLOW }; // armour types... take 20/40/60 % off enum { M_NONE = 0, @@ -314,54 +314,54 @@ #define PI (3.1415927f) #define PI2 (2 * PI) // simplistic vector ops #define dotprod(u, v) ((u).x * (v).x + (u).y * (v).y + (u).z * (v).z) -#define vmul(u, f) \ - { \ - (u).x *= (f); \ - (u).y *= (f); \ - (u).z *= (f); \ - } -#define vdiv(u, f) \ - { \ - (u).x /= (f); \ - (u).y /= (f); \ - (u).z /= (f); \ - } -#define vadd(u, v) \ - { \ - (u).x += (v).x; \ - (u).y += (v).y; \ - (u).z += (v).z; \ - }; -#define vsub(u, v) \ - { \ - (u).x -= (v).x; \ - (u).y -= (v).y; \ - (u).z -= (v).z; \ - }; -#define vdist(d, v, e, s) \ - OFVector3D v = s; \ - vsub(v, e); \ - float d = (float)sqrt(dotprod(v, v)); -#define vreject(v, u, max) \ - ((v).x > (u).x + (max) || (v).x < (u).x - (max) || \ - (v).y > (u).y + (max) || (v).y < (u).y - (max)) -#define vlinterp(v, f, u, g) \ - { \ - (v).x = (v).x * f + (u).x * g; \ - (v).y = (v).y * f + (u).y * g; \ - (v).z = (v).z * f + (u).z * g; \ - } - -#define sgetstr() \ - { \ - char *t = text; \ - do { \ - *t = getint(p); \ - } while (*t++); \ +#define vmul(u, f) \ + { \ + (u).x *= (f); \ + (u).y *= (f); \ + (u).z *= (f); \ + } +#define vdiv(u, f) \ + { \ + (u).x /= (f); \ + (u).y /= (f); \ + (u).z /= (f); \ + } +#define vadd(u, v) \ + { \ + (u).x += (v).x; \ + (u).y += (v).y; \ + (u).z += (v).z; \ + }; +#define vsub(u, v) \ + { \ + (u).x -= (v).x; \ + (u).y -= (v).y; \ + (u).z -= (v).z; \ + }; +#define vdist(d, v, e, s) \ + OFVector3D v = s; \ + vsub(v, e); \ + float d = (float)sqrt(dotprod(v, v)); +#define vreject(v, u, max) \ + ((v).x > (u).x + (max) || (v).x < (u).x - (max) || \ + (v).y > (u).y + (max) || (v).y < (u).y - (max)) +#define vlinterp(v, f, u, g) \ + { \ + (v).x = (v).x * f + (u).x * g; \ + (v).y = (v).y * f + (u).y * g; \ + (v).z = (v).z * f + (u).z * g; \ + } + +#define sgetstr() \ + { \ + char *t = text; \ + do { \ + *t = getint(p); \ + } while (*t++); \ } // used by networking #define m_noitems (gamemode >= 4) #define m_noitemsrail (gamemode <= 5) #define m_arena (gamemode >= 8) @@ -392,35 +392,35 @@ ARG_VARI }; // nasty macros for registering script functions, abuses globals to avoid // excessive infrastructure -#define COMMANDN(name, fun, nargs) \ - OF_CONSTRUCTOR() \ - { \ - enqueueInit(^{ \ - addcommand(@ #name, (void (*)())fun, nargs); \ - }); \ +#define COMMANDN(name, fun, nargs) \ + OF_CONSTRUCTOR() \ + { \ + enqueueInit(^{ \ + addcommand(@ #name, (void (*)())fun, nargs); \ + }); \ } #define COMMAND(name, nargs) COMMANDN(name, name, nargs) -#define VARP(name, min, cur, max) \ - int name; \ - OF_CONSTRUCTOR() \ - { \ - enqueueInit(^{ \ - name = variable( \ - @ #name, min, cur, max, &name, NULL, true); \ - }); \ - } -#define VAR(name, min, cur, max) \ - int name; \ - OF_CONSTRUCTOR() \ - { \ - enqueueInit(^{ \ - name = variable( \ - @ #name, min, cur, max, &name, NULL, false); \ - }); \ +#define VARP(name, min, cur, max) \ + int name; \ + OF_CONSTRUCTOR() \ + { \ + enqueueInit(^{ \ + name = variable( \ + @ #name, min, cur, max, &name, NULL, true); \ + }); \ + } +#define VAR(name, min, cur, max) \ + int name; \ + OF_CONSTRUCTOR() \ + { \ + enqueueInit(^{ \ + name = variable( \ + @ #name, min, cur, max, &name, NULL, false); \ + }); \ } #define VARF(name, min, cur, max, body) \ void var_##name(); \ static int name; \ OF_CONSTRUCTOR() \ @@ -429,20 +429,20 @@ name = variable( \ @ #name, min, cur, max, &name, var_##name, false); \ }); \ } \ void var_##name() { body; } -#define VARFP(name, min, cur, max, body) \ - void var_##name(); \ - static int name; \ - OF_CONSTRUCTOR() \ - { \ - enqueueInit(^{ \ - name = variable( \ - @ #name, min, cur, max, &name, var_##name, true); \ - }); \ - } \ +#define VARFP(name, min, cur, max, body) \ + void var_##name(); \ + static int name; \ + OF_CONSTRUCTOR() \ + { \ + enqueueInit(^{ \ + name = variable( \ + @ #name, min, cur, max, &name, var_##name, true); \ + }); \ + } \ void var_##name() { body; } #define ATOI(s) strtol(s, NULL, 0) // supports hexadecimal numbers #ifdef WIN32 Index: src/editing.mm ================================================================== --- src/editing.mm +++ src/editing.mm @@ -24,19 +24,19 @@ } int selh = 0; bool selset = false; -#define loopselxy(b) \ - { \ - makeundo(); \ - loop(x, sel.xs) loop(y, sel.ys) \ - { \ - sqr *s = S(sel.x + x, sel.y + y); \ - b; \ - }; \ - remip(sel); \ +#define loopselxy(b) \ + { \ + makeundo(); \ + loop(x, sel.xs) loop(y, sel.ys) \ + { \ + sqr *s = S(sel.x + x, sel.y + y); \ + b; \ + } \ + remip(sel); \ } int cx, cy, ch; int curedittex[] = {-1, -1, -1}; @@ -84,11 +84,11 @@ sel.xs = bsize - sel.x; if (sel.ys + sel.y > bsize) sel.ys = bsize - sel.y; if (sel.xs <= 0 || sel.ys <= 0) selset = false; -}; +} bool noteditmode() { correctsel(); @@ -103,28 +103,28 @@ if (!selset) conoutf(@"no selection"); return !selset; } -#define EDITSEL \ - if (noteditmode() || noselection()) \ - return; -#define EDITSELMP \ - if (noteditmode() || noselection() || multiplayer()) \ - return; -#define EDITMP \ - if (noteditmode() || multiplayer()) \ +#define EDITSEL \ + if (noteditmode() || noselection()) \ + return; +#define EDITSELMP \ + if (noteditmode() || noselection() || multiplayer()) \ + return; +#define EDITMP \ + if (noteditmode() || multiplayer()) \ return; void selectpos(int x, int y, int xs, int ys) { block s = {x, y, xs, ys}; sel = s; selh = 0; correctsel(); -}; +} void makesel() { block s = {min(lastx, cx), min(lasty, cy), abs(lastx - cx) + 1, @@ -132,24 +132,22 @@ sel = s; selh = max(lasth, ch); correctsel(); if (selset) rtex = *S(sel.x, sel.y); -}; +} VAR(flrceil, 0, 0, 2); float sheight( sqr *s, sqr *t, float z) // finds out z height when cursor points at wall { return !flrceil // z-s->floorceil-z - ? (s->type == FHF ? s->floor - t->vdelta / 4.0f - : (float)s->floor) - : (s->type == CHF ? s->ceil + t->vdelta / 4.0f - : (float)s->ceil); -}; + ? (s->type == FHF ? s->floor - t->vdelta / 4.0f : (float)s->floor) + : (s->type == CHF ? s->ceil + t->vdelta / 4.0f : (float)s->ceil); +} void cursorupdate() // called every frame from hud { flrceil = ((int)(player1->pitch >= 0)) * 2; @@ -233,11 +231,11 @@ if (selset) { linestyle(GRIDS, 0xFF, 0x40, 0x40); box(sel, (float)selh, (float)selh, (float)selh, (float)selh); }; -}; +} vector undos; // unlimited undo VARP(undomegs, 0, 1, 10); // bounded by n megs void @@ -247,19 +245,19 @@ loopvrev(undos) { t += undos[i]->xs * undos[i]->ys * sizeof(sqr); if (t > maxremain) free(undos.remove(i)); - }; -}; + } +} void makeundo() { undos.add(blockcopy(sel)); pruneundos(undomegs << 20); -}; +} void editundo() { EDITMP; @@ -279,11 +277,11 @@ { EDITSELMP; if (copybuf) free(copybuf); copybuf = blockcopy(sel); -}; +} void paste() { EDITMP; @@ -317,12 +315,12 @@ for (int a = c - 1; a >= 0; a--) p[a + 1] = p[a]; p[0] = t; curedittex[i] = -1; }; - }; -}; + } +} void editdrag(bool isdown) { if (dragging = isdown) { @@ -331,11 +329,11 @@ lasth = ch; selset = false; tofronttex(); }; makesel(); -}; +} // the core editing function. all the *xy functions perform the core operations // and are also called directly from the network, the function below it is // strictly triggered locally. They all have very similar structure. @@ -350,11 +348,11 @@ } else { s->ceil += amount; if (s->ceil <= s->floor) s->ceil = s->floor + 1; }); -}; +} void editheight(int flr, int amount) { EDITSEL; @@ -379,11 +377,11 @@ break; case 3: s->utex = t; break; }); -}; +} void edittex(int type, int dir) { EDITSEL; @@ -398,11 +396,11 @@ i = i < 0 ? 0 : i + dir; curedittex[atype] = i = min(max(i, 0), 255); int t = lasttex = hdr.texlists[atype][i]; edittexxy(type, t, sel); addmsg(1, 7, SV_EDITT, sel.x, sel.y, sel.xs, sel.ys, type, t); -}; +} void replace() { EDITSELMP; @@ -425,20 +423,20 @@ case 3: if (s->utex == rtex.utex) s->utex = lasttex; break; }; - }; + } block b = {0, 0, ssize, ssize}; remip(b); -}; +} void edittypexy(int type, block &sel) { loopselxy(s->type = type); -}; +} void edittype(int type) { EDITSEL; @@ -489,11 +487,11 @@ else s->ceil = hi; if (s->floor >= s->ceil) s->floor = s->ceil - 1; }); -}; +} void equalize(int flr) { bool isfloor = flr == 0; @@ -506,19 +504,19 @@ void setvdeltaxy(int delta, block &sel) { loopselxy(s->vdelta = max(s->vdelta + delta, 0)); remipmore(sel); -}; +} void setvdelta(int delta) { EDITSEL; setvdeltaxy(delta, sel); addmsg(1, 6, SV_EDITD, sel.x, sel.y, sel.xs, sel.ys, delta); -}; +} const int MAXARCHVERT = 50; int archverts[MAXARCHVERT][MAXARCHVERT]; bool archvinit = false; @@ -530,11 +528,11 @@ loop(s, MAXARCHVERT) loop(v, MAXARCHVERT) archverts[s][v] = 0; }; if (span >= MAXARCHVERT || vert >= MAXARCHVERT || span < 0 || vert < 0) return; archverts[span][vert] = delta; -}; +} void arch(int sidedelta, int _a) { EDITSELMP; @@ -542,18 +540,17 @@ sel.ys++; if (sel.xs > MAXARCHVERT) sel.xs = MAXARCHVERT; if (sel.ys > MAXARCHVERT) sel.ys = MAXARCHVERT; - 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); -}; +} void slope(int xd, int yd) { EDITSELMP; @@ -564,11 +561,11 @@ off -= yd * sel.ys; sel.xs++; sel.ys++; loopselxy(s->vdelta = xd * x + yd * y + off); remipmore(sel); -}; +} void perlin(int scale, int seed, int psize) { EDITSELMP; @@ -581,11 +578,11 @@ sel.xs++; sel.ys++; remipmore(sel); sel.xs--; sel.ys--; -}; +} VARF( fullbright, 0, 0, 1, if (fullbright) { if (noteditmode()) return; @@ -595,11 +592,11 @@ void edittag(int tag) { EDITSELMP; loopselxy(s->tag = tag); -}; +} void newent(OFString *what, OFString *a1, OFString *a2, OFString *a3, OFString *a4) { EDITSEL; Index: src/entities.mm ================================================================== --- src/entities.mm +++ src/entities.mm @@ -25,11 +25,11 @@ renderent(entity &e, OFString *mdlname, float z, float yaw, int frame = 0, int numf = 1, int basetime = 0, float speed = 10.0f) { rendermodel(mdlname, frame, numf, 0, 1.1f, e.x, z + S(e.x, e.y)->floor, e.y, yaw, 0, false, 1.0f, speed, 0, basetime); -}; +} void renderentities() { if (lastmillis > triggertime + 1000) @@ -57,13 +57,13 @@ if (!e.spawned && e.type != TELEPORT) continue; 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), + (float)(1 + + sin(lastmillis / 100.0 + e.x + e.y) / + 20), lastmillis / 10.0f); } else switch (e.attr2) { case 1: case 3: @@ -72,13 +72,14 @@ case 2: case 0: if (!e.spawned) continue; renderent(e, @"carrot", - (float)(1 + sin(lastmillis / 100.0 + - e.x + e.y) / - 20), + (float)(1 + + sin(lastmillis / 100.0 + e.x + + e.y) / + 20), lastmillis / (e.attr2 ? 1.0f : 10.0f)); break; case 4: @@ -98,12 +99,12 @@ : 30, triggertime, 35.0f); break; }; }; - }; -}; + } +} struct itemstat { int add, max, sound; } itemstats[] = { 10, @@ -137,11 +138,11 @@ void baseammo(int gun) { player1->ammo[gun] = itemstats[gun - 1].add * 2; -}; +} // these two functions are called when the server acknowledges that you really // picked up the item (in multiplayer someone may grab it before you). void @@ -151,11 +152,11 @@ ents[i].spawned = false; v += is.add; if (v > is.max) v = is.max; playsoundc(is.sound); -}; +} void realpickup(int n, dynent *d) { switch (ents[n].type) { @@ -232,11 +233,11 @@ entinmap(d); playsoundc(S_TELEPORT); break; }; }; -}; +} void pickup(int n, dynent *d) { int np = 1; @@ -344,11 +345,11 @@ void putitems(uchar *&p) // puts items in network stream and also spawns them locally { loopv(ents) if ((ents[i].type >= I_SHELLS && ents[i].type <= I_QUAD) || - ents[i].type == CARROT) + ents[i].type == CARROT) { putint(p, i); ents[i].spawned = true; } } @@ -355,12 +356,12 @@ void resetspawns() { loopv(ents) ents[i].spawned = false; -}; +} void setspawn(uint i, bool on) { if (i < (uint)ents.length()) ents[i].spawned = on; -}; +} Index: src/monster.mm ================================================================== --- src/monster.mm +++ src/monster.mm @@ -82,11 +82,11 @@ @autoreleasepool { strcpy_s(m->name, t->name.UTF8String); } monsters.add(m); return m; -}; +} void spawnmonster() // spawn a random monster according to freq distribution in DMSP { int n = rnd(TOTMFREQ), type; @@ -94,11 +94,11 @@ if ((n -= monstertypes[i].freq) < 0) { type = i; break; }; basicmonster(type, rnd(360), M_SEARCH, 1000, 1); -}; +} void monsterclear() // called after map start of when toggling edit mode to // reset/spawn all monsters to initial state { @@ -119,13 +119,13 @@ m->o.x = ents[i].x; m->o.y = ents[i].y; m->o.z = ents[i].z; entinmap(m); monstertotal++; - }; + } }; -}; +} bool los(float lx, float ly, float lz, float bx, float by, float bz, OFVector3D &v) // height-correct line of sight for monster shooting/seeing { @@ -158,19 +158,19 @@ x += dx / (float)steps; y += dy / (float)steps; i++; }; return i >= steps; -}; +} bool enemylos(dynent *m, OFVector3D &v) { v = m->o; return los(m->o.x, m->o.y, m->o.z, m->enemy->o.x, m->enemy->o.y, m->enemy->o.z, v); -}; +} // monster AI is sequenced using transitions: they are in a particular state // where they execute a particular behaviour until the trigger time is hit, and // then they reevaluate their situation based on the current state, the // environment etc., and transition to the next state. Transition timeframes are @@ -183,20 +183,20 @@ { m->monsterstate = state; m->move = moving; n = n * 130 / 100; m->trigger = lastmillis + n - skill * (n / 16) + rnd(r + 1); -}; +} void normalise(dynent *m, float angle) { while (m->yaw < angle - 180.0f) m->yaw += 360.0f; while (m->yaw > angle + 180.0f) m->yaw -= 360.0f; -}; +} void monsteraction( dynent *m) // main AI thinking routine, called every frame for every monster { @@ -221,17 +221,17 @@ if (m->blocked) // special case: if we run into scenery { m->blocked = false; if (!rnd(20000 / - monstertypes[m->mtype] - .speed)) // try to jump over obstackle (rare) + monstertypes[m->mtype] + .speed)) // try to jump over obstackle (rare) { m->jumpnext = true; } else if (m->trigger < lastmillis && - (m->monsterstate != M_HOME || - !rnd(5))) // search for a way around (common) + (m->monsterstate != M_HOME || + !rnd(5))) // search for a way around (common) { m->targetyaw += 180 + rnd(180); // patented "random walk" AI // pathfinding (tm) ;) transition(m, M_SEARCH, 1, 400, 1000); @@ -310,11 +310,11 @@ }; break; }; moveplayer(m, 1, false); // use physics to move monster -}; +} void monsterpain(dynent *m, int damage, dynent *d) { if (d->monsterstate) // a monster hit us @@ -345,11 +345,11 @@ if (remain > 0 && remain <= 5) conoutf(@"only %d monster(s) remaining", remain); } else { playsound(monstertypes[m->mtype].painsound, &m->o); } -}; +} void endsp(bool allkilled) { conoutf(allkilled ? @"you have cleared the map!" @@ -395,12 +395,12 @@ v.z += monsters[i]->eyeheight; vdist(dist, t, monsters[i]->o, v); v.z -= monsters[i]->eyeheight; if (dist < 4) teleport((int)(&e - &ents[0]), monsters[i]); - }; - }; + } + } loopv(monsters) if (monsters[i]->state == CS_ALIVE) monsteraction(monsters[i]); } Index: src/physics.mm ================================================================== --- src/physics.mm +++ src/physics.mm @@ -29,11 +29,11 @@ headspace = d->o.z - o->o.z - o->aboveeye - d->eyeheight; if (headspace < 0) headspace = 10; }; return true; -}; +} bool cornertest(int mip, int x, int y, int dx, int dy, int &bx, int &by, int &bs) // recursively collide with a mipmapped corner cube { @@ -49,11 +49,11 @@ by = y << mip; bs = 1 << mip; return cornertest(mip, x, y, dx, dy, bx, by, bs); }; return stest; -}; +} void mmcollide(dynent *d, float &hi, float &lo) // collide with a mapmodel { loopv(ents) @@ -95,13 +95,13 @@ const int y1 = fast_f2nat(fy1); const int x2 = fast_f2nat(fx2); const int y2 = fast_f2nat(fy2); float hi = 127, lo = -128; float minfloor = (d->monsterstate && !spawn && d->health > 100) - ? d->o.z - d->eyeheight - 4.5f - : -1000.0f; // big monsters are afraid of heights, - // unless angry :) + ? d->o.z - d->eyeheight - 4.5f + : -1000.0f; // big monsters are afraid of heights, + // unless angry :) for (int x = x1; x <= x2; x++) for (int y = y1; y <= y2; y++) // collide with map { if (OUTBORD(x, y)) @@ -137,18 +137,18 @@ case FHF: // FIXME: too simplistic collision with // slopes, makes it feels like tiny stairs floor -= (s->vdelta + S(x + 1, y)->vdelta + S(x, y + 1)->vdelta + S(x + 1, y + 1)->vdelta) / - 16.0f; + 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; + 16.0f; }; if (ceil < hi) hi = ceil; if (floor > lo) lo = floor; @@ -165,19 +165,19 @@ dynent *o = players[i]; if (!o || o == d) continue; if (!plcollide(d, o, headspace, hi, lo)) return false; - }; + } if (d != player1) if (!plcollide(d, player1, headspace, hi, lo)) return false; dvector &v = getmonsters(); // this loop can be a performance bottleneck with many monster on a slow // cpu, should replace with a blockmap but seems mostly fast enough loopv(v) if (!vreject(d->o, v[i]->o, 7.0f) && d != v[i] && - !plcollide(d, v[i], headspace, hi, lo)) return false; + !plcollide(d, v[i], headspace, hi, lo)) return false; headspace -= 0.01f; mmcollide(d, hi, lo); // collide with map models if (spawn) { @@ -211,11 +211,11 @@ float rad(float x) { return x * 3.14159f / 180; -}; +} VARP(maxroll, 0, 3, 20); int physicsfraction = 0, physicsrepeat = 0; const int MINFRAMETIME = 20; // physics always simulated at 50fps or better @@ -228,11 +228,11 @@ physicsrepeat = faketime / MINFRAMETIME; physicsfraction = faketime - physicsrepeat * MINFRAMETIME; } else { physicsrepeat = 1; }; -}; +} // main physics routine, moves a player/monster for a curtime step // moveres indicated the physics precision (which is lower for monsters and // multiplayer prediction) local is false for multiplayer prediction @@ -295,12 +295,12 @@ if (local) playsoundc(S_JUMP); else if (pl->monsterstate) playsound(S_JUMP, &pl->o); } else if (pl->timeinair > - 800) // if we land after long time must have - // been a high jump, make thud sound + 800) // if we land after long time must have + // been a high jump, make thud sound { if (local) playsoundc(S_LAND); else if (pl->monsterstate) playsound(S_LAND, &pl->o); @@ -310,22 +310,19 @@ pl->timeinair += curtime; }; const float gravity = 20; const float f = 1.0f / moveres; - float dropf = - ((gravity - 1) + - pl->timeinair / 15.0f); // incorrect, but works fine + float dropf = ((gravity - 1) + + pl->timeinair / 15.0f); // incorrect, but works fine if (water) { dropf = 5; 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 - const float rise = - speed / moveres / + const float rise = speed / moveres / 1.2f; // extra smoothness when lifting up stairs loopi(moveres) // discrete steps collision detection & sliding { // try move forward @@ -357,22 +354,21 @@ d.y = d.x = 0; continue; }; pl->o.z -= f * d.z; break; - }; + } }; // detect wether player is outside map, used for skipping zbuffer clear // mostly if (pl->o.x < 0 || pl->o.x >= ssize || pl->o.y < 0 || pl->o.y > ssize) { pl->outsidemap = true; } else { sqr *s = S((int)pl->o.x, (int)pl->o.y); - pl->outsidemap = - SOLID(s) || + pl->outsidemap = SOLID(s) || pl->o.z < s->floor - (s->type == FHF ? s->vdelta / 4 : 0) || pl->o.z > s->ceil + (s->type == CHF ? s->vdelta / 4 : 0); }; // automatically apply smooth roll when strafing @@ -393,14 +389,14 @@ playsound(S_SPLASH2, &pl->o); pl->vel.z = 0; } else if (pl->inwater && !water) playsound(S_SPLASH1, &pl->o); pl->inwater = water; -}; +} void moveplayer(dynent *pl, int moveres, bool local) { loopi(physicsrepeat) moveplayer(pl, moveres, local, i ? curtime / physicsrepeat : curtime - curtime / physicsrepeat * (physicsrepeat - 1)); -}; +} Index: src/rendercubes.mm ================================================================== --- src/rendercubes.mm +++ src/rendercubes.mm @@ -27,33 +27,33 @@ // generating the actual vertices is done dynamically every frame and sits at // the leaves of all these functions, and are part of the cpu bottleneck on // really slow machines, hence the macros. -#define vertcheck() \ - { \ - if (curvert >= curmaxverts) \ - reallocv(); \ - } - -#define vertf(v1, v2, v3, ls, t1, t2) \ - { \ - vertex &v = verts[curvert++]; \ - v.u = t1; \ - v.v = t2; \ - v.x = v1; \ - v.y = v2; \ - v.z = v3; \ - v.r = ls->r; \ - v.g = ls->g; \ - v.b = ls->b; \ - v.a = 255; \ - }; - -#define vert(v1, v2, v3, ls, t1, t2) \ - { \ - vertf((float)(v1), (float)(v2), (float)(v3), ls, t1, t2); \ +#define vertcheck() \ + { \ + if (curvert >= curmaxverts) \ + reallocv(); \ + } + +#define vertf(v1, v2, v3, ls, t1, t2) \ + { \ + vertex &v = verts[curvert++]; \ + v.u = t1; \ + v.v = t2; \ + v.x = v1; \ + v.y = v2; \ + v.z = v3; \ + v.r = ls->r; \ + v.g = ls->g; \ + v.b = ls->b; \ + v.a = 255; \ + }; + +#define vert(v1, v2, v3, ls, t1, t2) \ + { \ + vertf((float)(v1), (float)(v2), (float)(v3), ls, t1, t2); \ } int nquads; const float TEXTURESCALE = 32.0f; bool floorstrip = false, deltastrip = false; @@ -74,22 +74,22 @@ { if (showm) conoutf(@"1x1/2x2/4x4: %d / %d / %d", a, b, c); } -#define stripend() \ - { \ - if (floorstrip || deltastrip) { \ - addstrip(ogltex, firstindex, curvert - firstindex); \ - floorstrip = deltastrip = false; \ - }; \ +#define stripend() \ + { \ + if (floorstrip || deltastrip) { \ + addstrip(ogltex, firstindex, curvert - firstindex); \ + floorstrip = deltastrip = false; \ + }; \ }; void finishstrips() { stripend(); -}; +} sqr sbright, sdark; VAR(lighterror, 1, 8, 100); void @@ -110,11 +110,11 @@ float ys = size * yf; float xo = xf * x; float yo = yf * y; bool first = !floorstrip || y != oy + size || ogltex != gltex || - h != oh || x != ox; + h != oh || x != ox; if (first) // start strip here { stripend(); firstindex = curvert; @@ -168,11 +168,11 @@ vert(x + size, h, y + size, l3, xo + xs, yo + ys); }; oy = y; nquads++; -}; +} void render_flatdelta(int wtex, int x, int y, int size, float h1, float h2, float h3, float h4, sqr *l1, sqr *l2, sqr *l3, sqr *l4, bool isceil) // floor/ceil quads on a slope @@ -226,11 +226,11 @@ (float)x + size, h3, (float)y + size, l3, xo + xs, yo + ys); }; oy = y; nquads++; -}; +} void render_2tris(sqr *h, sqr *s, int x1, int y1, int x2, int y2, int x3, int y3, sqr *l1, sqr *l2, sqr *l3) // floor/ceil tris on a corner cube { @@ -254,11 +254,11 @@ vertf((float)x3, h->ceil, (float)y3, l3, xf * x3, yf * y3); vertf((float)x2, h->ceil, (float)y2, l2, xf * x2, yf * y2); vertf((float)x1, h->ceil, (float)y1, l1, xf * x1, yf * y1); addstrip(gltex, curvert - 3, 3); nquads++; -}; +} void render_tris(int x, int y, int size, bool topleft, sqr *h1, sqr *h2, sqr *s, sqr *t, sqr *u, sqr *v) { @@ -275,11 +275,11 @@ h1, s, x, y, x + size, y, x, y + size, s, t, u); if (h2) render_2tris(h2, s, x + size, y, x + size, y + size, x, y + size, t, u, v); }; -}; +} void render_square(int wtex, float floor1, float floor2, float ceil1, float ceil2, int x1, int y1, int x2, int y2, int size, sqr *l1, sqr *l2, bool flip) // wall quads @@ -310,11 +310,11 @@ vertf((float)x2, floor2, (float)y2, l2, xo + xs, -floor2 * yf); }; nquads++; addstrip(gltex, curvert - 4, 4); -}; +} int wx1, wy1, wx2, wy2; VAR(watersubdiv, 1, 4, 64); VARF(waterlevel, -128, -128, 127, @@ -324,22 +324,22 @@ vertw(int v1, float v2, int v3, sqr *c, float t1, float t2, float t) { vertcheck(); vertf((float)v1, v2 - (float)sin(v1 * v3 * 0.1 + t) * 0.2f, (float)v3, c, t1, t2); -}; +} inline float dx(float x) { return x + (float)sin(x * 2 + lastmillis / 1000.0f) * 0.04f; -}; +} inline float dy(float x) { return x + (float)sin(x * 2 + lastmillis / 900.0f + PI / 5) * 0.05f; -}; +} // renders water for bounding rect area that contains water... simple but very // inefficient int @@ -389,11 +389,11 @@ glDisable(GL_BLEND); glDepthMask(GL_TRUE); return nquads; -}; +} void addwaterquad(int x, int y, int size) // update bounding rect that contains water { int x2 = x + size; @@ -411,11 +411,11 @@ if (x2 > wx2) wx2 = x2; if (y2 > wy2) wy2 = y2; }; -}; +} void resetcubes() { if (!verts) @@ -423,6 +423,6 @@ floorstrip = deltastrip = false; wx1 = -1; nquads = 0; sbright.r = sbright.g = sbright.b = 255; sdark.r = sdark.g = sdark.b = 0; -}; +} Index: src/renderextras.mm ================================================================== --- src/renderextras.mm +++ src/renderextras.mm @@ -10,18 +10,18 @@ glVertex3f((float)x1, z1, y1 + 0.01f); glVertex3f((float)x2, z2, y2 + 0.01f); glVertex3f((float)x2, z2, (float)y2); glEnd(); xtraverts += 4; -}; +} void linestyle(float width, int r, int g, int b) { glLineWidth(width); glColor3ub(r, g, b); -}; +} void box(block &b, float z1, float z2, float z3, float z4) { glBegin(GL_POLYGON); @@ -29,11 +29,11 @@ glVertex3f((float)b.x + b.xs, z2, (float)b.y); glVertex3f((float)b.x + b.xs, z3, (float)b.y + b.ys); glVertex3f((float)b.x, z4, (float)b.y + b.ys); glEnd(); xtraverts += 4; -}; +} void dot(int x, int y, float z) { const float DOF = 0.1f; @@ -42,11 +42,11 @@ glVertex3f(x + DOF, (float)z, y - DOF); glVertex3f(x + DOF, (float)z, y + DOF); glVertex3f(x - DOF, (float)z, y + DOF); glEnd(); xtraverts += 4; -}; +} void blendbox(int x1, int y1, int x2, int y2, bool border) { glDepthMask(GL_FALSE); @@ -74,11 +74,11 @@ glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); xtraverts += 8; glEnable(GL_BLEND); glEnable(GL_TEXTURE_2D); glDepthMask(GL_TRUE); -}; +} const int MAXSPHERES = 50; struct sphere { OFVector3D o; float size, max; @@ -94,11 +94,11 @@ if (!sinit) { loopi(MAXSPHERES) { spheres[i].next = sempty; sempty = &spheres[i]; - }; + } sinit = true; }; if (sempty) { sphere *p = sempty; sempty = p->next; @@ -107,11 +107,11 @@ p->size = 1; p->type = type; p->next = slist; slist = p; }; -}; +} void renderspheres(int time) { glDepthMask(GL_FALSE); @@ -142,11 +142,11 @@ }; }; glDisable(GL_BLEND); glDepthMask(GL_TRUE); -}; +} string closeent; OFString *entnames[] = { @"none?", @"light", @@ -241,20 +241,20 @@ readmatrices() { glGetIntegerv(GL_VIEWPORT, viewport); glGetDoublev(GL_MODELVIEW_MATRIX, mm); glGetDoublev(GL_PROJECTION_MATRIX, pm); -}; +} // stupid function to cater for stupid ATI linux drivers that return incorrect // depth values float depthcorrect(float d) { return (d <= 1 / 256.0f) ? d * 256 : d; -}; +} // find out the 3d target of the crosshair in the world easily and very // acurately. sadly many very old cards and drivers appear to fuck up on // glReadPixels() and give false coordinates, making shooting and such // impossible. also hits map entities which is unwanted. could be replaced by a @@ -272,11 +272,11 @@ worldpos.y = (float)worldy; worldpos.z = (float)worldz; OFVector3D r = OFMakeVector3D(mm[0], mm[4], mm[8]); OFVector3D u = OFMakeVector3D(mm[1], mm[5], mm[9]); setorient(r, u); -}; +} void drawicon(float tx, float ty, int x, int y) { glBindTexture(GL_TEXTURE_2D, 5); @@ -293,11 +293,11 @@ glVertex2i(x + s, y + s); glTexCoord2f(tx, ty + o); glVertex2i(x, y + s); glEnd(); xtraverts += 4; -}; +} void invertperspective() { // This only generates a valid inverse matrix for matrices generated by @@ -310,20 +310,20 @@ inv[2 * 4 + 3] = 1.0 / pm[3 * 4 + 2]; inv[3 * 4 + 2] = -1.0; inv[3 * 4 + 3] = pm[2 * 4 + 2] / pm[3 * 4 + 2]; glLoadMatrixd(inv); -}; +} VARP(crosshairsize, 0, 15, 50); int dblend = 0; void damageblend(int n) { dblend += n; -}; +} VAR(hidestats, 0, 0, 1); VARP(crosshairfx, 0, 1, 1); void Index: src/rendergl.mm ================================================================== --- src/rendergl.mm +++ src/rendergl.mm @@ -61,11 +61,11 @@ gluQuadricOrientation(qsphere, GLU_INSIDE); gluQuadricTexture(qsphere, GL_TRUE); glNewList(1, GL_COMPILE); gluSphere(qsphere, 1, 12, 6); glEndList(); -}; +} void cleangl() { if (qsphere) @@ -172,11 +172,11 @@ void purgetextures() { loopi(256) loop(j, MAXFRAMES) mapping[i][j] = 0; -}; +} int curtexnum = 0; void texturereset() @@ -263,11 +263,11 @@ glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_MODULATE); glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE); glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_PRIMARY_COLOR_EXT); }; -}; +} int skyoglid; struct strip { int tex, start, num; @@ -337,11 +337,11 @@ glTranslated(-player1->o.x, (player1->state == CS_DEAD ? player1->eyeheight - 0.2f : 0) - player1->o.z, -player1->o.y); -}; +} VARP(fov, 10, 105, 120); int xtraverts; @@ -388,11 +388,11 @@ glLoadIdentity(); gluPerspective(fovy, aspect, 0.15f, farplane); glMatrixMode(GL_MODELVIEW); glDisable(GL_CULL_FACE); -}; +} void gl_drawframe(int w, int h, float curfps) { float hf = hdr.waterlevel - 0.3f; @@ -414,11 +414,11 @@ glFogi(GL_FOG_START, 0); glFogi(GL_FOG_END, (fog + 96) / 8); }; glClear((player1->outsidemap ? GL_COLOR_BUFFER_BIT : 0) | - GL_DEPTH_BUFFER_BIT); + GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); int farplane = fog * 5 / 2; gluPerspective(fovy, aspect, 0.15f, farplane); @@ -488,6 +488,6 @@ gl_drawhud(w, h, (int)curfps, nquads, curvert, underwater); glEnable(GL_CULL_FACE); glEnable(GL_FOG); -}; +} Index: src/renderparticles.mm ================================================================== --- src/renderparticles.mm +++ src/renderparticles.mm @@ -21,11 +21,11 @@ if (!parinit) { loopi(MAXPARTICLES) { particles[i].next = parempty; parempty = &particles[i]; - }; + } parinit = true; }; if (parempty) { particle *p = parempty; parempty = p->next; @@ -35,11 +35,11 @@ p->type = type; p->millis = lastmillis; p->next = parlist; parlist = p; }; -}; +} VAR(demotracking, 0, 0, 1); VARP(particlesize, 20, 100, 500); OFVector3D right, up; @@ -115,11 +115,11 @@ p->next = parempty; parempty = p; } else { if (pt->gr) p->o.z -= ((lastmillis - p->millis) / 3.0f) * - curtime / (pt->gr * 10000); + curtime / (pt->gr * 10000); OFVector3D a = p->d; vmul(a, time); vdiv(a, 20000.0f); vadd(p->o, a); pp = &p->next; @@ -127,11 +127,11 @@ } glEnable(GL_FOG); glDisable(GL_BLEND); glDepthMask(GL_TRUE); -}; +} void particle_splash(int type, int num, int fade, OFVector3D &p) { loopi(num) Index: src/rndmap.mm ================================================================== --- src/rndmap.mm +++ src/rndmap.mm @@ -7,12 +7,12 @@ noise(int x, int y, int seed) { int n = x + y * 57; n = (n << 13) ^ n; return 1.0f - - ((n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff) / - 1073741824.0f; + ((n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff) / + 1073741824.0f; } float smoothednoise(int x, int y, int seed) { @@ -20,11 +20,11 @@ (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; + 8; float center = noise(x, y, seed) / 4; return corners + sides + center; } float @@ -58,11 +58,11 @@ int seed = 0; for (int i = 0; i < 7; i++) { float frequency = (float)(2 ^ i); float amplitude = (float)pow(pers, i); total += interpolatednoise(x * frequency, y * frequency, seed) * - amplitude; + amplitude; seed += seedstep; } return total; } @@ -79,11 +79,11 @@ 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); + 50 + + 25); if (s->vdelta > 128) s->vdelta = 0; }; -}; +} Index: src/savegamedemo.mm ================================================================== --- src/savegamedemo.mm +++ src/savegamedemo.mm @@ -213,11 +213,11 @@ loopv(ents) { ents[i].spawned = gzgetc(f) != 0; if (ents[i].type == CARROT && !ents[i].spawned) trigger(ents[i].attr1, ents[i].attr2, true); - }; + } restoreserverstate(ents); gzread(f, player1, sizeof(dynent)); player1->lastaction = lastmillis; @@ -228,25 +228,24 @@ loopv(monsters) { gzread(f, monsters[i], sizeof(dynent)); monsters[i]->enemy = player1; // lazy, could save id of enemy instead - monsters[i]->lastaction = monsters[i]->trigger = - lastmillis + + monsters[i]->lastaction = monsters[i]->trigger = lastmillis + 500; // also lazy, but no real noticable effect on game if (monsters[i]->state == CS_DEAD) monsters[i]->lastaction = 0; - }; + } restoremonsterstate(); int nplayers = gzgeti(); loopi(nplayers) if (!gzget()) { dynent *d = getclient(i); assert(d); gzread(f, d, sizeof(dynent)); - }; + } conoutf(@"savegame restored"); if (demoloading) startdemo(); else @@ -290,16 +289,16 @@ void demodamage(int damage, OFVector3D &o) { ddamage = damage; dorig = o; -}; +} void demoblend(int damage) { bdamage = damage; -}; +} void incomingdemodata(uchar *buf, int len, bool extras) { if (!demorecording) @@ -407,20 +406,20 @@ vadd(dest, t); vmul(t1, s3 - 2 * s2 + s); vadd(dest, t1); vmul(t2, s3 - s2); vadd(dest, t2); -}; +} void fixwrap(dynent *a, dynent *b) { while (b->yaw - a->yaw > 180) a->yaw += 360; while (b->yaw - a->yaw < -180) a->yaw -= 360; -}; +} void demoplaybackstep() { while (demoplayback && lastmillis >= playbacktime) { @@ -479,13 +478,13 @@ } if (demoplayback) { int itime = lastmillis - demodelaymsec; loopvrev(playerhistory) if (playerhistory[i]->lastupdate < - itime) // find 2 positions in - // history that surround - // interpolation time point + itime) // find 2 positions in + // history that surround + // interpolation time point { dynent *a = playerhistory[i]; dynent *b = a; if (i + 1 < playerhistory.length()) b = playerhistory[i + 1]; @@ -498,12 +497,11 @@ dynent *z = a; if (i - 1 >= 0) z = playerhistory[i - 1]; // if(a==z || b==c) printf("* %d\n", // lastmillis); - float bf = - (itime - a->lastupdate) / + float bf = (itime - a->lastupdate) / (float)(b->lastupdate - a->lastupdate); fixwrap(a, player1); fixwrap(c, player1); fixwrap(z, player1); vdist(dist, v, z->o, c->o); Index: src/server.mm ================================================================== --- src/server.mm +++ src/server.mm @@ -38,12 +38,12 @@ { loopv(sents) { sents[i].spawned = ents[i].spawned; sents[i].spawnsecs = 0; - }; -}; + } +} int interm = 0, minremain = 0, mapend = 0; bool mapreload = false; static OFString *serverpassword = @""; @@ -72,11 +72,11 @@ case ST_LOCAL: localservertoclient(packet->data, packet->dataLength); break; }; -}; +} void send2(bool rel, int cn, int a, int b) { ENetPacket *packet = @@ -91,11 +91,11 @@ process(packet, -1); else send(cn, packet); if (packet->referenceCount == 0) enet_packet_destroy(packet); -}; +} void sendservmsg(OFString *msg) { ENetPacket *packet = enet_packet_create( @@ -116,18 +116,18 @@ { printf("disconnecting client (%s) [%s]\n", clients[n].hostname, reason); enet_peer_disconnect(clients[n].peer); clients[n].type = ST_EMPTY; send2(true, -1, SV_CDIS, n); -}; +} void resetitems() { sents.setsize(0); notgotitems = true; -}; +} void pickup(uint i, int sec, int sender) // server side item pickup, acknowledge // first client that gets it { @@ -136,17 +136,17 @@ if (sents[i].spawned) { sents[i].spawned = false; sents[i].spawnsecs = sec; send2(true, sender, SV_ITEMACC, i); }; -}; +} void resetvotes() { loopv(clients) clients[i].mapvote[0] = 0; -}; +} bool vote(char *map, int reqmode, int sender) { strcpy_s(clients[sender].mapvote, map); @@ -160,11 +160,11 @@ yes++; else no++; } else no++; - }; + } if (yes == 1 && no == 0) return true; // single player @autoreleasepool { OFString *msg = [OFString stringWithFormat: @@ -175,11 +175,11 @@ if (yes / (float)(yes + no) <= 0.5f) return false; sendservmsg(@"vote passed"); resetvotes(); return true; -}; +} // server side processing of updates: does very little and most state is tracked // client only could be extended to move more gameplay to server (at expense of // lag) @@ -301,11 +301,11 @@ if (p > end) { disconnect_client(sender, "end of packet"); return; }; multicast(packet, sender); -}; +} void send_welcome(int n) { ENetPacket *packet = @@ -339,44 +339,44 @@ loopv(clients) { if (i == sender) continue; send(i, packet); - }; -}; + } +} void localclienttoserver(ENetPacket *packet) { process(packet, 0); if (!packet->referenceCount) enet_packet_destroy(packet); -}; +} client & addclient() { loopv(clients) if (clients[i].type == ST_EMPTY) return clients[i]; return clients.add(); -}; +} void checkintermission() { if (!minremain) { interm = lastsec + 10; mapend = lastsec + 1000; }; send2(true, -1, SV_TIMEUP, minremain--); -}; +} void startintermission() { minremain = 0; checkintermission(); -}; +} void resetserverifempty() { loopv(clients) if (clients[i].type != ST_EMPTY) return; @@ -405,11 +405,11 @@ (sents[i].spawnsecs -= seconds - lastsec) <= 0) { sents[i].spawnsecs = 0; sents[i].spawned = true; send2(true, -1, SV_ITEMSPAWN, i); }; - }; + } lastsec = seconds; if ((mode > 1 || (mode == 0 && nonlocalclients)) && seconds > mapend - minremain * 60) @@ -420,11 +420,11 @@ { send2(true, i, SV_MAPRELOAD, 0); // ask a client to trigger map reload mapreload = true; break; - }; + } }; resetserverifempty(); if (!isdedicated) @@ -457,15 +457,15 @@ client &c = addclient(); c.type = ST_TCPIP; c.peer = event.peer; c.peer->data = (void *)(&c - &clients[0]); char hn[1024]; - strcpy_s( - c.hostname, (enet_address_get_host(&c.peer->address, - hn, sizeof(hn)) == 0) - ? hn - : "localhost"); + strcpy_s(c.hostname, + (enet_address_get_host( + &c.peer->address, hn, sizeof(hn)) == 0) + ? hn + : "localhost"); printf("client connected (%s)\n", c.hostname); send_welcome(lastconnect = &c - &clients[0]); break; } case ENET_EVENT_TYPE_RECEIVE: @@ -491,34 +491,34 @@ }; }; #ifndef _WIN32 fflush(stdout); #endif -}; +} void cleanupserver() { if (serverhost) enet_host_destroy(serverhost); -}; +} void localdisconnect() { loopv(clients) if (clients[i].type == ST_LOCAL) clients[i].type = ST_EMPTY; -}; +} void localconnect() { client &c = addclient(); c.type = ST_LOCAL; strcpy_s(c.hostname, "local"); send_welcome(&c - &clients[0]); -}; +} void initserver(bool dedicated, int uprate, OFString *sdesc, OFString *ip, OFString *master, OFString *passwd, int maxcl) { @@ -552,6 +552,6 @@ atexit(cleanupserver); atexit(enet_deinitialize); for (;;) serverslice(/*enet_time_get_sec()*/ time(NULL), 5); }; -}; +} Index: src/serverbrowser.mm ================================================================== --- src/serverbrowser.mm +++ src/serverbrowser.mm @@ -45,11 +45,11 @@ rt->query = NULL; rt->starttime = 0; SDL_UnlockMutex(resolvermutex); }; return 0; -}; +} void resolverinit(int threads, int limit) { resolverlimit = limit; @@ -90,22 +90,22 @@ ; loopv(resolverthreads) { resolverthread &rt = resolverthreads[i]; resolverstop(rt, true); - }; + } SDL_UnlockMutex(resolvermutex); -}; +} void resolverquery(char *name) { SDL_LockMutex(resolvermutex); resolverqueries.add(name); SDL_SemPost(resolversem); SDL_UnlockMutex(resolvermutex); -}; +} bool resolvercheck(char **name, ENetAddress *address) { SDL_LockMutex(resolvermutex); @@ -125,14 +125,14 @@ *name = rt.query; SDL_UnlockMutex(resolvermutex); return true; }; }; - }; + } SDL_UnlockMutex(resolvermutex); return false; -}; +} struct serverinfo { string name; string full; string map; @@ -157,11 +157,11 @@ addserver(OFString *servername_) { @autoreleasepool { const char *servername = servername_.UTF8String; loopv(servers) if (strcmp(servers[i].name, servername) == - 0) return; + 0) return; serverinfo &si = servers.insert(0, serverinfo()); strcpy_s(si.name, servername); si.full[0] = 0; si.mode = 0; si.numplayers = 0; @@ -189,13 +189,13 @@ p = ping; putint(p, lastmillis); buf.data = ping; buf.dataLength = p - ping; enet_socket_send(pingsock, &si.address, &buf, 1); - }; + } lastinfo = lastmillis; -}; +} void checkresolver() { char *name = NULL; @@ -252,12 +252,12 @@ int sicompare(const serverinfo *a, const serverinfo *b) { return a->ping > b->ping - ? 1 - : (a->ping < b->ping ? -1 : strcmp(a->name, b->name)); + ? 1 + : (a->ping < b->ping ? -1 : strcmp(a->name, b->name)); } void refreshservers() { @@ -283,12 +283,11 @@ modestr(si.mode).UTF8String, si.name, si.sdesc); } } } else { - sprintf_s(si.full)( - si.address.host != ENET_HOST_ANY + sprintf_s(si.full)(si.address.host != ENET_HOST_ANY ? "%s [waiting for server response]" : "%s [unknown host]\t", si.name); } si.full[50] = 0; // cut off too long server descriptions @@ -309,11 +308,11 @@ }; resolverclear(); loopv(servers) resolverquery(servers[i].name); refreshservers(); menuset(1); -}; +} void updatefrommaster() { const int MAXUPD = 32000; Index: src/serverms.mm ================================================================== --- src/serverms.mm +++ src/serverms.mm @@ -49,20 +49,20 @@ }; buf.data = ((char *)buf.data) + len; ((char *)buf.data)[0] = 0; buf.dataLength -= len; }; -}; +} uchar * stripheader(uchar *b) { char *s = strstr((char *)b, "\n\r\n"); if (!s) s = strstr((char *)b, "\n\n"); return s ? (uchar *)s : b; -}; +} ENetAddress masterserver = {ENET_HOST_ANY, 80}; int updmaster = 0; string masterbase; string masterpath; @@ -81,20 +81,20 @@ masterrep[0] = 0; masterb.data = masterrep; masterb.dataLength = MAXTRANS - 1; updmaster = seconds + 60 * 60; }; -}; +} void checkmasterreply() { bool busy = mssock != ENET_SOCKET_NULL; httpgetrecieve(masterb); if (busy && mssock == ENET_SOCKET_NULL) printf("masterserver reply: %s\n", stripheader(masterrep)); -}; +} uchar * retrieveservers(uchar *buf, int buflen) { sprintf_sd(path)("%sretrieve.do?item=list", masterpath); @@ -105,11 +105,11 @@ eb.data = buf; eb.dataLength = buflen - 1; while (mssock != ENET_SOCKET_NULL) httpgetrecieve(eb); return stripheader(buf); -}; +} ENetSocket pongsock = ENET_SOCKET_NULL; static OFString *serverdesc; void Index: src/serverutil.mm ================================================================== --- src/serverutil.mm +++ src/serverutil.mm @@ -19,11 +19,11 @@ *p++ = n; *p++ = n >> 8; *p++ = n >> 16; *p++ = n >> 24; }; -}; +} int getint(uchar *&p) { int c = *((char *)p); @@ -91,11 +91,11 @@ { for (char *p = msgsizesl; *p >= 0; p += 2) if (*p == msg) return p[1]; return -1; -}; +} // sending of maps between clients static OFString *copyname; int copysize; Index: src/sound.mm ================================================================== --- src/sound.mm +++ src/sound.mm @@ -50,11 +50,11 @@ #ifndef USE_MIXER FSOUND_Stream_Close(stream); #endif stream = NULL; }; -}; +} VAR(soundbufferlen, 128, 1024, 4096); void initsound() @@ -160,11 +160,11 @@ #ifdef USE_MIXER Mix_CloseAudio(); #else FSOUND_Close(); #endif -}; +} VAR(stereo, 0, 1, 1); void updatechanvol(int chan, OFVector3D *loc) @@ -171,19 +171,19 @@ { int vol = soundvol, pan = 255 / 2; if (loc) { vdist(dist, v, *loc, player1->o); vol -= (int)(dist * 3 * soundvol / - 255); // simple mono distance attenuation + 255); // simple mono distance attenuation if (stereo && (v.x != 0 || v.y != 0)) { float yaw = -atan2(v.x, v.y) - - player1->yaw * - (PI / 180.0f); // relative angle of - // sound along X-Y axis - pan = int(255.9f * (0.5 * sin(yaw) + - 0.5f)); // range is from 0 (left) - // to 255 (right) + player1->yaw * + (PI / 180.0f); // relative angle of + // sound along X-Y axis + pan = int(255.9f * + (0.5 * sin(yaw) + 0.5f)); // range is from 0 (left) + // to 255 (right) }; }; vol = (vol * MAXVOL) / 255; #ifdef USE_MIXER Mix_Volume(chan, vol); @@ -190,19 +190,19 @@ Mix_SetPanning(chan, 255 - pan, pan); #else FSOUND_SetVolume(chan, vol); FSOUND_SetPan(chan, pan); #endif -}; +} void newsoundloc(int chan, OFVector3D *loc) { assert(chan >= 0 && chan < MAXCHAN); soundlocs[chan].loc = *loc; soundlocs[chan].inuse = true; -}; +} void updatevol() { if (nosound) @@ -215,19 +215,19 @@ if (FSOUND_IsPlaying(i)) #endif updatechanvol(i, &soundlocs[i].loc); else soundlocs[i].inuse = false; - }; -}; + } +} void playsoundc(int n) { addmsg(0, 2, SV_SOUND, n); playsound(n); -}; +} int soundsatonce = 0, lastsoundmillis = 0; void playsound(int n, OFVector3D *loc) Index: src/tools.h ================================================================== --- src/tools.h +++ src/tools.h @@ -36,13 +36,13 @@ #define max(a, b) (((a) > (b)) ? (a) : (b)) #define min(a, b) (((a) < (b)) ? (a) : (b)) #define rnd(max) (rand() % (max)) #define rndreset() (srand(1)) -#define rndtime() \ - { \ - loopi(lastmillis & 0xF) rnd(i + 1); \ +#define rndtime() \ + { \ + loopi(lastmillis & 0xF) 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) @@ -100,20 +100,20 @@ d[_MAXDEFSTR - 1] = 0; } }; #define sprintf_s(d) sprintf_s_f((char *)d) -#define sprintf_sd(d) \ - string d; \ +#define sprintf_sd(d) \ + string d; \ sprintf_s(d) -#define sprintf_sdlv(d, last, fmt) \ - string d; \ - { \ - va_list ap; \ - va_start(ap, last); \ - formatstring(d, fmt, ap); \ - va_end(ap); \ +#define sprintf_sdlv(d, last, fmt) \ + string d; \ + { \ + va_list ap; \ + va_start(ap, last); \ + formatstring(d, fmt, ap); \ + va_end(ap); \ } #define sprintf_sdv(d, fmt) sprintf_sdlv(d, fmt, fmt) #define fast_f2nat(val) ((int)(val)) @@ -234,15 +234,15 @@ buf[i] = e; return buf[i]; } }; -#define loopv(v) \ - if (false) { \ - } else \ +#define loopv(v) \ + if (false) { \ + } else \ for (int i = 0; i < (v).length(); i++) -#define loopvrev(v) \ - if (false) { \ - } else \ +#define loopvrev(v) \ + if (false) { \ + } else \ for (int i = (v).length() - 1; i >= 0; i--) #endif Index: src/tools.mm ================================================================== --- src/tools.mm +++ src/tools.mm @@ -15,7 +15,7 @@ { uchar *p = (uchar *)memory + w * stride; uchar t = p[i]; p[i] = p[stride - i - 1]; p[stride - i - 1] = t; - }; + } } Index: src/weapon.mm ================================================================== --- src/weapon.mm +++ src/weapon.mm @@ -105,12 +105,12 @@ p = &v; } } return (p->x <= d->o.x + d->radius && p->x >= d->o.x - d->radius && - p->y <= d->o.y + d->radius && p->y >= d->o.y - d->radius && - p->z <= d->o.z + d->aboveeye && p->z >= d->o.z - d->eyeheight); + p->y <= d->o.y + d->radius && p->y >= d->o.y - d->radius && + p->z <= d->o.z + d->aboveeye && p->z >= d->o.z - d->eyeheight); } OFString * playerincrosshair() { @@ -267,11 +267,11 @@ } if (p->owner != player1) projdamage(player1, p, v, -1, -1, qdam); dvector &mv = getmonsters(); loopv(mv) if (!vreject(mv[i]->o, v, 10.0f) && - mv[i] != p->owner) + mv[i] != p->owner) projdamage(mv[i], p, v, -1, i, qdam); } if (p->inuse) { if (time == dtime) splash(p, v, p->o, -1, -1, qdam); Index: src/world.mm ================================================================== --- src/world.mm +++ src/world.mm @@ -33,27 +33,27 @@ if (x < minx) minx = x; if (y < miny) miny = y; }; - }; + } block b = {minx, miny, maxx - minx + 1, maxy - miny + 1}; if (maxx) remip(b); // remip minimal area of changed geometry -}; +} void resettagareas() { settag(0, 0); -}; // reset for editing or map saving +} // reset for editing or map saving void settagareas() { settag(0, 1); loopv(ents) if (ents[i].type == CARROT) setspawn(i, true); -}; // set for playing +} // set for playing void trigger(int tag, int type, bool savegame) { if (!tag) @@ -129,18 +129,17 @@ int fh = o[i]->floor; int ch = o[i]->ceil; if (r->type == SEMISOLID) { if (o[i]->type == FHF) fh -= o[i]->vdelta / 4 + - 2; // crap hack, - // needed for - // rendering - // large mips - // next to hfs + 2; // crap hack, + // needed for + // rendering + // large mips + // next to hfs if (o[i]->type == CHF) - ch += - o[i]->vdelta / 4 + + ch += o[i]->vdelta / 4 + 2; // FIXME: needs // to somehow // take into // account middle // vertices on @@ -153,11 +152,11 @@ // never have to see // missing lower/upper // from the side if (ch > ceil) ceil = ch; - }; + } r->floor = floor; r->ceil = ceil; }; if (r->type == CORNER) goto mip; // special case: don't ever split even @@ -170,11 +169,11 @@ goto c; // on an all solid cube, // only thing that needs // to be equal for a // perfect mip is the // wall texture - }; + } } else { loopi(3) { if (o[i]->type != o[3]->type || o[i]->floor != o[3]->floor || @@ -184,17 +183,17 @@ abs(o[i + 1]->r - o[0]->r) > lighterr // perfect mip even if // light is not exactly // equal || abs(o[i + 1]->g - o[0]->g) > - lighterr || + lighterr || abs(o[i + 1]->b - o[0]->b) > lighterr || o[i]->utex != o[3]->utex || o[i]->wtex != o[3]->wtex) goto c; - }; + } if (r->type == CHF || r->type == FHF) // can make a perfect mip out of a // hf if slopes lie on one line { @@ -232,11 +231,11 @@ s.x /= 2; s.y /= 2; s.xs /= 2; s.ys /= 2; remip(s, level + 1); -}; +} void remipmore(block &b, int level) { block bb = b; @@ -247,11 +246,11 @@ if (bb.xs < ssize - 3) bb.xs++; if (bb.ys < ssize - 3) bb.ys++; remip(bb, level); -}; +} int closestent() // used for delent and edit mode ent display { if (noteditmode()) @@ -267,13 +266,13 @@ vdist(dist, t, player1->o, v); if (dist < bdist) { best = i; bdist = dist; }; - }; + } return bdist == 99999 ? -1 : best; -}; +} void entproperty(int prop, int amount) { int e = closestent(); @@ -291,11 +290,11 @@ break; case 3: ents[e].attr4 += amount; break; }; -}; +} void delent() { int e = closestent(); @@ -353,11 +352,11 @@ e.attr2, e.attr3, e.attr4); ents.add(*((entity *)&e)); // unsafe! if (type == LIGHT) calclight(); return &ents.last(); -}; +} void clearents(OFString *name) { int type = findtype(name); @@ -366,11 +365,11 @@ loopv(ents) { entity &e = ents[i]; if (e.type == type) e.type = NOTUSED; - }; + } if (type == LIGHT) calclight(); } COMMAND(clearents, ARG_1STR) @@ -379,11 +378,11 @@ { int n = c * intens / 100; if (n > 255) n = 255; c = n; -}; +} void scalelights(int f, int intens) { loopv(ents) @@ -399,11 +398,11 @@ if (intens) { scalecomp(e.attr2, intens); scalecomp(e.attr3, intens); scalecomp(e.attr4, intens); }; - }; + } calclight(); } COMMAND(scalelights, ARG_2INT) int @@ -412,11 +411,11 @@ for (int i = index; i < ents.length(); i++) if (ents[i].type == type) return i; loopj(index) if (ents[j].type == type) return j; return -1; -}; +} sqr *wmip[LARGEST_FACTOR * 2]; void setupworld(int factor) @@ -427,12 +426,12 @@ sqr *w = world = (sqr *)alloc(mipsize * sizeof(sqr)); loopi(LARGEST_FACTOR * 2) { wmip[i] = w; w += cubicsize >> (i * 2); - }; -}; + } +} void empty_world( int factor, bool force) // main empty world creation routine, if passed // factor -1 will enlarge old world by 1 Index: src/worldio.mm ================================================================== --- src/worldio.mm +++ src/worldio.mm @@ -183,20 +183,20 @@ gzwrite(f, &tmp, sizeof(persistent_entity)); } } sqr *t = NULL; int sc = 0; -#define spurge \ - while (sc) { \ - gzputc(f, 255); \ - if (sc > 255) { \ - gzputc(f, 255); \ - sc -= 255; \ - } else { \ - gzputc(f, sc); \ - sc = 0; \ - } \ +#define spurge \ + while (sc) { \ + gzputc(f, 255); \ + if (sc > 255) { \ + gzputc(f, 255); \ + sc -= 255; \ + } else { \ + gzputc(f, sc); \ + sc = 0; \ + } \ } loopk(cubicsize) { sqr *s = &world[k]; #define c(f) (s->f == t->f) Index: src/worldlight.mm ================================================================== --- src/worldlight.mm +++ src/worldlight.mm @@ -17,11 +17,11 @@ float dist = (float)sqrt(dx * dx + dy * dy); if (dist < 1.0f) return; int reach = light.attr1; int steps = (int)(reach * reach * 1.6f / - dist); // can change this for speedup/quality? + dist); // can change this for speedup/quality? const int PRECBITS = 12; const float PRECF = 4096.0f; int x = (int)(lx * PRECF); int y = (int)(ly * PRECF); int l = light.attr2 << PRECBITS; @@ -75,11 +75,11 @@ g -= stepg; b -= stepb; stepl -= 25; stepg -= 25; stepb -= 25; - }; + } } else // white light, special optimized version { int dimness = rnd((255 - light.attr2) / 16 + 1); x += stepx * dimness; y += stepy * dimness; @@ -96,11 +96,11 @@ return; x += stepx; y += stepy; l -= stepl; stepl -= 25; - }; + } }; } else // the old (white) light code, here for the few people with old // video cards that don't support overbright { loopi(steps) @@ -112,13 +112,13 @@ if (SOLID(s)) return; x += stepx; y += stepy; l -= stepl; - }; + } }; -}; +} void calclightsource(persistent_entity &l) { int reach = l.attr1; @@ -139,32 +139,32 @@ lightray((float)sx, sy2, l); lightray((float)ex, sy2, l); }; rndtime(); -}; +} void postlightarea(block &a) // median filter, smooths out random noise in light and // makes it more mipable { loop(x, a.xs) loop(y, a.ys) // assumes area not on edge of world { sqr *s = S(x + a.x, y + a.y); -#define median(m) \ - 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) / \ +#define median(m) \ + 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 median(r); median(g); median(b); - }; + } remip(a); -}; +} void calclight() { loop(x, ssize) loop(y, ssize) Index: src/worldocull.mm ================================================================== --- src/worldocull.mm +++ src/worldocull.mm @@ -67,34 +67,34 @@ fast_f2nat( sy)))) // 90% of time spend in this // function is on this line { rdist[i] = (float)(fabs(sx - vx) + - fabs(sy - vy)); + fabs(sy - vy)); break; }; }; } else { rdist[i] = 2; }; - }; -}; + } +} // test occlusion for a cube... one of the most computationally expensive // functions in the engine as its done for every cube and entity, but its effect // is more than worth it! inline float ca(float x, float y) { return x > y ? y / x : 2 - x / y; -}; +} inline float ma(float x, float y) { return x == 0 ? (y > 0 ? 2 : -2) : y / x; -}; +} int isoccluded(float vx, float vy, float cx, float cy, float csize) // v = viewer, c = cube to test { @@ -185,11 +185,11 @@ h = ca(cx + csize - vx, cy - vy); l = ca(cx - vx, cy + csize - vy); }; // H }; 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; if (ei <= si) ei += NUMRAYS; for (int i = si; i <= ei; i++) { @@ -198,6 +198,6 @@ // occlusion map is further away then cube is // not occluded }; return 1; // cube is entirely occluded -}; +} Index: src/worldrender.mm ================================================================== --- src/worldrender.mm +++ src/worldrender.mm @@ -59,11 +59,11 @@ if (c1 <= f1 && c2 <= f2) return; render_square(o->utex, f1, f2, c1, c2, x1 << mip, y1 << mip, x2 << mip, y2 << mip, 1 << mip, d1, d2, topleft); }; -}; +} const int MAX_MIP = 5; // 32x32 unit blocks const int MIN_LOD = 2; const int LOW_LOD = 25; const int MAX_LOD = 1000; @@ -104,11 +104,11 @@ break; default: return true; }; return false; -}; +} bool render_floor, render_ceil; // the core recursive function, renders a rect of cubes at a certain mip level // from a viewer perspective call itself for lower mip levels, on most modern @@ -156,36 +156,36 @@ // (occlusion at higher mip levels is a big time saver!). during the // first loop (ceil) we collect cubes that lie within the lower mip rect // and are also deferred, and render them recursively. Anything left // (perfect mips and higher lods) we render here. -#define LOOPH \ - { \ - for (int xx = x; xx < xs; xx++) \ - for (int yy = y; yy < ys; yy++) { \ - sqr *s = SWS(w, xx, yy, sz); \ - if (s->occluded == 1) \ - continue; \ - if (s->defer && !s->occluded && mip && \ - xx >= lx && xx < rx && yy >= ly && \ +#define LOOPH \ + { \ + for (int xx = x; xx < xs; xx++) \ + for (int yy = y; yy < ys; yy++) { \ + sqr *s = SWS(w, xx, yy, sz); \ + if (s->occluded == 1) \ + continue; \ + if (s->defer && !s->occluded && mip && \ + xx >= lx && xx < rx && yy >= ly && \ yy < ry) -#define LOOPD \ - sqr *t = SWS(s, 1, 0, sz); \ - sqr *u = SWS(s, 1, 1, sz); \ +#define LOOPD \ + sqr *t = SWS(s, 1, 0, sz); \ + sqr *u = SWS(s, 1, 1, sz); \ sqr *v = SWS(s, 0, 1, sz); LOOPH // ceils { int start = yy; sqr *next; while (yy < ys - 1 && (next = SWS(w, xx, yy + 1, sz))->defer && - !next->occluded) + !next->occluded) yy++; // collect 2xN rect of lower mip render_seg_new(vx, vy, vh, mip - 1, xx * 2, start * 2, xx * 2 + 2, yy * 2 + 2); continue; - }; + } stats[mip]++; LOOPD if ((s->type == SPACE || s->type == FHF) && s->ceil >= vh && render_ceil) render_flat(s->ctex, xx << mip, yy << mip, 1 << mip, s->ceil, s, @@ -309,11 +309,11 @@ high = (int)(angle / f); if (low < min_lod) low = min_lod; if (high < min_lod) high = min_lod; -}; +} // does some out of date view frustrum optimisation that doesn't contribute much // anymore void @@ -326,12 +326,13 @@ float widef = fov / 75.0f; int cdist = abs(yaw % 90 - 45); if (cdist < 7) // hack to avoid popup at high fovs at 45 yaw { min_lod = max(min_lod, - (int)(MIN_LOD + (10 - cdist) / 1.0f * - widef)); // less if lod worked better + (int)(MIN_LOD + + (10 - cdist) / 1.0f * + widef)); // less if lod worked better widef = 1.0f; }; lod = MAX_LOD; lodtop = lodbot = lodleft = lodright = min_lod; if (yaw > 45 && yaw <= 135) { @@ -353,6 +354,6 @@ render_ceil = -pitch < hyfov; render_seg_new( vx, vy, vh, MAX_MIP, 0, 0, ssize >> MAX_MIP, ssize >> MAX_MIP); mipstats(stats[0], stats[1], stats[2]); -}; +}