Esempio n. 1
0
int main() {
	Stack st;
	int val;
	st.top = NULL;

	/* Stack test */

	StackPush(&st, 1);
	StackPush(&st, 2);
	StackPush(&st, 3);
	StackPush(&st, 4);
	StackPush(&st, 5);
	StackPush(&st, 6);
	StackPush(&st, 7);

	while ((val = StackPop(&st)) != -1)
		printf("%d\n", val);

	/* Hashmap test */

	Map map;
	MapInit(&map);
	MapInsert(&map, "1>", 1);
	MapInsert(&map, "2>", 2);
	MapInsert(&map, "3>", 3);
	MapInsert(&map, "4>", 4);
	MapInsert(&map, "5>", 5);
	MapInsert(&map, "6>", 6);
	MapInsert(&map, "7>", 7);
	MapInsert(&map, "8>", 8);
	MapInsert(&map, "9>", 9);

	printf("%d\n", MapGet(&map, "1>"));
	printf("%d\n", MapGet(&map, "2>"));
	printf("%d\n", MapGet(&map, "3>"));
	printf("%d\n", MapGet(&map, "4>"));
	printf("%d\n", MapGet(&map, "5>"));
	printf("%d\n", MapGet(&map, "6>"));
	printf("%d\n", MapGet(&map, "7>"));
	printf("%d\n", MapGet(&map, "8>"));
	printf("%d\n", MapGet(&map, "9>"));

	MapRemove(&map, "1>");
	printf("%d\n", MapGet(&map, "1>"));

	MapInsert(&map, "2>", 22);
	printf("%d\n", MapGet(&map, "2>"));
	MapRemove(&map, "2>");
	printf("%d\n", MapGet(&map, "2>"));

	return 0;
}
Esempio n. 2
0
void CPerPlayerEntity::AddPlayerReference(CPlayer* pPlayer)
{
    if (g_pGame->GetPlayerManager()->Exists(pPlayer))
        MapInsert(m_Players, pPlayer);
    else
        CLogger::ErrorPrintf("CPerPlayerEntity tried to add reference for non existing player: %08x\n", pPlayer);
}
Esempio n. 3
0
void CPerPlayerEntity::RemovePlayersBelow(CElement* pElement, std::set<CPlayer*>& Removed)
{
    assert(pElement);

    // Is this a player?
    if (IS_PLAYER(pElement))
    {
        // Remove the reference
        CPlayer* pPlayer = static_cast<CPlayer*>(pElement);
        RemovePlayerReference(pPlayer);

        // Did we just loose the last reference to that player? Add him to the list over removed players.
        if (!IsVisibleToPlayer(*pPlayer))
        {
            MapInsert(Removed, pPlayer);
        }
    }

    // Call ourself on all our children
    CChildListType ::const_iterator iterChildren = pElement->IterBegin();
    for (; iterChildren != pElement->IterEnd(); iterChildren++)
    {
        CElement* pElement = *iterChildren;
        if (pElement->CountChildren() || IS_PLAYER(pElement))            // This check reduces cpu usage when unloading large maps (due to recursion)
            RemovePlayersBelow(pElement, Removed);
    }
}
Esempio n. 4
0
void CPerPlayerEntity::AddPlayersBelow(CElement* pElement, std::set<CPlayer*>& Added)
{
    assert(pElement);

    // Is this a player?
    if (IS_PLAYER(pElement))
    {
        // Are we not already visible to that player? Add it to the list
        CPlayer* pPlayer = static_cast<CPlayer*>(pElement);
        if (!IsVisibleToPlayer(*pPlayer))
        {
            MapInsert(Added, pPlayer);
        }

        // Add it to our reference list
        AddPlayerReference(pPlayer);
    }

    // Call ourself on all its children elements
    CChildListType ::const_iterator iterChildren = pElement->IterBegin();
    for (; iterChildren != pElement->IterEnd(); iterChildren++)
    {
        CElement* pElement = *iterChildren;
        if (pElement->CountChildren() || IS_PLAYER(pElement))            // This check reduces cpu usage when loading large maps (due to recursion)
            AddPlayersBelow(pElement, Added);
    }
}
//
// Set hiddeness of a debug tag
//
void SharedUtil::SetDebugTagHidden ( const SString& strTag, bool bHidden  )
{
    if ( bHidden )
        MapInsert ( ms_debugTagInvisibleMap, strTag.ToLower () );
    else
        MapRemove ( ms_debugTagInvisibleMap, strTag.ToLower () );
}
Esempio n. 6
0
////////////////////////////////////////////////////////////////
//
// CRenderItemManager::NotifyShaderItemUsesDepthBuffer
//
//
//
////////////////////////////////////////////////////////////////
void CRenderItemManager::NotifyShaderItemUsesDepthBuffer ( CShaderItem* pShaderItem, bool bUsesDepthBuffer )
{
    if ( bUsesDepthBuffer )
        MapInsert ( m_ShadersUsingDepthBuffer, pShaderItem );
    else
        MapRemove ( m_ShadersUsingDepthBuffer, pShaderItem );
}
Esempio n. 7
0
////////////////////////////////////////////////////////////////
//
// CRenderItemManager::NotifyShaderItemUsesMultipleRenderTargets
//
//
//
////////////////////////////////////////////////////////////////
void CRenderItemManager::NotifyShaderItemUsesMultipleRenderTargets ( CShaderItem* pShaderItem, bool bUsesMultipleRenderTargets )
{
    if ( bUsesMultipleRenderTargets )
        MapInsert ( m_ShadersUsingMultipleRenderTargets, pShaderItem );
    else
        MapRemove ( m_ShadersUsingMultipleRenderTargets, pShaderItem );
}
Esempio n. 8
0
std::vector<SString> SharedUtil::FindFiles(const SString& strMatch, bool bFiles, bool bDirectories, bool bSortByDate)
{
    std::vector<SString>           strResult;
    std::multimap<uint64, SString> sortMap;

    DIR*           Dir;
    struct dirent* DirEntry;

    // Extract any filename matching characters
    SString strFileMatch;
    SString strSearchDirectory = PathJoin(PathConform(strMatch).SplitLeft("/", &strFileMatch, -1), "/");

    if ((Dir = opendir(strSearchDirectory)))
    {
        while ((DirEntry = readdir(Dir)) != NULL)
        {
            // Skip dotted entries
            if (strcmp(DirEntry->d_name, ".") && strcmp(DirEntry->d_name, ".."))
            {
                struct stat Info;
                bool        bIsDir = false;

                // Do wildcard matching if required
                if (!strFileMatch.empty() && !WildcardMatch(strFileMatch, DirEntry->d_name))
                {
                    continue;
                }

                SString strPath = PathJoin(strSearchDirectory, DirEntry->d_name);

                // Determine the file stats
                if (lstat(strPath, &Info) != -1)
                    bIsDir = S_ISDIR(Info.st_mode);

                if (bIsDir ? bDirectories : bFiles)
                {
                    if (bSortByDate)
                    {
                        SString     strAbsPath = strSearchDirectory + DirEntry->d_name;
                        struct stat attrib;
                        stat(strAbsPath, &attrib);
                        MapInsert(sortMap, (uint64)attrib.st_mtime, SStringX(DirEntry->d_name));
                    }
                    else
                        strResult.push_back(DirEntry->d_name);
                }
            }
        }
        closedir(Dir);
    }

    // Resolve sorted map if required
    if (!sortMap.empty())
    {
        for (std::multimap<uint64, SString>::iterator iter = sortMap.begin(); iter != sortMap.end(); ++iter)
            strResult.push_back(iter->second);
    }

    return strResult;
}
Esempio n. 9
0
///////////////////////////////////////////////////////////////
//
// CCompressorJobQueueImpl::RemoveUnwantedResults
//
// Check result queue items for match with ignore list items.
// * Must be called from inside a locked section *
//
///////////////////////////////////////////////////////////////
void CCompressorJobQueueImpl::RemoveUnwantedResults ( void )
{
    if ( m_IgnoreResultList.empty () )
        return;

again:
    for ( std::list < CCompressJobData* >::iterator iter = shared.m_ResultQueue.begin () ; iter != shared.m_ResultQueue.end () ; )
    {
        CCompressJobData* pJobData = *iter;
        if ( MapContains ( m_IgnoreResultList, pJobData ) )
        {
            // Found result to ignore, remove from result and ignore lists, add to finished list
            iter = shared.m_ResultQueue.erase ( iter );
            MapRemove ( m_IgnoreResultList, 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 ();
                goto again;
            }
        }
        else
            ++iter;
    }
}
////////////////////////////////////////////////////////////////
//
// CRenderItemManager::GetAppliedShaderForD3DData
//
// Find which shader item is being used to render this D3DData
//
////////////////////////////////////////////////////////////////
SShaderItemLayers* CRenderItemManager::GetAppliedShaderForD3DData ( CD3DDUMMY* pD3DData )
{
    // Save texture usage for later
    MapInsert ( m_FrameTextureUsage, pD3DData );

    return m_pRenderWare->GetAppliedShaderForD3DData ( pD3DData );
}
Esempio n. 11
0
///////////////////////////////////////////////////////////////
//
// CModelCacheManagerImpl::AddModelToPersistentCache
//
// Keep this model around 4 evar now
//
///////////////////////////////////////////////////////////////
void CModelCacheManagerImpl::AddModelToPersistentCache ( ushort usModelId )
{
    if ( !MapContains ( m_PermoLoadedModels, usModelId ) )
    {
        AddModelRefCount ( usModelId );
        MapInsert ( m_PermoLoadedModels, usModelId );
    }
}
Esempio n. 12
0
////////////////////////////////////////////////////////////////
//
// CRenderItemManager::NotifyContructRenderItem
//
// Add to managers list
//
////////////////////////////////////////////////////////////////
void CRenderItemManager::NotifyContructRenderItem ( CRenderItem* pItem )
{
    assert ( !MapContains ( m_CreatedItemList, pItem ) );
    MapInsert ( m_CreatedItemList, pItem );

    if ( CScreenSourceItem* pScreenSourceItem = DynamicCast < CScreenSourceItem > ( pItem ) )
        m_bBackBufferCopyMaybeNeedsResize = true;
}
Esempio n. 13
0
static void DoBroadcast ( const CPacket& Packet, const T& sendList )
{
    // Group players by bitstream version
    std::multimap < ushort, CPlayer* > groupMap;
    for ( typename T::const_iterator iter = sendList.begin () ; iter != sendList.end () ; ++iter )
    {
        CPlayer* pPlayer = *iter;
        MapInsert ( groupMap, pPlayer->GetBitStreamVersion (), pPlayer );
    }

    DoBroadcast( Packet, groupMap );
}
Esempio n. 14
0
///////////////////////////////////////////////////////////////
//
// CCompressorJobQueueImpl::PollCommand
//
// Find result for previous command
// Returns false if result not ready.
//
///////////////////////////////////////////////////////////////
bool CCompressorJobQueueImpl::PollCommand ( CCompressJobData* pJobData, uint uiTimeout )
{
    bool bFound = false;

    shared.m_Mutex.Lock ();
    while ( true )
    {
        // Remove ignored before checking
        RemoveUnwantedResults ();

        // Find result with the required job handle
        for ( std::list < CCompressJobData* >::iterator iter = shared.m_ResultQueue.begin () ; iter != shared.m_ResultQueue.end () ; ++iter )
        {
            if ( pJobData == *iter )
            {
                // Found result. Remove from the result queue and flag return value
                shared.m_ResultQueue.erase ( iter );
                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;
                break;
            }
        }

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

        shared.m_Mutex.Wait ( uiTimeout );

        // If not infinite, break after next check
        if ( uiTimeout != (uint)-1 )
            uiTimeout = 0;
    }

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

    return bFound;
}
Esempio n. 15
0
///////////////////////////////////////////////////////////////
//
// CPerfStatDebugInfoImpl::GetStats
//
//
//
///////////////////////////////////////////////////////////////
void CPerfStatDebugInfoImpl::GetStats ( CPerfStatResult* pResult, const std::map < SString, int >& strOptionMap, const SString& strFilter )
{
    m_bActive = true;
    m_LastGetStatsTime = CTickCount::Now ();


    //
    // Set option flags
    //
    bool bHelp = MapContains ( strOptionMap, "h" );

    m_LastFilter = strFilter;

    //
    // Process help
    //
    if ( bHelp || strFilter.empty () )
    {
        pResult->AddColumn ( "Debug info help" );

        std::set < SString > sectionNames;
        for ( std::list < SLineInfo >::iterator iter = m_LineList.begin () ; iter != m_LineList.end () ; ++iter )
            MapInsert ( sectionNames, (*iter).strSection );

        pResult->AddRow ()[0] = "Option h - This help";
        pResult->AddRow ()[0] = "Filter all - View all data";
        for ( std::set < SString >::iterator iter = sectionNames.begin () ; iter != sectionNames.end () ; ++iter )
        {
            pResult->AddRow ()[0] = SString ( "Filter %s - View only this data set", **iter );
        }
        return;
    }

    // Add columns
    pResult->AddColumn ( "" );
    pResult->AddColumn ( "" );

    for ( std::list < SLineInfo >::iterator iter = m_LineList.begin () ; iter != m_LineList.end () ; ++iter )
    {
        const SLineInfo& info = *iter;

        if ( m_LastFilter.ContainsI ( "all" ) || m_LastFilter.ContainsI ( info.strSection ) )
        {
            SString* row = pResult->AddRow ();
            int c = 0;

            row[c++] = info.strHead;
            row[c++] = info.strData;
        }
    }
}
Esempio n. 16
0
 void CArgMap::MergeFromString ( const SString& strLine, bool bAllowMultiValues )
 {
     std::vector < SString > parts;
     strLine.Split( m_strPartsSep, parts );
     for ( uint i = 0 ; i < parts.size () ; i++ )
     {
         SString strCmd, strArg;
         parts[i].Split ( m_strArgSep, &strCmd, &strArg );
         if ( !bAllowMultiValues )
             m_Map.erase ( strCmd );
         if ( strCmd.length () ) // Key can not be empty
             MapInsert ( m_Map, strCmd, strArg );
     }
 }
