Quality of life with road lines edge data (lots, buildings, etc.)
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
#ifndef ROAD_LINES_DATA_H
|
||||
#define ROAD_LINES_DATA_H
|
||||
#include <cassert>
|
||||
#include <core/io/json.h>
|
||||
#include "callable.h"
|
||||
class ImmediateGeometry;
|
||||
class RoadLinesData {
|
||||
@@ -14,20 +16,6 @@ protected:
|
||||
static RoadLinesData *singleton;
|
||||
_Signal<void> lines_updated;
|
||||
|
||||
public:
|
||||
struct line_building_data {
|
||||
String id;
|
||||
String building_key;
|
||||
uint64_t building_key_hash;
|
||||
float line_offset;
|
||||
float normal_offset;
|
||||
float y_rotation;
|
||||
float y_offset;
|
||||
static void from_dict(struct line_building_data *b,
|
||||
const Dictionary &from);
|
||||
Dictionary to_dict() const;
|
||||
};
|
||||
|
||||
public:
|
||||
struct line_segment {
|
||||
Vector3 p1;
|
||||
@@ -39,10 +27,172 @@ public:
|
||||
};
|
||||
|
||||
public:
|
||||
struct road_edge_side {
|
||||
int transit_stop_count;
|
||||
String transit_stop_type;
|
||||
float transit_stop_offset;
|
||||
float transit_stop_dir_offset;
|
||||
float transit_stop_y_rotation;
|
||||
int sideroad;
|
||||
float sideroad_offset;
|
||||
float sideroad_dir_offset;
|
||||
float sideroad_y_offset;
|
||||
float sideroad_y_rotation;
|
||||
String sideroad_type;
|
||||
int lot;
|
||||
float lot_offset;
|
||||
float lot_dir_offset;
|
||||
float lot_y_offset;
|
||||
float lot_y_rotation;
|
||||
String lot_type;
|
||||
struct buildings {
|
||||
String id;
|
||||
Vector3 offsets;
|
||||
float y_rotation;
|
||||
String to_string() const
|
||||
{
|
||||
String ret;
|
||||
ret += id + ":";
|
||||
ret += String::num(offsets.x) + ", ";
|
||||
ret += String::num(offsets.y) + ", ";
|
||||
ret += String::num(offsets.z) + ":";
|
||||
ret += String::num(y_rotation);
|
||||
return ret;
|
||||
}
|
||||
static void from_string(struct buildings &buildings,
|
||||
const String &data)
|
||||
{
|
||||
Vector<String> parts = data.split(":");
|
||||
if (parts.size() < 3)
|
||||
return;
|
||||
assert(parts.size() == 3);
|
||||
Vector<String> vecparts = parts[1].split(",");
|
||||
assert(vecparts.size() == 3);
|
||||
buildings.id = parts[0];
|
||||
buildings.offsets.x =
|
||||
vecparts[0].strip_edges().to_float();
|
||||
buildings.offsets.y =
|
||||
vecparts[1].strip_edges().to_float();
|
||||
buildings.offsets.z =
|
||||
vecparts[2].strip_edges().to_float();
|
||||
buildings.y_rotation =
|
||||
parts[2].strip_edges().to_float();
|
||||
}
|
||||
};
|
||||
std::vector<struct buildings> buildings;
|
||||
Dictionary to_dict() const
|
||||
{
|
||||
Dictionary ret;
|
||||
ret["transit_stop_count"] = transit_stop_count;
|
||||
ret["transit_stop_type"] = transit_stop_type;
|
||||
ret["transit_stop_offset"] = transit_stop_offset;
|
||||
ret["transit_stop_dir_offset"] =
|
||||
transit_stop_dir_offset;
|
||||
ret["transit_stop_y_rotation"] =
|
||||
transit_stop_y_rotation;
|
||||
ret["sideroad"] = sideroad;
|
||||
ret["sideroad_offset"] = sideroad_offset;
|
||||
ret["sideroad_dir_offset"] = sideroad_dir_offset;
|
||||
ret["sideroad_y_offset"] = sideroad_y_offset;
|
||||
ret["sideroad_y_rotation"] = sideroad_y_rotation;
|
||||
ret["sideroad_type"] = sideroad_type;
|
||||
ret["lot"] = lot;
|
||||
ret["lot_offset"] = lot_offset;
|
||||
ret["lot_dir_offset"] = lot_dir_offset;
|
||||
ret["lot_y_offset"] = lot_y_offset;
|
||||
ret["lot_y_rotation"] = lot_y_rotation;
|
||||
ret["lot_type"] = lot_type;
|
||||
String lot_buildings;
|
||||
int i;
|
||||
for (i = 0; i < (int)buildings.size(); i++) {
|
||||
lot_buildings += buildings[i].to_string();
|
||||
if (i < (int)buildings.size() - 1)
|
||||
lot_buildings += "!";
|
||||
}
|
||||
ret["lot_buildings"] = lot_buildings;
|
||||
return ret;
|
||||
}
|
||||
road_edge_side()
|
||||
: transit_stop_count(0)
|
||||
, transit_stop_type("")
|
||||
, transit_stop_offset(0.0f)
|
||||
, transit_stop_dir_offset(0.0f)
|
||||
, transit_stop_y_rotation(0.0f)
|
||||
, sideroad(0)
|
||||
, sideroad_offset(0.0f)
|
||||
, sideroad_dir_offset(0.0f)
|
||||
, sideroad_y_offset(0.0f)
|
||||
, sideroad_y_rotation(0.0f)
|
||||
, sideroad_type(String(""))
|
||||
, lot(0)
|
||||
, lot_offset(0.0f)
|
||||
, lot_dir_offset(0.0f)
|
||||
, lot_y_offset(0.0f)
|
||||
, lot_y_rotation(0.0f)
|
||||
, lot_type(String(""))
|
||||
, buildings{}
|
||||
{
|
||||
}
|
||||
static void from_dict(struct road_edge_side &side,
|
||||
const Dictionary &dict)
|
||||
{
|
||||
int i;
|
||||
side.transit_stop_count = dict["transit_stop_count"];
|
||||
side.transit_stop_type = dict["transit_stop_type"];
|
||||
side.transit_stop_offset = dict["transit_stop_offset"];
|
||||
side.transit_stop_dir_offset =
|
||||
dict["transit_stop_dir_offset"];
|
||||
side.transit_stop_y_rotation =
|
||||
dict["transit_stop_y_rotation"];
|
||||
side.sideroad = dict["sideroad"];
|
||||
side.sideroad_offset = dict["sideroad_offset"];
|
||||
side.sideroad_dir_offset = dict["sideroad_dir_offset"];
|
||||
side.sideroad_y_offset = dict["sideroad_y_offset"];
|
||||
side.sideroad_y_rotation = dict["sideroad_y_rotation"];
|
||||
side.sideroad_type = dict["sideroad_type"];
|
||||
side.lot = dict["lot"];
|
||||
side.lot_offset = dict["lot_offset"];
|
||||
side.lot_dir_offset = dict["lot_dir_offset"];
|
||||
side.lot_y_offset = dict["lot_y_offset"];
|
||||
side.lot_y_rotation = dict["lot_y_rotation"];
|
||||
side.lot_type = dict["lot_type"];
|
||||
String lot_buildings = dict["lot_buildings"];
|
||||
lot_buildings = lot_buildings.strip_edges();
|
||||
Vector<String> parts;
|
||||
if (lot_buildings.find("!") >= 0)
|
||||
parts = lot_buildings.split("!");
|
||||
else
|
||||
parts.push_back(lot_buildings);
|
||||
side.buildings.resize(parts.size());
|
||||
for (i = 0; i < parts.size(); i++) {
|
||||
buildings::from_string(side.buildings[i],
|
||||
parts[i]);
|
||||
}
|
||||
}
|
||||
};
|
||||
struct road_edge {
|
||||
struct road_edge_side left, right;
|
||||
|
||||
Dictionary to_dict() const
|
||||
{
|
||||
Dictionary ret;
|
||||
ret["left"] = left.to_dict();
|
||||
ret["right"] = right.to_dict();
|
||||
return ret;
|
||||
}
|
||||
static void from_dict(struct road_edge &edge,
|
||||
const Dictionary &dict)
|
||||
{
|
||||
const Dictionary &dleft = dict["left"],
|
||||
&dright = dict["right"];
|
||||
road_edge_side::from_dict(edge.left, dleft);
|
||||
road_edge_side::from_dict(edge.right, dright);
|
||||
}
|
||||
};
|
||||
struct road_line {
|
||||
std::vector<Transform> points;
|
||||
std::vector<struct road_edge> edges;
|
||||
std::vector<int> indices;
|
||||
std::vector<struct line_building_data> buildings;
|
||||
std::vector<struct line_segment> segments;
|
||||
int lanes;
|
||||
int pattern;
|
||||
@@ -87,14 +237,8 @@ public:
|
||||
void set_debug_flags(int debug_flags);
|
||||
int get_debug_flags() const;
|
||||
void update_line_segments(const String &line);
|
||||
void line_add_building(const String &line, const String &key,
|
||||
float curve_offset, float normal_offset,
|
||||
float y_rotation, float y_offset);
|
||||
void assign_close_buildings(const String &line);
|
||||
bool line_has_building(const String &line, const String &building_key);
|
||||
Vector3 get_point_by_offsets(const String &line, float dir_offset,
|
||||
float normal_offset);
|
||||
void update_buildings_from_lines();
|
||||
|
||||
private:
|
||||
void create_segments_from_lines();
|
||||
|
||||
Reference in New Issue
Block a user