Now line buildings save/load works
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -17,6 +17,48 @@
|
||||
ImmediateGeometry *RoadLinesData::debug_im = nullptr;
|
||||
static Ref<Material> debug_material;
|
||||
RoadLinesData::RoadLinesData()
|
||||
{
|
||||
load_data();
|
||||
}
|
||||
RoadLinesData *RoadLinesData::singleton = nullptr;
|
||||
RoadLinesData *RoadLinesData::get_singleton()
|
||||
{
|
||||
if (!singleton)
|
||||
singleton = memnew(RoadLinesData);
|
||||
return singleton;
|
||||
}
|
||||
RoadLinesData::~RoadLinesData()
|
||||
{
|
||||
#if 0
|
||||
if (debug_im) {
|
||||
memdelete(debug_im);
|
||||
debug_im = nullptr;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
void RoadLinesData::cleanup()
|
||||
{
|
||||
memdelete(singleton);
|
||||
singleton = nullptr;
|
||||
}
|
||||
String RoadLinesData::get_road_lines_path()
|
||||
{
|
||||
return road_lines_path;
|
||||
}
|
||||
void RoadLinesData::get_road_lines_key_list(List<String> *keys)
|
||||
{
|
||||
List<String> line_keys;
|
||||
lines.get_key_list(&line_keys);
|
||||
List<String>::Element *e = line_keys.front();
|
||||
keys->clear();
|
||||
while (e) {
|
||||
const String &key = e->get();
|
||||
if (key.ends_with("_road"))
|
||||
keys->push_back(key);
|
||||
e = e->next();
|
||||
}
|
||||
}
|
||||
void RoadLinesData::load_data()
|
||||
{
|
||||
int i;
|
||||
ConfigFile config;
|
||||
@@ -57,50 +99,19 @@ RoadLinesData::RoadLinesData()
|
||||
int index = indices[i];
|
||||
rline.indices[i] = index;
|
||||
}
|
||||
Array buildings = entry.get("buildings", Array());
|
||||
rline.buildings.resize(buildings.size());
|
||||
for (i = 0; i < (int)buildings.size(); i++) {
|
||||
struct line_building_data b;
|
||||
line_building_data::from_dict(&b, buildings[i]);
|
||||
rline.buildings.push_back(b);
|
||||
}
|
||||
// TODO: wtf is flags?
|
||||
rline.lanes = lanes;
|
||||
lines[key] = rline;
|
||||
e = e->next();
|
||||
}
|
||||
}
|
||||
RoadLinesData *RoadLinesData::singleton = nullptr;
|
||||
RoadLinesData *RoadLinesData::get_singleton()
|
||||
{
|
||||
if (!singleton)
|
||||
singleton = memnew(RoadLinesData);
|
||||
return singleton;
|
||||
}
|
||||
RoadLinesData::~RoadLinesData()
|
||||
{
|
||||
#if 0
|
||||
if (debug_im) {
|
||||
memdelete(debug_im);
|
||||
debug_im = nullptr;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
void RoadLinesData::cleanup()
|
||||
{
|
||||
memdelete(singleton);
|
||||
singleton = nullptr;
|
||||
}
|
||||
String RoadLinesData::get_road_lines_path()
|
||||
{
|
||||
return road_lines_path;
|
||||
}
|
||||
void RoadLinesData::get_road_lines_key_list(List<String> *keys)
|
||||
{
|
||||
List<String> line_keys;
|
||||
lines.get_key_list(&line_keys);
|
||||
List<String>::Element *e = line_keys.front();
|
||||
keys->clear();
|
||||
while (e) {
|
||||
const String &key = e->get();
|
||||
if (key.ends_with("_road"))
|
||||
keys->push_back(key);
|
||||
e = e->next();
|
||||
}
|
||||
}
|
||||
void RoadLinesData::save_data()
|
||||
{
|
||||
int i;
|
||||
@@ -128,6 +139,11 @@ void RoadLinesData::save_data()
|
||||
pvalues["metadata"] = lines[e->get()].metadata;
|
||||
pvalues["lanes"] = lines[e->get()].lanes;
|
||||
pvalues["pattern"] = lines[e->get()].pattern;
|
||||
Array buildings;
|
||||
for (i = 0; i < (int)lines[e->get()].buildings.size(); i++)
|
||||
buildings.push_back(
|
||||
lines[e->get()].buildings[i].to_dict());
|
||||
pvalues["buildings"] = buildings;
|
||||
output[e->get()] = pvalues;
|
||||
e = e->next();
|
||||
}
|
||||
@@ -640,6 +656,7 @@ Vector3 RoadLinesData::get_point_by_offsets(const String &line,
|
||||
{
|
||||
Vector3 ret;
|
||||
int i;
|
||||
assert(lines.has(line));
|
||||
print_verbose("line: " + line +
|
||||
" line_offset: " + String::num(dir_offset) +
|
||||
" normal_offset: " + String::num(normal_offset));
|
||||
@@ -653,8 +670,34 @@ Vector3 RoadLinesData::get_point_by_offsets(const String &line,
|
||||
}
|
||||
n_offset -= segment->length;
|
||||
}
|
||||
print_line("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;
|
||||
print_line("data: " + (ret.operator String()));
|
||||
return ret;
|
||||
}
|
||||
|
||||
void RoadLinesData::line_building_data::from_dict(line_building_data *b,
|
||||
const Dictionary &from)
|
||||
{
|
||||
assert(from.has("building_key"));
|
||||
assert(from.has("line_offset"));
|
||||
assert(from.has("normal_offset"));
|
||||
assert(from.has("y_rotation"));
|
||||
b->building_key = from.get("building_key", "");
|
||||
b->building_key_hash = b->building_key.hash64();
|
||||
b->line_offset = from.get("line_offset", -1.0f);
|
||||
b->normal_offset = from.get("normal_offset", -1.0f);
|
||||
b->y_rotation = from.get("y_rotation", Math_NAN);
|
||||
}
|
||||
|
||||
Dictionary RoadLinesData::line_building_data::to_dict() const
|
||||
{
|
||||
Dictionary ret;
|
||||
ret["building_key"] = building_key;
|
||||
ret["line_offset"] = line_offset;
|
||||
ret["normal_offset"] = normal_offset;
|
||||
ret["y_rotation"] = y_rotation;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -20,6 +20,9 @@ public:
|
||||
float line_offset;
|
||||
float normal_offset;
|
||||
float y_rotation;
|
||||
static void from_dict(struct line_building_data *b,
|
||||
const Dictionary &from);
|
||||
Dictionary to_dict() const;
|
||||
};
|
||||
struct line_segment {
|
||||
Vector3 p1;
|
||||
@@ -48,6 +51,7 @@ public:
|
||||
static void cleanup();
|
||||
String get_road_lines_path();
|
||||
void get_road_lines_key_list(List<String> *keys);
|
||||
void load_data();
|
||||
void save_data();
|
||||
void process_lines(std::unordered_map<uint32_t, std::vector<Vector3> >
|
||||
&road_lines_nodes_hash,
|
||||
|
||||
@@ -657,11 +657,14 @@ void RoadLinesEditor::update_line_geometry()
|
||||
}
|
||||
line_im->end();
|
||||
}
|
||||
// FIXME: update line segments on load and when line is changed
|
||||
rld->update_line_segments(current_line);
|
||||
if (rld->lines[current_line].buildings.size() > 1) {
|
||||
line_im->begin(Mesh::PRIMITIVE_LINES);
|
||||
for (i = 0;
|
||||
i < (int)rld->lines[current_line].buildings.size();
|
||||
i++) {
|
||||
print_line("idx: " + itos(i));
|
||||
const RoadLinesData::line_building_data &b =
|
||||
rld->lines[current_line].buildings[i];
|
||||
Vector3 pt = rld->get_point_by_offsets(
|
||||
@@ -673,6 +676,7 @@ void RoadLinesEditor::update_line_geometry()
|
||||
Vector3(0.0f, 5.0f, 0.0f));
|
||||
line_im->add_vertex(pt +
|
||||
Vector3(0.0f, 15.0f, 0.0f));
|
||||
print_line("idx: " + itos(i) + " done");
|
||||
}
|
||||
line_im->end();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user