summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaweł Redman <pawel.redman@gmail.com>2017-10-24 23:39:15 +0200
committerPaweł Redman <pawel.redman@gmail.com>2017-10-24 23:39:15 +0200
commit16e1a2f3dd5c08a3847aa635d4bd9dbf83f83c3f (patch)
treef268eb9171bf17817e7b6065870e027a5d834f3f /src
parent6723790daa66c333103f940540ea7ef83a4057d9 (diff)
Tile rendering needs a redoing.
Diffstat (limited to 'src')
-rw-r--r--src/assets.cpp8
-rw-r--r--src/common.hpp31
-rw-r--r--src/render.cpp57
-rw-r--r--src/world.cpp8
4 files changed, 18 insertions, 86 deletions
diff --git a/src/assets.cpp b/src/assets.cpp
index 7d77a38..94651c6 100644
--- a/src/assets.cpp
+++ b/src/assets.cpp
@@ -3,8 +3,8 @@
namespace assets {
human_assets_t human;
-render::tile_monotonic_t tile_dirt;
-render::tile_connecting12_t tile_wall;
+sf::Texture tile_dirt;
+sf::Texture tile_wall;
void load(void)
{
@@ -13,8 +13,8 @@ void load(void)
human.legs_idle.load("assets/units/human/legs_idle", 2, 2);
human.legs_walking.load("assets/units/human/legs_walking", 2, 2);
- tile_dirt.load("assets/tiles/dirt");
- tile_wall.load("assets/tiles/wall");
+ tile_dirt.loadFromFile("assets/tiles/dirt.png");
+ tile_wall.loadFromFile("assets/tiles/wall.png");
}
} // namespace assets
diff --git a/src/common.hpp b/src/common.hpp
index 5da7f33..fde9bc8 100644
--- a/src/common.hpp
+++ b/src/common.hpp
@@ -44,8 +44,9 @@ namespace world {
typedef vec_t<coord_t, 2> sector_index_t;
typedef vec_t<coord_t, 2> tile_index_t;
- static tile_index_t neighbor_offsets[4] = {
- {1, 0}, {0, 1}, {-1, 0}, {0, -1}
+ static tile_index_t neighbor_offsets[8] = {
+ {+1, 0}, {+1, +1}, {0, +1}, {-1, +1},
+ {-1, 0}, {-1, -1}, {0, -1}, {+1, -1}
};
enum {
@@ -57,7 +58,7 @@ namespace world {
class tile_t {
public:
unsigned type : 8;
- unsigned neighbors : 4;
+ unsigned neighbors : 8;
unsigned variant : 8;
};
@@ -221,26 +222,6 @@ namespace render {
void load(std::string prefix, size_t xc, size_t yc);
};
- class tile_t {
- public:
- virtual void load(std::string prefix) = 0;
- virtual sf::Texture *get_texture(int neighbors, bool *mirror) = 0;
- };
-
- class tile_monotonic_t : public tile_t {
- sf::Texture texture;
- public:
- void load(std::string prefix);
- sf::Texture *get_texture(int neighbors, bool *mirror);
- };
-
- class tile_connecting12_t : public tile_t {
- sf::Texture textures[12];
- public:
- void load(std::string prefix);
- sf::Texture *get_texture(int neighbors, bool *mirror);
- };
-
class state_t {
sf::RenderWindow *window;
double now;
@@ -264,8 +245,8 @@ namespace assets {
} human_assets_t;
extern human_assets_t human;
- extern render::tile_monotonic_t tile_dirt;
- extern render::tile_connecting12_t tile_wall;
+ extern sf::Texture tile_dirt;
+ extern sf::Texture tile_wall;
void load(void);
};
diff --git a/src/render.cpp b/src/render.cpp
index 819641f..c8513cb 100644
--- a/src/render.cpp
+++ b/src/render.cpp
@@ -7,34 +7,24 @@ static sf::Font font;
static void draw_tile(sf::RenderWindow *window, v2f_t x, world::tile_t *tile)
{
- render::tile_t *tile_assets;
sf::Texture *texture;
- bool mirror;
switch (tile->type) {
default:
return;
case world::TILE_DIRT:
- tile_assets = &assets::tile_dirt;
+ texture = &assets::tile_dirt;
break;
case world::TILE_WALL:
- tile_assets = &assets::tile_wall;
+ texture = &assets::tile_wall;
break;
}
- texture = tile_assets->get_texture(tile->neighbors, &mirror);
-
wot_rect.setTexture(texture);
wot_rect.setSize(sf::Vector2f(1.0f, 1.0f));
- if (!mirror) {
- wot_rect.setPosition(x);
- wot_rect.setScale(v2f_t(1, 1));
- } else {
- wot_rect.setPosition(x + v2f_t(1.0f, 0));
- wot_rect.setScale(v2f_t(-1, 1));
- }
+ wot_rect.setPosition(x);
wot_rect.setFillColor(sf::Color::White);
wot_rect.setOutlineColor(sf::Color::Transparent);
window->draw(wot_rect);
@@ -274,45 +264,4 @@ void oriented_sprite_4M2_t::load(std::string prefix, size_t xc, size_t yc)
textures[1].load(prefix + "_y_", yc);
}
-void tile_monotonic_t::load(std::string prefix)
-{
- texture.loadFromFile(prefix + ".png");
-}
-
-void tile_connecting12_t::load(std::string prefix)
-{
- for (size_t i = 0; i < 12; i++)
- textures[i].loadFromFile(prefix + "_" + std::to_string(i) + ".png");
-}
-
-sf::Texture *tile_monotonic_t::get_texture(int neighbors, bool *mirror)
-{
- *mirror = false;
- return &texture;
-}
-
-sf::Texture *tile_connecting12_t::get_texture(int neighbors, bool *mirror)
-{
- const static struct{ size_t index; bool mirror; } map[16] = {
- {0, false},
- {1, false},
- {2, false},
- {3, false},
- {1, true},
- {4, false},
- {3, true},
- {5, false},
- {6, false},
- {7, false},
- {8, false},
- {9, false},
- {7, true},
- {10, false},
- {9, true}
- };
-
- *mirror = map[neighbors].mirror;
- return textures + map[neighbors].index;
-}
-
} // namespace render
diff --git a/src/world.cpp b/src/world.cpp
index e176913..9a504c3 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -34,10 +34,12 @@ void world_t::generate_tile(tile_t *tile, tile_index_t x)
if (height < waterlevel)
tile->type = TILE_NONE;
- else if (height < waterlevel + 0.3)
+ else if (height < waterlevel + 0.1)
tile->type = TILE_DIRT;
- else
+ else if (perlin.get(x, 3.0f) > 0.0f)
tile->type = TILE_WALL;
+ else
+ tile->type = TILE_DIRT;
}
void world_t::generate(sector_t *sector, sector_index_t index, bool partial)
@@ -65,7 +67,7 @@ void world_t::generate(sector_t *sector, sector_index_t index, bool partial)
tile = sector->tiles + ly * SECTOR_SIZE + lx;
tile->neighbors = 0;
- for (size_t i = 0; i < 4; i++) {
+ for (size_t i = 0; i < 8; i++) {
tile_index_t neighbor_index;
tile_t *neighbor;