1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2025-02-02 12:19:18 +00:00

refactored colortables

This commit is contained in:
Zeno Rogue 2018-11-08 16:21:33 +01:00
parent be4dee6f0b
commit b019cfcd4f
4 changed files with 140 additions and 158 deletions

View File

@ -519,7 +519,7 @@ void do_viewdist(cell *c, const transmatrix& V, color_t& wcol, color_t& fcol) {
int cd = (use_color_codes || number_coding == ncDistance || number_coding == ncDebug) ? curr_dist(c) : 0; int cd = (use_color_codes || number_coding == ncDistance || number_coding == ncDebug) ? curr_dist(c) : 0;
if(use_color_codes) { if(use_color_codes) {
int dc = distcolors[cd&7]; int dc = distcolors[cd];
wcol = gradient(wcol, dc, 0, .4, 1); wcol = gradient(wcol, dc, 0, .4, 1);
fcol = gradient(fcol, dc, 0, .4, 1); fcol = gradient(fcol, dc, 0, .4, 1);
} }
@ -530,7 +530,7 @@ void do_viewdist(cell *c, const transmatrix& V, color_t& wcol, color_t& fcol) {
switch(number_coding) { switch(number_coding) {
case ncDistance: { case ncDistance: {
label = its(cd); label = its(cd);
dc = distcolors[cd&7]; dc = distcolors[cd];
break; break;
} }
case ncType: { case ncType: {
@ -627,7 +627,7 @@ void expansion_analyzer::view_distances_dialog() {
} }
lastticks = SDL_GetTicks(); lastticks = SDL_GetTicks();
distcolors[0] = forecolor; dynamicval<color_t> dv(distcolors[0], forecolor);
dialog::init(""); dialog::init("");
cmode |= sm::DIALOG_STRICT_X | sm::EXPANSION; cmode |= sm::DIALOG_STRICT_X | sm::EXPANSION;
@ -665,7 +665,7 @@ void expansion_analyzer::view_distances_dialog() {
dialog::addBreak(100 - 100 * scrolltime / scrollspeed); dialog::addBreak(100 - 100 * scrolltime / scrollspeed);
for(int i=first_distance; i<maxlen; i++) if(!qty[i].digits.empty()) for(int i=first_distance; i<maxlen; i++) if(!qty[i].digits.empty())
dialog::addInfo(its(i) + ": " + qty[i].get_str(100), distcolors[i&7]); dialog::addInfo(its(i) + ": " + qty[i].get_str(100), distcolors[i]);
dialog::addBreak(100 * scrolltime / scrollspeed); dialog::addBreak(100 * scrolltime / scrollspeed);

View File

@ -2425,12 +2425,12 @@ bool bugsNearby(cell *c, int dist = 2) {
return false; return false;
} }
int minecolors[8] = { colortable minecolors = {
0xFFFFFF, 0xF0, 0xF060, 0xF00000, 0xFFFFFF, 0xF0, 0xF060, 0xF00000,
0x60, 0x600000, 0x00C0C0, 0x000000 0x60, 0x600000, 0x00C0C0, 0x000000
}; };
int distcolors[8] = { colortable distcolors = {
0xFFFFFF, 0xF0, 0xF060, 0xF00000, 0xFFFFFF, 0xF0, 0xF060, 0xF00000,
0xA0A000, 0xA000A0, 0x00A0A0, 0xFFD500 0xA0A000, 0xA000A0, 0x00A0A0, 0xFFD500
}; };
@ -2689,7 +2689,7 @@ ld wavefun(ld x) {
else return 0; */ else return 0; */
} }
const unsigned int nestcolors[8] = { 0x800000, 0x008000, 0x000080, 0x404040, 0x700070, 0x007070, 0x707000, 0x606060 }; colortable nestcolors = { 0x800000, 0x008000, 0x000080, 0x404040, 0x700070, 0x007070, 0x707000, 0x606060 };
void setcolors(cell *c, color_t& wcol, color_t& fcol) { void setcolors(cell *c, color_t& wcol, color_t& fcol) {
@ -4525,7 +4525,7 @@ void drawcell(cell *c, transmatrix V, int spinv, bool mirrored) {
case waMineOpen: { case waMineOpen: {
int mines = countMinesAround(c); int mines = countMinesAround(c);
if(mines) if(mines)
queuepoly(V, shMineMark[ct6], (minecolors[mines] << 8) | 0xFF); queuepoly(V, shMineMark[ct6], darkena(minecolors[mines], 0, 0xFF));
break; break;
} }

11
hyper.h
View File

@ -2372,13 +2372,20 @@ int textwidth(int siz, const string &str);
extern bool gtouched, mousepressed, mousemoved, actonrelease; extern bool gtouched, mousepressed, mousemoved, actonrelease;
extern bool inslider; extern bool inslider;
struct colortable: vector<color_t> {
color_t& operator [] (int i) { i %= size(); if(i<0) i += size(); return ((vector<color_t>&)(*this)) [i]; }
const color_t& operator [] (int i) const { i %= size(); if(i<0) i += size(); return ((vector<color_t>&)(*this)) [i]; }
colortable(std::initializer_list<color_t> v) : vector(v) {}
colortable() : vector({0}) {}
};
extern bool outoffocus; extern bool outoffocus;
extern int frames; extern int frames;
extern transmatrix playerV; extern transmatrix playerV;
extern bool didsomething; extern bool didsomething;
extern void drawStats(); extern void drawStats();
extern int calcfps(); extern int calcfps();
extern int distcolors[8]; extern colortable distcolors, minecolors;
extern eItem orbToTarget; extern eItem orbToTarget;
extern eMonster monsterToSummon; extern eMonster monsterToSummon;
@ -3043,7 +3050,7 @@ int emeraldval(cell *c);
int inpair(cell *c, int colorpair); int inpair(cell *c, int colorpair);
int snake_pair(cell *c); int snake_pair(cell *c);
extern const color_t nestcolors[8]; extern colortable nestcolors;
#if CAP_TEXTURE #if CAP_TEXTURE
namespace texture { namespace texture {

View File

@ -1264,6 +1264,48 @@ bool warptype(cell *c) {
return pattern_threecolor(c) == 0; return pattern_threecolor(c) == 0;
} }
map<char, colortable> colortables = {
{'A', {
0xF04040, 0x40F040, 0x4040F0,
0xD0D000, 0xD000D0, 0x00D0D0,
0xC0C0C0, 0x404040, 0x808080,
0xF08040, 0xF04080, 0x40F080,
0x4080F0, 0x8040F0, 0x80F040,
0xFFD500 }},
{'B', {
// trying to get colors as in Wikipedia [ https://en.wikipedia.org/wiki/Euclidean_tilings_by_convex_regular_polygons#k-uniform_tilings ]
0, 0, 0xFFFFFF, 0xFFFF00,
0xFF0000, 0xC000C0 /* unknown5 */, 0x00FF00, 0x00C0C0 /* unknown7 */, 0xFF8000,
0xFFFF80, 0xC040C0, 0xFFD500, 0x000080,
0x404040, 0x606060, 0x808080
}},
{'a', {0x800000, 0x503000, 0x206000, 0x007010, 0x004040, 0x001070, 0x200060, 0x500030}},
{'e', {0x404040, 0x800000, 0x008000, 0x000080 }},
{'b', {0x404040, 0x800000, 0x008000, 0x000080 }},
{'z', {0xC0C0C0, 0xE0E0E0, 0x404040, 0x606060 }},
{'x', {0xC0C0C0, 0x800000, 0x008000, 0x000080 }},
{'t', {0x804040, 0x408040, 0x404080, 0x808040 }},
{'c', {0x202020, 0xC0C0C0}},
{'F', {0xC0C0C0, 0x202020}},
{'w', {0x303030, 0xC0C0C0}}
};
color_t random_landscape(cell *c, int mul, int div, int step) {
int col[4];
for(int j=0; j<4; j++) {
col[j] = getCdata(c, j);
col[j] *= mul;
col[j] %= 240;
if(col[j] > 120) col[j] = 240 - col[j];
if(col[j] < -120) col[j] = -240 - col[j];
}
col[0] /= div;
col[1] /= div;
col[2] /= div;
if(ISWEB) for(int a=0; a<3; a++) col[a] = (col[a] + step/2) / step * step;
return (0x808080 + col[0] + (col[1] << 8) + (col[2] << 16));
}
namespace patterns { namespace patterns {
int canvasback = linf[laCanvas].color >> 2; int canvasback = linf[laCanvas].color >> 2;
int subcanvas; int subcanvas;
@ -1272,27 +1314,13 @@ namespace patterns {
char whichCanvas = 0; char whichCanvas = 0;
int generateCanvas(cell *c) { int generateCanvas(cell *c) {
if(whichCanvas == 'A' && archimedean) { switch(whichCanvas) {
int gcolors[16] = { case 'A':
0xF04040, 0x40F040, 0x4040F0, if(archimedean) return colortables['A'][arcm::current.tilegroup[arcm::id_of(c->master)]];
0xD0D000, 0xD000D0, 0x00D0D0, case 'B':
0xC0C0C0, 0x404040, 0x808080, return colortables['B'][c->type & 15];
0xF08040, 0xF04080, 0x40F080, case 'C': {
0x4080F0, 0x8040F0, 0x80F040, if(!hyperbolic) return canvasback;
0xFFD500 };
return gcolors[arcm::current.tilegroup[arcm::id_of(c->master)] & 15];
}
if(whichCanvas == 'B') {
int gcolors[16] = {
// trying to get colors as in Wikipedia [ https://en.wikipedia.org/wiki/Euclidean_tilings_by_convex_regular_polygons#k-uniform_tilings ]
0, 0, 0xFFFFFF, 0xFFFF00,
0xFF0000, 0xC000C0 /* unknown5 */, 0x00FF00, 0x00C0C0 /* unknown7 */, 0xFF8000,
0xFFFF80, 0xC040C0, 0xFFD500, 0x000080,
0x404040, 0x606060, 0x808080
};
return gcolors[c->type & 15];
}
if(whichCanvas == 'C' && hyperbolic) {
using namespace fieldpattern; using namespace fieldpattern;
int z = currfp.getdist(fieldval(c), make_pair(0,false)); int z = currfp.getdist(fieldval(c), make_pair(0,false));
if(z < currfp.circrad) return 0x00C000; if(z < currfp.circrad) return 0x00C000;
@ -1301,12 +1329,14 @@ namespace patterns {
return 0x3000; return 0x3000;
return 0x6000; return 0x6000;
} }
if(whichCanvas == 'D' && hyperbolic) { case 'D': {
if(!hyperbolic) return canvasback;
using namespace fieldpattern; using namespace fieldpattern;
int z = currfp.getdist(fieldval(c), make_pair(0,false)); int z = currfp.getdist(fieldval(c), make_pair(0,false));
return 255 * (currfp.maxdist+1-z) / currfp.maxdist; return 255 * (currfp.maxdist+1-z) / currfp.maxdist;
} }
if(whichCanvas == 'N' && hyperbolic) { case 'N': {
if(!hyperbolic) return canvasback;
using namespace fieldpattern; using namespace fieldpattern;
int z = currfp.getdist(fieldval(c), make_pair(0,false)); int z = currfp.getdist(fieldval(c), make_pair(0,false));
int z2 = currfp.getdist(fieldval(c), make_pair(currfp.otherpole,false)); int z2 = currfp.getdist(fieldval(c), make_pair(currfp.otherpole,false));
@ -1314,116 +1344,47 @@ namespace patterns {
if(z > z2) return 0xC00000; if(z > z2) return 0xC00000;
return 0xCCCC00; return 0xCCCC00;
} }
if(whichCanvas == 'M') { case 'M':
int cd = celldist(c); return gradient(0, canvasback, 0, min(1.8/(1+celldist(c)), 1.), 1);
return gradient(0, canvasback, 0, min(1.8/(1+cd), 1.), 1); case 'S':
} if(!hyperbolic) return canvasback;
if(whichCanvas == 'S' && hyperbolic) {
return 0x3F1F0F * fieldpattern::subval(c).second + 0x000080; return 0x3F1F0F * fieldpattern::subval(c).second + 0x000080;
} case 'g':
if(whichCanvas == 'g')
return canvasback; return canvasback;
if(whichCanvas == 'r') case 'r':
return hrand(0xFFFFFF + 1); return hrand(0xFFFFFF + 1);
if(whichCanvas == 'e') { case 'e':
static color_t fcol[4] = { 0x404040, 0x800000, 0x008000, 0x000080 }; return colortables['e'][emeraldval(c)];
int fv = emeraldval(c); case 'a': {
return fcol[fv&3]; color_t col = colortables['a'][land50(c)];
}
if(whichCanvas == 'a') {
static color_t fcol8[8] = {
0x800000,
0x503000,
0x206000,
0x007010,
0x004040,
0x001070,
0x200060,
0x500030
};
if(c->wall == waNone) {
color_t col = fcol8[land50(c)];
if(polara50(c)) col += 0x181818; if(polara50(c)) col += 0x181818;
return col; return col;
} }
} case 'b':
if(whichCanvas == 'b') { return colortables['b'][polara50(c) + 2 * polarb50(c)];
static color_t fcol[4] = { 0x404040, 0x800000, 0x008000, 0x000080 }; case 'z':
return fcol[polara50(c) + 2 * polarb50(c)]; return colortables['z'][zebra40(c)];
} case 't': {
if(whichCanvas == 'z') {
static color_t fcol[4] = { 0xC0C0C0, 0xE0E0E0, 0x404040, 0x606060 };
int fv = zebra40(c);
return fcol[fv&3];
}
if(whichCanvas == 't') {
static color_t fcol[4] = { 0x804040, 0x408040, 0x404080, 0x808040 };
int fv = zebra40(c); int fv = zebra40(c);
if(fv/4 == 4 || fv/4 == 6 || fv/4 == 5 || fv/4 == 10) fv ^= 2; if(fv/4 == 4 || fv/4 == 6 || fv/4 == 5 || fv/4 == 10) fv ^= 2;
return fcol[fv&3]; return colortables['t'][fv];
} }
if(whichCanvas == 'x') { case 'x':
static color_t fcol[4] = { 0xC0C0C0, 0x800000, 0x008000, 0x000080 }; return colortables['x'][zebra3(c)];
return fcol[zebra3(c)]; case 'w':
} return colortables['w'][randpattern(c, subcanvas) ? 1 : 0];
if(whichCanvas == 'w') { case 'l':
static color_t fcol[2] = { 0x303030, 0xC0C0C0 }; return random_landscape(c, 3, 1, 17);
return fcol[randpattern(c, subcanvas) ? 1 : 0]; case 'd':
} return random_landscape(c, 6, 8, 2);
if(whichCanvas == 'l') { case 'h':
int col[4]; return random_landscape(c, 6, 4, 4);
bool err = false; case 'c':
for(int j=0; j<4; j++) { return colortables['c'][chessvalue(c)];
col[j] = getCdata(c, j); case 'F':
col[j] *= 3; return colortables['F'][pseudohept(c)];
col[j] %= 240; case 'T':
if(col[j] > 120) col[j] = 240 - col[j]; return nestcolors[pattern_threecolor(c)];
if(col[j] < -120) col[j] = -240 - col[j];
}
if(ISWEB) for(int a=0; a<3; a++) col[a] = (col[a] + 8) / 17 * 17;
return (0x808080 + col[0] + (col[1] << 8) + (col[2] << 16)) >> (err?2:0);
}
if(whichCanvas == 'd') {
int col[4];
bool err = false;
for(int j=0; j<4; j++) {
col[j] = getCdata(c, j);
col[j] *= 6;
col[j] %= 240;
if(col[j] > 120) col[j] = 240 - col[j];
if(col[j] < -120) col[j] = -240 - col[j];
}
col[0] /= 8;
col[1] /= 8;
col[2] /= 8;
if(ISWEB) for(int a=0; a<3; a++) col[a] = (col[a] + 1) / 2 * 2;
return (0x101010 + col[0] + (col[1] << 8) + (col[2] << 16)) >> (err?2:0);
}
if(whichCanvas == 'h') {
int col[4];
bool err = false;
for(int j=0; j<4; j++) {
col[j] = getCdata(c, j);
col[j] *= 6;
col[j] %= 240;
if(col[j] > 120) col[j] = 240 - col[j];
if(col[j] < -120) col[j] = -240 - col[j];
}
col[0] /= 4;
col[1] /= 4;
col[2] /= 4;
return (0x202020 + col[0] + (col[1] << 8) + (col[2] << 16)) >> (err?2:0);
}
if(whichCanvas == 'c') {
return chessvalue(c) ? 0xC0C0C0 : 0x202020;
}
if(whichCanvas == 'F') {
return pseudohept(c) ? 0x202020 : 0xC0C0C0;
}
if(whichCanvas == 'T') {
int fv = pattern_threecolor(c);
return nestcolors[fv&7];
} }
return canvasback; return canvasback;
} }
@ -2311,6 +2272,20 @@ int read_pattern_args() {
} }
else if(argis("-noplayer")) mapeditor::drawplayer = !mapeditor::drawplayer; else if(argis("-noplayer")) mapeditor::drawplayer = !mapeditor::drawplayer;
else if(argis("-pcol")) {
shift();
colortable *ct = &(colortables[patterns::whichCanvas]);
if(args()[0] > '9') {
char c = args()[0];
if(c == 't') ct = &nestcolors;
else if(c == 'd') ct = &distcolors;
else if(c == 'm') ct = &minecolors;
else ct = &(colortables[patterns::whichCanvas]);
shift();
}
int d = argi();
shift(); (*ct)[d] = arghex();
}
else if(argis("-canvas")) { else if(argis("-canvas")) {
PHASEFROM(2); PHASEFROM(2);
stop_game(); stop_game();