Ejemplo n.º 1
0
///////////////////////////////////////////////////////////////
//
// CDatabaseJobQueueImpl::FreeCommand
//
// Throw away result when this job is done
// Returns false if jobHandle not correct
//
///////////////////////////////////////////////////////////////
bool CDatabaseJobQueueImpl::FreeCommand ( CDbJobData* pJobData )
{
    if ( !MapContains ( m_ActiveJobHandles, pJobData->GetId () ) )
    {
        CLogger::ErrorPrintf ( "FreeCommand: Serious problem #1 here\n" );
        return false;
    }

    if ( pJobData->result.bIgnoreResult )
        return false;       // Already ignoring query handle

    // if in command or result queue, then put in ignore result list
    bool bFound;
    shared.m_Mutex.Lock ();

    bFound = ListContains ( shared.m_CommandQueue, pJobData ) || ListContains ( shared.m_ResultQueue, pJobData );

    shared.m_Mutex.Unlock ();

    if ( !bFound )
    {
        // Must be in finished list
        if ( !MapContains ( m_FinishedList, pJobData ) )
            CLogger::ErrorPrintf ( "FreeCommand: Serious problem #2 here\n" );
        return false; 
    }

    IgnoreJobResults ( pJobData );
    return true;
}
///////////////////////////////////////////////////////////////
//
// CResourceFileDownloadManager::AddPendingFileDownload
//
// Add resource file to the list of files to be downloaded
//
///////////////////////////////////////////////////////////////
void CResourceFileDownloadManager::AddPendingFileDownload(CDownloadableResource* pResourceFile)
{
    assert(!ListContains(m_PendingFileDownloadList, pResourceFile));
    assert(!ListContains(m_ActiveFileDownloadList, pResourceFile));
    m_PendingFileDownloadList.push_back(pResourceFile);
    pResourceFile->SetIsWaitingForDownload(true);
    AddDownloadSize(pResourceFile->GetDownloadSize());
}
Ejemplo n.º 3
0
///////////////////////////////////////////////////////////////
//
// CClientPerfStatManagerImpl::AddModule
//
//
//
///////////////////////////////////////////////////////////////
void CClientPerfStatManagerImpl::AddModule(CClientPerfStatModule* pModule)
{
    if (!ListContains(m_ModuleList, pModule))
    {
        m_ModuleList.push_back(pModule);
    }
}
Ejemplo n.º 4
0
CLuaTimer* CLuaTimerManager::GetTimerFromScriptID ( uint uiScriptID )
{
    CLuaTimer* pLuaTimer = (CLuaTimer*) CIdArray::FindEntry ( uiScriptID, EIdClass::TIMER );
    if ( !pLuaTimer )
        return NULL;

    if ( !ListContains ( m_TimerList, pLuaTimer ) )
        return NULL;
    return pLuaTimer;
}
Ejemplo n.º 5
0
///////////////////////////////////////////////////////////////
//
// CCompressorJobQueueImpl::DoPulse
//
// Check if any callback functions are due
//
///////////////////////////////////////////////////////////////
void CCompressorJobQueueImpl::DoPulse ( void )
{
    shared.m_Mutex.Lock ();

again:
    // Delete finished
    for ( std::set < CCompressJobData* >::iterator iter = m_FinishedList.begin () ; iter != m_FinishedList.end () ; )
    {
        CCompressJobData* pJobData = *iter;
        m_FinishedList.erase ( iter++ );
        // Check not refed
        assert ( !ListContains ( shared.m_CommandQueue, pJobData ) );
        assert ( !ListContains ( shared.m_ResultQueue, pJobData ) );
        assert ( !MapContains ( m_IgnoreResultList, pJobData ) );
        assert ( !MapContains ( m_FinishedList, pJobData ) );

        assert ( !pJobData->HasCallback () );
        SAFE_DELETE( pJobData );
    }

    // Remove ignored
    RemoveUnwantedResults ();

    // Do pending callbacks
    for ( std::list < CCompressJobData* >::iterator iter = shared.m_ResultQueue.begin () ; iter != shared.m_ResultQueue.end () ; ++iter )
    {
        CCompressJobData* pJobData = *iter;

        if ( pJobData->HasCallback () )
        {
            shared.m_Mutex.Unlock ();
            pJobData->ProcessCallback ();
            shared.m_Mutex.Lock ();

            // Redo from the top to ensure everything is consistent
            goto again;
        }
    }

    shared.m_Mutex.Unlock ();
}
///////////////////////////////////////////////////////////////
//
// CResourceFileDownloadManager::DownloadFinished
//
// Callback when file download has finished
//
///////////////////////////////////////////////////////////////
void CResourceFileDownloadManager::DownloadFinished(const SHttpDownloadResult& result)
{
    CDownloadableResource* pResourceFile = ResolveDownloadContextString((SString*)result.pObj);
    if (!pResourceFile)
        return;

    assert(ListContains(m_ActiveFileDownloadList, pResourceFile));
    if (result.bSuccess)
    {
        CChecksum checksum = CChecksum::GenerateChecksumFromFile(pResourceFile->GetName());
        if (checksum != pResourceFile->GetServerChecksum())
        {
            // Checksum failed - Try download on next server
            if (BeginResourceFileDownload(pResourceFile, pResourceFile->GetHttpServerIndex() + 1))
            {
                // Was re-added - Add size again to total.
                AddDownloadSize(pResourceFile->GetDownloadSize());
                SString strMessage("External HTTP file mismatch (Retrying this file with internal HTTP) [%s]", *ConformResourcePath(pResourceFile->GetName()));
                g_pClientGame->TellServerSomethingImportant(1011, strMessage, 3);
                return;
            }
        }
    }
    else
    {
        // Download failed due to connection type problem
        CNetHTTPDownloadManagerInterface* pHTTP = g_pNet->GetHTTPDownloadManager(m_HttpServerList[pResourceFile->GetHttpServerIndex()].downloadChannel);
        SString                           strHTTPError = pHTTP->GetError();
        // Disable server from being used (if possible)
        if (DisableHttpServer(pResourceFile->GetHttpServerIndex()))
        {
            //  Try download on next server
            if (BeginResourceFileDownload(pResourceFile, pResourceFile->GetHttpServerIndex() + 1))
            {
                // Was re-added - Add size again to total.
                AddDownloadSize(pResourceFile->GetDownloadSize());
                SString strMessage("External HTTP file download error:[%d] %s (Disabling External HTTP) [%s]", result.iErrorCode, *strHTTPError,
                                   *ConformResourcePath(pResourceFile->GetName()));
                g_pClientGame->TellServerSomethingImportant(1012, strMessage, 3);
                return;
            }
        }
        m_strLastHTTPError = strHTTPError;
    }

    // File now done (or failed)
    ListRemove(m_ActiveFileDownloadList, pResourceFile);
    pResourceFile->SetIsWaitingForDownload(false);
}
Ejemplo n.º 7
0
///////////////////////////////////////////////////////////////
//
// CCompressorJobQueueImpl::FreeCommand
//
// Throw away result when this job is done
// Returns false if jobHandle not correct
//
///////////////////////////////////////////////////////////////
bool CCompressorJobQueueImpl::FreeCommand ( CCompressJobData* pJobData )
{
    if ( MapContains ( m_IgnoreResultList, pJobData ) )
        return false;       // Already ignoring query handle

    // if in command or result queue, then put in ignore result list
    bool bFound;
    shared.m_Mutex.Lock ();

    bFound = ListContains ( shared.m_CommandQueue, pJobData ) || ListContains ( shared.m_ResultQueue, pJobData );

    shared.m_Mutex.Unlock ();

    if ( !bFound )
    {
        // Must be in finished list
        if ( !MapContains ( m_FinishedList, pJobData ) )
            OutputDebugLine ( "FreeCommand: Serious problem #2 here\n" );
        return false; 
    }

    IgnoreJobResults ( pJobData );
    return true;
}
Ejemplo n.º 8
0
void CLuaTimerManager::RemoveTimer ( CLuaTimer* pLuaTimer )
{
    assert ( pLuaTimer );

    // Check if already removed
    if ( !ListContains ( m_TimerList, pLuaTimer ) )
        return;

    // Remove all references
    ListRemove ( m_TimerList, pLuaTimer );
    ListRemove ( m_ProcessQueue, pLuaTimer );

    if ( m_pProcessingTimer == pLuaTimer )
    {
        assert ( !m_pPendingDelete );
        pLuaTimer->RemoveScriptID ();
        m_pPendingDelete = pLuaTimer;
    }
    else
        delete pLuaTimer;
}
Ejemplo n.º 9
0
bool CObject::SetLowLodObject ( CObject* pNewLowLodObject )
{
    // This object has to be high lod
    if ( m_bIsLowLod )
        return false;

    // Set or clear?
    if ( !pNewLowLodObject )
    {
        // Check if already clear
        if ( !m_pLowLodObject )
            return false;

        // Verify link
        assert ( ListContains ( m_pLowLodObject->m_HighLodObjectList, this ) );

        // Clear there and here
        ListRemove ( m_pLowLodObject->m_HighLodObjectList, this );
        m_pLowLodObject = NULL;
        return true;
    }
    else
    {
        // new object has to be low lod
        if ( !pNewLowLodObject->m_bIsLowLod )
            return false;

        // Remove any previous link
        SetLowLodObject ( NULL );

        // Make new link
        m_pLowLodObject = pNewLowLodObject;
        pNewLowLodObject->m_HighLodObjectList.push_back ( this );
        return true;
    }
}
Ejemplo n.º 10
0
bool CPedManager::Exists(CPed* pPed)
{
    return ListContains(m_List, pPed);
}
Ejemplo n.º 11
0
bool CElementDeleter::IsBeingDeleted ( CElement* pElement )
{
    return ListContains ( m_List, pElement );
}
Ejemplo n.º 12
0
CAccountManager::CAccountManager ( const SString& strDbPathFilename )
    : m_AccountProtect( 6, 30000, 60000 * 1 )     // Max of 6 attempts per 30 seconds, then 1 minute ignore
{
    m_llLastTimeSaved = GetTickCount64_ ();
    m_bChangedSinceSaved = false;
    m_iAccounts = 1;
    m_pDatabaseManager = g_pGame->GetDatabaseManager ();
    m_strDbPathFilename = strDbPathFilename;
    m_hDbConnection = INVALID_DB_HANDLE;

    //Load internal.db
    ReconnectToDatabase();

    // Check if new installation
    CRegistryResult result;
	m_pDatabaseManager->QueryWithResultf ( m_hDbConnection, &result, "SELECT name FROM sqlite_master WHERE type='table' AND name='accounts'" );
    bool bNewInstallation = ( result->nRows == 0 );

    //Create all our tables (Don't echo the results)
    m_pDatabaseManager->Execf ( m_hDbConnection, "CREATE TABLE IF NOT EXISTS accounts (id INTEGER PRIMARY KEY, name TEXT, password TEXT, ip TEXT, serial TEXT)" );
    m_pDatabaseManager->Execf ( m_hDbConnection, "CREATE TABLE IF NOT EXISTS userdata (id INTEGER PRIMARY KEY, userid INTEGER, key TEXT, value TEXT, type INTEGER)" );
    m_pDatabaseManager->Execf ( m_hDbConnection, "CREATE TABLE IF NOT EXISTS serialusage (id INTEGER PRIMARY KEY, userid INTEGER, "
                                                                                                "serial TEXT, "
                                                                                                "added_ip TEXT, "
                                                                                                "added_date INTEGER, "
                                                                                                "auth_who INTEGER, "
                                                                                                "auth_date INTEGER, "
                                                                                                "last_login_ip TEXT, "
                                                                                                "last_login_date INTEGER, "
                                                                                                "last_login_http_date INTEGER )" );
    m_pDatabaseManager->Execf ( m_hDbConnection, "CREATE INDEX IF NOT EXISTS IDX_SERIALUSAGE_USERID on serialusage(userid)" );
    m_pDatabaseManager->Execf ( m_hDbConnection, "CREATE UNIQUE INDEX IF NOT EXISTS IDX_SERIALUSAGE_USERID_SERIAL_U on serialusage(userid,serial)" );

    // Check if unique index on accounts exists
	m_pDatabaseManager->QueryWithResultf ( m_hDbConnection, &result, "SELECT name FROM sqlite_master WHERE type='index' AND name='IDX_ACCOUNTS_NAME_U'" );
    if ( result->nRows == 0 )
    {
        // Need to add unique index on accounts
        if ( !bNewInstallation )
            CLogger::LogPrintNoStamp ( "Updating accounts table...\n" );

        // Make sure we have a non-unique index to speed up the duplication removal
	    m_pDatabaseManager->Execf ( m_hDbConnection, "CREATE INDEX IF NOT EXISTS IDX_ACCOUNTS_NAME on accounts(name)" );
        // Remove any duplicate name entries
	    m_pDatabaseManager->Execf ( m_hDbConnection, "DELETE FROM accounts WHERE rowid in "
						                                " (SELECT A.rowid"
						                                " FROM accounts A, accounts B"
						                                " WHERE A.rowid > B.rowid AND A.name = B.name)" );
        // Remove non-unique index
        m_pDatabaseManager->Execf ( m_hDbConnection, "DROP INDEX IF EXISTS IDX_ACCOUNTS_NAME" );
        // Add unique index
	    m_pDatabaseManager->Execf ( m_hDbConnection, "CREATE UNIQUE INDEX IF NOT EXISTS IDX_ACCOUNTS_NAME_U on accounts(name)" );
    }

    // Check if unique index on userdata exists
	m_pDatabaseManager->QueryWithResultf ( m_hDbConnection, &result, "SELECT name FROM sqlite_master WHERE type='index' AND name='IDX_USERDATA_USERID_KEY_U'" );
    if ( result->nRows == 0 )
    {
        // Need to add unique index on userdata
        if ( !bNewInstallation )
            CLogger::LogPrintNoStamp ( "Updating userdata table...\n" );

        // Make sure we have a non-unique index to speed up the duplication removal
	    m_pDatabaseManager->Execf ( m_hDbConnection, "CREATE INDEX IF NOT EXISTS IDX_USERDATA_USERID_KEY on userdata(userid,key)" );
        // Remove any duplicate userid+key entries
	    m_pDatabaseManager->Execf ( m_hDbConnection, "DELETE FROM userdata WHERE rowid in "
						                                " (SELECT A.rowid"
						                                " FROM userdata A, userdata B"
						                                " WHERE A.rowid > B.rowid AND A.userid = B.userid AND A.key = B.key)" );
        // Remove non-unique index
        m_pDatabaseManager->Execf ( m_hDbConnection, "DROP INDEX IF EXISTS IDX_USERDATA_USERID_KEY" );
        // Add unique index
	    m_pDatabaseManager->Execf ( m_hDbConnection, "CREATE UNIQUE INDEX IF NOT EXISTS IDX_USERDATA_USERID_KEY_U on userdata(userid,key)" );
    }

    // Ensure old indexes are removed
    m_pDatabaseManager->Execf ( m_hDbConnection, "DROP INDEX IF EXISTS IDX_ACCOUNTS_NAME" );
    m_pDatabaseManager->Execf ( m_hDbConnection, "DROP INDEX IF EXISTS IDX_USERDATA_USERID" );
    m_pDatabaseManager->Execf ( m_hDbConnection, "DROP INDEX IF EXISTS IDX_USERDATA_USERID_KEY" );

    // Check if httppass has been added yet
	m_pDatabaseManager->QueryWithResultf(m_hDbConnection, &result, "PRAGMA table_info(accounts)");
    if (ListContains(result->ColNames, "httppass") == false)
    {
        m_pDatabaseManager->Execf(m_hDbConnection, "ALTER TABLE accounts ADD COLUMN httppass TEXT");
    }
}
Ejemplo n.º 13
0
CAccount* CAccountManager::GetAccountFromScriptID ( uint uiScriptID )
{
    CAccount* pAccount = (CAccount*) CIdArray::FindEntry ( uiScriptID, EIdClass::ACCOUNT );
    dassert ( !pAccount || ListContains ( m_List, pAccount ) );
    return pAccount;
}
Ejemplo n.º 14
0
bool CRadarAreaManager::Exists ( CRadarArea* pArea )
{
    return ListContains ( m_List, pArea );
}
Ejemplo n.º 15
0
///////////////////////////////////////////////////////////////
//
// CDatabaseJobQueueImpl::DoPulse
//
// Check if any callback functions are due
//
///////////////////////////////////////////////////////////////
void CDatabaseJobQueueImpl::DoPulse ( void )
{
    // Check if any connection needs a flush
    while ( m_PendingFlushMap.size () )
    {
        SConnectionHandle connectionHandle = *m_PendingFlushMap.begin ();
        MapRemove ( m_PendingFlushMap, connectionHandle );
        CDbJobData* pJobData = AddCommand ( EJobCommand::FLUSH, connectionHandle, "" );
        FreeCommand ( pJobData );
    }

    shared.m_Mutex.Lock ();

again:
    // Delete finished
    for ( std::set < CDbJobData* >::iterator iter = m_FinishedList.begin () ; iter != m_FinishedList.end () ; )
    {
        CDbJobData* pJobData = *iter;
        m_FinishedList.erase ( iter++ );
        // Check not refed
        dassert ( !ListContains ( shared.m_CommandQueue, pJobData ) );
        dassert ( !ListContains ( shared.m_ResultQueue, pJobData ) );
        dassert ( !MapContains ( m_FinishedList, pJobData ) );

        dassert ( MapContains ( m_ActiveJobHandles, pJobData->GetId () ) );
        MapRemove ( m_ActiveJobHandles, pJobData->GetId () );
        dassert ( !pJobData->HasCallback () );
        SAFE_DELETE( pJobData );
        g_pStats->iDbJobDataCount--;
    }

    // Do pending callbacks
    for ( CJobQueueType::iterator iter = shared.m_ResultQueue.begin () ; iter != shared.m_ResultQueue.end () ; )
    {
        CDbJobData* pJobData = *iter;

        if ( pJobData->result.bIgnoreResult )
        {
            // Ignored results won't be collected, so move to finished list here
            iter = shared.m_ResultQueue.erase ( iter );
            pJobData->stage = EJobStage::FINISHED;
            MapInsert ( m_FinishedList, pJobData );
            // Still allow callback incase any cleanup is needed
        }
        else
            ++iter;

        if ( pJobData->HasCallback () )
        {
            shared.m_Mutex.Unlock ();
            pJobData->ProcessCallback ();              
            shared.m_Mutex.Lock ();

            // Redo from the top ensure everything is consistent
            goto again;
        }
    }

    shared.m_Mutex.Unlock ();

    UpdateDebugData ();
}
Ejemplo n.º 16
0
CTextItem* CLuaMain::GetTextItemFromScriptID ( uint uiScriptID )
{
    CTextItem* pTextItem = (CTextItem*) CIdArray::FindEntry ( uiScriptID, EIdClass::TEXT_ITEM );
    dassert ( !pTextItem || ListContains ( m_TextItems, pTextItem ) );
    return pTextItem;
}
Ejemplo n.º 17
0
bool CTeamManager::Exists(CTeam* pTeam)
{
    return ListContains(m_List, pTeam);
}
CAccessControlList* CAccessControlListManager::GetACLFromScriptID ( uint uiScriptID )
{
    CAccessControlList* pACL = (CAccessControlList*) CIdArray::FindEntry ( uiScriptID, EIdClass::ACL );
    dassert ( !pACL || ListContains ( m_ACLs, pACL ) );
    return pACL;
}
Ejemplo n.º 19
0
bool CClientObjectManager::Exists ( CClientObject* pObject )
{
    return ListContains( m_Objects, pObject );
}
////////////////////////////////////////////////////////////////
//
// CRenderWareSA::ModelInfoTXDAddTextures
//
// Adds texture into the TXD of a model.
// Returns true if model was affected.
//
////////////////////////////////////////////////////////////////
bool CRenderWareSA::ModelInfoTXDAddTextures ( SReplacementTextures* pReplacementTextures, ushort usModelId )
{
    // Already done for this modelid?
    if ( ListContains ( pReplacementTextures->usedInModelIds, usModelId ) )
        return false;

    // Get valid textures info for this model
    CModelTexturesInfo* pInfo = GetModelTexturesInfo ( usModelId );
    if ( !pInfo )
        return false;

    // Remember which models this set has been applied to
    pReplacementTextures->usedInModelIds.push_back ( usModelId );

    // Already done for this txd?
    if ( ListContains ( pReplacementTextures->usedInTxdIds, pInfo->usTxdId ) )
        return true;    // Return true as model may need restreaming

    //
    // Add section for this txd
    //
    pReplacementTextures->perTxdList.push_back ( SReplacementTextures::SPerTxd () );
    SReplacementTextures::SPerTxd& perTxdInfo = pReplacementTextures->perTxdList.back ();

    perTxdInfo.usTxdId = pInfo->usTxdId;
    perTxdInfo.bTexturesAreCopies = ( pReplacementTextures->usedInTxdIds.size () > 0 );

    // Copy / clone textures
    for ( std::vector < RwTexture* >::iterator iter = pReplacementTextures->textures.begin () ; iter != pReplacementTextures->textures.end () ; iter++ )
    {
        RwTexture* pNewTexture = *iter;

        // Use a copy if not first txd
        if ( perTxdInfo.bTexturesAreCopies )
        {
            // Reuse the given texture's raster
            RwTexture* pCopyTex = RwTextureCreate ( pNewTexture->raster );

            // Copy over additional properties
            MemCpyFast ( &pCopyTex->name, &pNewTexture->name, RW_TEXTURE_NAME_LENGTH );
            MemCpyFast ( &pCopyTex->mask, &pNewTexture->mask, RW_TEXTURE_NAME_LENGTH );
            pCopyTex->flags = pNewTexture->flags;
            
            pNewTexture = pCopyTex;
        }
        perTxdInfo.usingTextures.push_back ( pNewTexture );
    }

    //
    // Add each texture to the target txd
    //
    for ( std::vector < RwTexture* >::iterator iter = perTxdInfo.usingTextures.begin () ; iter != perTxdInfo.usingTextures.end () ; iter++ )
    {
        RwTexture* pNewTexture = *iter;

        // If there is a name clash with an existing texture, replace it
        RwTexture* pExistingTexture = RwTexDictionaryFindNamedTexture ( pInfo->pTxd, pNewTexture->name );
        if ( pExistingTexture )
        {
            RwTexDictionaryRemoveTexture ( pInfo->pTxd, pExistingTexture );
        }

        // Add the texture
        dassert ( !RwTexDictionaryContainsTexture ( pInfo->pTxd, pNewTexture ) );
        RwTexDictionaryAddTexture ( pInfo->pTxd, pNewTexture );
    }

    // Remember which txds this set has been applied to
    pReplacementTextures->usedInTxdIds.push_back ( pInfo->usTxdId );
    dassert ( !ListContains ( pInfo->usedByReplacements, pReplacementTextures ) );
    pInfo->usedByReplacements.push_back ( pReplacementTextures );
    return true;
}
Ejemplo n.º 21
0
bool CObjectManager::Exists ( CObject* pObject )
{
    return ListContains ( m_List, pObject );
}
Ejemplo n.º 22
0
bool CPickupManager::Exists(CPickup* pPickup)
{
    return ListContains(m_List, pPickup);
}
Ejemplo n.º 23
0
/*
	Looks for energy sources that can potentially drive an opamp feedback branch.
	*/
