Skip to content

Commit

Permalink
Improved performance of value slider changing. Still can be better, b…
Browse files Browse the repository at this point in the history
…ut it's a start.
  • Loading branch information
vchelaru committed Jan 8, 2024
1 parent 2deca10 commit b93f44f
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
using FlatRedBall.Glue.AutomatedGlue;
using static FlatRedBall.Debugging.Debugger;
using FlatRedBall.Glue.Plugins.EmbeddedPlugins.FactoryPlugin;
using WpfDataUi.DataTypes;

namespace FlatRedBall.Glue.Plugins.ExportedImplementations.CommandInterfaces;

Expand Down Expand Up @@ -2393,9 +2394,9 @@ await SetVariableOnInner(assignment.NamedObjectSave, assignment.VariableName, as

[Obsolete("Use SetVariableOnAsync")]
public async void SetVariableOn(NamedObjectSave nos, string memberName, object value, bool performSaveAndGenerateCode = true,
bool updateUi = true, bool recordUndo = true)
bool updateUi = true, bool recordUndo = true, SetPropertyCommitType commitType = SetPropertyCommitType.Full)
{
await SetVariableOnInner(nos, memberName, value, performSaveAndGenerateCode, updateUi, notifyPlugins: true, recordUndo:recordUndo);
await SetVariableOnInner(nos, memberName, value, performSaveAndGenerateCode, updateUi, notifyPlugins: true, recordUndo:recordUndo, commitType);
}


Expand All @@ -2408,7 +2409,7 @@ await TaskManager.Self.AddAsync(
}

