summaryrefslogtreecommitdiff
path: root/src/common.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/common.hpp')
-rw-r--r--src/common.hpp24
1 files changed, 16 insertions, 8 deletions
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 <iostream>
#include <cstdint>
#include <cmath>
+#include <cassert>
#include <map>
+#include <list>
#include <unordered_set>
#include <SFML/Graphics.hpp>
@@ -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<entity_t*> ents;
@@ -64,6 +68,7 @@ namespace world {
procgen::perlin_noise_t perlin;
std::map<sector_index_t, sector_t> 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<sector_t*> get_sectors(sf::FloatRect rect);
+ std::list<entity_t*> 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 <typename T>
-T mod(T x, T y)
-{
- return (x % y) + (x < 0 ? y : 0);
-}
-
// Linear interpolation.
template <typename T>
T lerp(T a, T b, T x)