Compoile fixes
This commit is contained in:
Submodule src/flecs updated: a51883026c...254e7ee72f
Submodule src/godot updated: 9ce78ca5c2...766b02c9cd
Submodule src/meshoptimizer updated: fc45e051a8...7634a68dd5
@@ -7,8 +7,8 @@ Import("env_modules")
|
||||
|
||||
env_stream = env_modules.Clone()
|
||||
env_stream.module_obj = []
|
||||
env_stream.Prepend(CPPPATH=["../../meshoptimizer/src"])
|
||||
env_stream.Prepend(CPPPATH=["event"])
|
||||
env_stream.Append(CPPPATH=["../../meshoptimizer/src"])
|
||||
env_stream.Append(CPPPATH=["./event"])
|
||||
env_stream.add_source_files(env_stream.module_obj, "*.cpp")
|
||||
env.modules_sources += env_stream.module_obj
|
||||
|
||||
@@ -21,3 +21,4 @@ SConscript("flecs/SCsub")
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -15,4 +15,5 @@ env.add_source_files(env.stream_building_sources, "*.cpp")
|
||||
lib = env.add_library("buildings", env.stream_building_sources)
|
||||
env.Prepend(LIBS=[lib])
|
||||
env.Prepend(CPPPATH=[".."])
|
||||
env.Prepend(CPPPATH=["../event"])
|
||||
env.Prepend(CPPPATH=["../../../meshoptimizer/src"])
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <core/object.h>
|
||||
#include <scene/3d/immediate_geometry.h>
|
||||
#include "wedge.h"
|
||||
#include "base_data.h"
|
||||
#include "contours.h"
|
||||
|
||||
Contours *Contours::singleton = nullptr;
|
||||
@@ -17,6 +18,7 @@ Contours *Contours::get_singleton()
|
||||
Contours::Contours()
|
||||
: dbg(nullptr)
|
||||
{
|
||||
BaseData::get_singleton()->get().component<Lot>();
|
||||
}
|
||||
|
||||
Contours::~Contours()
|
||||
@@ -84,41 +86,107 @@ void Contours::build()
|
||||
}
|
||||
contours.push_back(mc);
|
||||
}
|
||||
polygons.clear();
|
||||
for (i = 0; i < (int)contours.size(); i++)
|
||||
polygons.push_back({ contours[i].points, contours[i].aabb });
|
||||
List<struct polygon> polygon_queue;
|
||||
List<struct polygon> polygon_output;
|
||||
for (i = 0; i < (int)polygons.size(); i++)
|
||||
polygon_queue.push_back(polygons[i]);
|
||||
polygons.clear();
|
||||
List<struct polygon>::Element *e = polygon_queue.front();
|
||||
while (e) {
|
||||
struct polygon item = e->get();
|
||||
print_line("queue: " + itos(polygon_queue.size()));
|
||||
polygon_queue.pop_front();
|
||||
float area = item.area();
|
||||
if (area > 120.0f * 120.0f && item.aabb.size.x > 10.0f &&
|
||||
item.aabb.size.z > 10.0f) {
|
||||
std::pair<struct polygon, struct polygon> polys =
|
||||
item.split();
|
||||
if (polys.first.area() < 10.0f ||
|
||||
polys.second.area() < 10.0f) {
|
||||
polygon_output.push_back(item);
|
||||
} else {
|
||||
polygon_queue.push_back(polys.first);
|
||||
polygon_queue.push_back(polys.second);
|
||||
flecs::entity base_e = BaseData::get_singleton()->get().lookup("lots");
|
||||
if (base_e.is_valid())
|
||||
base_e.destruct();
|
||||
base_e = BaseData::get_singleton()->get().entity("lots");
|
||||
List<struct Lot::polygon> polygon_queue;
|
||||
List<struct Lot::polygon> polygon_output;
|
||||
Vector<struct Lot::polygon> check;
|
||||
check.resize(contours.size());
|
||||
/* checking contours do not intersect */
|
||||
for (i = 0; i < (int)contours.size(); i++) {
|
||||
check.write[i] = { contours[i].points, contours[i].aabb };
|
||||
}
|
||||
Set<int> ignore;
|
||||
int k, l;
|
||||
for (i = 0; i < (int)contours.size(); i++) {
|
||||
for (j = 0; j < (int)check.size(); j++) {
|
||||
if (i != j) {
|
||||
for (k = 0; k < (int)contours[i].points.size();
|
||||
k++) {
|
||||
for (l = 0;
|
||||
l < (int)contours[j].points.size();
|
||||
l++) {
|
||||
assert(!contours[i].points[k].is_equal_approx(
|
||||
contours[j].points[l]));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else
|
||||
polygon_output.push_back(item);
|
||||
e = polygon_queue.front();
|
||||
}
|
||||
}
|
||||
polygons.reserve(polygon_output.size());
|
||||
e = polygon_output.front();
|
||||
while (e) {
|
||||
polygons.push_back(e->get());
|
||||
e = e->next();
|
||||
for (i = 0; i < (int)contours.size(); i++) {
|
||||
check.write[i] = { contours[i].points, contours[i].aabb };
|
||||
check.write[i].update_aabb();
|
||||
}
|
||||
for (i = 0; i < check.size(); i++) {
|
||||
for (j = 0; j < (int)check.size(); j++) {
|
||||
if (i == j)
|
||||
continue;
|
||||
check[i].intersects(&check[j]);
|
||||
}
|
||||
}
|
||||
for (i = 0; i < (int)check.size(); i++) {
|
||||
polygon_queue.push_back(check[i]);
|
||||
#if 0
|
||||
polygon_output.push_back(check[i]);
|
||||
#endif
|
||||
}
|
||||
#if 0
|
||||
for (i = 0; i < (int)contours.size(); i++)
|
||||
polygon_queue.push_back(
|
||||
{ contours[i].points, contours[i].aabb });
|
||||
#endif
|
||||
{
|
||||
List<struct Lot::polygon>::Element *e = polygon_queue.front();
|
||||
while (e) {
|
||||
struct Lot::polygon item = e->get();
|
||||
print_line("queue: " + itos(polygon_queue.size()));
|
||||
polygon_queue.pop_front();
|
||||
float area = item.area();
|
||||
if (area > 120.0f * 120.0f &&
|
||||
item.aabb.size.x > 10.0f &&
|
||||
item.aabb.size.z > 10.0f) {
|
||||
std::pair<struct Lot::polygon,
|
||||
struct Lot::polygon>
|
||||
polys = item.split();
|
||||
if (polys.first.area() < 10.0f ||
|
||||
polys.second.area() < 10.0f) {
|
||||
polygon_output.push_back(item);
|
||||
} else {
|
||||
polygon_queue.push_back(polys.first);
|
||||
polygon_queue.push_back(polys.second);
|
||||
}
|
||||
} else
|
||||
polygon_output.push_back(item);
|
||||
e = polygon_queue.front();
|
||||
}
|
||||
e = polygon_output.front();
|
||||
while (e) {
|
||||
flecs::entity lot_e = BaseData::get_singleton()
|
||||
->get()
|
||||
.entity()
|
||||
.child_of(base_e);
|
||||
lot_e.set<Lot>({ e->get() });
|
||||
e = e->next();
|
||||
}
|
||||
}
|
||||
BaseData::get_singleton()->get().query_builder<Lot>().build().each(
|
||||
[&](flecs::entity e, Lot &lot) { lot.polygon.update_aabb(); });
|
||||
BaseData::get_singleton()->get().query_builder<Lot>().build().each(
|
||||
[&](flecs::entity e, Lot &lot) {
|
||||
BaseData::get_singleton()
|
||||
->get()
|
||||
.query_builder<Lot>()
|
||||
.build()
|
||||
.each([&](flecs::entity we, Lot &wlot) {
|
||||
if (e != we) {
|
||||
assert(!lot.polygon.intersects(
|
||||
&wlot.polygon));
|
||||
}
|
||||
});
|
||||
});
|
||||
Lot::pack();
|
||||
}
|
||||
|
||||
void Contours::debug()
|
||||
@@ -155,124 +223,102 @@ void Contours::debug()
|
||||
}
|
||||
}
|
||||
dbg->end();
|
||||
flecs::entity base_e = BaseData::get_singleton()->get().lookup("lots");
|
||||
assert(base_e.is_valid());
|
||||
flecs::query<Lot> query = BaseData::get_singleton()
|
||||
->get()
|
||||
.query_builder<Lot>()
|
||||
.with(flecs::ChildOf, base_e)
|
||||
.build();
|
||||
dbg->begin(Mesh::PRIMITIVE_LINES);
|
||||
dbg->set_color(Color(1, 1, 0.4f, 1));
|
||||
for (i = 0; i < (int)polygons.size(); i++) {
|
||||
for (j = 0; j < (int)polygons[i].points.size(); j++) {
|
||||
dbg->add_vertex(polygons[i].points[j] +
|
||||
query.each([&](flecs::entity e, const Lot &lot) {
|
||||
for (j = 0; j < (int)lot.polygon.points.size(); j++) {
|
||||
dbg->add_vertex(lot.polygon.points[j] +
|
||||
Vector3(0, 2, 0));
|
||||
dbg->add_vertex(
|
||||
polygons[i].points[(j + 1) %
|
||||
polygons[i].points.size()] +
|
||||
lot.polygon.points[(j + 1) %
|
||||
lot.polygon.points.size()] +
|
||||
Vector3(0, 2, 0));
|
||||
List<Pair<AABB, String> > lot_data;
|
||||
Lot::get_lot_data(e, &lot_data);
|
||||
List<Pair<AABB, String> >::Element *me =
|
||||
lot_data.front();
|
||||
while (me) {
|
||||
const Pair<AABB, String> &data = me->get();
|
||||
dbg->add_vertex(data.first.get_center());
|
||||
dbg->add_vertex(data.first.get_center() +
|
||||
Vector3(0, 50, 0));
|
||||
me = me->next();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
dbg->end();
|
||||
dbg->begin(Mesh::PRIMITIVE_LINES);
|
||||
dbg->set_color(Color(1, 1, 0.3, 1));
|
||||
query.each([&](flecs::entity e, const Lot &lot) {
|
||||
for (i = 0; i < lot.polygon.intersections.size(); i++) {
|
||||
for (j = 0; j < lot.polygon.intersections[i].size();
|
||||
j++) {
|
||||
int i0 = j;
|
||||
int i1 = (j + 1) %
|
||||
lot.polygon.intersections.size();
|
||||
Vector2 p0 = lot.polygon.intersections[i][i0];
|
||||
Vector2 p1 = lot.polygon.intersections[i][i1];
|
||||
dbg->add_vertex(Vector3(p0.x, 50, p0.y));
|
||||
dbg->add_vertex(Vector3(p1.x, 50, p1.y));
|
||||
}
|
||||
assert(false);
|
||||
}
|
||||
});
|
||||
dbg->end();
|
||||
dbg->begin(Mesh::PRIMITIVE_LINES);
|
||||
dbg->set_color(Color(0.8f, 0.5f, 0.9f, 1));
|
||||
query.each([&](flecs::entity e, const Lot &lot) {
|
||||
Vector<Pair<Rect2, String> > buildings;
|
||||
Lot::get_lot_buildings(e, &buildings);
|
||||
Vector<Vector<Vector2> > polys = Lot::get_lot_polygons(e);
|
||||
for (i = 0; i < (int)buildings.size(); i++) {
|
||||
const Rect2 r = buildings[i].first;
|
||||
Vector2 mp0 = r.position;
|
||||
Vector2 mp1 = r.position + Vector2(r.size.x, 0);
|
||||
Vector2 mp2 = r.position + r.size;
|
||||
Vector2 mp3 = r.position + Vector2(0, r.size.y);
|
||||
Vector2 rect[] = { mp0, mp1, mp2, mp3 };
|
||||
Vector2 c = r.get_center();
|
||||
dbg->set_color(Color(0.3f, 0.1f, 0.9f, 1));
|
||||
for (j = 0; j < 4; j++) {
|
||||
int i0 = j;
|
||||
int i1 = (j + 1) % 4;
|
||||
Vector3 p0 = Vector3(rect[i0].x, 0, rect[i0].y);
|
||||
Vector3 p1 = Vector3(rect[i1].x, 0, rect[i1].y);
|
||||
dbg->add_vertex(p0);
|
||||
dbg->add_vertex(p1);
|
||||
dbg->add_vertex(p0 + Vector3(0, -10, 0));
|
||||
dbg->add_vertex(p0 + Vector3(0, +10, 0));
|
||||
}
|
||||
#if 0
|
||||
dbg->set_color(Color(0.1f, 0.1f, 1.0f, 1));
|
||||
dbg->add_vertex(Vector3(c.x, 0, c.y));
|
||||
dbg->add_vertex(lot.polygon.points[0]);
|
||||
#endif
|
||||
dbg->set_color(Color(0.3f, 0.1f, 0.9f, 1));
|
||||
assert(polys[i].size() > 0);
|
||||
for (j = 0; j < (int)polys[i].size(); j++) {
|
||||
int i0 = j;
|
||||
int i1 = (j + 1) % (int)polys[i].size();
|
||||
Vector3 p0 = Vector3(polys[i][i0].x, 100,
|
||||
polys[i][i0].y);
|
||||
Vector3 p1 = Vector3(polys[i][i1].x, 100,
|
||||
polys[i][i1].y);
|
||||
dbg->add_vertex(p0);
|
||||
dbg->add_vertex(p1);
|
||||
}
|
||||
dbg->set_color(Color(1.0f, 0.1f, 0.1f, 1));
|
||||
dbg->add_vertex(Vector3(c.x, 0, c.y));
|
||||
dbg->add_vertex(
|
||||
Vector3(polys[i][0].x, 100, polys[i][0].y));
|
||||
}
|
||||
});
|
||||
dbg->end();
|
||||
}
|
||||
|
||||
std::pair<struct Contours::polygon, struct Contours::polygon>
|
||||
Contours::polygon::split() const
|
||||
{
|
||||
int i, j;
|
||||
float split_polygons_area = 0.0f;
|
||||
float split_polygons_area_min = 0.0f;
|
||||
std::pair<struct Contours::polygon, struct Contours::polygon>
|
||||
split_polygons;
|
||||
std::vector<int> edges;
|
||||
for (i = 0; i < (int)points.size(); i++) {
|
||||
Vector3 p0 = points[i];
|
||||
Vector3 p1 = points[(i + 1) % points.size()];
|
||||
if (p0.distance_squared_to(p1) > 100 * 100)
|
||||
edges.push_back(i);
|
||||
}
|
||||
if (edges.size() == 0) {
|
||||
for (i = 0; i < (int)points.size(); i++) {
|
||||
Vector3 p0 = points[i];
|
||||
Vector3 p1 = points[(i + 1) % points.size()];
|
||||
edges.push_back(i);
|
||||
}
|
||||
}
|
||||
for (i = 0; i < (int)edges.size(); i++) {
|
||||
Vector3 p0 = points[edges[i]];
|
||||
Vector3 p1 = points[(edges[i] + 1) % points.size()];
|
||||
Transform xf =
|
||||
Transform(Basis(), p0).looking_at(p1, Vector3(0, 1, 0));
|
||||
AABB base;
|
||||
base.position = xf.xform_inv(p0);
|
||||
base.expand_to(xf.xform_inv(p1));
|
||||
for (j = 0; j < (int)points.size(); j++)
|
||||
base.expand_to(xf.xform_inv(points[j]));
|
||||
Vector3 mpos0, mpos1;
|
||||
if (base.size.x > base.size.z) {
|
||||
mpos0 = base.position +
|
||||
Vector3(base.size.x, 0, 0) * 0.5f;
|
||||
mpos1 = mpos0 + Vector3(0, 0, base.size.z);
|
||||
mpos0 = xf.xform(mpos0);
|
||||
mpos1 = xf.xform(mpos1);
|
||||
} else {
|
||||
mpos0 = base.position +
|
||||
Vector3(0, 0, base.size.z) * 0.5f;
|
||||
mpos1 = mpos0 + Vector3(base.size.x, 0, 0);
|
||||
mpos0 = xf.xform(mpos0);
|
||||
mpos1 = xf.xform(mpos1);
|
||||
}
|
||||
mpos0.y = 0;
|
||||
mpos1.y == 0;
|
||||
/* mpos0 is at start of cut */
|
||||
|
||||
Vector3 n =
|
||||
(mpos1 - mpos0).cross(Vector3(0, 1, 0)).normalized();
|
||||
Plane pl1(mpos0 - n * 1.5f, n);
|
||||
Plane pl2(mpos0 + n * 1.5f, -n);
|
||||
Vector<Vector3> pdata;
|
||||
pdata.resize(points.size());
|
||||
memcpy(pdata.ptrw(), points.data(),
|
||||
points.size() * sizeof(Vector3));
|
||||
struct polygon poly1, poly2;
|
||||
Vector<Vector3> rpdata = Geometry::clip_polygon(pdata, pl1);
|
||||
poly1.points.resize(rpdata.size());
|
||||
memcpy(poly1.points.data(), rpdata.ptr(),
|
||||
rpdata.size() * sizeof(Vector3));
|
||||
poly1.update_aabb();
|
||||
rpdata = Geometry::clip_polygon(pdata, pl2);
|
||||
poly2.points.resize(rpdata.size());
|
||||
memcpy(poly2.points.data(), rpdata.ptr(),
|
||||
rpdata.size() * sizeof(Vector3));
|
||||
poly2.update_aabb();
|
||||
float area1 = poly1.area();
|
||||
float area2 = poly2.area();
|
||||
if (area1 <= 4.0f || area2 <= 4.0f)
|
||||
continue;
|
||||
float area_min = MIN(area1, area2);
|
||||
float area = area1 + area2;
|
||||
if (split_polygons_area_min < area_min &&
|
||||
split_polygons_area < area) {
|
||||
split_polygons = { poly1, poly2 };
|
||||
split_polygons_area_min = area_min;
|
||||
split_polygons_area = area;
|
||||
}
|
||||
}
|
||||
return split_polygons;
|
||||
}
|
||||
|
||||
int Contours::polygon::longest_edge() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Contours::polygon::update_aabb()
|
||||
{
|
||||
aabb = AABB();
|
||||
int i;
|
||||
for (i = 0; i < (int)points.size(); i++) {
|
||||
if (aabb.is_equal_approx(AABB()))
|
||||
aabb.position = points[i];
|
||||
else
|
||||
aabb.expand_to(points[i]);
|
||||
}
|
||||
}
|
||||
|
||||
float Contours::polygon::area() const
|
||||
{
|
||||
return Geometry::find_polygon_area(points.data(), points.size());
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#ifndef CONTOURS_H_
|
||||
#define CONTOURS_H_
|
||||
#include <vector>
|
||||
#include "road_lot.h"
|
||||
|
||||
class ImmediateGeometry;
|
||||
struct Contours {
|
||||
@@ -14,20 +15,11 @@ struct Contours {
|
||||
std::vector<Vector3> points;
|
||||
AABB aabb;
|
||||
};
|
||||
struct polygon {
|
||||
std::vector<Vector3> points;
|
||||
AABB aabb;
|
||||
std::pair<struct polygon, struct polygon> split() const;
|
||||
float area() const;
|
||||
int longest_edge() const;
|
||||
void update_aabb();
|
||||
};
|
||||
void build();
|
||||
ImmediateGeometry *dbg;
|
||||
Ref<SpatialMaterial> imm_mat;
|
||||
std::vector<std::vector<struct wedge *> > wedge_contours;
|
||||
std::vector<struct main_contour> contours;
|
||||
std::vector<struct polygon> polygons;
|
||||
static Contours *singleton;
|
||||
static Contours *get_singleton();
|
||||
Contours();
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
#ifndef ROAD_LINES_DATA_H
|
||||
#define ROAD_LINES_DATA_H
|
||||
#include <cassert>
|
||||
#include <unordered_map>
|
||||
#include <core/io/json.h>
|
||||
#include <scene/resources/curve.h>
|
||||
#include "callable.h"
|
||||
class ImmediateGeometry;
|
||||
class RoadLinesData {
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "buildings_data.h"
|
||||
#include "contours.h"
|
||||
#include "wedge.h"
|
||||
#include "road_lot.h"
|
||||
#include "road_processing.h"
|
||||
|
||||
class DebugGeo : public ImmediateGeometry {
|
||||
@@ -140,8 +141,9 @@ struct RoadLinesProcessing {
|
||||
else
|
||||
BuildingsData::get_singleton()->add_scene_item(b.id,
|
||||
b.key);
|
||||
print_line("created building: " + b.key);
|
||||
print_line("created building: " + b.key + " " + b.id);
|
||||
print_line("at: " + (b.xform.origin.operator String()));
|
||||
print_line("created ok");
|
||||
}
|
||||
int create_sideroads(const String &line_key, int edge_no,
|
||||
const RoadLinesData::road_edge &edge,
|
||||
@@ -205,6 +207,7 @@ out2:;
|
||||
}
|
||||
return structures_generated;
|
||||
}
|
||||
#if 0
|
||||
int
|
||||
create_line_building(const String &line_key, int edge_id,
|
||||
const Transform &xform,
|
||||
@@ -245,6 +248,7 @@ out2:;
|
||||
}
|
||||
return structures_generated;
|
||||
}
|
||||
#endif
|
||||
int create_lots(const String &line_key, int edge_no,
|
||||
const RoadLinesData::road_edge &edge, const Vector3 &p0,
|
||||
const Vector3 &p1, const Vector3 &dir)
|
||||
@@ -841,6 +845,155 @@ out_skip_end:;
|
||||
}
|
||||
e = e->next();
|
||||
}
|
||||
#define GENERATE_STRUCTURES
|
||||
#ifdef GENERATE_STRUCTURES
|
||||
BaseData::get_singleton()
|
||||
->get()
|
||||
.query_builder<Lot>()
|
||||
.build()
|
||||
.each([&](flecs::entity e, Lot &lot) {
|
||||
BaseData::get_singleton()
|
||||
->get()
|
||||
.query_builder<Lot>()
|
||||
.build()
|
||||
.each([&](flecs::entity we, Lot &wlot) {
|
||||
if (e != we) {
|
||||
lot.polygon
|
||||
.update_aabb();
|
||||
wlot.polygon
|
||||
.update_aabb();
|
||||
if (lot.polygon.aabb
|
||||
.size
|
||||
.length() >
|
||||
100000.0f *
|
||||
1000000.0f)
|
||||
e.destruct();
|
||||
else if (wlot.polygon
|
||||
.aabb
|
||||
.size
|
||||
.length() >
|
||||
100000.0f *
|
||||
1000000.0f)
|
||||
we.destruct();
|
||||
else if (lot.polygon.intersects(
|
||||
&wlot.polygon)) {
|
||||
print_line(
|
||||
"polygon intersection:");
|
||||
lot.polygon
|
||||
.dump();
|
||||
wlot.polygon
|
||||
.dump();
|
||||
if (lot.polygon
|
||||
.area() >
|
||||
wlot.polygon
|
||||
.area())
|
||||
we.destruct();
|
||||
else
|
||||
e.destruct();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
BaseData::get_singleton()
|
||||
->get()
|
||||
.query_builder<Lot>()
|
||||
.build()
|
||||
.each([&](flecs::entity e, const Lot &lot) {
|
||||
List<Pair<AABB, String> > lot_data;
|
||||
Lot::get_lot_data(e, &lot_data);
|
||||
List<Pair<AABB, String> >::Element *lot_e =
|
||||
lot_data.front();
|
||||
int ccount = 0;
|
||||
while (lot_e) {
|
||||
Pair<AABB, String> data = lot_e->get();
|
||||
Vector3 center = data.first.position;
|
||||
center += Vector3(data.first.size.x, 0,
|
||||
data.first.size.z) *
|
||||
0.5f;
|
||||
Transform xform(Basis(), center);
|
||||
Vector3 m = xform.origin;
|
||||
m.y = 0;
|
||||
print_line("Position: " +
|
||||
m.operator String());
|
||||
if (m.length() < 1.0f) {
|
||||
int j;
|
||||
print_line("id: " +
|
||||
data.second);
|
||||
print_line("aabb: " +
|
||||
data.first.
|
||||
operator String());
|
||||
for (j = 0;
|
||||
j <
|
||||
lot.polygon.points.size();
|
||||
j++)
|
||||
print_line(
|
||||
"polygon: " +
|
||||
itos(j) + " " +
|
||||
lot.polygon
|
||||
.points[j]
|
||||
.
|
||||
operator String());
|
||||
}
|
||||
lot_e = lot_e->next();
|
||||
}
|
||||
});
|
||||
BaseData::get_singleton()
|
||||
->get()
|
||||
.query_builder<Lot>()
|
||||
.build()
|
||||
.each([&](flecs::entity e, const Lot &lot) {
|
||||
List<Pair<AABB, String> > lot_data;
|
||||
List<Transform> lot_xform;
|
||||
Lot::get_lot_data(e, &lot_data);
|
||||
Lot::get_lot_rotations(e, &lot_xform);
|
||||
List<Pair<AABB, String> >::Element *lot_e =
|
||||
lot_data.front();
|
||||
List<Transform>::Element *lotx_e =
|
||||
lot_xform.front();
|
||||
int ccount = 0;
|
||||
while (lot_e) {
|
||||
Pair<AABB, String> data = lot_e->get();
|
||||
String key = "road__lot__" +
|
||||
String(e.path()) + "_" +
|
||||
itos(ccount);
|
||||
key = key.replace("#", "_");
|
||||
BuildingsData::building b;
|
||||
b.key = key;
|
||||
b.id = data.second;
|
||||
b.generated = true;
|
||||
b.line_name = "";
|
||||
// TODO: add lot to BuildingsData:: building struct;
|
||||
// TODO use rotation with building packing
|
||||
Vector3 center = data.first.position;
|
||||
center += Vector3(data.first.size.x, 0,
|
||||
data.first.size.z) *
|
||||
0.5f;
|
||||
Transform rot = lotx_e->get();
|
||||
Transform xform(rot.basis, center);
|
||||
Vector3 m = xform.origin;
|
||||
m.y = 0;
|
||||
print_line("Position: " +
|
||||
m.operator String());
|
||||
assert(!m.is_equal_approx(Vector3()));
|
||||
b.key_hash = b.key.hash64();
|
||||
b.pattern_id = 0;
|
||||
b.xform = xform;
|
||||
// TODO: fix working time for building
|
||||
b.worktime[0] = 0;
|
||||
b.worktime[1] = 23;
|
||||
create_building_structure(b);
|
||||
print_line(
|
||||
"building: " + key + ": " +
|
||||
data.first.operator String());
|
||||
print_line(
|
||||
"center: " +
|
||||
xform.origin.operator String());
|
||||
lot_e = lot_e->next();
|
||||
lotx_e = lotx_e->next();
|
||||
ccount++;
|
||||
}
|
||||
});
|
||||
#endif
|
||||
print_line("structures generated: " +
|
||||
itos(structures_generated));
|
||||
}
|
||||
|
||||
@@ -14,4 +14,4 @@ env.add_source_files(env.stream_building_sources, "*.cpp")
|
||||
|
||||
lib = env.add_library("rtree", env.stream_building_sources)
|
||||
env.Prepend(LIBS=[lib])
|
||||
env.Prepend(CPPPATH=["..", ".", "../ui"])
|
||||
env.Prepend(CPPPATH=["../ui", ".."])
|
||||
|
||||
@@ -4,7 +4,9 @@
|
||||
#include <core/list.h>
|
||||
#include <core/hashfuncs.h>
|
||||
#include <core/hash_map.h>
|
||||
#include "world_editor.h"
|
||||
#include "building_layout_graph.h"
|
||||
#include "grid_misc.h"
|
||||
#include "region_tree.h"
|
||||
|
||||
#define SHRINK_RIGHT (1 << 0)
|
||||
|
||||
@@ -1094,4 +1094,4 @@ void BuildingLayoutGraphUI::_bind_methods()
|
||||
ClassDB::bind_method(D_METHOD("select_grid_floor_ob", "id", "button",
|
||||
"draw"),
|
||||
&BuildingLayoutGraphUI::select_grid_floor_ob);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
#include "growth_regions.h"
|
||||
@@ -1,51 +0,0 @@
|
||||
#ifndef GROWTH_REGIONS_H
|
||||
#define GROWTH_REGIONS_H
|
||||
#include <core/vector.h>
|
||||
#include <core/list.h>
|
||||
#include <core/pair.h>
|
||||
#include <core/math/vector2.h>
|
||||
#include "base_data.h"
|
||||
#include "region_rect2.h"
|
||||
#include "graph_module.h"
|
||||
struct region {
|
||||
flecs::entity_t parent;
|
||||
flecs::entity_t seed_et;
|
||||
flecs::entity_t region_et;
|
||||
RegionRect2i rect;
|
||||
int remains_area;
|
||||
bool can_grow_square;
|
||||
bool can_move;
|
||||
bool can_grow;
|
||||
bool complete;
|
||||
bool can_grow_region() const
|
||||
{
|
||||
bool ret = can_grow;
|
||||
if (remains_area <= 0)
|
||||
ret = false;
|
||||
return ret;
|
||||
}
|
||||
bool update_region_size(RegionRect2i &mrect)
|
||||
{
|
||||
bool ret = false;
|
||||
int old_area = rect.get_area();
|
||||
int new_area = mrect.get_area();
|
||||
int area_diff = new_area - old_area;
|
||||
if (area_diff > 0) {
|
||||
rect = mrect;
|
||||
remains_area -= area_diff;
|
||||
ret = true;
|
||||
}
|
||||
if (remains_area <= 0) {
|
||||
can_grow_square = false;
|
||||
can_grow = false;
|
||||
}
|
||||
flecs::log::dbg("update_region_size %d -> %d", area_diff, ret);
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
struct growth_regions {
|
||||
List<struct grow_job> job_list;
|
||||
bool complete;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user