Skip to content

Commit

Permalink
Gloom: Changing the Sector representation
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent eb551a1 commit 98c66c8
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 17 deletions.
60 changes: 46 additions & 14 deletions doomsday/tests/test_gloom/gloom/world/map.cpp
Expand Up @@ -192,18 +192,37 @@ void Map::removeInvalid()
{
for (QMutableHashIterator<ID, Sector> iter(d->sectors); iter.hasNext(); )
{
const ID secId = iter.key();
auto &sector = iter.next().value();
// Remove missing points.
for (QMutableListIterator<ID> i(sector.points); i.hasNext(); )
{
i.next();
if (!d->points.contains(i.value()))
{
i.remove();
}
}
// Remove missing lines.
for (QMutableListIterator<ID> i(sector.lines); i.hasNext(); )
for (QMutableListIterator<ID> i(sector.walls); i.hasNext(); )
{
i.next();
if (!d->lines.contains(i.value()))
{
i.remove();
}
else
{
// Missing references?
const Line &line = Map::line(i.value());
if (line.sectors[0] != secId && line.sectors[1] != secId)
{
i.remove();
}
}
}
// Remove empty sectors.
if (sector.lines.isEmpty())
if (sector.points.isEmpty() || sector.walls.isEmpty())
{
iter.remove();
continue;
Expand Down Expand Up @@ -373,16 +392,19 @@ geo::Line2d Map::geoLine(ID lineId) const

geo::Polygon Map::sectorPolygon(ID sectorId) const
{
// TODO: Store geo::Polygon in Sector; no need to rebuild it all the time.

const auto &sec = sector(sectorId);
geo::Polygon poly;
//ID prevPointId = 0;
ID atPoint;
//ID atPoint;

//const int order[2][2] = {{ 0, 1 }, { 1, 0 }};
for (ID lineId : sec.lines)
geo::Polygon poly;
for (ID pid : sec.points)
{
const auto &line = Map::line(lineId);
const int dir = (line.sectors[0] == sectorId ? 0 : 1);
poly.points << geo::Polygon::Point{point(pid), pid};

//const auto &line = Map::line(pid);
//const int dir = (line.sectors[0] == sectorId ? 0 : 1);
/*
ID pointId = line.points[idx];
if (line.points[idx^1] == prevPointId)
Expand All @@ -406,6 +428,12 @@ geo::Polygon Map::sectorPolygon(ID sectorId) const
return poly;
}

void Map::buildSector(QSet<ID> sourceLines, IDList &sectorPoints, IDList &sectorWalls,
bool createNewSector)
{

}

static QString idStr(ID id)
{
return String::number(id, 16);
Expand Down Expand Up @@ -483,7 +511,8 @@ Block Map::serialize() const
for (auto i = _d->sectors.begin(); i != _d->sectors.end(); ++i)
{
QJsonObject secObj;
secObj.insert("ln", idListToJsonArray(i.value().lines));
secObj.insert("pt", idListToJsonArray(i.value().points));
secObj.insert("wl", idListToJsonArray(i.value().walls));
secObj.insert("vol", idListToJsonArray(i.value().volumes));
sectors.insert(idStr(i.key()), secObj);
}
Expand Down Expand Up @@ -564,11 +593,14 @@ void Map::deserialize(const Block &data)
const auto sectors = map["sectors"].toHash();
for (auto i = sectors.begin(); i != sectors.end(); ++i)
{
const auto obj = i.value().toHash();
const auto lines = obj["ln"].toList();
const auto obj = i.value().toHash();
const auto points = obj["pt"].toList();
const auto walls = obj["wl"].toList();
const auto volumes = obj["vol"].toList();
d->sectors.insert(getId(i.key()),
Sector{variantListToIDList(lines), variantListToIDList(volumes)});
Sector{variantListToIDList(points),
variantListToIDList(walls),
variantListToIDList(volumes)});
}
}

Expand All @@ -588,9 +620,9 @@ void Map::deserialize(const Block &data)

void Sector::replaceLine(ID oldId, ID newId)
{
for (int i = 0; i < lines.size(); ++i)
for (int i = 0; i < walls.size(); ++i)
{
if (lines[i] == oldId) lines[i] = newId;
if (walls[i] == oldId) walls[i] = newId;
}
}

Expand Down
11 changes: 9 additions & 2 deletions doomsday/tests/test_gloom/gloom/world/map.h
Expand Up @@ -61,8 +61,12 @@ struct Volume
};
struct Sector
{
IDList lines; // must have clockwise winding
IDList volumes; // must be ascending and share planes
IDList points; // polygon, clockwise winding
IDList walls; // unordered
IDList volumes; // must be ascending and share planes; bottom plane of first volume is the
// sector floor, top plane of last volume is the sector ceiling

void replaceLine(ID oldId, ID newId);
};

typedef QHash<ID, Point> Points;
Expand Down Expand Up @@ -124,6 +128,9 @@ class Map
geo::Line2d geoLine(ID lineId) const;
geo::Polygon sectorPolygon(ID sectorId) const;

void buildSector(QSet<ID> sourceLines, IDList &sectorPoints, IDList &sectorWalls,
bool createNewSector = false);

de::Block serialize() const;
void deserialize(const de::Block &data);

Expand Down
5 changes: 4 additions & 1 deletion doomsday/tests/test_gloom/src/editor.cpp
Expand Up @@ -370,6 +370,8 @@ DENG2_PIMPL(Editor)

bool linkSectorLines(ID sectorId)
{
return false;
/*
auto &sector = map.sector(sectorId);
IDList remaining = sector.lines;
Expand Down Expand Up @@ -411,6 +413,7 @@ DENG2_PIMPL(Editor)
// Complete.
sector.lines = sorted;
return true;
*/
}

void userAdd()
Expand All @@ -436,7 +439,7 @@ DENG2_PIMPL(Editor)
Sector sector;
for (ID id : selection)
{
if (map.isLine(id)) sector.lines << id;
if (map.isLine(id)) sector.walls << id;
}
selection.clear();
ID floor = map.append(map.planes(), Plane{{Vector3d()}, {Vector3f(0, 1, 0)}});
Expand Down

0 comments on commit 98c66c8

Please sign in to comment.