@@ -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.
22192275WorldComparisonStats 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}
0 commit comments