void circuit_t::LookForOpampDrivingSources (const node_t* start, const node_t* output,
											 list<branch_t*>& covered_branches, list<element_t*>& energy_sources) const	
{
	/*
		To keep track of how many energy sources we found
		*/
	unsigned int initial_energy_source_count = energy_sources.size();
		
	/*
		First, we get a list of all branches going in/out of the starting aid.
		*/
	list<branch_t*> all_branches = start->VirtualBranchList();
	
	/*
		Special case: no branches exist, look for sources connected directly to the terminal
		*/
	if (all_branches.size() == 0)
	{
		
		
		
		// Search for VSRC whose actnode is this
		for (list<element_t*>::const_iterator e = start->elements.begin(); e != start->elements.end(); e++)
		{
			element_t* elm = (*e);
			
			
			/* Look for energy sources */
			if ((elm->type == E_VSRC || elm->type == E_CSRC)
				&& (elm->OtherNode (start) != output))
				energy_sources.push_back (elm);				
		} /* for */
		
		/* Look for opamp sources */
		if (start->IsOpampOutput())
			for (list<element_t*>::const_iterator e = start->elements.begin(); e != start->elements.end(); e++)
			{
				element_t* elm = (*e);
				if (elm->type == E_OPAMP_INV)
					energy_sources.push_back (elm);		
			} /* for */
			
	} /* if */
	else
	{
		/*
			An array to store filtered results in 
			*/
		list<branch_t*> filtered_results;
			
		/*
			If checks for energy sources in this actnode's branches 
			fail, we will run recursively until all a source is found
			or all branches have been tried.
		*/	
		for (list<branch_t*>::const_iterator b = all_branches.begin(); b != all_branches.end(); b++)
		{
			/*
				Filter out branches that go to the output node 
				*/
			if (((*b)->TopNode() == output)
				 || ((*b)->BottomNode() == output)
				 ||  ListContains (covered_branches, *b ))
				 continue;

			filtered_results.push_back (*b);
						
			/*
				We now have a list of branches that we know don't come from or
				go to the output node. 
				
				We first check the remaining branches for energy sources;
			*/
			if ((*b)->HasElement (E_CSRC) || (*b)->HasElement (E_VSRC) || (*b)->HasElement (E_OPAMP_INV))
			{		
				list<element_t*> csrc_list = (*b)->GetElements (E_CSRC);
				list<element_t*> vsrc_list = (*b)->GetElements (E_VSRC);
				list<element_t*> ooi_list = (*b)->GetElements  (E_OPAMP_INV);
				
				energy_sources.insert (energy_sources.end(), csrc_list.begin(), csrc_list.end());
				energy_sources.insert (energy_sources.end(), vsrc_list.begin(), vsrc_list.end());
				energy_sources.insert (energy_sources.end(), ooi_list.begin(),  ooi_list.end());
				
			} /* if */		
		} /* for */
				
		/* 
			No immediate energy sources were found,
			re-iterate through all loops 
			*/
		if (initial_energy_source_count == energy_sources.size())
		{
			// Add all branches as covered branches
			for (list<branch_t*>::const_iterator b = filtered_results.begin(); b != filtered_results.end(); b++)
			{				
				covered_branches.push_back (*b);
				
			} /* for */
		
			// iterate through all actnodes
			for (list<branch_t*>::const_iterator b = filtered_results.begin(); b != filtered_results.end(); b++)
			{
				
				/* 
					Recursiveness 
					*/
				LookForOpampDrivingSources ((*b)->OtherSupernode (start), output, covered_branches, energy_sources);
			
			} /* for */	
		} /* if */
			
			
	} /* else */
	
} /* circuit_t::LookForOpampDrivingSources */
Ejemplo n.º 24
0
bool CVehicleManager::Exists ( CVehicle* pVehicle )
{
    return ListContains ( m_List, pVehicle );
}
Ejemplo n.º 25
0
void CScriptDebugging::OnLuaMainDestroy ( CLuaMain* pLuaMain )
{
    dassert ( !ListContains ( m_LuaMainStack, pLuaMain ) );
    ListRemove ( m_LuaMainStack, pLuaMain );
}
Ejemplo n.º 26
0
///////////////////////////////////////////////////////////////
//
// CDatabaseJobQueueImpl::PollCommand
//
// Find result for previous command
// Returns false if result not ready.
//
///////////////////////////////////////////////////////////////
bool CDatabaseJobQueueImpl::PollCommand ( CDbJobData* pJobData, uint uiTimeout )
{
    bool bFound = false;
    uint uiTotalWaitTime = 0;
    uint uiWaitTimeWarnThresh = TICKS_FROM_SECONDS( 60 );

    shared.m_Mutex.Lock ();
    while ( true )
    {
        // Should not be called for ignored results
        dassert ( !pJobData->result.bIgnoreResult );

        // Should not be called for collected results
        dassert ( pJobData->stage != EJobStage::FINISHED );

        // See if result has come in yet
        if ( ListContains( shared.m_ResultQueue, pJobData ) )
        {
            ListRemove( shared.m_ResultQueue, pJobData );

            pJobData->stage = EJobStage::FINISHED;
            MapInsert ( m_FinishedList, pJobData );

            // Do callback incase any cleanup is needed
            if ( pJobData->HasCallback () )
            {
                shared.m_Mutex.Unlock ();                 
                pJobData->ProcessCallback ();              
                shared.m_Mutex.Lock ();
            }

            bFound = true;
        }

        if ( bFound || uiTimeout == 0 )
        {
            shared.m_Mutex.Unlock ();
            break;
        }

        CElapsedTime timer;
        shared.m_Mutex.Wait (std::min( uiTimeout, 1000U ) );
        uint uiDelta = (uint)timer.Get() + 1;
        uiTotalWaitTime += uiDelta;

        // If not infinite, subtract time actually waited
        if ( uiTimeout != (uint)-1 )
        {
            if ( uiDelta < uiTimeout )
                uiTimeout -= uiDelta;
            else
                uiTimeout = 0;
        }

        // Issue warning if it's taking a long time
        if ( uiTotalWaitTime > uiWaitTimeWarnThresh )
        {
            shared.m_Mutex.Unlock ();
            g_pGame->GetScriptDebugging()->LogWarning( pJobData->m_LuaDebugInfo, "dbPoll is waiting a long time (%d seconds so far). [Query: %s]", uiTotalWaitTime / 1000, *pJobData->GetCommandStringForLog() );
            shared.m_Mutex.Lock ();
            uiWaitTimeWarnThresh += TICKS_FROM_SECONDS( 60 );
        }
    }

    // Make sure if wait was infinite, we have a result
    assert ( uiTimeout != (uint)-1 || bFound );

    return bFound;
}
Ejemplo n.º 27
0
CTextDisplay* CLuaMain::GetTextDisplayFromScriptID ( uint uiScriptID )
{
    CTextDisplay* pTextDisplay = (CTextDisplay*) CIdArray::FindEntry ( uiScriptID, EIdClass::TEXT_DISPLAY );
    dassert ( !pTextDisplay || ListContains ( m_Displays, pTextDisplay ) );
    return pTextDisplay;
}
////////////////////////////////////////////////////////////////
//
// CRenderWareSA::ModelInfoTXDRemoveTextures
//
// Remove the textures from the txds that are using them.
//
////////////////////////////////////////////////////////////////
void CRenderWareSA::ModelInfoTXDRemoveTextures ( SReplacementTextures* pReplacementTextures )
{
    // For each using txd
    for ( uint i = 0 ; i < pReplacementTextures->perTxdList.size () ; i++ )
    {
        SReplacementTextures::SPerTxd& perTxdInfo = pReplacementTextures->perTxdList[i];

        // Get textures info
        ushort usTxdId = perTxdInfo.usTxdId;
        CModelTexturesInfo* pInfo = MapFind ( ms_ModelTexturesInfoMap, usTxdId );

        // Validate
        dassert ( MapFind ( ms_ModelTexturesInfoMap, usTxdId ) );
        dassert ( ListContains ( pInfo->usedByReplacements, pReplacementTextures ) );

        // Remove replacement textures
        for ( uint i = 0 ; i < perTxdInfo.usingTextures.size () ; i++ )
        {
            RwTexture* pOldTexture = perTxdInfo.usingTextures[i];
            RwTexDictionaryRemoveTexture ( pInfo->pTxd, pOldTexture );
            dassert ( !RwTexDictionaryContainsTexture ( pInfo->pTxd, pOldTexture ) );
            if ( perTxdInfo.bTexturesAreCopies )
            {
                // Destroy the copy (but not the raster as that was not copied)
                pOldTexture->raster = NULL;
                RwTextureDestroy ( pOldTexture );
            }
        }

        // Ensure there are original named textures in the txd
        for ( uint i = 0 ; i < pInfo->originalTextures.size () ; i++ )
        {
            RwTexture* pOriginalTexture = pInfo->originalTextures[i];
            if ( !RwTexDictionaryFindNamedTexture ( pInfo->pTxd, pOriginalTexture->name ) )
                RwTexDictionaryAddTexture ( pInfo->pTxd, pOriginalTexture );
        }

        // Remove refs
        ListRemove ( pInfo->usedByReplacements, pReplacementTextures );

        // If no refs left, check original state and then remove info
        if ( pInfo->usedByReplacements.empty () )
        {
            // txd should now contain the same textures as 'originalTextures'
        #ifdef MTA_DEBUG
            std::vector < RwTexture* > currentTextures;
            GetTxdTextures ( currentTextures, pInfo->pTxd );
            assert ( currentTextures.size () == pInfo->originalTextures.size () );
            for ( uint i = 0 ; i < pInfo->originalTextures.size () ; i++ )
            {
                RwTexture* pOriginalTexture = pInfo->originalTextures[i];
                assert ( ListContains ( currentTextures, pOriginalTexture ) );
                ListRemove ( currentTextures, pOriginalTexture );
            }
            assert ( currentTextures.empty () );
        #endif

            // Remove info
            CTxdStore_RemoveRef ( pInfo->usTxdId );
            MapRemove ( ms_ModelTexturesInfoMap, usTxdId );
        }
    }

    // Destroy replacement textures
    for ( uint i = 0 ; i < pReplacementTextures->textures.size () ; i++ )
    {
        RwTexture* pOldTexture = pReplacementTextures->textures[i];
        DestroyTexture ( pOldTexture );
    }
    pReplacementTextures->textures.clear ();
}
CAccessControlListGroup* CAccessControlListManager::GetGroupFromScriptID ( uint uiScriptID )
{
    CAccessControlListGroup* pGroup = (CAccessControlListGroup*) CIdArray::FindEntry ( uiScriptID, EIdClass::ACL_GROUP );
    dassert ( !pGroup || ListContains ( m_Groups, pGroup ) );
    return pGroup;
}
Ejemplo n.º 30
0
bool CColManager::Exists ( CColShape* pShape )
{
    return ListContains ( m_List, pShape );
}