mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2024-11-23 21:07:17 +00:00
Merge pull request #47 from Quuxplusone/misc-portability
Eliminate VLAs; eliminate std::random_shuffle()
This commit is contained in:
commit
5ab0f98c83
@ -8,7 +8,7 @@
|
||||
|
||||
CXXFLAGS += -std=c++11 -march=native -DMAC
|
||||
CXXFLAGS += -W -Wall -Wextra -pedantic
|
||||
CXXFLAGS += -Wno-format-pedantic -Wno-unused-parameter -Wno-missing-field-initializers -Wno-vla-extension
|
||||
CXXFLAGS += -Wno-format-pedantic -Wno-unused-parameter -Wno-missing-field-initializers
|
||||
CXXFLAGS += -I/usr/local/include
|
||||
CXXFLAGS += ${EXTRA_CXXFLAGS}
|
||||
|
||||
|
@ -360,9 +360,9 @@ void sdltogl(SDL_Surface *txt, glfont_t& f, int ch) {
|
||||
int theight = next_p2( otheight );
|
||||
|
||||
#if CAP_TABFONT
|
||||
int expanded_data[twidth * theight];
|
||||
std::vector<int> expanded_data(twidth * theight);
|
||||
#else
|
||||
Uint16 expanded_data[twidth * theight];
|
||||
std::vector<Uint16> expanded_data(twidth * theight);
|
||||
#endif
|
||||
|
||||
for(int j=0; j <theight;j++) for(int i=0; i < twidth; i++) {
|
||||
@ -387,7 +387,7 @@ void sdltogl(SDL_Surface *txt, glfont_t& f, int ch) {
|
||||
#else
|
||||
GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE,
|
||||
#endif
|
||||
expanded_data );
|
||||
expanded_data.data() );
|
||||
|
||||
float x=(float)otwidth / (float)twidth;
|
||||
float y=(float)otheight / (float)theight;
|
||||
|
@ -176,7 +176,7 @@ heptagon *createAlternateMap(cell *c, int rad, hstate firststate, int special) {
|
||||
|
||||
// okay, let's go then!
|
||||
cellwalker bf(c, gdir);
|
||||
cell *cx[rad+1];
|
||||
std::vector<cell *> cx(rad+1);
|
||||
for(int i=0; i<rad; i++) {
|
||||
cx[i] = bf.c;
|
||||
bf += revstep;
|
||||
@ -1347,4 +1347,4 @@ void moreBigStuff(cell *c) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -92,9 +92,6 @@ namespace hr { namespace inv { bool on, activating; } }
|
||||
#if CAP_TOUR
|
||||
#include "tour.cpp"
|
||||
#endif
|
||||
#if ISMOBILE==0
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include "commandline.cpp"
|
||||
#include "bigstuff.cpp"
|
||||
|
||||
|
@ -2046,7 +2046,7 @@ void livecaves() {
|
||||
vector<cell*> bringlife;
|
||||
int gr = gamerange();
|
||||
|
||||
int heatvals[dcs];
|
||||
std::vector<int> heatvals(dcs);
|
||||
|
||||
for(int i=0; i<dcs; i++) {
|
||||
cell *c = allcells[i];
|
||||
@ -2991,7 +2991,7 @@ namespace ca {
|
||||
if(cwt.c->land != laCA) return;
|
||||
vector<cell*>& allcells = currentmap->allcells();
|
||||
int dcs = isize(allcells);
|
||||
bool willlive[dcs];
|
||||
std::vector<bool> willlive(dcs);
|
||||
for(int i=0; i<dcs; i++) {
|
||||
cell *c = allcells[i];
|
||||
if(c->land != laCA) return;
|
||||
@ -3126,9 +3126,9 @@ namespace windmap {
|
||||
|
||||
for(int i=0; i<N; i++) windcodes[i] = hrand(256);
|
||||
|
||||
bool inqueue[N];
|
||||
vector<bool> inqueue(N, true);
|
||||
vector<int> tocheck;
|
||||
for(int i=0; i<N; i++) tocheck.push_back(i), inqueue[i] = true;
|
||||
for(int i=0; i<N; i++) tocheck.push_back(i);
|
||||
hrandom_shuffle(&tocheck[0], isize(tocheck));
|
||||
|
||||
for(int a=0; a<isize(tocheck); a++) {
|
||||
|
@ -219,12 +219,11 @@ struct fpattern {
|
||||
} else wsquare = 0;
|
||||
|
||||
#ifdef EASY
|
||||
int sqrts[Prime];
|
||||
for(int k=0; k<Prime; k++) sqrts[k] = 0;
|
||||
std::vector<int> sqrts(Prime, 0);
|
||||
for(int k=1-Prime; k<Prime; k++) sqrts[sqr(k)] = k;
|
||||
int fmax = Prime;
|
||||
#else
|
||||
int sqrts[Field];
|
||||
std::vector<int> sqrts(Field);
|
||||
for(int k=0; k<Field; k++) sqrts[sqr(k)] = k;
|
||||
int fmax = Field;
|
||||
#endif
|
||||
|
2
game.cpp
2
game.cpp
@ -4732,7 +4732,7 @@ void movehex(bool mounted, int colorpair) {
|
||||
for(int t=0; t<c->type; t++) if(c->mov[t] && inpair(c->mov[t], colorpair))
|
||||
dirtable[qdirtable++] = t;
|
||||
|
||||
random_shuffle(dirtable, dirtable+qdirtable);
|
||||
hrandom_shuffle(dirtable, qdirtable);
|
||||
while(qdirtable--) {
|
||||
int t = dirtable[qdirtable];
|
||||
hexvisit(c->mov[t], c, t, mounted, colorpair);
|
||||
|
1
hyper.h
1
hyper.h
@ -37,7 +37,6 @@ using std::imag;
|
||||
using std::stable_sort;
|
||||
using std::out_of_range;
|
||||
using std::get;
|
||||
using std::random_shuffle;
|
||||
using std::move;
|
||||
using std::make_tuple;
|
||||
|
||||
|
@ -201,9 +201,9 @@ void polylineColor(SDL_Surface *s, int *x, int *y, int polyi, int col) {
|
||||
}
|
||||
|
||||
void filledPolygonColorI(SDL_Surface *s, int* px, int *py, int polyi, int col) {
|
||||
Sint16 spx[polyi], spy[polyi];
|
||||
for(int i=0; i<polyi; i++) spx[i] = px[i], spy[i] = py[i];
|
||||
filledPolygonColor(s, spx, spy, polyi, col);
|
||||
std::vector<Sint16> spx(px, px + polyi);
|
||||
std::vector<Sint16> spy(py, py + polyi);
|
||||
filledPolygonColor(s, spx.data(), spy.data(), polyi, col);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -691,7 +691,7 @@ void describe(cell *c) {
|
||||
help += "\n";
|
||||
vector<pair<double, int>> v;
|
||||
for(int s=0; s<samples; s++) if(whowon[s] == n) v.emplace_back(vnorm(n->net, data[s].val), s);
|
||||
random_shuffle(v.begin(), v.end());
|
||||
hrandom_shuffle(&v[0], isize(v));
|
||||
sort(v.begin(), v.end(), [] (pair<double,int> a, pair<double,int> b) { return a.first < b.first; });
|
||||
|
||||
for(int i=0; i<isize(v) && i<20; i++) {
|
||||
|
12
shaders.cpp
12
shaders.cpp
@ -172,10 +172,10 @@ int compileShader(int type, const string& s) {
|
||||
GLint logLength;
|
||||
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &logLength);
|
||||
if (logLength > 0) {
|
||||
char log[logLength];
|
||||
glGetShaderInfoLog(shader, logLength, &logLength, log);
|
||||
std::vector<char> log(logLength);
|
||||
glGetShaderInfoLog(shader, logLength, &logLength, log.data());
|
||||
if(logLength > 0)
|
||||
printf("compiler log (%d): '%s'\n", logLength, log);
|
||||
printf("compiler log (%d): '%s'\n", logLength, log.data());
|
||||
}
|
||||
|
||||
glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
|
||||
@ -232,10 +232,10 @@ struct GLprogram {
|
||||
GLint logLength;
|
||||
glGetProgramiv(_program, GL_INFO_LOG_LENGTH, &logLength);
|
||||
if (logLength > 0) {
|
||||
char log[logLength];
|
||||
glGetProgramInfoLog(_program, logLength, &logLength, log);
|
||||
std::vector<char> log(logLength);
|
||||
glGetProgramInfoLog(_program, logLength, &logLength, log.data());
|
||||
if(logLength > 0)
|
||||
printf("linking log (%d): %s\n", logLength, log);
|
||||
printf("linking log (%d): %s\n", logLength, log.data());
|
||||
}
|
||||
|
||||
glGetProgramiv(_program, GL_LINK_STATUS, &status);
|
||||
|
Loading…
Reference in New Issue
Block a user