bool GlobalsArray::ValidMArrayIter(const ArrayData* ad, const MArrayIter & fp) { assert(fp.getContainer() == ad); auto a = asGlobals(ad); if (fp.getResetFlag()) return false; if (fp.m_pos == IterEnd(a)) return false; NameValueTable::Iterator iter(a->m_tab, fp.m_pos); return iter.valid(); }
size_t GlobalsArray::Vsize(const ArrayData* ad) { // We need to iterate to find out the actual size, since kNamedLocalDataType // elements in the array may have been set to KindOfUninit. auto a = asGlobals(ad); size_t count = 0; auto iter_limit = IterEnd(a); for (auto iter = IterBegin(a); iter != iter_limit; iter = IterAdvance(a, iter)) { ++count; } return count; }
size_t NameValueTableWrapper::Vsize(const ArrayData* ad) { // We need to iterate to find out the actual size, since // KindOfNamedLocal elements in the array may have been set to // KindOfUninit. auto a = asNVTW(ad); size_t count = 0; auto iter_limit = IterEnd(a); for (auto iter = IterBegin(a); iter != iter_limit; iter = IterAdvance(a, iter)) { ++count; } return count; }
std::string ASE::QueryFull ( void ) { std::stringstream reply; std::stringstream temp; reply << "EYE1"; // game reply << ( unsigned char ) 4; reply << "mta"; // port reply << ( unsigned char ) ( m_strPort.length() + 1 ); reply << m_strPort; // server name reply << ( unsigned char ) ( m_pMainConfig->GetServerName ().length() + 1 ); reply << m_pMainConfig->GetServerName (); // game type reply << ( unsigned char ) ( m_strGameType.length() + 1 ); reply << m_strGameType; // map name reply << ( unsigned char ) ( m_strMapName.length() + 1 ); reply << m_strMapName; // version temp << MTA_DM_ASE_VERSION; reply << ( unsigned char ) ( temp.str().length() + 1 ); reply << temp.str(); // passworded reply << ( unsigned char ) 2; reply << ( ( m_pMainConfig->HasPassword () ) ? 1 : 0 ); // players count temp.str ( "" ); temp << m_pPlayerManager->CountJoined (); reply << ( unsigned char ) ( temp.str().length () + 1 ); reply << temp.str(); // players max temp.str ( "" ); temp << m_pMainConfig->GetMaxPlayers (); reply << ( unsigned char ) ( temp.str().length () + 1 ); reply << temp.str(); // rules list < CASERule* > ::iterator rIter = IterBegin (); for ( ; rIter != IterEnd () ; rIter++ ) { // maybe use a map and std strings for rules? reply << ( unsigned char ) ( strlen ( (*rIter)->GetKey () ) + 1 ); reply << (*rIter)->GetKey (); reply << ( unsigned char ) ( strlen ( (*rIter)->GetValue () ) + 1 ); reply << (*rIter)->GetValue (); } reply << ( unsigned char ) 1; // players // the flags that tell what data we carry per player ( apparently we need all set cause of GM atm ) unsigned char ucFlags = 0; ucFlags |= 0x01; // nick ucFlags |= 0x02; // team ucFlags |= 0x04; // skin ucFlags |= 0x08; // score ucFlags |= 0x16; // ping ucFlags |= 0x32; // time char szTemp[256] = { '\0' }; CPlayer* pPlayer = NULL; list < CPlayer* > ::const_iterator pIter = m_pPlayerManager->IterBegin (); for ( ; pIter != m_pPlayerManager->IterEnd (); pIter++ ) { pPlayer = *pIter; if ( pPlayer->IsJoined () ) { reply << ucFlags; // nick std::string strPlayerName = RemoveColorCodes ( pPlayer->GetNick () ); if ( strPlayerName.length () == 0 ) strPlayerName = pPlayer->GetNick (); reply << ( unsigned char ) ( strPlayerName.length () + 1 ); reply << strPlayerName.c_str (); // team (skip) reply << ( unsigned char ) 1; // skin (skip) reply << ( unsigned char ) 1; // score const std::string& strScore = pPlayer->GetAnnounceValue ( "score" ); reply << ( unsigned char ) ( strScore.length () + 1 ); reply << strScore.c_str (); // ping snprintf ( szTemp, 255, "%u", pPlayer->GetPing () ); reply << ( unsigned char ) ( strlen ( szTemp ) + 1 ); reply << szTemp; // time (skip) reply << ( unsigned char ) 1; } } return reply.str(); }
void CAreaManager::UpdateEntity(Vec3 const& rPos, IEntity const* const pEntity) { EntityId const nEntityID = pEntity->GetId(); SAreasCache* pAreaCache = GetAreaCache(nEntityID); // Create a new area cache if necessary. if (pAreaCache == NULL) { pAreaCache = MakeAreaCache(nEntityID); } assert(pAreaCache != NULL); // Audio listeners and moving entities affected by environment changes need to update more often // to ensure smooth fading. uint32 const nExtendedFlags = pEntity->GetFlagsExtended(); float const fPosDelta = ((nExtendedFlags & ENTITY_FLAG_EXTENDED_AUDIO_LISTENER) != 0) || ((nExtendedFlags & ENTITY_FLAG_EXTENDED_NEEDS_MOVEINSIDE) != 0) ? 0.01f : CVar::es_EntityUpdatePosDelta; if (pAreaCache != NULL && !rPos.IsEquivalent(pAreaCache->vLastUpdatePos, fPosDelta)) { pAreaCache->vLastUpdatePos = rPos; // First mark all cache entries that as if they are not in the grid. TAreaCacheVector::iterator Iter(pAreaCache->aoAreas.begin()); TAreaCacheVector::const_iterator IterEnd(pAreaCache->aoAreas.end()); for (; Iter != IterEnd; ++Iter) { SAreaCacheEntry& rAreaCacheEntry = (*Iter); CArea* const pArea = rAreaCacheEntry.pArea; #if defined(DEBUG_AREAMANAGER) if (!stl::find(m_apAreas, pArea)) { CryFatalError("<AreaManager>: area in entity-area-cache not found in overall areas list!"); } #endif // DEBUG_AREAMANAGER rAreaCacheEntry.bInGrid = false; // Now pre-calculate position data. pArea->InvalidateCachedAreaData(nEntityID); pArea->CalcPosType(nEntityID, rPos); } TAreaPointers const& rAreasAtPos(m_areaGrid.GetAreas(rPos)); TAreaPointers::const_iterator IterAreas(rAreasAtPos.begin()); TAreaPointers::const_iterator const IterAreasEnd(rAreasAtPos.end()); for (; IterAreas != IterAreasEnd; ++IterAreas) { // Mark cache entries as if they are in the grid. CArea* const pArea = *IterAreas; SAreaCacheEntry* pAreaCacheEntry = NULL; if (pAreaCache->GetCacheEntry(pArea, &pAreaCacheEntry)) { // cppcheck-suppress nullPointer pAreaCacheEntry->bInGrid = true; } else { // if they are not yet in the cache, add them pAreaCache->aoAreas.push_back(SAreaCacheEntry(pArea, false, false)); pArea->OnAddedToAreaCache(pEntity); } #if defined(DEBUG_AREAMANAGER) if (!stl::find(m_apAreas, pArea)) { CryFatalError("<AreaManager>: area in entity-area-cache not found in overall areas list!"); } #endif // DEBUG_AREAMANAGER } // Go through all cache entries and process the areas. Iter = pAreaCache->aoAreas.begin(); IterEnd = pAreaCache->aoAreas.end(); for (; Iter != IterEnd; ++Iter) { SAreaCacheEntry& rAreaCacheEntry = (*Iter); CArea* const pArea = rAreaCacheEntry.pArea; #if defined(DEBUG_AREAMANAGER) if (!stl::find(m_apAreas, pArea)) { CryFatalError("<AreaManager>: area in entity-area-cache not found in overall areas list!"); } #endif // DEBUG_AREAMANAGER // check if Area is hidden IEntity const* const pAreaEntity = m_pEntitySystem->GetEntity(pArea->GetEntityID()); bool bIsHidden = (pAreaEntity && pAreaEntity->IsHidden()); // area was just hidden if (bIsHidden && pArea->IsActive()) { pArea->LeaveArea(pEntity); pArea->LeaveNearArea(pEntity); rAreaCacheEntry.bNear = false; rAreaCacheEntry.bInside = false; pArea->SetActive(false); continue; } // area was just unhidden if (!bIsHidden && !pArea->IsActive()) { // ProcessArea will take care of properly setting cache entry data. rAreaCacheEntry.bNear = false; rAreaCacheEntry.bInside = false; pArea->SetActive(true); } // We process only for active areas in which grid we are. // Areas in our cache in which grid we are not get removed down below anyhow. if (pArea->IsActive()) { ProcessArea(pArea, rAreaCacheEntry, pAreaCache, rPos, pEntity); } } // Go through all areas again and send accumulated events. (needs to be done in a separate step) Iter = pAreaCache->aoAreas.begin(); for (; Iter != IterEnd; ++Iter) { SAreaCacheEntry& rAreaCacheEntry = (*Iter); CArea* const pArea = rAreaCacheEntry.pArea; #if defined(DEBUG_AREAMANAGER) if (!stl::find(m_apAreas, pArea)) { CryFatalError("<AreaManager>: area in entity-area-cache not found in overall areas list!"); } #endif // DEBUG_AREAMANAGER pArea->SendCachedEventsFor(nEntityID); } // Remove all entries in the cache which are no longer in the grid. if (!pAreaCache->aoAreas.empty()) { pAreaCache->aoAreas.erase(std::remove_if(pAreaCache->aoAreas.begin(), pAreaCache->aoAreas.end(), SIsNotInGrid(pEntity, m_apAreas, m_apAreas.size())), pAreaCache->aoAreas.end()); } if (pAreaCache->aoAreas.empty()) { DeleteAreaCache(nEntityID); } } }