From 601af1feff18fd7c9a53a52f00687013c3a88c60 Mon Sep 17 00:00:00 2001 From: jacob1 Date: Mon, 23 Apr 2018 21:57:30 -0400 Subject: [PATCH] fix compile warnings, remove ugly PRTI/PRTO hack --- src/common/tpt-rand.cpp | 8 +++++--- src/common/tpt-rand.h | 2 +- src/simulation/Simulation.cpp | 2 +- src/simulation/Simulation.h | 2 +- src/simulation/elements/ACID.cpp | 2 +- src/simulation/elements/CAUS.cpp | 2 +- src/simulation/elements/EXOT.cpp | 2 +- src/simulation/elements/FIRE.cpp | 4 ++-- src/simulation/elements/FRZW.cpp | 2 +- src/simulation/elements/ISOZ.cpp | 2 +- src/simulation/elements/ISZS.cpp | 2 +- src/simulation/elements/LIGH.cpp | 4 ++-- src/simulation/elements/NEUT.cpp | 4 ++-- src/simulation/elements/PLUT.cpp | 2 +- src/simulation/elements/PROT.cpp | 2 +- src/simulation/elements/PRTI.cpp | 4 ++-- src/simulation/elements/PRTO.cpp | 4 ++-- src/simulation/elements/VIRS.cpp | 2 +- 18 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/common/tpt-rand.cpp b/src/common/tpt-rand.cpp index 9c151134a..be1f6aaba 100644 --- a/src/common/tpt-rand.cpp +++ b/src/common/tpt-rand.cpp @@ -3,11 +3,13 @@ /* xoroshiro128+ by David Blackman and Sebastiano Vigna */ -static inline uint64_t rotl(const uint64_t x, int k) { +static inline uint64_t rotl(const uint64_t x, int k) +{ return (x << k) | (x >> (64 - k)); } -uint64_t RandomGen::next(void) { +uint64_t RandomGen::next() +{ const uint64_t s0 = s[0]; uint64_t s1 = s[1]; const uint64_t result = s0 + s1; @@ -27,7 +29,7 @@ unsigned int RandomGen::operator()() unsigned int RandomGen::between(unsigned int lower, unsigned int upper) { unsigned int r = (*this)(); - + return r % (upper - lower + 1) + lower; } diff --git a/src/common/tpt-rand.h b/src/common/tpt-rand.h index 6d877b939..274e452cb 100644 --- a/src/common/tpt-rand.h +++ b/src/common/tpt-rand.h @@ -7,7 +7,7 @@ class RandomGen { private: uint64_t s[2]; - uint64_t next(void); + uint64_t next(); public: unsigned int operator()(); unsigned int between(unsigned int lower, unsigned int upper); diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index 9cae922e7..4053a6ef5 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -5137,7 +5137,7 @@ void Simulation::CheckStacking() excessive_stacking_found = 1; } } - else if (pmap_count[y][x]>1500 || (random_gen()%1600)<=(pmap_count[y][x]+100)) + else if (pmap_count[y][x]>1500 || (random_gen()%1600) <= (pmap_count[y][x]+100)) { pmap_count[y][x] = pmap_count[y][x] + NPART; excessive_stacking_found = true; diff --git a/src/simulation/Simulation.h b/src/simulation/Simulation.h index c79cea842..3ae09fabd 100644 --- a/src/simulation/Simulation.h +++ b/src/simulation/Simulation.h @@ -101,7 +101,7 @@ public: Particle parts[NPART]; int pmap[YRES][XRES]; int photons[YRES][XRES]; - int pmap_count[YRES][XRES]; + unsigned int pmap_count[YRES][XRES]; //Simulation Settings int edgeMode; int gravityMode; diff --git a/src/simulation/elements/ACID.cpp b/src/simulation/elements/ACID.cpp index 2d0e65d20..9a11bd8d6 100644 --- a/src/simulation/elements/ACID.cpp +++ b/src/simulation/elements/ACID.cpp @@ -76,7 +76,7 @@ int Element_ACID::update(UPDATE_FUNC_ARGS) sim->kill_part(ID(r)); } } - else if ((rt != PT_CLNE && rt != PT_PCLN && sim->elements[rt].Hardness>(random_gen()%1000))&&parts[i].life>=50) + else if ((rt != PT_CLNE && rt != PT_PCLN && (unsigned int)sim->elements[rt].Hardness>(random_gen()%1000))&&parts[i].life>=50) { if (sim->parts_avg(i, ID(r),PT_GLAS)!= PT_GLAS)//GLAS protects stuff from acid { diff --git a/src/simulation/elements/CAUS.cpp b/src/simulation/elements/CAUS.cpp index ee330a6b2..b952f2188 100644 --- a/src/simulation/elements/CAUS.cpp +++ b/src/simulation/elements/CAUS.cpp @@ -64,7 +64,7 @@ int Element_CAUS::update(UPDATE_FUNC_ARGS) } else if (TYP(r) != PT_ACID && TYP(r) != PT_CAUS && TYP(r) != PT_RFRG && TYP(r) != PT_RFGL) { - if ((TYP(r) != PT_CLNE && TYP(r) != PT_PCLN && sim->elements[TYP(r)].Hardness > (random_gen()%1000)) && parts[i].life >= 50) + if ((TYP(r) != PT_CLNE && TYP(r) != PT_PCLN && (unsigned int)sim->elements[TYP(r)].Hardness > (random_gen()%1000)) && parts[i].life >= 50) { // GLAS protects stuff from acid if (sim->parts_avg(i, ID(r),PT_GLAS) != PT_GLAS) diff --git a/src/simulation/elements/EXOT.cpp b/src/simulation/elements/EXOT.cpp index 28268df42..5eb61ee0a 100644 --- a/src/simulation/elements/EXOT.cpp +++ b/src/simulation/elements/EXOT.cpp @@ -186,7 +186,7 @@ int Element_EXOT::graphics(GRAPHICS_FUNC_ARGS) int c = cpart->tmp2; if (cpart->life < 1001) { - if ((cpart->tmp2 - 1)>random_gen()%1000) + if ((cpart->tmp2 - 1) > (int)(random_gen()%1000)) { float frequency = 0.04045; *colr = (sin(frequency*c + 4) * 127 + 150); diff --git a/src/simulation/elements/FIRE.cpp b/src/simulation/elements/FIRE.cpp index a81c04c53..ee1dc0d97 100644 --- a/src/simulation/elements/FIRE.cpp +++ b/src/simulation/elements/FIRE.cpp @@ -153,7 +153,7 @@ int Element_FIRE::update(UPDATE_FUNC_ARGS) } if ((surround_space || sim->elements[rt].Explosive) && - sim->elements[rt].Flammable && (sim->elements[rt].Flammable + (int)(sim->pv[(y+ry)/CELL][(x+rx)/CELL] * 10.0f)) > (random_gen()%1000) && + sim->elements[rt].Flammable && (sim->elements[rt].Flammable + (sim->pv[(y+ry)/CELL][(x+rx)/CELL] * 10.0f)) > (random_gen()%1000) && //exceptions, t is the thing causing the spark and rt is what's burning (t != PT_SPRK || (rt != PT_RBDM && rt != PT_LRBD && rt != PT_INSL)) && (t != PT_PHOT || rt != PT_INSL) && @@ -188,7 +188,7 @@ int Element_FIRE::updateLegacy(UPDATE_FUNC_ARGS) { lpv = (int)sim->pv[(y+ry)/CELL][(x+rx)/CELL]; if (lpv < 1) lpv = 1; - if (sim->elements[rt].Meltable && ((rt!=PT_RBDM && rt!=PT_LRBD) || t!=PT_SPRK) && ((t!=PT_FIRE&&t!=PT_PLSM) || (rt!=PT_METL && rt!=PT_IRON && rt!=PT_ETRD && rt!=PT_PSCN && rt!=PT_NSCN && rt!=PT_NTCT && rt!=PT_PTCT && rt!=PT_BMTL && rt!=PT_BRMT && rt!=PT_SALT && rt!=PT_INWR)) &&sim->elements[rt].Meltable*lpv>(random_gen()%1000)) + if (sim->elements[rt].Meltable && ((rt!=PT_RBDM && rt!=PT_LRBD) || t!=PT_SPRK) && ((t!=PT_FIRE&&t!=PT_PLSM) || (rt!=PT_METL && rt!=PT_IRON && rt!=PT_ETRD && rt!=PT_PSCN && rt!=PT_NSCN && rt!=PT_NTCT && rt!=PT_PTCT && rt!=PT_BMTL && rt!=PT_BRMT && rt!=PT_SALT && rt!=PT_INWR)) && (unsigned int)sim->elements[rt].Meltable*lpv>(random_gen()%1000)) { if (t!=PT_LAVA || parts[i].life>0) { diff --git a/src/simulation/elements/FRZW.cpp b/src/simulation/elements/FRZW.cpp index 1f5b997fb..b63e7e38d 100644 --- a/src/simulation/elements/FRZW.cpp +++ b/src/simulation/elements/FRZW.cpp @@ -60,7 +60,7 @@ int Element_FRZW::update(UPDATE_FUNC_ARGS) sim->part_change_type(ID(r),x+rx,y+ry,PT_FRZW); } } - if ((parts[i].life==0 && !(random_gen()%192)) || (100-(parts[i].life))>random_gen()%50000 ) + if ((parts[i].life==0 && !(random_gen()%192)) || (100-(parts[i].life)) > (int)(random_gen()%50000)) { sim->part_change_type(i,x,y,PT_ICEI); parts[i].ctype=PT_FRZW; diff --git a/src/simulation/elements/ISOZ.cpp b/src/simulation/elements/ISOZ.cpp index 252e7b0e5..4766755cb 100644 --- a/src/simulation/elements/ISOZ.cpp +++ b/src/simulation/elements/ISOZ.cpp @@ -48,7 +48,7 @@ Element_ISOZ::Element_ISOZ() int Element_ISOZ::update(UPDATE_FUNC_ARGS) { // for both ISZS and ISOZ float rr, rrr; - if (!(random_gen()%200) && ((int)(-4.0f*(sim->pv[y/CELL][x/CELL])))>(random_gen()%1000)) + if (!(random_gen()%200) && (-4.0f*(sim->pv[y/CELL][x/CELL])) > (random_gen()%1000)) { sim->create_part(i, x, y, PT_PHOT); rr = (random_gen()%228+128)/127.0f; diff --git a/src/simulation/elements/ISZS.cpp b/src/simulation/elements/ISZS.cpp index 7b357f3ff..97cf468ae 100644 --- a/src/simulation/elements/ISZS.cpp +++ b/src/simulation/elements/ISZS.cpp @@ -48,7 +48,7 @@ Element_ISZS::Element_ISZS() int Element_ISZS::update(UPDATE_FUNC_ARGS) { // for both ISZS and ISOZ float rr, rrr; - if (!(random_gen()%200) && ((int)(-4.0f*(sim->pv[y/CELL][x/CELL])))>(random_gen()%1000)) + if (!(random_gen()%200) && (-4.0f*(sim->pv[y/CELL][x/CELL])) > (random_gen()%1000)) { sim->create_part(i, x, y, PT_PHOT); rr = (random_gen()%228+128)/127.0f; diff --git a/src/simulation/elements/LIGH.cpp b/src/simulation/elements/LIGH.cpp index e22c79529..50fa57c1d 100644 --- a/src/simulation/elements/LIGH.cpp +++ b/src/simulation/elements/LIGH.cpp @@ -91,7 +91,7 @@ int Element_LIGH::update(UPDATE_FUNC_ARGS) rt = TYP(r); if ((surround_space || sim->elements[rt].Explosive) && (rt!=PT_SPNG || parts[ID(r)].life==0) && - sim->elements[rt].Flammable && (sim->elements[rt].Flammable + (int)(sim->pv[(y+ry)/CELL][(x+rx)/CELL]*10.0f))>(random_gen()%1000)) + sim->elements[rt].Flammable && (sim->elements[rt].Flammable + (sim->pv[(y+ry)/CELL][(x+rx)/CELL]*10.0f)) > (random_gen()%1000)) { sim->part_change_type(ID(r),x+rx,y+ry,PT_FIRE); parts[ID(r)].temp = restrict_flt(sim->elements[PT_FIRE].Temperature + (sim->elements[rt].Flammable/2), MIN_TEMP, MAX_TEMP); @@ -278,7 +278,7 @@ bool Element_LIGH::create_LIGH(Simulation * sim, int x, int y, int c, int temp, sim->parts[p].tmp = tmp; if (last) { - sim->parts[p].tmp2=1+(random_gen()%200>tmp2*tmp2/10+60); + sim->parts[p].tmp2=1+((int)(random_gen()%200) > tmp2*tmp2/10+60); sim->parts[p].life=(int)(life/1.5-random_gen()%2); } else diff --git a/src/simulation/elements/NEUT.cpp b/src/simulation/elements/NEUT.cpp index 1dd20b7fd..3351b913f 100644 --- a/src/simulation/elements/NEUT.cpp +++ b/src/simulation/elements/NEUT.cpp @@ -49,7 +49,7 @@ Element_NEUT::Element_NEUT() int Element_NEUT::update(UPDATE_FUNC_ARGS) { int r, rx, ry; - int pressureFactor = 3 + (int)sim->pv[y/CELL][x/CELL]; + unsigned int pressureFactor = 3 + (int)sim->pv[y/CELL][x/CELL]; for (rx=-1; rx<2; rx++) for (ry=-1; ry<2; ry++) if (BOUNDS_CHECK) @@ -66,7 +66,7 @@ int Element_NEUT::update(UPDATE_FUNC_ARGS) parts[i].vy *= 0.995; break; case PT_PLUT: - if (pressureFactor>(random_gen()%1000)) + if (pressureFactor > (random_gen()%1000)) { if (!(random_gen()%3)) { diff --git a/src/simulation/elements/PLUT.cpp b/src/simulation/elements/PLUT.cpp index 1e8025a32..57ea9c5ca 100644 --- a/src/simulation/elements/PLUT.cpp +++ b/src/simulation/elements/PLUT.cpp @@ -48,7 +48,7 @@ Element_PLUT::Element_PLUT() //#TPT-Directive ElementHeader Element_PLUT static int update(UPDATE_FUNC_ARGS) int Element_PLUT::update(UPDATE_FUNC_ARGS) { - if (!(random_gen()%100) && ((int)(5.0f*sim->pv[y/CELL][x/CELL]))>(random_gen()%1000)) + if (!(random_gen()%100) && (5.0f*sim->pv[y/CELL][x/CELL]) > (random_gen()%1000)) { sim->create_part(i, x, y, PT_NEUT); } diff --git a/src/simulation/elements/PROT.cpp b/src/simulation/elements/PROT.cpp index febb48dd3..34576da71 100644 --- a/src/simulation/elements/PROT.cpp +++ b/src/simulation/elements/PROT.cpp @@ -68,7 +68,7 @@ int Element_PROT::update(UPDATE_FUNC_ARGS) break; } case PT_DEUT: - if ((-((int)sim->pv[y / CELL][x / CELL] - 4) + (parts[uID].life / 100)) > random_gen() % 200) + if ((-((int)sim->pv[y / CELL][x / CELL] - 4) + (parts[uID].life / 100)) > (int)(random_gen() % 200)) { DeutImplosion(sim, parts[uID].life, x, y, restrict_flt(parts[uID].temp + parts[uID].life * 500, MIN_TEMP, MAX_TEMP), PT_PROT); sim->kill_part(uID); diff --git a/src/simulation/elements/PRTI.cpp b/src/simulation/elements/PRTI.cpp index 1a9b7e637..9cdbd7e49 100644 --- a/src/simulation/elements/PRTI.cpp +++ b/src/simulation/elements/PRTI.cpp @@ -116,8 +116,8 @@ int Element_PRTI::update(UPDATE_FUNC_ARGS) if (fe) { int orbd[4] = {0, 0, 0, 0}; //Orbital distances int orbl[4] = {0, 0, 0, 0}; //Orbital locations - if (!sim->parts[i].life) parts[i].life = random_gen()*random_gen()*random_gen(); - if (!sim->parts[i].ctype) parts[i].ctype = random_gen()*random_gen()*random_gen(); + if (!sim->parts[i].life) parts[i].life = random_gen(); + if (!sim->parts[i].ctype) parts[i].ctype = random_gen(); sim->orbitalparts_get(parts[i].life, parts[i].ctype, orbd, orbl); for (int r = 0; r < 4; r++) { if (orbd[r]>1) { diff --git a/src/simulation/elements/PRTO.cpp b/src/simulation/elements/PRTO.cpp index 5f4ed9e38..ad2c92a40 100644 --- a/src/simulation/elements/PRTO.cpp +++ b/src/simulation/elements/PRTO.cpp @@ -141,8 +141,8 @@ int Element_PRTO::update(UPDATE_FUNC_ARGS) if (fe) { int orbd[4] = {0, 0, 0, 0}; //Orbital distances int orbl[4] = {0, 0, 0, 0}; //Orbital locations - if (!sim->parts[i].life) parts[i].life = random_gen()*random_gen()*random_gen(); - if (!sim->parts[i].ctype) parts[i].ctype = random_gen()*random_gen()*random_gen(); + if (!sim->parts[i].life) parts[i].life = random_gen(); + if (!sim->parts[i].ctype) parts[i].ctype = random_gen(); sim->orbitalparts_get(parts[i].life, parts[i].ctype, orbd, orbl); for (r = 0; r < 4; r++) { if (orbd[r]<254) { diff --git a/src/simulation/elements/VIRS.cpp b/src/simulation/elements/VIRS.cpp index 009ff0008..906fa62df 100644 --- a/src/simulation/elements/VIRS.cpp +++ b/src/simulation/elements/VIRS.cpp @@ -101,7 +101,7 @@ int Element_VIRS::update(UPDATE_FUNC_ARGS) } else if (TYP(r) == PT_PLSM) { - if (surround_space && 10 + (int)(sim->pv[(y+ry)/CELL][(x+rx)/CELL]) > (random_gen()%100)) + if (surround_space && 10 + sim->pv[(y+ry)/CELL][(x+rx)/CELL] > (random_gen()%100)) { sim->create_part(i, x, y, PT_PLSM); return 1;