int32_t C4FindObject::Count(const C4ObjectList &Objs) { // Trivial cases if (IsImpossible()) return 0; if (IsEnsured()) return Objs.ObjectCount(); // Count int32_t iCount = 0; for (C4ObjectLink *pLnk = Objs.First; pLnk; pLnk = pLnk->Next) if (pLnk->Obj->Status) if (Check(pLnk->Obj)) iCount++; return iCount; }
int32_t C4FindObject::Count(const C4ObjectList &Objs) { // Trivial cases if (IsImpossible()) return 0; if (IsEnsured()) return Objs.ObjectCount(); // Count int32_t iCount = 0; for (C4Object *obj : Objs) if (obj->Status && Check(obj)) iCount++; return iCount; }
int32_t C4FindObject::Count(const C4ObjectList &Objs, const C4LSectors &Sct) { // Trivial cases if (IsImpossible()) return 0; if (IsEnsured()) return Objs.ObjectCount(); // Check bounds C4Rect *pBounds = GetBounds(); if (!pBounds) return Count(Objs); else if (UseShapes()) { // Get area C4LArea Area(&::Objects.Sectors, *pBounds); C4LSector *pSct; C4ObjectList *pLst = Area.FirstObjectShapes(&pSct); // Check if a single-sector check is enough if (!Area.Next(pSct)) return Count(pSct->ObjectShapes); // Create marker, count over all areas uint32_t iMarker = ::Objects.GetNextMarker(); int32_t iCount = 0; for (; pLst; pLst=Area.NextObjectShapes(pLst, &pSct)) for (C4Object *obj : Objs) if (obj->Status) if (obj->Marker != iMarker) { obj->Marker = iMarker; if (Check(obj)) iCount++; } return iCount; } else { // Count objects per area C4LArea Area(&::Objects.Sectors, *pBounds); C4LSector *pSct; int32_t iCount = 0; for (C4ObjectList *pLst=Area.FirstObjects(&pSct); pLst; pLst=Area.NextObjects(pLst, &pSct)) iCount += Count(*pLst); return iCount; } }