Started prototyping a viewport iterator but couldn't get it right so I'll test drive it next.
This commit is contained in:
parent
4cb41a61db
commit
1962b0c24e
2 changed files with 43 additions and 7 deletions
15
gui.cpp
15
gui.cpp
|
@ -98,7 +98,8 @@ void MapViewUI::draw_map() {
|
|||
size_t end_y = std::min(size_t(height), $game_map.height() - start.y);
|
||||
|
||||
for(size_t y = 0; y < end_y; ++y) {
|
||||
for(size_t x = 0; x < end_x; ++x) {
|
||||
for(size_t x = 0; x < end_x; ++x)
|
||||
{
|
||||
const TileCell& tile = tiles.at(start.x+x, start.y+y);
|
||||
// light value is an integer that's a percent
|
||||
float light_value = debug.LIGHT ? 80 * PERCENT : lighting[start.y+y][start.x+x] * PERCENT;
|
||||
|
@ -108,14 +109,14 @@ void MapViewUI::draw_map() {
|
|||
string num = dnum > 15 ? "*" : format("{:x}", dnum);
|
||||
|
||||
$canvas.DrawText(x * 2, y * 4, num, [dnum, tile, light_value](auto &pixel) {
|
||||
pixel.foreground_color = Color::HSV(dnum * 20, 150, 200);
|
||||
pixel.background_color = Color::HSV(30, 20, tile.bg_v * 50 * PERCENT);
|
||||
});
|
||||
pixel.foreground_color = Color::HSV(dnum * 20, 150, 200);
|
||||
pixel.background_color = Color::HSV(30, 20, tile.bg_v * 50 * PERCENT);
|
||||
});
|
||||
} else {
|
||||
$canvas.DrawText(x * 2, y * 4, tile.display, [tile, light_value](auto &pixel) {
|
||||
pixel.foreground_color = Color::HSV(tile.fg_h, tile.fg_s, tile.fg_v * light_value);
|
||||
pixel.background_color = Color::HSV(tile.bg_h, tile.bg_s, tile.bg_v * light_value);
|
||||
});
|
||||
pixel.foreground_color = Color::HSV(tile.fg_h, tile.fg_s, tile.fg_v * light_value);
|
||||
pixel.background_color = Color::HSV(tile.bg_h, tile.bg_s, tile.bg_v * light_value);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
35
matrix.hpp
35
matrix.hpp
|
@ -78,6 +78,41 @@ namespace matrix {
|
|||
}
|
||||
};
|
||||
|
||||
template<typename MAT>
|
||||
struct viewport_t {
|
||||
Point start;
|
||||
// this is the point in the map
|
||||
size_t x;
|
||||
size_t y;
|
||||
// this is the point inside the box, start at 0
|
||||
size_t view_x = ~0;
|
||||
size_t view_y = ~0;
|
||||
// viewport width/height
|
||||
size_t width;
|
||||
size_t height;
|
||||
|
||||
viewport_t(MAT &mat, Point start, int max_x, int max_y) :
|
||||
start(start),
|
||||
x(start.x-1),
|
||||
y(start.y-1)
|
||||
{
|
||||
width = std::min(size_t(max_x), matrix::width(mat) - start.x);
|
||||
height = std::min(size_t(max_y), matrix::height(mat) - start.y);
|
||||
fmt::println("viewport_t max_x, max_y {},{} vs matrix {},{}, x={}, y={}",
|
||||
max_x, max_y, matrix::width(mat), matrix::height(mat), x, y);
|
||||
}
|
||||
|
||||
bool next() {
|
||||
y = next_y(x, y);
|
||||
x = next_x(x, width);
|
||||
view_x = next_x(view_x, width);
|
||||
view_y = next_y(view_x, view_y);
|
||||
return at_end(y, height);
|
||||
}
|
||||
};
|
||||
|
||||
using viewport = viewport_t<Matrix>;
|
||||
|
||||
using each_cell = each_cell_t<Matrix>;
|
||||
|
||||
template<typename MAT>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue