Cleanup; prepared for buildings
This commit is contained in:
@@ -188,7 +188,9 @@ void RoadGrid::index_site(struct map_site *site)
|
||||
diagram_vertices.push_back(v);
|
||||
}
|
||||
site->polygon_ind.write[i] = idx;
|
||||
site->rect.expand_to(Vector2i((int)v.x, (int)v.y));
|
||||
}
|
||||
site->rect.grow(1);
|
||||
site->hedges.resize(site->polygon.size());
|
||||
int count = 0;
|
||||
for (i = 0; i < site->polygon.size(); i++) {
|
||||
@@ -301,6 +303,20 @@ void RoadGrid::build(Ref<Curve> curve, Ref<FastNoiseLite> noise)
|
||||
diagram_vertex_heights.write[i] = 2.0;
|
||||
#endif
|
||||
}
|
||||
generate_3d_vertices();
|
||||
for (i = 0; i < map_sites.size(); i++) {
|
||||
float max_height = -10000.0f;
|
||||
float min_height = 10000.0f;
|
||||
for (j = 0; j < map_sites[i].polygon_ind.size(); j++) {
|
||||
float y = vertices[map_sites[i].polygon_ind[j]].y;
|
||||
if (max_height < y)
|
||||
max_height = y;
|
||||
if (min_height > y)
|
||||
min_height = y;
|
||||
}
|
||||
map_sites.write[i].avg_height = min_height * 0.4f + max_height * 0.6f;
|
||||
}
|
||||
generate_building_positions();
|
||||
printf("building 3rd dimention done\n");
|
||||
}
|
||||
}
|
||||
@@ -369,12 +385,6 @@ int RoadGrid::find_edge(int a, int b)
|
||||
void RoadGrid::setup_vshapes()
|
||||
{
|
||||
int i, j;
|
||||
vertices.resize(get_diagram_vertex_count());
|
||||
for (i = 0; i < vertices.size(); i++) {
|
||||
vertices.write()[i].x = diagram_vertices[i].x;
|
||||
vertices.write()[i].y = diagram_vertex_heights[i];
|
||||
vertices.write()[i].z = diagram_vertices[i].y;
|
||||
}
|
||||
List<struct vshape> vdata_list;
|
||||
for (i = 0; i < map_hedges.size(); i++) {
|
||||
for (j = 0; j < map_hedges.size(); j++) {
|
||||
@@ -482,6 +492,36 @@ void RoadGrid::sort_angle(Vector<int> &sort_data)
|
||||
sorter.sort(sort_data.ptrw(), sort_data.size());
|
||||
}
|
||||
|
||||
void RoadGrid::build_building_positions()
|
||||
void RoadGrid::generate_3d_vertices()
|
||||
{
|
||||
int i;
|
||||
vertices.resize(get_diagram_vertex_count());
|
||||
for (i = 0; i < vertices.size(); i++) {
|
||||
vertices.write()[i].x = diagram_vertices[i].x;
|
||||
vertices.write()[i].y = diagram_vertex_heights[i];
|
||||
vertices.write()[i].z = diagram_vertices[i].y;
|
||||
}
|
||||
}
|
||||
|
||||
void RoadGrid::generate_building_positions()
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < map_sites.size(); i++)
|
||||
generate_site_building_positions(&map_sites[i]);
|
||||
}
|
||||
|
||||
void RoadGrid::generate_site_building_positions(const struct map_site *site)
|
||||
{
|
||||
Vector<Vector2> border;
|
||||
Vector3 center_point;
|
||||
}
|
||||
int RoadGrid::get_site_from_point(int x, int z)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < map_sites.size(); i++)
|
||||
if (map_sites[i].rect.has_point(Vector2i(x, z)))
|
||||
if (Geometry::is_point_in_polygon(Vector2((float)x, (float)z), map_sites[i].polygon))
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -80,6 +80,9 @@ protected:
|
||||
int site_type;
|
||||
int cluster;
|
||||
Vector<struct half_edge> hedges;
|
||||
Vector2 building_positions;
|
||||
Rect2i rect;
|
||||
float avg_height;
|
||||
};
|
||||
void index_site(struct map_site *site);
|
||||
Vector<Vector2> diagram_vertices;
|
||||
@@ -107,8 +110,10 @@ protected:
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* for now the starting town is at 0 */
|
||||
printf("area: %d class: %d\n", cl_area, map_sites[j].site_type);
|
||||
}
|
||||
map_sites.write[0].site_type = SITE_TOWN;
|
||||
}
|
||||
void process_diagram(const Dictionary &diagram);
|
||||
bool segment_intersects_rect(const Vector2 &a, const Vector2 &b, const Rect2 &rect);
|
||||
@@ -247,6 +252,25 @@ public:
|
||||
{
|
||||
return map_hedges.size();
|
||||
}
|
||||
void build_building_positions();
|
||||
void generate_3d_vertices();
|
||||
void generate_building_positions();
|
||||
void generate_site_building_positions(const struct map_site *site);
|
||||
int get_site_from_point(int x, int z);
|
||||
inline bool site_is_town(int site)
|
||||
{
|
||||
return map_sites[site].site_type == SITE_TOWN;
|
||||
}
|
||||
inline bool site_is_farm(int site)
|
||||
{
|
||||
return map_sites[site].site_type == SITE_FARM;
|
||||
}
|
||||
inline float get_site_avg_height(int site)
|
||||
{
|
||||
return map_sites[site].avg_height;
|
||||
}
|
||||
inline Vector2 get_site_pos(int site)
|
||||
{
|
||||
return map_sites[site].pos;
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -479,6 +479,7 @@ void RoadsData::_bind_methods()
|
||||
{
|
||||
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_site_pos", "site"), &RoadsData::get_site_pos);
|
||||
}
|
||||
void RoadsData::set_noise(Ref<FastNoiseLite> noise)
|
||||
{
|
||||
@@ -492,6 +493,7 @@ float RoadsData::get_sdf(int x, int y, int z)
|
||||
{
|
||||
if (!curve.is_valid() || !noise.is_valid())
|
||||
return (float)y;
|
||||
/* will need to fix this for larger world */
|
||||
if (sdf_data.has(x * 50000 + z))
|
||||
return (float)y - sdf_data[x * 50000 + z];
|
||||
float ret;
|
||||
@@ -510,9 +512,21 @@ float RoadsData::get_sdf(int x, int y, int z)
|
||||
}
|
||||
sdf_mutex.unlock();
|
||||
goto out;
|
||||
} else {
|
||||
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));
|
||||
if (site >= 0 && (rg->site_is_town(site) || rg->site_is_farm(site))) {
|
||||
ret = y - rg->get_site_avg_height(site);
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
ret = y - n;
|
||||
out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
Vector2 RoadsData::get_site_pos(int site)
|
||||
{
|
||||
return rg->get_site_pos(site);
|
||||
}
|
||||
|
||||
|
||||
@@ -96,5 +96,6 @@ public:
|
||||
void set_noise(Ref<FastNoiseLite> noise);
|
||||
void set_curve(Ref<Curve> curve);
|
||||
float get_sdf(int x, int y, int z);
|
||||
Vector2 get_site_pos(int site);
|
||||
};
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ VoxelGenerator::Result WorldGenerator::generate_block(VoxelBlockRequest &input)
|
||||
|
||||
Result result;
|
||||
|
||||
real_t time_before = OS::get_singleton()->get_ticks_usec(), total;
|
||||
VoxelBufferInternal &out_buffer = input.voxel_buffer;
|
||||
result = WorldGenerator::generate(
|
||||
out_buffer,
|
||||
@@ -26,8 +25,6 @@ VoxelGenerator::Result WorldGenerator::generate_block(VoxelBlockRequest &input)
|
||||
input.origin_in_voxels, input.lod);
|
||||
|
||||
out_buffer.compress_uniform_channels();
|
||||
total = OS::get_singleton()->get_ticks_usec() - time_before;
|
||||
printf("generate_block: %f\n", total);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user