private async Task SetVariableOnInner(NamedObjectSave nos, string memberName, object value, bool performSaveAndGenerateCode = true,
bool updateUi = true, bool notifyPlugins = true, bool recordUndo = true)
bool updateUi = true, bool notifyPlugins = true, bool recordUndo = true, SetPropertyCommitType commitType = SetPropertyCommitType.Full)
{
// XML serialization doesn't like enums
var needsEnum = GlueState.Self.CurrentGlueProject.FileVersion < (int)GlueProjectSave.GluxVersions.GlueSavedToJson;
Expand Down Expand Up @@ -2509,7 +2510,8 @@ await EditorObjects.IoC.Container.Get<NamedObjectSetVariableLogic>().ReactToName
{
NamedObjectSave = nos,
ChangedPropertyName = memberName,
OldValue = oldValue
OldValue = oldValue,
CommitType = commitType
};
PluginManager.ReactToChangedProperty(memberName, oldValue, nosContainer, variableChange);

Expand All @@ -2520,7 +2522,8 @@ await EditorObjects.IoC.Container.Get<NamedObjectSetVariableLogic>().ReactToName
NamedObject = nos,
ChangedMember = memberName,
OldValue = oldValue,
RecordUndo = recordUndo
RecordUndo = recordUndo,
CommitType = commitType
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Threading.Tasks;
using FlatRedBall.Glue.Managers;
using FlatRedBall.Glue.FormHelpers;
using WpfDataUi.DataTypes;

namespace FlatRedBall.Glue.Plugins.ExportedInterfaces.CommandInterfaces
{
Expand Down Expand Up @@ -195,7 +196,7 @@ Task AddNamedObjectToAsync(NamedObjectSave newNos, GlueElement element, NamedObj
/// <param name="value">The value of the variable.</param>
[Obsolete("Use SetVariableOnAsync")]
void SetVariableOn(NamedObjectSave nos, string memberName, object value, bool performSaveAndGenerateCode = true,
bool updateUi = true, bool recordUndo = true);
bool updateUi = true, bool recordUndo = true, SetPropertyCommitType commitType = SetPropertyCommitType.Full);

Task SetVariableOnAsync(NamedObjectSave nos, string memberName, object value, bool performSaveAndGenerateCode = true,
bool updateUi = true, bool recordUndo = true);
Expand Down
3 changes: 2 additions & 1 deletion FRBDK/Glue/Glue/Plugins/PluginBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
using Newtonsoft.Json.Linq;
using System.Windows;
using System.Windows.Media;
using WpfDataUi.DataTypes;

namespace FlatRedBall.Glue.Plugins
{
Expand Down Expand Up @@ -188,7 +189,7 @@ public class VariableChangeArguments
public object OldValue { get; set; }
public NamedObjectSave NamedObject { get; set; }
public bool RecordUndo { get; set; } = true;

public SetPropertyCommitType CommitType { get; set; } = SetPropertyCommitType.Full;
public override string ToString()
{
return $"{NamedObject}.{ChangedMember}";
Expand Down
2 changes: 2 additions & 0 deletions FRBDK/Glue/Glue/Plugins/PluginManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
using System.Threading.Tasks;
using FlatRedBall.Glue.Managers;
using FlatRedBall.Glue.Plugins.ExportedInterfaces.CommandInterfaces;
using WpfDataUi.DataTypes;
//using Gum.Wireframe;
//using Gum.Converters;

Expand Down Expand Up @@ -1615,6 +1616,7 @@ public class NamedObjectSavePropertyChange
public NamedObjectSave NamedObjectSave { get; set; }
public string ChangedPropertyName { get; set; }
public object OldValue { get; set; }
public SetPropertyCommitType CommitType { get; set; } = SetPropertyCommitType.Full;

public bool RecordUndo { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ public static void AddDisplayerUi(DataUiGrid grid, CustomVariable variable)

};

member.CustomSetEvent += (instance, value) =>
member.CustomSetPropertyEvent += (instance, args) =>
{
var value = args.Value;
var variableDefinition = instance as VariableDefinition;
if (value is Type type)
{
Expand Down Expand Up @@ -109,8 +110,9 @@ void Add<T>(string propertyName)
var member = new InstanceMember();
member.Name = propertyName;
member.CustomGetTypeEvent += (_) => typeof(T);
member.CustomSetEvent += (_, newValue) =>
member.CustomSetPropertyEvent += (_, args) =>
{
var newValue = args.Value;
variable.VariableDefinition.PropertiesToSetOnDisplayer[propertyName] = newValue;
};
member.CustomGetEvent += (_) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ public override void StartUp()

private async void HandleChangedNamedObjectPropertyList(List<PluginManager.NamedObjectSavePropertyChange> obj)
{
await GlueCommands.Self.RefreshCommands.ClearFixedErrors();
this.RefreshErrors();
if(obj.Count > 0 && obj[0].CommitType == WpfDataUi.DataTypes.SetPropertyCommitType.Full)
{
await GlueCommands.Self.RefreshCommands.ClearFixedErrors();
this.RefreshErrors();
}
}

//private async void HandleNamedObjectChangedValue(string changedMember, object oldValue, NamedObjectSave namedObject)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,9 @@ private static DataGridItem CreateInstanceMemberForVariable(GlueElement element,
instanceMember.UiCreated += (view) => variableDefinition.UiCreated(view);
}

instanceMember.CustomSetEvent += async (intance, value) =>
instanceMember.CustomSetPropertyEvent += async (intance, args) =>
{
var value = args.Value;
instanceMember.IsDefault = false;

//RefreshLogic.IgnoreNextRefresh();
Expand Down Expand Up @@ -329,8 +330,9 @@ private static void CreateInstanceMembersForVariables(GlueElement element, List<
//TypeConverter converter = variable.GetTypeConverter(element);
//instanceMember.TypeConverter = converter;

instanceMember.CustomSetEvent += (intance, value) =>
instanceMember.CustomSetPropertyEvent += (intance, args) =>
{
var value = args.Value;
instanceMember.IsDefault = false;

RefreshLogic.IgnoreNextRefresh();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ public NamedObjectSaveVariableDataGridItem()
{
CustomGetEvent += HandleCustomGet;

CustomSetEvent += HandleVariableSet;
//CustomSetEvent += HandleVariableSet;
CustomSetPropertyEvent += HandleVariableSet;

SetValueError += (newValue) =>
{
Expand Down Expand Up @@ -252,10 +253,11 @@ public object HandleCustomGet(object throwaway)
}
}

private async void HandleVariableSet(object owner, object value)
private async void HandleVariableSet(object owner, SetPropertyArgs args)
{
if (GlueState.Self.CurrentGlueProject == null)
return;
var value = args.Value;
//NamedObjectVariableChangeLogic.ReactToValueSet(instance, memberName, value, out bool makeDefault);

//static void ReactToValueSet(NamedObjectSave instance, string memberName, object value, out bool makeDefault)
Expand Down Expand Up @@ -319,46 +321,52 @@ private async void HandleVariableSet(object owner, object value)
GlueCommands.Self.GluxCommands.SetVariableOn(
NamedObjectSave,
NameOnInstance,
value, performSaveAndGenerateCode: false, updateUi: false);
value, performSaveAndGenerateCode: false, updateUi: false, commitType: args.CommitType);
#pragma warning restore CS0618 // Type or member is obsolete


// We're going to delay updating all UI, saving, and codegen for a half second to not spam the system:
await System.Threading.Tasks.Task.Delay(400);

// Set subtext before refreshing property grid
NamedObjectVariableShowingLogic.AssignVariableSubtext(NamedObjectSave, categories.ToList(), NamedObjectSave.GetAssetTypeInfo());
// If it's an intermediate set, no need to generate, refresh UI, or save:
if(args.CommitType == SetPropertyCommitType.Full)
{

IsDefault = makeDefault;
// We're going to delay updating all UI, saving, and codegen for a half second to not spam the system:
await System.Threading.Tasks.Task.Delay(400);

await TaskManager.Self.AddAsync(async () =>
{
GlueCommands.Self.GenerateCodeCommands.GenerateElementCode(Container);
EditorObjects.IoC.Container.Get<GlueErrorManager>().ClearFixedErrors();
// Set subtext before refreshing property grid
NamedObjectVariableShowingLogic.AssignVariableSubtext(NamedObjectSave, categories.ToList(), NamedObjectSave.GetAssetTypeInfo());

IsDefault = makeDefault;

GlueCommands.Self.DoOnUiThread(() =>
await TaskManager.Self.AddAsync(async () =>
{
MainGlueWindow.Self.PropertyGrid.Refresh();
PropertyGridHelper.UpdateNamedObjectDisplay();
if (DisplayName == "Name")
GlueCommands.Self.GenerateCodeCommands.GenerateElementCode(Container);
EditorObjects.IoC.Container.Get<GlueErrorManager>().ClearFixedErrors();

GlueCommands.Self.DoOnUiThread(() =>
{
MainGlueWindow.Self.PropertyGrid.Refresh();
PropertyGridHelper.UpdateNamedObjectDisplay();
if (DisplayName == "Name")
{
GlueCommands.Self.RefreshCommands.RefreshTreeNodeFor(Container,
// We can be faster by doing only a NamedObject refresh, since the only way this could change is the Name...right?
FlatRedBall.Glue.Plugins.ExportedInterfaces.CommandInterfaces.TreeNodeRefreshType.NamedObjects);
}
});

if (GlueState.Self.CurrentGlueProject.FileVersion >= (int)GluxVersions.SeparateJsonFilesForElements)
{
GlueCommands.Self.RefreshCommands.RefreshTreeNodeFor(Container,
// We can be faster by doing only a NamedObject refresh, since the only way this could change is the Name...right?
FlatRedBall.Glue.Plugins.ExportedInterfaces.CommandInterfaces.TreeNodeRefreshType.NamedObjects);
await GlueCommands.Self.GluxCommands.SaveElementAsync(Container);
}
else
{
GlueCommands.Self.GluxCommands.SaveProjectAndElements(TaskExecutionPreference.AddOrMoveToEnd);
}
});

if (GlueState.Self.CurrentGlueProject.FileVersion >= (int)GluxVersions.SeparateJsonFilesForElements)
{
await GlueCommands.Self.GluxCommands.SaveElementAsync(Container);
}
else
{
GlueCommands.Self.GluxCommands.SaveProjectAndElements(TaskExecutionPreference.AddOrMoveToEnd);
}


}, $"Delayed task to do all updates for {NamedObjectSave}", TaskExecutionPreference.AddOrMoveToEnd);
}, $"Delayed task to do all updates for {NamedObjectSave}", TaskExecutionPreference.AddOrMoveToEnd);
}

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,9 @@ private static InstanceMember CreateInstanceMemberForSourceName(NamedObjectSave
return instance.SourceName;
};

instanceMember.CustomSetEvent += (owner, value) =>
instanceMember.CustomSetPropertyEvent += (owner, args) =>
{
var value = args.Value;
instanceMember.IsDefault = false;
RefreshLogic.IgnoreNextRefresh();

Expand Down Expand Up @@ -525,8 +526,9 @@ private static DataGridItem CreateNameInstanceMember(NamedObjectSave instance)
instanceMember.MakeReadOnly();
}

instanceMember.CustomSetEvent += (throwaway, value) =>
instanceMember.CustomSetPropertyEvent += (throwaway, args) =>
{
var value = args.Value;
instanceMember.IsDefault = false;
RefreshLogic.IgnoreNextRefresh();

Expand Down Expand Up @@ -564,8 +566,9 @@ private static DataGridItem CreateIsLockedMember(NamedObjectSave instance)

var oldValue = instance.IsEditingLocked;

instanceMember.CustomSetEvent += (throwaway, value) =>
instanceMember.CustomSetPropertyEvent += (throwaway, args) =>
{
var value = args.Value;
instanceMember.IsDefault = false;
RefreshLogic.IgnoreNextRefresh();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ private void HandleDataContextChanged(object sender, DependencyPropertyChangedEv
var instanceMember = new InstanceMember();

instanceMember.Name = kvp.Key;
instanceMember.CustomSetEvent += (owner, value) =>
instanceMember.CustomSetPropertyEvent += (owner, args) =>
{
var value = args.Value;
ViewModel.AdditionalProperties[kvp.Key].Value = value;
ViewModel.NotifyAdditionalPropertiesChanged();

Expand Down

0 comments on commit b93f44f

Please sign in to comment.