void CStimResponseCollection::Restore(idRestoreGame *savefile) { int num; savefile->ReadInt(num); m_Stims.SetNum(num); for (int i = 0; i < num; i++) { // Allocate a new stim class (according to the type info) int typeInt; savefile->ReadInt(typeInt); m_Stims[i] = CStimPtr(new CStim(NULL, static_cast<StimType>(typeInt), -1)); m_Stims[i]->Restore(savefile); } savefile->ReadInt(num); m_Responses.SetNum(num); for (int i = 0; i < num; i++) { // Allocate a new response class (according to the type info) int typeInt; savefile->ReadInt(typeInt); m_Responses[i] = CResponsePtr(new CResponse(NULL, static_cast<StimType>(typeInt), -1)); m_Responses[i]->Restore(savefile); } }
CResponsePtr CStimResponseCollection::GetResponseByType( StimType type ) { for( int i = 0; i < m_Responses.Num(); ++i ) { if( m_Responses[i]->m_StimTypeId == type ) { return m_Responses[i]; } } return CResponsePtr(); }
//-------------------------------------------------------------------// bool CGateway::GetResponse(CRequestKeyPtr key, ResponseTypeEnum type, CResponsePtr &response) { CAutoLock lock(m_dataLock); bool __isExist = true; if (m_spData) { CDataColl::iterator it = m_spData->find(key); CResponseCollPtr spResponseColl; if (m_spData->end() == it){ spResponseColl = CResponseCollPtr(new CResponseColl); (*m_spData)[key] = spResponseColl; __isExist = false; } else{ spResponseColl = it->second; }; CResponsePtr spResponse; CResponseColl::iterator itRespone = spResponseColl->find(type); if (spResponseColl->end() == itRespone){ if (enQuotesResponse == type) spResponse = CResponsePtr(new CQuoteResponse(type, key)); else if (enRisksResponse == type) spResponse = CResponsePtr(new CRisksResponse(type, key)); if (spResponse) { (*spResponseColl)[type] = spResponse; __isExist = false; } } else{ spResponse = itRespone->second; } if (spResponse) response = spResponse; } return __isExist; };
CResponsePtr CStimResponseCollection::CreateResponse( idEntity *p_owner, StimType type ) { // Increase the counter to the next ID gameLocal.m_HighestSRId++; DM_LOG( LC_STIM_RESPONSE, LT_DEBUG )LOGSTRING( "Creating Response with ID: %d\r", gameLocal.m_HighestSRId ); // Optimization: Set contents to include CONTENTS_RESPONSE p_owner->GetPhysics()->SetContents( p_owner->GetPhysics()->GetContents() | CONTENTS_RESPONSE ); //DM_LOG(LC_STIM_RESPONSE, LT_DEBUG)LOGSTRING("Creating CResponse\r"); return CResponsePtr( new CResponse( p_owner, type, gameLocal.m_HighestSRId ) ); }