From 2a9a219e619431f7ffbd66cf0abb6d944c87f2a9 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Thu, 5 May 2022 22:37:05 +0200 Subject: [PATCH] nilrider:: stepped display --- rogueviz/nilrider/level.cpp | 180 ++++++++++++++++++++++++--------- rogueviz/nilrider/levels.cpp | 5 +- rogueviz/nilrider/nilrider.cpp | 4 + rogueviz/nilrider/nilrider.h | 12 ++- 4 files changed, 153 insertions(+), 48 deletions(-) diff --git a/rogueviz/nilrider/level.cpp b/rogueviz/nilrider/level.cpp index f22de812..018bed59 100644 --- a/rogueviz/nilrider/level.cpp +++ b/rogueviz/nilrider/level.cpp @@ -1,13 +1,76 @@ namespace nilrider { +const int steps_per_block = 16; +const int texture_density = 64; + +void level::init_textures() { + int tY = isize(map_tiles); + int tX = isize(map_tiles[0]); + + for(int stepped: {0, 1}) { + + auto& target = stepped ? unil_texture_stepped : unil_texture; + + target = new texture::texture_data; + + auto& tex = *target; + + tex.twidth = tex.tx = tX * texture_density; + tex.theight = tex.ty = tY * texture_density; + tex.stretched = false; + tex.strx = tex.tx; + tex.stry = tex.ty; + tex.base_x = 0; + tex.base_y = 0; + tex.whitetexture(); + + auto getpix = [&] (int x, int y) { + int px = x / pixel_per_block; + int py = y / pixel_per_block; + if(px < 0 || py < 0 || px >= tX || py >= tY) return '!'; + char bmch = map_tiles[py][px]; + if(bmch == '!') return '!'; + return submaps[bmch][y % pixel_per_block][x % pixel_per_block]; + }; + + int subpixels = texture_density / pixel_per_block; + int stepdiv = texture_density / steps_per_block; + + for(int y=0; yscale); + init_textures(); + int tY = isize(map_tiles); int tX = isize(map_tiles[0]); - tex.twidth = tex.tx = tX * 64; - tex.theight = tex.ty = tY * 64; - tex.stretched = false; - tex.strx = tex.tx; - tex.stry = tex.ty; - tex.base_x = 0; - tex.base_y = 0; - tex.whitetexture(); - println(hlog, "tX=", tX, " tY=", tY, " tex=", tex.tx, "x", tex.ty); - - for(int y=0; y (cdiv/2)) q+=2; + if(y % cdiv == (cdiv/2)) q++; + if(y % cdiv > (cdiv/2)) q+=2; + if(q > 1) continue; + } pt(x, y); pt(x, y+1); pt(x+1, y); @@ -245,7 +325,6 @@ void level::init() { } } cgi.finishshape(); - // println(hlog, shFloor[i].s, " to ", shFloor[i].e); } if(flags & nrlOrder) { @@ -315,6 +394,8 @@ ld level::safe_alt(hyperpoint h, ld mul, ld mulx) { return maxv; } +bool stepped_display; + void level::draw_level(const shiftmatrix& V) { int id = 0; for(auto& t: triangles) { @@ -339,9 +420,16 @@ void level::draw_level(const shiftmatrix& V) { queuepoly(V, shField, 0xFFFF00FF); - auto& poly = queuepoly(V, shFloor, 0xFFFFFFFF); // 0xFFFFFFFF); - poly.tinf = &uniltinf; - uniltinf.texture_id = unil_texture->textureid; + if(!stepped_display) { + auto& poly = queuepoly(V, shFloor, 0xFFFFFFFF); // 0xFFFFFFFF); + poly.tinf = &uniltinf; + uniltinf.texture_id = unil_texture->textureid; + } + else { + auto& poly = queuepoly(V, shStepFloor, 0xFFFFFFFF); // 0xFFFFFFFF); + poly.tinf = &uniltinf_stepped; + uniltinf_stepped.texture_id = unil_texture_stepped->textureid; + } } } diff --git a/rogueviz/nilrider/levels.cpp b/rogueviz/nilrider/levels.cpp index 713dcbcb..8e43b154 100644 --- a/rogueviz/nilrider/levels.cpp +++ b/rogueviz/nilrider/levels.cpp @@ -88,9 +88,12 @@ map bcols = { {'2', 0xFF404040}, {'4', 0xFF808080}, {'6', 0xFFC0C0C0}, + {'!', 0xFF000000} }; -map > submaps = { +const int pixel_per_block = 16; + +map > submaps = { {'o', { "WWWWWWWWWWWWWWWW", "W22222222222222W", diff --git a/rogueviz/nilrider/nilrider.cpp b/rogueviz/nilrider/nilrider.cpp index d87a0430..a593c992 100644 --- a/rogueviz/nilrider/nilrider.cpp +++ b/rogueviz/nilrider/nilrider.cpp @@ -226,6 +226,7 @@ void settings() { add_edit(whrad); add_edit(whdist); add_edit(min_gfx_slope); + add_edit(stepped_display); dialog::addItem("configure keys", 'k'); dialog::add_action_push(multi::get_key_configurer(1, move_names, "Nilrider keys")); dialog::addItem("RogueViz settings", 'r'); @@ -382,6 +383,9 @@ void initialize() { param_enum(planning_mode, "nil_planning", "nil_planning", false) -> editable({{"manual", "control the unicycle manually"}, {"planning", "try to plan the optimal route!"}}, "game mode", 'p'); + param_enum(stepped_display, "stepped_display", "stepped_display", false) + -> editable({{"smooth", "ride on a smooth surface"}, {"blocky", "makes slopes more visible -- actual physics are not affected"}}, "game mode", 's'); + rv_hook(hooks_frame, 100, frame); rv_hook(shmup::hooks_turn, 100, turn); on = true; diff --git a/rogueviz/nilrider/nilrider.h b/rogueviz/nilrider/nilrider.h index 8edb1553..9e81eaf0 100644 --- a/rogueviz/nilrider/nilrider.h +++ b/rogueviz/nilrider/nilrider.h @@ -102,6 +102,7 @@ struct level { /* data */ hpcshape shFloor; /**< the 3D model of floor */ hpcshape shPlanFloor; /**< the 3D model of floor for planning */ + hpcshape shStepFloor; /**< the 3D model of stepped floor */ hpcshape shField; /**< the 3D model of the 'field' */ hpcshape shCastle; /**< the 3D model of the 'castle' */ @@ -112,11 +113,17 @@ struct level { /** the texture data used for the ground */ texture::texture_data *unil_texture; + /** the texture data used for the ground in the stepped mode */ + texture::texture_data *unil_texture_stepped; + /** the texture used for the ground */ basic_textureinfo uniltinf; /** the texture used for the ground */ basic_textureinfo castle_tinf; + + /** the texture used for the ground in the stepped mode*/ + basic_textureinfo uniltinf_stepped; /** starting timestamp */ timestamp start; @@ -124,7 +131,10 @@ struct level { /** current timestamp */ timestamp current; - /** initialize textures and start */ + /** initialize textures */ + void init_textures(); + + /** initialize all */ void init(); vector history;