From 753f71536339b78c49468ba6452c96d6b3c345b2 Mon Sep 17 00:00:00 2001 From: Paweł Redman Date: Tue, 10 Oct 2017 19:33:33 +0200 Subject: Finish work on world entities, start experimenting with world generation. --- src/common.hpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'src/common.hpp') diff --git a/src/common.hpp b/src/common.hpp index 6a30f9e..06e9d9f 100644 --- a/src/common.hpp +++ b/src/common.hpp @@ -1,7 +1,9 @@ #include #include #include +#include #include +#include #include #include @@ -45,6 +47,7 @@ namespace world { sector_index_t (); sector_index_t (int64_t x_, int64_t y_); + sector_index_t (float x_, float y_); bool operator<(sector_index_t B) const; }; @@ -52,6 +55,7 @@ namespace world { class sector_t { public: + sector_index_t index; sf::FloatRect bounds; std::unordered_set ents; @@ -64,6 +68,7 @@ namespace world { procgen::perlin_noise_t perlin; std::map sectors; + void generate_tile(ssize_t lx, ssize_t ly, tile_t *tile); void generate(sector_t *sector, sector_index_t index); public: @@ -71,7 +76,13 @@ namespace world { sector_t *get_sector(sector_index_t index); tile_t *get_tile(ssize_t x, ssize_t y); + // FIXME: iterators instead of returning std::lists + std::list get_sectors(sf::FloatRect rect); + std::list get_entities(sf::FloatRect rect); + void render(sf::RenderWindow *window); + + void debug_point(sf::Vector2f point); }; class entity_t { @@ -80,6 +91,10 @@ namespace world { void link_to_sector(sector_t *sector); + protected: + friend world_t; + size_t cookie = 0; + public: sf::FloatRect bounds; @@ -92,9 +107,9 @@ namespace world { namespace game { class state_t { + public: world::world_t world; - public: void start(void); void tick(void); void render(sf::RenderWindow *window_); @@ -142,13 +157,6 @@ T divide_rmi(T x, T y, T *rem) return rv; } -// Modulo operation. y is expected to be positive. -template -T mod(T x, T y) -{ - return (x % y) + (x < 0 ? y : 0); -} - // Linear interpolation. template T lerp(T a, T b, T x) -- cgit