1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-06-18 11:19:59 +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) {
if(shmup::on || nontruncated) warp = false;
#if CAP_TEXTURE
if(qfi.tinf) {
queuetable(V*qfi.spin, &qfi.tinf->vertices[0], size(qfi.tinf->vertices) / 3, 0, texture::recolor(col), prio);
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);
else plainfloor(c, warp, V, col, prio);
}
@ -3532,7 +3535,9 @@ void drawcell(cell *c, transmatrix V, int spinv, bool mirrored) {
}
#endif
#if CAP_TEXTURE
else if(texture::apply(c, Vf, darkena(fcol, fd, 0xFF))) ;
#endif
else if(c->land == laMirrorWall) {
int d = mirror::mirrordir(c);

View File

@ -687,6 +687,7 @@ namespace patterns {
static const int SPF_EXTRASYM = 64;
static const int SPF_ALTERNATE = 128;
static const int SPF_FOOTBALL = 256;
static const int SPF_FULLSYM = 512;
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];
#if CAP_TEXTURE
namespace texture {
enum eTextureState {
tsOff, tsAdjusting, tsActive
@ -2395,6 +2397,7 @@ namespace texture {
extern cpatterntype cgroup;
}
#endif
void queueline(const hyperpoint& H1, const hyperpoint& H2, int col, int prf = 0, int prio = PPR_LINE);

View File

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

View File

@ -891,17 +891,21 @@ namespace mapeditor {
string line1, line2;
usershape *us = NULL;
#if CAP_TEXTURE
if(texture::tstate == texture::tsActive) {
sg = 16;
line1 = "texture";
line2 = "";
texture::update();
}
#else
if(0);
#endif
else {
int sg = drawcellShapeGroup();
sg = drawcellShapeGroup();
switch(sg) {
case 0:
@ -967,10 +971,12 @@ namespace mapeditor {
displayButton(8, 8+fs*16, XLAT("p = paint"), 'p', 0);
}
#if CAP_TEXTURE
else if(texture::tstate == texture::tsActive) {
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);
}
#endif
else {
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);
@ -981,9 +987,11 @@ namespace mapeditor {
displaymm('g', vid.xres-8, 8+fs*4, 2, vid.fsize, XLAT("g = grid"), 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);
#if CAP_TEXTURE
if(texture::tstate != texture::tsActive)
displaymm('e', vid.xres-8, 8+fs, 2, vid.fsize, XLAT("e = edit this"), 16);
#endif
if(!mouseout()) {
hyperpoint mh = inverse(drawtrans * rgpushxto0(ccenter)) * mouseh;
@ -1286,8 +1294,18 @@ namespace mapeditor {
hyperpoint mh = inverse(drawtrans) * mouseh;
if(uni == 'g') coldcenter = ccenter, ccenter = mh;
if(uni == 'z') vid.scale *= 2, texture::itt = xyscale(texture::itt, .5);
if(uni == 'o') vid.scale /= 2, texture::itt = xyscale(texture::itt, 2);
if(uni == 'z') {
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) {
popScreen();
@ -1318,6 +1336,7 @@ namespace mapeditor {
if(sym == SDLK_F10) popScreen();
#if CAP_TEXTURE
if(texture::tstate == texture::tsActive) {
if(uni == '-') {
texture::drawPixel(mouseover, mouseh, (texture::paint_color >> 8) | ((texture::paint_color & 0xFF) << 24));
@ -1346,7 +1365,10 @@ namespace mapeditor {
if(uni == 'w')
dialog::editNumber(texture::penwidth, 0, 0.1, 0.005, 0.02, XLAT("pen width"), XLAT("pen width"));
}
#else
if(0);
#endif
else {
dslayer %= USERLAYERS;
@ -1455,7 +1477,8 @@ namespace mapeditor {
}
if(cmode & sm::DRAW) if(!holdmouse) {
#if CAP_TEXTURE
if(texture::tstate == texture::tsActive && lmouseover && !mouseout()) {
auto sio = patterns::getpatterninfo0(lmouseover);
auto sih = patterns::getpatterninfo0(c);
@ -1474,7 +1497,8 @@ namespace mapeditor {
}
}
}
#endif
if(mapeditor::editingShape(group, id)) {
/* for(int a=0; a<size(ds.list); a++) {

View File

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

View File

@ -253,6 +253,7 @@ void filledPolygonColorI(SDL_Surface *s, int* px, int *py, int polyi, int col) {
}
#endif
#if CAP_TEXTURE
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 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
void glcolor2(int color) {
@ -634,9 +636,11 @@ void drawpolyline(polytodraw& p) {
#elif CAP_SDLGFX==1
if(pp.tinf) {
#if CAP_TEXTURE
if(!(poly_flags & POLY_INVERSE))
for(int i=0; i<polyi; i += 3)
drawTexturedTriangle(s, polyx+i, polyy+i, &pp.tinf->tvertices[i*3], p.col);
#endif
}
else if(poly_flags & POLY_INVERSE) {
int i = polyi;

View File

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

View File

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