Skip to content

Commit 88ef6c6

Browse files
committed
MapDrawableBatch.MergeOntoThis does an early-out if all argument layers have 0 quads
Added more informative error when trying to merge with null textures. Removed 400 ms delay on variable grid. Fixed incorrect subtext under X,Y,Z when toggling whether animation relative positions are used.
1 parent 78a7a1e commit 88ef6c6

File tree

3 files changed

+76
-28
lines changed

3 files changed

+76
-28
lines changed

Engines/FlatRedBallAddOns/FlatRedBall.TileGraphics/FlatRedBall.TileGraphics/MapDrawableBatch.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1633,13 +1633,34 @@ public void MergeOntoThis(IEnumerable<MapDrawableBatch> mapDrawableBatches)
16331633
{
16341634
int quadsOnThis = QuadCount;
16351635

1636+
mapDrawableBatches = mapDrawableBatches.Where(item => item.QuadCount > 0).ToArray();
1637+
1638+
if (mapDrawableBatches.Count() == 0)
1639+
{
1640+
// no need to do anything:
1641+
return;
1642+
}
1643+
16361644
// If this is empty, then this will inherit the first MDB's texture
16371645

16381646
if (quadsOnThis == 0 && this.Texture == null)
16391647
{
16401648
var firstWithNonNullTexture = mapDrawableBatches.FirstOrDefault(item => item.Texture != null);
16411649

1642-
this.Texture = firstWithNonNullTexture?.Texture;
1650+
if (firstWithNonNullTexture == null)
1651+
{
1652+
var message = $"Merging failed because there are no layers with non-null textures. All are null. " +
1653+
$"There are {mapDrawableBatches.Count()} total layers.";
1654+
1655+
foreach (var item in mapDrawableBatches)
1656+
{
1657+
message += "\n" + item.Name;
1658+
}
1659+
1660+
throw new InvalidOperationException(message);
1661+
}
1662+
1663+
this.Texture = firstWithNonNullTexture.Texture;
16431664
}
16441665

16451666

FRBDK/Glue/OfficialPlugins/PropertyGrid/NamedObjectSaveVariableDataGridItem.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,10 +334,19 @@ private async void HandleVariableSet(object owner, SetPropertyArgs args)
334334
{
335335

336336
// We're going to delay updating all UI, saving, and codegen for a half second to not spam the system:
337-
await System.Threading.Tasks.Task.Delay(400);
337+
// Update March 29, 2025 - why not spam the system? Let the CPU do its thing. This just makes FRB seems
338+
// less responsive. We have "throttling" in place by checking if a commit is full.
339+
// I'm taking this out so Glue is even more responsive:
340+
//await System.Threading.Tasks.Task.Delay(100);
338341

339342
// Set subtext before refreshing property grid
340-
NamedObjectVariableShowingLogic.AssignVariableSubtext(NamedObjectSave, categories.ToList(), NamedObjectSave.GetAssetTypeInfo());
343+
var didChange = NamedObjectVariableShowingLogic.AssignVariableSubtext(NamedObjectSave, categories.ToList(), NamedObjectSave.GetAssetTypeInfo());
344+
345+
if(didChange)
346+
{
347+
// we changed subtext, so we need to refresh the grid again:
348+
GlueCommands.Self.RefreshCommands.RefreshVariables();
349+
}
341350

342351
IsDefault = makeDefault;
343352

FRBDK/Glue/OfficialPlugins/PropertyGrid/NamedObjectVariableShowingLogic.cs

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -124,18 +124,18 @@ private static Dictionary<string, VariableDefinition> GetVariableDefinitions(Nam
124124
{
125125
var shouldAdd = true;
126126

127-
if(definition.IsVariableVisibleInEditor != null)
127+
if (definition.IsVariableVisibleInEditor != null)
128128
{
129129
shouldAdd = definition.IsVariableVisibleInEditor(container, instance);
130130
}
131131

132-
if(shouldAdd)
132+
if (shouldAdd)
133133
{
134134
variableDefinitions[definition.Name] = definition;
135135
}
136136
}
137137
}
138-
else if(instance.SourceType == SourceType.Entity)
138+
else if (instance.SourceType == SourceType.Entity)
139139
{
140140
var instanceElement = ObjectFinder.Self.GetElement(instance);
141141
if (instanceElement != null)
@@ -174,9 +174,9 @@ private static Dictionary<string, VariableDefinition> GetVariableDefinitions(Nam
174174
}
175175

176176
var subtext = variableInElement?.Summary ?? baseVariable?.Summary;
177-
if(!string.IsNullOrWhiteSpace(subtext))
177+
if (!string.IsNullOrWhiteSpace(subtext))
178178
{
179-
baseVariableDefinition.SubtextFunc = (_,_) => subtext;
179+
baseVariableDefinition.SubtextFunc = (_, _) => subtext;
180180
}
181181

182182
if (variableInElement.CustomGetForcedOptionsFunc != null)
@@ -318,17 +318,17 @@ public static void UpdateShownVariables(DataUiGrid grid, NamedObjectSave instanc
318318
public static void UpdateConditionalVisibility(DataUiGrid grid, NamedObjectSave instance, GlueElement container, AssetTypeInfo ati)
319319
{
320320
var needsFullRefresh = false;
321-
foreach(var category in grid.Categories)
321+
foreach (var category in grid.Categories)
322322
{
323-
foreach(var member in category.Members)
323+
foreach (var member in category.Members)
324324
{
325-
if(member is NamedObjectSaveVariableDataGridItem namedObjectSaveVariableDataGridItem)
325+
if (member is NamedObjectSaveVariableDataGridItem namedObjectSaveVariableDataGridItem)
326326
{
327-
if(namedObjectSaveVariableDataGridItem.VariableDefinition.IsVariableVisibleInEditor != null)
327+
if (namedObjectSaveVariableDataGridItem.VariableDefinition.IsVariableVisibleInEditor != null)
328328
{
329329
// Is it true?
330330
var shouldBeVisible = namedObjectSaveVariableDataGridItem.VariableDefinition.IsVariableVisibleInEditor(container, instance);
331-
if(!shouldBeVisible)
331+
if (!shouldBeVisible)
332332
{
333333
// this shouldn't be here, we need a refresh
334334
needsFullRefresh = true;
@@ -338,24 +338,24 @@ public static void UpdateConditionalVisibility(DataUiGrid grid, NamedObjectSave
338338
}
339339
}
340340

341-
if(!needsFullRefresh && ati != null)
341+
if (!needsFullRefresh && ati != null)
342342
{
343-
foreach(var variableDefinition in ati.VariableDefinitions)
343+
foreach (var variableDefinition in ati.VariableDefinitions)
344344
{
345-
if(variableDefinition.IsVariableVisibleInEditor != null)
345+
if (variableDefinition.IsVariableVisibleInEditor != null)
346346
{
347347
var shouldBeShown = variableDefinition.IsVariableVisibleInEditor(container, instance);
348-
if(shouldBeShown)
348+
if (shouldBeShown)
349349
{
350350
var wasFound = false;
351351
// This better be in one of the categories
352-
foreach(var category in grid.Categories)
352+
foreach (var category in grid.Categories)
353353
{
354-
foreach(var member in category.Members)
354+
foreach (var member in category.Members)
355355
{
356-
if(member is NamedObjectSaveVariableDataGridItem namedObjectSaveVariableDataGridItem)
356+
if (member is NamedObjectSaveVariableDataGridItem namedObjectSaveVariableDataGridItem)
357357
{
358-
if(namedObjectSaveVariableDataGridItem.VariableDefinition.Name == variableDefinition.Name)
358+
if (namedObjectSaveVariableDataGridItem.VariableDefinition.Name == variableDefinition.Name)
359359
{
360360
// This is good, we found it
361361
wasFound = true;
@@ -364,7 +364,7 @@ public static void UpdateConditionalVisibility(DataUiGrid grid, NamedObjectSave
364364
}
365365
}
366366
}
367-
if(!wasFound)
367+
if (!wasFound)
368368
{
369369
needsFullRefresh = true;
370370
break;
@@ -375,7 +375,7 @@ public static void UpdateConditionalVisibility(DataUiGrid grid, NamedObjectSave
375375
}
376376
}
377377

378-
if(needsFullRefresh)
378+
if (needsFullRefresh)
379379
{
380380
UpdateShownVariables(grid, instance, container, ati);
381381
}
@@ -427,7 +427,7 @@ private static MemberCategory CreateTopmostCategory(List<MemberCategory> categor
427427
return topmostCategory;
428428
}
429429

430-
public static void AssignVariableSubtext(NamedObjectSave instance, List<MemberCategory> categories, AssetTypeInfo assetTypeInfo)
430+
public static bool AssignVariableSubtext(NamedObjectSave instance, List<MemberCategory> categories, AssetTypeInfo assetTypeInfo)
431431
{
432432
var xVariable = categories.SelectMany(item => item.Members).FirstOrDefault(item => item.DisplayName == "X");
433433
var yVariable = categories.SelectMany(item => item.Members).FirstOrDefault(item => item.DisplayName == "Y");
@@ -461,18 +461,36 @@ public static void AssignVariableSubtext(NamedObjectSave instance, List<MemberCa
461461
setZ = true;
462462
}
463463

464-
464+
var changed = false;
465465
if (xVariable != null)
466-
{ xVariable.DetailText = subtext; }
466+
{
467+
if (xVariable.DetailText != subtext)
468+
{
469+
changed = true;
470+
xVariable.DetailText = subtext;
471+
}
472+
}
467473

468474

469475
if (yVariable != null)
470-
{ yVariable.DetailText = subtext; }
476+
{
477+
if (yVariable.DetailText != subtext)
478+
{
479+
changed = true;
480+
yVariable.DetailText = subtext;
481+
}
482+
}
471483

472484
if (zVariable != null && setZ)
473485
{
474-
zVariable.DetailText = subtext;
486+
if(zVariable.DetailText != subtext)
487+
{
488+
changed = true;
489+
zVariable.DetailText = subtext;
490+
}
475491
}
492+
493+
return changed;
476494
}
477495

478496
private static void AddForTypedMember(NamedObjectSave instance, GlueElement container, List<MemberCategory> categories,

0 commit comments

Comments
 (0)