refactured 'texture_order' as a separate function

This commit is contained in:
Zeno Rogue 2019-05-09 17:20:31 +02:00
parent 80ce15ded9
commit d89fb49e13
4 changed files with 75 additions and 129 deletions

View File

@ -206,7 +206,7 @@ void bshape_regular(floorshape &fsh, int id, int sides, int shift, ld size) {
cell fc;
fc.type = 6+id;
const int STEP = TEXTURE_STEP_3D;
const int STEP = vid.texture_step;
using namespace hyperpoint_vec;
for(int t=0; t<2; t++) {
@ -471,66 +471,33 @@ void generate_floorshapes_for(int id, cell *c, int siid, int sidir) {
for(int k=0; k<SIDEPARS; k++) {
sizeto(fsh.levels[k], id);
bshape(fsh.levels[k][id], fsh.prio);
fsh.levels[k][id].tinf = &fsh.tinf3;
fsh.levels[k][id].texture_offset = 0;
bshape(fsh.levels[k][id], fsh.prio);
last->flags |= POLY_TRIANGLES;
last->tinf = &fsh.tinf3;
last->texture_offset = 0;
const int STEP = TEXTURE_STEP_3D;
int s = fsh.b[id].s;
int e = fsh.b[id].e-1;
#if CAP_BT
if(binarytiling) {
if(binarytiling)
for(int t=0; t<c->type; t++)
for(int y=0; y<STEP; y++)
for(int x=0; x<STEP; x++) {
auto at = [&] (int x, int y) {
texture_order([&] (ld x, ld y) {
using namespace hyperpoint_vec;
hyperpoint left = binary::get_corner_horo_coordinates(c, t);
hyperpoint right = binary::get_corner_horo_coordinates(c, t+1);
hyperpoint mid = (left * x + right * y) / STEP;
hpcpush(binary::get_horopoint(mid));
};
if(x+y < STEP) {
at(x, y);
at(x+1, y);
at(x, y+1);
}
if(x+y <= STEP && x && y) {
at(x, y);
at(x-1, y);
at(x, y-1);
}
}
}
hpcpush(rgpushxto0(binary::get_horopoint(left * x + right * y)) * zpush(dfloor_table[k]) * C0);
});
else
#endif
if(1) {
auto at = [&] (hyperpoint h, int a) {
hpcpush(normalize(h));
};
for(int t=0; t<e-s; t++)
for(int y=0; y<STEP; y++)
for(int x=0; x<STEP; x++) {
int s = fsh.b[id].s;
int e = fsh.b[id].e-1;
for(int t=0; t<e-s; t++) {
using namespace hyperpoint_vec;
hyperpoint center = zpush(dfloor_table[k]) * C0;
hyperpoint v1 = (rgpushxto0(hpc[s+t]) * center - center) / STEP;
hyperpoint v2 = (rgpushxto0(hpc[s+t+1]) * center - center) / STEP;
if(x+y < STEP) {
at(center + v1 * x + v2 * y, 0);
at(center + v1 * (x+1) + v2 * y, 1);
at(center + v1 * x + v2 * (y+1), 2);
}
if(x+y <= STEP && x && y) {
at(center + v1 * x + v2 * y, 0);
at(center + v1 * (x-1) + v2 * y, 1);
at(center + v1 * x + v2 * (y-1), 2);
}
hyperpoint v1 = (rgpushxto0(hpc[s+t]) * center - center);
hyperpoint v2 = (rgpushxto0(hpc[s+t+1]) * center - center);
texture_order([&] (ld x, ld y) { hpcpush(normalize(center + v1 * x + v2 * y)); });
}
}
last->flags |= POLY_TRIANGLES;
}
}
@ -838,36 +805,21 @@ void draw_shape_for_texture(floorshape* sh, int& id) {
sh->tinf3.tvertices.clear();
sh->tinf3.texture_id = floor_textures->renderedTexture;
auto at = [&] (hyperpoint h, int a) {
hyperpoint inmodel;
applymodel(h, inmodel);
glvec2 v;
v[0] = (1 + inmodel[0] * vid.scale) / 2;
v[1] = (1 - inmodel[1] * vid.scale) / 2;
sh->tinf3.tvertices.push_back(glhr::makevertex(v[0], v[1], 0));
};
const int STEP = TEXTURE_STEP_3D;
using namespace hyperpoint_vec;
hyperpoint center = eupush(gx, gy) * C0;
hyperpoint v1 = hpxyz3(0.25, 0.25, 0, 0);
hyperpoint v2 = hpxyz3(0.25, -0.25, 0, 0);
for(int a=0; a<8; a++)
for(int y=0; y<STEP; y++)
for(int x=0; x<STEP; x++) {
hyperpoint center = eupush(gx, gy) * C0;
hyperpoint v1 = hpxyz3(0.25, 0.25, 0, 0) / STEP;
hyperpoint v2 = hpxyz3(0.25, -0.25, 0, 0) / STEP;
if(x+y < STEP) {
at(center + v1 * x + v2 * y, 0);
at(center + v1 * (x+1) + v2 * y, 1);
at(center + v1 * x + v2 * (y+1), 2);
}
if(x+y <= STEP && x && y) {
at(center + v1 * x + v2 * y, 0);
at(center + v1 * (x-1) + v2 * y, 1);
at(center + v1 * x + v2 * (y-1), 2);
}
}
texture_order([&] (ld x, ld y) {
hyperpoint h = center + v1 * x + v2 * y;
hyperpoint inmodel;
applymodel(h, inmodel);
glvec2 v;
v[0] = (1 + inmodel[0] * vid.scale) / 2;
v[1] = (1 - inmodel[1] * vid.scale) / 2;
sh->tinf3.tvertices.push_back(glhr::makevertex(v[0], v[1], 0));
});
}
const int FLOORTEXTURESIZE = 4096;

18
hyper.h
View File

@ -5054,7 +5054,23 @@ namespace subscreens {
bool split(reaction_t for_each_subscreen);
}
#define TEXTURE_STEP_3D vid.texture_step
template <class T> void texture_order(const T& f) {
const int STEP = vid.texture_step;
const ld STEP2 = STEP;
for(int y=0; y<STEP; y++)
for(int x=0; x<STEP; x++) {
ld x0 = x / STEP2;
ld y0 = y / STEP2;
ld b = 1 / STEP2;
if(x+y < STEP) {
f(x0, y0); f(x0+b, y0); f(x0, y0+b);
}
if(x+y <= STEP && x && y) {
f(x0, y0); f(x0-b, y0); f(x0, y0-b);
}
}
}
void set_euland3(cell *c, int co0, int co1, int alt, int hash);

View File

@ -2397,44 +2397,36 @@ void make_wall(int id, vector<hyperpoint> vertices, bool force_triangles = false
reverse(vertices.begin(), vertices.end());
ld yy = log(2) / 2;
auto at = [&] (hyperpoint h) {
if(!binarytiling) { hpcpush(normalize(h)); return; }
hyperpoint res = binary::parabolic3(h[0], h[1]) * xpush0(yy*h[2]);
hpcpush(res);
};
const auto STEP = TEXTURE_STEP_3D;
const int n = isize(vertices);
bshape(shWall3D[id], PPR::WALL);
last->flags |= POLY_TRIANGLES;
hyperpoint center = Hypc;
for(auto v: vertices) center += v;
center /= n;
for(int a=0; a<n; a++)
for(int y=0; y<STEP; y++)
for(int x=0; x<STEP; x++) {
hyperpoint v1 = (vertices[a] - center) / STEP;
hyperpoint v2 = (vertices[(a+1)%n] - center) / STEP;
if(x+y < STEP) {
at(center + v1 * x + v2 * y);
at(center + v1 * (x+1) + v2 * y);
at(center + v1 * x + v2 * (y+1));
}
if(x+y <= STEP && x && y) {
at(center + v1 * x + v2 * y);
at(center + v1 * (x-1) + v2 * y);
at(center + v1 * x + v2 * (y-1));
}
}
int n = isize(vertices);
center /= n;
for(int a=0; a<n; a++) {
hyperpoint v1 = vertices[a] - center;
hyperpoint v2 = vertices[(a+1)%n] - center;
texture_order([&] (ld x, ld y) {
hyperpoint h = center + v1 * x + v2 * y;
if(!binarytiling) { hpcpush(normalize(h)); return; }
hyperpoint res = binary::parabolic3(h[0], h[1]) * xpush0(yy*h[2]);
hpcpush(res);
});
}
bshape(shWireframe3D[id], PPR::WALL);
if(true) {
for(int a=0; a<n; a++) for(int y=0; y<STEP; y++)
at((vertices[a] * (STEP-y) + vertices[(a+1)%n] * y)/STEP);
at(vertices[0]);
int STEP = vid.texture_step;
for(int a=0; a<n; a++) for(int y=0; y<STEP; y++) {
hyperpoint h = (vertices[a] * (STEP-y) + vertices[(a+1)%n] * y)/STEP;
if(!binarytiling) { hpcpush(normalize(h)); return; }
hyperpoint res = binary::parabolic3(h[0], h[1]) * xpush0(yy*h[2]);
hpcpush(res);
}
hpcpush(hpc[last->s]);
}
finishshape();

View File

@ -462,32 +462,18 @@ void texture_config::finish_mapping() {
tinf3.texture_id = config.data.textureid;
if(isize(texture_map) && isize(texture_map.begin()->second.triangles)) {
auto& tris = texture_map.begin()->second.triangles;
const int STEP = TEXTURE_STEP_3D;
using namespace hyperpoint_vec;
auto at = [&] (hyperpoint h, int a) {
h = normalize(h);
tinf3.tvertices.push_back(glhr::pointtogl(texture_coordinates(h)));
};
for(int a=0; a<8; a++)
for(int y=0; y<STEP; y++)
for(int x=0; x<STEP; x++) {
auto& tri = tris[a % isize(tris)];
hyperpoint center = tri.tv[0];
hyperpoint v1 = (tri.tv[1] - center) / STEP;
hyperpoint v2 = (tri.tv[2] - center) / STEP;
if(x+y < STEP) {
at(center + v1 * x + v2 * y, 0);
at(center + v1 * (x+1) + v2 * y, 1);
at(center + v1 * x + v2 * (y+1), 2);
}
if(x+y <= STEP && x && y) {
at(center + v1 * x + v2 * y, 0);
at(center + v1 * (x-1) + v2 * y, 1);
at(center + v1 * x + v2 * (y-1), 2);
}
}
for(int a=0; a<8; a++) {
auto& tri = tris[a % isize(tris)];
hyperpoint center = tri.tv[0];
hyperpoint v1 = tri.tv[1] - center;
hyperpoint v2 = tri.tv[2] - center;
texture_order([&] (ld x, ld y) {
hyperpoint h = normalize(center + v1 * x + v2 * y);
tinf3.tvertices.push_back(glhr::pointtogl(texture_coordinates(h)));
});
}
}
if(config.tstate == tsActive) {