69 lines
1.3 KiB
C++
69 lines
1.3 KiB
C++
#include <core/object.h>
|
|
|
|
#define WORLD_MAP_TESTS
|
|
|
|
class WorldMapData: public Object {
|
|
GDCLASS(WorldMapData, Object)
|
|
public:
|
|
WorldMapData();
|
|
~WorldMapData();
|
|
static WorldMapData *get_singleton();
|
|
static void create_singleton();
|
|
static void destroy_singleton();
|
|
struct area {
|
|
int x;
|
|
int y;
|
|
float radius;
|
|
Vector2i to_vec2i() const
|
|
{
|
|
Vector2i pos;
|
|
pos.x = x;
|
|
pos.y = y;
|
|
return pos;
|
|
}
|
|
};
|
|
void add_circle(int x, int y, float radius);
|
|
List<int> get_circles_for_pos(int x, int y);
|
|
bool in_circle(int id, int x, int y);
|
|
void set_world_size(int x, int y)
|
|
{
|
|
world_x = x;
|
|
world_y = y;
|
|
}
|
|
#ifdef WORLD_MAP_TESTS
|
|
void unit_test();
|
|
bool tests_run;
|
|
#endif
|
|
void save_debug_image();
|
|
void clear();
|
|
void set_seed(int seed)
|
|
{
|
|
this->seed = seed;
|
|
}
|
|
int get_seed() const
|
|
{
|
|
return seed;
|
|
}
|
|
void build_point_clusters_iteration(Vector2i seed_point, int bound, int count);
|
|
protected:
|
|
int get_sorted_index(const List<int> &items, float radius) const;
|
|
inline void get_circle(int id, int &x, int &y, float &radius)
|
|
{
|
|
if (id >= areas.size())
|
|
return;
|
|
x = areas[id].x;
|
|
y = areas[id].y;
|
|
radius = areas[id].radius;
|
|
}
|
|
int grid_size;
|
|
int last_area;
|
|
int alloc_count;
|
|
Vector<struct area> areas;
|
|
HashMap<Vector2i, List<int> > grid;
|
|
static void _bind_methods();
|
|
int world_x;
|
|
int world_y;
|
|
int seed;
|
|
};
|
|
|