diff options
author | Paweł Redman <pawel.redman@gmail.com> | 2017-11-07 11:01:20 +0100 |
---|---|---|
committer | Paweł Redman <pawel.redman@gmail.com> | 2017-11-07 11:01:20 +0100 |
commit | 68afd10851e01872c5c7774a2c1a09039d6e61d7 (patch) | |
tree | 382043bc62bad9751a3ef7778e799d78b4362bc3 /src/render.cpp | |
parent | 6ab51bfb002af08da74a693f386c4154d2c4108a (diff) |
Improve path finding.
The path finder will avoid paths that would intersect obstacles.
Diffstat (limited to 'src/render.cpp')
-rw-r--r-- | src/render.cpp | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/src/render.cpp b/src/render.cpp index 7b38989..9fb1625 100644 --- a/src/render.cpp +++ b/src/render.cpp @@ -69,6 +69,53 @@ void state_t::end_frame(void) window->display(); } +void state_t::drender_rect(rectf_t rect, sf::Color color) +{ + sf::Color fill; + + + fill = sf::Color(color.r, color.g, color.b, 50); + + wot_rect.setSize(rect.dims()); + wot_rect.setPosition(rect[0]); + wot_rect.setFillColor(fill); + wot_rect.setOutlineThickness(0.01); + wot_rect.setOutlineColor(color); + window->draw(wot_rect); +} + +void state_t::drender_text(rectf_t rect, std::string str) +{ + sf::Text text(str, font, 20); + sf::FloatRect text_rect; + v2f_t text_size, x; + + text.setScale(0.006f, 0.006f); + text_rect = text.getGlobalBounds(); + text_size = v2f_t(text_rect.width, text_rect.height); + x = rect.center() - text_size / 2; + + text.setPosition(x + v2f_t(0.01f, 0.01f)); + text.setFillColor(sf::Color::Black); + window->draw(text); + + text.setPosition(x); + text.setFillColor(sf::Color::White); + window->draw(text); +} + +void state_t::drender_entity(world::entity_t *ent) +{ + std::stringstream ss; + + drender_rect(ent->render_bounds, sf::Color::Red); + drender_rect(ent->cmodel.bounds, sf::Color::Yellow); + + ss << (void*)ent << "\n"; + ss << "CF=" << ent->cmodel.cflags; + drender_text(ent->render_bounds, ss.str()); +} + void state_t::render(game::state_t *game) { sf::Vector2u size = window->getSize(); @@ -96,8 +143,10 @@ void state_t::render(game::state_t *game) return x->render_bounds[1][0] < y->render_bounds[1][0]; }); - for (world::entity_t *ent : ents) + for (world::entity_t *ent : ents) { ent->render_to(this); + drender_entity(ent); + } for (world::world_t::debug_t &debug : game->world.debug) { sf::Text text(debug.text, font, 20); |