Skip to content

Commit

Permalink
Merge pull request #160 from blue-nebula/fix-std-swap
Browse files Browse the repository at this point in the history
Use std::swap without "using" keyword
  • Loading branch information
Morel Bérenger authored Jul 26, 2020
2 parents 60da7b1 + 0b87595 commit 326acad
Show file tree
Hide file tree
Showing 64 changed files with 83 additions and 232 deletions.
5 changes: 1 addition & 4 deletions src/engine/bih.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#include <algorithm>
using std::swap;

#include <vector>
#include "engine.h"

Expand Down Expand Up @@ -205,7 +202,7 @@ void BIH::build(mesh &m, ushort *indices, int numindices, const ivec &vmin, cons
else
{
--right;
swap(indices[left], indices[right]);
std::swap(indices[left], indices[right]);
splitright = min(splitright, amin);
rightmin.min(trimin);
rightmax.max(trimax);
Expand Down
5 changes: 1 addition & 4 deletions src/engine/blend.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#include <algorithm>
using std::swap;

#include <vector>
#include "engine.h"

Expand Down Expand Up @@ -520,7 +517,7 @@ struct BlendBrush
}
dst += stridey;
}
if(swapxy) swap(w, h);
if(swapxy) std::swap(w, h);
delete[] data;
data = rdata;
if(tex) gentex();
Expand Down
3 changes: 0 additions & 3 deletions src/engine/blob.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#include <algorithm>
using std::swap;

#include "engine.h"

extern int intel_mapbufferrange_bug;
Expand Down
3 changes: 0 additions & 3 deletions src/engine/client.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// client.cpp, mostly network related client game code
#include <algorithm>
using std::swap;

#include "engine.h"

ENetHost *clienthost = NULL;
Expand Down
2 changes: 0 additions & 2 deletions src/engine/command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
// is largely backwards compatible with the quake console language.

#include <vector>
#include <algorithm>
#include <string>
using std::swap;
#include "engine.h"

bool interactive = false;
Expand Down
2 changes: 0 additions & 2 deletions src/engine/console.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// console.cpp: the console buffer, its display, and command line control
#include <algorithm>
#include <string>
using std::swap;

#include "engine.h"
#include "game.h"
Expand Down
3 changes: 0 additions & 3 deletions src/engine/decal.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#include <algorithm>
using std::swap;

#include "engine.h"

struct decalvert
Expand Down
3 changes: 0 additions & 3 deletions src/engine/dynlight.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#include <algorithm>
using std::swap;

#include "engine.h"

VAR(IDF_PERSIST, maxdynlights, 0, min(3, MAXDYNLIGHTS), MAXDYNLIGHTS);
Expand Down
3 changes: 0 additions & 3 deletions src/engine/genkey.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#include <algorithm>
using std::swap;

#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
Expand Down
3 changes: 0 additions & 3 deletions src/engine/glare.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#include <algorithm>
using std::swap;

#include "engine.h"
#include "rendertarget.h"

Expand Down
3 changes: 0 additions & 3 deletions src/engine/grass.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#include <algorithm>
using std::swap;

#include "engine.h"

VAR(IDF_PERSIST, grass, 0, 0, 1);
Expand Down
3 changes: 0 additions & 3 deletions src/engine/irc.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#include <algorithm>
using std::swap;

#include "engine.h"

VAR(0, ircfilter, 0, 2, 2);
Expand Down
9 changes: 3 additions & 6 deletions src/engine/lightmap.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#include <algorithm>
using std::swap;

#include "engine.h"

#define MAXLIGHTMAPTASKS 4096
Expand Down Expand Up @@ -695,7 +692,7 @@ static inline void generatealpha(lightmapworker *w, float tolerance, const vec &
float k = 8.0f/w->vslot->scale,
s = (pos[sdim[dim]] * k - w->vslot->offset.x) / w->slot->layermaskscale,
t = (pos[tdim[dim]] * (dim <= 1 ? -k : k) - w->vslot->offset.y) / w->slot->layermaskscale;
if((w->rotate&5)==1) swap(s, t);
if((w->rotate&5)==1) std::swap(s, t);
if(w->rotate>=2 && w->rotate<=4) s = -s;
if((w->rotate>=1 && w->rotate<=2) || w->rotate==5) t = -t;
const ImageData &mask = *w->slot->layermask;
Expand Down Expand Up @@ -863,7 +860,7 @@ static int finishlightmap(lightmapworker *w)
if((hasskylight() || sunlights.length()) && blurskylight && (w->w>1 || w->h>1))
{
blurtexture(blurskylight, w->bpp, w->w, w->h, w->blur, w->ambient);
swap(w->blur, w->ambient);
std::swap(w->blur, w->ambient);
}
vec *sample = w->colordata;
int aasample = min(1 << lmaa, 4), stride = aasample*(w->w+1);
Expand Down Expand Up @@ -2300,7 +2297,7 @@ static void rotatenormals(LightMap &lmlv, int x, int y, int w, int h, int rotate
{
if(flipx) lv[0] = 255 - lv[0];
if(flipy) lv[1] = 255 - lv[1];
if(swapxy) swap(lv[0], lv[1]);
if(swapxy) std::swap(lv[0], lv[1]);
lv += 3;
}
lv += stride;
Expand Down
3 changes: 0 additions & 3 deletions src/engine/main.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// main.cpp: initialisation & main loop
#include <algorithm>
using std::swap;

#include "engine.h"
#include <signal.h>

Expand Down
3 changes: 0 additions & 3 deletions src/engine/master.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#include <algorithm>
using std::swap;

#ifdef WIN32
#define FD_SETSIZE 4096
#else
Expand Down
9 changes: 3 additions & 6 deletions src/engine/material.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#include <algorithm>
using std::swap;

#include "engine.h"

struct QuadNode
Expand Down Expand Up @@ -512,9 +509,9 @@ void sortmaterials(vector<materialsurface *> &vismats)
if(reflecting) sortorigin.z = int(reflectz - (camera1->o.z - reflectz));
vec dir(camera1->yaw*RAD, reflecting ? -camera1->pitch : camera1->pitch);
loopi(3) { dir[i] = fabs(dir[i]); sortdim[i] = i; }
if(dir[sortdim[2]] > dir[sortdim[1]]) swap(sortdim[2], sortdim[1]);
if(dir[sortdim[1]] > dir[sortdim[0]]) swap(sortdim[1], sortdim[0]);
if(dir[sortdim[2]] > dir[sortdim[1]]) swap(sortdim[2], sortdim[1]);
if(dir[sortdim[2]] > dir[sortdim[1]]) std::swap(sortdim[2], sortdim[1]);
if(dir[sortdim[1]] > dir[sortdim[0]]) std::swap(sortdim[1], sortdim[0]);
if(dir[sortdim[2]] > dir[sortdim[1]]) std::swap(sortdim[2], sortdim[1]);

for(vtxarray *va = reflecting ? reflectedva : visibleva; va; va = reflecting ? va->rnext : va->next)
{
Expand Down
3 changes: 0 additions & 3 deletions src/engine/menus.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// menus.cpp: ingame menu system (also used for scores and serverlist)
#include <algorithm>
using std::swap;

#include "engine.h"

VAR(0, guipasses, 1, -1, -1);
Expand Down
8 changes: 4 additions & 4 deletions src/engine/mpr.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ namespace mpr
// If the origin is on the - side of the plane, reverse the direction of the plane
if(n.dot(v0) > 0)
{
swap(v1, v2);
std::swap(v1, v2);
n.neg();
}

Expand Down Expand Up @@ -415,9 +415,9 @@ namespace mpr
// If the origin is on the - side of the plane, reverse the direction of the plane
if(n.dot(v0) > 0)
{
swap(v1, v2);
swap(v11, v21);
swap(v12, v22);
std::swap(v1, v2);
std::swap(v11, v21);
std::swap(v12, v22);
n.neg();
}

Expand Down
3 changes: 0 additions & 3 deletions src/engine/normal.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#include <algorithm>
using std::swap;

#include "engine.h"

struct normalgroup
Expand Down
7 changes: 2 additions & 5 deletions src/engine/octa.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// core world management routines
#include <algorithm>
using std::swap;

#include "engine.h"

cube *worldroot = newcubes(F_SOLID);
Expand Down Expand Up @@ -1645,7 +1642,7 @@ bool mergepolys(int orient, hashset<plink> &links, vector<plink *> &queue, int o
{
pedge e(p.verts[prev], p.verts[j]);
int order = e.from.x > e.to.x || (e.from.x == e.to.x && e.from.y > e.to.y) ? 1 : 0;
if(order) swap(e.from, e.to);
if(order) std::swap(e.from, e.to);
plink &l = links.access(e, e);
bool shouldqueue = l.polys[order] < 0 && l.polys[order^1] >= 0;
l.polys[order] = owner;
Expand Down Expand Up @@ -1733,7 +1730,7 @@ void mergepolys(int orient, const ivec &co, const ivec &n, int offset, vector<po
{
pedge e(p.verts[prev], p.verts[j]);
int order = e.from.x > e.to.x || (e.from.x == e.to.x && e.from.y > e.to.y) ? 1 : 0;
if(order) swap(e.from, e.to);
if(order) std::swap(e.from, e.to);
plink &l = links.access(e, e);
l.polys[order] = i;
if(l.polys[0] >= 0 && l.polys[1] >= 0) queue.add(&l);
Expand Down
20 changes: 9 additions & 11 deletions src/engine/octaedit.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include <algorithm>
using std::swap;
#include <vector>
#include "engine.h"

Expand Down Expand Up @@ -223,7 +221,7 @@ COMMAND(0, selextend, "");
ICOMMAND(0, selmoved, "", (), { if(noedit(true)) return; intret(sel.o != savedsel.o ? 1 : 0); });
ICOMMAND(0, selsave, "", (), { if(noedit(true)) return; savedsel = sel; });
ICOMMAND(0, selrestore, "", (), { if(noedit(true)) return; sel = savedsel; });
ICOMMAND(0, selswap, "", (), { if(noedit(true)) return; swap(sel, savedsel); });
ICOMMAND(0, selswap, "", (), { if(noedit(true)) return; std::swap(sel, savedsel); });

///////// selection support /////////////

Expand Down Expand Up @@ -2613,13 +2611,13 @@ uint mflip(uint face) { return (face&0xFF0000FF) | ((face&0x00FF0000)>>8) | ((fa

void flipcube(cube &c, int d)
{
swap(c.texture[d*2], c.texture[d*2+1]);
std::swap(c.texture[d*2], c.texture[d*2+1]);
c.faces[D[d]] = dflip(c.faces[D[d]]);
c.faces[C[d]] = cflip(c.faces[C[d]]);
c.faces[R[d]] = rflip(c.faces[R[d]]);
if(c.children)
{
loopi(8) if(i&octadim(d)) swap(c.children[i], c.children[i-octadim(d)]);
loopi(8) if(i&octadim(d)) std::swap(c.children[i], c.children[i-octadim(d)]);
loopi(8) flipcube(c.children[i], d);
}
}
Expand All @@ -2634,11 +2632,11 @@ void rotatecube(cube &c, int d) // rotates cube clockwise. see pics in cvs for h
c.faces[D[d]] = cflip (mflip(c.faces[D[d]]));
c.faces[C[d]] = dflip (mflip(c.faces[C[d]]));
c.faces[R[d]] = rflip (mflip(c.faces[R[d]]));
swap(c.faces[R[d]], c.faces[C[d]]);
std::swap(c.faces[R[d]], c.faces[C[d]]);

swap(c.texture[2*R[d]], c.texture[2*C[d]+1]);
swap(c.texture[2*C[d]], c.texture[2*R[d]+1]);
swap(c.texture[2*C[d]], c.texture[2*C[d]+1]);
std::swap(c.texture[2*R[d]], c.texture[2*C[d]+1]);
std::swap(c.texture[2*C[d]], c.texture[2*R[d]+1]);
std::swap(c.texture[2*C[d]], c.texture[2*C[d]+1]);

if(c.children)
{
Expand Down Expand Up @@ -2670,7 +2668,7 @@ void mpflip(selinfo &sel, bool local)
{
cube &a = selcube(x, y, z);
cube &b = selcube(x, y, zs-z-1);
swap(a, b);
std::swap(a, b);
}
}
changed(sel);
Expand Down Expand Up @@ -3003,7 +3001,7 @@ void rendertexturepanel(int w, int h)
float xoff = vslot.offset.x, yoff = vslot.offset.y;
if(vslot.rotation)
{
if((vslot.rotation&5) == 1) { swap(xoff, yoff); loopk(4) swap(tc[k].x, tc[k].y); }
if((vslot.rotation&5) == 1) { std::swap(xoff, yoff); loopk(4) std::swap(tc[k].x, tc[k].y); }
if(vslot.rotation >= 2 && vslot.rotation <= 4) { xoff *= -1; loopk(4) tc[k].x *= -1; }
if(vslot.rotation <= 2 || vslot.rotation == 5) { yoff *= -1; loopk(4) tc[k].y *= -1; }
}
Expand Down
5 changes: 1 addition & 4 deletions src/engine/octarender.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// octarender.cpp: fill vertex arrays with different cube surfaces.
#include <algorithm>
using std::swap;

#include "engine.h"

struct vboinfo
Expand Down Expand Up @@ -964,7 +961,7 @@ void gencubeedges(cube &c, const ivec &co, int size)
if(d[axis] < 0)
{
d.neg();
swap(e1, e2);
std::swap(e1, e2);
}
reduceslope(d);

Expand Down
3 changes: 0 additions & 3 deletions src/engine/physics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
// All physics computations and constants were invented on the fly and simply tweaked until
// they "felt right", and have no basis in reality. Collision detection is simplistic but
// very robust (uses discrete steps at fixed fps).
#include <algorithm>
using std::swap;

#include "engine.h"
#include "mpr.h"

Expand Down
14 changes: 6 additions & 8 deletions src/engine/pvs.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include <algorithm>
using std::swap;
#include "engine.h"
#include "SDL_thread.h"

Expand Down Expand Up @@ -440,9 +438,9 @@ struct pvsworker
order[1] = cullorder(1, diff.x);
order[2] = cullorder(2, diff.y);
order[3] = cullorder(4, diff.z);
if(order[2].dist < order[1].dist) swap(order[1], order[2]);
if(order[3].dist < order[2].dist) swap(order[2], order[3]);
if(order[2].dist < order[1].dist) swap(order[1], order[2]);
if(order[2].dist < order[1].dist) std::swap(order[1], order[2]);
if(order[3].dist < order[2].dist) std::swap(order[2], order[3]);
if(order[2].dist < order[1].dist) std::swap(order[1], order[2]);
cullorder dxy(order[1].index|order[2].index, order[1].dist+order[2].dist),
dxz(order[1].index|order[3].index, order[1].dist+order[3].dist),
dyz(order[2].index|order[3].index, order[2].dist+order[3].dist);
Expand All @@ -466,9 +464,9 @@ struct pvsworker
shaftbb geom(co, size, edges);
ivec diff = ivec(geom.max).sub(ivec(viewcellbb.min)).abs();
cullorder order[3] = { cullorder(0, diff.x), cullorder(1, diff.y), cullorder(2, diff.z) };
if(order[1].dist > order[0].dist) swap(order[0], order[1]);
if(order[2].dist > order[1].dist) swap(order[1], order[2]);
if(order[1].dist > order[0].dist) swap(order[0], order[1]);
if(order[1].dist > order[0].dist) std::swap(order[0], order[1]);
if(order[2].dist > order[1].dist) std::swap(order[1], order[2]);
if(order[1].dist > order[0].dist) std::swap(order[0], order[1]);
loopi(6)
{
int dim = order[i >= 3 ? i-3 : i].index, dc = (i >= 3) != (geom.max[dim] <= viewcellbb.min[dim]) ? 1 : 0, r = R[dim], c = C[dim];
Expand Down
11 changes: 4 additions & 7 deletions src/engine/rendergl.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// rendergl.cpp: core opengl rendering stuff
#include <algorithm>
using std::swap;

#include "engine.h"

bool hasVAO = false, hasFBO = false, hasAFBO = false, hasDS = false, hasTF = false, hasTRG = false, hasTSW = false, hasS3TC = false, hasFXT1 = false, hasLATC = false, hasRGTC = false, hasAF = false, hasFBB = false, hasUBO = false, hasMBR = false;
Expand Down Expand Up @@ -1487,10 +1484,10 @@ void drawcubemap(int level, const vec &o, float yaw, float pitch, bool flipx, bo
if(flipx || flipy) projmatrix.scalexy(flipx ? -1 : 1, flipy ? -1 : 1);
if(swapxy)
{
swap(projmatrix.a.x, projmatrix.a.y);
swap(projmatrix.b.x, projmatrix.b.y);
swap(projmatrix.c.x, projmatrix.c.y);
swap(projmatrix.d.x, projmatrix.d.y);
std::swap(projmatrix.a.x, projmatrix.a.y);
std::swap(projmatrix.b.x, projmatrix.b.y);
std::swap(projmatrix.c.x, projmatrix.c.y);
std::swap(projmatrix.d.x, projmatrix.d.y);
}
setcamprojmatrix();

Expand Down
2 changes: 0 additions & 2 deletions src/engine/rendermodel.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include <algorithm>
using std::swap;
#include "engine.h"

VAR(0, oqdynent, 0, 1, 1);
Expand Down
Loading

0 comments on commit 326acad

Please sign in to comment.