summaryrefslogtreecommitdiff
path: root/src/common.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/common.hpp')
-rw-r--r--src/common.hpp52
1 files changed, 43 insertions, 9 deletions
diff --git a/src/common.hpp b/src/common.hpp
index bf2a300..5da7f33 100644
--- a/src/common.hpp
+++ b/src/common.hpp
@@ -40,15 +40,27 @@ namespace render { class state_t; }
namespace world {
#define SECTOR_SIZE 8
- class tile_t {
- public:
- char type;
- };
-
typedef int64_t coord_t;
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}
+ };
+
+ enum {
+ TILE_NONE,
+ TILE_DIRT,
+ TILE_WALL
+ };
+
+ class tile_t {
+ public:
+ unsigned type : 8;
+ unsigned neighbors : 4;
+ unsigned variant : 8;
+ };
+
sector_index_t sector_index_at(v2f_t x);
tile_index_t tile_index_at(v2f_t x);
@@ -71,7 +83,7 @@ namespace world {
std::map<sector_index_t, sector_t> sectors;
void generate_tile(tile_t *tile, tile_index_t index);
- void generate(sector_t *sector, sector_index_t index);
+ void generate(sector_t *sector, sector_index_t index, bool partial);
protected:
friend render::state_t;
@@ -83,8 +95,8 @@ namespace world {
public:
world_t(void);
- sector_t *get_sector(sector_index_t index);
- tile_t *get_tile(tile_index_t index);
+ sector_t *get_sector(sector_index_t index, bool partial = false);
+ tile_t *get_tile(tile_index_t index, bool partial = false);
bool find_path(v2f_t src, v2f_t dst, rectf_t size, entity_t *ignore, std::list<v2f_t> *path);
@@ -147,7 +159,7 @@ namespace game {
world::world_t world;
void start(void);
- void tick(void);
+ void tick(double now);
void debug_click(v2f_t x);
};
@@ -209,6 +221,26 @@ 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;
@@ -232,6 +264,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;
void load(void);
};