port TIunA to export framework, part 2
progress bars!
This commit is contained in:
		
							parent
							
								
									bb5ad38fb6
								
							
						
					
					
						commit
						249032f096
					
				| 
						 | 
				
			
			@ -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<maxCmId) {
 | 
			
		||||
    if (mustAbort) {
 | 
			
		||||
      logAppend("aborted!");
 | 
			
		||||
      failed=true;
 | 
			
		||||
| 
						 | 
				
			
			@ -377,13 +380,16 @@ void DivExportTiuna::run() {
 | 
			
		|||
      return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    float theOtherSide=pow(1.0/float(MAX(1,lastMaxPMVal)),0.2)*0.98;
 | 
			
		||||
    progress[0].amount=theOtherSide+(1.0-theOtherSide)*((float)cmId/(float)maxCmId);
 | 
			
		||||
 | 
			
		||||
    logAppendf("start CM %04x...",cmId);
 | 
			
		||||
    std::map<int,TiunaMatches> potentialMatches;
 | 
			
		||||
    logAppendf("scan %d size...",cmdSize-1);
 | 
			
		||||
    for (int i=0; i<cmdSize-1;) {
 | 
			
		||||
      // continue and skip if it's part of previous confirmed matches
 | 
			
		||||
      while (i<cmdSize-1 && processed[i]) i++;
 | 
			
		||||
      if (i>=cmdSize-1) break;
 | 
			
		||||
      progress[1].amount=(float)i/(float)(cmdSize-1);
 | 
			
		||||
      std::vector<TiunaMatch> match;
 | 
			
		||||
      int ch=renderedCmds[i].ch;
 | 
			
		||||
      for (int j=i+1; j<cmdSize;) {
 | 
			
		||||
| 
						 | 
				
			
			@ -458,7 +464,6 @@ void DivExportTiuna::run() {
 | 
			
		|||
    }
 | 
			
		||||
    int maxPMIdx=0;
 | 
			
		||||
    int maxPMVal=0;
 | 
			
		||||
    logAppend("looking through potentialMatches...");
 | 
			
		||||
    for (const auto& i: potentialMatches) {
 | 
			
		||||
      if (i.second.bytesSaved>maxPMVal) {
 | 
			
		||||
        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];
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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() {}
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue