Exemplo n.º 1
0
void glTextureManager::OnEvtThread( OCPN_CompressionThreadEvent & event )
{
    JobTicket *ticket = event.GetTicket();

    if(ticket->b_isaborted || ticket->b_abort){
        for(int i=0 ; i < g_mipmap_max_level+1 ; i++) {
            free(ticket->comp_bits_array[i]);
            free( ticket->compcomp_bits_array[i] );
        }
        
        if(bthread_debug)
            printf( "    Abort job: %08X  Jobs running: %d             Job count: %lu   \n",
                    ticket->ident, GetRunningJobCount(), (unsigned long)todo_list.GetCount());
    } else if(!b_inCompressAllCharts) {
        //   Normal completion from here
        glTextureDescriptor *ptd = ticket->pFact->GetpTD( ticket->rect );
        if(ptd) {
            for(int i=0 ; i < g_mipmap_max_level+1 ; i++)
                ptd->comp_array[i] = ticket->comp_bits_array[i];

            if(ticket->bpost_zip_compress){
                for(int i=0 ; i < g_mipmap_max_level+1 ; i++){
                    ptd->compcomp_array[i] = ticket->compcomp_bits_array[i];
                    ptd->compcomp_size[i] = ticket->compcomp_size_array[i];
                }
            }

            // We need to force a refresh to replace the uncompressed texture
            // This frees video memory and is also really required if we had
            // gone up a mipmap level
            extern ChartCanvas *cc1;
            if(cc1) {
                glChartCanvas::Invalidate(); // ensure we refresh
                cc1->Refresh();
            }
            ptd->compdata_ticks = 10;
        }

        if(bthread_debug)
            printf( "    Finished job: %08X  Jobs running: %d             Job count: %lu   \n",
                    ticket->ident, GetRunningJobCount(), (unsigned long)todo_list.GetCount());
    }

    //      Free all possible memory
    if(b_inCompressAllCharts) { // if compressing all write cache here
        ChartBase *pchart = ChartData->OpenChartFromDB(ticket->m_ChartPath, FULL_INIT );
        ChartData->DeleteCacheChart(pchart);
        delete ticket->pFact;
    }

    delete ticket;

    if(g_raster_format != GL_COMPRESSED_RGB_FXT1_3DFX) {
        running_list.DeleteObject(ticket);
        StartTopJob();
    }
}
Exemplo n.º 2
0
void glTextureManager::OnEvtThread( OCPN_CompressionThreadEvent & event )
{
    JobTicket *ticket = event.GetTicket();

    if(event.type ==1){
        if(m_progDialog){
            
            // Look for a matching entry...
            bool bfound = false;
            ProgressInfoItem *item;
            wxProgressInfoListNode *tnode = progList.GetFirst();
            while(tnode){
                item = tnode->GetData();
                if(item->file_path == ticket->m_ChartPath){
                    bfound = true;
                    break;
                }
                tnode = tnode->GetNext();
            }
            if(bfound){
                wxString msgx;
                if(1){
                    int bar_length = NBAR_LENGTH;
                    if(m_bcompact)
                        bar_length = 20;
                    
                    msgx += _T("\n[");
                    wxString block = wxString::Format(_T("%c"), 0x2589);
                    float cutoff = ((event.nstat+1) / (float)event.nstat_max) * bar_length;
                    for(int i=0 ; i < bar_length ; i++){
                        if(i <= cutoff)
                            msgx += block;
                        else
                            msgx += _T("-");
                    }
                    msgx += _T("]");

                    if(!m_bcompact){
                        wxString msgy;
                        msgy.Printf(_T("  [%3d/%3d]  "), event.nstat+1, event.nstat_max);
                        msgx += msgy;
                
                        wxFileName fn(ticket->m_ChartPath);
                        msgx += fn.GetFullName();
                    }
                }
                else
                    msgx.Printf(_T("\n %3d/%3d"), event.nstat+1, event.nstat_max);
                
                item->msgx = msgx;
            }

                // look for an empty slot
            else{
                bool bfound_empty = false;
                tnode = progList.GetFirst();
                while(tnode){
                    item = tnode->GetData();
                    if(item->file_path.IsEmpty()){
                        bfound_empty = true;
                        break;
                    }
                    
                    tnode = tnode->GetNext();
                }
                
                if(bfound_empty){
                    item->file_path = ticket->m_ChartPath;
                    wxString msgx;
                    msgx.Printf(_T("\n [%3d/%3d]"), event.nstat+1, event.nstat_max);
                    item->msgx = msgx;
                }
            }
        
            // Ready to compose
            wxString msg;
            tnode = progList.GetFirst();
            while(tnode){
                item = tnode->GetData();
                msg += item->msgx + _T("\n");
                tnode = tnode->GetNext();
            }
            
            if(m_skipout)
                m_progMsg = _T("Skipping, please wait...\n\n");
            
            m_progDialog->Update(m_jcnt, m_progMsg + msg, &m_skip );
            if(m_skip)
                m_skipout = true;
            return;
        }
    }
    
    if(ticket->b_isaborted || ticket->b_abort){
        for(int i=0 ; i < g_mipmap_max_level+1 ; i++) {
            free(ticket->comp_bits_array[i]);
            free( ticket->compcomp_bits_array[i] );
        }
        
        if(bthread_debug)
            printf( "    Abort job: %08X  Jobs running: %d             Job count: %lu   \n",
                    ticket->ident, GetRunningJobCount(), (unsigned long)todo_list.GetCount());
    } else if(!b_inCompressAllCharts) {
        //   Normal completion from here
        glTextureDescriptor *ptd = ticket->pFact->GetpTD( ticket->rect );
        if(ptd) {
            for(int i=0 ; i < g_mipmap_max_level+1 ; i++)
                ptd->comp_array[i] = ticket->comp_bits_array[i];

            if(ticket->bpost_zip_compress){
                for(int i=0 ; i < g_mipmap_max_level+1 ; i++){
                    ptd->compcomp_array[i] = ticket->compcomp_bits_array[i];
                    ptd->compcomp_size[i] = ticket->compcomp_size_array[i];
                }
            }

                    
                    
            // We need to force a refresh to replace the uncompressed texture
            // This frees video memory and is also really required if we had
            // gone up a mipmap level
            extern ChartCanvas *cc1;
            if(cc1) {
                glChartCanvas::Invalidate(); // ensure we refresh
                cc1->Refresh();
            }
            ptd->compdata_ticks = 10;
        }

        if(bthread_debug)
            printf( "    Finished job: %08X  Jobs running: %d             Job count: %lu   \n",
                    ticket->ident, GetRunningJobCount(), (unsigned long)todo_list.GetCount());
    }

    //      Free all possible memory
    if(b_inCompressAllCharts) { // if compressing all write cache here
        ChartBase *pchart = ChartData->OpenChartFromDB(ticket->m_ChartPath, FULL_INIT );
        ChartData->DeleteCacheChart(pchart);
        delete ticket->pFact;
    }

    wxProgressInfoListNode *tnode = progList.GetFirst();
    while(tnode){
        ProgressInfoItem *item = tnode->GetData();
        if(item->file_path == ticket->m_ChartPath)
            item->file_path = _T("");
        tnode = tnode->GetNext();
    }
    
    delete ticket;

    if(g_raster_format != GL_COMPRESSED_RGB_FXT1_3DFX) {
        running_list.DeleteObject(ticket);
        StartTopJob();
    }
}