Merge pull request #7960 from archimede67/editor-fix-auto-automap

Editor: fix FPS drop when editing tiles layer properties
This commit is contained in:
Dennis Felsing 2024-02-10 13:44:52 +00:00 committed by GitHub
commit e747a57af8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 41 additions and 2 deletions

View file

@ -88,3 +88,8 @@ void CEditorHistory::EndBulk(const char *pDisplay)
m_vpBulkActions.clear();
}
void CEditorHistory::EndBulk(int DisplayToUse)
{
EndBulk((DisplayToUse < 0 || DisplayToUse >= (int)m_vpBulkActions.size()) ? nullptr : m_vpBulkActions[DisplayToUse]->DisplayText());
}

View file

@ -32,6 +32,7 @@ public:
void BeginBulk();
void EndBulk(const char *pDisplay = nullptr);
void EndBulk(int DisplayToUse);
CEditor *m_pEditor;
std::deque<std::shared_ptr<IEditorAction>> m_vpUndoActions;

View file

@ -976,6 +976,7 @@ CUI::EPopupMenuFunctionResult CLayerTiles::RenderProperties(CUIRect *pToolBox)
static CLayerTilesPropTracker s_Tracker(m_pEditor);
s_Tracker.Begin(this, Prop, State);
m_pEditor->m_EditorHistory.BeginBulk();
if(Prop == ETilesProp::PROP_WIDTH && NewVal > 1)
{
@ -1064,12 +1065,25 @@ CUI::EPopupMenuFunctionResult CLayerTiles::RenderProperties(CUIRect *pToolBox)
m_AutoMapperConfig = -1;
}
if(Prop != ETilesProp::PROP_NONE && Prop != ETilesProp::PROP_SHIFT_BY)
s_Tracker.End(Prop, State);
// Check if modified property could have an effect on automapper
if(HasAutomapEffect(Prop))
{
FlagModified(0, 0, m_Width, m_Height);
// Record undo if automapper was ran
if(m_AutoAutoMap && !m_TilesHistory.empty())
{
m_pEditor->m_EditorHistory.RecordAction(std::make_shared<CEditorActionTileChanges>(m_pEditor, m_pEditor->m_SelectedGroup, m_pEditor->m_vSelectedLayers[0], "Auto map", m_TilesHistory));
ClearHistory();
}
}
s_Tracker.End(Prop, State);
// End undo bulk, taking the first action display as the displayed text in the history
// This is usually the resulting text of the edit layer tiles prop action
// Since we may also squeeze a tile changes action, we want both to appear as one, thus using a bulk
m_pEditor->m_EditorHistory.EndBulk(0);
return CUI::POPUP_KEEP_OPEN;
}
@ -1275,3 +1289,20 @@ void CLayerTiles::ShowPreventUnusedTilesWarning()
m_pEditor->m_PreventUnusedTilesWasWarned = true;
}
}
bool CLayerTiles::HasAutomapEffect(ETilesProp Prop)
{
switch(Prop)
{
case ETilesProp::PROP_WIDTH:
case ETilesProp::PROP_HEIGHT:
case ETilesProp::PROP_SHIFT:
case ETilesProp::PROP_IMAGE:
case ETilesProp::PROP_AUTOMAPPER:
case ETilesProp::PROP_SEED:
return true;
default:
return false;
}
return false;
}

View file

@ -185,6 +185,8 @@ public:
EditorTileStateChangeHistory<STileStateChange> m_TilesHistory;
inline virtual void ClearHistory() { m_TilesHistory.clear(); }
static bool HasAutomapEffect(ETilesProp Prop);
protected:
void RecordStateChange(int x, int y, CTile Previous, CTile Tile);