1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-11-23 21:07:17 +00:00

nilrider:: levellines

This commit is contained in:
Zeno Rogue 2022-05-09 10:02:21 +02:00
parent d4957fd56b
commit 17a18d7579
3 changed files with 59 additions and 17 deletions

View File

@ -8,23 +8,31 @@ void level::init_textures() {
int tY = isize(map_tiles); int tY = isize(map_tiles);
int tX = isize(map_tiles[0]); int tX = isize(map_tiles[0]);
for(int stepped: {0, 1}) { transmatrix T = gpushxto0(new_levellines_for);
auto& target = stepped ? unil_texture_stepped : unil_texture; for(int which: {0, 1, 2}) {
if(target) return;
target = new texture::texture_data; bool stepped = which == 1;
bool levels = which == 2;
auto& target = stepped ? unil_texture_stepped : levels ? unil_texture_levels : unil_texture;
if(target && !(levels && levellines_for != new_levellines_for)) continue;
bool regen = !target;
if(regen) target = new texture::texture_data;
auto& tex = *target; auto& tex = *target;
tex.twidth = tex.tx = tX * texture_density; if(regen) {
tex.theight = tex.ty = tY * texture_density; tex.twidth = tex.tx = tX * texture_density;
tex.stretched = false; tex.theight = tex.ty = tY * texture_density;
tex.strx = tex.tx; tex.stretched = false;
tex.stry = tex.ty; tex.strx = tex.tx;
tex.base_x = 0; tex.stry = tex.ty;
tex.base_y = 0; tex.base_x = 0;
tex.whitetexture(); tex.base_y = 0;
tex.whitetexture();
}
auto getpix = [&] (int x, int y) { auto getpix = [&] (int x, int y) {
int px = x / pixel_per_block; int px = x / pixel_per_block;
@ -44,6 +52,12 @@ void level::init_textures() {
if(!stepped) { if(!stepped) {
char c = getpix(x / subpixels, y / subpixels); char c = getpix(x / subpixels, y / subpixels);
col = bcols[c]; col = bcols[c];
if(levels && new_levellines_for[3]) {
hyperpoint h = T * mappt(x, y, texture_density);
ld z = h[2] - sym_to_heis_bonus(h);
if(z > 0) col = gradient(col, 0xFFFF0000, 0, z - floor(z), 4);
if(z < 0) col = gradient(col, 0xFF0000FF, 0, -z - floor(-z), 4);
}
} }
else { else {
int mx = x % stepdiv; int mx = x % stepdiv;
@ -69,10 +83,12 @@ void level::init_textures() {
} }
tex.get_texture_pixel(x, y) = col; tex.get_texture_pixel(x, y) = col;
tex.get_texture_pixel(x, y) |= 0xFF000000; tex.get_texture_pixel(x, y) |= 0xFF000000;
tex.get_texture_pixel(x, y) ^= hrand(0x1000000) & 0xF0F0F; if(!levels)
tex.get_texture_pixel(x, y) ^= hrand(0x1000000) & 0xF0F0F;
} }
tex.loadTextureGL(); tex.loadTextureGL();
} }
levellines_for = new_levellines_for;
} }
void level::init_shapes() { void level::init_shapes() {
@ -330,6 +346,8 @@ void level::init() {
scale = abs(maxx - minx) / isize(map_tiles[0]); scale = abs(maxx - minx) / isize(map_tiles[0]);
println(hlog, "SCALE IS ", this->scale); println(hlog, "SCALE IS ", this->scale);
levellines_for = new_levellines_for = C0;
if(1) { if(1) {
int tY = isize(map_tiles); int tY = isize(map_tiles);
int tX = isize(map_tiles[0]); int tX = isize(map_tiles[0]);

View File

@ -116,10 +116,19 @@ struct level {
/** the texture data used for the ground in the stepped mode */ /** the texture data used for the ground in the stepped mode */
texture::texture_data *unil_texture_stepped; texture::texture_data *unil_texture_stepped;
/** the texture data used for the ground with level lines */
texture::texture_data *unil_texture_levels;
/** the texture used for the ground */ /** the texture used for the ground */
basic_textureinfo uniltinf; basic_textureinfo uniltinf;
/** the texture used for the ground */ /** currently used point for levellines -- levellines[3]==0 means none */
hyperpoint levellines_for;
/** requested point for levellines (texture redrawn in init_textures) */
hyperpoint new_levellines_for;
/** the texture used for the castles */
basic_textureinfo castle_tinf; basic_textureinfo castle_tinf;
/** the texture used for the ground in the stepped mode*/ /** the texture used for the ground in the stepped mode*/

View File

@ -74,7 +74,7 @@ ld closest_t;
char planmode = 'p'; char planmode = 'p';
vector<pair<char, string> > buttons = { vector<pair<char, string> > buttons = {
{'p', "pan"}, {'a', "add"}, {'m', "move"}, {'i', "insert"}, {'d', "delete"} {'p', "pan"}, {'a', "add"}, {'m', "move"}, {'i', "insert"}, {'d', "delete"}, {'l', "levels"}
}; };
bool recompute_plan_transform = true; bool recompute_plan_transform = true;
@ -126,7 +126,7 @@ void level::draw_planning_screen() {
/* draw the map */ /* draw the map */
auto& p = queuepolyat(T, shPlanFloor, 0xFFFFFFFF, PPR::FLOOR); auto& p = queuepolyat(T, shPlanFloor, 0xFFFFFFFF, PPR::FLOOR);
p.tinf = &uniltinf; p.tinf = &uniltinf;
uniltinf.texture_id = unil_texture->textureid; uniltinf.texture_id = unil_texture_levels->textureid;
auto draw_sq = [&] (hyperpoint h, color_t col, PPR prio) { auto draw_sq = [&] (hyperpoint h, color_t col, PPR prio) {
curvepoint(hpxy(h[0]+box, h[1]+box)); curvepoint(hpxy(h[0]+box, h[1]+box));
@ -143,6 +143,9 @@ void level::draw_planning_screen() {
queuecurve(T, col, 0, prio); queuecurve(T, col, 0, prio);
}; };
if(levellines_for[3])
draw_sq(levellines_for, 0xFFC0FFFF, PPR::ITEM);
/* draw the plan */ /* draw the plan */
for(auto& pp: plan) { for(auto& pp: plan) {
draw_sq(pp.at - pp.vel, 0xFF8080FF, PPR::ITEM); draw_sq(pp.at - pp.vel, 0xFF8080FF, PPR::ITEM);
@ -210,7 +213,10 @@ bool level::handle_planning(int sym, int uni) {
plan_transform.T = atscreenpos(mousex, mousey, 1) * inverse(atscreenpos(mousex, mousey, 1.2)) * plan_transform.T; plan_transform.T = atscreenpos(mousex, mousey, 1) * inverse(atscreenpos(mousex, mousey, 1.2)) * plan_transform.T;
return true; return true;
} }
for(auto& b: buttons) if(uni == b.first) { planmode = uni; return true; } for(auto& b: buttons) if(uni == b.first) {
if(uni == 'l' && planmode == 'l') new_levellines_for[3] = 0;
planmode = uni; return true;
}
auto clean_history_to = [&] (int i) { auto clean_history_to = [&] (int i) {
while(history.size() > 1 && history.back().t > i) history.pop_back(); while(history.size() > 1 && history.back().t > i) history.pop_back();
}; };
@ -291,6 +297,15 @@ bool level::handle_planning(int sym, int uni) {
} }
return false; return false;
} }
case 'l': {
if(uni == '-') {
new_levellines_for = mousept;
new_levellines_for[2] = surface(new_levellines_for);
holdmouse = true;
return true;
}
return false;
}
default: default:
return false; return false;
} }