bool CClientModelRequestManager::Request ( unsigned short usModelID, CClientEntity* pRequester )
{
    assert ( pRequester );
    SClientModelRequest* pEntry;

    // Grab the model info for that model
    CModelInfo* pInfo = g_pGame->GetModelInfo ( usModelID );
    if ( pInfo )
    {
        // Has it already requested something?
        list < SClientModelRequest* > ::iterator iter;
        if ( GetRequestEntry ( pRequester, iter ) )
        {
            // Get the entry
            pEntry = *iter;

            // The same model?
            if ( pInfo == pEntry->pModel )
            {
                // He has to wait more for it
                return false;
            }
            else
            {
                // Remove the reference to the old model
                pEntry->pModel->RemoveRef ();

                // Is it loaded?
                if ( pInfo->IsLoaded () )
                {
                    // Delete it, remove the it from the list and return true.
                    delete pEntry;
                    m_Requests.erase ( iter );

                    pInfo->MakeCustomModel ();
                    return true;
                }
                else
                {
                    // If not loaded. Replace the model we're going to load.
                    // Also remember that we requested it now.
                    pEntry->pModel = pInfo;
                    pEntry->requestTimer.Reset ();

                    // Start loading the new model.
                    pInfo->ModelAddRef ( NON_BLOCKING, "CClientModelRequestManager::Request" );

                    // He has to wait for it.
                    return false;
                }
            }
        }
        else
        {
            // Already loaded? Don't bother adding to the list.
            if ( pInfo->IsLoaded () )
            {
                pInfo->MakeCustomModel ();

                return true;
            }

            // Request it
            pInfo->ModelAddRef ( NON_BLOCKING, "CClientModelRequestManager::Request #2" );

            // Add him to the list over models we're waiting for.
            pEntry = new SClientModelRequest;
            pEntry->pModel = pInfo;
            pEntry->pEntity = pRequester;
            pEntry->requestTimer.SetMaxIncrement ( 500 );
            pEntry->requestTimer.Reset ();
            m_Requests.push_back ( pEntry );

            // Return false. Caller needs to wait.
            return false;
        }
    }

    // Error, model is bad. Caller should not do this.
    return false;
}
Exemplo n.º 2
0
///////////////////////////////////////////////////////////////
//
// CModelCacheManagerImpl::AddModelRefCount
//
///////////////////////////////////////////////////////////////
void CModelCacheManagerImpl::AddModelRefCount ( ushort usModelId )
{
    CModelInfo* pModelInfo = m_pGame->GetModelInfo ( usModelId );
    if ( pModelInfo )
        pModelInfo->ModelAddRef ( NON_BLOCKING, "cache" );
}