From 1e4292e52a9d6b9510b49b5208b2e6be89060610 Mon Sep 17 00:00:00 2001 From: Robert Beckebans Date: Thu, 7 Jul 2016 00:32:44 +0200 Subject: [PATCH] Merged LordHavoc's image compression progress bar --- neo/framework/common_frame.cpp | 61 ++++++++++++++++++++++++++++++---- neo/renderer/Image_load.cpp | 42 +++++++++++++++++++++++ 2 files changed, 96 insertions(+), 7 deletions(-) diff --git a/neo/framework/common_frame.cpp b/neo/framework/common_frame.cpp index c9b11c8e..52d198bf 100644 --- a/neo/framework/common_frame.cpp +++ b/neo/framework/common_frame.cpp @@ -32,7 +32,7 @@ If you have questions concerning this license or the applicable additional terms #pragma hdrstop #include "Common_local.h" -#include "../renderer/Image.h" // now I did it! +#include "../renderer/Image.h" // RB begin #if defined(USE_DOOMCLASSIC) @@ -194,7 +194,8 @@ gameReturn_t idGameThread::RunGameAndDraw( int numGameFrames_, idUserCmdMgr& use numGameFrames = numGameFrames_; // start the thread going - if( com_smp.GetInteger() <= 0 ) + // foresthale 2014-05-12: also check com_editors as many of them are not particularly thread-safe (editLights for example) + if( com_smp.GetBool() == false || com_editors != 0 ) { // run it in the main thread so PIX profiling catches everything Run(); @@ -249,8 +250,49 @@ void idCommonLocal::Draw() Sys_Sleep( com_sleepDraw.GetInteger() ); } - if( loadGUI != NULL ) + if( loadPacifierBinarizeActive ) { + // foresthale 2014-05-30: when binarizing an asset we show a special + // overlay indicating progress + renderSystem->SetColor( colorBlack ); + renderSystem->DrawStretchPic( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 1, 1, whiteMaterial ); + + // render the loading gui (idSWF actually) if it is loaded + // (we want to see progress of the loading gui binarize too) + if( loadGUI != NULL ) + loadGUI->Render( renderSystem, Sys_Milliseconds() ); + + // update our progress estimates + int time = Sys_Milliseconds(); + if( loadPacifierBinarizeProgress > 0.0f ) + loadPacifierBinarizeTimeLeft = ( 1.0 - loadPacifierBinarizeProgress ) * ( time - loadPacifierBinarizeStartTime ) * 0.001f / loadPacifierBinarizeProgress; + else + loadPacifierBinarizeTimeLeft = -1.0f; + + // prepare our strings + const char* text; + if( loadPacifierBinarizeTimeLeft >= 99.5f ) + text = va( "Binarizing %3.0f%% ETA %2.0f minutes", loadPacifierBinarizeProgress * 100.0f, loadPacifierBinarizeTimeLeft / 60.0f ); + else if( loadPacifierBinarizeTimeLeft ) + text = va( "Binarizing %3.0f%% ETA %2.0f seconds", loadPacifierBinarizeProgress * 100.0f, loadPacifierBinarizeTimeLeft ); + else + text = va( "Binarizing %3.0f%%", loadPacifierBinarizeProgress * 100.0f ); + + // draw our basic overlay + renderSystem->SetColor( idVec4( 0.0f, 0.0f, 0.5f, 1.0f ) ); + renderSystem->DrawStretchPic( 0, SCREEN_HEIGHT - 48, SCREEN_WIDTH, 48, 0, 0, 1, 1, whiteMaterial ); + renderSystem->SetColor( idVec4( 0.0f, 0.5f, 0.8f, 1.0f ) ); + renderSystem->DrawStretchPic( 0, SCREEN_HEIGHT - 48, loadPacifierBinarizeProgress * SCREEN_WIDTH, 32, 0, 0, 1, 1, whiteMaterial ); + renderSystem->DrawSmallStringExt( 0, SCREEN_HEIGHT - 48, loadPacifierBinarizeFilename.c_str(), idVec4( 1.0f, 1.0f, 1.0f, 1.0f ), true ); + renderSystem->DrawSmallStringExt( 0, SCREEN_HEIGHT - 32, va( "%s %d/%d lvls", loadPacifierBinarizeInfo.c_str(), loadPacifierBinarizeMiplevel, loadPacifierBinarizeMiplevelTotal ), idVec4( 1.0f, 1.0f, 1.0f, 1.0f ), true ); + renderSystem->DrawSmallStringExt( 0, SCREEN_HEIGHT - 16, text, idVec4( 1.0f, 1.0f, 1.0f, 1.0f ), true ); + } + else if( loadGUI != NULL ) + { + // foresthale 2014-05-30: showing a black background looks better than flickering in widescreen + renderSystem->SetColor( colorBlack ); + renderSystem->DrawStretchPic( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 1, 1, whiteMaterial ); + loadGUI->Render( renderSystem, Sys_Milliseconds() ); } // RB begin @@ -371,6 +413,7 @@ void idCommonLocal::UpdateScreen( bool captureToImage, bool releaseMouse ) // build all the draw commands without running a new game tic Draw(); + // foresthale 2014-03-01: note: the only place that has captureToImage=true is idAutoRender::StartBackgroundAutoSwaps if( captureToImage ) { renderSystem->CaptureRenderToImage( "_currentRender", false ); @@ -479,6 +522,8 @@ void idCommonLocal::Frame() eventLoop->RunEventLoop(); + renderSystem->OnFrame(); + // Activate the shell if it's been requested if( showShellRequested && game ) { @@ -554,7 +599,9 @@ void idCommonLocal::Frame() // This may block if the GPU isn't finished renderng the previous frame. frameTiming.startSyncTime = Sys_Microseconds(); const emptyCommand_t* renderCommands = NULL; - if( com_smp.GetInteger() > 0 ) + + // foresthale 2014-05-12: also check com_editors as many of them are not particularly thread-safe (editLights for example) + if( com_smp.GetInteger() > 0 && com_editors == 0 ) { renderCommands = renderSystem->SwapCommandBuffers( &time_frontend, &time_backend, &time_shadows, &time_gpu ); } @@ -783,12 +830,12 @@ void idCommonLocal::Frame() // start the game / draw command generation thread going in the background gameReturn_t ret = gameThread.RunGameAndDraw( numGameFrames, userCmdMgr, IsClient(), gameFrame - numGameFrames ); - if( com_smp.GetInteger() < 0 ) - { + // foresthale 2014-05-12: also check com_editors as many of them are not particularly thread-safe (editLights for example) + if( !com_smp.GetInteger() < 0 ) // RB: this is the same as Doom 3 renderSystem->EndFrame() renderSystem->SwapCommandBuffers_FinishRendering( &time_frontend, &time_backend, &time_shadows, &time_gpu ); } - else if( com_smp.GetInteger() == 0 ) + else if( com_smp.GetInteger() == 0 || com_editors != 0 ) { // in non-smp mode, run the commands we just generated, instead of // frame-delayed ones from a background thread diff --git a/neo/renderer/Image_load.cpp b/neo/renderer/Image_load.cpp index 5a5e0164..49e1b705 100644 --- a/neo/renderer/Image_load.cpp +++ b/neo/renderer/Image_load.cpp @@ -217,6 +217,35 @@ void idImage::AllocImage( const idImageOpts& imgOpts, textureFilter_t tf, textur } /* + + + // foresthale 2014-05-30: give a nice progress display when binarizing + commonLocal.LoadPacifierBinarizeFilename( GetName() , "generated image" ); + if( opts.numLevels > 1 ) + { + commonLocal.LoadPacifierBinarizeProgressTotal( opts.width * opts.height * 4 / 3 ); + } + else + { + commonLocal.LoadPacifierBinarizeProgressTotal( opts.width * opts.height ); + } + + commonLocal.LoadPacifierBinarizeEnd(); + + + // foresthale 2014-05-30: give a nice progress display when binarizing + commonLocal.LoadPacifierBinarizeFilename( GetName(), "generated cube image" ); + if( opts.numLevels > 1 ) + { + commonLocal.LoadPacifierBinarizeProgressTotal( opts.width * opts.width * 6 * 4 / 3 ); + } + else + { + commonLocal.LoadPacifierBinarizeProgressTotal( opts.width * opts.width * 6 ); + } + + commonLocal.LoadPacifierBinarizeEnd(); + =============== GetGeneratedName @@ -474,6 +503,19 @@ void idImage::ActuallyLoadImage( bool fromBackEnd ) commonLocal.LoadPacifierBinarizeProgressTotal( opts.width * opts.width * 6 ); } + commonLocal.LoadPacifierBinarizeEnd(); + + // foresthale 2014-05-30: give a nice progress display when binarizing + commonLocal.LoadPacifierBinarizeFilename( generatedName.c_str(), binarizeReason.c_str() ); + if( opts.numLevels > 1 ) + { + commonLocal.LoadPacifierBinarizeProgressTotal( opts.width * opts.width * 6 * 4 / 3 ); + } + else + { + commonLocal.LoadPacifierBinarizeProgressTotal( opts.width * opts.width * 6 ); + } + im.Load2DFromMemory( opts.width, opts.height, pic, opts.numLevels, opts.format, opts.colorFormat, opts.gammaMips ); commonLocal.LoadPacifierBinarizeEnd();