///////////////////////////////////////////////////////////////
    //
    // CStatResults::FrameEnd
    //
    // Save all stats in a ResultCollection
    //
    ///////////////////////////////////////////////////////////////
    void CStatResults::FrameEnd ( void )
    {
        CLOCK( "Profiling", "Compile stats" );

        SStatResultCollection& collection = m_CollectionCombo;

        bool bClearMax = false;

        float fNextLength = (float)GetSecondCount () - m_fNextMaxClearTime;
        if ( fNextLength >= 2.0f )
        {
            bClearMax = true;
            m_fNextMaxClearTime = (float)GetSecondCount ();  
        }

        // Clear max time thing
        for ( std::map < std::string, SStatResultSection > :: iterator itSection = collection.begin () ; itSection != collection.end () ; itSection++ )
        {
            SStatResultSection& section = itSection->second;

            for ( std::map < std::string, SStatResultItem > :: iterator itItem = section.begin () ; itItem != section.end () ; itItem++ )
            {
                SStatResultItem& item = itItem->second;
                item.iCounter = 0;
                item.fMs = 0;
                if ( bClearMax )
                {
                    item.fMsMax = item.fMsMaxNext;
                    item.fMsMaxNext = 0;
                    item.fMsTotal = item.fMsTotalAcc;
                    item.fMsTotalPercent = item.fMsTotalAcc / fNextLength * 0.1f;
                    item.fMsTotalAcc = 0;
                    item.iCounterTotal = item.iCounterTotalAcc;
                    item.iCounterTotalAcc = 0;
                }
            }
        }

        // Retrieve stats from g_StatEvents
        {
            SStatCollection collectionSrc;
            g_StatEvents.Sample ( collectionSrc );
            const SStatCollection* pCollectionSrc = &collectionSrc;

            // Merge collections

            // Merge section maps
            for ( std::map < std::string, SStatSection > :: const_iterator itSectionSrc = pCollectionSrc->begin () ; itSectionSrc != pCollectionSrc->end () ; itSectionSrc++ )
            {
                const std::string& strSectionNameSrc = itSectionSrc->first;
                const SStatSection& sectionSrc = itSectionSrc->second;

                // Merge sections
                SStatResultSection& sectionCombo = MapGet ( m_CollectionCombo, strSectionNameSrc );

                // Merge item maps
                for ( std::map < std::string, SStatItem > :: const_iterator itItemSrc = sectionSrc.begin () ; itItemSrc != sectionSrc.end () ; itItemSrc++ )
                {
                    const std::string& strItemNameSrc = itItemSrc->first;
                    const SStatItem& itemSrc = itItemSrc->second;

                    // Merge item
                    SStatResultItem& itemCombo = MapGet ( sectionCombo, strItemNameSrc );
                    itemCombo.iCounter += itemSrc.iCounter;
                    itemCombo.fMs      += itemSrc.fMs;
                }
            }
        }

        // Update some counters and stuff
        for ( std::map < std::string, SStatResultSection > :: iterator itSection = collection.begin () ; itSection != collection.end () ; itSection++ )
        {
            SStatResultSection& section = itSection->second;

            for ( std::map < std::string, SStatResultItem > :: iterator itItem = section.begin () ; itItem != section.end () ; itItem++ )
            {
                SStatResultItem& item = itItem->second;
                item.fMsMaxNext         = Max ( item.fMsMaxNext, item.fMs );
                item.fMsTotalAcc        += item.fMs;
                item.iCounterTotalAcc   += item.iCounter;
            }
        }

        UNCLOCK( "Profiling", "Compile stats" );
    }
int CLuaFunctionDefs::GetTickCount_ ( lua_State* luaVM )
{
    double dTime = GetSecondCount () * 1000.0;
    lua_pushnumber ( luaVM, dTime );
    return 1;
}