summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common.hpp4
-rw-r--r--src/game/game.hpp3
-rw-r--r--src/game/pseudostate.cpp5
-rw-r--r--src/main.cpp3
-rw-r--r--src/render.cpp41
5 files changed, 49 insertions, 7 deletions
diff --git a/src/common.hpp b/src/common.hpp
index 6aa88d7..bb425e9 100644
--- a/src/common.hpp
+++ b/src/common.hpp
@@ -321,6 +321,7 @@ namespace render {
class state_t {
sf::RenderWindow *window;
+ void render_water(world::world_t *world, rectf_t rect, double time);
void render_tile(world::world_t *world, v2f_t tx, world::tile_t *tile);
void render_layer(world::world_t *world, rect_t<world::coord_t, 2> &sectors, std::list<world::entity_t*> &ents, layer_t layer);
void drender_text(rectf_t rect, std::string str);
@@ -337,7 +338,7 @@ namespace render {
void begin_frame(ntime_t time_, double dt);
void end_frame(void);
- void render(world::world_t *world);
+ void render(world::world_t *world, double time);
void render(double phase, animated_texture_t *anim, rectf_t bounds, sf::Color color = sf::Color::White, bool mirror = false);
void render(double phase, oriented_sprite_t *sprite, rectf_t bounds, float angle);
@@ -392,6 +393,7 @@ namespace game {
void stop(void);
void tick(ntime_t time, double dt);
world::world_t *get_world(void);
+ double get_render_time(void);
void render_interface_to(render::state_t *render);
};
diff --git a/src/game/game.hpp b/src/game/game.hpp
index 3e5042c..31eb164 100644
--- a/src/game/game.hpp
+++ b/src/game/game.hpp
@@ -163,12 +163,11 @@ namespace game {
};
enum {
- TILE_NONE,
+ TILE_WATER = 0, // special value
TILE_DIRT,
TILE_DIRT_RED,
TILE_STONE,
TILE_STONE_RED,
- TILE_WATER,
TILE_GRAVEL
};
diff --git a/src/game/pseudostate.cpp b/src/game/pseudostate.cpp
index 5b64b9e..969b979 100644
--- a/src/game/pseudostate.cpp
+++ b/src/game/pseudostate.cpp
@@ -53,6 +53,11 @@ world::world_t *pseudostate_t::get_world(void)
return &pimpl->world;
}
+double pseudostate_t::get_render_time(void)
+{
+ return pimpl->now;
+}
+
void pseudostate_t::render_interface_to(render::state_t *render)
{
pimpl->interface.render_to(render);
diff --git a/src/main.cpp b/src/main.cpp
index c7a6f77..c4388b1 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -123,9 +123,8 @@ int main()
sys_get_rss();
- window.clear();
render.begin_frame(now, dt);
- render.render(game.get_world());
+ render.render(game.get_world(), game.get_render_time());
game.render_interface_to(&render);
render.end_frame();
}
diff --git a/src/render.cpp b/src/render.cpp
index 57c1185..54fbe58 100644
--- a/src/render.cpp
+++ b/src/render.cpp
@@ -68,7 +68,6 @@ void state_t::begin_frame(ntime_t time_, double dt_)
{
time = time_;
dt = dt_;
- window->clear();
stats.sectors = 0;
stats.tiles = 0;
@@ -141,6 +140,9 @@ void state_t::render_tile(world::world_t *world, v2f_t tx, world::tile_t *tile)
sf::Vertex verts[8];
tiledata_t *data;
+ if (tile->type == 0)
+ return;
+
data = tiledata + tile->type;
generate_tile_verts(verts, tx, &world->perlin);
@@ -216,6 +218,38 @@ bool visibility_order(const world::entity_t *x, const world::entity_t *y)
return x->render_bounds[1][1] > y->render_bounds[1][1];
}
+void state_t::render_water(world::world_t *world, rectf_t rect, double time)
+{
+ sf::Vertex quad[4];
+ sf::RenderStates states;
+
+ quad[0].position = rect[0];
+ quad[1].position = v2f_t(rect[1][0], rect[0][1]);
+ quad[2].position = rect[1];
+ quad[3].position = v2f_t(rect[0][0], rect[1][1]);
+
+ states.texture = tiledata[0].top;
+
+ for (size_t i = 0; i < 3; i++) {
+ states.blendMode = (i == 0 ? sf::BlendAlpha : sf::BlendAdd);
+
+ for (size_t j = 0; j < 4; j++) {
+ float mul;
+ v2f_t delta;
+
+ mul = powf(2.0f, i + 4);
+ delta[0] = world->perlin.get(v2f_t(time, time), mul);
+ delta[1] = world->perlin.get(v2f_t(time, -time), mul);
+ delta *= 20.0f;
+
+ quad[j].texCoords = (quad[j].position + delta) * mul;
+ quad[j].texCoords.y *= 2.0f;
+ }
+
+ window->draw(quad, 4, sf::Quads, states);
+ }
+}
+
void state_t::render_layer(world::world_t *world, rect_t<world::coord_t, 2> &sectors,
std::list<world::entity_t*> &ents, layer_t layer)
{
@@ -259,7 +293,7 @@ void state_t::render_layer(world::world_t *world, rect_t<world::coord_t, 2> &sec
}
}
-void state_t::render(world::world_t *world)
+void state_t::render(world::world_t *world, double time)
{
const v2f_t margin = {1.5f, 1.5f};
rectf_t bounds;
@@ -272,6 +306,9 @@ void state_t::render(world::world_t *world)
sectors[0] = world::sector_index_at(bounds[0]);
sectors[1] = world::sector_index_at(bounds[1]);
+ // Draw the water _with_ the margin to avoid seams at the screen's edges.
+ render_water(world, bounds, time);
+
ents = world->get_render_entities(bounds);
ents.sort(rendering_order);