57 lines
1.4 KiB
C++
57 lines
1.4 KiB
C++
#ifndef DENSITY_MAP_H
|
|
#define DENSITY_MAP_H
|
|
#include <core/resource.h>
|
|
#include <core/math/random_number_generator.h>
|
|
#include <modules/voxel/util/math/vector3i.h>
|
|
|
|
class DensityMap: public Resource {
|
|
GDCLASS(DensityMap, Resource);
|
|
public:
|
|
DensityMap();
|
|
~DensityMap();
|
|
protected:
|
|
Ref<RandomNumberGenerator> rnd;
|
|
struct area {
|
|
Vector2i pos;
|
|
float radius;
|
|
struct area *parent;
|
|
inline bool has_point(const Vector2i &pt)
|
|
{
|
|
int tox = pos.x - pt.x;
|
|
int toy = pos.y - pt.y;
|
|
int tdst = tox * tox + toy * toy;
|
|
int rsq = (int)(radius * radius);
|
|
return tdst < rsq;
|
|
}
|
|
};
|
|
List<struct area> clusters;
|
|
List<struct area> regions;
|
|
List<struct area> counties;
|
|
List<struct area> cities;
|
|
List<struct area> districts;
|
|
int num_clusters;
|
|
int num_regions;
|
|
int num_counties;
|
|
int num_cities;
|
|
int num_districts;
|
|
HashMap<Vector2i, Vector<struct area> > circle_grid;
|
|
void split_area(struct area *area, int num_split, List<struct area> &list);
|
|
void populate_grid(List<struct area> &list);
|
|
|
|
void set_num_clusters(int num);
|
|
int get_num_clusters() const;
|
|
/* 100m grid */
|
|
int grid_size;
|
|
uint32_t world_x_size;
|
|
uint32_t world_y_size;
|
|
uint32_t world_z_size;
|
|
Vector3i world_center;
|
|
int seed;
|
|
bool _set(const StringName &p_name, const Variant &p_value);
|
|
bool _get(const StringName &p_name, Variant &r_ret) const;
|
|
void _get_property_list(List<PropertyInfo> *p_list) const;
|
|
public:
|
|
void update_clusters();
|
|
};
|
|
#endif
|