Skip to content

Commit 58456c9

Browse files
committed
avoid remeshing on text and server id changes
1 parent 4a5f084 commit 58456c9

3 files changed

Lines changed: 74 additions & 15 deletions

File tree

src/map/Map.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ static void reportDetectedChanges(std::ostream &os, const WorldComparisonStats &
191191
SHOW(parseTreeChanged);
192192
SHOW(serverIdsChanged);
193193

194-
SHOW(anyRoomFieldsChanged);
194+
SHOW(hasMeshDifferences);
195195

196196
#undef SHOW
197197
} while (false);
@@ -207,12 +207,7 @@ NODISCARD static RoomUpdateFlags reportNeededUpdates(std::ostream &os,
207207
// REVISIT: actually it doesn't matter if Align or Portable changed,
208208
// but there's no way to quickly those individually any more.
209209

210-
const bool needRoomMeshUpdate = stats.anyRoomsRemoved //
211-
|| stats.anyRoomsAdded //
212-
|| stats.spatialDbChanged //
213-
|| stats.anyRoomFieldsChanged //
214-
;
215-
210+
const bool needRoomMeshUpdate = stats.hasMeshDifferences;
216211
const bool boundsChanged = stats.boundsChanged;
217212

218213
os << "[update] Bounds changed: " << (boundsChanged ? "YES" : "NO") << ".\n";
@@ -1588,7 +1583,7 @@ void testAddAndRemoveIsNoChange()
15881583
TEST_ASSERT(stats12.anyRoomsAdded);
15891584
TEST_ASSERT(stats12.spatialDbChanged);
15901585
TEST_ASSERT(stats12.parseTreeChanged);
1591-
TEST_ASSERT(stats12.anyRoomFieldsChanged);
1586+
TEST_ASSERT(stats12.hasMeshDifferences);
15921587
TEST_ASSERT(!stats12.serverIdsChanged);
15931588
}
15941589

@@ -1599,7 +1594,7 @@ void testAddAndRemoveIsNoChange()
15991594
TEST_ASSERT(!stats23.anyRoomsAdded);
16001595
TEST_ASSERT(stats23.spatialDbChanged);
16011596
TEST_ASSERT(stats23.parseTreeChanged);
1602-
TEST_ASSERT(stats23.anyRoomFieldsChanged);
1597+
TEST_ASSERT(stats23.hasMeshDifferences);
16031598
TEST_ASSERT(!stats23.serverIdsChanged);
16041599
}
16051600

@@ -1610,7 +1605,7 @@ void testAddAndRemoveIsNoChange()
16101605
TEST_ASSERT(!stats13.anyRoomsAdded);
16111606
TEST_ASSERT(!stats13.spatialDbChanged);
16121607
TEST_ASSERT(!stats13.parseTreeChanged);
1613-
TEST_ASSERT(!stats13.anyRoomFieldsChanged);
1608+
TEST_ASSERT(!stats13.hasMeshDifferences);
16141609
TEST_ASSERT(!stats13.serverIdsChanged);
16151610
}
16161611
}

src/map/World.cpp

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2215,16 +2215,80 @@ bool World::containsRoomsNotIn(const World &other) const
22152215
return m_cachedRoomSet.containsElementNotIn(other.m_cachedRoomSet);
22162216
}
22172217

2218+
namespace { // anonymous
2219+
2220+
NODISCARD bool hasMeshDifference(const RawExit &a, const RawExit &b)
2221+
{
2222+
// door name change is not a mesh difference
2223+
return a.fields.exitFlags != b.fields.exitFlags //
2224+
|| a.fields.doorFlags != b.fields.doorFlags; //
2225+
}
2226+
2227+
NODISCARD bool hasMeshDifference(const RawRoom::Exits &a, const RawRoom::Exits &b)
2228+
{
2229+
for (auto dir : ALL_EXITS7) {
2230+
if (hasMeshDifference(a[dir], b[dir])) {
2231+
return true;
2232+
}
2233+
}
2234+
return false;
2235+
}
2236+
2237+
NODISCARD bool hasMeshDifference(const RoomFields &a, const RoomFields &b)
2238+
{
2239+
#define X_CASE(_Type, _Name, _Init) \
2240+
if ((a._Name) != (b._Name)) { \
2241+
return true; \
2242+
}
2243+
// NOTE: Purposely *NOT* doing "XFOREACH_ROOM_STRING_PROPERTY(X_CASE)"
2244+
XFOREACH_ROOM_FLAG_PROPERTY(X_CASE)
2245+
XFOREACH_ROOM_ENUM_PROPERTY(X_CASE)
2246+
return false;
2247+
#undef X_CASE
2248+
}
2249+
2250+
NODISCARD bool hasMeshDifference(const RawRoom &a, const RawRoom &b)
2251+
{
2252+
return a.position != b.position //
2253+
|| hasMeshDifference(a.fields, b.fields) //
2254+
|| hasMeshDifference(a.exits, b.exits); //
2255+
}
2256+
2257+
// Only valid if one is immediately derived from the other.
2258+
NODISCARD bool hasMeshDifference(const World &a, const World &b)
2259+
{
2260+
for (const RoomId id : a.getRoomSet()) {
2261+
if (!b.hasRoom(id)) {
2262+
// technically we could return true here, but the function assumes that it won't be
2263+
// called if the worlds added or removed any rooms, so we only care about common rooms.
2264+
continue;
2265+
}
2266+
if (hasMeshDifference(deref(a.getRoom(id)), deref(b.getRoom(id)))) {
2267+
return true;
2268+
}
2269+
}
2270+
return false;
2271+
}
2272+
} // namespace
2273+
22182274
// Only valid if one is immediately derived from the other.
22192275
WorldComparisonStats World::getComparisonStats(const World &base, const World &modified)
22202276
{
2277+
const auto anyRoomsAdded = modified.containsRoomsNotIn(base);
2278+
const auto anyRoomsRemoved = base.containsRoomsNotIn(modified);
2279+
const auto anyRoomsMoved = base.m_spatialDb != modified.m_spatialDb;
2280+
22212281
WorldComparisonStats result;
22222282
result.boundsChanged = base.getBounds() != modified.getBounds();
2223-
result.anyRoomsRemoved = base.containsRoomsNotIn(modified);
2224-
result.anyRoomsAdded = modified.containsRoomsNotIn(base);
2225-
result.spatialDbChanged = base.m_spatialDb != modified.m_spatialDb;
2283+
result.anyRoomsRemoved = anyRoomsRemoved;
2284+
result.anyRoomsAdded = anyRoomsAdded;
2285+
result.spatialDbChanged = anyRoomsMoved;
22262286
result.serverIdsChanged = base.m_serverIds != modified.m_serverIds;
22272287
result.parseTreeChanged = base.m_parseTree != modified.m_parseTree;
2228-
result.anyRoomFieldsChanged = base.m_rooms != modified.m_rooms;
2288+
result.hasMeshDifferences = anyRoomsAdded //
2289+
|| anyRoomsRemoved //
2290+
|| anyRoomsMoved //
2291+
|| hasMeshDifference(base, modified); //
2292+
22292293
return result;
22302294
}

src/map/World.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ struct NODISCARD WorldComparisonStats final
3434
bool parseTreeChanged = false;
3535
bool serverIdsChanged = false;
3636

37-
bool anyRoomFieldsChanged = false;
37+
bool hasMeshDifferences = false;
3838
};
3939

4040
class NODISCARD World final

0 commit comments

Comments
 (0)