Prepared for buildings spawning
This commit is contained in:
@@ -314,7 +314,7 @@ void RoadGrid::build(Ref<Curve> curve, Ref<FastNoiseLite> noise)
|
|||||||
if (min_height > y)
|
if (min_height > y)
|
||||||
min_height = y;
|
min_height = y;
|
||||||
}
|
}
|
||||||
map_sites.write[i].avg_height = min_height * 0.4f + max_height * 0.6f;
|
map_sites.write[i].avg_height = min_height * 0.7f + max_height * 0.3f;
|
||||||
}
|
}
|
||||||
generate_building_positions();
|
generate_building_positions();
|
||||||
printf("building 3rd dimention done\n");
|
printf("building 3rd dimention done\n");
|
||||||
|
|||||||
@@ -272,5 +272,62 @@ public:
|
|||||||
{
|
{
|
||||||
return map_sites[site].pos;
|
return map_sites[site].pos;
|
||||||
}
|
}
|
||||||
|
HashMap<int, PoolVector<Vector2> > polygon_cache_2d;
|
||||||
|
inline PoolVector<Vector2> get_site_polygon_2d(int site)
|
||||||
|
{
|
||||||
|
if (polygon_cache_2d.has(site))
|
||||||
|
return polygon_cache_2d[site];
|
||||||
|
int count = 0, i;
|
||||||
|
int psize = map_sites[site].polygon_ind.size();
|
||||||
|
PoolVector<Vector2> polygon;
|
||||||
|
polygon.resize(psize);
|
||||||
|
int prev = -1;
|
||||||
|
for (i = 0; i < psize; i++) {
|
||||||
|
int idx = map_sites[site].polygon_ind[i];
|
||||||
|
if (idx == prev)
|
||||||
|
continue;
|
||||||
|
polygon.write()[count++] = diagram_vertices[idx];
|
||||||
|
prev = idx;
|
||||||
|
}
|
||||||
|
polygon.resize(count);
|
||||||
|
polygon_cache_2d[site] = polygon;
|
||||||
|
return polygon;
|
||||||
|
}
|
||||||
|
HashMap<int, PoolVector<Vector3> > polygon_cache_3d;
|
||||||
|
inline PoolVector<Vector3> get_site_polygon_3d(int site)
|
||||||
|
{
|
||||||
|
if (polygon_cache_3d.has(site))
|
||||||
|
return polygon_cache_3d[site];
|
||||||
|
int count = 0, i;
|
||||||
|
int psize = map_sites[site].polygon_ind.size();
|
||||||
|
PoolVector<Vector3> polygon;
|
||||||
|
polygon.resize(psize);
|
||||||
|
int prev = -1;
|
||||||
|
for (i = 0; i < psize; i++) {
|
||||||
|
int idx = map_sites[site].polygon_ind[i];
|
||||||
|
if (idx == prev)
|
||||||
|
continue;
|
||||||
|
polygon.write()[count++] = vertices[idx];
|
||||||
|
prev = idx;
|
||||||
|
}
|
||||||
|
polygon.resize(count);
|
||||||
|
polygon_cache_3d[site] = polygon;
|
||||||
|
return polygon;
|
||||||
|
}
|
||||||
|
inline PoolVector<int> get_here_sites(const Vector3 &position)
|
||||||
|
{
|
||||||
|
PoolVector<int> ret;
|
||||||
|
int i;
|
||||||
|
Rect2i xpos;
|
||||||
|
xpos.position = Vector2i((int)position.x, (int)position.z);
|
||||||
|
xpos.grow(300);
|
||||||
|
for (i = 0; i < map_sites.size(); i++) {
|
||||||
|
if (xpos.intersects(map_sites[i].rect))
|
||||||
|
ret.push_back(i);
|
||||||
|
if (xpos.encloses(map_sites[i].rect))
|
||||||
|
ret.push_back(i);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -480,6 +480,10 @@ void RoadsData::_bind_methods()
|
|||||||
ClassDB::bind_method(D_METHOD("get_road_grid"), &RoadsData::get_road_grid);
|
ClassDB::bind_method(D_METHOD("get_road_grid"), &RoadsData::get_road_grid);
|
||||||
ClassDB::bind_method(D_METHOD("get_sdf", "x", "y", "z"), &RoadsData::get_sdf);
|
ClassDB::bind_method(D_METHOD("get_sdf", "x", "y", "z"), &RoadsData::get_sdf);
|
||||||
ClassDB::bind_method(D_METHOD("get_site_pos", "site"), &RoadsData::get_site_pos);
|
ClassDB::bind_method(D_METHOD("get_site_pos", "site"), &RoadsData::get_site_pos);
|
||||||
|
ClassDB::bind_method(D_METHOD("get_site_polygon_2d", "site"), &RoadsData::get_site_polygon_2d);
|
||||||
|
ClassDB::bind_method(D_METHOD("get_site_polygon_3d", "site"), &RoadsData::get_site_polygon_3d);
|
||||||
|
ClassDB::bind_method(D_METHOD("get_here_sites", "site"), &RoadsData::get_here_sites);
|
||||||
|
ClassDB::bind_method(D_METHOD("get_site_avg_height", "site"), &RoadsData::get_site_avg_height);
|
||||||
}
|
}
|
||||||
void RoadsData::set_noise(Ref<FastNoiseLite> noise)
|
void RoadsData::set_noise(Ref<FastNoiseLite> noise)
|
||||||
{
|
{
|
||||||
@@ -516,7 +520,7 @@ float RoadsData::get_sdf(int x, int y, int z)
|
|||||||
int site = rg->get_site_from_point(x, z);
|
int site = rg->get_site_from_point(x, z);
|
||||||
// printf("in site %d %d %d\n", site, rg->site_is_town(site), rg->site_is_farm(site));
|
// printf("in site %d %d %d\n", site, rg->site_is_town(site), rg->site_is_farm(site));
|
||||||
if (site >= 0 && (rg->site_is_town(site) || rg->site_is_farm(site))) {
|
if (site >= 0 && (rg->site_is_town(site) || rg->site_is_farm(site))) {
|
||||||
ret = y - rg->get_site_avg_height(site);
|
ret = y - rg->get_site_avg_height(site) - CLAMP(n * 0.1f, -0.5f, 0.5f);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -530,3 +534,17 @@ Vector2 RoadsData::get_site_pos(int site)
|
|||||||
return rg->get_site_pos(site);
|
return rg->get_site_pos(site);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PoolVector<Vector2> RoadsData::get_site_polygon_2d(int site)
|
||||||
|
{
|
||||||
|
return rg->get_site_polygon_2d(site);
|
||||||
|
}
|
||||||
|
|
||||||
|
PoolVector<Vector3> RoadsData::get_site_polygon_3d(int site)
|
||||||
|
{
|
||||||
|
return rg->get_site_polygon_3d(site);
|
||||||
|
}
|
||||||
|
|
||||||
|
PoolVector<int> RoadsData::get_here_sites(const Vector3 &position)
|
||||||
|
{
|
||||||
|
return rg->get_here_sites(position);
|
||||||
|
}
|
||||||
|
|||||||
@@ -97,5 +97,12 @@ public:
|
|||||||
void set_curve(Ref<Curve> curve);
|
void set_curve(Ref<Curve> curve);
|
||||||
float get_sdf(int x, int y, int z);
|
float get_sdf(int x, int y, int z);
|
||||||
Vector2 get_site_pos(int site);
|
Vector2 get_site_pos(int site);
|
||||||
|
PoolVector<Vector2> get_site_polygon_2d(int site);
|
||||||
|
PoolVector<Vector3> get_site_polygon_3d(int site);
|
||||||
|
PoolVector<int> get_here_sites(const Vector3 &pos);
|
||||||
|
inline float get_site_avg_height(int site)
|
||||||
|
{
|
||||||
|
return rg->get_site_avg_height(site);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user