Separating line data classes into components
This commit is contained in:
@@ -23,12 +23,22 @@ struct CLine {
|
||||
struct CLineIndex {
|
||||
struct RoadLinesData::road_line_index index;
|
||||
};
|
||||
class LinesAccessor;
|
||||
struct CLinesCommon {
|
||||
Node *debug;
|
||||
LinesAccessor *lines;
|
||||
};
|
||||
|
||||
class LinesAccessor {
|
||||
flecs::entity root_e;
|
||||
|
||||
public:
|
||||
LinesAccessor()
|
||||
{
|
||||
BaseData::get_singleton()->get().component<CLine>();
|
||||
root_e = BaseData::get_singleton()->get().entity("lines");
|
||||
root_e.set<CLinesCommon>({ nullptr, this });
|
||||
assert(root_e.is_valid());
|
||||
}
|
||||
const flecs::world &get() const
|
||||
{
|
||||
@@ -40,12 +50,14 @@ public:
|
||||
}
|
||||
template <typename F> void each(F &&func) const
|
||||
{
|
||||
get().each<F>(func);
|
||||
assert(root_e.is_valid());
|
||||
root_e.each<F>(func);
|
||||
}
|
||||
inline flecs::entity lookup(const String &key) const
|
||||
{
|
||||
assert(root_e.is_valid());
|
||||
String ename = "line:" + key;
|
||||
flecs::entity e = get().lookup(ename.ascii().ptr());
|
||||
flecs::entity e = root_e.lookup(ename.ascii().ptr());
|
||||
if (!e.is_valid())
|
||||
print_line("can't find: " + key);
|
||||
assert(e.is_valid());
|
||||
@@ -53,15 +65,18 @@ public:
|
||||
}
|
||||
inline flecs::entity lookup_create(const String &key) const
|
||||
{
|
||||
assert(root_e.is_valid());
|
||||
String ename = "line:" + key;
|
||||
flecs::entity e = get().entity(ename.ascii().ptr());
|
||||
flecs::entity e =
|
||||
get().entity(ename.ascii().ptr()).child_of(root_e);
|
||||
assert(e.is_valid());
|
||||
return e;
|
||||
}
|
||||
bool has_entity(const String &key) const
|
||||
{
|
||||
assert(root_e.is_valid());
|
||||
String ename = "line:" + key;
|
||||
flecs::entity e = get().lookup(ename.ascii().ptr());
|
||||
flecs::entity e = root_e.lookup(ename.ascii().ptr());
|
||||
return e.is_valid();
|
||||
}
|
||||
inline const struct RoadLinesData::road_line &
|
||||
@@ -146,13 +161,14 @@ public:
|
||||
return cl->line;
|
||||
}
|
||||
inline const Transform &get_line_point_transform(const String &key,
|
||||
int point_index)
|
||||
int point_index) const
|
||||
{
|
||||
flecs::entity e = lookup(key);
|
||||
const struct CLine *cl = e.get<CLine>();
|
||||
return cl->line.points[point_index];
|
||||
}
|
||||
inline const Vector3 &get_line_point(const String &key, int point_index)
|
||||
inline const Vector3 &get_line_point(const String &key,
|
||||
int point_index) const
|
||||
{
|
||||
flecs::entity e = lookup(key);
|
||||
const struct CLine *cl = e.get<CLine>();
|
||||
@@ -252,14 +268,14 @@ public:
|
||||
cl->line.metadata = metadata;
|
||||
}
|
||||
|
||||
inline bool has(const String &key)
|
||||
inline bool has(const String &key) const
|
||||
{
|
||||
return has_entity(key);
|
||||
}
|
||||
void get_key_list(List<String> *keys)
|
||||
void get_key_list(List<String> *keys) const
|
||||
{
|
||||
// ugly as fuck
|
||||
get().each([keys](flecs::entity e, const CLine &cl) {
|
||||
root_e.children([keys](flecs::entity e) {
|
||||
String name(e.name());
|
||||
if (name.begins_with("line:")) {
|
||||
name = name.substr(5, -1);
|
||||
@@ -267,7 +283,7 @@ public:
|
||||
}
|
||||
});
|
||||
}
|
||||
const String &get_next(const String &key)
|
||||
const String &get_next(const String &key) const
|
||||
{
|
||||
List<String> keys;
|
||||
get_key_list(&keys);
|
||||
@@ -285,10 +301,14 @@ public:
|
||||
};
|
||||
|
||||
class IndexAccessor {
|
||||
flecs::entity root_e;
|
||||
|
||||
public:
|
||||
IndexAccessor()
|
||||
{
|
||||
BaseData::get_singleton()->get().component<CLineIndex>();
|
||||
root_e = BaseData::get_singleton()->get().entity("lines");
|
||||
assert(root_e.is_valid());
|
||||
}
|
||||
inline const struct RoadLinesData::road_line_index &
|
||||
operator[](const String &key) const
|
||||
@@ -307,12 +327,12 @@ public:
|
||||
}
|
||||
template <typename F> void each(F &&func) const
|
||||
{
|
||||
get().each<F>(func);
|
||||
root_e.each<F>(func);
|
||||
}
|
||||
inline flecs::entity lookup(const String &key) const
|
||||
{
|
||||
String ename = "line:" + key;
|
||||
flecs::entity e = get().lookup(ename.ascii().ptr());
|
||||
flecs::entity e = root_e.lookup(ename.ascii().ptr());
|
||||
if (!e.is_valid())
|
||||
print_line("can't find: " + key);
|
||||
assert(e.is_valid());
|
||||
@@ -320,8 +340,10 @@ public:
|
||||
}
|
||||
inline void clear_all_line_indices()
|
||||
{
|
||||
BaseData::get_singleton()->get_singleton()->get().each(
|
||||
[](CLineIndex &cl) { cl.index.indices.clear(); });
|
||||
root_e.children([](flecs::entity e) {
|
||||
e.get_mut<CLineIndex>()->index.indices.clear();
|
||||
e.modified<CLineIndex>();
|
||||
});
|
||||
}
|
||||
inline void clear_line_indices(const String &key)
|
||||
{
|
||||
@@ -329,6 +351,7 @@ public:
|
||||
struct CLineIndex *cl = e.get_mut<CLineIndex>();
|
||||
assert(cl);
|
||||
cl->index.indices.clear();
|
||||
e.modified<CLineIndex>();
|
||||
}
|
||||
inline void add_line_index(const String &key, int id)
|
||||
{
|
||||
@@ -341,58 +364,81 @@ public:
|
||||
flecs::entity e = lookup(key);
|
||||
struct CLineIndex *cl = e.get_mut<CLineIndex>();
|
||||
cl->index.indices.insert(cl->index.indices.begin() + index, id);
|
||||
e.modified<CLineIndex>();
|
||||
}
|
||||
inline void
|
||||
set_index(const String &key,
|
||||
const struct RoadLinesData::road_line_index &index)
|
||||
{
|
||||
flecs::entity e = lookup_create(key);
|
||||
flecs::entity e = lookup(key);
|
||||
e.set<CLineIndex>({ index });
|
||||
}
|
||||
inline flecs::entity lookup_create(const String &key) const
|
||||
{
|
||||
String ename = "line:" + key;
|
||||
flecs::entity e = get().entity(ename.ascii().ptr());
|
||||
flecs::entity e =
|
||||
get().entity(ename.ascii().ptr()).child_of(root_e);
|
||||
assert(e.is_valid());
|
||||
return e;
|
||||
}
|
||||
};
|
||||
|
||||
static LinesAccessor lines;
|
||||
static IndexAccessor indices;
|
||||
|
||||
ImmediateGeometry *RoadLinesData::debug_im = nullptr;
|
||||
static Ref<Material> debug_material;
|
||||
RoadLinesData::RoadLinesData()
|
||||
: initialized(false)
|
||||
{
|
||||
BaseData::get_singleton()->get().component<LinesAccessor>();
|
||||
flecs::entity root_e = BaseData::get_singleton()->get().entity("lines");
|
||||
assert(root_e.is_valid());
|
||||
root_e.emplace<LinesAccessor>();
|
||||
assert(root_e.has<LinesAccessor>());
|
||||
assert(root_e.get<LinesAccessor>());
|
||||
root_e.emplace<IndexAccessor>();
|
||||
assert(root_e.has<IndexAccessor>());
|
||||
assert(root_e.get<IndexAccessor>());
|
||||
load_data();
|
||||
}
|
||||
RoadLinesData *RoadLinesData::singleton = nullptr;
|
||||
const struct RoadLinesData::road_line &
|
||||
RoadLinesData::get_line(const String &key) const
|
||||
{
|
||||
return ::lines[key];
|
||||
flecs::entity root_e = BaseData::get_singleton()->get().lookup("lines");
|
||||
assert(root_e.is_valid());
|
||||
const LinesAccessor *lines = root_e.get<LinesAccessor>();
|
||||
return lines->get_line(key);
|
||||
}
|
||||
const struct RoadLinesData::road_line *
|
||||
RoadLinesData::get_line_ptr(const String &key) const
|
||||
{
|
||||
return ::lines.get_line_ptr(key);
|
||||
flecs::entity root_e = BaseData::get_singleton()->get().lookup("lines");
|
||||
assert(root_e.is_valid());
|
||||
const LinesAccessor *lines = root_e.get<LinesAccessor>();
|
||||
return lines->get_line_ptr(key);
|
||||
}
|
||||
RoadLinesData::road_edge RoadLinesData::get_line_edge(const String &key,
|
||||
int edge) const
|
||||
{
|
||||
return ::lines.get_line_ptr(key)->edges[edge];
|
||||
flecs::entity root_e = BaseData::get_singleton()->get().lookup("lines");
|
||||
assert(root_e.is_valid());
|
||||
const LinesAccessor *lines = root_e.get<LinesAccessor>();
|
||||
return lines->get_line_ptr(key)->edges[edge];
|
||||
}
|
||||
RoadLinesData::road_edge_side
|
||||
RoadLinesData::get_line_edge_left(const String &key, int edge) const
|
||||
{
|
||||
return ::lines.get_line_edge_left(key, edge);
|
||||
flecs::entity root_e = BaseData::get_singleton()->get().lookup("lines");
|
||||
assert(root_e.is_valid());
|
||||
const LinesAccessor *lines = root_e.get<LinesAccessor>();
|
||||
return lines->get_line_edge_left(key, edge);
|
||||
}
|
||||
RoadLinesData::road_edge_side
|
||||
RoadLinesData::get_line_edge_right(const String &key, int edge) const
|
||||
{
|
||||
return ::lines.get_line_edge_right(key, edge);
|
||||
flecs::entity root_e = BaseData::get_singleton()->get().lookup("lines");
|
||||
assert(root_e.is_valid());
|
||||
const LinesAccessor *lines = root_e.get<LinesAccessor>();
|
||||
return lines->get_line_edge_right(key, edge);
|
||||
}
|
||||
RoadLinesData::road_edge_side
|
||||
RoadLinesData::get_line_edge_side(const String &key, int edge, int side) const
|
||||
@@ -415,82 +461,142 @@ RoadLinesData::get_line_edge_side(const String &key, int edge, int side) const
|
||||
void RoadLinesData::set_line_edge_left(const String &key, int edge,
|
||||
road_edge_side &side)
|
||||
{
|
||||
::lines.set_line_edge_left(key, edge, side);
|
||||
assert(::lines.get_line_edge(key, edge).left.lot == side.lot);
|
||||
flecs::entity root_e = BaseData::get_singleton()->get().lookup("lines");
|
||||
assert(root_e.is_valid());
|
||||
LinesAccessor *lines = root_e.get_mut<LinesAccessor>();
|
||||
lines->set_line_edge_left(key, edge, side);
|
||||
root_e.modified<LinesAccessor>();
|
||||
assert(lines->get_line_edge(key, edge).left.lot == side.lot);
|
||||
}
|
||||
void RoadLinesData::set_line_edge_right(const String &key, int edge,
|
||||
road_edge_side &side)
|
||||
{
|
||||
::lines.set_line_edge_right(key, edge, side);
|
||||
assert(::lines.get_line_edge(key, edge).right.lot == side.lot);
|
||||
flecs::entity root_e = BaseData::get_singleton()->get().lookup("lines");
|
||||
assert(root_e.is_valid());
|
||||
LinesAccessor *lines = root_e.get_mut<LinesAccessor>();
|
||||
lines->set_line_edge_right(key, edge, side);
|
||||
root_e.modified<LinesAccessor>();
|
||||
assert(lines->get_line_edge(key, edge).right.lot == side.lot);
|
||||
}
|
||||
void RoadLinesData::set_line_edge(const String &key, int edge_id,
|
||||
const road_edge &edge)
|
||||
{
|
||||
::lines.set_line_edge(key, edge_id, edge);
|
||||
assert(::lines.get_line_edge(key, edge_id).left.lot == edge.left.lot);
|
||||
assert(::lines.get_line_edge(key, edge_id).right.lot == edge.right.lot);
|
||||
flecs::entity root_e = BaseData::get_singleton()->get().lookup("lines");
|
||||
assert(root_e.is_valid());
|
||||
LinesAccessor *lines = root_e.get_mut<LinesAccessor>();
|
||||
lines->set_line_edge(key, edge_id, edge);
|
||||
root_e.modified<LinesAccessor>();
|
||||
assert(lines->get_line_edge(key, edge_id).left.lot == edge.left.lot);
|
||||
assert(lines->get_line_edge(key, edge_id).right.lot == edge.right.lot);
|
||||
}
|
||||
int RoadLinesData::get_line_edge_count(const String &key) const
|
||||
{
|
||||
return ::lines.get_line_edge_count(key);
|
||||
flecs::entity root_e = BaseData::get_singleton()->get().lookup("lines");
|
||||
assert(root_e.is_valid());
|
||||
const LinesAccessor *lines = root_e.get<LinesAccessor>();
|
||||
return lines->get_line_edge_count(key);
|
||||
}
|
||||
const Vector3 &RoadLinesData::get_line_point(const String &key, int index) const
|
||||
{
|
||||
return ::lines.get_line_point(key, index);
|
||||
flecs::entity root_e = BaseData::get_singleton()->get().lookup("lines");
|
||||
assert(root_e.is_valid());
|
||||
const LinesAccessor *lines = root_e.get<LinesAccessor>();
|
||||
return lines->get_line_point(key, index);
|
||||
}
|
||||
const RoadLinesData::road_line &RoadLinesData::lines(const String &key) const
|
||||
{
|
||||
return ::lines[key];
|
||||
flecs::entity root_e = BaseData::get_singleton()->get().lookup("lines");
|
||||
assert(root_e.is_valid());
|
||||
const LinesAccessor *lines = root_e.get<LinesAccessor>();
|
||||
return lines->get_line(key);
|
||||
}
|
||||
const RoadLinesData::road_line_index &
|
||||
RoadLinesData::indices(const String &key) const
|
||||
{
|
||||
return ::indices[key];
|
||||
flecs::entity root_e = BaseData::get_singleton()->get().lookup("lines");
|
||||
assert(root_e.is_valid());
|
||||
IndexAccessor &indices = *root_e.get_mut<IndexAccessor>();
|
||||
return indices[key];
|
||||
}
|
||||
void RoadLinesData::set_line(const String &key, const road_line &line)
|
||||
{
|
||||
::lines.set_line(key, line);
|
||||
flecs::entity root_e = BaseData::get_singleton()->get().lookup("lines");
|
||||
assert(root_e.is_valid());
|
||||
LinesAccessor *lines = root_e.get_mut<LinesAccessor>();
|
||||
lines->set_line(key, line);
|
||||
root_e.modified<LinesAccessor>();
|
||||
}
|
||||
void RoadLinesData::update_line(const String &key)
|
||||
{
|
||||
::lines.update_line(key);
|
||||
flecs::entity root_e = BaseData::get_singleton()->get().lookup("lines");
|
||||
assert(root_e.is_valid());
|
||||
LinesAccessor *lines = root_e.get_mut<LinesAccessor>();
|
||||
lines->update_line(key);
|
||||
root_e.modified<LinesAccessor>();
|
||||
}
|
||||
const Transform &RoadLinesData::get_line_point_transform(const String &key,
|
||||
int index) const
|
||||
{
|
||||
return ::lines.get_line_point_transform(key, index);
|
||||
flecs::entity root_e = BaseData::get_singleton()->get().lookup("lines");
|
||||
assert(root_e.is_valid());
|
||||
const LinesAccessor *lines = root_e.get<LinesAccessor>();
|
||||
return lines->get_line_point_transform(key, index);
|
||||
}
|
||||
bool RoadLinesData::has_line(const String &key)
|
||||
bool RoadLinesData::has_line(const String &key) const
|
||||
{
|
||||
return ::lines.has(key);
|
||||
flecs::entity root_e = BaseData::get_singleton()->get().lookup("lines");
|
||||
assert(root_e.is_valid());
|
||||
const LinesAccessor *lines = root_e.get<LinesAccessor>();
|
||||
return lines->has(key);
|
||||
}
|
||||
void RoadLinesData::insert_line_point(const String &key, int index,
|
||||
const Transform &xform)
|
||||
{
|
||||
::lines.insert_line_point(key, index, xform);
|
||||
flecs::entity root_e = BaseData::get_singleton()->get().lookup("lines");
|
||||
assert(root_e.is_valid());
|
||||
LinesAccessor *lines = root_e.get_mut<LinesAccessor>();
|
||||
lines->insert_line_point(key, index, xform);
|
||||
root_e.modified<LinesAccessor>();
|
||||
}
|
||||
void RoadLinesData::erase_line_point(const String &key, int index)
|
||||
{
|
||||
::lines.erase_line_point(key, index);
|
||||
flecs::entity root_e = BaseData::get_singleton()->get().lookup("lines");
|
||||
assert(root_e.is_valid());
|
||||
LinesAccessor *lines = root_e.get_mut<LinesAccessor>();
|
||||
lines->erase_line_point(key, index);
|
||||
root_e.modified<LinesAccessor>();
|
||||
}
|
||||
void RoadLinesData::set_line_point_position(const String &key, int index,
|
||||
const Vector3 &position)
|
||||
{
|
||||
::lines.set_line_point_position(key, index, position);
|
||||
flecs::entity root_e = BaseData::get_singleton()->get().lookup("lines");
|
||||
assert(root_e.is_valid());
|
||||
LinesAccessor *lines = root_e.get_mut<LinesAccessor>();
|
||||
lines->set_line_point_position(key, index, position);
|
||||
root_e.modified<LinesAccessor>();
|
||||
}
|
||||
void RoadLinesData::clear_all_line_indices()
|
||||
{
|
||||
::indices.clear_all_line_indices();
|
||||
flecs::entity root_e = BaseData::get_singleton()->get().lookup("lines");
|
||||
assert(root_e.is_valid());
|
||||
IndexAccessor &indices = *root_e.get_mut<IndexAccessor>();
|
||||
indices.clear_all_line_indices();
|
||||
}
|
||||
void RoadLinesData::clear_line_indices(const String &key)
|
||||
{
|
||||
::indices.clear_line_indices(key);
|
||||
flecs::entity root_e = BaseData::get_singleton()->get().lookup("lines");
|
||||
assert(root_e.is_valid());
|
||||
IndexAccessor &indices = *root_e.get_mut<IndexAccessor>();
|
||||
indices.clear_line_indices(key);
|
||||
}
|
||||
void RoadLinesData::set_line_metadata(const String &key,
|
||||
const Dictionary &metadata)
|
||||
{
|
||||
::lines.set_line_metadata(key, metadata);
|
||||
flecs::entity root_e = BaseData::get_singleton()->get().lookup("lines");
|
||||
assert(root_e.is_valid());
|
||||
LinesAccessor *lines = root_e.get_mut<LinesAccessor>();
|
||||
lines->set_line_metadata(key, metadata);
|
||||
root_e.modified<LinesAccessor>();
|
||||
}
|
||||
RoadLinesData *RoadLinesData::get_singleton()
|
||||
{
|
||||
@@ -520,7 +626,10 @@ String RoadLinesData::get_road_lines_path()
|
||||
void RoadLinesData::get_road_lines_key_list(List<String> *keys)
|
||||
{
|
||||
List<String> line_keys;
|
||||
::lines.get_key_list(&line_keys);
|
||||
flecs::entity root_e = BaseData::get_singleton()->get().lookup("lines");
|
||||
assert(root_e.is_valid());
|
||||
const LinesAccessor *lines = root_e.get<LinesAccessor>();
|
||||
lines->get_key_list(&line_keys);
|
||||
List<String>::Element *e = line_keys.front();
|
||||
keys->clear();
|
||||
while (e) {
|
||||
@@ -533,21 +642,35 @@ void RoadLinesData::get_road_lines_key_list(List<String> *keys)
|
||||
void RoadLinesData::get_lines_key_list(List<String> *keys)
|
||||
{
|
||||
assert(initialized);
|
||||
::lines.get_key_list(keys);
|
||||
flecs::entity root_e = BaseData::get_singleton()->get().lookup("lines");
|
||||
assert(root_e.is_valid());
|
||||
const LinesAccessor *lines = root_e.get<LinesAccessor>();
|
||||
lines->get_key_list(keys);
|
||||
assert(!keys->empty());
|
||||
}
|
||||
const String &RoadLinesData::get_next_line(const String &key)
|
||||
const String &RoadLinesData::get_next_line(const String &key) const
|
||||
{
|
||||
return ::lines.get_next(key);
|
||||
flecs::entity root_e = BaseData::get_singleton()->get().lookup("lines");
|
||||
assert(root_e.is_valid());
|
||||
const LinesAccessor *lines = root_e.get<LinesAccessor>();
|
||||
return lines->get_next(key);
|
||||
}
|
||||
void RoadLinesData::erase_line(const String &key)
|
||||
{
|
||||
return ::lines.erase(key);
|
||||
flecs::entity root_e = BaseData::get_singleton()->get().lookup("lines");
|
||||
assert(root_e.is_valid());
|
||||
LinesAccessor *lines = root_e.get_mut<LinesAccessor>();
|
||||
lines->erase(key);
|
||||
root_e.modified<LinesAccessor>();
|
||||
}
|
||||
void RoadLinesData::load_data()
|
||||
{
|
||||
int i;
|
||||
ConfigFile config;
|
||||
flecs::entity root_e = BaseData::get_singleton()->get().lookup("lines");
|
||||
assert(root_e.is_valid());
|
||||
IndexAccessor &line_indices = *root_e.get_mut<IndexAccessor>();
|
||||
const LinesAccessor *lines = root_e.get<LinesAccessor>();
|
||||
Error result = config.load("res://config/stream.conf");
|
||||
ERR_FAIL_COND_MSG(result != OK, "Failed to load config");
|
||||
assert(result == OK);
|
||||
@@ -592,12 +715,12 @@ void RoadLinesData::load_data()
|
||||
rline.lanes = lanes;
|
||||
set_line(key, rline);
|
||||
RoadLinesData::road_line_index index;
|
||||
::indices.set_index(key, index);
|
||||
line_indices.set_index(key, index);
|
||||
e = e->next();
|
||||
}
|
||||
{
|
||||
List<String> tkeys;
|
||||
::lines.get_key_list(&tkeys);
|
||||
lines->get_key_list(&tkeys);
|
||||
assert(!tkeys.empty());
|
||||
}
|
||||
update_line_edges();
|
||||
@@ -615,17 +738,23 @@ void RoadLinesData::save_data()
|
||||
FileAccess::get_file_as_string(road_lines_path);
|
||||
Dictionary output;
|
||||
List<String> keys;
|
||||
::lines.get_key_list(&keys);
|
||||
flecs::entity root_e = BaseData::get_singleton()->get().lookup("lines");
|
||||
assert(root_e.is_valid());
|
||||
const LinesAccessor *lines = root_e.get<LinesAccessor>();
|
||||
lines->get_key_list(&keys);
|
||||
List<String>::Element *e = keys.front();
|
||||
while (e) {
|
||||
Dictionary pvalues;
|
||||
Array points, edges, indices;
|
||||
points.resize(lines(e->get()).points.size());
|
||||
edges.resize(lines(e->get()).edges.size());
|
||||
for (i = 0; i < (int)lines(e->get()).points.size(); i++)
|
||||
points[i] = to_string(lines(e->get()).points[i]);
|
||||
for (i = 0; i < (int)lines(e->get()).edges.size(); i++)
|
||||
edges[i] = lines(e->get()).edges[i].to_dict();
|
||||
points.resize(lines->get_line(e->get()).points.size());
|
||||
edges.resize(lines->get_line(e->get()).edges.size());
|
||||
for (i = 0; i < (int)lines->get_line(e->get()).points.size();
|
||||
i++)
|
||||
points[i] =
|
||||
to_string(lines->get_line(e->get()).points[i]);
|
||||
for (i = 0; i < (int)lines->get_line(e->get()).edges.size();
|
||||
i++)
|
||||
edges[i] = lines->get_line(e->get()).edges[i].to_dict();
|
||||
indices.resize(this->indices(e->get()).indices.size());
|
||||
for (i = 0; i < (int)this->indices(e->get()).indices.size();
|
||||
i++)
|
||||
@@ -633,9 +762,9 @@ void RoadLinesData::save_data()
|
||||
pvalues["points"] = points;
|
||||
pvalues["edges"] = edges;
|
||||
// pvalues["indices"] = indices;
|
||||
pvalues["metadata"] = lines(e->get()).metadata;
|
||||
pvalues["lanes"] = lines(e->get()).lanes;
|
||||
pvalues["pattern"] = ::lines[e->get()].pattern;
|
||||
pvalues["metadata"] = lines->get_line(e->get()).metadata;
|
||||
pvalues["lanes"] = lines->get_line(e->get()).lanes;
|
||||
pvalues["pattern"] = lines->get_line(e->get()).pattern;
|
||||
output[e->get()] = pvalues;
|
||||
e = e->next();
|
||||
}
|
||||
@@ -701,9 +830,13 @@ void RoadLinesData::road_lines_curve_index(
|
||||
std::vector<Vector3> &road_lines_nodes)
|
||||
{
|
||||
int i, j;
|
||||
::indices.clear_line_indices(key);
|
||||
for (i = 0; i < (int)::lines.get_line_points_count(key); i++) {
|
||||
Vector3 pt = ::lines.get_line_point_position(key, i);
|
||||
flecs::entity root_e = BaseData::get_singleton()->get().lookup("lines");
|
||||
assert(root_e.is_valid());
|
||||
IndexAccessor &indices = *root_e.get_mut<IndexAccessor>();
|
||||
indices.clear_line_indices(key);
|
||||
const LinesAccessor *lines = root_e.get<LinesAccessor>();
|
||||
for (i = 0; i < (int)lines->get_line_points_count(key); i++) {
|
||||
Vector3 pt = lines->get_line_point_position(key, i);
|
||||
int pt_hash = road_lines_hash(pt);
|
||||
if (road_lines_nodes_hash.find(pt_hash) !=
|
||||
road_lines_nodes_hash.end()) {
|
||||
@@ -731,7 +864,7 @@ void RoadLinesData::road_lines_curve_index(
|
||||
road_lines_nodes.begin(), road_lines_nodes.end(), pt);
|
||||
assert(it != road_lines_nodes.end());
|
||||
int index = it - road_lines_nodes.begin();
|
||||
::indices.add_line_index(key, index);
|
||||
indices.add_line_index(key, index);
|
||||
}
|
||||
}
|
||||
void RoadLinesData::index_lines(
|
||||
@@ -765,7 +898,10 @@ void RoadLinesData::create_segments(const String &road,
|
||||
std::vector<int> &segments)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < (int)::indices[road].indices.size() - 1; i++) {
|
||||
flecs::entity root_e = BaseData::get_singleton()->get().lookup("lines");
|
||||
assert(root_e.is_valid());
|
||||
const IndexAccessor &indices = *root_e.get<IndexAccessor>();
|
||||
for (i = 0; i < (int)indices[road].indices.size() - 1; i++) {
|
||||
segments.push_back(i);
|
||||
segments.push_back(i + 1);
|
||||
}
|
||||
@@ -777,6 +913,9 @@ void RoadLinesData::insert_close_points(std::vector<Vector3> &road_lines_nodes,
|
||||
{
|
||||
int i;
|
||||
List<String> keys;
|
||||
flecs::entity root_e = BaseData::get_singleton()->get().lookup("lines");
|
||||
assert(root_e.is_valid());
|
||||
IndexAccessor &indices = *root_e.get_mut<IndexAccessor>();
|
||||
get_road_lines_key_list(&keys);
|
||||
List<String>::Element *e = keys.front();
|
||||
for (i = 0; i < (int)road_lines_nodes.size(); i++) {
|
||||
@@ -816,8 +955,8 @@ void RoadLinesData::insert_close_points(std::vector<Vector3> &road_lines_nodes,
|
||||
distance_squared) {
|
||||
/* split segment and replace road
|
||||
point with a point on segment */
|
||||
::indices.insert_line_index(rkey, idx,
|
||||
idx3);
|
||||
indices.insert_line_index(rkey, idx,
|
||||
idx3);
|
||||
road_lines_nodes[idx3] = closest;
|
||||
}
|
||||
}
|
||||
@@ -829,6 +968,9 @@ void RoadLinesData::update_road_lines_nodes(
|
||||
std::vector<Vector3> &road_lines_nodes)
|
||||
{
|
||||
List<String> keys;
|
||||
flecs::entity root_e = BaseData::get_singleton()->get().lookup("lines");
|
||||
assert(root_e.is_valid());
|
||||
IndexAccessor &indices = *root_e.get_mut<IndexAccessor>();
|
||||
|
||||
get_road_lines_key_list(&keys);
|
||||
std::unordered_map<uint32_t, std::tuple<String, String> > kcmp;
|
||||
@@ -862,12 +1004,12 @@ void RoadLinesData::update_road_lines_nodes(
|
||||
std::tuple<String, String> data = kcmp[it->first];
|
||||
const String &k = std::get<0>(data);
|
||||
const String &r = std::get<1>(data);
|
||||
if (::indices[k].indices.size() < 2)
|
||||
if (indices[k].indices.size() < 2)
|
||||
continue;
|
||||
if (::indices[r].indices.size() < 2)
|
||||
if (indices[r].indices.size() < 2)
|
||||
continue;
|
||||
for (i = 0; i < (int)::indices[k].indices.size() - 1; i++) {
|
||||
for (j = 0; j < (int)::indices[k].indices.size() - 1;
|
||||
for (i = 0; i < (int)indices[k].indices.size() - 1; i++) {
|
||||
for (j = 0; j < (int)indices[k].indices.size() - 1;
|
||||
j++) {
|
||||
uint32_t key = k.hash() ^ i ^ r.hash() ^ j ^
|
||||
2147483137;
|
||||
@@ -875,12 +1017,10 @@ void RoadLinesData::update_road_lines_nodes(
|
||||
2147463167;
|
||||
if (checks.find(key) == checks.end() &&
|
||||
checks.find(key2) == checks.end()) {
|
||||
int idx_a1 = ::indices[k].indices[i];
|
||||
int idx_a2 =
|
||||
::indices[k].indices[i + 1];
|
||||
int idx_b1 = ::indices[k].indices[j];
|
||||
int idx_b2 =
|
||||
::indices[k].indices[j + 1];
|
||||
int idx_a1 = indices[k].indices[i];
|
||||
int idx_a2 = indices[k].indices[i + 1];
|
||||
int idx_b1 = indices[k].indices[j];
|
||||
int idx_b2 = indices[k].indices[j + 1];
|
||||
std::vector<int> cmp1 = { idx_a1,
|
||||
idx_a2 };
|
||||
if (std::find(cmp1.begin(), cmp1.end(),
|
||||
@@ -946,14 +1086,14 @@ void RoadLinesData::update_road_lines_nodes(
|
||||
int nidx = road_lines_nodes.size();
|
||||
road_lines_nodes.push_back(pxt);
|
||||
// int il = (int)road_lines[k].indices.size();
|
||||
assert(std::find(::indices[k].indices.begin(),
|
||||
::indices[k].indices.end(),
|
||||
nidx) == ::indices[k].indices.end());
|
||||
assert(std::find(::indices[r].indices.begin(),
|
||||
::indices[r].indices.end(),
|
||||
nidx) == ::indices[r].indices.end());
|
||||
::indices.insert_line_index(k, i + 1, nidx);
|
||||
::indices.insert_line_index(r, j + 1, nidx);
|
||||
assert(std::find(indices[k].indices.begin(),
|
||||
indices[k].indices.end(),
|
||||
nidx) == indices[k].indices.end());
|
||||
assert(std::find(indices[r].indices.begin(),
|
||||
indices[r].indices.end(),
|
||||
nidx) == indices[r].indices.end());
|
||||
indices.insert_line_index(k, i + 1, nidx);
|
||||
indices.insert_line_index(r, j + 1, nidx);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1020,7 +1160,11 @@ int RoadLinesData::get_debug_flags() const
|
||||
|
||||
void RoadLinesData::update_line_segments(const String &line)
|
||||
{
|
||||
::lines.update_line_segments(line);
|
||||
flecs::entity root_e = BaseData::get_singleton()->get().lookup("lines");
|
||||
assert(root_e.is_valid());
|
||||
LinesAccessor *lines = root_e.get_mut<LinesAccessor>();
|
||||
lines->update_line_segments(line);
|
||||
root_e.modified<LinesAccessor>();
|
||||
}
|
||||
|
||||
Vector3 RoadLinesData::get_point_by_offsets(const String &line,
|
||||
@@ -1029,14 +1173,18 @@ Vector3 RoadLinesData::get_point_by_offsets(const String &line,
|
||||
{
|
||||
Vector3 ret;
|
||||
int i;
|
||||
assert(::lines.has(line));
|
||||
flecs::entity root_e = BaseData::get_singleton()->get().lookup("lines");
|
||||
assert(root_e.is_valid());
|
||||
const LinesAccessor *lines = root_e.get<LinesAccessor>();
|
||||
assert(lines->has(line));
|
||||
print_verbose("line: " + line +
|
||||
" line_offset: " + String::num(dir_offset) +
|
||||
" normal_offset: " + String::num(normal_offset));
|
||||
float n_offset = dir_offset;
|
||||
int selected_segment = 0;
|
||||
for (i = 0; i < (int)::lines[line].segments.size(); i++) {
|
||||
const struct line_segment *segment = &::lines[line].segments[i];
|
||||
for (i = 0; i < (int)lines->get_line(line).segments.size(); i++) {
|
||||
const struct line_segment *segment =
|
||||
&lines->get_line(line).segments[i];
|
||||
if (n_offset < segment->length) {
|
||||
selected_segment = i;
|
||||
break;
|
||||
@@ -1044,9 +1192,10 @@ Vector3 RoadLinesData::get_point_by_offsets(const String &line,
|
||||
n_offset -= segment->length;
|
||||
}
|
||||
print_verbose("offset: " + String::num(n_offset));
|
||||
ret = ::lines[line].segments[selected_segment].p1 +
|
||||
::lines[line].segments[selected_segment].dir * n_offset +
|
||||
::lines[line].segments[selected_segment].tangent * normal_offset;
|
||||
ret = lines->get_line(line).segments[selected_segment].p1 +
|
||||
lines->get_line(line).segments[selected_segment].dir * n_offset +
|
||||
lines->get_line(line).segments[selected_segment].tangent *
|
||||
normal_offset;
|
||||
print_verbose("data: " + (ret.operator String()));
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ public:
|
||||
Vector3 pmid[2];
|
||||
Vector3 pside[2];
|
||||
Vector3 test_p[2];
|
||||
std::vector<Vector3> lot_points;
|
||||
int transit_stop_count;
|
||||
String transit_stop_type;
|
||||
float transit_stop_offset;
|
||||
@@ -415,7 +416,7 @@ public:
|
||||
const Vector3 &get_line_point(const String &key, int index) const;
|
||||
const Transform &get_line_point_transform(const String &key,
|
||||
int index) const;
|
||||
bool has_line(const String &key);
|
||||
bool has_line(const String &key) const;
|
||||
void insert_line_point(const String &key, int index,
|
||||
const Transform &xform);
|
||||
void erase_line_point(const String &key, int index);
|
||||
@@ -431,7 +432,7 @@ public:
|
||||
String get_road_lines_path();
|
||||
void get_road_lines_key_list(List<String> *keys);
|
||||
void get_lines_key_list(List<String> *keys);
|
||||
const String &get_next_line(const String &key);
|
||||
const String &get_next_line(const String &key) const;
|
||||
void erase_line(const String &key);
|
||||
void load_data();
|
||||
void save_data();
|
||||
|
||||
@@ -313,60 +313,6 @@ out2:;
|
||||
const Vector3 &p1, const Vector3 &dir)
|
||||
{
|
||||
int structures_generated = 0;
|
||||
#if 0
|
||||
if (edge.left.lot > 0) {
|
||||
Transform xform = get_structure_transform(
|
||||
p0, p1, dir, left_n, edge.left.lot_offset,
|
||||
edge.left.lot_dir_offset,
|
||||
edge.left.lot_y_rotation,
|
||||
edge.left.lot_y_offset);
|
||||
BuildingsData::building b;
|
||||
b.key = "road__" + line_key + "__lot__" +
|
||||
itos(edge_no) + "__left__lot-" +
|
||||
edge.left.lot_type;
|
||||
b.id = "lot-" + edge.left.lot_type;
|
||||
b.generated = true;
|
||||
b.line_name = line_key;
|
||||
b.key_hash = b.key.hash64();
|
||||
b.pattern_id = 0;
|
||||
b.xform = xform;
|
||||
b.worktime[0] = 0;
|
||||
b.worktime[1] = 23;
|
||||
create_building_structure(b);
|
||||
structures_generated++;
|
||||
if (edge.left.buildings.size() > 0) {
|
||||
structures_generated += create_line_building(
|
||||
line_key, edge_no, xform, edge.left,
|
||||
"left");
|
||||
}
|
||||
}
|
||||
if (edge.right.lot > 0) {
|
||||
Transform xform = get_structure_transform(
|
||||
p0, p1, dir, right_n, edge.right.lot_offset,
|
||||
edge.right.lot_dir_offset,
|
||||
edge.right.lot_y_rotation,
|
||||
edge.right.lot_y_offset);
|
||||
BuildingsData::building b;
|
||||
b.key = "road__" + line_key + "__lot__" +
|
||||
itos(edge_no) + "__right__lot-" +
|
||||
edge.right.lot_type;
|
||||
b.id = "lot-" + edge.right.lot_type;
|
||||
b.generated = true;
|
||||
b.line_name = line_key;
|
||||
b.key_hash = b.key.hash64();
|
||||
b.pattern_id = 0;
|
||||
b.xform = xform;
|
||||
b.worktime[0] = 0;
|
||||
b.worktime[1] = 23;
|
||||
create_building_structure(b);
|
||||
structures_generated++;
|
||||
if (edge.right.buildings.size() > 0) {
|
||||
structures_generated += create_line_building(
|
||||
line_key, edge_no, xform, edge.right,
|
||||
"right");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return structures_generated;
|
||||
}
|
||||
int create_transit_stops(const String &line_key, int edge_no,
|
||||
@@ -473,12 +419,6 @@ out2:;
|
||||
}
|
||||
return !ok;
|
||||
}
|
||||
void build_edge_list()
|
||||
{
|
||||
}
|
||||
#if 0
|
||||
std::vector<struct RoadLinesData::test_edge> test_edges;
|
||||
#endif
|
||||
void test_lines()
|
||||
{
|
||||
int i;
|
||||
@@ -498,122 +438,6 @@ out2:;
|
||||
e = e->next();
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
void build_test_edges()
|
||||
{
|
||||
int i, j;
|
||||
int edge_count = 0;
|
||||
List<String> keys;
|
||||
RoadLinesData *rld = RoadLinesData::get_singleton();
|
||||
rld->get_road_lines_key_list(&keys);
|
||||
List<String>::Element *e = keys.front();
|
||||
while (e) {
|
||||
const String &key = e->get();
|
||||
edge_count += rld->lines(key).edges.size();
|
||||
e = e->next();
|
||||
}
|
||||
test_edges.clear();
|
||||
test_edges.reserve(edge_count);
|
||||
e = keys.front();
|
||||
while (e) {
|
||||
const String &key = e->get();
|
||||
for (i = 0; i < (int)rld->lines(key).edges.size();
|
||||
i++) {
|
||||
assert(rld->lines(key).edges[i].left.pmid[0] ==
|
||||
rld->lines(key).edges[i].right.pmid[0]);
|
||||
assert(rld->lines(key).edges[i].left.pmid[1] ==
|
||||
rld->lines(key).edges[i].right.pmid[1]);
|
||||
test_edges.emplace(test_edges.end(), key, i);
|
||||
}
|
||||
e = e->next();
|
||||
}
|
||||
for (i = 0; i < (int)test_edges.size(); i++) {
|
||||
test_edges[i].validate();
|
||||
}
|
||||
// FIXME: the bug is here
|
||||
for (i = 0; i < (int)test_edges.size(); i++)
|
||||
test_edges[i].update_line();
|
||||
for (i = 0; i < (int)test_edges.size(); i++)
|
||||
test_edges[i].validate();
|
||||
float depth_mul = 0.5f;
|
||||
for (i = 0; i < (int)test_edges.size(); i++)
|
||||
for (j = 0; j < (int)test_edges.size(); j++) {
|
||||
if (i == j)
|
||||
continue;
|
||||
if (test_edges[i] == test_edges[j])
|
||||
continue;
|
||||
if (test_edges[i].left.lot > 0) {
|
||||
while (!test_edges[i].left.test(
|
||||
test_edges[j])) {
|
||||
test_edges[i].left.lot_depth *=
|
||||
depth_mul;
|
||||
print_error(
|
||||
"Badness: " +
|
||||
String::num(
|
||||
test_edges[i]
|
||||
.left
|
||||
.lot_depth));
|
||||
test_edges[i].left.test_p[1] =
|
||||
test_edges[i]
|
||||
.left.test_p[0] +
|
||||
test_edges[i].left
|
||||
.normal *
|
||||
test_edges[i]
|
||||
.left
|
||||
.lot_depth;
|
||||
if (test_edges[i].left.lot_depth <
|
||||
10.0f) {
|
||||
test_edges[i].left.lot =
|
||||
0;
|
||||
print_line(
|
||||
"lot disabled");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (test_edges[i].right.lot > 0) {
|
||||
while (!test_edges[i].right.test(
|
||||
test_edges[j])) {
|
||||
test_edges[i].right.lot_depth *=
|
||||
depth_mul;
|
||||
print_error(
|
||||
"Badness: " +
|
||||
String::num(
|
||||
test_edges[i]
|
||||
.right
|
||||
.lot_depth));
|
||||
test_edges[i].right.test_p[0] =
|
||||
test_edges[i].p0 +
|
||||
(test_edges[i].p1 -
|
||||
test_edges[i].p0) *
|
||||
0.5f;
|
||||
test_edges[i].right.test_p[1] =
|
||||
test_edges[i]
|
||||
.right
|
||||
.test_p[0] +
|
||||
test_edges[i].right
|
||||
.normal *
|
||||
test_edges[i]
|
||||
.left
|
||||
.lot_depth;
|
||||
if (test_edges[i]
|
||||
.right.lot_depth <
|
||||
10.0f) {
|
||||
test_edges[i].right.lot =
|
||||
0;
|
||||
print_line(
|
||||
"lot disabled");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (i = 0; i < (int)test_edges.size(); i++)
|
||||
test_edges[i].update_line();
|
||||
for (i = 0; i < (int)test_edges.size(); i++)
|
||||
test_edges[i].validate();
|
||||
}
|
||||
#endif
|
||||
void calculate_lot_depths()
|
||||
{
|
||||
int i;
|
||||
@@ -640,16 +464,7 @@ out2:;
|
||||
}
|
||||
e = e->next();
|
||||
}
|
||||
#if 0
|
||||
build_test_edges();
|
||||
#endif
|
||||
}
|
||||
#if 0
|
||||
RID imm;
|
||||
RID imm_instance;
|
||||
RID scenario;
|
||||
Ref<SpatialMaterial> imm_mat;
|
||||
#endif
|
||||
void update_lot_depths()
|
||||
{
|
||||
int i, j;
|
||||
@@ -664,52 +479,6 @@ out2:;
|
||||
RoadLinesProcessing *r = RoadLinesProcessing::get_singleton();
|
||||
if (r->nodes.size() == 0)
|
||||
return;
|
||||
#if 0
|
||||
if (!imm_mat.is_valid()) {
|
||||
imm_mat.instance();
|
||||
imm_mat->set_flag(
|
||||
SpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR,
|
||||
true);
|
||||
imm_mat->set_flag(
|
||||
SpatialMaterial::FLAG_DISABLE_DEPTH_TEST, true);
|
||||
imm_mat->set_flag(SpatialMaterial::FLAG_UNSHADED, true);
|
||||
}
|
||||
if (imm == RID() || imm_instance == RID() ||
|
||||
scenario == RID()) {
|
||||
scenario = SceneTree::get_singleton()
|
||||
->get_root()
|
||||
->get_world()
|
||||
->get_scenario();
|
||||
assert(scenario != RID());
|
||||
imm_instance = RID_PRIME(VisualServer::get_singleton()
|
||||
->instance_create());
|
||||
assert(imm_instance != RID());
|
||||
|
||||
VisualServer::get_singleton()->instance_set_scenario(
|
||||
imm_instance, scenario);
|
||||
|
||||
imm = VisualServer::get_singleton()->immediate_create();
|
||||
assert(imm != RID());
|
||||
VisualServer::get_singleton()->instance_set_base(
|
||||
imm_instance, imm);
|
||||
|
||||
VisualServer::get_singleton()->instance_set_transform(
|
||||
imm_instance, Transform());
|
||||
|
||||
VisualServer::get_singleton()->immediate_set_material(
|
||||
imm, imm_mat->get_rid());
|
||||
VisualServer::get_singleton()
|
||||
->instance_geometry_set_cast_shadows_setting(
|
||||
imm_instance,
|
||||
VisualServer::SHADOW_CASTING_SETTING_OFF);
|
||||
;
|
||||
}
|
||||
VisualServer::get_singleton()->instance_set_visible(
|
||||
imm_instance, false);
|
||||
VisualServer::get_singleton()->immediate_clear(imm);
|
||||
VisualServer::get_singleton()->immediate_begin(
|
||||
imm, VisualServer::PRIMITIVE_LINES, RID());
|
||||
#endif
|
||||
DebugGeo *dbg = memnew(DebugGeo);
|
||||
if (r->nodes.empty())
|
||||
goto out_skip_end;
|
||||
@@ -719,12 +488,6 @@ out2:;
|
||||
dbg->clear();
|
||||
dbg->begin(Mesh::PRIMITIVE_LINES);
|
||||
dbg->set_color(Color(1, 0, 0, 1));
|
||||
#if 0
|
||||
dbg->add_vertex(Vector3(0, 0, 0));
|
||||
dbg->add_vertex(Vector3(0, 1000, 0));
|
||||
dbg->add_vertex(Vector3(10, 0, 0));
|
||||
dbg->add_vertex(Vector3(10, 1000, 0));
|
||||
#endif
|
||||
for (i = 0; i < (int)r->nodes.size(); i++) {
|
||||
const std::vector<struct wedge> &ws = wedges[i];
|
||||
int wsize = ws.size();
|
||||
@@ -775,86 +538,8 @@ out2:;
|
||||
lc2.rect.position = lc2.startp;
|
||||
lc2.rect.size = Vector3();
|
||||
lc2.rect.expand_to(lc2.startp + n2 * lc2.depth);
|
||||
#if 0
|
||||
lc3.side = w.side2_ref;
|
||||
lc3.depth = mside2.lot_depth_eff;
|
||||
lc3.normal = n3;
|
||||
lc3.startp = w.p[2];
|
||||
lc3.rect.position = lc3.startp;
|
||||
lc3.rect.size = Vector3();
|
||||
lc3.rect.expand_to(lc3.startp + n3 * lc3.depth);
|
||||
#endif
|
||||
check_lines.push_back(lc1);
|
||||
check_lines.push_back(lc2);
|
||||
// check_lines.push_back(lc3);
|
||||
#if 0
|
||||
Vector3 p0 = w.p[0];
|
||||
Vector3 p1 = p0 + n1 * mside1.lot_depth_eff;
|
||||
Vector3 p2 = w.p[2];
|
||||
Vector3 p3 = p2 + n2 * mside2.lot_depth_eff;
|
||||
p0.y = 0;
|
||||
p1.y = 0;
|
||||
p2.y = 0;
|
||||
p3.y = 0;
|
||||
Vector3 s, t;
|
||||
Geometry::get_closest_points_between_segments(
|
||||
p0, p1, p2, p3, s, t);
|
||||
s.y = 0;
|
||||
t.y = 0;
|
||||
if (s.distance_to(t) < 1) {
|
||||
Vector3 d =
|
||||
s.linear_interpolate(t, 0.5f);
|
||||
/* We consider having intersection */
|
||||
// FIXME: fix wedge to store line, edge, side
|
||||
float l = w.p[1].distance_to(d);
|
||||
if (mside1.lot_depth_eff > l) {
|
||||
mside1.lot_depth_eff = l;
|
||||
mside1.lot_depth = l;
|
||||
if (w.side1_ref.side == 0)
|
||||
RoadLinesData::get_singleton()
|
||||
->set_line_edge_left(
|
||||
w.side1_ref
|
||||
.line_key,
|
||||
w.side1_ref
|
||||
.edge,
|
||||
mside1);
|
||||
else
|
||||
RoadLinesData::get_singleton()
|
||||
->set_line_edge_right(
|
||||
w.side1_ref
|
||||
.line_key,
|
||||
w.side1_ref
|
||||
.edge,
|
||||
mside1);
|
||||
print_line(
|
||||
"updated depth: side1: " +
|
||||
String::num(l));
|
||||
}
|
||||
if (mside2.lot_depth_eff > l) {
|
||||
mside2.lot_depth_eff = l;
|
||||
mside2.lot_depth = l;
|
||||
if (w.side2_ref.side == 0)
|
||||
RoadLinesData::get_singleton()
|
||||
->set_line_edge_left(
|
||||
w.side2_ref
|
||||
.line_key,
|
||||
w.side2_ref
|
||||
.edge,
|
||||
mside2);
|
||||
else
|
||||
RoadLinesData::get_singleton()
|
||||
->set_line_edge_right(
|
||||
w.side2_ref
|
||||
.line_key,
|
||||
w.side2_ref
|
||||
.edge,
|
||||
mside2);
|
||||
print_line(
|
||||
"updated depth: side2: " +
|
||||
String::num(l));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
assert(check_lines.size() > 0);
|
||||
@@ -878,11 +563,6 @@ out2:;
|
||||
Vector3 p3 = p2 + check_lines[j].normal *
|
||||
check_lines[j].depth;
|
||||
Vector3 s, t;
|
||||
#if 0
|
||||
if (!check_lines[i].rect.intersects_segment(p2,
|
||||
p3))
|
||||
continue;
|
||||
#endif
|
||||
/* samey segments do not intersect */
|
||||
if (p0.is_equal_approx(p2) &&
|
||||
p1.is_equal_approx(p3))
|
||||
@@ -899,32 +579,10 @@ out2:;
|
||||
continue;
|
||||
if (p1.is_equal_approx(p2))
|
||||
continue;
|
||||
#if 0
|
||||
VisualServer::get_singleton()->immediate_color(
|
||||
imm, Color(1, 0, 0, 1));
|
||||
VisualServer::get_singleton()->immediate_vertex(
|
||||
imm, Vector3(-10, 10, 0));
|
||||
print_line("p0: " + p0.operator String());
|
||||
VisualServer::get_singleton()->immediate_vertex(
|
||||
imm, Vector3(0, 10, 0));
|
||||
#endif
|
||||
#if 0
|
||||
VisualServer::get_singleton()->immediate_vertex(
|
||||
imm, p0);
|
||||
VisualServer::get_singleton()->immediate_vertex(
|
||||
imm, p1);
|
||||
VisualServer::get_singleton()->immediate_vertex(
|
||||
imm, p2);
|
||||
VisualServer::get_singleton()->immediate_vertex(
|
||||
imm, p3);
|
||||
#endif
|
||||
assert(!p0.is_equal_approx(p1) &&
|
||||
!p2.is_equal_approx(p3));
|
||||
Geometry::get_closest_points_between_segments(
|
||||
p0, p1, p2, p3, s, t);
|
||||
/* consider match at end as not match at all */
|
||||
print_line("points: s: " + s.operator String());
|
||||
print_line("points: t: " + t.operator String());
|
||||
if (s.is_equal_approx(p0))
|
||||
continue;
|
||||
if (s.is_equal_approx(p1))
|
||||
@@ -962,11 +620,6 @@ out2:;
|
||||
}
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
VisualServer::get_singleton()->immediate_end(imm);
|
||||
VisualServer::get_singleton()->instance_set_visible(
|
||||
imm_instance, true);
|
||||
#endif
|
||||
dbg->end();
|
||||
dbg->clear();
|
||||
dbg->begin(Mesh::PRIMITIVE_LINES);
|
||||
@@ -992,6 +645,8 @@ out2:;
|
||||
side1.side);
|
||||
mside1.lot_depth_eff = check_lines[i].depth;
|
||||
mside1.lot_depth = mside1.lot_depth_eff;
|
||||
mside1.lot_points.push_back(p0);
|
||||
mside1.lot_points.push_back(p1);
|
||||
if (side1.side == 0)
|
||||
RoadLinesData::get_singleton()
|
||||
->set_line_edge_left(side1.line_key,
|
||||
|
||||
Reference in New Issue
Block a user