////////////////////////////////////////////////////////////////
//
// CRenderWareSA::GetShadInfo
//
// Get SShadInfo linked with the pShaderData
//
////////////////////////////////////////////////////////////////
SShadInfo* CRenderWareSA::GetShadInfo ( CSHADERDUMMY* pShaderData, bool bAddIfRequired, float fPriority )
{
    // Find existing
    SShadInfo* pShadInfo = MapFindRef ( m_ShadInfoMap, pShaderData );
    if ( !pShadInfo && bAddIfRequired )
    {
        // Add new
        MapSet ( m_ShadInfoMap, pShaderData, new SShadInfo ( pShaderData, fPriority ) );
        pShadInfo = MapFindRef ( m_ShadInfoMap, pShaderData );

        // Add to order map
        MapInsert ( m_OrderMap, pShadInfo->fOrderPriority, pShadInfo );
    }

    return pShadInfo;
}
////////////////////////////////////////////////////////////////
//
// CEffectTemplateImpl::CloneD3DEffect
//
// Clone the d3d effect
//
////////////////////////////////////////////////////////////////
ID3DXEffect* CEffectTemplateImpl::CloneD3DEffect ( SString& strOutStatus, bool& bOutUsesVertexShader, bool& bOutUsesDepthBuffer )
{
    // Clone D3DXEffect
    ID3DXEffect* pNewD3DEffect = NULL;
    LPDIRECT3DDEVICE9 pDevice = NULL;
    m_pD3DEffect->GetDevice ( &pDevice );
    m_pD3DEffect->CloneEffect ( pDevice, &pNewD3DEffect );

    if ( !pNewD3DEffect )
        return NULL;

    // Set the same technique
    {
        D3DXHANDLE hTechnique = m_pD3DEffect->GetCurrentTechnique ();
        D3DXTECHNIQUE_DESC TechniqueDesc;
        m_pD3DEffect->GetTechniqueDesc( hTechnique, &TechniqueDesc );
        pNewD3DEffect->SetTechnique ( pNewD3DEffect->GetTechniqueByName ( TechniqueDesc.Name ) );

        // Output technique name
        strOutStatus = TechniqueDesc.Name;
    }

    // Check if any technique uses a vertex shader
    bOutUsesVertexShader = false;
    D3DXEFFECT_DESC EffectDesc;
    m_pD3DEffect->GetDesc ( &EffectDesc );
    for ( uint i = 0 ; i < EffectDesc.Techniques ; i++ )
    {
        D3DXHANDLE hTechnique = m_pD3DEffect->GetTechnique ( i );
        D3DXTECHNIQUE_DESC TechniqueDesc;
        m_pD3DEffect->GetTechniqueDesc( hTechnique, &TechniqueDesc );
        for ( uint i = 0 ; i < TechniqueDesc.Passes ; i++ )
        {
            D3DXPASS_DESC PassDesc;
            m_pD3DEffect->GetPassDesc ( m_pD3DEffect->GetPass ( hTechnique, i ), &PassDesc );
            if ( PassDesc.pVertexShaderFunction )
                bOutUsesVertexShader = true;
        }
    }

    bOutUsesDepthBuffer = m_bUsesDepthBuffer;

    // Add to list of clones
    assert ( !MapContains ( m_CloneList, pNewD3DEffect ) );
    MapInsert ( m_CloneList, pNewD3DEffect );
    return pNewD3DEffect;
}
///////////////////////////////////////////////////////////////////////////
//
// CSimPlayer::GetPuresyncSendList
//
// Returns list of players, grouped by bitstream version
//
///////////////////////////////////////////////////////////////////////////
const std::multimap < ushort, CSimPlayer* >& CSimPlayer::GetPuresyncSendList ( void )
{
    if ( m_bSendListChanged )
    {
        m_bSendListChanged = false;
        // Group players by bitstream version
        m_PuresyncSendListGrouped.clear();
        for ( std::vector < CSimPlayer* >::const_iterator iter = m_PuresyncSendListFlat.begin () ; iter != m_PuresyncSendListFlat.end () ; ++iter )
        {
            CSimPlayer* pPlayer = *iter;
            MapInsert ( m_PuresyncSendListGrouped, pPlayer->GetBitStreamVersion (), pPlayer );
        }
    }

    dassert( m_PuresyncSendListFlat.size() == m_PuresyncSendListGrouped.size() );
    return m_PuresyncSendListGrouped;
}
///////////////////////////////////////////////////////////////////////////
//
// CSimPlayerManager::AddSimPlayer
//
// Thread:              main
// CS should be locked: no
//
// Make a matching sim player object
//
///////////////////////////////////////////////////////////////////////////
void CSimPlayerManager::AddSimPlayer ( CPlayer* pPlayer )
{
    LockSimSystem ();     // Prevent any sim activity on the sync thread

    // Create
    CSimPlayer* pSim = new CSimPlayer ();

    // Interlink
    pSim->m_pRealPlayer = pPlayer;
    pPlayer->m_pSimPlayer = pSim;

    // Copy some important data
    pSim->m_PlayerSocket = pPlayer->GetSocket ();

    // Add to lists
    MapInsert ( m_AllSimPlayerMap, pSim );
    MapSet ( m_SocketSimMap, pSim->m_PlayerSocket, pSim );

    UnlockSimSystem ();
}
Esempio n. 21
0
///////////////////////////////////////////////////////////////
//
// CDebugHookManager::AddDebugHook
//
// Returns true if hook was added
//
///////////////////////////////////////////////////////////////
bool CDebugHookManager::AddDebugHook(EDebugHookType hookType, const CLuaFunctionRef& functionRef, const std::vector<SString>& allowedNameList)
{
    std::vector<SDebugHookCallInfo>& hookInfoList = GetHookInfoListForType(hookType);
    for (std::vector<SDebugHookCallInfo>::iterator iter = hookInfoList.begin(); iter != hookInfoList.end(); ++iter)
    {
        if ((*iter).functionRef == functionRef)
            return false;
    }

    SDebugHookCallInfo info;
    info.functionRef = functionRef;
    info.pLuaMain = g_pGame->GetLuaManager()->GetVirtualMachine(functionRef.GetLuaVM());
    if (!info.pLuaMain)
        return false;

    for (uint i = 0; i < allowedNameList.size(); i++)
        MapInsert(info.allowedNameMap, allowedNameList[i]);

    hookInfoList.push_back(info);
    return true;
}
Esempio n. 22
0
void CMapManager::BroadcastElementChildren ( CElement* pParentElement, CEntityAddPacket &Packet, std::vector < CPerPlayerEntity* > &pPerPlayerList, std::set < CElement* >& outDoneElements )
{
    CChildListType ::const_iterator iter = pParentElement->IterBegin ();
    for ( ; iter != pParentElement->IterEnd(); iter++ )
    {
        CElement* pChildElement = *iter;
        MapInsert( outDoneElements, pChildElement );

        // Is it a per-player entity
        if ( pChildElement->IsPerPlayerEntity () )
        {
            pPerPlayerList.push_back ( static_cast < CPerPlayerEntity* > ( pChildElement ) );
        }
        else
        {
            Packet.Add ( pChildElement );
        }

        if ( pChildElement->CountChildren() > 0 )
            BroadcastElementChildren ( pChildElement, Packet, pPerPlayerList, outDoneElements );
    }
}
Esempio n. 23
0
///////////////////////////////////////////////////////////////
//
// CDatabaseJobQueueImpl::AddCommand
//
// AddCommand to queue
// Can't fail
//
///////////////////////////////////////////////////////////////
CDbJobData* CDatabaseJobQueueImpl::AddCommand ( EJobCommandType jobType, SConnectionHandle connectionHandle, const SString& strData )
{
    // Add connection handle to the flush todo list
    if ( jobType == EJobCommand::QUERY )
        MapInsert ( m_PendingFlushMap, connectionHandle );

    // Create command
    CDbJobData* pJobData = GetNewJobData ();
    pJobData->command.type = jobType;
    pJobData->command.connectionHandle = connectionHandle;
    pJobData->command.strData = strData;
    pJobData->command.pJobQueue = this;

    // Add to queue
    shared.m_Mutex.Lock ();
    pJobData->stage = EJobStage::COMMAND_QUEUE;
    shared.m_CommandQueue.push_back ( pJobData );
    shared.m_Mutex.Signal ();
    shared.m_Mutex.Unlock ();

    return pJobData;
}
Esempio n. 24
0
///////////////////////////////////////////////////////////////
//
// FindFiles
//
// Find all files or directories at a path
// If sorted by date, returns last modified last
//
///////////////////////////////////////////////////////////////
std::vector < SString > SharedUtil::FindFiles ( const SString& strInMatch, bool bFiles, bool bDirectories, bool bSortByDate )
{
    std::vector < SString > strResult;
    std::multimap < uint64, SString > sortMap;

    SString strMatch = PathConform ( strInMatch );
    if ( strMatch.Right ( 1 ) == PATH_SEPERATOR )
        strMatch += "*";

    WIN32_FIND_DATAW findData;
    HANDLE hFind = FindFirstFileW ( FromUTF8( strMatch ), &findData );
    if( hFind != INVALID_HANDLE_VALUE )
    {
        do
        {
            if ( ( findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) ? bDirectories : bFiles )
                if ( wcscmp ( findData.cFileName, L"." ) && wcscmp ( findData.cFileName, L".." ) )
                {
                    if ( bSortByDate )
                        MapInsert( sortMap, (uint64&)findData.ftLastWriteTime, ToUTF8( findData.cFileName ) );
                    else
                        strResult.push_back ( ToUTF8( findData.cFileName ) );
                }
        }
        while( FindNextFileW( hFind, &findData ) );
        FindClose( hFind );
    }

    // Resolve sorted map if required
    if ( !sortMap.empty() )
    {
        for ( std::multimap < uint64, SString >::iterator iter = sortMap.begin() ; iter != sortMap.end() ; ++iter )
            strResult.push_back ( iter->second );
    }

    return strResult;
}
Esempio n. 25
0
void SetAdd(Set *set, void *element)
{
    MapInsert(set, element, element);
}
Esempio n. 26
0
///////////////////////////////////////////////////////////////
//
// CCompressorJobQueueImpl::IgnoreJobResult
//
// Throw away the result for this job
// * Assumed job data is in either m_CommandQueue or m_ResultQueue *
//
///////////////////////////////////////////////////////////////
void CCompressorJobQueueImpl::IgnoreJobResults ( CCompressJobData* pJobData )
{
    dassert ( pJobData->stage <= EJobStage::RESULT );
    dassert ( !MapContains ( m_FinishedList, pJobData ) );
    MapInsert ( m_IgnoreResultList, pJobData );
}
Esempio n. 27
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 ();
}
Esempio n. 28
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;
}
Esempio n. 29
0
///////////////////////////////////////////////////////////////
//
// SharedUtil_Collection_Tests
//
// Test behaviour of iterators and such
//
///////////////////////////////////////////////////////////////
void SharedUtil_Collection_Tests ( void )
{
    // std::map
    {
        std::map < uint, SString > testMap;
        MapSet ( testMap, 10, "10" );
        MapSet ( testMap, 20, "20" );
        MapSet ( testMap, 30, "30" );
        MapSet ( testMap, 40, "40" );

        std::map < uint, SString >::iterator iter = testMap.begin ();
        assert ( iter->first == 10 );
        iter++;
        assert ( iter->first == 20 );
        iter++;
        testMap.erase ( iter++ );
        assert ( iter->first == 40 );
        iter++;
        assert ( iter == testMap.end () );
    }

    // std::set
    {
        std::set < uint > testMap;
        MapInsert ( testMap, 10 );
        MapInsert ( testMap, 20 );
        MapInsert ( testMap, 30 );
        MapInsert ( testMap, 40 );

        std::set < uint >::iterator iter = testMap.begin ();
        assert ( *iter == 10 );
        iter++;
        assert ( *iter == 20 );
        iter++;
        testMap.erase ( iter++ );
        assert ( *iter == 40 );
        iter++;
        assert ( iter == testMap.end () );
    }

    // std::list
    {
        std::list < uint > testList;
        testList.push_back ( 10 );
        testList.push_back ( 20 );
        testList.push_back ( 30 );
        testList.push_back ( 40 );

        std::list < uint >::iterator iter = testList.begin ();
        assert ( *iter == 10 );
        iter++;
        assert ( *iter == 20 );
        iter++;
        iter = testList.erase ( iter );
        assert ( *iter == 40 );
        iter++;
        assert ( iter == testList.end () );
    }

    // std::vector
    {
        std::vector < uint > testList;
        testList.push_back ( 10 );
        testList.push_back ( 20 );
        testList.push_back ( 30 );
        testList.push_back ( 40 );

        std::vector < uint >::iterator iter = testList.begin ();
        assert ( *iter == 10 );
        iter++;
        assert ( *iter == 20 );
        iter++;
        iter = testList.erase ( iter );
        assert ( *iter == 40 );
        iter++;
        assert ( iter == testList.end () );
    }

}
Esempio n. 30
0
CPerPlayerEntity::CPerPlayerEntity(CElement* pParent) : CElement(pParent)
{
    MapInsert(ms_AllPerPlayerEntityMap, this);
    m_bIsSynced = false;
    AddVisibleToReference(g_pGame->GetMapManager()->GetRootElement());
};