summaryrefslogtreecommitdiff
path: root/src/render.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/render.cpp')
-rw-r--r--src/render.cpp47
1 files changed, 19 insertions, 28 deletions
diff --git a/src/render.cpp b/src/render.cpp
index 0353f97..5e7d1a4 100644
--- a/src/render.cpp
+++ b/src/render.cpp
@@ -3,14 +3,13 @@
static sf::RectangleShape wot_rect;
-static void draw_tile(sf::RenderWindow *window, float x, float y,
- world::tile_t *tile)
+static void draw_tile(sf::RenderWindow *window, v2f_t x, world::tile_t *tile)
{
sf::Color color;
wot_rect.setTexture(NULL);
wot_rect.setSize(sf::Vector2f(1.0f, 1.0f));
- wot_rect.setPosition(sf::Vector2f(x, y));
+ wot_rect.setPosition(x);
switch (tile->type) {
case -1:
@@ -41,16 +40,8 @@ static void draw_sector(sf::RenderWindow *window, world::sector_t *sector)
{
for (ssize_t y = 0; y < SECTOR_SIZE; y++)
for (ssize_t x = 0; x < SECTOR_SIZE; x++)
- draw_tile(window,
- sector->bounds.left + x, sector->bounds.top + y,
+ draw_tile(window, sector->bounds.v[0] + v2f_t(x, y),
sector->tiles + y * SECTOR_SIZE + x);
-
- /*if ((sector->index.x & 2) ^ (sector->index.y & 2)) {
- wot_rect.setSize(sf::Vector2f(SECTOR_SIZE, SECTOR_SIZE));
- wot_rect.setPosition(sf::Vector2f(sector->bounds.left, sector->bounds.top));
- wot_rect.setFillColor(sf::Color(0, 0, 0, 50));
- window->draw(wot_rect);
- }*/
}
void interface::state_t::render()
@@ -78,8 +69,8 @@ void state_t::end_frame(void)
void state_t::render(game::state_t *game)
{
sf::Vector2u size = window->getSize();
- sf::Vector2f A, B, C, D;
- sf::Rect<float> bbox;
+ v2f_t A, B, C, D;
+ rectf_t bbox;
std::list<world::entity_t*> ents;
A = window->mapPixelToCoords(sf::Vector2i(0, 0));
@@ -87,10 +78,10 @@ void state_t::render(game::state_t *game)
C = window->mapPixelToCoords(sf::Vector2i(0, size.y));
D = window->mapPixelToCoords(sf::Vector2i(size.x, size.y));
- bbox.left = std::min({A.x, B.x, C.x, D.x});
- bbox.top = std::min({A.y, B.y, C.y, D.y});
- bbox.width = std::max({A.x, B.x, C.x, D.x}) - bbox.left;
- bbox.height = std::max({A.y, B.y, C.y, D.y}) - bbox.top;
+ bbox[0][0] = std::min({A[0], B[0], C[0], D[0]});
+ bbox[0][1] = std::min({A[1], B[1], C[1], D[1]});
+ bbox[1][0] = std::max({A[0], B[0], C[0], D[0]});
+ bbox[1][1] = std::max({A[1], B[1], C[1], D[1]});
for (world::sector_t *sector : game->world.get_sectors(bbox))
draw_sector(window, sector);
@@ -99,15 +90,14 @@ void state_t::render(game::state_t *game)
ents.sort(
[](const world::entity_t *x, const world::entity_t *y) -> bool
{
- return x->bounds.top + x->bounds.height
- < y->bounds.top + y->bounds.height;
+ return x->bounds[1][0] < y->bounds[1][0];
});
for (world::entity_t *ent : ents)
ent->render_to(this);
}
-void state_t::render(animated_texture_t *anim, sf::FloatRect bounds, bool mirror){
+void state_t::render(animated_texture_t *anim, rectf_t bounds, bool mirror){
size_t frame;
if (!anim)
@@ -122,20 +112,21 @@ void state_t::render(animated_texture_t *anim, sf::FloatRect bounds, bool mirror
wot_rect.setFillColor(sf::Color::White);
if (!mirror) {
- wot_rect.setPosition(bounds.left, bounds.top);
- wot_rect.setSize(sf::Vector2f(bounds.width, bounds.height));
+ wot_rect.setPosition(bounds[0]);
+ wot_rect.setSize(bounds[1] - bounds[0]);
} else {
- wot_rect.setPosition(bounds.left + bounds.width, bounds.top);
- wot_rect.setSize(sf::Vector2f(bounds.width, bounds.height));
- wot_rect.setScale(sf::Vector2f(-1, 1));
+ float dx = bounds[1][0] - bounds[0][0];
+ wot_rect.setPosition(bounds[0] + v2f_t(dx, 0));
+ wot_rect.setSize(bounds[1] - bounds[0]);
+ wot_rect.setScale(v2f_t(-1, 1));
}
window->draw(wot_rect);
wot_rect.setTexture(NULL);
- wot_rect.setScale(sf::Vector2f(1, 1));
+ wot_rect.setScale(v2f_t(1, 1));
}
-void state_t::render(oriented_sprite_t *sprite, sf::FloatRect bounds, float angle)
+void state_t::render(oriented_sprite_t *sprite, rectf_t bounds, float angle)
{
size_t index;
bool mirror;