1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2025-01-11 18:00:34 +00:00

CAP_TEXTURE can be off; right-size textures loaded without scaling; SPF_FULLSYM

This commit is contained in:
Zeno Rogue 2017-12-21 11:36:07 +01:00
parent d0a925a8ca
commit 57a5337b9f
9 changed files with 113 additions and 38 deletions

View File

@ -2911,11 +2911,14 @@ int wavephase;
void warpfloor(cell *c, const transmatrix& V, int col, int prio, bool warp) { void warpfloor(cell *c, const transmatrix& V, int col, int prio, bool warp) {
if(shmup::on || nontruncated) warp = false; if(shmup::on || nontruncated) warp = false;
#if CAP_TEXTURE
if(qfi.tinf) { if(qfi.tinf) {
queuetable(V*qfi.spin, &qfi.tinf->vertices[0], size(qfi.tinf->vertices) / 3, 0, texture::recolor(col), prio); queuetable(V*qfi.spin, &qfi.tinf->vertices[0], size(qfi.tinf->vertices) / 3, 0, texture::recolor(col), prio);
lastptd().u.poly.tinf = qfi.tinf; lastptd().u.poly.tinf = qfi.tinf;
} }
else if(wmescher && qfi.special) else
#endif
if(wmescher && qfi.special)
queuepolyat(V*qfi.spin, *qfi.shape, col, prio); queuepolyat(V*qfi.spin, *qfi.shape, col, prio);
else plainfloor(c, warp, V, col, prio); else plainfloor(c, warp, V, col, prio);
} }
@ -3532,7 +3535,9 @@ void drawcell(cell *c, transmatrix V, int spinv, bool mirrored) {
} }
#endif #endif
#if CAP_TEXTURE
else if(texture::apply(c, Vf, darkena(fcol, fd, 0xFF))) ; else if(texture::apply(c, Vf, darkena(fcol, fd, 0xFF))) ;
#endif
else if(c->land == laMirrorWall) { else if(c->land == laMirrorWall) {
int d = mirror::mirrordir(c); int d = mirror::mirrordir(c);

View File

@ -687,6 +687,7 @@ namespace patterns {
static const int SPF_EXTRASYM = 64; static const int SPF_EXTRASYM = 64;
static const int SPF_ALTERNATE = 128; static const int SPF_ALTERNATE = 128;
static const int SPF_FOOTBALL = 256; static const int SPF_FOOTBALL = 256;
static const int SPF_FULLSYM = 512;
static const int SPF_SYM0123 = SPF_SYM01 | SPF_SYM02 | SPF_SYM03; static const int SPF_SYM0123 = SPF_SYM01 | SPF_SYM02 | SPF_SYM03;
@ -2374,6 +2375,7 @@ int snake_pair(cell *c);
extern const unsigned int nestcolors[8]; extern const unsigned int nestcolors[8];
#if CAP_TEXTURE
namespace texture { namespace texture {
enum eTextureState { enum eTextureState {
tsOff, tsAdjusting, tsActive tsOff, tsAdjusting, tsActive
@ -2395,6 +2397,7 @@ namespace texture {
extern cpatterntype cgroup; extern cpatterntype cgroup;
} }
#endif
void queueline(const hyperpoint& H1, const hyperpoint& H2, int col, int prf = 0, int prio = PPR_LINE); void queueline(const hyperpoint& H1, const hyperpoint& H2, int col, int prf = 0, int prio = PPR_LINE);

View File

@ -121,7 +121,7 @@
#endif #endif
#ifndef CAP_TEXTURE #ifndef CAP_TEXTURE
#define CAP_TEXTURE CAP_PNG #define CAP_TEXTURE 0 // CAP_PNG
#endif #endif
#ifndef CAP_MODEL #ifndef CAP_MODEL
@ -180,6 +180,11 @@
#define CAP_SDLJOY (CAP_SDL && !ISWEB) #define CAP_SDLJOY (CAP_SDL && !ISWEB)
#endif #endif
#ifndef CAP_SDL_IMG
#define CAP_SDL_IMG 0
#endif
#ifndef CAP_SDLTTF #ifndef CAP_SDLTTF
#define CAP_SDLTTF (CAP_SDL && !ISMOBILE && !ISWEB) #define CAP_SDLTTF (CAP_SDL && !ISMOBILE && !ISWEB)
#endif #endif

View File

@ -892,16 +892,20 @@ namespace mapeditor {
usershape *us = NULL; usershape *us = NULL;
#if CAP_TEXTURE
if(texture::tstate == texture::tsActive) { if(texture::tstate == texture::tsActive) {
sg = 16; sg = 16;
line1 = "texture"; line1 = "texture";
line2 = ""; line2 = "";
texture::update(); texture::update();
} }
#else
if(0);
#endif
else { else {
int sg = drawcellShapeGroup(); sg = drawcellShapeGroup();
switch(sg) { switch(sg) {
case 0: case 0:
@ -967,10 +971,12 @@ namespace mapeditor {
displayButton(8, 8+fs*16, XLAT("p = paint"), 'p', 0); displayButton(8, 8+fs*16, XLAT("p = paint"), 'p', 0);
} }
#if CAP_TEXTURE
else if(texture::tstate == texture::tsActive) { else if(texture::tstate == texture::tsActive) {
displayButton(8, 8+fs*7, XLAT("p = color"), 'p', 0); displayButton(8, 8+fs*7, XLAT("p = color"), 'p', 0);
displayButton(8, 8+fs*8, XLAT("w = pen size: %1", fts4(texture::penwidth)), 'w', 0); displayButton(8, 8+fs*8, XLAT("w = pen size: %1", fts4(texture::penwidth)), 'w', 0);
} }
#endif
else { else {
displaymm('n', 8, 8+fs*5, 2, vid.fsize, XLAT("'n' to start"), 0); displaymm('n', 8, 8+fs*5, 2, vid.fsize, XLAT("'n' to start"), 0);
displaymm('u', 8, 8+fs*6, 2, vid.fsize, XLAT("'u' to load current"), 0); displaymm('u', 8, 8+fs*6, 2, vid.fsize, XLAT("'u' to load current"), 0);
@ -982,8 +988,10 @@ namespace mapeditor {
displayButton(vid.xres-8, 8+fs*3, XLAT("z = zoom in"), 'z', 16); displayButton(vid.xres-8, 8+fs*3, XLAT("z = zoom in"), 'z', 16);
displayButton(vid.xres-8, 8+fs*2, XLAT("o = zoom out"), 'o', 16); displayButton(vid.xres-8, 8+fs*2, XLAT("o = zoom out"), 'o', 16);
#if CAP_TEXTURE
if(texture::tstate != texture::tsActive) if(texture::tstate != texture::tsActive)
displaymm('e', vid.xres-8, 8+fs, 2, vid.fsize, XLAT("e = edit this"), 16); displaymm('e', vid.xres-8, 8+fs, 2, vid.fsize, XLAT("e = edit this"), 16);
#endif
if(!mouseout()) { if(!mouseout()) {
hyperpoint mh = inverse(drawtrans * rgpushxto0(ccenter)) * mouseh; hyperpoint mh = inverse(drawtrans * rgpushxto0(ccenter)) * mouseh;
@ -1286,8 +1294,18 @@ namespace mapeditor {
hyperpoint mh = inverse(drawtrans) * mouseh; hyperpoint mh = inverse(drawtrans) * mouseh;
if(uni == 'g') coldcenter = ccenter, ccenter = mh; if(uni == 'g') coldcenter = ccenter, ccenter = mh;
if(uni == 'z') vid.scale *= 2, texture::itt = xyscale(texture::itt, .5); if(uni == 'z') {
if(uni == 'o') vid.scale /= 2, texture::itt = xyscale(texture::itt, 2); vid.scale *= 2;
#if CAP_TEXTURE
texture::itt = xyscale(texture::itt, .5);
#endif
}
if(uni == 'o') {
vid.scale /= 2;
#if CAP_TEXTURE
texture::itt = xyscale(texture::itt, 2);
#endif
}
if(uni == ' ' && cheater) { if(uni == ' ' && cheater) {
popScreen(); popScreen();
@ -1318,6 +1336,7 @@ namespace mapeditor {
if(sym == SDLK_F10) popScreen(); if(sym == SDLK_F10) popScreen();
#if CAP_TEXTURE
if(texture::tstate == texture::tsActive) { if(texture::tstate == texture::tsActive) {
if(uni == '-') { if(uni == '-') {
texture::drawPixel(mouseover, mouseh, (texture::paint_color >> 8) | ((texture::paint_color & 0xFF) << 24)); texture::drawPixel(mouseover, mouseh, (texture::paint_color >> 8) | ((texture::paint_color & 0xFF) << 24));
@ -1346,6 +1365,9 @@ namespace mapeditor {
if(uni == 'w') if(uni == 'w')
dialog::editNumber(texture::penwidth, 0, 0.1, 0.005, 0.02, XLAT("pen width"), XLAT("pen width")); dialog::editNumber(texture::penwidth, 0, 0.1, 0.005, 0.02, XLAT("pen width"), XLAT("pen width"));
} }
#else
if(0);
#endif
else { else {
dslayer %= USERLAYERS; dslayer %= USERLAYERS;
@ -1456,6 +1478,7 @@ namespace mapeditor {
if(cmode & sm::DRAW) if(!holdmouse) { if(cmode & sm::DRAW) if(!holdmouse) {
#if CAP_TEXTURE
if(texture::tstate == texture::tsActive && lmouseover && !mouseout()) { if(texture::tstate == texture::tsActive && lmouseover && !mouseout()) {
auto sio = patterns::getpatterninfo0(lmouseover); auto sio = patterns::getpatterninfo0(lmouseover);
auto sih = patterns::getpatterninfo0(c); auto sih = patterns::getpatterninfo0(c);
@ -1474,6 +1497,7 @@ namespace mapeditor {
} }
} }
} }
#endif
if(mapeditor::editingShape(group, id)) { if(mapeditor::editingShape(group, id)) {

View File

@ -372,7 +372,9 @@ void showDisplayMode() {
if(xuni == 'z') editScale(); if(xuni == 'z') editScale();
#if CAP_TEXTURE
if(xuni == 't') pushScreen(texture::showMenu); if(xuni == 't') pushScreen(texture::showMenu);
#endif
if(xuni == 'm') { vid.monmode += 60 + (shiftmul > 0 ? 1 : -1); vid.monmode %= 6; } if(xuni == 'm') { vid.monmode += 60 + (shiftmul > 0 ? 1 : -1); vid.monmode %= 6; }

View File

@ -574,7 +574,9 @@ namespace patterns {
if(sub & SPF_CHANGEROT) { if(sub & SPF_CHANGEROT) {
si.dir = (zebra40(c)*4) % 6; si.dir = (zebra40(c)*4) % 6;
} }
if(symRotation) si.id = 0; if(symRotation) si.id = 1;
if(euclid6 && (sub & SPF_FULLSYM))
si.symmetries = 1;
} }
void valEuclid4(cell *c, patterninfo &si, int sub) { void valEuclid4(cell *c, patterninfo &si, int sub) {
@ -679,6 +681,8 @@ namespace patterns {
if(ctof(c)) si.symmetries = 3; if(ctof(c)) si.symmetries = 3;
if(subpattern_flags & SPF_EXTRASYM) if(subpattern_flags & SPF_EXTRASYM)
si.symmetries /= 3; si.symmetries /= 3;
if(subpattern_flags & SPF_FULLSYM)
si.symmetries = 1;
} }
if(sphere && !(nontruncated) && !(S7 == 3)) if(sphere && !(nontruncated) && !(S7 == 3))
si.symmetries = ctof(c) ? 1 : 2; si.symmetries = ctof(c) ? 1 : 2;
@ -715,10 +719,12 @@ namespace patterns {
} }
} }
if(euclid6 && (sub & SPF_CHANGEROT)) si.dir = 0; if(euclid6 && (sub & SPF_CHANGEROT)) si.dir = 0;
if(sub & SPF_ROT) si.id = 0; if(sub & SPF_ROT) si.id = 1;
if(euclid6 && !(sub & SPF_EXTRASYM)) { if(euclid6 && !(sub & SPF_EXTRASYM)) {
si.symmetries = 6; si.symmetries = 6;
} }
if(euclid6 && (sub & SPF_FULLSYM))
si.symmetries = 1;
if(S7 == 4) if(S7 == 4)
applyAlt(si, sub, PAT_COLORING); applyAlt(si, sub, PAT_COLORING);
} }
@ -1232,6 +1238,9 @@ namespace patterns {
if(euclid && among(whichPattern, PAT_COLORING, 0)) if(euclid && among(whichPattern, PAT_COLORING, 0))
dialog::addBoolItem(XLAT("extra symmetries"), subpattern_flags & SPF_EXTRASYM, '='); dialog::addBoolItem(XLAT("extra symmetries"), subpattern_flags & SPF_EXTRASYM, '=');
if(euclid && among(whichPattern, PAT_COLORING, 0))
dialog::addBoolItem(XLAT("full symmetry"), subpattern_flags & SPF_FULLSYM, '!');
if(a38 && nontruncated && whichPattern == 0) { if(a38 && nontruncated && whichPattern == 0) {
dialog::addBoolItem(XLAT("extra symmetries"), subpattern_flags & SPF_EXTRASYM, '='); dialog::addBoolItem(XLAT("extra symmetries"), subpattern_flags & SPF_EXTRASYM, '=');
} }
@ -1283,6 +1292,10 @@ namespace patterns {
subpattern_flags &= ~SPF_ALTERNATE; subpattern_flags &= ~SPF_ALTERNATE;
} }
else if(uni == '!') {
subpattern_flags ^= SPF_FULLSYM;
}
else if(uni == '6' || uni == '7' || uni == '8') { else if(uni == '6' || uni == '7' || uni == '8') {
if(whichShape == uni) whichShape = 0; if(whichShape == uni) whichShape = 0;
else whichShape = uni; else whichShape = uni;
@ -1361,7 +1374,7 @@ namespace patterns {
{"single type", { {"single type", {
{gNormal, true, 0, 0}, {gNormal, true, 0, 0},
{gSphere, true, 0, SPF_EXTRASYM}, {gSphere, true, 0, SPF_EXTRASYM},
{gEuclid, false, 0, SPF_EXTRASYM | SPF_ROT}, {gEuclid, false, PAT_COLORING, SPF_EXTRASYM | SPF_ROT | SPF_FULLSYM},
{gOctagon, true, 0, SPF_EXTRASYM}, {gOctagon, true, 0, SPF_EXTRASYM},
{g45, true, 0, 0}, {g45, true, 0, 0},
{g46, true, 0, 0}, {g46, true, 0, 0},
@ -1390,8 +1403,10 @@ namespace patterns {
dialog::init(); dialog::init();
for(int i=0; i<size(cpatterns); i++) { for(int i=0; i<size(cpatterns); i++) {
dialog::addBoolItem(XLAT(cpatterns[i].name), cgroup == i, '0'+i); dialog::addBoolItem(XLAT(cpatterns[i].name), cgroup == i, '0'+i);
#if CAP_TEXTURE
if(texture::tstate == texture::tsActive && !compatible(texture::cgroup, (cpatterntype) i)) if(texture::tstate == texture::tsActive && !compatible(texture::cgroup, (cpatterntype) i))
dialog::lastItem().value = XLAT("BAD"); dialog::lastItem().value = XLAT("BAD");
#endif
} }
dialog::addBreak(100); dialog::addBreak(100);
if(cgroup != cpUnknown && cgroup < size(cpatterns)) if(cgroup != cpUnknown && cgroup < size(cpatterns))
@ -1412,14 +1427,18 @@ namespace patterns {
else if(uni >= '0' && uni < '0' + size(cpatterns)) else if(uni >= '0' && uni < '0' + size(cpatterns))
cgroup = cpatterntype(uni - '0'); cgroup = cpatterntype(uni - '0');
else if(cgroup != cpUnknown && uni >= 'a' && uni < 'a' + size(cpatterns[cgroup].geometries)) { else if(cgroup != cpUnknown && uni >= 'a' && uni < 'a' + size(cpatterns[cgroup].geometries)) {
#if CAP_TEXTURE
auto old_tstate = texture::tstate; auto old_tstate = texture::tstate;
auto old_tstate_max = texture::tstate_max; auto old_tstate_max = texture::tstate_max;
#endif
auto &g = cpatterns[cgroup].geometries[uni - 'a']; auto &g = cpatterns[cgroup].geometries[uni - 'a'];
if(g.geo != geometry) { targetgeometry = g.geo; restartGame('g', false, true); } if(g.geo != geometry) { targetgeometry = g.geo; restartGame('g', false, true); }
if(g.nontrunc != nontruncated) restartGame('7', false, true); if(g.nontrunc != nontruncated) restartGame('7', false, true);
whichPattern = g.whichPattern; whichPattern = g.whichPattern;
subpattern_flags = g.subpattern_flags; subpattern_flags = g.subpattern_flags;
#if CAP_TEXTURE
texture::remap(old_tstate, old_tstate_max); texture::remap(old_tstate, old_tstate_max);
#endif
} }
else if(doexiton(sym, uni)) else if(doexiton(sym, uni))
popScreen(); popScreen();

View File

@ -253,6 +253,7 @@ void filledPolygonColorI(SDL_Surface *s, int* px, int *py, int polyi, int col) {
} }
#endif #endif
#if CAP_TEXTURE
void drawTexturedTriangle(SDL_Surface *s, int *px, int *py, GLfloat *tv, int col) { void drawTexturedTriangle(SDL_Surface *s, int *px, int *py, GLfloat *tv, int col) {
transmatrix source = {{{ld(px[0]),ld(px[1]),ld(px[2])}, {ld(py[0]),ld(py[1]),ld(py[2])}, {1,1,1}}}; transmatrix source = {{{ld(px[0]),ld(px[1]),ld(px[2])}, {ld(py[0]),ld(py[1]),ld(py[2])}, {1,1,1}}};
transmatrix target = {{{tv[0],tv[3],tv[6]}, {tv[1],tv[4],tv[7]}, {1,1,1}}}; transmatrix target = {{{tv[0],tv[3],tv[6]}, {tv[1],tv[4],tv[7]}, {1,1,1}}};
@ -279,6 +280,7 @@ void drawTexturedTriangle(SDL_Surface *s, int *px, int *py, GLfloat *tv, int col
} }
} }
} }
#endif
#if CAP_GL #if CAP_GL
void glcolor2(int color) { void glcolor2(int color) {
@ -634,9 +636,11 @@ void drawpolyline(polytodraw& p) {
#elif CAP_SDLGFX==1 #elif CAP_SDLGFX==1
if(pp.tinf) { if(pp.tinf) {
#if CAP_TEXTURE
if(!(poly_flags & POLY_INVERSE)) if(!(poly_flags & POLY_INVERSE))
for(int i=0; i<polyi; i += 3) for(int i=0; i<polyi; i += 3)
drawTexturedTriangle(s, polyx+i, polyy+i, &pp.tinf->tvertices[i*3], p.col); drawTexturedTriangle(s, polyx+i, polyy+i, &pp.tinf->tvertices[i*3], p.col);
#endif
} }
else if(poly_flags & POLY_INVERSE) { else if(poly_flags & POLY_INVERSE) {
int i = polyi; int i = polyi;

View File

@ -1097,10 +1097,12 @@ void restartGame(char switchWhat, bool push, bool keep_screens) {
if(euclid6) geometry = gNormal; if(euclid6) geometry = gNormal;
nontruncated = !nontruncated; nontruncated = !nontruncated;
resetGeometry(); resetGeometry();
#if CAP_TEXTURE
if(texture::tstate == texture::tsActive) if(texture::tstate == texture::tsActive)
texture::tstate = texture::tsAdjusting; texture::tstate = texture::tsAdjusting;
if(texture::tstate_max == texture::tsActive) if(texture::tstate_max == texture::tsActive)
texture::tstate = texture::tsAdjusting; texture::tstate = texture::tsAdjusting;
#endif
} }
if(switchWhat == 'g') { if(switchWhat == 'g') {
if(geometry == targetgeometry) geometry = gNormal; if(geometry == targetgeometry) geometry = gNormal;
@ -1109,8 +1111,12 @@ void restartGame(char switchWhat, bool push, bool keep_screens) {
if(nontruncated && euclid6) nontruncated = false; if(nontruncated && euclid6) nontruncated = false;
resetGeometry(); resetGeometry();
#if CAP_TEXTURE
if(texture::tstate == texture::tsActive) if(texture::tstate == texture::tsActive)
texture::tstate = texture::tsOff; texture::tstate = texture::tsOff;
if(texture::tstate_max == texture::tsActive)
texture::tstate = texture::tsAdjusting;
#endif
} }
if(switchWhat == 'y') { if(switchWhat == 'y') {
yendor::on = !yendor::on; yendor::on = !yendor::on;

View File

@ -1,5 +1,6 @@
#include <SDL/SDL_image.h> #include <SDL/SDL_image.h>
#if CAP_TEXTURE
namespace texture { namespace texture {
GLuint textureid = 0; GLuint textureid = 0;
@ -106,13 +107,22 @@ bool readtexture() {
vector<int> half_expanded(twidth * ty); vector<int> half_expanded(twidth * ty);
texture_pixels.resize(twidth * twidth); texture_pixels.resize(twidth * twidth);
if(tx == twidth && ty == twidth) {
int i = 0;
for(int y=0; y<ty; y++)
for(int x=0; x<tx; x++)
texture_pixels[i++] = qpixel(txt2, x, y);
}
else {
int origdim = max(tx, ty); int origdim = max(tx, ty);
int base_x = tx/2 - origdim/2; int base_x = tx/2 - origdim/2;
int base_y = ty/2 - origdim/2; int base_y = ty/2 - origdim/2;
ZZ = 0; // outside is black ZZ = 0; // outside is black
/* for(int y=0; y<twidth; y++) /* for(int y=0; y<twidth; y++)
for(int x=0; x<twidth; x++) for(int x=0; x<twidth; x++)
texture_pixels[y*twidth+x] = qpixel(txt2, y%ty, x%tx); */ texture_pixels[y*twidth+x] = qpixel(txt2, y%ty, x%tx); */
@ -127,6 +137,7 @@ bool readtexture() {
[&] (int x) { return qpixel(txt2, base_x + x, y); }, [&] (int x) { return qpixel(txt2, base_x + x, y); },
[&] (int x, int v) { half_expanded[twidth * y + x] = v; } [&] (int x, int v) { half_expanded[twidth * y + x] = v; }
); );
}
SDL_FreeSurface(txt2); SDL_FreeSurface(txt2);
@ -970,8 +981,4 @@ void remap(eTextureState old_tstate, eTextureState old_tstate_max) {
} }
} }
#endif
// - fix spheres
// - save texture image
// - undo
// - verify