diff --git a/src/.clang-format b/src/.clang-format index 2270666..ae1c442 100644 --- a/src/.clang-format +++ b/src/.clang-format @@ -1,9 +1,26 @@ 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 @@ -15,5 +32,11 @@ ObjCPropertyAttributeOrder: [ atomic, nonatomic, getter, setter ] +SpaceBeforeInheritanceColon: false +QualifierAlignment: Left +#RemoveEmptyLinesInUnwrappedLines: true +RemoveSemicolon: true +CompactNamespaces: true +SortIncludes: CaseSensitive IndentPPDirectives: AfterHash PPIndentWidth: 1 diff --git a/src/Alias.h b/src/Alias.h index b798d44..85b80bd 100644 --- a/src/Alias.h +++ b/src/Alias.h @@ -2,7 +2,7 @@ OF_ASSUME_NONNULL_BEGIN -@interface Alias : Identifier +@interface Alias: Identifier @property (copy, nonatomic) OFString *action; @property (readonly, nonatomic) bool persisted; diff --git a/src/Command.h b/src/Command.h index bde4544..d22c778 100644 --- a/src/Command.h +++ b/src/Command.h @@ -2,7 +2,7 @@ OF_ASSUME_NONNULL_BEGIN -@interface Command : Identifier +@interface Command: Identifier @property (readonly, nonatomic) void (*function)(); @property (readonly, nonatomic) int argumentsTypes; diff --git a/src/Cube.mm b/src/Cube.mm index 818b0cc..f6847b3 100644 --- a/src/Cube.mm +++ b/src/Cube.mm @@ -7,7 +7,8 @@ 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; } diff --git a/src/Identifier.h b/src/Identifier.h index 554425e..6b5421c 100644 --- a/src/Identifier.h +++ b/src/Identifier.h @@ -2,7 +2,7 @@ OF_ASSUME_NONNULL_BEGIN -@interface Identifier : OFObject +@interface Identifier: OFObject @property (readonly, copy, nonatomic) OFString *name; - (instancetype)init OF_UNAVAILABLE; diff --git a/src/KeyMapping.h b/src/KeyMapping.h index be0171f..da020ea 100644 --- a/src/KeyMapping.h +++ b/src/KeyMapping.h @@ -2,7 +2,7 @@ OF_ASSUME_NONNULL_BEGIN -@interface KeyMapping : OFObject +@interface KeyMapping: OFObject @property (readonly) int code; @property (readonly, nonatomic) OFString *name; @property (copy, nonatomic) OFString *action; diff --git a/src/MD2.h b/src/MD2.h index e41aad2..70a93b4 100644 --- a/src/MD2.h +++ b/src/MD2.h @@ -4,7 +4,7 @@ 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; diff --git a/src/MD2.mm b/src/MD2.mm index ccbe274..80d8754 100644 --- a/src/MD2.mm +++ b/src/MD2.mm @@ -30,7 +30,8 @@ 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; diff --git a/src/MapModelInfo.h b/src/MapModelInfo.h index a5d6ece..e82e764 100644 --- a/src/MapModelInfo.h +++ b/src/MapModelInfo.h @@ -2,7 +2,7 @@ OF_ASSUME_NONNULL_BEGIN -@interface MapModelInfo : OFObject +@interface MapModelInfo: OFObject @property (nonatomic) int rad, h, zoff, snap; @property (copy, nonatomic) OFString *name; diff --git a/src/Menu.h b/src/Menu.h index c886450..493234b 100644 --- a/src/Menu.h +++ b/src/Menu.h @@ -4,7 +4,7 @@ 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; diff --git a/src/MenuItem.h b/src/MenuItem.h index 6b1990f..4ff4709 100644 --- a/src/MenuItem.h +++ b/src/MenuItem.h @@ -1,6 +1,6 @@ #import -@interface MenuItem : OFObject +@interface MenuItem: OFObject @property (readonly, nonatomic) OFString *text, *action; - (instancetype)initWithText:(OFString *)text action:(OFString *)action; diff --git a/src/Variable.h b/src/Variable.h index 1ff4255..92c4bff 100644 --- a/src/Variable.h +++ b/src/Variable.h @@ -2,7 +2,7 @@ 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)(); diff --git a/src/client.mm b/src/client.mm index 3f87531..411f2b9 100644 --- a/src/client.mm +++ b/src/client.mm @@ -295,10 +295,10 @@ c2sinfo(dynent *d) // send update to the server } 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)); @@ -311,10 +311,10 @@ c2sinfo(dynent *d) // send update to the server 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; @@ -412,4 +412,4 @@ gets2c() // get updates from the server server_err(); return; } -}; +} diff --git a/src/clientextras.mm b/src/clientextras.mm index 519faf5..d564dba 100644 --- a/src/clientextras.mm +++ b/src/clientextras.mm @@ -78,9 +78,8 @@ 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 diff --git a/src/clientgame.mm b/src/clientgame.mm index 4e784fd..0cdf866 100644 --- a/src/clientgame.mm +++ b/src/clientgame.mm @@ -41,7 +41,7 @@ resetmovement(dynent *d) d->jumpnext = false; d->strafe = 0; d->move = 0; -}; +} void spawnstate(dynent *d) // reset player state not persistent accross spawns @@ -95,7 +95,7 @@ spawnstate(dynent *d) // reset player state not persistent accross spawns } else { d->ammo[GUN_SG] = 5; }; -}; +} dynent * newdynent() // create a new blank player or monster @@ -125,14 +125,14 @@ newdynent() // create a new blank player or monster 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) @@ -145,7 +145,7 @@ arenacount(dynent *d, int &alive, int &dead, char *&lastteam, bool &oneteam) } else { dead++; }; -}; +} int arenarespawnwait = 0; int arenadetectwait = 0; @@ -180,7 +180,7 @@ arenarespawn() player1->roll = 0; }; }; -}; +} void zapdynent(dynent *&d) @@ -188,7 +188,7 @@ zapdynent(dynent *&d) if (d) free(d); d = NULL; -}; +} extern int democlientnum; @@ -207,8 +207,8 @@ otherplayers() moveplayer( players[i], 2, false); // use physics to extrapolate // player position - }; -}; + } +} void respawn() @@ -268,8 +268,7 @@ updateworld(int millis) // main game update loop 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); @@ -300,7 +299,7 @@ entinmap(dynent * 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; @@ -324,17 +323,17 @@ spawnplayer(dynent *d) // place at random spawn. also used by monsters! 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); @@ -350,14 +349,14 @@ attack(bool on) 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) @@ -379,7 +378,7 @@ fixplayer1range() player1->yaw += 360.0f; while (player1->yaw >= 360.0f) player1->yaw -= 360.0f; -}; +} void mousemove(int dx, int dy) @@ -389,10 +388,9 @@ mousemove(int dx, int dy) 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. @@ -404,20 +402,19 @@ selfdamage(int damage, int actor, dynent *act) 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); diff --git a/src/clients2c.mm b/src/clients2c.mm index 35d05d2..5aba279 100644 --- a/src/clients2c.mm +++ b/src/clients2c.mm @@ -52,7 +52,7 @@ updatepos(dynent *d) d->plag = (d->plag * 5 + lagtime) / 6; d->lastupdate = lastmillis; }; -}; +} void localservertoclient( diff --git a/src/console.mm b/src/console.mm index a53d60e..2a95cfa 100644 --- a/src/console.mm +++ b/src/console.mm @@ -78,13 +78,14 @@ 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) diff --git a/src/cube.h b/src/cube.h index 937f28f..2f5854f 100644 --- a/src/cube.h +++ b/src/cube.h @@ -8,7 +8,7 @@ #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; @@ -80,7 +80,7 @@ struct persistent_entity // map entity uchar attr2, attr3, attr4; }; -struct entity : public persistent_entity { +struct entity: public persistent_entity { bool spawned; // the only dynamic state of a map entity }; @@ -107,8 +107,8 @@ struct header // map file format header #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 { @@ -161,7 +161,7 @@ struct dynent // players & monsters 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 @@ -316,50 +316,50 @@ extern bool demoplayback; // 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 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 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 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 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); \ +#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) || \ +#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 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 sgetstr() \ + { \ + char *t = text; \ + do { \ + *t = getint(p); \ + } while (*t++); \ } // used by networking #define m_noitems (gamemode >= 4) @@ -394,31 +394,31 @@ enum // function signatures for script functions, see command.cpp // 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 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 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(); \ @@ -431,16 +431,16 @@ enum // function signatures for script functions, see command.cpp }); \ } \ 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 diff --git a/src/editing.mm b/src/editing.mm index 03449a6..60c5a27 100644 --- a/src/editing.mm +++ b/src/editing.mm @@ -26,15 +26,15 @@ OF_CONSTRUCTOR() 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; @@ -86,7 +86,7 @@ correctsel() // ensures above invariant sel.ys = bsize - sel.y; if (sel.xs <= 0 || sel.ys <= 0) selset = false; -}; +} bool noteditmode() @@ -105,14 +105,14 @@ noselection() return !selset; } -#define EDITSEL \ - if (noteditmode() || noselection()) \ +#define EDITSEL \ + if (noteditmode() || noselection()) \ return; -#define EDITSELMP \ - if (noteditmode() || noselection() || multiplayer()) \ +#define EDITSELMP \ + if (noteditmode() || noselection() || multiplayer()) \ return; -#define EDITMP \ - if (noteditmode() || multiplayer()) \ +#define EDITMP \ + if (noteditmode() || multiplayer()) \ return; void @@ -122,7 +122,7 @@ selectpos(int x, int y, int xs, int ys) sel = s; selh = 0; correctsel(); -}; +} void makesel() @@ -134,7 +134,7 @@ makesel() correctsel(); if (selset) rtex = *S(sel.x, sel.y); -}; +} VAR(flrceil, 0, 0, 2); @@ -143,11 +143,9 @@ 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 @@ -235,7 +233,7 @@ cursorupdate() // called every frame from hud 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 @@ -249,15 +247,15 @@ pruneundos(int maxremain) // bound memory 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() @@ -281,7 +279,7 @@ copy() if (copybuf) free(copybuf); copybuf = blockcopy(sel); -}; +} void paste() @@ -319,8 +317,8 @@ tofronttex() // maintain most recently used of the texture lists when applying p[0] = t; curedittex[i] = -1; }; - }; -}; + } +} void editdrag(bool isdown) @@ -333,7 +331,7 @@ editdrag(bool isdown) 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 @@ -352,7 +350,7 @@ editheightxy(bool isfloor, int amount, block &sel) if (s->ceil <= s->floor) s->ceil = s->floor + 1; }); -}; +} void editheight(int flr, int amount) @@ -381,7 +379,7 @@ edittexxy(int type, int t, block &sel) s->utex = t; break; }); -}; +} void edittex(int type, int dir) @@ -400,7 +398,7 @@ edittex(int type, int dir) 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() @@ -427,16 +425,16 @@ replace() 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) @@ -491,7 +489,7 @@ editequalisexy(bool isfloor, block &sel) if (s->floor >= s->ceil) s->floor = s->ceil - 1; }); -}; +} void equalize(int flr) @@ -508,7 +506,7 @@ setvdeltaxy(int delta, block &sel) { loopselxy(s->vdelta = max(s->vdelta + delta, 0)); remipmore(sel); -}; +} void setvdelta(int delta) @@ -516,7 +514,7 @@ 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]; @@ -532,7 +530,7 @@ archvertex(int span, int vert, int delta) if (span >= MAXARCHVERT || vert >= MAXARCHVERT || span < 0 || vert < 0) return; archverts[span][vert] = delta; -}; +} void arch(int sidedelta, int _a) @@ -544,14 +542,13 @@ arch(int sidedelta, int _a) 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) @@ -566,7 +563,7 @@ slope(int xd, int yd) sel.ys++; loopselxy(s->vdelta = xd * x + yd * y + off); remipmore(sel); -}; +} void perlin(int scale, int seed, int psize) @@ -583,7 +580,7 @@ perlin(int scale, int seed, int psize) remipmore(sel); sel.xs--; sel.ys--; -}; +} VARF( fullbright, 0, 0, 1, if (fullbright) { @@ -597,7 +594,7 @@ edittag(int tag) { EDITSELMP; loopselxy(s->tag = tag); -}; +} void newent(OFString *what, OFString *a1, OFString *a2, OFString *a3, OFString *a4) diff --git a/src/entities.mm b/src/entities.mm index 4f3fbc8..e2971df 100644 --- a/src/entities.mm +++ b/src/entities.mm @@ -27,7 +27,7 @@ renderent(entity &e, OFString *mdlname, float z, float yaw, int frame = 0, { 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() @@ -59,9 +59,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), + (float)(1 + + sin(lastmillis / 100.0 + e.x + e.y) / + 20), lastmillis / 10.0f); } else switch (e.attr2) { @@ -74,9 +74,10 @@ renderentities() 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; @@ -100,8 +101,8 @@ renderentities() break; }; }; - }; -}; + } +} struct itemstat { int add, max, sound; @@ -139,7 +140,7 @@ 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). @@ -153,7 +154,7 @@ radditem(int i, int &v) if (v > is.max) v = is.max; playsoundc(is.sound); -}; +} void realpickup(int n, dynent *d) @@ -234,7 +235,7 @@ teleport(int n, dynent *d) // also used by monsters break; }; }; -}; +} void pickup(int n, dynent *d) @@ -346,7 +347,7 @@ 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; @@ -357,10 +358,10 @@ void resetspawns() { loopv(ents) ents[i].spawned = false; -}; +} void setspawn(uint i, bool on) { if (i < (uint)ents.length()) ents[i].spawned = on; -}; +} diff --git a/src/monster.mm b/src/monster.mm index 4d1813c..58d4dd7 100644 --- a/src/monster.mm +++ b/src/monster.mm @@ -84,7 +84,7 @@ basicmonster(int type, int yaw, int state, int trigger, int move) } monsters.add(m); return m; -}; +} void spawnmonster() // spawn a random monster according to freq distribution in DMSP @@ -96,7 +96,7 @@ spawnmonster() // spawn a random monster according to freq distribution in DMSP break; }; basicmonster(type, rnd(360), M_SEARCH, 1000, 1); -}; +} void monsterclear() // called after map start of when toggling edit mode to @@ -121,9 +121,9 @@ monsterclear() // called after map start of when toggling edit mode to m->o.z = ents[i].z; entinmap(m); monstertotal++; - }; + } }; -}; +} bool los(float lx, float ly, float lz, float bx, float by, float bz, @@ -160,7 +160,7 @@ los(float lx, float ly, float lz, float bx, float by, float bz, i++; }; return i >= steps; -}; +} bool enemylos(dynent *m, OFVector3D &v) @@ -168,7 +168,7 @@ 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 @@ -185,7 +185,7 @@ transition(dynent *m, int state, int moving, int n, m->move = moving; n = n * 130 / 100; m->trigger = lastmillis + n - skill * (n / 16) + rnd(r + 1); -}; +} void normalise(dynent *m, float angle) @@ -194,7 +194,7 @@ normalise(dynent *m, float angle) m->yaw += 360.0f; while (m->yaw > angle + 180.0f) m->yaw -= 360.0f; -}; +} void monsteraction( @@ -223,13 +223,13 @@ monsteraction( { 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 @@ -312,7 +312,7 @@ monsteraction( }; moveplayer(m, 1, false); // use physics to move monster -}; +} void monsterpain(dynent *m, int damage, dynent *d) @@ -347,7 +347,7 @@ monsterpain(dynent *m, int damage, dynent *d) } else { playsound(monstertypes[m->mtype].painsound, &m->o); } -}; +} void endsp(bool allkilled) @@ -397,8 +397,8 @@ monsterthink() 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]); diff --git a/src/physics.mm b/src/physics.mm index 7324b92..83520a3 100644 --- a/src/physics.mm +++ b/src/physics.mm @@ -31,7 +31,7 @@ plcollide(dynent *d, dynent *o, float &headspace, float &hi, headspace = 10; }; return true; -}; +} bool cornertest(int mip, int x, int y, int dx, int dy, int &bx, int &by, @@ -51,7 +51,7 @@ cornertest(int mip, int x, int y, int dx, int dy, int &bx, int &by, return cornertest(mip, x, y, dx, dy, bx, by, bs); }; return stest; -}; +} void mmcollide(dynent *d, float &hi, float &lo) // collide with a mapmodel @@ -97,9 +97,9 @@ collide(dynent *d, bool spawn, float drop, float rise) 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 @@ -139,14 +139,14 @@ collide(dynent *d, bool spawn, float drop, float rise) 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; @@ -167,7 +167,7 @@ collide(dynent *d, bool spawn, float drop, float rise) continue; if (!plcollide(d, o, headspace, hi, lo)) return false; - }; + } if (d != player1) if (!plcollide(d, player1, headspace, hi, lo)) return false; @@ -175,7 +175,7 @@ collide(dynent *d, bool spawn, float drop, float rise) // 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 @@ -213,7 +213,7 @@ float rad(float x) { return x * 3.14159f / 180; -}; +} VARP(maxroll, 0, 3, 20); @@ -230,7 +230,7 @@ physicsframe() // optimally schedule physics frames inside the graphics frames } 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 @@ -297,8 +297,8 @@ moveplayer(dynent *pl, int moveres, bool local, int curtime) 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); @@ -312,18 +312,15 @@ moveplayer(dynent *pl, int moveres, bool local, int 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 @@ -359,7 +356,7 @@ moveplayer(dynent *pl, int moveres, bool local, int curtime) }; pl->o.z -= f * d.z; break; - }; + } }; // detect wether player is outside map, used for skipping zbuffer clear @@ -369,8 +366,7 @@ moveplayer(dynent *pl, int moveres, bool local, int curtime) 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); }; @@ -395,7 +391,7 @@ moveplayer(dynent *pl, int moveres, bool local, int curtime) } else if (pl->inwater && !water) playsound(S_SPLASH1, &pl->o); pl->inwater = water; -}; +} void moveplayer(dynent *pl, int moveres, bool local) @@ -403,4 +399,4 @@ moveplayer(dynent *pl, int moveres, bool local) loopi(physicsrepeat) moveplayer(pl, moveres, local, i ? curtime / physicsrepeat : curtime - curtime / physicsrepeat * (physicsrepeat - 1)); -}; +} diff --git a/src/rendercubes.mm b/src/rendercubes.mm index 9cf33d5..6b95868 100644 --- a/src/rendercubes.mm +++ b/src/rendercubes.mm @@ -29,29 +29,29 @@ reallocv() // 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 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 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 vert(v1, v2, v3, ls, t1, t2) \ + { \ + vertf((float)(v1), (float)(v2), (float)(v3), ls, t1, t2); \ } int nquads; @@ -76,18 +76,18 @@ mipstats(int a, int b, int c) 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); @@ -112,7 +112,7 @@ render_flat(int wtex, int x, int y, int size, int h, sqr *l1, sqr *l2, sqr *l3, 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 { @@ -170,7 +170,7 @@ render_flat(int wtex, int x, int y, int size, int h, sqr *l1, sqr *l2, sqr *l3, oy = y; nquads++; -}; +} void render_flatdelta(int wtex, int x, int y, int size, float h1, float h2, float h3, @@ -228,7 +228,7 @@ render_flatdelta(int wtex, int x, int y, int size, float h1, float h2, float h3, oy = y; nquads++; -}; +} void render_2tris(sqr *h, sqr *s, int x1, int y1, int x2, int y2, int x3, int y3, @@ -256,7 +256,7 @@ render_2tris(sqr *h, sqr *s, int x1, int y1, int x2, int y2, int x3, int y3, 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, @@ -277,7 +277,7 @@ render_tris(int x, int y, int size, bool topleft, sqr *h1, sqr *h2, sqr *s, 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, @@ -312,7 +312,7 @@ render_square(int wtex, float floor1, float floor2, float ceil1, float ceil2, nquads++; addstrip(gltex, curvert - 4, 4); -}; +} int wx1, wy1, wx2, wy2; @@ -326,18 +326,18 @@ 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 @@ -391,7 +391,7 @@ renderwater(float hf) glDepthMask(GL_TRUE); return nquads; -}; +} void addwaterquad(int x, int y, int size) // update bounding rect that contains water @@ -413,7 +413,7 @@ addwaterquad(int x, int y, int size) // update bounding rect that contains water if (y2 > wy2) wy2 = y2; }; -}; +} void resetcubes() @@ -425,4 +425,4 @@ resetcubes() nquads = 0; sbright.r = sbright.g = sbright.b = 255; sdark.r = sdark.g = sdark.b = 0; -}; +} diff --git a/src/renderextras.mm b/src/renderextras.mm index fcda6f4..78ea525 100644 --- a/src/renderextras.mm +++ b/src/renderextras.mm @@ -12,14 +12,14 @@ line(int x1, int y1, float z1, int x2, int y2, float z2) 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) @@ -31,7 +31,7 @@ box(block &b, float z1, float z2, float z3, float z4) glVertex3f((float)b.x, z4, (float)b.y + b.ys); glEnd(); xtraverts += 4; -}; +} void dot(int x, int y, float z) @@ -44,7 +44,7 @@ dot(int x, int y, float z) glVertex3f(x - DOF, (float)z, y + DOF); glEnd(); xtraverts += 4; -}; +} void blendbox(int x1, int y1, int x2, int y2, bool border) @@ -76,7 +76,7 @@ blendbox(int x1, int y1, int x2, int y2, bool border) glEnable(GL_BLEND); glEnable(GL_TEXTURE_2D); glDepthMask(GL_TRUE); -}; +} const int MAXSPHERES = 50; struct sphere { @@ -96,7 +96,7 @@ newsphere(OFVector3D &o, float max, int type) { spheres[i].next = sempty; sempty = &spheres[i]; - }; + } sinit = true; }; if (sempty) { @@ -109,7 +109,7 @@ newsphere(OFVector3D &o, float max, int type) p->next = slist; slist = p; }; -}; +} void renderspheres(int time) @@ -144,7 +144,7 @@ renderspheres(int time) glDisable(GL_BLEND); glDepthMask(GL_TRUE); -}; +} string closeent; OFString *entnames[] = { @@ -243,7 +243,7 @@ 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 @@ -252,7 +252,7 @@ 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 @@ -274,7 +274,7 @@ readdepth(int w, int h) 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) @@ -295,7 +295,7 @@ drawicon(float tx, float ty, int x, int y) glVertex2i(x, y + s); glEnd(); xtraverts += 4; -}; +} void invertperspective() @@ -312,7 +312,7 @@ invertperspective() inv[3 * 4 + 3] = pm[2 * 4 + 2] / pm[3 * 4 + 2]; glLoadMatrixd(inv); -}; +} VARP(crosshairsize, 0, 15, 50); @@ -321,7 +321,7 @@ void damageblend(int n) { dblend += n; -}; +} VAR(hidestats, 0, 0, 1); VARP(crosshairfx, 0, 1, 1); diff --git a/src/rendergl.mm b/src/rendergl.mm index fd91421..5336a89 100644 --- a/src/rendergl.mm +++ b/src/rendergl.mm @@ -63,7 +63,7 @@ gl_init(int w, int h) glNewList(1, GL_COMPILE); gluSphere(qsphere, 1, 12, 6); glEndList(); -}; +} void cleangl() @@ -174,7 +174,7 @@ void purgetextures() { loopi(256) loop(j, MAXFRAMES) mapping[i][j] = 0; -}; +} int curtexnum = 0; @@ -265,7 +265,7 @@ setupworld() glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_PRIMARY_COLOR_EXT); }; -}; +} int skyoglid; @@ -339,7 +339,7 @@ transplayer() (player1->state == CS_DEAD ? player1->eyeheight - 0.2f : 0) - player1->o.z, -player1->o.y); -}; +} VARP(fov, 10, 105, 120); @@ -390,7 +390,7 @@ drawhudgun(float fovy, float aspect, int farplane) glMatrixMode(GL_MODELVIEW); glDisable(GL_CULL_FACE); -}; +} void gl_drawframe(int w, int h, float curfps) @@ -416,7 +416,7 @@ gl_drawframe(int w, int h, float curfps) }; glClear((player1->outsidemap ? GL_COLOR_BUFFER_BIT : 0) | - GL_DEPTH_BUFFER_BIT); + GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); @@ -490,4 +490,4 @@ gl_drawframe(int w, int h, float curfps) glEnable(GL_CULL_FACE); glEnable(GL_FOG); -}; +} diff --git a/src/renderparticles.mm b/src/renderparticles.mm index 21ff794..76ecdae 100644 --- a/src/renderparticles.mm +++ b/src/renderparticles.mm @@ -23,7 +23,7 @@ newparticle(OFVector3D &o, OFVector3D &d, int fade, int type) { particles[i].next = parempty; parempty = &particles[i]; - }; + } parinit = true; }; if (parempty) { @@ -37,7 +37,7 @@ newparticle(OFVector3D &o, OFVector3D &d, int fade, int type) p->next = parlist; parlist = p; }; -}; +} VAR(demotracking, 0, 0, 1); VARP(particlesize, 20, 100, 500); @@ -117,7 +117,7 @@ render_particles(int time) } 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); @@ -129,7 +129,7 @@ render_particles(int time) glEnable(GL_FOG); glDisable(GL_BLEND); glDepthMask(GL_TRUE); -}; +} void particle_splash(int type, int num, int fade, OFVector3D &p) diff --git a/src/rndmap.mm b/src/rndmap.mm index 1928ec8..40638e7 100644 --- a/src/rndmap.mm +++ b/src/rndmap.mm @@ -9,8 +9,8 @@ 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 @@ -22,7 +22,7 @@ smoothednoise(int x, int y, int 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; } @@ -60,7 +60,7 @@ perlinnoise_2D(float x, float y, int seedstep, float pers) float frequency = (float)(2 ^ i); float amplitude = (float)pow(pers, i); total += interpolatednoise(x * frequency, y * frequency, seed) * - amplitude; + amplitude; seed += seedstep; } return total; @@ -81,9 +81,9 @@ perlinarea(block &b, int scale, int seed, int psize) 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; }; -}; +} diff --git a/src/savegamedemo.mm b/src/savegamedemo.mm index 544130f..4bbef55 100644 --- a/src/savegamedemo.mm +++ b/src/savegamedemo.mm @@ -215,7 +215,7 @@ loadgamerest() 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)); @@ -230,12 +230,11 @@ loadgamerest() 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(); @@ -244,7 +243,7 @@ loadgamerest() dynent *d = getclient(i); assert(d); gzread(f, d, sizeof(dynent)); - }; + } conoutf(@"savegame restored"); if (demoloading) @@ -292,12 +291,12 @@ demodamage(int damage, OFVector3D &o) { ddamage = damage; dorig = o; -}; +} void demoblend(int damage) { bdamage = damage; -}; +} void incomingdemodata(uchar *buf, int len, bool extras) @@ -409,7 +408,7 @@ catmulrom(OFVector3D &z, OFVector3D &a, OFVector3D &b, OFVector3D &c, float s, vadd(dest, t1); vmul(t2, s3 - s2); vadd(dest, t2); -}; +} void fixwrap(dynent *a, dynent *b) @@ -418,7 +417,7 @@ fixwrap(dynent *a, dynent *b) a->yaw += 360; while (b->yaw - a->yaw < -180) a->yaw -= 360; -}; +} void demoplaybackstep() @@ -481,9 +480,9 @@ demoplaybackstep() 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; @@ -500,8 +499,7 @@ demoplaybackstep() 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); diff --git a/src/server.mm b/src/server.mm index 10d5de0..1789264 100644 --- a/src/server.mm +++ b/src/server.mm @@ -40,8 +40,8 @@ restoreserverstate( { sents[i].spawned = ents[i].spawned; sents[i].spawnsecs = 0; - }; -}; + } +} int interm = 0, minremain = 0, mapend = 0; bool mapreload = false; @@ -74,7 +74,7 @@ send(int n, ENetPacket *packet) localservertoclient(packet->data, packet->dataLength); break; }; -}; +} void send2(bool rel, int cn, int a, int b) @@ -93,7 +93,7 @@ send2(bool rel, int cn, int a, int b) send(cn, packet); if (packet->referenceCount == 0) enet_packet_destroy(packet); -}; +} void sendservmsg(OFString *msg) @@ -118,14 +118,14 @@ disconnect_client(int n, char *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 @@ -138,13 +138,13 @@ pickup(uint i, int sec, int sender) // server side item pickup, acknowledge 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) @@ -162,7 +162,7 @@ vote(char *map, int reqmode, int sender) no++; } else no++; - }; + } if (yes == 1 && no == 0) return true; // single player @autoreleasepool { @@ -177,7 +177,7 @@ vote(char *map, int reqmode, int sender) 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 @@ -303,7 +303,7 @@ process(ENetPacket *packet, int sender) // sender may be -1 return; }; multicast(packet, sender); -}; +} void send_welcome(int n) @@ -341,8 +341,8 @@ multicast(ENetPacket *packet, int sender) if (i == sender) continue; send(i, packet); - }; -}; + } +} void localclienttoserver(ENetPacket *packet) @@ -350,14 +350,14 @@ 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() @@ -367,14 +367,14 @@ checkintermission() mapend = lastsec + 1000; }; send2(true, -1, SV_TIMEUP, minremain--); -}; +} void startintermission() { minremain = 0; checkintermission(); -}; +} void resetserverifempty() @@ -407,7 +407,7 @@ serverslice(int seconds, sents[i].spawned = true; send2(true, -1, SV_ITEMSPAWN, i); }; - }; + } lastsec = seconds; @@ -422,7 +422,7 @@ serverslice(int seconds, 0); // ask a client to trigger map reload mapreload = true; break; - }; + } }; resetserverifempty(); @@ -459,11 +459,11 @@ serverslice(int seconds, 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; @@ -493,21 +493,21 @@ serverslice(int seconds, #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() @@ -516,7 +516,7 @@ localconnect() c.type = ST_LOCAL; strcpy_s(c.hostname, "local"); send_welcome(&c - &clients[0]); -}; +} void initserver(bool dedicated, int uprate, OFString *sdesc, OFString *ip, @@ -554,4 +554,4 @@ initserver(bool dedicated, int uprate, OFString *sdesc, OFString *ip, for (;;) serverslice(/*enet_time_get_sec()*/ time(NULL), 5); }; -}; +} diff --git a/src/serverbrowser.mm b/src/serverbrowser.mm index c098f67..1862046 100644 --- a/src/serverbrowser.mm +++ b/src/serverbrowser.mm @@ -47,7 +47,7 @@ resolverloop(void *data) SDL_UnlockMutex(resolvermutex); }; return 0; -}; +} void resolverinit(int threads, int limit) @@ -92,9 +92,9 @@ resolverclear() { resolverthread &rt = resolverthreads[i]; resolverstop(rt, true); - }; + } SDL_UnlockMutex(resolvermutex); -}; +} void resolverquery(char *name) @@ -103,7 +103,7 @@ resolverquery(char *name) resolverqueries.add(name); SDL_SemPost(resolversem); SDL_UnlockMutex(resolvermutex); -}; +} bool resolvercheck(char **name, ENetAddress *address) @@ -127,10 +127,10 @@ resolvercheck(char **name, ENetAddress *address) return true; }; }; - }; + } SDL_UnlockMutex(resolvermutex); return false; -}; +} struct serverinfo { string name; @@ -159,7 +159,7 @@ 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; @@ -191,9 +191,9 @@ pingservers() buf.data = ping; buf.dataLength = p - ping; enet_socket_send(pingsock, &si.address, &buf, 1); - }; + } lastinfo = lastmillis; -}; +} void checkresolver() @@ -254,8 +254,8 @@ 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 @@ -285,8 +285,7 @@ refreshservers() } } } 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); @@ -311,7 +310,7 @@ servermenu() loopv(servers) resolverquery(servers[i].name); refreshservers(); menuset(1); -}; +} void updatefrommaster() diff --git a/src/serverms.mm b/src/serverms.mm index 9d1a0b1..9da7bb3 100644 --- a/src/serverms.mm +++ b/src/serverms.mm @@ -51,7 +51,7 @@ httpgetrecieve(ENetBuffer &buf) ((char *)buf.data)[0] = 0; buf.dataLength -= len; }; -}; +} uchar * stripheader(uchar *b) @@ -60,7 +60,7 @@ stripheader(uchar *b) if (!s) s = strstr((char *)b, "\n\n"); return s ? (uchar *)s : b; -}; +} ENetAddress masterserver = {ENET_HOST_ANY, 80}; int updmaster = 0; @@ -83,7 +83,7 @@ updatemasterserver(int seconds) masterb.dataLength = MAXTRANS - 1; updmaster = seconds + 60 * 60; }; -}; +} void checkmasterreply() @@ -92,7 +92,7 @@ checkmasterreply() httpgetrecieve(masterb); if (busy && mssock == ENET_SOCKET_NULL) printf("masterserver reply: %s\n", stripheader(masterrep)); -}; +} uchar * retrieveservers(uchar *buf, int buflen) @@ -107,7 +107,7 @@ retrieveservers(uchar *buf, int buflen) while (mssock != ENET_SOCKET_NULL) httpgetrecieve(eb); return stripheader(buf); -}; +} ENetSocket pongsock = ENET_SOCKET_NULL; static OFString *serverdesc; diff --git a/src/serverutil.mm b/src/serverutil.mm index 7652972..34ee73a 100644 --- a/src/serverutil.mm +++ b/src/serverutil.mm @@ -21,7 +21,7 @@ putint(uchar *&p, int n) *p++ = n >> 16; *p++ = n >> 24; }; -}; +} int getint(uchar *&p) @@ -93,7 +93,7 @@ msgsizelookup(int msg) if (*p == msg) return p[1]; return -1; -}; +} // sending of maps between clients diff --git a/src/sound.mm b/src/sound.mm index 482727c..dcc2e01 100644 --- a/src/sound.mm +++ b/src/sound.mm @@ -52,7 +52,7 @@ stopsound() #endif stream = NULL; }; -}; +} VAR(soundbufferlen, 128, 1024, 4096); @@ -162,7 +162,7 @@ cleansound() #else FSOUND_Close(); #endif -}; +} VAR(stereo, 0, 1, 1); @@ -173,15 +173,15 @@ updatechanvol(int chan, OFVector3D *loc) 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; @@ -192,7 +192,7 @@ updatechanvol(int chan, OFVector3D *loc) FSOUND_SetVolume(chan, vol); FSOUND_SetPan(chan, pan); #endif -}; +} void newsoundloc(int chan, OFVector3D *loc) @@ -200,7 +200,7 @@ newsoundloc(int chan, OFVector3D *loc) assert(chan >= 0 && chan < MAXCHAN); soundlocs[chan].loc = *loc; soundlocs[chan].inuse = true; -}; +} void updatevol() @@ -217,15 +217,15 @@ updatevol() 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; diff --git a/src/tools.h b/src/tools.h index 7eeeda9..9ffd2cf 100644 --- a/src/tools.h +++ b/src/tools.h @@ -38,9 +38,9 @@ typedef unsigned int uint; #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) @@ -102,16 +102,16 @@ struct sprintf_s_f { }; #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) @@ -236,13 +236,13 @@ template struct vector { } }; -#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 diff --git a/src/tools.mm b/src/tools.mm index bb0e516..8215bff 100644 --- a/src/tools.mm +++ b/src/tools.mm @@ -17,5 +17,5 @@ endianswap( uchar t = p[i]; p[i] = p[stride - i - 1]; p[stride - i - 1] = t; - }; + } } diff --git a/src/weapon.mm b/src/weapon.mm index 1b10247..e418406 100644 --- a/src/weapon.mm +++ b/src/weapon.mm @@ -107,8 +107,8 @@ intersect(dynent *d, OFVector3D &from, } 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 * @@ -269,7 +269,7 @@ moveprojectiles(float time) 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) { diff --git a/src/world.mm b/src/world.mm index f71d687..edcd6a6 100644 --- a/src/world.mm +++ b/src/world.mm @@ -35,23 +35,23 @@ settag(int tag, int type) // set all cubes with "tag" to space, if tag is 0 then 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) @@ -131,14 +131,13 @@ remip(block &b, int level) 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 @@ -155,7 +154,7 @@ remip(block &b, int level) // from the side if (ch > ceil) ceil = ch; - }; + } r->floor = floor; r->ceil = ceil; }; @@ -172,7 +171,7 @@ remip(block &b, int level) // to be equal for a // perfect mip is the // wall texture - }; + } } else { loopi(3) { @@ -186,13 +185,13 @@ remip(block &b, int level) // 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 @@ -234,7 +233,7 @@ remip(block &b, int level) s.xs /= 2; s.ys /= 2; remip(s, level + 1); -}; +} void remipmore(block &b, int level) @@ -249,7 +248,7 @@ remipmore(block &b, int level) if (bb.ys < ssize - 3) bb.ys++; remip(bb, level); -}; +} int closestent() // used for delent and edit mode ent display @@ -269,9 +268,9 @@ closestent() // used for delent and edit mode ent display best = i; bdist = dist; }; - }; + } return bdist == 99999 ? -1 : best; -}; +} void entproperty(int prop, int amount) @@ -293,7 +292,7 @@ entproperty(int prop, int amount) ents[e].attr4 += amount; break; }; -}; +} void delent() @@ -355,7 +354,7 @@ newentity(int x, int y, int z, OFString *what, int v1, int v2, int v3, int v4) if (type == LIGHT) calclight(); return &ents.last(); -}; +} void clearents(OFString *name) @@ -368,7 +367,7 @@ clearents(OFString *name) entity &e = ents[i]; if (e.type == type) e.type = NOTUSED; - }; + } if (type == LIGHT) calclight(); } @@ -381,7 +380,7 @@ scalecomp(uchar &c, int intens) if (n > 255) n = 255; c = n; -}; +} void scalelights(int f, int intens) @@ -401,7 +400,7 @@ scalelights(int f, int intens) scalecomp(e.attr3, intens); scalecomp(e.attr4, intens); }; - }; + } calclight(); } COMMAND(scalelights, ARG_2INT) @@ -414,7 +413,7 @@ findentity(int type, int index) return i; loopj(index) if (ents[j].type == type) return j; return -1; -}; +} sqr *wmip[LARGEST_FACTOR * 2]; @@ -429,8 +428,8 @@ setupworld(int factor) { wmip[i] = w; w += cubicsize >> (i * 2); - }; -}; + } +} void empty_world( diff --git a/src/worldio.mm b/src/worldio.mm index 499a838..e7bf7de 100644 --- a/src/worldio.mm +++ b/src/worldio.mm @@ -185,16 +185,16 @@ save_world(OFString *mname) } 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) { diff --git a/src/worldlight.mm b/src/worldlight.mm index ab72c01..bebe3c3 100644 --- a/src/worldlight.mm +++ b/src/worldlight.mm @@ -19,7 +19,7 @@ lightray(float bx, float by, 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); @@ -77,7 +77,7 @@ lightray(float bx, float by, stepl -= 25; stepg -= 25; stepb -= 25; - }; + } } else // white light, special optimized version { int dimness = rnd((255 - light.attr2) / 16 + 1); @@ -98,7 +98,7 @@ lightray(float bx, float by, 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 @@ -114,9 +114,9 @@ lightray(float bx, float by, x += stepx; y += stepy; l -= stepl; - }; + } }; -}; +} void calclightsource(persistent_entity &l) @@ -141,7 +141,7 @@ calclightsource(persistent_entity &l) }; rndtime(); -}; +} void postlightarea(block &a) // median filter, smooths out random noise in light and @@ -150,19 +150,19 @@ postlightarea(block &a) // median filter, smooths out random noise in light and 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() diff --git a/src/worldocull.mm b/src/worldocull.mm index e0a0cb1..002c56a 100644 --- a/src/worldocull.mm +++ b/src/worldocull.mm @@ -69,15 +69,15 @@ computeraytable(float vx, float vy) // 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 @@ -87,12 +87,12 @@ 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, @@ -187,7 +187,7 @@ isoccluded(float vx, float vy, float cx, float cy, }; // 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; @@ -200,4 +200,4 @@ isoccluded(float vx, float vy, float cx, float cy, }; return 1; // cube is entirely occluded -}; +} diff --git a/src/worldrender.mm b/src/worldrender.mm index 808530c..bc5856f 100644 --- a/src/worldrender.mm +++ b/src/worldrender.mm @@ -61,7 +61,7 @@ skip: { 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; @@ -106,7 +106,7 @@ issemi(int mip, int x, int y, int x1, int y1, int x2, int y2) return true; }; return false; -}; +} bool render_floor, render_ceil; @@ -158,19 +158,19 @@ render_seg_new( // 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 @@ -178,12 +178,12 @@ render_seg_new( 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 && @@ -311,7 +311,7 @@ distlod(int &low, int &high, int angle, float widef) low = min_lod; if (high < min_lod) high = min_lod; -}; +} // does some out of date view frustrum optimisation that doesn't contribute much // anymore @@ -328,8 +328,9 @@ render_world( 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; @@ -355,4 +356,4 @@ render_world( render_seg_new( vx, vy, vh, MAX_MIP, 0, 0, ssize >> MAX_MIP, ssize >> MAX_MIP); mipstats(stats[0], stats[1], stats[2]); -}; +}