GUI: attempt at optimizing pattern draw code
This commit is contained in:
		
							parent
							
								
									258a905aaa
								
							
						
					
					
						commit
						5f71857439
					
				| 
						 | 
					@ -133,6 +133,8 @@ enum FurnaceGUIColors {
 | 
				
			||||||
  GUI_COLOR_PATTERN_ACTIVE,
 | 
					  GUI_COLOR_PATTERN_ACTIVE,
 | 
				
			||||||
  GUI_COLOR_PATTERN_INACTIVE,
 | 
					  GUI_COLOR_PATTERN_INACTIVE,
 | 
				
			||||||
  GUI_COLOR_PATTERN_INS,
 | 
					  GUI_COLOR_PATTERN_INS,
 | 
				
			||||||
 | 
					  GUI_COLOR_PATTERN_INS_WARN,
 | 
				
			||||||
 | 
					  GUI_COLOR_PATTERN_INS_ERROR,
 | 
				
			||||||
  GUI_COLOR_PATTERN_VOLUME_MAX,
 | 
					  GUI_COLOR_PATTERN_VOLUME_MAX,
 | 
				
			||||||
  GUI_COLOR_PATTERN_VOLUME_HALF,
 | 
					  GUI_COLOR_PATTERN_VOLUME_HALF,
 | 
				
			||||||
  GUI_COLOR_PATTERN_VOLUME_MIN,
 | 
					  GUI_COLOR_PATTERN_VOLUME_MIN,
 | 
				
			||||||
| 
						 | 
					@ -970,7 +972,7 @@ class FurnaceGUI {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  float calcBPM(int s1, int s2, float hz);
 | 
					  float calcBPM(int s1, int s2, float hz);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void patternRow(int i, bool isPlaying, float lineHeight, int chans, int ord);
 | 
					  void patternRow(int i, bool isPlaying, float lineHeight, int chans, int ord, const DivPattern** patCache);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void actualWaveList();
 | 
					  void actualWaveList();
 | 
				
			||||||
  void actualSampleList();
 | 
					  void actualSampleList();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -17,9 +17,11 @@
 | 
				
			||||||
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 | 
					 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <SDL_timer.h>
 | 
				
			||||||
#include <imgui.h>
 | 
					#include <imgui.h>
 | 
				
			||||||
#define _USE_MATH_DEFINES
 | 
					#define _USE_MATH_DEFINES
 | 
				
			||||||
#include "gui.h"
 | 
					#include "gui.h"
 | 
				
			||||||
 | 
					#include "../ta-log.h"
 | 
				
			||||||
#include "imgui_internal.h"
 | 
					#include "imgui_internal.h"
 | 
				
			||||||
#include "IconsFontAwesome4.h"
 | 
					#include "IconsFontAwesome4.h"
 | 
				
			||||||
#include "misc/cpp/imgui_stdlib.h"
 | 
					#include "misc/cpp/imgui_stdlib.h"
 | 
				
			||||||
| 
						 | 
					@ -85,7 +87,7 @@ inline float randRange(float min, float max) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// draw a pattern row
 | 
					// draw a pattern row
 | 
				
			||||||
inline void FurnaceGUI::patternRow(int i, bool isPlaying, float lineHeight, int chans, int ord) {
 | 
					inline void FurnaceGUI::patternRow(int i, bool isPlaying, float lineHeight, int chans, int ord, const DivPattern** patCache) {
 | 
				
			||||||
  static char id[32];
 | 
					  static char id[32];
 | 
				
			||||||
  bool selectedRow=(i>=sel1.y && i<=sel2.y);
 | 
					  bool selectedRow=(i>=sel1.y && i<=sel2.y);
 | 
				
			||||||
  ImGui::TableNextRow(0,lineHeight);
 | 
					  ImGui::TableNextRow(0,lineHeight);
 | 
				
			||||||
| 
						 | 
					@ -143,7 +145,7 @@ inline void FurnaceGUI::patternRow(int i, bool isPlaying, float lineHeight, int
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    int chanVolMax=e->getMaxVolumeChan(j);
 | 
					    int chanVolMax=e->getMaxVolumeChan(j);
 | 
				
			||||||
    if (chanVolMax<1) chanVolMax=1;
 | 
					    if (chanVolMax<1) chanVolMax=1;
 | 
				
			||||||
    DivPattern* pat=e->song.pat[j].getPattern(e->song.orders.ord[j][ord],true);
 | 
					    const DivPattern* pat=patCache[j];
 | 
				
			||||||
    ImGui::TableNextColumn();
 | 
					    ImGui::TableNextColumn();
 | 
				
			||||||
    patChanX[j]=ImGui::GetCursorPosX();
 | 
					    patChanX[j]=ImGui::GetCursorPosX();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -158,8 +160,6 @@ inline void FurnaceGUI::patternRow(int i, bool isPlaying, float lineHeight, int
 | 
				
			||||||
    bool cursorIns=(cursor.y==i && cursor.xCoarse==j && cursor.xFine==1);
 | 
					    bool cursorIns=(cursor.y==i && cursor.xCoarse==j && cursor.xFine==1);
 | 
				
			||||||
    bool cursorVol=(cursor.y==i && cursor.xCoarse==j && cursor.xFine==2);
 | 
					    bool cursorVol=(cursor.y==i && cursor.xCoarse==j && cursor.xFine==2);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    // note
 | 
					    // note
 | 
				
			||||||
    sprintf(id,"%s##PN_%d_%d",noteName(pat->data[i][0],pat->data[i][1]),i,j);
 | 
					    sprintf(id,"%s##PN_%d_%d",noteName(pat->data[i][0],pat->data[i][1]),i,j);
 | 
				
			||||||
    if (pat->data[i][0]==0 && pat->data[i][1]==0) {
 | 
					    if (pat->data[i][0]==0 && pat->data[i][1]==0) {
 | 
				
			||||||
| 
						 | 
					@ -194,7 +194,16 @@ inline void FurnaceGUI::patternRow(int i, bool isPlaying, float lineHeight, int
 | 
				
			||||||
        ImGui::PushStyleColor(ImGuiCol_Text,uiColors[GUI_COLOR_PATTERN_INACTIVE]);
 | 
					        ImGui::PushStyleColor(ImGuiCol_Text,uiColors[GUI_COLOR_PATTERN_INACTIVE]);
 | 
				
			||||||
        sprintf(id,"..##PI_%d_%d",i,j);
 | 
					        sprintf(id,"..##PI_%d_%d",i,j);
 | 
				
			||||||
      } else {
 | 
					      } else {
 | 
				
			||||||
        ImGui::PushStyleColor(ImGuiCol_Text,uiColors[GUI_COLOR_PATTERN_INS]);
 | 
					        if (pat->data[i][2]<0 || pat->data[i][2]>=e->song.insLen) {
 | 
				
			||||||
 | 
					          ImGui::PushStyleColor(ImGuiCol_Text,uiColors[GUI_COLOR_PATTERN_INS_ERROR]);
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					          DivInstrumentType t=e->song.ins[pat->data[i][2]]->type;
 | 
				
			||||||
 | 
					          if (t!=DIV_INS_AMIGA && t!=e->getPreferInsType(j)) {
 | 
				
			||||||
 | 
					            ImGui::PushStyleColor(ImGuiCol_Text,uiColors[GUI_COLOR_PATTERN_INS_WARN]);
 | 
				
			||||||
 | 
					          } else {
 | 
				
			||||||
 | 
					            ImGui::PushStyleColor(ImGuiCol_Text,uiColors[GUI_COLOR_PATTERN_INS]);
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        sprintf(id,"%.2X##PI_%d_%d",pat->data[i][2],i,j);
 | 
					        sprintf(id,"%.2X##PI_%d_%d",pat->data[i][2],i,j);
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      ImGui::SameLine(0.0f,0.0f);
 | 
					      ImGui::SameLine(0.0f,0.0f);
 | 
				
			||||||
| 
						 | 
					@ -343,6 +352,7 @@ inline void FurnaceGUI::patternRow(int i, bool isPlaying, float lineHeight, int
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void FurnaceGUI::drawPattern() {
 | 
					void FurnaceGUI::drawPattern() {
 | 
				
			||||||
 | 
					  //int delta0=SDL_GetPerformanceCounter();
 | 
				
			||||||
  if (nextWindow==GUI_WINDOW_PATTERN) {
 | 
					  if (nextWindow==GUI_WINDOW_PATTERN) {
 | 
				
			||||||
    patternOpen=true;
 | 
					    patternOpen=true;
 | 
				
			||||||
    ImGui::SetNextWindowFocus();
 | 
					    ImGui::SetNextWindowFocus();
 | 
				
			||||||
| 
						 | 
					@ -386,6 +396,7 @@ void FurnaceGUI::drawPattern() {
 | 
				
			||||||
    oldOrder=e->getOrder();
 | 
					    oldOrder=e->getOrder();
 | 
				
			||||||
    int chans=e->getTotalChannelCount();
 | 
					    int chans=e->getTotalChannelCount();
 | 
				
			||||||
    int displayChans=0;
 | 
					    int displayChans=0;
 | 
				
			||||||
 | 
					    const DivPattern* patCache[DIV_MAX_CHANS];
 | 
				
			||||||
    for (int i=0; i<chans; i++) {
 | 
					    for (int i=0; i<chans; i++) {
 | 
				
			||||||
      if (e->song.chanShow[i]) displayChans++;
 | 
					      if (e->song.chanShow[i]) displayChans++;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -571,8 +582,11 @@ void FurnaceGUI::drawPattern() {
 | 
				
			||||||
      // previous pattern
 | 
					      // previous pattern
 | 
				
			||||||
      ImGui::BeginDisabled();
 | 
					      ImGui::BeginDisabled();
 | 
				
			||||||
      if (settings.viewPrevPattern) {
 | 
					      if (settings.viewPrevPattern) {
 | 
				
			||||||
 | 
					        if ((ord-1)>=0) for (int i=0; i<chans; i++) {
 | 
				
			||||||
 | 
					          patCache[i]=e->song.pat[i].getPattern(e->song.orders.ord[i][ord-1],true);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        for (int i=0; i<dummyRows-1; i++) {
 | 
					        for (int i=0; i<dummyRows-1; i++) {
 | 
				
			||||||
          patternRow(e->song.patLen+i-dummyRows+1,e->isPlaying(),lineHeight,chans,ord-1);
 | 
					          patternRow(e->song.patLen+i-dummyRows+1,e->isPlaying(),lineHeight,chans,ord-1,patCache);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      } else {
 | 
					      } else {
 | 
				
			||||||
        for (int i=0; i<dummyRows-1; i++) {
 | 
					        for (int i=0; i<dummyRows-1; i++) {
 | 
				
			||||||
| 
						 | 
					@ -582,14 +596,20 @@ void FurnaceGUI::drawPattern() {
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      ImGui::EndDisabled();
 | 
					      ImGui::EndDisabled();
 | 
				
			||||||
      // active area
 | 
					      // active area
 | 
				
			||||||
 | 
					      for (int i=0; i<chans; i++) {
 | 
				
			||||||
 | 
					        patCache[i]=e->song.pat[i].getPattern(e->song.orders.ord[i][ord],true);
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
      for (int i=0; i<e->song.patLen; i++) {
 | 
					      for (int i=0; i<e->song.patLen; i++) {
 | 
				
			||||||
        patternRow(i,e->isPlaying(),lineHeight,chans,ord);
 | 
					        patternRow(i,e->isPlaying(),lineHeight,chans,ord,patCache);
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      // next pattern
 | 
					      // next pattern
 | 
				
			||||||
      ImGui::BeginDisabled();
 | 
					      ImGui::BeginDisabled();
 | 
				
			||||||
      if (settings.viewPrevPattern) {
 | 
					      if (settings.viewPrevPattern) {
 | 
				
			||||||
 | 
					        if ((ord+1)<e->song.ordersLen) for (int i=0; i<chans; i++) {
 | 
				
			||||||
 | 
					          patCache[i]=e->song.pat[i].getPattern(e->song.orders.ord[i][ord+1],true);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        for (int i=0; i<=dummyRows; i++) {
 | 
					        for (int i=0; i<=dummyRows; i++) {
 | 
				
			||||||
          patternRow(i,e->isPlaying(),lineHeight,chans,ord+1);
 | 
					          patternRow(i,e->isPlaying(),lineHeight,chans,ord+1,patCache);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      } else {
 | 
					      } else {
 | 
				
			||||||
        for (int i=0; i<=dummyRows; i++) {
 | 
					        for (int i=0; i<=dummyRows; i++) {
 | 
				
			||||||
| 
						 | 
					@ -837,5 +857,7 @@ void FurnaceGUI::drawPattern() {
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  if (ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows)) curWindow=GUI_WINDOW_PATTERN;
 | 
					  if (ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows)) curWindow=GUI_WINDOW_PATTERN;
 | 
				
			||||||
  ImGui::End();
 | 
					  ImGui::End();
 | 
				
			||||||
 | 
					  //int delta1=SDL_GetPerformanceCounter();
 | 
				
			||||||
 | 
					  //logV("render time: %dµs\n",(delta1-delta0)/(SDL_GetPerformanceFrequency()/1000000));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -980,6 +980,8 @@ void FurnaceGUI::drawSettings() {
 | 
				
			||||||
            UI_COLOR_CONFIG(GUI_COLOR_PATTERN_ACTIVE,"Note");
 | 
					            UI_COLOR_CONFIG(GUI_COLOR_PATTERN_ACTIVE,"Note");
 | 
				
			||||||
            UI_COLOR_CONFIG(GUI_COLOR_PATTERN_INACTIVE,"Blank");
 | 
					            UI_COLOR_CONFIG(GUI_COLOR_PATTERN_INACTIVE,"Blank");
 | 
				
			||||||
            UI_COLOR_CONFIG(GUI_COLOR_PATTERN_INS,"Instrument");
 | 
					            UI_COLOR_CONFIG(GUI_COLOR_PATTERN_INS,"Instrument");
 | 
				
			||||||
 | 
					            UI_COLOR_CONFIG(GUI_COLOR_PATTERN_INS_WARN,"Instrument (invalid type)");
 | 
				
			||||||
 | 
					            UI_COLOR_CONFIG(GUI_COLOR_PATTERN_INS_ERROR,"Instrument (out of range)");
 | 
				
			||||||
            UI_COLOR_CONFIG(GUI_COLOR_PATTERN_VOLUME_MIN,"Volume (0%)");
 | 
					            UI_COLOR_CONFIG(GUI_COLOR_PATTERN_VOLUME_MIN,"Volume (0%)");
 | 
				
			||||||
            UI_COLOR_CONFIG(GUI_COLOR_PATTERN_VOLUME_HALF,"Volume (50%)");
 | 
					            UI_COLOR_CONFIG(GUI_COLOR_PATTERN_VOLUME_HALF,"Volume (50%)");
 | 
				
			||||||
            UI_COLOR_CONFIG(GUI_COLOR_PATTERN_VOLUME_MAX,"Volume (100%)");
 | 
					            UI_COLOR_CONFIG(GUI_COLOR_PATTERN_VOLUME_MAX,"Volume (100%)");
 | 
				
			||||||
| 
						 | 
					@ -1772,6 +1774,8 @@ void FurnaceGUI::commitSettings() {
 | 
				
			||||||
  PUT_UI_COLOR(GUI_COLOR_PATTERN_ACTIVE);
 | 
					  PUT_UI_COLOR(GUI_COLOR_PATTERN_ACTIVE);
 | 
				
			||||||
  PUT_UI_COLOR(GUI_COLOR_PATTERN_INACTIVE);
 | 
					  PUT_UI_COLOR(GUI_COLOR_PATTERN_INACTIVE);
 | 
				
			||||||
  PUT_UI_COLOR(GUI_COLOR_PATTERN_INS);
 | 
					  PUT_UI_COLOR(GUI_COLOR_PATTERN_INS);
 | 
				
			||||||
 | 
					  PUT_UI_COLOR(GUI_COLOR_PATTERN_INS_WARN);
 | 
				
			||||||
 | 
					  PUT_UI_COLOR(GUI_COLOR_PATTERN_INS_ERROR);
 | 
				
			||||||
  PUT_UI_COLOR(GUI_COLOR_PATTERN_VOLUME_MIN);
 | 
					  PUT_UI_COLOR(GUI_COLOR_PATTERN_VOLUME_MIN);
 | 
				
			||||||
  PUT_UI_COLOR(GUI_COLOR_PATTERN_VOLUME_HALF);
 | 
					  PUT_UI_COLOR(GUI_COLOR_PATTERN_VOLUME_HALF);
 | 
				
			||||||
  PUT_UI_COLOR(GUI_COLOR_PATTERN_VOLUME_MAX);
 | 
					  PUT_UI_COLOR(GUI_COLOR_PATTERN_VOLUME_MAX);
 | 
				
			||||||
| 
						 | 
					@ -2174,6 +2178,8 @@ void FurnaceGUI::applyUISettings() {
 | 
				
			||||||
  GET_UI_COLOR(GUI_COLOR_PATTERN_ACTIVE,ImVec4(1.0f,1.0f,1.0f,1.0f));
 | 
					  GET_UI_COLOR(GUI_COLOR_PATTERN_ACTIVE,ImVec4(1.0f,1.0f,1.0f,1.0f));
 | 
				
			||||||
  GET_UI_COLOR(GUI_COLOR_PATTERN_INACTIVE,ImVec4(0.5f,0.5f,0.5f,1.0f));
 | 
					  GET_UI_COLOR(GUI_COLOR_PATTERN_INACTIVE,ImVec4(0.5f,0.5f,0.5f,1.0f));
 | 
				
			||||||
  GET_UI_COLOR(GUI_COLOR_PATTERN_INS,ImVec4(0.4f,0.7f,1.0f,1.0f));
 | 
					  GET_UI_COLOR(GUI_COLOR_PATTERN_INS,ImVec4(0.4f,0.7f,1.0f,1.0f));
 | 
				
			||||||
 | 
					  GET_UI_COLOR(GUI_COLOR_PATTERN_INS_WARN,ImVec4(1.0f,1.0f,0.1f,1.0f));
 | 
				
			||||||
 | 
					  GET_UI_COLOR(GUI_COLOR_PATTERN_INS_ERROR,ImVec4(1.0f,0.1f,0.1f,1.0f));
 | 
				
			||||||
  GET_UI_COLOR(GUI_COLOR_PATTERN_VOLUME_MIN,ImVec4(0.0f,0.5f,0.0f,1.0f));
 | 
					  GET_UI_COLOR(GUI_COLOR_PATTERN_VOLUME_MIN,ImVec4(0.0f,0.5f,0.0f,1.0f));
 | 
				
			||||||
  GET_UI_COLOR(GUI_COLOR_PATTERN_VOLUME_HALF,ImVec4(0.0f,0.75f,0.0f,1.0f));
 | 
					  GET_UI_COLOR(GUI_COLOR_PATTERN_VOLUME_HALF,ImVec4(0.0f,0.75f,0.0f,1.0f));
 | 
				
			||||||
  GET_UI_COLOR(GUI_COLOR_PATTERN_VOLUME_MAX,ImVec4(0.0f,1.0f,0.0f,1.0f));
 | 
					  GET_UI_COLOR(GUI_COLOR_PATTERN_VOLUME_MAX,ImVec4(0.0f,1.0f,0.0f,1.0f));
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue