Ripped out the string based map and created a Matrix map drawing function.
This commit is contained in:
parent
d9219a8c64
commit
dd541ae59d
4 changed files with 11 additions and 28 deletions
|
@ -46,23 +46,21 @@ namespace gui {
|
|||
}
|
||||
|
||||
void MapViewUI::render(sf::RenderWindow &window, int compass_dir) {
|
||||
(void)compass_dir;
|
||||
window.draw(*$paper.sprite);
|
||||
|
||||
auto grid = $gui.entity("map_grid");
|
||||
|
||||
std::wstring map_out = System::draw_map($level, 23, 9, compass_dir);
|
||||
|
||||
// System::draw_map
|
||||
auto& map_text = $gui.get<Textual>(grid);
|
||||
map_text.update(map_out);
|
||||
map_text.update(L"MAP BROKEN");
|
||||
|
||||
$gui.render(window);
|
||||
// $gui.debug_layout(window);
|
||||
}
|
||||
|
||||
void MapViewUI::save_map(const std::string& outfile, int compass_dir) {
|
||||
std::wstring map_out = System::draw_map(
|
||||
$level, $level.map->width(), $level.map->height(), compass_dir);
|
||||
dbc::check(map_out.size() > 0, "WHAT? printed map has nothing in it.");
|
||||
(void)compass_dir;
|
||||
std::wstring map_out = L"I'M BROKEN";
|
||||
|
||||
std::wofstream out(outfile, std::ios::binary);
|
||||
std::locale loc(std::locale::classic(), new std::codecvt_utf8<wchar_t>);
|
||||
|
|
|
@ -32,8 +32,8 @@ namespace gui {
|
|||
}
|
||||
|
||||
void MiniMapUI::render(sf::RenderWindow &window, int compass_dir) {
|
||||
std::wstring map_out = System::draw_map($level, 5, 3, compass_dir);
|
||||
$map_grid.update(map_out);
|
||||
(void)compass_dir;
|
||||
$map_grid.update(L"I'M BROKEN");
|
||||
window.draw(*$map_grid.text);
|
||||
}
|
||||
}
|
||||
|
|
21
systems.cpp
21
systems.cpp
|
@ -407,22 +407,17 @@ void System::plan_motion(World& world, Position move_to) {
|
|||
motion.dy = move_to.location.y - player_position.location.y;
|
||||
}
|
||||
|
||||
/*
|
||||
* This one is called inside the MapViewUI very often so
|
||||
* just avoid GameMap unlike the others.
|
||||
*/
|
||||
std::wstring System::draw_map(GameLevel& level, size_t view_x, size_t view_y, int compass_dir) {
|
||||
void System::draw_map(GameLevel& level, Matrix& grid, int compass_dir) {
|
||||
World &world = *level.world;
|
||||
Map &map = *level.map;
|
||||
size_t view_x = matrix::width(grid);
|
||||
size_t view_y = matrix::height(grid);
|
||||
|
||||
auto player_pos = world.get<Position>(level.player).location;
|
||||
Point cam_orig = map.center_camera(player_pos, view_x, view_y);
|
||||
auto &tiles = map.tiles();
|
||||
auto &tile_set = textures::get_map_tile_set();
|
||||
|
||||
// make a grid of chars to work with
|
||||
auto grid = shiterator::make<wchar_t>(view_x+1, view_y+1);
|
||||
|
||||
// first fill it with the map cells
|
||||
for(shiterator::each_cell_t it{grid}; it.next();) {
|
||||
size_t tile_y = size_t(it.y) + cam_orig.y;
|
||||
|
@ -449,16 +444,6 @@ std::wstring System::draw_map(GameLevel& level, size_t view_x, size_t view_y, in
|
|||
}
|
||||
}
|
||||
});
|
||||
|
||||
// then generate the string to display, but this goes away soon
|
||||
std::wstring result;
|
||||
|
||||
for(shiterator::each_row_t it{grid}; it.next();) {
|
||||
result += grid[it.y][it.x];
|
||||
if(it.row) result += '\n';
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void System::player_status(GameLevel &level) {
|
||||
|
|
|
@ -19,7 +19,7 @@ namespace System {
|
|||
void init_positions(World &world, SpatialMap &collider);
|
||||
void device(World &world, Entity actor, Entity item);
|
||||
void plan_motion(World& world, Position move_to);
|
||||
std::wstring draw_map(GameLevel& level, size_t view_x, size_t view_y, int compass_dir);
|
||||
void draw_map(GameLevel& level, Matrix& grid, int compass_dir);
|
||||
Entity spawn_item(World& world, const string& name);
|
||||
bool drop_item(GameLevel& level, Entity item);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue