From 249032f096a76d4aed10031403a4e6451c905192 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Tue, 13 Aug 2024 17:47:18 -0500 Subject: [PATCH] port TIunA to export framework, part 2 progress bars! --- src/engine/export/tiuna.cpp | 26 ++++++++++++++++++++++---- src/engine/export/tiuna.h | 2 ++ src/gui/gui.cpp | 32 +++++++++++++++++++++----------- 3 files changed, 45 insertions(+), 15 deletions(-) diff --git a/src/engine/export/tiuna.cpp b/src/engine/export/tiuna.cpp index c4236d53a..985eba49f 100644 --- a/src/engine/export/tiuna.cpp +++ b/src/engine/export/tiuna.cpp @@ -367,8 +367,11 @@ void DivExportTiuna::run() { bool* processed=new bool[cmdSize]; memset(processed,0,cmdSize*sizeof(bool)); logAppend("compressing! this may take a while."); - logAppendf("max cmId: %d",(MAX(firstBankSize/1024,1))*256); - while (firstBankSize>768 && cmId<(MAX(firstBankSize/1024,1))*256) { + int maxCmId=(MAX(firstBankSize/1024,1))*256; + int lastMaxPMVal=100000; + logAppendf("max cmId: %d",maxCmId); + logAppendf("commands: %d",cmdSize); + while (firstBankSize>768 && cmId potentialMatches; - logAppendf("scan %d size...",cmdSize-1); for (int i=0; i=cmdSize-1) break; + progress[1].amount=(float)i/(float)(cmdSize-1); std::vector match; int ch=renderedCmds[i].ch; for (int j=i+1; jmaxPMVal) { maxPMVal=i.second.bytesSaved; @@ -473,8 +478,11 @@ void DivExportTiuna::run() { } callTicks.push_back(potentialMatches[maxPMIdx].ticks); logAppendf("CM %04x added: pos=%d,len=%d,matches=%d,saved=%d",cmId,maxPMIdx,maxPMLen,potentialMatches[maxPMIdx].pos.size(),maxPMVal); + lastMaxPMVal=maxPMVal; cmId++; } + progress[0].amount=1.0f; + progress[1].amount=1.0f; logAppend("generating data..."); delete[] processed; std::sort(confirmedMatches.begin(),confirmedMatches.end(),[](const TiunaMatch& l, const TiunaMatch& r){ @@ -612,6 +620,11 @@ void DivExportTiuna::run() { } bool DivExportTiuna::go(DivEngine* eng) { + progress[0].name="Compression"; + progress[0].amount=0.0f; + progress[1].name="Confirmed Matches"; + progress[1].amount=0.0f; + e=eng; running=true; failed=false; @@ -639,3 +652,8 @@ bool DivExportTiuna::isRunning() { bool DivExportTiuna::hasFailed() { return failed; } + +DivROMExportProgress DivExportTiuna::getProgress(int index) { + if (index<0 || index>2) return progress[2]; + return progress[index]; +} diff --git a/src/engine/export/tiuna.h b/src/engine/export/tiuna.h index 8e93b9fb4..ae1a661a9 100644 --- a/src/engine/export/tiuna.h +++ b/src/engine/export/tiuna.h @@ -24,6 +24,7 @@ class DivExportTiuna: public DivROMExport { DivEngine* e; std::thread* exportThread; + DivROMExportProgress progress[3]; bool running, failed, mustAbort; void run(); public: @@ -32,5 +33,6 @@ class DivExportTiuna: public DivROMExport { bool hasFailed(); void abort(); void wait(); + DivROMExportProgress getProgress(int index=0); ~DivExportTiuna() {} }; diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 86948b0df..d01589503 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -5741,11 +5741,16 @@ bool FurnaceGUI::loop() { ImGui::EndPopup(); } + ImVec2 romExportMinSize=mobileUI?ImVec2(canvasW-(portrait?0:(60.0*dpiScale)),canvasH-60.0*dpiScale):ImVec2(400.0f*dpiScale,200.0f*dpiScale); + ImVec2 romExportMaxSize=ImVec2(canvasW-((mobileUI && !portrait)?(60.0*dpiScale):0),canvasH-(mobileUI?(60.0*dpiScale):0)); + centerNextWindow(_("ROM Export Progress"),canvasW,canvasH); + ImGui::SetNextWindowSizeConstraints(romExportMinSize,romExportMaxSize); if (ImGui::BeginPopupModal(_("ROM Export Progress"),NULL)) { if (pendingExport==NULL) { - ImGui::TextUnformatted(_("...ooooor you could try asking me a new ROM export?")); - if (ImGui::Button(_("Erm what the sigma???"))) { + ImGui::TextWrapped("%s",_("...ooooor you could try asking me a new ROM export?")); + ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); + if (ImGui::Button(_("Erm what the sigma???"),ImVec2(ImGui::GetContentRegionAvail().x,0.0f))) { ImGui::CloseCurrentPopup(); } } else { @@ -5762,17 +5767,20 @@ bool FurnaceGUI::loop() { if (romLogSize.y<60.0f*dpiScale) romLogSize.y=60.0f*dpiScale; if (ImGui::BeginChild("Export Log",romLogSize,true)) { pendingExport->logLock.lock(); + ImGui::PushFont(patFont); for (String& i: pendingExport->exportLog) { - ImGui::TextUnformatted(i.c_str()); + ImGui::TextWrapped("%s",i.c_str()); } if (romExportSave) { ImGui::SetScrollY(ImGui::GetScrollMaxY()); } + ImGui::PopFont(); pendingExport->logLock.unlock(); } ImGui::EndChild(); if (pendingExport->isRunning()) { - if (ImGui::Button(_("Abort"))) { + WAKE_UP; + if (ImGui::Button(_("Abort"),ImVec2(ImGui::GetContentRegionAvail().x,0.0f))) { pendingExport->abort(); delete pendingExport; pendingExport=NULL; @@ -5803,17 +5811,19 @@ bool FurnaceGUI::loop() { } romExportSave=false; } - if (ImGui::Button(_("OK"))) { + if (pendingExport!=NULL) { + if (pendingExport->hasFailed()) { + ImGui::AlignTextToFramePadding(); + ImGui::TextUnformatted(_("Error!")); + ImGui::SameLine(); + } + } + ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); + if (ImGui::Button(_("OK"),ImVec2(ImGui::GetContentRegionAvail().x,0.0f))) { delete pendingExport; pendingExport=NULL; ImGui::CloseCurrentPopup(); } - if (pendingExport!=NULL) { - if (pendingExport->hasFailed()) { - ImGui::SameLine(); - ImGui::TextUnformatted(_("Error!")); - } - } } } ImGui::EndPopup();