diff options
Diffstat (limited to 'src/render.cpp')
-rw-r--r-- | src/render.cpp | 40 |
1 files changed, 33 insertions, 7 deletions
diff --git a/src/render.cpp b/src/render.cpp index f773f92..2e8447b 100644 --- a/src/render.cpp +++ b/src/render.cpp @@ -10,6 +10,9 @@ state_t::state_t(sf::RenderWindow *window_) window = window_; font.loadFromFile("assets/FanwoodText.otf"); + + prng.seed(396); + perlin.generate(&prng, 16); } // FIXME: rename @@ -20,6 +23,7 @@ void register_tile(uint8_t type, const char *path) printf("load %s\n", path); tiles[type] = new sf::Texture; tiles[type]->loadFromFile(path); + tiles[type]->setRepeated(true); } void state_t::begin_frame(double now_, double dt_) @@ -70,10 +74,32 @@ void state_t::drender_entity(world::entity_t *ent) drender_text(ent->render_bounds, ss.str()); } +static const v2f_t tile_base[8] ={ + {1.0f, 0.5f}, {1.0f, 1.0f}, {0.5f, 1.0f}, {0.0f, 1.0f}, + {0.0f, 0.5f}, {0.0f, 0.0f}, {0.5f, 0.0f}, {1.0f, 0.0f} +}; + +static void generate_tile_verts(sf::Vertex *verts, v2f_t tx, procgen::perlin_noise_t *perlin) +{ + for (size_t i = 0; i < 8; i++) { + v2f_t base, turb; + + base = tile_base[i] + tx; + + turb[0] = perlin->get(base, 1.0f) * 0.5f; + turb[1] = perlin->get(base, 2.0f) * 0.5f; + + verts[i].position = base + turb; + verts[i].texCoords = (base + turb) * 32.0f; + verts[i].color = sf::Color::White; + } +} + void state_t::render_sector(world::sector_t *sector) { for (ssize_t y = 0; y < SECTOR_SIZE; y++) for (ssize_t x = 0; x < SECTOR_SIZE; x++) { + sf::Vertex verts[8]; sf::Texture *texture; v2f_t tx; world::tile_t *tile; @@ -87,13 +113,9 @@ void state_t::render_sector(world::sector_t *sector) abort(); } - wot_rect.setTexture(texture, true); - wot_rect.setSize(sf::Vector2f(1.0f, 1.0f)); - wot_rect.setPosition(tx); - wot_rect.setFillColor(sf::Color::White); - wot_rect.setOutlineColor(sf::Color::Transparent); - window->draw(wot_rect); - wot_rect.setTexture(NULL); + sf::RenderStates states(texture); + generate_tile_verts(verts, tx, &perlin); + window->draw(verts, 8, sf::TrianglesFan, states); if (debug_draw_tile_coords) { world::tile_index_t local(x, y); @@ -116,6 +138,7 @@ void state_t::render(game::state_t *game) { sf::Vector2u size = window->getSize(); v2f_t A, B, C, D; + const v2f_t margin(1.0f, 1.0f); rectf_t bbox; std::list<world::entity_t*> ents; @@ -129,6 +152,9 @@ void state_t::render(game::state_t *game) 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]}); + bbox[0] -= margin; + bbox[1] += margin; + for (world::sector_t *sector : game->world.get_sectors(bbox)) render_sector(sector); |